##########################################################################/
-import base
-from glx import libgl
-
-
-def is_arg_supported(arg_type):
- if isinstance(arg_type, (base.Literal, base._String, base.Enum)):
- return True
- if isinstance(arg_type, (base.Alias, base.Flags)):
- return is_arg_supported(arg_type.type)
- return False
-
-
-def is_function_supported(function):
- for arg_type, arg_name in function.args:
- if not is_arg_supported(arg_type):
- return False
- return True
-
-
-class ValueExtractor(base.Visitor):
-
- def visit_literal(self, type, lvalue, rvalue):
- #print ' %s = static_cast<%s>(Trace::as%s(%s));' % (lvalue, type, type.format, rvalue)
- print ' %s = Trace::as%s(%s);' % (lvalue, type.format, rvalue)
-
- def visit_alias(self, type, lvalue, rvalue):
- self.visit(type.type, lvalue, rvalue)
-
- def visit_enum(self, type, lvalue, rvalue):
- #print ' %s = static_cast<%s>(Trace::as%s(%s));' % (lvalue, type, 'SInt', rvalue)
- print ' %s = Trace::as%s(%s);' % (lvalue, 'SInt', rvalue)
-
- def visit_bitmask(self, type, lvalue, rvalue):
- self.visit(type.type, lvalue, rvalue)
-
-
-
-def retrace_function(function):
- print 'static void retrace_%s(Trace::Call &call) {' % function.name
- if not function.name.startswith('glX'):
- success = True
- for arg_type, arg_name in function.args:
- print ' %s %s;' % (arg_type, arg_name)
- for arg_type, arg_name in function.args:
- rvalue = 'call.arg("%s")' % (arg_name,)
- lvalue = arg_name
- try:
- ValueExtractor().visit(arg_type, lvalue, rvalue)
- except NotImplementedError:
- success = False
- print ' %s = 0; // FIXME' % arg_name
- if not success:
- print ' std::cerr << "warning: unsupported call %s\\n";' % function.name
- print ' return;'
- arg_names = ", ".join([arg_name for arg_type, arg_name in function.args])
- print ' %s(%s);' % (function.name, arg_names)
- print '}'
- print
+"""GL retracer generator."""
+
+
+import stdapi
+import glapi
+from retrace import Retracer
+
+
+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",
+ "glVertexAttribLPointerEXT",
+
+ #"glMatrixIndexPointerARB",
+ ))
+
+ 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 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 (glretrace::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 ' }'
+
+ Retracer.retrace_function_body(self, function)
+
+ def call_function(self, function):
+ if function.name == "glViewport":
+ print ' bool reshape_window = false;'
+ print ' if (x + width > glretrace::window_width) {'
+ print ' glretrace::window_width = x + width;'
+ print ' reshape_window = true;'
+ print ' }'
+ print ' if (y + height > glretrace::window_height) {'
+ print ' glretrace::window_height = y + height;'
+ print ' reshape_window = true;'
+ print ' }'
+ print ' if (reshape_window) {'
+ print ' // XXX: does not always work'
+ print ' glretrace::drawable->resize(glretrace::window_width, glretrace::window_height);'
+ print ' reshape_window = false;'
+ print ' }'
+
+ if function.name == "glEnd":
+ print ' glretrace::insideGlBeginEnd = false;'
+
+ Retracer.call_function(self, function)
+
+ if function.name == "glBegin":
+ print ' glretrace::insideGlBeginEnd = true;'
+ else:
+ # glGetError is not allowed inside glBegin/glEnd
+ print ' glretrace::checkGlError();'
+
+ def extract_arg(self, function, arg, arg_type, lvalue, rvalue):
+ if function.name in self.array_pointer_function_names and arg.name == 'pointer':
+ print ' %s = %s.blob();' % (lvalue, rvalue)
+ return
+
+ if function.name in self.draw_elements_function_names and arg.name == 'indices':
+ print ' %s = %s.blob();' % (lvalue, rvalue)
+ return
+
+ if function.name.startswith('glUniform') and function.args[0].name == arg.name == 'location':
+ print ' GLint program = -1;'
+ print ' glGetIntegerv(GL_CURRENT_PROGRAM, &program);'
+
+ Retracer.extract_arg(self, function, arg, arg_type, lvalue, rvalue)
if __name__ == '__main__':
- print
- print '#include <stdlib.h>'
- print '#include <string.h>'
- print '#include <GL/glew.h>'
- print '#include <GL/glut.h>'
- print
- print '#include "trace_parser.hpp"'
- print
-
- functions = filter(is_function_supported, libgl.functions)
-
- for function in libgl.functions:
- retrace_function(function)
-
- print 'static bool retrace_call(Trace::Call &call) {'
- for function in libgl.functions:
- print ' if (call.name == "%s") {' % function.name
- print ' retrace_%s(call);' % function.name
- print ' return true;'
- print ' }'
- print ' std::cerr << "warning: unsupported call " << call.name << "\\n";'
- print ' return false;'
- print '}'
- print '''
-
-class Retracer : public Trace::Parser
-{
- void handle_call(Trace::Call &call) {
- std::cout << call;
- std::cout.flush();
- retrace_call(call);
- }
-};
-
-int main(int argc, char **argv)
-{
- glutInit(&argc, argv);
- glutInitWindowPosition( 0, 0 );
- glutInitWindowSize( 800, 600 );
- glutInitDisplayMode( GLUT_DEPTH | GLUT_RGB | GLUT_SINGLE );
- glutCreateWindow(argv[0]);
- glewInit();
- for (int i = 1; i < argc; ++i) {
- Retracer p;
- p.parse(argv[i]);
- glutMainLoop();
- }
- return 0;
-}
-
-'''
+ print r'''
+#include "glproc.hpp"
+#include "glretrace.hpp"
+
+
+'''
+ api = glapi.glapi
+ retracer = GlRetracer()
+ retracer.retrace_api(glapi.glapi)