From: José Fonseca Date: Wed, 23 Mar 2011 16:44:30 +0000 (+0000) Subject: Unbreak tracing glDrawElements with VBOs. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=8a6c6cb07fbb009bb1587d890309db70a0f08fed;p=apitrace Unbreak tracing glDrawElements with VBOs. --- diff --git a/glsize.hpp b/glsize.hpp index d3df4aa..8d46ea5 100644 --- a/glsize.hpp +++ b/glsize.hpp @@ -95,49 +95,74 @@ __glArrayPointer_size(GLint size, GLenum type, GLsizei stride, GLsizei maxIndex) #define __glFogCoordPointer_size(type, stride, maxIndex) __glArrayPointer_size(1, type, stride, maxIndex) #define __glSecondaryColorPointer_size(size, type, stride, maxIndex) __glArrayPointer_size(size, type, stride, maxIndex) -static inline size_t +static inline GLuint __glDrawArrays_maxindex(GLint first, GLsizei count) { return first + count - 1; } -static inline size_t -__glDrawElements_maxindex(GLsizei count, GLenum type, const GLvoid *_indices) +static inline GLuint +__glDrawElements_maxindex(GLsizei count, GLenum type, const GLvoid *indices) { - size_t maxindex = 0; - unsigned i; + GLvoid *temp = 0; + GLint __element_array_buffer = 0; + __glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &__element_array_buffer); + if (__element_array_buffer) { + // Read indices from index buffer object + GLintptr offset = (GLintptr)indices; + GLsizeiptr size = count*__gl_type_size(type); + GLvoid *temp = malloc(size); + if (!temp) { + return 0; + } + memset(temp, 0, size); + __glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, size, temp); + indices = temp; + } else { + if (!indices) { + return 0; + } + } + GLuint maxindex = 0; + GLsizei i; if (type == GL_UNSIGNED_BYTE) { - const GLubyte *indices = (const GLubyte *)_indices; + const GLubyte *p = (const GLubyte *)indices; for (i = 0; i < count; ++i) { - if (indices[i] > maxindex) { - maxindex = indices[i]; + if (p[i] > maxindex) { + maxindex = p[i]; } } } else if (type == GL_UNSIGNED_SHORT) { - const GLushort *indices = (const GLushort *)_indices; + const GLushort *p = (const GLushort *)indices; for (i = 0; i < count; ++i) { - if (indices[i] > maxindex) { - maxindex = indices[i]; + if (p[i] > maxindex) { + maxindex = p[i]; } } } else if (type == GL_UNSIGNED_INT) { - const GLuint *indices = (const GLuint *)_indices; + const GLuint *p = (const GLuint *)indices; for (i = 0; i < count; ++i) { - if (indices[i] > maxindex) { - maxindex = indices[i]; + if (p[i] > maxindex) { + maxindex = p[i]; } } } else { OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, type); } + if (__element_array_buffer) { + free(temp); + } + return maxindex; } -static inline size_t +static inline GLuint __glDrawRangeElements_maxindex(GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid * indices) { + (void)start; + (void)end; return __glDrawElements_maxindex(count, type, indices); } diff --git a/gltrace.py b/gltrace.py index 0aa60cd..1186c09 100644 --- a/gltrace.py +++ b/gltrace.py @@ -84,9 +84,31 @@ class GlTracer(Tracer): ] def state_tracker_decl(self, api): - # A simple state tracker to track the pointer values + # Whether we need user arrays + print 'static inline bool __need_user_arrays(void)' + print '{' + for camelcase_name, uppercase_name in self.arrays: + function_name = 'gl%sPointer' % camelcase_name + enable_name = 'GL_%s_ARRAY' % uppercase_name + binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name + print ' // %s' % function_name + print ' {' + print ' GLboolean __enabled = GL_FALSE;' + print ' __glGetBooleanv(%s, &__enabled);' % enable_name + print ' if (__enabled) {' + print ' GLint __binding = 0;' + print ' __glGetIntegerv(%s, &__binding);' % binding_name + print ' if (!__binding) {' + print ' return true;' + print ' }' + print ' }' + print ' }' + print + print ' return false;' + print '}' + print - print 'static void __trace_arrays(GLsizei maxindex);' + print 'static void __trace_user_arrays(GLuint maxindex);' print array_pointer_function_names = set(( @@ -125,7 +147,7 @@ class GlTracer(Tracer): )) def trace_function_impl_body(self, function): - # Defer tracing of array pointers + # Defer tracing of user array pointers... if function.name in self.array_pointer_function_names: print ' GLint __array_buffer = 0;' print ' __glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);' @@ -134,23 +156,34 @@ class GlTracer(Tracer): print ' return;' print ' }' + # ... to the draw calls if function.name in self.draw_function_names: + print ' if (__need_user_arrays()) {' arg_names = ', '.join([arg.name for arg in function.args[1:]]) - print ' __trace_arrays(__%s_maxindex(%s));' % (function.name, arg_names) + print ' GLuint maxindex = __%s_maxindex(%s);' % (function.name, arg_names) + print ' __trace_user_arrays(maxindex);' + print ' }' Tracer.trace_function_impl_body(self, function) def dump_arg_instance(self, function, arg): if function.name in self.draw_function_names and arg.name == 'indices': - print ' Trace::LiteralBlob((const void *)%s, count*__gl_type_size(type));' % (arg.name) - else: - dump_instance(arg.type, arg.name) + print ' GLint __element_array_buffer = 0;' + print ' __glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &__element_array_buffer);' + print ' if (!__element_array_buffer) {' + print ' Trace::LiteralBlob((const void *)%s, count*__gl_type_size(type));' % (arg.name) + print ' } else {' + print ' Trace::LiteralOpaque((const void *)%s);' % (arg.name) + print ' }' + return + + Tracer.dump_arg_instance(self, function, arg) def state_tracker_impl(self, api): # A simple state tracker to track the pointer values # update the state - print 'static void __trace_arrays(GLsizei maxindex)' + print 'static void __trace_user_arrays(GLuint maxindex)' print '{' for camelcase_name, uppercase_name in self.arrays: function_name = 'gl%sPointer' % camelcase_name