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 retrace_function(self, function):
44 Retracer.retrace_function(self, function)
46 def call_function(self, function):
47 if function.name in ("glDrawArrays", "glDrawElements", "glDrawRangeElements", "glMultiDrawElements"):
48 print ' GLint __array_buffer = 0;'
49 print ' glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);'
50 print ' if (!__array_buffer) {'
51 self.fail_function(function)
54 if function.name == "glEnd":
55 print ' insideGlBeginEnd = false;'
56 Retracer.call_function(self, function)
57 if function.name == "glBegin":
58 print ' insideGlBeginEnd = true;'
60 # glGetError is not allowed inside glBegin/glEnd
61 print ' checkGlError();'
64 def extract_arg(self, function, arg, arg_type, lvalue, rvalue):
73 "glSecondaryColorPointer",
74 "glVertexAttribPointer",
75 ] and arg.name == 'pointer':
76 self.extract_pointer(function, arg, arg_type, lvalue, rvalue)
78 Retracer.extract_arg(self, function, arg, arg_type, lvalue, rvalue)
80 def extract_pointer(self, function, arg, arg_type, lvalue, rvalue):
81 print ' if (dynamic_cast<Trace::Null *>(&%s)) {' % rvalue
82 print ' %s = 0;' % (lvalue)
84 print ' %s = (%s)(uintptr_t)(%s);' % (lvalue, arg_type, rvalue)
88 if __name__ == '__main__':
90 print '#include <string.h>'
91 print '#include <iostream>'
94 print '#include <windows.h>'
97 print '#include <GL/glew.h>'
98 print '#include <GL/glut.h>'
100 print 'static bool double_buffer = false;'
101 print 'static bool insideGlBeginEnd = false;'
106 if (insideGlBeginEnd) {
110 GLenum error = glGetError();
111 if (error == GL_NO_ERROR) {
115 std::cerr << "warning: glGetError() = ";
117 case GL_INVALID_ENUM:
118 std::cerr << "GL_INVALID_ENUM";
120 case GL_INVALID_VALUE:
121 std::cerr << "GL_INVALID_VALUE";
123 case GL_INVALID_OPERATION:
124 std::cerr << "GL_INVALID_OPERATION";
126 case GL_STACK_OVERFLOW:
127 std::cerr << "GL_STACK_OVERFLOW";
129 case GL_STACK_UNDERFLOW:
130 std::cerr << "GL_STACK_UNDERFLOW";
132 case GL_OUT_OF_MEMORY:
133 std::cerr << "GL_OUT_OF_MEMORY";
135 case GL_INVALID_FRAMEBUFFER_OPERATION:
136 std::cerr << "GL_INVALID_FRAMEBUFFER_OPERATION";
138 case GL_TABLE_TOO_LARGE:
139 std::cerr << "GL_TABLE_TOO_LARGE";
149 retracer = GlRetracer()
150 retracer.retrace_api(glapi.glapi)
153 static Trace::Parser parser;
155 static void display(void) {
158 while ((call = parser.parse_call())) {
159 if (call->name() == "glFlush") {
164 if (!retrace_call(*call)) {
165 if (call->name() == "glXSwapBuffers" ||
166 call->name() == "wglSwapBuffers") {
180 static void idle(void) {
184 int main(int argc, char **argv)
188 for (i = 1; i < argc; ++i) {
189 const char *arg = argv[i];
195 if (!strcmp(arg, "--")) {
198 else if (!strcmp(arg, "-db")) {
199 double_buffer = true;
200 } else if (!strcmp(arg, "-v")) {
203 std::cerr << "error: unknown option " << arg << "\\n";
208 glutInit(&argc, argv);
209 glutInitWindowPosition(0, 0);
210 glutInitWindowSize(800, 600);
211 glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | (double_buffer ? GLUT_DOUBLE : GLUT_SINGLE));
212 glutCreateWindow(argv[0]);
215 glutDisplayFunc(&display);
218 for (GLuint h = 0; h < 1024; ++h) {
222 for ( ; i < argc; ++i) {
223 if (parser.open(argv[i])) {