blob: 6c73e697d9128f3947b50d5be712f30916dbd7bb [file] [log] [blame]
José Fonseca7e329022010-11-19 17:05:18 +00001##########################################################################
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
José Fonseca4a826ed2010-11-30 16:58:22 +000027"""GL retracer generator."""
28
29
José Fonseca9d27a542012-04-14 17:22:57 +010030from retrace import Retracer
José Fonsecabd86a222011-09-27 09:21:38 +010031import specs.stdapi as stdapi
32import specs.glapi as glapi
Chia-I Wua8b5b442011-11-07 14:10:46 -070033import specs.glesapi as glesapi
José Fonseca7e329022010-11-19 17:05:18 +000034
35
José Fonsecadacd8dd2010-11-25 17:50:26 +000036class GlRetracer(Retracer):
José Fonsecac9edb832010-11-20 09:03:10 +000037
José Fonseca2741ed82011-10-07 23:36:39 +010038 table_name = 'glretrace::gl_callbacks'
39
José Fonseca54f304a2012-01-14 19:33:08 +000040 def retraceFunction(self, function):
41 Retracer.retraceFunction(self, function)
José Fonseca3d245f42010-11-28 00:08:23 +000042
José Fonseca62212972011-03-23 13:22:55 +000043 array_pointer_function_names = set((
44 "glVertexPointer",
45 "glNormalPointer",
46 "glColorPointer",
47 "glIndexPointer",
48 "glTexCoordPointer",
49 "glEdgeFlagPointer",
50 "glFogCoordPointer",
51 "glSecondaryColorPointer",
52
53 "glInterleavedArrays",
54
José Fonsecaac5285b2011-05-04 11:09:08 +010055 "glVertexPointerEXT",
56 "glNormalPointerEXT",
57 "glColorPointerEXT",
58 "glIndexPointerEXT",
59 "glTexCoordPointerEXT",
60 "glEdgeFlagPointerEXT",
61 "glFogCoordPointerEXT",
62 "glSecondaryColorPointerEXT",
José Fonseca62212972011-03-23 13:22:55 +000063
José Fonseca7f5163e2011-03-31 23:37:26 +010064 "glVertexAttribPointer",
65 "glVertexAttribPointerARB",
66 "glVertexAttribPointerNV",
José Fonsecaac5285b2011-05-04 11:09:08 +010067 "glVertexAttribIPointer",
68 "glVertexAttribIPointerEXT",
José Fonseca7f5163e2011-03-31 23:37:26 +010069 "glVertexAttribLPointer",
70 "glVertexAttribLPointerEXT",
José Fonseca62212972011-03-23 13:22:55 +000071
72 #"glMatrixIndexPointerARB",
73 ))
74
José Fonseca8caf2c82010-11-30 12:09:12 +000075 draw_array_function_names = set([
76 "glDrawArrays",
77 "glDrawArraysEXT",
78 "glDrawArraysIndirect",
79 "glDrawArraysInstanced",
80 "glDrawArraysInstancedARB",
81 "glDrawArraysInstancedEXT",
José Fonsecaff8848b2011-10-09 01:04:17 +010082 "glDrawArraysInstancedBaseInstance",
José Fonseca8caf2c82010-11-30 12:09:12 +000083 "glDrawMeshArraysSUN",
84 "glMultiDrawArrays",
85 "glMultiDrawArraysEXT",
86 "glMultiModeDrawArraysIBM",
87 ])
88
89 draw_elements_function_names = set([
90 "glDrawElements",
91 "glDrawElementsBaseVertex",
92 "glDrawElementsIndirect",
93 "glDrawElementsInstanced",
94 "glDrawElementsInstancedARB",
José Fonseca8caf2c82010-11-30 12:09:12 +000095 "glDrawElementsInstancedEXT",
José Fonsecaff8848b2011-10-09 01:04:17 +010096 "glDrawElementsInstancedBaseVertex",
97 "glDrawElementsInstancedBaseInstance",
98 "glDrawElementsInstancedBaseVertexBaseInstance",
José Fonseca8caf2c82010-11-30 12:09:12 +000099 "glDrawRangeElements",
José Fonseca8caf2c82010-11-30 12:09:12 +0000100 "glDrawRangeElementsEXT",
José Fonsecaff8848b2011-10-09 01:04:17 +0100101 "glDrawRangeElementsBaseVertex",
José Fonsecafd34e4e2011-06-03 19:34:29 +0100102 "glMultiDrawElements",
103 "glMultiDrawElementsBaseVertex",
104 "glMultiDrawElementsEXT",
105 "glMultiModeDrawElementsIBM",
José Fonseca8caf2c82010-11-30 12:09:12 +0000106 ])
107
José Fonseca9b126ea2011-09-15 08:15:33 +0100108 draw_indirect_function_names = set([
109 "glDrawArraysIndirect",
110 "glDrawElementsIndirect",
111 ])
112
José Fonseca920bffd2011-06-02 10:04:52 +0100113 misc_draw_function_names = set([
José Fonsecaca925d12012-03-21 06:46:46 +0000114 "glCallList",
115 "glCallLists",
José Fonseca920bffd2011-06-02 10:04:52 +0100116 "glClear",
117 "glEnd",
José Fonsecaf8a99a02011-06-07 20:49:56 +0100118 "glDrawPixels",
119 "glBlitFramebuffer",
120 "glBlitFramebufferEXT",
José Fonseca920bffd2011-06-02 10:04:52 +0100121 ])
122
123 bind_framebuffer_function_names = set([
124 "glBindFramebuffer",
José Fonseca920bffd2011-06-02 10:04:52 +0100125 "glBindFramebufferEXT",
José Fonsecac98ca8d2012-01-19 10:48:09 +0000126 "glBindFramebufferOES",
José Fonseca920bffd2011-06-02 10:04:52 +0100127 ])
128
José Fonsecac29f4f12011-06-11 12:19:05 +0100129 # Names of the functions that can pack into the current pixel buffer
130 # object. See also the ARB_pixel_buffer_object specification.
131 pack_function_names = set([
132 'glGetCompressedTexImage',
133 'glGetConvolutionFilter',
134 'glGetHistogram',
135 'glGetMinmax',
136 'glGetPixelMapfv',
137 'glGetPixelMapuiv',
138 'glGetPixelMapusv',
139 'glGetPolygonStipple',
José Fonseca880d7972011-10-09 09:44:03 +0100140 'glGetSeparableFilter',
José Fonsecac29f4f12011-06-11 12:19:05 +0100141 'glGetTexImage',
142 'glReadPixels',
143 'glGetnCompressedTexImageARB',
144 'glGetnConvolutionFilterARB',
145 'glGetnHistogramARB',
146 'glGetnMinmaxARB',
147 'glGetnPixelMapfvARB',
148 'glGetnPixelMapuivARB',
149 'glGetnPixelMapusvARB',
150 'glGetnPolygonStippleARB',
151 'glGetnSeparableFilterARB',
152 'glGetnTexImageARB',
153 'glReadnPixelsARB',
154 ])
155
José Fonseca46a48392011-10-14 11:34:27 +0100156 map_function_names = set([
157 'glMapBuffer',
158 'glMapBufferARB',
José Fonseca8ee21822012-01-15 13:30:43 +0000159 'glMapBufferOES',
José Fonseca46a48392011-10-14 11:34:27 +0100160 'glMapBufferRange',
161 'glMapNamedBufferEXT',
José Fonsecacbc859f2012-04-05 19:55:53 +0100162 'glMapNamedBufferRangeEXT',
163 'glMapObjectBufferATI',
José Fonseca46a48392011-10-14 11:34:27 +0100164 ])
165
166 unmap_function_names = set([
167 'glUnmapBuffer',
168 'glUnmapBufferARB',
José Fonseca8ee21822012-01-15 13:30:43 +0000169 'glUnmapBufferOES',
José Fonseca46a48392011-10-14 11:34:27 +0100170 'glUnmapNamedBufferEXT',
José Fonsecacbc859f2012-04-05 19:55:53 +0100171 'glUnmapObjectBufferATI',
José Fonseca46a48392011-10-14 11:34:27 +0100172 ])
173
José Fonseca54f304a2012-01-14 19:33:08 +0000174 def retraceFunctionBody(self, function):
José Fonseca62212972011-03-23 13:22:55 +0000175 is_array_pointer = function.name in self.array_pointer_function_names
176 is_draw_array = function.name in self.draw_array_function_names
177 is_draw_elements = function.name in self.draw_elements_function_names
José Fonseca920bffd2011-06-02 10:04:52 +0100178 is_misc_draw = function.name in self.misc_draw_function_names
José Fonseca62212972011-03-23 13:22:55 +0000179
180 if is_array_pointer or is_draw_array or is_draw_elements:
José Fonsecac0b0e992012-04-02 21:00:53 +0100181 print ' if (retrace::parser.version < 1) {'
José Fonseca62212972011-03-23 13:22:55 +0000182
183 if is_array_pointer or is_draw_array:
José Fonseca632a78d2012-04-19 07:18:59 +0100184 print ' GLint _array_buffer = 0;'
185 print ' glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &_array_buffer);'
186 print ' if (!_array_buffer) {'
José Fonseca54f304a2012-01-14 19:33:08 +0000187 self.failFunction(function)
José Fonseca62212972011-03-23 13:22:55 +0000188 print ' }'
189
190 if is_draw_elements:
José Fonseca632a78d2012-04-19 07:18:59 +0100191 print ' GLint _element_array_buffer = 0;'
192 print ' glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &_element_array_buffer);'
193 print ' if (!_element_array_buffer) {'
José Fonseca54f304a2012-01-14 19:33:08 +0000194 self.failFunction(function)
José Fonseca62212972011-03-23 13:22:55 +0000195 print ' }'
196
197 print ' }'
198
José Fonsecac29f4f12011-06-11 12:19:05 +0100199 # When no pack buffer object is bound, the pack functions are no-ops.
200 if function.name in self.pack_function_names:
José Fonseca632a78d2012-04-19 07:18:59 +0100201 print ' GLint _pack_buffer = 0;'
202 print ' glGetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &_pack_buffer);'
203 print ' if (!_pack_buffer) {'
José Fonsecac29f4f12011-06-11 12:19:05 +0100204 print ' return;'
205 print ' }'
206
José Fonseca920bffd2011-06-02 10:04:52 +0100207 # Pre-snapshots
208 if function.name in self.bind_framebuffer_function_names:
José Fonsecaa96b7252012-01-19 10:48:38 +0000209 print ' assert(call.flags & trace::CALL_FLAG_SWAP_RENDERTARGET);'
José Fonseca439ae3c2011-09-01 17:36:10 +0100210 if function.name == 'glFrameTerminatorGREMEDY':
José Fonseca4c865742011-10-25 09:56:15 +0100211 print ' glretrace::frame_complete(call);'
José Fonseca439ae3c2011-09-01 17:36:10 +0100212 return
José Fonseca920bffd2011-06-02 10:04:52 +0100213
José Fonseca54f304a2012-01-14 19:33:08 +0000214 Retracer.retraceFunctionBody(self, function)
José Fonseca62212972011-03-23 13:22:55 +0000215
José Fonseca920bffd2011-06-02 10:04:52 +0100216 # Post-snapshots
José Fonseca4d7f1fe2011-05-09 20:54:31 +0100217 if function.name in ('glFlush', 'glFinish'):
José Fonseca06555612012-04-22 09:36:59 +0100218 print ' if (!retrace::doubleBuffer) {'
José Fonseca4c865742011-10-25 09:56:15 +0100219 print ' glretrace::frame_complete(call);'
José Fonseca4d7f1fe2011-05-09 20:54:31 +0100220 print ' }'
José Fonseca920bffd2011-06-02 10:04:52 +0100221 if is_draw_array or is_draw_elements or is_misc_draw:
José Fonsecaa96b7252012-01-19 10:48:38 +0000222 print ' assert(call.flags & trace::CALL_FLAG_RENDER);'
José Fonseca920bffd2011-06-02 10:04:52 +0100223
José Fonseca4d7f1fe2011-05-09 20:54:31 +0100224
José Fonseca54f304a2012-01-14 19:33:08 +0000225 def invokeFunction(self, function):
José Fonseca757b2b62011-09-19 10:09:53 +0100226 # Infer the drawable size from GL calls
José Fonsecacdb574a2010-11-29 12:23:35 +0000227 if function.name == "glViewport":
José Fonseca757b2b62011-09-19 10:09:53 +0100228 print ' glretrace::updateDrawable(x + width, y + height);'
José Fonsecaea82c3f2012-03-29 08:19:19 +0100229 if function.name == "glViewportArray":
230 # We are concerned about drawables so only care for the first viewport
231 print ' if (first == 0 && count > 0) {'
232 print ' GLfloat x = v[0], y = v[1], w = v[2], h = v[3];'
233 print ' glretrace::updateDrawable(x + w, y + h);'
234 print ' }'
235 if function.name == "glViewportIndexedf":
236 print ' if (index == 0) {'
237 print ' glretrace::updateDrawable(x + w, y + h);'
238 print ' }'
239 if function.name == "glViewportIndexedfv":
240 print ' if (index == 0) {'
241 print ' GLfloat x = v[0], y = v[1], w = v[2], h = v[3];'
242 print ' glretrace::updateDrawable(x + w, y + h);'
243 print ' }'
José Fonseca757b2b62011-09-19 10:09:53 +0100244 if function.name in ('glBlitFramebuffer', 'glBlitFramebufferEXT'):
245 # Some applications do all their rendering in a framebuffer, and
246 # then just blit to the drawable without ever calling glViewport.
247 print ' glretrace::updateDrawable(std::max(dstX0, dstX1), std::max(dstY0, dstY1));'
José Fonsecacdb574a2010-11-29 12:23:35 +0000248
José Fonseca3d245f42010-11-28 00:08:23 +0000249 if function.name == "glEnd":
José Fonseca32871ed2011-04-10 13:40:52 +0100250 print ' glretrace::insideGlBeginEnd = false;'
José Fonsecafea81f92011-05-23 21:20:53 +0100251
José Fonsecaae9c4c12012-02-02 13:59:31 +0000252 if function.name.startswith('gl') and not function.name.startswith('glX'):
José Fonsecaa50b8972012-04-26 23:18:28 +0100253 print r' if (retrace::debug && !glretrace::currentContext) {'
José Fonsecaae9c4c12012-02-02 13:59:31 +0000254 print r' retrace::warning(call) << "no current context\n";'
255 print r' }'
256
José Fonsecafea81f92011-05-23 21:20:53 +0100257 if function.name == 'memcpy':
258 print ' if (!dest || !src || !n) return;'
José Fonseca694dc0b2012-03-01 15:44:07 +0000259
Gregory Hainaut8ac8b6b2012-06-11 13:58:22 +0100260 # Skip glEnable/Disable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB) as we don't
261 # faithfully set the CONTEXT_DEBUG_BIT_ARB flags on context creation.
262 if function.name in ('glEnable', 'glDisable'):
263 print ' if (cap == GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB) return;'
264
José Fonseca694dc0b2012-03-01 15:44:07 +0000265 # Destroy the buffer mapping
266 if function.name in self.unmap_function_names:
267 print r' GLvoid *ptr = NULL;'
268 if function.name == 'glUnmapBuffer':
269 print r' glGetBufferPointerv(target, GL_BUFFER_MAP_POINTER, &ptr);'
270 elif function.name == 'glUnmapBufferARB':
271 print r' glGetBufferPointervARB(target, GL_BUFFER_MAP_POINTER_ARB, &ptr);'
272 elif function.name == 'glUnmapBufferOES':
273 print r' glGetBufferPointervOES(target, GL_BUFFER_MAP_POINTER_OES, &ptr);'
274 elif function.name == 'glUnmapNamedBufferEXT':
275 print r' glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &ptr);'
José Fonsecacbc859f2012-04-05 19:55:53 +0100276 elif function.name == 'glUnmapObjectBufferATI':
277 # TODO
278 pass
José Fonseca694dc0b2012-03-01 15:44:07 +0000279 else:
280 assert False
281 print r' if (ptr) {'
282 print r' retrace::delRegionByPointer(ptr);'
283 print r' } else {'
284 print r' retrace::warning(call) << "no current context\n";'
285 print r' }'
Gregory Hainautb79e26a2012-05-11 14:49:10 +0100286
287 if function.name in ('glBindProgramPipeline', 'glBindProgramPipelineEXT'):
288 # Note if glBindProgramPipeline has ever been called
289 print r' if (pipeline) {'
290 print r' _pipelineHasBeenBound = true;'
291 print r' }'
James Bentonaddf7f92012-07-20 18:56:19 +0100292
293 profileDraw = (
294 function.name in self.draw_array_function_names or
295 function.name in self.draw_elements_function_names or
296 function.name in self.draw_indirect_function_names or
James Benton3bb28dd2012-08-06 11:44:23 +0100297 function.name in self.misc_draw_function_names or
298 function.name == 'glBegin'
James Bentonaddf7f92012-07-20 18:56:19 +0100299 )
300
James Benton6d923272012-07-25 13:48:20 +0100301 if function.name in ('glUseProgram', 'glUseProgramObjectARB'):
James Benton60139d62012-08-09 14:23:44 +0100302 print r' if (glretrace::currentContext) {'
303 print r' glretrace::currentContext->activeProgram = call.arg(0).toUInt();'
304 print r' }'
James Benton6d923272012-07-25 13:48:20 +0100305
306 # Only profile if not inside a list as the queries get inserted into list
James Bentonaddf7f92012-07-20 18:56:19 +0100307 if function.name == 'glNewList':
James Benton6d923272012-07-25 13:48:20 +0100308 print r' glretrace::insideList = true;'
James Bentonaddf7f92012-07-20 18:56:19 +0100309
310 if function.name == 'glEndList':
James Benton6d923272012-07-25 13:48:20 +0100311 print r' glretrace::insideList = false;'
James Bentonaddf7f92012-07-20 18:56:19 +0100312
James Bentonc53c6492012-08-13 18:21:16 +0100313 if function.name != 'glEnd':
James Benton3bb28dd2012-08-06 11:44:23 +0100314 print r' if (!glretrace::insideList && !glretrace::insideGlBeginEnd && retrace::profiling) {'
James Bentonc53c6492012-08-13 18:21:16 +0100315 if profileDraw:
316 print r' glretrace::beginProfile(call, true);'
317 else:
318 print r' glretrace::beginProfile(call, false);'
James Bentonaddf7f92012-07-20 18:56:19 +0100319 print r' }'
320
José Fonseca3db3b2f2012-05-11 14:55:50 +0100321 if function.name == 'glCreateShaderProgramv':
322 # When dumping state, break down glCreateShaderProgramv so that the
323 # shader source can be recovered.
324 print r' if (retrace::dumpingState) {'
325 print r' GLuint _shader = glCreateShader(type);'
326 print r' if (_shader) {'
327 print r' glShaderSource(_shader, count, strings, NULL);'
328 print r' glCompileShader(_shader);'
329 print r' const GLuint _program = glCreateProgram();'
330 print r' if (_program) {'
331 print r' GLint compiled = GL_FALSE;'
332 print r' glGetShaderiv(_shader, GL_COMPILE_STATUS, &compiled);'
333 print r' glProgramParameteri(_program, GL_PROGRAM_SEPARABLE, GL_TRUE);'
334 print r' if (compiled) {'
335 print r' glAttachShader(_program, _shader);'
336 print r' glLinkProgram(_program);'
337 print r' //glDetachShader(_program, _shader);'
338 print r' }'
339 print r' //append-shader-info-log-to-program-info-log'
340 print r' }'
341 print r' //glDeleteShader(_shader);'
342 print r' _result = _program;'
343 print r' } else {'
344 print r' _result = 0;'
345 print r' }'
346 print r' } else {'
347 Retracer.invokeFunction(self, function)
348 print r' }'
349 else:
350 Retracer.invokeFunction(self, function)
José Fonsecacdb574a2010-11-29 12:23:35 +0000351
James Bentond852eae2012-08-10 15:56:18 +0100352 if function.name == "glBegin":
353 print ' glretrace::insideGlBeginEnd = true;'
354
James Bentonc53c6492012-08-13 18:21:16 +0100355 print r' if (!glretrace::insideList && !glretrace::insideGlBeginEnd && retrace::profiling) {'
356 if profileDraw:
357 print r' glretrace::endProfile(call, true);'
358 else:
359 print r' glretrace::endProfile(call, false);'
360 print r' }'
James Bentonaddf7f92012-07-20 18:56:19 +0100361
José Fonsecaecf37412011-05-21 01:56:08 +0100362 # Error checking
James Bentond852eae2012-08-10 15:56:18 +0100363 if function.name.startswith('gl'):
José Fonseca3d245f42010-11-28 00:08:23 +0000364 # glGetError is not allowed inside glBegin/glEnd
José Fonseca06555612012-04-22 09:36:59 +0100365 print ' if (retrace::debug && !glretrace::insideGlBeginEnd) {'
José Fonsecaecf37412011-05-21 01:56:08 +0100366 print ' glretrace::checkGlError(call);'
367 if function.name in ('glProgramStringARB', 'glProgramStringNV'):
368 print r' GLint error_position = -1;'
369 print r' glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_position);'
370 print r' if (error_position != -1) {'
371 print r' const char *error_string = (const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB);'
José Fonsecab1bb3c22011-10-08 20:23:18 +0100372 print r' retrace::warning(call) << error_string << "\n";'
José Fonsecaecf37412011-05-21 01:56:08 +0100373 print r' }'
374 if function.name == 'glCompileShader':
375 print r' GLint compile_status = 0;'
376 print r' glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_status);'
377 print r' if (!compile_status) {'
378 print r' GLint info_log_length = 0;'
379 print r' glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_log_length);'
380 print r' GLchar *infoLog = new GLchar[info_log_length];'
381 print r' glGetShaderInfoLog(shader, info_log_length, NULL, infoLog);'
José Fonsecab1bb3c22011-10-08 20:23:18 +0100382 print r' retrace::warning(call) << infoLog << "\n";'
José Fonsecaecf37412011-05-21 01:56:08 +0100383 print r' delete [] infoLog;'
384 print r' }'
José Fonseca65d34262012-05-11 14:16:49 +0100385 if function.name in ('glLinkProgram', 'glCreateShaderProgramv', 'glCreateShaderProgramEXT'):
386 if function.name != 'glLinkProgram':
387 print r' GLuint program = _result;'
José Fonsecaecf37412011-05-21 01:56:08 +0100388 print r' GLint link_status = 0;'
389 print r' glGetProgramiv(program, GL_LINK_STATUS, &link_status);'
390 print r' if (!link_status) {'
391 print r' GLint info_log_length = 0;'
392 print r' glGetProgramiv(program, GL_INFO_LOG_LENGTH, &info_log_length);'
393 print r' GLchar *infoLog = new GLchar[info_log_length];'
394 print r' glGetProgramInfoLog(program, info_log_length, NULL, infoLog);'
José Fonsecab1bb3c22011-10-08 20:23:18 +0100395 print r' retrace::warning(call) << infoLog << "\n";'
José Fonsecaecf37412011-05-21 01:56:08 +0100396 print r' delete [] infoLog;'
397 print r' }'
398 if function.name == 'glCompileShaderARB':
399 print r' GLint compile_status = 0;'
400 print r' glGetObjectParameterivARB(shaderObj, GL_OBJECT_COMPILE_STATUS_ARB, &compile_status);'
401 print r' if (!compile_status) {'
402 print r' GLint info_log_length = 0;'
403 print r' glGetObjectParameterivARB(shaderObj, GL_OBJECT_INFO_LOG_LENGTH_ARB, &info_log_length);'
404 print r' GLchar *infoLog = new GLchar[info_log_length];'
405 print r' glGetInfoLogARB(shaderObj, info_log_length, NULL, infoLog);'
José Fonsecab1bb3c22011-10-08 20:23:18 +0100406 print r' retrace::warning(call) << infoLog << "\n";'
José Fonsecaecf37412011-05-21 01:56:08 +0100407 print r' delete [] infoLog;'
408 print r' }'
409 if function.name == 'glLinkProgramARB':
410 print r' GLint link_status = 0;'
411 print r' glGetObjectParameterivARB(programObj, GL_OBJECT_LINK_STATUS_ARB, &link_status);'
412 print r' if (!link_status) {'
413 print r' GLint info_log_length = 0;'
414 print r' glGetObjectParameterivARB(programObj, GL_OBJECT_INFO_LOG_LENGTH_ARB, &info_log_length);'
415 print r' GLchar *infoLog = new GLchar[info_log_length];'
416 print r' glGetInfoLogARB(programObj, info_log_length, NULL, infoLog);'
José Fonsecab1bb3c22011-10-08 20:23:18 +0100417 print r' retrace::warning(call) << infoLog << "\n";'
José Fonsecaecf37412011-05-21 01:56:08 +0100418 print r' delete [] infoLog;'
419 print r' }'
José Fonseca46a48392011-10-14 11:34:27 +0100420 if function.name in self.map_function_names:
José Fonseca632a78d2012-04-19 07:18:59 +0100421 print r' if (!_result) {'
José Fonsecab1bb3c22011-10-08 20:23:18 +0100422 print r' retrace::warning(call) << "failed to map buffer\n";'
José Fonsecafea81f92011-05-23 21:20:53 +0100423 print r' }'
José Fonsecacbc859f2012-04-05 19:55:53 +0100424 if function.name in self.unmap_function_names and function.type is not stdapi.Void:
José Fonseca632a78d2012-04-19 07:18:59 +0100425 print r' if (!_result) {'
José Fonseca96a57e72012-03-01 15:44:28 +0000426 print r' retrace::warning(call) << "failed to unmap buffer\n";'
427 print r' }'
José Fonseca91492d22011-05-23 21:20:31 +0100428 if function.name in ('glGetAttribLocation', 'glGetAttribLocationARB'):
José Fonseca632a78d2012-04-19 07:18:59 +0100429 print r' GLint _origResult = call.ret->toSInt();'
430 print r' if (_result != _origResult) {'
431 print r' retrace::warning(call) << "vertex attrib location mismatch " << _origResult << " -> " << _result << "\n";'
José Fonseca91492d22011-05-23 21:20:31 +0100432 print r' }'
José Fonsecad5377812011-06-07 20:48:55 +0100433 if function.name in ('glCheckFramebufferStatus', 'glCheckFramebufferStatusEXT', 'glCheckNamedFramebufferStatusEXT'):
José Fonseca632a78d2012-04-19 07:18:59 +0100434 print r' GLint _origResult = call.ret->toSInt();'
435 print r' if (_origResult == GL_FRAMEBUFFER_COMPLETE &&'
436 print r' _result != GL_FRAMEBUFFER_COMPLETE) {'
437 print r' retrace::warning(call) << "incomplete framebuffer (" << glstate::enumToString(_result) << ")\n";'
José Fonsecad5377812011-06-07 20:48:55 +0100438 print r' }'
José Fonsecaecf37412011-05-21 01:56:08 +0100439 print ' }'
José Fonsecae4999b92011-05-05 00:31:01 +0100440
José Fonseca561266b2012-03-21 06:49:41 +0000441 # Query the buffer length for whole buffer mappings
442 if function.name in self.map_function_names:
443 if 'length' in function.argNames():
444 assert 'BufferRange' in function.name
445 else:
446 assert 'BufferRange' not in function.name
447 print r' GLint length = 0;'
448 if function.name in ('glMapBuffer', 'glMapBufferOES'):
449 print r' glGetBufferParameteriv(target, GL_BUFFER_SIZE, &length);'
450 elif function.name == 'glMapBufferARB':
451 print r' glGetBufferParameterivARB(target, GL_BUFFER_SIZE_ARB, &length);'
452 elif function.name == 'glMapNamedBufferEXT':
453 print r' glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_SIZE, &length);'
José Fonsecacbc859f2012-04-05 19:55:53 +0100454 elif function.name == 'glMapObjectBufferATI':
455 print r' glGetObjectBufferivATI(buffer, GL_OBJECT_BUFFER_SIZE_ATI, &length);'
José Fonseca59ee88e2012-01-15 14:24:10 +0000456 else:
José Fonseca561266b2012-03-21 06:49:41 +0000457 assert False
José Fonseca46a48392011-10-14 11:34:27 +0100458
José Fonseca54f304a2012-01-14 19:33:08 +0000459 def extractArg(self, function, arg, arg_type, lvalue, rvalue):
José Fonseca7f5163e2011-03-31 23:37:26 +0100460 if function.name in self.array_pointer_function_names and arg.name == 'pointer':
José Fonseca46a48392011-10-14 11:34:27 +0100461 print ' %s = static_cast<%s>(retrace::toPointer(%s, true));' % (lvalue, arg_type, rvalue)
José Fonseca14c21bc2011-02-20 23:32:22 +0000462 return
463
José Fonseca9b126ea2011-09-15 08:15:33 +0100464 if function.name in self.draw_elements_function_names and arg.name == 'indices' or\
465 function.name in self.draw_indirect_function_names and arg.name == 'indirect':
José Fonseca54f304a2012-01-14 19:33:08 +0000466 self.extractOpaqueArg(function, arg, arg_type, lvalue, rvalue)
José Fonseca8a844ae2010-12-06 18:50:52 +0000467 return
José Fonsecadacd8dd2010-11-25 17:50:26 +0000468
José Fonsecac29f4f12011-06-11 12:19:05 +0100469 # Handle pointer with offsets into the current pack pixel buffer
470 # object.
471 if function.name in self.pack_function_names and arg.output:
José Fonseca4a2c57b2012-04-07 10:50:53 +0100472 assert isinstance(arg_type, (stdapi.Pointer, stdapi.Array, stdapi.Blob, stdapi.Opaque))
473 print ' %s = static_cast<%s>((%s).toPointer());' % (lvalue, arg_type, rvalue)
José Fonsecac29f4f12011-06-11 12:19:05 +0100474 return
475
José Fonseca3c1b7ce2011-05-09 11:22:54 +0100476 if arg.type is glapi.GLlocation \
José Fonseca568ecc22012-01-15 13:57:03 +0000477 and 'program' not in function.argNames():
Gregory Hainautb79e26a2012-05-11 14:49:10 +0100478 # Determine the active program for uniforms swizzling
José Fonseca8a844ae2010-12-06 18:50:52 +0000479 print ' GLint program = -1;'
Gregory Hainautb79e26a2012-05-11 14:49:10 +0100480 print ' GLint pipeline = 0;'
481 print ' if (_pipelineHasBeenBound) {'
482 print ' glGetIntegerv(GL_PROGRAM_PIPELINE_BINDING, &pipeline);'
483 print ' }'
484 print ' if (pipeline) {'
485 print ' glGetProgramPipelineiv(pipeline, GL_ACTIVE_PROGRAM, &program);'
486 print ' } else {'
487 print ' glGetIntegerv(GL_CURRENT_PROGRAM, &program);'
488 print ' }'
489 print
490
José Fonseca3c1b7ce2011-05-09 11:22:54 +0100491 if arg.type is glapi.GLlocationARB \
José Fonseca568ecc22012-01-15 13:57:03 +0000492 and 'programObj' not in function.argNames():
José Fonseca3a84b682011-05-09 11:33:47 +0100493 print ' GLhandleARB programObj = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);'
José Fonseca8a844ae2010-12-06 18:50:52 +0000494
José Fonseca54f304a2012-01-14 19:33:08 +0000495 Retracer.extractArg(self, function, arg, arg_type, lvalue, rvalue)
José Fonsecae6a50bd2010-11-24 10:12:22 +0000496
José Fonseca42926462011-05-09 11:32:15 +0100497 # Don't try to use more samples than the implementation supports
498 if arg.name == 'samples':
499 assert arg.type is glapi.GLsizei
500 print ' GLint max_samples = 0;'
501 print ' glGetIntegerv(GL_MAX_SAMPLES, &max_samples);'
502 print ' if (samples > max_samples) {'
503 print ' samples = max_samples;'
504 print ' }'
505
José Fonseca62abddc2012-04-13 14:57:08 +0100506 # These parameters are referred beyond the call life-time
507 # TODO: Replace ad-hoc solution for bindable parameters with general one
508 if function.name in ('glFeedbackBuffer', 'glSelectBuffer') and arg.output:
509 print ' _allocator.bind(%s);' % arg.name
510
511
José Fonsecae6a50bd2010-11-24 10:12:22 +0000512
José Fonseca7e329022010-11-19 17:05:18 +0000513if __name__ == '__main__':
José Fonseca796a3042010-11-29 14:21:06 +0000514 print r'''
José Fonseca867b1b72011-04-24 11:58:04 +0100515#include <string.h>
516
José Fonsecadf66a902010-11-29 13:24:20 +0000517#include "glproc.hpp"
José Fonseca32871ed2011-04-10 13:40:52 +0100518#include "glretrace.hpp"
José Fonseca56391262011-09-19 09:30:10 +0100519#include "glstate.hpp"
José Fonseca589082d2011-03-30 09:10:40 +0100520
José Fonsecadf66a902010-11-29 13:24:20 +0000521
Gregory Hainautb79e26a2012-05-11 14:49:10 +0100522static bool _pipelineHasBeenBound = false;
José Fonseca3d245f42010-11-28 00:08:23 +0000523'''
José Fonsecae0e61402010-11-25 15:03:23 +0000524 api = glapi.glapi
José Fonseca54f304a2012-01-14 19:33:08 +0000525 api.addApi(glesapi.glesapi)
José Fonsecae0e61402010-11-25 15:03:23 +0000526 retracer = GlRetracer()
José Fonseca54f304a2012-01-14 19:33:08 +0000527 retracer.retraceApi(api)