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 extract_arg(self, function, arg, arg_type, lvalue, rvalue):
43 "glSecondaryColorPointer",
44 "glVertexAttribPointer",
45 ] and arg.name == 'pointer':
46 self.extract_pointer(function, arg, arg_type, lvalue, rvalue)
48 Retracer.extract_arg(self, function, arg, arg_type, lvalue, rvalue)
50 def extract_pointer(self, function, arg, arg_type, lvalue, rvalue):
51 print ' if (dynamic_cast<Trace::Null *>(&%s)) {' % rvalue
52 print ' %s = 0;' % (lvalue)
54 print ' %s = (%s)(uintptr_t)(%s);' % (lvalue, arg_type, rvalue)
58 if __name__ == '__main__':
60 print '#include <stdlib.h>'
61 print '#include <string.h>'
64 print '#include <windows.h>'
67 print '#include <GL/glew.h>'
68 print '#include <GL/glut.h>'
70 print 'static bool double_buffer = false;'
73 retracer = GlRetracer()
74 retracer.retrace_api(glapi.glapi)
79 static bool insideGlBeginEnd;
81 static void display(void) {
84 while ((call = parser.parse_call())) {
85 if (call->name == "glFlush") {
90 if (call->name == "glXSwapBuffers" ||
91 call->name == "wglSwapBuffers") {
101 if (call->name == "glBegin") {
102 insideGlBeginEnd = true;
105 if (call->name == "glEnd") {
106 insideGlBeginEnd = false;
109 if (!insideGlBeginEnd) {
110 GLenum error = glGetError();
111 if (error != GL_NO_ERROR) {
112 std::cerr << "warning: glGetError() = ";
114 case GL_INVALID_ENUM:
115 std::cerr << "GL_INVALID_ENUM";
117 case GL_INVALID_VALUE:
118 std::cerr << "GL_INVALID_VALUE";
120 case GL_INVALID_OPERATION:
121 std::cerr << "GL_INVALID_OPERATION";
123 case GL_STACK_OVERFLOW:
124 std::cerr << "GL_STACK_OVERFLOW";
126 case GL_STACK_UNDERFLOW:
127 std::cerr << "GL_STACK_UNDERFLOW";
129 case GL_OUT_OF_MEMORY:
130 std::cerr << "GL_OUT_OF_MEMORY";
132 case GL_INVALID_FRAMEBUFFER_OPERATION:
133 std::cerr << "GL_INVALID_FRAMEBUFFER_OPERATION";
135 case GL_TABLE_TOO_LARGE:
136 std::cerr << "GL_TABLE_TOO_LARGE";
151 static void idle(void) {
155 int main(int argc, char **argv)
159 for (i = 1; i < argc; ++i) {
160 const char *arg = argv[i];
166 if (!strcmp(arg, "--")) {
169 else if (!strcmp(arg, "-db")) {
170 double_buffer = true;
171 } else if (!strcmp(arg, "-v")) {
174 std::cerr << "error: unknown option " << arg << "\\n";
179 glutInit(&argc, argv);
180 glutInitWindowPosition(0, 0);
181 glutInitWindowSize(800, 600);
182 glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | (double_buffer ? GLUT_DOUBLE : GLUT_SINGLE));
183 glutCreateWindow(argv[0]);
186 glutDisplayFunc(&display);
189 for (GLuint h = 0; h < 1024; ++h) {
193 for ( ; i < argc; ++i) {
194 if (parser.open(argv[i])) {