1 ##########################################################################
3 # Copyright 2010 VMware, Inc.
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 ##########################################################################/
29 from retrace import Retracer
32 class GlRetracer(Retracer):
34 def filter_function(self, function):
35 return function.name not in [
37 "glDeleteBufferRegion",
40 "glBufferRegionEnabled",
43 def extract_arg(self, function, arg, arg_type, lvalue, rvalue):
52 "glSecondaryColorPointer",
53 "glVertexAttribPointer",
54 ] and arg.name == 'pointer':
55 self.extract_pointer(function, arg, arg_type, lvalue, rvalue)
57 Retracer.extract_arg(self, function, arg, arg_type, lvalue, rvalue)
59 def extract_pointer(self, function, arg, arg_type, lvalue, rvalue):
60 print ' if (dynamic_cast<Trace::Null *>(&%s)) {' % rvalue
61 print ' %s = 0;' % (lvalue)
63 print ' %s = (%s)(uintptr_t)(%s);' % (lvalue, arg_type, rvalue)
67 if __name__ == '__main__':
69 print '#include <stdlib.h>'
70 print '#include <string.h>'
73 print '#include <windows.h>'
76 print '#include <GL/glew.h>'
77 print '#include <GL/glut.h>'
79 print 'static bool double_buffer = false;'
82 retracer = GlRetracer()
83 retracer.retrace_api(glapi.glapi)
88 static bool insideGlBeginEnd;
90 static void display(void) {
93 while ((call = parser.parse_call())) {
94 if (call->name == "glFlush") {
99 if (call->name == "glXSwapBuffers" ||
100 call->name == "wglSwapBuffers") {
110 if (call->name == "glBegin") {
111 insideGlBeginEnd = true;
114 if (call->name == "glEnd") {
115 insideGlBeginEnd = false;
118 if (!insideGlBeginEnd) {
119 GLenum error = glGetError();
120 if (error != GL_NO_ERROR) {
121 std::cerr << "warning: glGetError() = ";
123 case GL_INVALID_ENUM:
124 std::cerr << "GL_INVALID_ENUM";
126 case GL_INVALID_VALUE:
127 std::cerr << "GL_INVALID_VALUE";
129 case GL_INVALID_OPERATION:
130 std::cerr << "GL_INVALID_OPERATION";
132 case GL_STACK_OVERFLOW:
133 std::cerr << "GL_STACK_OVERFLOW";
135 case GL_STACK_UNDERFLOW:
136 std::cerr << "GL_STACK_UNDERFLOW";
138 case GL_OUT_OF_MEMORY:
139 std::cerr << "GL_OUT_OF_MEMORY";
141 case GL_INVALID_FRAMEBUFFER_OPERATION:
142 std::cerr << "GL_INVALID_FRAMEBUFFER_OPERATION";
144 case GL_TABLE_TOO_LARGE:
145 std::cerr << "GL_TABLE_TOO_LARGE";
160 static void idle(void) {
164 int main(int argc, char **argv)
168 for (i = 1; i < argc; ++i) {
169 const char *arg = argv[i];
175 if (!strcmp(arg, "--")) {
178 else if (!strcmp(arg, "-db")) {
179 double_buffer = true;
180 } else if (!strcmp(arg, "-v")) {
183 std::cerr << "error: unknown option " << arg << "\\n";
188 glutInit(&argc, argv);
189 glutInitWindowPosition(0, 0);
190 glutInitWindowSize(800, 600);
191 glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | (double_buffer ? GLUT_DOUBLE : GLUT_SINGLE));
192 glutCreateWindow(argv[0]);
195 glutDisplayFunc(&display);
198 for (GLuint h = 0; h < 1024; ++h) {
202 for ( ; i < argc; ++i) {
203 if (parser.open(argv[i])) {