return 0;
}
+ if (size == GL_BGRA) {
+ size = 4;
+ }
+
+ if (size > 4) {
+ os::log("apitrace: warning: %s: unexpected size 0x%04X\n", __FUNCTION__, size);
+ }
+
size_t elementSize = size*_gl_type_size(type);
if (!stride) {
stride = (GLsizei)elementSize;
#define _glVertexAttribPointerARB_size(size, type, normalized, stride, count) _glArrayPointer_size(size, type, stride, count)
#define _glVertexAttribPointerNV_size(size, type, stride, count) _glArrayPointer_size(size, type, stride, count)
+/**
+ * Same as glGetIntegerv, but passing the result in the return value.
+ */
+static inline GLint
+_glGetInteger(GLenum pname) {
+ GLint param = 0;
+ _glGetIntegerv(pname, ¶m);
+ return param;
+}
+
+static inline GLint
+_element_array_buffer_binding(void) {
+ return _glGetInteger(GL_ELEMENT_ARRAY_BUFFER_BINDING);
+}
+
static inline GLuint
_glDrawArrays_count(GLint first, GLsizei count)
{
#define _glDrawArraysEXT_count _glDrawArrays_count
+/* Forward declaration for definition in gltrace.py */
+void
+_shadow_glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size,
+ GLvoid *data);
+
static inline GLuint
_glDrawElementsBaseVertex_count(GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex)
{
GLvoid *temp = 0;
- GLint element_array_buffer = 0;
if (!count) {
return 0;
}
- _glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &element_array_buffer);
+ GLint element_array_buffer = _element_array_buffer_binding();
if (element_array_buffer) {
// Read indices from index buffer object
GLintptr offset = (GLintptr)indices;
return 0;
}
memset(temp, 0, size);
- _glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, size, temp);
+ _shadow_glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, size, temp);
indices = temp;
} else {
if (!indices) {
#define _glDrawArraysInstancedEXT_count _glDrawArraysInstanced_count
#define _glDrawElementsInstancedEXT_count _glDrawElementsInstanced_count
+typedef struct {
+ GLuint count;
+ GLuint primCount;
+ GLuint first;
+ GLuint baseInstance;
+} DrawArraysIndirectCommand;
+
+static inline GLuint
+_glMultiDrawArraysIndirect_count(const GLvoid *indirect, GLsizei drawcount, GLsizei stride) {
+ const DrawArraysIndirectCommand *cmd;
+ GLvoid *temp = 0;
+
+ if (drawcount <= 0) {
+ return 0;
+ }
+
+ if (stride == 0) {
+ stride = sizeof *cmd;
+ }
+
+ GLint draw_indirect_buffer = _glGetInteger(GL_DRAW_INDIRECT_BUFFER_BINDING);
+ if (draw_indirect_buffer) {
+ // Read commands from indirect buffer object
+ GLintptr offset = (GLintptr)indirect;
+ GLsizeiptr size = sizeof *cmd + (drawcount - 1) * stride;
+ GLvoid *temp = malloc(size);
+ if (!temp) {
+ return 0;
+ }
+ memset(temp, 0, size);
+ _glGetBufferSubData(GL_DRAW_INDIRECT_BUFFER, offset, size, temp);
+ indirect = temp;
+ } else {
+ if (!indirect) {
+ return 0;
+ }
+ }
+
+ GLuint count = 0;
+ for (GLsizei i = 0; i < drawcount; ++i) {
+ cmd = (const DrawArraysIndirectCommand *)((const GLbyte *)indirect + i * stride);
+
+ GLuint count_i = _glDrawArraysInstancedBaseInstance_count(
+ cmd->first,
+ cmd->count,
+ cmd->primCount,
+ cmd->baseInstance
+ );
+
+ count = std::max(count, count_i);
+ }
+
+ if (draw_indirect_buffer) {
+ free(temp);
+ }
+
+ return count;
+}
+
static inline GLuint
_glDrawArraysIndirect_count(const GLvoid *indirect) {
- os::log("apitrace: warning: %s: unsupported\n", __FUNCTION__);
- return 0;
+ return _glMultiDrawArraysIndirect_count(indirect, 1, 0);
+}
+
+typedef struct {
+ GLuint count;
+ GLuint primCount;
+ GLuint firstIndex;
+ GLuint baseVertex;
+ GLuint baseInstance;
+} DrawElementsIndirectCommand;
+
+static inline GLuint
+_glMultiDrawElementsIndirect_count(GLenum type, const GLvoid *indirect, GLsizei drawcount, GLsizei stride) {
+ const DrawElementsIndirectCommand *cmd;
+ GLvoid *temp = 0;
+
+ if (drawcount <= 0) {
+ return 0;
+ }
+
+ if (stride == 0) {
+ stride = sizeof *cmd;
+ }
+
+ GLint draw_indirect_buffer = _glGetInteger(GL_DRAW_INDIRECT_BUFFER_BINDING);
+ if (draw_indirect_buffer) {
+ // Read commands from indirect buffer object
+ GLintptr offset = (GLintptr)indirect;
+ GLsizeiptr size = sizeof *cmd + (drawcount - 1) * stride;
+ GLvoid *temp = malloc(size);
+ if (!temp) {
+ return 0;
+ }
+ memset(temp, 0, size);
+ _glGetBufferSubData(GL_DRAW_INDIRECT_BUFFER, offset, size, temp);
+ indirect = temp;
+ } else {
+ if (!indirect) {
+ return 0;
+ }
+ }
+
+ cmd = (const DrawElementsIndirectCommand *)indirect;
+
+ GLuint count = 0;
+ for (GLsizei i = 0; i < drawcount; ++i) {
+ cmd = (const DrawElementsIndirectCommand *)((const GLbyte *)indirect + i * stride);
+
+ GLuint count_i = _glDrawElementsInstancedBaseVertexBaseInstance_count(
+ cmd->count,
+ type,
+ (GLvoid *)(uintptr_t)(cmd->firstIndex * _gl_type_size(type)),
+ cmd->primCount,
+ cmd->baseVertex,
+ cmd->baseInstance
+ );
+
+ count = std::max(count, count_i);
+ }
+
+ if (draw_indirect_buffer) {
+ free(temp);
+ }
+
+ return count;
}
static inline GLuint
_glDrawElementsIndirect_count(GLenum type, const GLvoid *indirect) {
- os::log("apitrace: warning: %s: unsupported\n", __FUNCTION__);
- return 0;
+ return _glMultiDrawElementsIndirect_count(type, indirect, 1, 0);
}
+#define _glMultiDrawArraysIndirectAMD_count _glMultiDrawArraysIndirect_count
+#define _glMultiDrawElementsIndirectAMD_count _glMultiDrawElementsIndirect_count
+
static inline GLuint
_glMultiDrawArrays_count(const GLint *first, const GLsizei *count, GLsizei drawcount) {
GLuint _count = 0;
return (x + (y - 1)) & ~(y - 1);
}
-static inline size_t
-_gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth, GLboolean has_unpack_subimage) {
+static inline void
+_gl_format_size(GLenum format, GLenum type,
+ unsigned & bits_per_element, unsigned & bits_per_pixel)
+{
unsigned num_channels = _gl_format_channels(format);
- unsigned bits_per_element;
- unsigned bits_per_pixel;
switch (type) {
case GL_BITMAP:
bits_per_pixel = bits_per_element = 1;
bits_per_pixel = bits_per_element = 0;
break;
}
+}
+
+static inline size_t
+_glClearBufferData_size(GLenum format, GLenum type) {
+ unsigned bits_per_element;
+ unsigned bits_per_pixel;
+ _gl_format_size(format, type, bits_per_element, bits_per_pixel);
+ return (bits_per_pixel + 7)/8;
+}
+
+static inline size_t
+_gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth, GLboolean has_unpack_subimage) {
+
+ unsigned bits_per_element;
+ unsigned bits_per_pixel;
+ _gl_format_size(format, type, bits_per_element, bits_per_pixel);
GLint alignment = 4;
GLint row_length = 0;
}
}
+
+/**
+ * Helper function for determining the string lengths for glShaderSource and
+ * glShaderSourceARB, which is a tad too complex to inline in the specs.
+ */
+template<class Char>
+static inline size_t
+_glShaderSource_length(const Char * const * string, const GLint *length, GLsizei index)
+{
+ if (length != NULL && length[index] >= 0) {
+ return (size_t)length[index];
+ } else {
+ return strlen(string[index]);
+ }
+}
+
+/**
+ * Helper function for determining the string lengths for glGetDebugMessageLog*.
+ */
+template<class Char>
+static inline size_t
+_glGetDebugMessageLog_length(const Char * string, const GLsizei *lengths, GLuint count)
+{
+ size_t size = 0;
+ GLuint index;
+ if (lengths) {
+ for (index = 0; index < count; ++index) {
+ size += lengths[index];
+ }
+ } else {
+ for (index = 0; index < count; ++index) {
+ size += strlen(&string[size]) + 1;
+ }
+ }
+ if (size) {
+ // Remove the last null terminator
+ --size;
+ }
+ return size;
+}
+
/*
* attribute list, terminated by the given terminator.
*/