Retrace glDrawElements.
authorJosé Fonseca <jfonseca@vmware.com>
Tue, 30 Nov 2010 12:09:12 +0000 (12:09 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Tue, 30 Nov 2010 12:09:12 +0000 (12:09 +0000)
glretrace.py

index fde4f0f..2b41f1d 100644 (file)
@@ -34,14 +34,52 @@ class GlRetracer(Retracer):
     def retrace_function(self, function):
         Retracer.retrace_function(self, function)
 
+    draw_array_function_names = set([
+        "glDrawArrays",
+        "glDrawArraysEXT",
+        "glDrawArraysIndirect",
+        "glDrawArraysInstanced",
+        "glDrawArraysInstancedARB",
+        "glDrawArraysInstancedEXT",
+        "glDrawMeshArraysSUN",
+        "glMultiDrawArrays",
+        "glMultiDrawArraysEXT",
+        "glMultiModeDrawArraysIBM",
+    ])
+
+    draw_elements_function_names = set([
+        "glDrawElements",
+        "glDrawElementsBaseVertex",
+        "glDrawElementsIndirect",
+        "glDrawElementsInstanced",
+        "glDrawElementsInstancedARB",
+        "glDrawElementsInstancedBaseVertex",
+        "glDrawElementsInstancedEXT",
+        "glDrawRangeElements",
+        "glDrawRangeElementsBaseVertex",
+        "glDrawRangeElementsEXT",
+        "glMultiDrawElements",
+        "glMultiDrawElementsBaseVertex",
+        "glMultiDrawElementsEXT",
+        "glMultiModeDrawElementsIBM",
+    ])
+
     def call_function(self, function):
-        if function.name in ("glDrawArrays", "glDrawElements", "glDrawRangeElements", "glMultiDrawElements"):
+        if (function.name in self.draw_array_function_names or 
+            function.name in self.draw_elements_function_names):
             print '    GLint __array_buffer = 0;'
             print '    glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);'
             print '    if (!__array_buffer) {'
             self.fail_function(function)
             print '    }'
 
+        if function.name in self.draw_elements_function_names:
+            print '    GLint __element_array_buffer = 0;'
+            print '    glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &__element_array_buffer);'
+            print '    if (!__element_array_buffer) {'
+            self.fail_function(function)
+            print '    }'
+
         if function.name == "glViewport":
             print '    if (x + width > __window_width) {'
             print '        __window_width = x + width;'
@@ -63,31 +101,33 @@ class GlRetracer(Retracer):
             # glGetError is not allowed inside glBegin/glEnd
             print '    checkGlError();'
 
+    pointer_function_names = set([
+        "glColorPointer",
+        "glColorPointerEXT",
+        "glEdgeFlagPointer",
+        "glEdgeFlagPointerEXT",
+        "glFogCoordPointer",
+        "glFogCoordPointerEXT",
+        "glIndexPointer",
+        "glIndexPointerEXT",
+        "glMatrixIndexPointerARB",
+        "glNormalPointer",
+        "glNormalPointerEXT",
+        "glSecondaryColorPointer",
+        "glSecondaryColorPointerEXT",
+        "glTexCoordPointer",
+        "glTexCoordPointerEXT",
+        "glVertexAttribLPointer",
+        "glVertexAttribPointer",
+        "glVertexAttribPointerARB",
+        "glVertexAttribPointerNV",
+        "glVertexPointer",
+        "glVertexPointerEXT",
+    ])
 
     def extract_arg(self, function, arg, arg_type, lvalue, rvalue):
-        if function.name in [
-            "glColorPointer",
-            "glColorPointerEXT",
-            "glEdgeFlagPointer",
-            "glEdgeFlagPointerEXT",
-            "glFogCoordPointer",
-            "glFogCoordPointerEXT",
-            "glIndexPointer",
-            "glIndexPointerEXT",
-            "glMatrixIndexPointerARB",
-            "glNormalPointer",
-            "glNormalPointerEXT",
-            "glSecondaryColorPointer",
-            "glSecondaryColorPointerEXT",
-            "glTexCoordPointer",
-            "glTexCoordPointerEXT",
-            "glVertexAttribLPointer",
-            "glVertexAttribPointer",
-            "glVertexAttribPointerARB",
-            "glVertexAttribPointerNV",
-            "glVertexPointer",
-            "glVertexPointerEXT",
-        ] and arg.name == 'pointer':
+        if (function.name in self.pointer_function_names and arg.name == 'pointer' or
+            function.name in self.draw_elements_function_names and arg.name == 'indices'):
             self.extract_pointer(function, arg, arg_type, lvalue, rvalue)
         else:
             Retracer.extract_arg(self, function, arg, arg_type, lvalue, rvalue)