From 6221297f9c095be9a204adb4d1fd201a5004cc32 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 23 Mar 2011 13:22:55 +0000 Subject: [PATCH] Handle older traces gracefully. --- glretrace.py | 70 +++++++++++++++++++++++++++++++++++++++++++++--------------- retrace.py | 7 ++++-- 2 files changed, 58 insertions(+), 19 deletions(-) diff --git a/glretrace.py b/glretrace.py index 63b21fe..aaf5660 100644 --- a/glretrace.py +++ b/glretrace.py @@ -37,6 +37,35 @@ class GlRetracer(Retracer): def retrace_function(self, function): Retracer.retrace_function(self, function) + array_pointer_function_names = set(( + "glVertexPointer", + "glNormalPointer", + "glColorPointer", + "glIndexPointer", + "glTexCoordPointer", + "glEdgeFlagPointer", + "glFogCoordPointer", + "glSecondaryColorPointer", + + "glInterleavedArrays", + + #"glVertexPointerEXT", + #"glNormalPointerEXT", + #"glColorPointerEXT", + #"glIndexPointerEXT", + #"glTexCoordPointerEXT", + #"glEdgeFlagPointerEXT", + #"glFogCoordPointerEXT", + #"glSecondaryColorPointerEXT", + + #"glVertexAttribPointer", + #"glVertexAttribPointerARB", + #"glVertexAttribPointerNV", + #"glVertexAttribLPointer", + + #"glMatrixIndexPointerARB", + )) + draw_array_function_names = set([ "glDrawArrays", "glDrawArraysEXT", @@ -67,26 +96,33 @@ class GlRetracer(Retracer): #"glMultiModeDrawElementsIBM", ]) - def call_function(self, function): - print ' if (Trace::Parser::version < 1) {' - - 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) + def retrace_function_body(self, function): + is_array_pointer = function.name in self.array_pointer_function_names + is_draw_array = function.name in self.draw_array_function_names + is_draw_elements = function.name in self.draw_elements_function_names + + if is_array_pointer or is_draw_array or is_draw_elements: + print ' if (Trace::Parser::version < 1) {' + + if is_array_pointer or is_draw_array: + print ' GLint __array_buffer = 0;' + print ' glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);' + print ' if (!__array_buffer) {' + self.fail_function(function) + print ' }' + + if is_draw_elements: + 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 ' }' + 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 ' }' - - print ' }' + Retracer.retrace_function_body(self, function) + def call_function(self, function): if function.name == "glViewport": print ' if (x + width > __window_width) {' print ' __window_width = x + width;' diff --git a/retrace.py b/retrace.py index c68179b..ad8c844 100644 --- a/retrace.py +++ b/retrace.py @@ -174,6 +174,11 @@ class Retracer: def retrace_function(self, function): print 'static void retrace_%s(Trace::Call &call) {' % function.name + self.retrace_function_body(function) + print '}' + print + + def retrace_function_body(self, function): success = True for arg in function.args: arg_type = ConstRemover().visit(arg.type) @@ -205,8 +210,6 @@ class Retracer: ValueWrapper().visit(function.type, lvalue, rvalue) except NotImplementedError: print ' // FIXME: result' - print '}' - print def fail_function(self, function): print ' if (verbosity >= 0)' -- 2.7.4