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 call_function(self, function):
44 if function.name in ("glDrawArrays", "glDrawElements", "glDrawRangeElements", "glMultiDrawElements"):
45 print ' GLint __array_buffer = 0;'
46 print ' glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);'
47 print ' if (!__array_buffer) {'
48 self.fail_function(function)
51 Retracer.call_function(self, function)
53 def extract_arg(self, function, arg, arg_type, lvalue, rvalue):
62 "glSecondaryColorPointer",
63 "glVertexAttribPointer",
64 ] and arg.name == 'pointer':
65 self.extract_pointer(function, arg, arg_type, lvalue, rvalue)
67 Retracer.extract_arg(self, function, arg, arg_type, lvalue, rvalue)
69 def extract_pointer(self, function, arg, arg_type, lvalue, rvalue):
70 print ' if (dynamic_cast<Trace::Null *>(&%s)) {' % rvalue
71 print ' %s = 0;' % (lvalue)
73 print ' %s = (%s)(uintptr_t)(%s);' % (lvalue, arg_type, rvalue)
77 if __name__ == '__main__':
79 print '#include <stdlib.h>'
80 print '#include <string.h>'
83 print '#include <windows.h>'
86 print '#include <GL/glew.h>'
87 print '#include <GL/glut.h>'
89 print 'static bool double_buffer = false;'
92 retracer = GlRetracer()
93 retracer.retrace_api(glapi.glapi)
98 static bool insideGlBeginEnd;
100 static void display(void) {
103 while ((call = parser.parse_call())) {
104 if (call->name == "glFlush") {
109 if (call->name == "glXSwapBuffers" ||
110 call->name == "wglSwapBuffers") {
120 if (call->name == "glBegin") {
121 insideGlBeginEnd = true;
124 if (call->name == "glEnd") {
125 insideGlBeginEnd = false;
128 if (!insideGlBeginEnd) {
129 GLenum error = glGetError();
130 if (error != GL_NO_ERROR) {
131 std::cerr << "warning: glGetError() = ";
133 case GL_INVALID_ENUM:
134 std::cerr << "GL_INVALID_ENUM";
136 case GL_INVALID_VALUE:
137 std::cerr << "GL_INVALID_VALUE";
139 case GL_INVALID_OPERATION:
140 std::cerr << "GL_INVALID_OPERATION";
142 case GL_STACK_OVERFLOW:
143 std::cerr << "GL_STACK_OVERFLOW";
145 case GL_STACK_UNDERFLOW:
146 std::cerr << "GL_STACK_UNDERFLOW";
148 case GL_OUT_OF_MEMORY:
149 std::cerr << "GL_OUT_OF_MEMORY";
151 case GL_INVALID_FRAMEBUFFER_OPERATION:
152 std::cerr << "GL_INVALID_FRAMEBUFFER_OPERATION";
154 case GL_TABLE_TOO_LARGE:
155 std::cerr << "GL_TABLE_TOO_LARGE";
170 static void idle(void) {
174 int main(int argc, char **argv)
178 for (i = 1; i < argc; ++i) {
179 const char *arg = argv[i];
185 if (!strcmp(arg, "--")) {
188 else if (!strcmp(arg, "-db")) {
189 double_buffer = true;
190 } else if (!strcmp(arg, "-v")) {
193 std::cerr << "error: unknown option " << arg << "\\n";
198 glutInit(&argc, argv);
199 glutInitWindowPosition(0, 0);
200 glutInitWindowSize(800, 600);
201 glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | (double_buffer ? GLUT_DOUBLE : GLUT_SINGLE));
202 glutCreateWindow(argv[0]);
205 glutDisplayFunc(&display);
208 for (GLuint h = 0; h < 1024; ++h) {
212 for ( ; i < argc; ++i) {
213 if (parser.open(argv[i])) {