]> git.cworth.org Git - apitrace/blob - glretrace.py
Show info log when glCompileShader/glLinkProgram fails.
[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         "glVertexAttribIPointer",
65         "glVertexAttribIPointerEXT",
66         "glVertexAttribLPointer",
67         "glVertexAttribLPointerEXT",
68         
69         #"glMatrixIndexPointerARB",
70     ))
71
72     draw_array_function_names = set([
73         "glDrawArrays",
74         "glDrawArraysEXT",
75         "glDrawArraysIndirect",
76         "glDrawArraysInstanced",
77         "glDrawArraysInstancedARB",
78         "glDrawArraysInstancedEXT",
79         "glDrawMeshArraysSUN",
80         "glMultiDrawArrays",
81         "glMultiDrawArraysEXT",
82         "glMultiModeDrawArraysIBM",
83     ])
84
85     draw_elements_function_names = set([
86         "glDrawElements",
87         "glDrawElementsBaseVertex",
88         "glDrawElementsIndirect",
89         "glDrawElementsInstanced",
90         "glDrawElementsInstancedARB",
91         "glDrawElementsInstancedBaseVertex",
92         "glDrawElementsInstancedEXT",
93         "glDrawRangeElements",
94         "glDrawRangeElementsBaseVertex",
95         "glDrawRangeElementsEXT",
96         #"glMultiDrawElements",
97         #"glMultiDrawElementsBaseVertex",
98         #"glMultiDrawElementsEXT",
99         #"glMultiModeDrawElementsIBM",
100     ])
101
102     def retrace_function_body(self, function):
103         is_array_pointer = function.name in self.array_pointer_function_names
104         is_draw_array = function.name in self.draw_array_function_names
105         is_draw_elements = function.name in self.draw_elements_function_names
106
107         if is_array_pointer or is_draw_array or is_draw_elements:
108             print '    if (glretrace::parser.version < 1) {'
109
110             if is_array_pointer or is_draw_array:
111                 print '        GLint __array_buffer = 0;'
112                 print '        glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);'
113                 print '        if (!__array_buffer) {'
114                 self.fail_function(function)
115                 print '        }'
116
117             if is_draw_elements:
118                 print '        GLint __element_array_buffer = 0;'
119                 print '        glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &__element_array_buffer);'
120                 print '        if (!__element_array_buffer) {'
121                 self.fail_function(function)
122                 print '        }'
123             
124             print '    }'
125
126         Retracer.retrace_function_body(self, function)
127
128     def call_function(self, function):
129         if function.name == "glViewport":
130             print '    bool reshape_window = false;'
131             print '    if (x + width > glretrace::window_width) {'
132             print '        glretrace::window_width = x + width;'
133             print '        reshape_window = true;'
134             print '    }'
135             print '    if (y + height > glretrace::window_height) {'
136             print '        glretrace::window_height = y + height;'
137             print '        reshape_window = true;'
138             print '    }'
139             print '    if (reshape_window) {'
140             print '        // XXX: does not always work'
141             print '        glretrace::drawable->resize(glretrace::window_width, glretrace::window_height);'
142             print '        reshape_window = false;'
143             print '    }'
144
145         if function.name == "glEnd":
146             print '    glretrace::insideGlBeginEnd = false;'
147         
148         Retracer.call_function(self, function)
149
150         if function.name == "glBegin":
151             print '    glretrace::insideGlBeginEnd = true;'
152         elif function.name.startswith('gl'):
153             # glGetError is not allowed inside glBegin/glEnd
154             print '    glretrace::checkGlError(call);'
155
156         if function.name == 'glCompileShader':
157             print r'    GLint compile_status = 0;'
158             print r'    glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_status);'
159             print r'    if (!compile_status) {'
160             print r'         GLint info_log_length = 0;'
161             print r'         glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_log_length);'
162             print r'         GLchar *infoLog = new GLchar[info_log_length];'
163             print r'         glGetShaderInfoLog(shader, info_log_length, NULL, infoLog);'
164             print r'         std::cerr << call.no << ": warning: " << infoLog << "\n";'
165             print r'         delete [] infoLog;'
166             print r'    }'
167
168         if function.name == 'glLinkProgram':
169             print r'    GLint link_status = 0;'
170             print r'    glGetProgramiv(program, GL_LINK_STATUS, &link_status);'
171             print r'    if (!link_status) {'
172             print r'         GLint info_log_length = 0;'
173             print r'         glGetProgramiv(program, GL_INFO_LOG_LENGTH, &info_log_length);'
174             print r'         GLchar *infoLog = new GLchar[info_log_length];'
175             print r'         glGetProgramInfoLog(program, info_log_length, NULL, infoLog);'
176             print r'         std::cerr << call.no << ": warning: " << infoLog << "\n";'
177             print r'         delete [] infoLog;'
178             print r'    }'
179
180         if function.name == 'glFlush':
181             print '    if (!glretrace::double_buffer) {'
182             print '        glretrace::frame_complete(call.no);'
183             print '    }'
184
185     def extract_arg(self, function, arg, arg_type, lvalue, rvalue):
186         if function.name in self.array_pointer_function_names and arg.name == 'pointer':
187             print '    %s = static_cast<%s>(%s.blob());' % (lvalue, arg_type, rvalue)
188             return
189
190         if function.name in self.draw_elements_function_names and arg.name == 'indices':
191             print '    %s = %s.blob();' % (lvalue, rvalue)
192             return
193
194         if arg.type is glapi.GLlocation \
195            and 'program' not in [arg.name for arg in function.args]:
196             print '    GLint program = -1;'
197             print '    glGetIntegerv(GL_CURRENT_PROGRAM, &program);'
198         
199         if arg.type is glapi.GLlocationARB \
200            and 'programObj' not in [arg.name for arg in function.args]:
201             print '    GLhandleARB programObj = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);'
202
203         Retracer.extract_arg(self, function, arg, arg_type, lvalue, rvalue)
204
205         # Don't try to use more samples than the implementation supports
206         if arg.name == 'samples':
207             assert arg.type is glapi.GLsizei
208             print '    GLint max_samples = 0;'
209             print '    glGetIntegerv(GL_MAX_SAMPLES, &max_samples);'
210             print '    if (samples > max_samples) {'
211             print '        samples = max_samples;'
212             print '    }'
213
214
215 if __name__ == '__main__':
216     print r'''
217 #include <string.h>
218
219 #include "glproc.hpp"
220 #include "glretrace.hpp"
221
222
223 '''
224     api = glapi.glapi
225     api.add_function(glapi.memcpy)
226     retracer = GlRetracer()
227     retracer.retrace_api(api)