]> git.cworth.org Git - apitrace/blob - glretrace.py
Allow to choose double buffer visual.
[apitrace] / glretrace.py
1 ##########################################################################
2 #
3 # Copyright 2010 VMware, Inc.
4 # All Rights Reserved.
5 #
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:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
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
22 # THE SOFTWARE.
23 #
24 ##########################################################################/
25
26
27 import stdapi
28 import glapi
29 import retrace
30
31
32 class GlRetracer(retrace.Retracer):
33
34     pass
35
36
37 if __name__ == '__main__':
38     print
39     print '#include <stdlib.h>'
40     print '#include <string.h>'
41     print
42     print '#ifdef WIN32'
43     print '#include <windows.h>'
44     print '#endif'
45     print
46     print '#include <GL/glew.h>'
47     print '#include <GL/glut.h>'
48     print
49     print 'static bool double_buffer = false;'
50     print
51     api = glapi.glapi
52     retracer = GlRetracer()
53     retracer.retrace_api(glapi.glapi)
54     print '''
55
56 Trace::Parser parser;
57
58 static bool insideGlBeginEnd;
59
60 static void display(void) {
61    Trace::Call *call;
62
63    while ((call = parser.parse_call())) {
64       if (call->name == "glFlush") {
65          glFlush();
66          return;
67       }
68       
69       if (call->name == "glXSwapBuffers" ||
70           call->name == "wglSwapBuffers") {
71          if (double_buffer)
72             glutSwapBuffers();
73          else
74             glFlush();
75          return;
76       }
77       
78       retrace_call(*call);
79
80       if (call->name == "glBegin") {
81          insideGlBeginEnd = true;
82       }
83       
84       if (call->name == "glEnd") {
85          insideGlBeginEnd = false;
86       }
87
88       if (!insideGlBeginEnd) {
89          GLenum error = glGetError();
90          if (error != GL_NO_ERROR) {
91             std::cerr << "warning: glGetError() = ";
92             switch (error) {
93             case GL_INVALID_ENUM:
94                std::cerr << "GL_INVALID_ENUM";
95                break;
96             case GL_INVALID_VALUE:
97                std::cerr << "GL_INVALID_VALUE";
98                break;
99             case GL_INVALID_OPERATION:
100                std::cerr << "GL_INVALID_OPERATION";
101                break;
102             case GL_STACK_OVERFLOW:
103                std::cerr << "GL_STACK_OVERFLOW";
104                break;
105             case GL_STACK_UNDERFLOW:
106                std::cerr << "GL_STACK_UNDERFLOW";
107                break;
108             case GL_OUT_OF_MEMORY:
109                std::cerr << "GL_OUT_OF_MEMORY";
110                break;
111             case GL_INVALID_FRAMEBUFFER_OPERATION:
112                std::cerr << "GL_INVALID_FRAMEBUFFER_OPERATION";
113                break;
114             case GL_TABLE_TOO_LARGE:
115                std::cerr << "GL_TABLE_TOO_LARGE";
116                break;
117             default:
118                std::cerr << error;
119                break;
120             }
121             std::cerr << "\\n";
122          }
123       }
124    }
125
126    glFlush();
127    glutIdleFunc(NULL);
128 }
129
130 static void idle(void) {
131    glutPostRedisplay();
132 }
133
134 int main(int argc, char **argv)
135 {
136
137    int i;
138    for (i = 1; i < argc; ++i) {
139       const char *arg = argv[i];
140
141       if (arg[0] != '-') {
142          break;
143       }
144
145       if (!strcmp(arg, "--")) {
146          break;
147       }
148       else if (!strcmp(arg, "-db")) {
149          double_buffer = true;
150       } else if (!strcmp(arg, "-v")) {
151          ++verbosity;
152       } else {
153          std::cerr << "error: unknown option " << arg << "\\n";
154          return 1;
155       }
156    }
157
158    glutInit(&argc, argv);
159    glutInitWindowPosition(0, 0);
160    glutInitWindowSize(800, 600);
161    glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | (double_buffer ? GLUT_DOUBLE : GLUT_SINGLE));
162    glutCreateWindow(argv[0]);
163    glewInit();
164
165    glutDisplayFunc(&display);
166    glutIdleFunc(&idle);
167
168    for (GLuint h = 0; h < 1024; ++h) {
169       __list_map[h] = h;
170    }
171
172    for ( ; i < argc; ++i) {
173       if (parser.open(argv[i])) {
174          glutMainLoop();
175          parser.close();
176       }
177    }
178
179    return 0;
180 }
181
182 '''