]> git.cworth.org Git - apitrace/blob - glretrace.py
Accept zero valued bitmasks.
[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 """GL retracer generator."""
28
29
30 import stdapi
31 import glapi
32 from retrace import Retracer
33
34
35 class GlRetracer(Retracer):
36
37     def retrace_function(self, function):
38         Retracer.retrace_function(self, function)
39
40     array_pointer_function_names = set((
41         "glVertexPointer",
42         "glNormalPointer",
43         "glColorPointer",
44         "glIndexPointer",
45         "glTexCoordPointer",
46         "glEdgeFlagPointer",
47         "glFogCoordPointer",
48         "glSecondaryColorPointer",
49
50         "glInterleavedArrays",
51
52         #"glVertexPointerEXT",
53         #"glNormalPointerEXT",
54         #"glColorPointerEXT",
55         #"glIndexPointerEXT",
56         #"glTexCoordPointerEXT",
57         #"glEdgeFlagPointerEXT",
58         #"glFogCoordPointerEXT",
59         #"glSecondaryColorPointerEXT",
60
61         "glVertexAttribPointer",
62         "glVertexAttribPointerARB",
63         "glVertexAttribPointerNV",
64         "glVertexAttribLPointer",
65         "glVertexAttribLPointerEXT",
66         
67         #"glMatrixIndexPointerARB",
68     ))
69
70     draw_array_function_names = set([
71         "glDrawArrays",
72         "glDrawArraysEXT",
73         "glDrawArraysIndirect",
74         "glDrawArraysInstanced",
75         "glDrawArraysInstancedARB",
76         "glDrawArraysInstancedEXT",
77         "glDrawMeshArraysSUN",
78         "glMultiDrawArrays",
79         "glMultiDrawArraysEXT",
80         "glMultiModeDrawArraysIBM",
81     ])
82
83     draw_elements_function_names = set([
84         "glDrawElements",
85         "glDrawElementsBaseVertex",
86         "glDrawElementsIndirect",
87         "glDrawElementsInstanced",
88         "glDrawElementsInstancedARB",
89         "glDrawElementsInstancedBaseVertex",
90         "glDrawElementsInstancedEXT",
91         "glDrawRangeElements",
92         "glDrawRangeElementsBaseVertex",
93         "glDrawRangeElementsEXT",
94         #"glMultiDrawElements",
95         #"glMultiDrawElementsBaseVertex",
96         #"glMultiDrawElementsEXT",
97         #"glMultiModeDrawElementsIBM",
98     ])
99
100     def retrace_function_body(self, function):
101         is_array_pointer = function.name in self.array_pointer_function_names
102         is_draw_array = function.name in self.draw_array_function_names
103         is_draw_elements = function.name in self.draw_elements_function_names
104
105         if is_array_pointer or is_draw_array or is_draw_elements:
106             print '    if (Trace::Parser::version < 1) {'
107
108             if is_array_pointer or is_draw_array:
109                 print '        GLint __array_buffer = 0;'
110                 print '        glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);'
111                 print '        if (!__array_buffer) {'
112                 self.fail_function(function)
113                 print '        }'
114
115             if is_draw_elements:
116                 print '        GLint __element_array_buffer = 0;'
117                 print '        glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &__element_array_buffer);'
118                 print '        if (!__element_array_buffer) {'
119                 self.fail_function(function)
120                 print '        }'
121             
122             print '    }'
123
124         Retracer.retrace_function_body(self, function)
125
126     def call_function(self, function):
127         if function.name == "glViewport":
128             print '    bool reshape_window = false;'
129             print '    if (x + width > glretrace::window_width) {'
130             print '        glretrace::window_width = x + width;'
131             print '        reshape_window = true;'
132             print '    }'
133             print '    if (y + height > glretrace::window_height) {'
134             print '        glretrace::window_height = y + height;'
135             print '        reshape_window = true;'
136             print '    }'
137             print '    if (reshape_window) {'
138             print '        // XXX: does not always work'
139             print '        glretrace::drawable->resize(glretrace::window_width, glretrace::window_height);'
140             print '        reshape_window = false;'
141             print '    }'
142
143         if function.name == "glEnd":
144             print '    glretrace::insideGlBeginEnd = false;'
145         
146         Retracer.call_function(self, function)
147
148         if function.name == "glBegin":
149             print '    glretrace::insideGlBeginEnd = true;'
150         else:
151             # glGetError is not allowed inside glBegin/glEnd
152             print '    glretrace::checkGlError();'
153
154     def extract_arg(self, function, arg, arg_type, lvalue, rvalue):
155         if function.name in self.array_pointer_function_names and arg.name == 'pointer':
156             print '    %s = %s.blob();' % (lvalue, rvalue)
157             return
158
159         if function.name in self.draw_elements_function_names and arg.name == 'indices':
160             print '    %s = %s.blob();' % (lvalue, rvalue)
161             return
162
163         if function.name.startswith('glUniform') and function.args[0].name == arg.name == 'location':
164             print '    GLint program = -1;'
165             print '    glGetIntegerv(GL_CURRENT_PROGRAM, &program);'
166
167         Retracer.extract_arg(self, function, arg, arg_type, lvalue, rvalue)
168
169
170 if __name__ == '__main__':
171     print r'''
172 #include "glproc.hpp"
173 #include "glretrace.hpp"
174
175
176 '''
177     api = glapi.glapi
178     retracer = GlRetracer()
179     retracer.retrace_api(glapi.glapi)