blob: a2637074afe27e52ed521bbdcc61b832a3e2d7df [file] [log] [blame]
José Fonseca669b1222011-02-20 09:05:10 +00001##########################################################################
2#
3# Copyright 2008-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 tracing generator."""
28
29
José Fonsecac5bf77a2014-08-14 16:10:02 +010030import re
31import sys
32
José Fonseca452d3252012-04-14 15:55:40 +010033from trace import Tracer
José Fonseca1b6c8752012-04-15 14:33:00 +010034from dispatch import function_pointer_type, function_pointer_value
José Fonsecabd86a222011-09-27 09:21:38 +010035import specs.stdapi as stdapi
36import specs.glapi as glapi
37import specs.glparams as glparams
38from specs.glxapi import glxapi
José Fonseca669b1222011-02-20 09:05:10 +000039
40
José Fonseca99221832011-03-22 22:15:46 +000041class TypeGetter(stdapi.Visitor):
42 '''Determine which glGet*v function that matches the specified type.'''
43
José Fonsecac493e3e2011-06-29 12:57:06 +010044 def __init__(self, prefix = 'glGet', long_suffix = True, ext_suffix = ''):
José Fonseca1a2fdd22011-04-01 00:55:09 +010045 self.prefix = prefix
46 self.long_suffix = long_suffix
José Fonsecac493e3e2011-06-29 12:57:06 +010047 self.ext_suffix = ext_suffix
José Fonseca1a2fdd22011-04-01 00:55:09 +010048
José Fonseca54f304a2012-01-14 19:33:08 +000049 def visitConst(self, const):
José Fonseca99221832011-03-22 22:15:46 +000050 return self.visit(const.type)
51
José Fonseca54f304a2012-01-14 19:33:08 +000052 def visitAlias(self, alias):
José Fonseca99221832011-03-22 22:15:46 +000053 if alias.expr == 'GLboolean':
José Fonseca1a2fdd22011-04-01 00:55:09 +010054 if self.long_suffix:
José Fonsecac493e3e2011-06-29 12:57:06 +010055 suffix = 'Booleanv'
56 arg_type = alias.expr
José Fonseca1a2fdd22011-04-01 00:55:09 +010057 else:
José Fonsecac493e3e2011-06-29 12:57:06 +010058 suffix = 'iv'
59 arg_type = 'GLint'
José Fonseca99221832011-03-22 22:15:46 +000060 elif alias.expr == 'GLdouble':
José Fonseca1a2fdd22011-04-01 00:55:09 +010061 if self.long_suffix:
José Fonsecac493e3e2011-06-29 12:57:06 +010062 suffix = 'Doublev'
63 arg_type = alias.expr
José Fonseca1a2fdd22011-04-01 00:55:09 +010064 else:
José Fonsecac493e3e2011-06-29 12:57:06 +010065 suffix = 'dv'
66 arg_type = alias.expr
José Fonseca99221832011-03-22 22:15:46 +000067 elif alias.expr == 'GLfloat':
José Fonseca1a2fdd22011-04-01 00:55:09 +010068 if self.long_suffix:
José Fonsecac493e3e2011-06-29 12:57:06 +010069 suffix = 'Floatv'
70 arg_type = alias.expr
José Fonseca1a2fdd22011-04-01 00:55:09 +010071 else:
José Fonsecac493e3e2011-06-29 12:57:06 +010072 suffix = 'fv'
73 arg_type = alias.expr
José Fonseca7f5163e2011-03-31 23:37:26 +010074 elif alias.expr in ('GLint', 'GLuint', 'GLsizei'):
José Fonseca1a2fdd22011-04-01 00:55:09 +010075 if self.long_suffix:
José Fonsecac493e3e2011-06-29 12:57:06 +010076 suffix = 'Integerv'
77 arg_type = 'GLint'
José Fonseca1a2fdd22011-04-01 00:55:09 +010078 else:
José Fonsecac493e3e2011-06-29 12:57:06 +010079 suffix = 'iv'
80 arg_type = 'GLint'
José Fonseca99221832011-03-22 22:15:46 +000081 else:
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010082 print(alias.expr)
José Fonseca99221832011-03-22 22:15:46 +000083 assert False
José Fonsecac493e3e2011-06-29 12:57:06 +010084 function_name = self.prefix + suffix + self.ext_suffix
85 return function_name, arg_type
José Fonseca99221832011-03-22 22:15:46 +000086
José Fonseca54f304a2012-01-14 19:33:08 +000087 def visitEnum(self, enum):
José Fonseca1a2fdd22011-04-01 00:55:09 +010088 return self.visit(glapi.GLint)
José Fonseca99221832011-03-22 22:15:46 +000089
José Fonseca54f304a2012-01-14 19:33:08 +000090 def visitBitmask(self, bitmask):
José Fonseca1a2fdd22011-04-01 00:55:09 +010091 return self.visit(glapi.GLint)
José Fonseca99221832011-03-22 22:15:46 +000092
José Fonseca54f304a2012-01-14 19:33:08 +000093 def visitOpaque(self, pointer):
José Fonsecac493e3e2011-06-29 12:57:06 +010094 return self.prefix + 'Pointerv' + self.ext_suffix, 'GLvoid *'
José Fonseca99221832011-03-22 22:15:46 +000095
96
José Fonseca669b1222011-02-20 09:05:10 +000097class GlTracer(Tracer):
98
José Fonseca99221832011-03-22 22:15:46 +000099 arrays = [
100 ("Vertex", "VERTEX"),
101 ("Normal", "NORMAL"),
102 ("Color", "COLOR"),
103 ("Index", "INDEX"),
104 ("TexCoord", "TEXTURE_COORD"),
105 ("EdgeFlag", "EDGE_FLAG"),
106 ("FogCoord", "FOG_COORD"),
107 ("SecondaryColor", "SECONDARY_COLOR"),
José Fonseca14c21bc2011-02-20 23:32:22 +0000108 ]
José Fonsecac9f12232011-03-25 20:07:42 +0000109 arrays.reverse()
José Fonseca669b1222011-02-20 09:05:10 +0000110
José Fonsecab0c59722015-01-05 20:45:41 +0000111 # arrays available in ES1
Chia-I Wub3d218d2011-11-03 01:37:36 +0800112 arrays_es1 = ("Vertex", "Normal", "Color", "TexCoord")
113
José Fonseca4c938c22011-04-30 22:44:38 +0100114 def header(self, api):
115 Tracer.header(self, api)
116
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100117 print('#include <algorithm>')
118 print()
119 print('#include "gltrace.hpp"')
120 print('#include "gltrace_arrays.hpp"')
121 print()
José Fonseca5a568a92011-06-29 16:43:36 +0100122
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000123 # Whether we need user arrays
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100124 print('static inline bool _need_user_arrays(gltrace::Context *_ctx)')
125 print('{')
126 print(' if (!_ctx->user_arrays) {')
127 print(' return false;')
128 print(' }')
129 print()
130 print(' glfeatures::Profile profile = _ctx->profile;')
131 print(' bool es1 = profile.es() && profile.major == 1;')
132 print()
José Fonseca1a2fdd22011-04-01 00:55:09 +0100133
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000134 for camelcase_name, uppercase_name in self.arrays:
Chia-I Wub3d218d2011-11-03 01:37:36 +0800135 # in which profile is the array available?
José Fonseca34ea6162015-01-08 23:45:43 +0000136 profile_check = 'profile.desktop()'
Chia-I Wub3d218d2011-11-03 01:37:36 +0800137 if camelcase_name in self.arrays_es1:
José Fonsecab0c59722015-01-05 20:45:41 +0000138 profile_check = '(' + profile_check + ' || es1)';
Chia-I Wub3d218d2011-11-03 01:37:36 +0800139
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000140 function_name = 'gl%sPointer' % camelcase_name
141 enable_name = 'GL_%s_ARRAY' % uppercase_name
142 binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100143 print(' // %s' % function_name)
144 print(' if (%s) {' % profile_check)
José Fonsecafb6744f2011-04-15 11:18:37 +0100145 self.array_prolog(api, uppercase_name)
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100146 print(' if (_glIsEnabled(%s) &&' % enable_name)
147 print(' _glGetInteger(%s) == 0) {' % binding_name)
José Fonsecafb6744f2011-04-15 11:18:37 +0100148 self.array_cleanup(api, uppercase_name)
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100149 print(' return true;')
150 print(' }')
José Fonsecafb6744f2011-04-15 11:18:37 +0100151 self.array_epilog(api, uppercase_name)
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100152 print(' }')
153 print()
José Fonseca7f5163e2011-03-31 23:37:26 +0100154
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100155 print(' // ES1 does not support generic vertex attributes')
156 print(' if (es1)')
157 print(' return false;')
158 print()
159 print(' // glVertexAttribPointer')
160 print(' GLint _max_vertex_attribs = _glGetInteger(GL_MAX_VERTEX_ATTRIBS);')
161 print(' for (GLint index = 0; index < _max_vertex_attribs; ++index) {')
162 print(' if (_glGetVertexAttribi(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED) &&')
163 print(' _glGetVertexAttribi(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING) == 0) {')
164 print(' return true;')
165 print(' }')
166 print(' }')
167 print()
José Fonseca1a2fdd22011-04-01 00:55:09 +0100168
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100169 print(' return false;')
170 print('}')
171 print()
José Fonseca669b1222011-02-20 09:05:10 +0000172
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100173 print(r'static void _trace_user_arrays(gltrace::Context *_ctx, GLuint count);')
174 print()
Jose Fonseca6ef9b3c2016-01-27 23:18:52 +0000175
Jose Fonseca27b8d812016-05-13 07:09:09 -0700176 # Declare helper functions to emit fake function calls into the trace
177 for function in api.getAllFunctions():
178 if function.name in self.fake_function_names:
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100179 print(function.prototype('_fake_' + function.name) + ';')
180 print()
181 print(r'static inline void')
182 print(r'_fakeStringMarker(const std::string &s) {')
183 print(r' _fake_glStringMarkerGREMEDY(s.length(), s.data());')
184 print(r'}')
185 print()
José Fonseca867b1b72011-04-24 11:58:04 +0100186
José Fonseca9c536b02012-02-29 20:54:13 +0000187 # Buffer mappings
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100188 print('// whether glMapBufferRange(GL_MAP_WRITE_BIT) has ever been called')
189 print('static bool _checkBufferMapRange = false;')
190 print()
191 print('// whether glBufferParameteriAPPLE(GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE) has ever been called')
192 print('static bool _checkBufferFlushingUnmapAPPLE = false;')
193 print()
José Fonseca867b1b72011-04-24 11:58:04 +0100194
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100195 # Generate a helper function to determine whether a parameter name
196 # refers to a symbolic value or not
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100197 print('static bool')
198 print('is_symbolic_pname(GLenum pname) {')
199 print(' switch (pname) {')
José Fonseca5ea91872011-05-04 09:41:55 +0100200 for function, type, count, name in glparams.parameters:
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100201 if type is glapi.GLenum:
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100202 print(' case %s:' % name)
203 print(' return true;')
204 print(' default:')
205 print(' return false;')
206 print(' }')
207 print('}')
208 print()
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100209
210 # Generate a helper function to determine whether a parameter value is
211 # potentially symbolic or not; i.e., if the value can be represented in
212 # an enum or not
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100213 print('template<class T>')
214 print('static inline bool')
215 print('is_symbolic_param(T param) {')
216 print(' return static_cast<T>(static_cast<GLenum>(param)) == param;')
217 print('}')
218 print()
José Fonseca4c938c22011-04-30 22:44:38 +0100219
220 # Generate a helper function to know how many elements a parameter has
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100221 print('static size_t')
222 print('_gl_param_size(GLenum pname) {')
223 print(' switch (pname) {')
José Fonseca5ea91872011-05-04 09:41:55 +0100224 for function, type, count, name in glparams.parameters:
Jose Fonseca11b6bfa2015-07-21 13:32:51 +0100225 if name == 'GL_PROGRAM_BINARY_FORMATS':
226 count = 0
José Fonseca4c938c22011-04-30 22:44:38 +0100227 if type is not None:
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100228 print(' case %s: return %s;' % (name, count))
229 print(' default:')
230 print(r' os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);')
231 print(' return 1;')
232 print(' }')
233 print('}')
234 print()
José Fonseca4c938c22011-04-30 22:44:38 +0100235
Chia-I Wu335efb42011-11-03 01:59:22 +0800236 # states such as GL_UNPACK_ROW_LENGTH are not available in GLES
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100237 print('static inline bool')
238 print('can_unpack_subimage(void) {')
239 print(' gltrace::Context *_ctx = gltrace::getContext();')
Jose Fonseca487e9c52019-06-17 10:36:16 +0100240 print(' return _ctx->features.unpack_subimage;')
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100241 print('}')
242 print()
Chia-I Wu335efb42011-11-03 01:59:22 +0800243
José Fonseca631dbd12014-12-15 16:34:45 +0000244 # VMWX_map_buffer_debug
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100245 print(r'extern "C" PUBLIC')
246 print(r'void APIENTRY')
247 print(r'glNotifyMappedBufferRangeVMWX(const void * start, GLsizeiptr length) {')
José Fonseca631dbd12014-12-15 16:34:45 +0000248 self.emit_memcpy('start', 'length')
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100249 print(r'}')
250 print()
José Fonseca631dbd12014-12-15 16:34:45 +0000251
José Fonseca1b6c8752012-04-15 14:33:00 +0100252 getProcAddressFunctionNames = []
253
254 def traceApi(self, api):
255 if self.getProcAddressFunctionNames:
256 # Generate a function to wrap proc addresses
257 getProcAddressFunction = api.getFunctionByName(self.getProcAddressFunctionNames[0])
258 argType = getProcAddressFunction.args[0].type
259 retType = getProcAddressFunction.type
260
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100261 print('static %s _wrapProcAddress(%s procName, %s procPtr);' % (retType, argType, retType))
262 print()
José Fonseca1b6c8752012-04-15 14:33:00 +0100263
264 Tracer.traceApi(self, api)
265
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100266 print('static %s _wrapProcAddress(%s procName, %s procPtr) {' % (retType, argType, retType))
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700267
268 # Provide fallback functions to missing debug functions
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100269 print(' if (!procPtr) {')
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700270 else_ = ''
271 for function_name in self.debug_functions:
272 if self.api.getFunctionByName(function_name):
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100273 print(' %sif (strcmp("%s", (const char *)procName) == 0) {' % (else_, function_name))
274 print(' return (%s)&%s;' % (retType, function_name))
275 print(' }')
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700276 else_ = 'else '
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100277 print(' %s{' % else_)
278 print(' return NULL;')
279 print(' }')
280 print(' }')
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700281
José Fonseca81301932012-11-11 00:10:20 +0000282 for function in api.getAllFunctions():
José Fonseca1b6c8752012-04-15 14:33:00 +0100283 ptype = function_pointer_type(function)
284 pvalue = function_pointer_value(function)
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100285 print(' if (strcmp("%s", (const char *)procName) == 0) {' % function.name)
286 print(' assert(procPtr != (%s)&%s);' % (retType, function.name))
287 print(' %s = (%s)procPtr;' % (pvalue, ptype))
288 print(' return (%s)&%s;' % (retType, function.name,))
289 print(' }')
290 print(' os::log("apitrace: warning: unknown function \\"%s\\"\\n", (const char *)procName);')
291 print(' return procPtr;')
292 print('}')
293 print()
José Fonseca1b6c8752012-04-15 14:33:00 +0100294 else:
295 Tracer.traceApi(self, api)
296
José Fonseca99221832011-03-22 22:15:46 +0000297 array_pointer_function_names = set((
298 "glVertexPointer",
299 "glNormalPointer",
300 "glColorPointer",
301 "glIndexPointer",
302 "glTexCoordPointer",
303 "glEdgeFlagPointer",
304 "glFogCoordPointer",
305 "glSecondaryColorPointer",
José Fonseca7f5163e2011-03-31 23:37:26 +0100306
José Fonsecaac5285b2011-05-04 11:09:08 +0100307 "glInterleavedArrays",
308
José Fonseca7e0bfd92011-04-30 23:09:03 +0100309 "glVertexPointerEXT",
310 "glNormalPointerEXT",
311 "glColorPointerEXT",
312 "glIndexPointerEXT",
313 "glTexCoordPointerEXT",
314 "glEdgeFlagPointerEXT",
315 "glFogCoordPointerEXT",
316 "glSecondaryColorPointerEXT",
José Fonseca99221832011-03-22 22:15:46 +0000317
José Fonseca7f5163e2011-03-31 23:37:26 +0100318 "glVertexAttribPointer",
319 "glVertexAttribPointerARB",
320 "glVertexAttribPointerNV",
José Fonsecaac5285b2011-05-04 11:09:08 +0100321 "glVertexAttribIPointer",
322 "glVertexAttribIPointerEXT",
José Fonseca7f5163e2011-03-31 23:37:26 +0100323 "glVertexAttribLPointer",
324 "glVertexAttribLPointerEXT",
José Fonseca99221832011-03-22 22:15:46 +0000325
326 #"glMatrixIndexPointerARB",
327 ))
328
José Fonsecac5bf77a2014-08-14 16:10:02 +0100329 # XXX: We currently ignore the gl*Draw*ElementArray* functions
Jose Fonsecadddc5b82016-05-08 22:33:44 +0100330 draw_function_regex = re.compile(r'^(?P<radical>gl([A-Z][a-z]+)*Draw(Range)?(Arrays|Elements))(?P<suffix>[A-Z][a-zA-Z]*)?$' )
José Fonseca99221832011-03-22 22:15:46 +0000331
José Fonsecac9f12232011-03-25 20:07:42 +0000332 interleaved_formats = [
333 'GL_V2F',
334 'GL_V3F',
335 'GL_C4UB_V2F',
336 'GL_C4UB_V3F',
337 'GL_C3F_V3F',
338 'GL_N3F_V3F',
339 'GL_C4F_N3F_V3F',
340 'GL_T2F_V3F',
341 'GL_T4F_V4F',
342 'GL_T2F_C4UB_V3F',
343 'GL_T2F_C3F_V3F',
344 'GL_T2F_N3F_V3F',
345 'GL_T2F_C4F_N3F_V3F',
346 'GL_T4F_C4F_N3F_V4F',
347 ]
348
José Fonseca54f304a2012-01-14 19:33:08 +0000349 def traceFunctionImplBody(self, function):
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000350 # Defer tracing of user array pointers...
José Fonseca99221832011-03-22 22:15:46 +0000351 if function.name in self.array_pointer_function_names:
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100352 print(' GLint _array_buffer = _glGetInteger(GL_ARRAY_BUFFER_BINDING);')
353 print(' if (!_array_buffer) {')
354 print(' static bool warned = false;')
355 print(' if (!warned) {')
356 print(' warned = true;')
357 print(' os::log("apitrace: warning: %s: call will be faked due to pointer to user memory (https://github.com/apitrace/apitrace/blob/master/docs/BUGS.markdown#tracing)\\n", __FUNCTION__);')
358 print(' }')
359 print(' gltrace::Context *_ctx = gltrace::getContext();')
360 print(' _ctx->user_arrays = true;')
José Fonseca5a568a92011-06-29 16:43:36 +0100361 if function.name == "glVertexAttribPointerNV":
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100362 print(r' os::log("apitrace: warning: %s: user memory arrays with NV_vertex_program longer supported\n", __FUNCTION__);')
José Fonseca54f304a2012-01-14 19:33:08 +0000363 self.invokeFunction(function)
José Fonsecaac5285b2011-05-04 11:09:08 +0100364
365 # And also break down glInterleavedArrays into the individual calls
366 if function.name == 'glInterleavedArrays':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100367 print()
José Fonsecaac5285b2011-05-04 11:09:08 +0100368
369 # Initialize the enable flags
370 for camelcase_name, uppercase_name in self.arrays:
José Fonseca632a78d2012-04-19 07:18:59 +0100371 flag_name = '_' + uppercase_name.lower()
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100372 print(' GLboolean %s = GL_FALSE;' % flag_name)
373 print()
José Fonsecaac5285b2011-05-04 11:09:08 +0100374
375 # Switch for the interleaved formats
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100376 print(' switch (format) {')
José Fonsecaac5285b2011-05-04 11:09:08 +0100377 for format in self.interleaved_formats:
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100378 print(' case %s:' % format)
José Fonsecaac5285b2011-05-04 11:09:08 +0100379 for camelcase_name, uppercase_name in self.arrays:
José Fonseca632a78d2012-04-19 07:18:59 +0100380 flag_name = '_' + uppercase_name.lower()
José Fonsecaac5285b2011-05-04 11:09:08 +0100381 if format.find('_' + uppercase_name[0]) >= 0:
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100382 print(' %s = GL_TRUE;' % flag_name)
383 print(' break;')
384 print(' default:')
385 print(' return;')
386 print(' }')
387 print()
José Fonsecaac5285b2011-05-04 11:09:08 +0100388
389 # Emit fake glEnableClientState/glDisableClientState flags
390 for camelcase_name, uppercase_name in self.arrays:
José Fonseca632a78d2012-04-19 07:18:59 +0100391 flag_name = '_' + uppercase_name.lower()
José Fonsecaac5285b2011-05-04 11:09:08 +0100392 enable_name = 'GL_%s_ARRAY' % uppercase_name
393
394 # Emit a fake function
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100395 print(' if (%s) {' % flag_name)
396 print(' _fake_glEnableClientState(%s);' % enable_name)
397 print(' } else {')
398 print(' _fake_glDisableClientState(%s);' % enable_name)
399 print(' }')
José Fonsecaac5285b2011-05-04 11:09:08 +0100400
José Fonsecac629a8c2014-06-01 21:12:27 +0100401 # Warn about buggy glGet(GL_*ARRAY_SIZE) not returning GL_BGRA
402 buggyFunctions = {
403 'glColorPointer': ('glGetIntegerv', '', 'GL_COLOR_ARRAY_SIZE'),
404 'glSecondaryColorPointer': ('glGetIntegerv', '', 'GL_SECONDARY_COLOR_ARRAY_SIZE'),
405 'glVertexAttribPointer': ('glGetVertexAttribiv', 'index, ', 'GL_VERTEX_ATTRIB_ARRAY_SIZE'),
406 'glVertexAttribPointerARB': ('glGetVertexAttribivARB', 'index, ', 'GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB'),
407 }
408 if function.name in buggyFunctions:
409 getter, extraArg, pname = buggyFunctions[function.name]
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100410 print(r' static bool _checked = false;')
411 print(r' if (!_checked && size == GL_BGRA) {')
412 print(r' GLint _size = 0;')
413 print(r' _%s(%s%s, &_size);' % (getter, extraArg, pname))
414 print(r' if (_size != GL_BGRA) {')
415 print(r' os::log("apitrace: warning: %s(%s) does not return GL_BGRA; trace will be incorrect (https://github.com/apitrace/apitrace/issues/261)\n");' % (getter, pname))
416 print(r' }')
417 print(r' _checked = true;')
418 print(r' }')
José Fonsecac629a8c2014-06-01 21:12:27 +0100419
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100420 print(' return;')
421 print(' }')
José Fonseca14c21bc2011-02-20 23:32:22 +0000422
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000423 # ... to the draw calls
Jose Fonsecadddc5b82016-05-08 22:33:44 +0100424 mo = self.draw_function_regex.match(function.name)
425 if mo:
426 functionRadical = mo.group('radical')
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100427 print(' gltrace::Context *_ctx = gltrace::getContext();')
428 print(' if (_need_user_arrays(_ctx)) {')
José Fonseca246508e2014-08-14 16:07:46 +0100429 if 'Indirect' in function.name:
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100430 print(r' os::log("apitrace: warning: %s: indirect user arrays not supported\n");' % (function.name,))
José Fonseca246508e2014-08-14 16:07:46 +0100431 else:
Jose Fonsecadddc5b82016-05-08 22:33:44 +0100432 # Pick the corresponding *Params
433 if 'Arrays' in functionRadical:
434 paramsType = 'DrawArraysParams'
435 elif 'Elements' in functionRadical:
436 paramsType = 'DrawElementsParams'
437 else:
438 assert 0
439 if 'Multi' in functionRadical:
440 assert 'drawcount' in function.argNames()
441 paramsType = 'Multi' + paramsType
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100442 print(r' %s _params;' % paramsType)
Jose Fonsecadddc5b82016-05-08 22:33:44 +0100443
444 for arg in function.args:
445 paramsMember = arg.name.lower()
446 if paramsMember in ('mode', 'modestride'):
447 continue
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100448 print(r' _params.%s = %s;' % (paramsMember, arg.name))
Jose Fonsecadddc5b82016-05-08 22:33:44 +0100449
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100450 print(' GLuint _count = _glDraw_count(_ctx, _params);')
451 print(' _trace_user_arrays(_ctx, _count);')
452 print(' }')
José Fonseca707630d2014-03-07 14:20:35 +0000453 if function.name == 'glLockArraysEXT':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100454 print(' gltrace::Context *_ctx = gltrace::getContext();')
455 print(' if (_ctx) {')
456 print(' _ctx->lockedArrayCount = first + count;')
457 print(' }')
José Fonseca4a7d8602014-06-18 16:03:44 +0100458
459 # Warn if user arrays are used with glBegin/glArrayElement/glEnd.
460 if function.name == 'glBegin':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100461 print(r' gltrace::Context *_ctx = gltrace::getContext();')
462 print(r' _ctx->userArraysOnBegin = _need_user_arrays(_ctx);')
José Fonseca7c39d012014-11-07 19:46:53 +0000463 if function.name.startswith('glArrayElement'):
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100464 print(r' gltrace::Context *_ctx = gltrace::getContext();')
465 print(r' if (_ctx->userArraysOnBegin) {')
466 print(r' os::log("apitrace: warning: user arrays with glArrayElement not supported (https://github.com/apitrace/apitrace/issues/276)\n");')
467 print(r' _ctx->userArraysOnBegin = false;')
468 print(r' }')
José Fonseca14c21bc2011-02-20 23:32:22 +0000469
José Fonseca73373602011-05-20 17:45:26 +0100470 # Emit a fake memcpy on buffer uploads
José Fonseca9c536b02012-02-29 20:54:13 +0000471 if function.name == 'glBufferParameteriAPPLE':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100472 print(' if (pname == GL_BUFFER_FLUSHING_UNMAP_APPLE && param == GL_FALSE) {')
473 print(' _checkBufferFlushingUnmapAPPLE = true;')
474 print(' }')
José Fonsecacdc322c2012-02-29 19:29:51 +0000475 if function.name in ('glUnmapBuffer', 'glUnmapBufferARB'):
José Fonseca9c536b02012-02-29 20:54:13 +0000476 if function.name.endswith('ARB'):
477 suffix = 'ARB'
478 else:
479 suffix = ''
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100480 print(' GLint access_flags = 0;')
481 print(' GLint access = 0;')
482 print(' bool flush;')
483 print(' // GLES3 does not have GL_BUFFER_ACCESS;')
484 print(' if (_checkBufferMapRange) {')
485 print(' _glGetBufferParameteriv%s(target, GL_BUFFER_ACCESS_FLAGS, &access_flags);' % suffix)
486 print(' flush = (access_flags & GL_MAP_WRITE_BIT) && !(access_flags & (GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_PERSISTENT_BIT));')
487 print(' } else {')
488 print(' _glGetBufferParameteriv%s(target, GL_BUFFER_ACCESS, &access);' % suffix)
489 print(' flush = access != GL_READ_ONLY;')
490 print(' }')
491 print(' if (flush) {')
492 print(' GLvoid *map = NULL;')
493 print(' _glGetBufferPointerv%s(target, GL_BUFFER_MAP_POINTER, &map);' % suffix)
494 print(' if (map) {')
495 print(' GLint length = -1;')
496 print(' if (_checkBufferMapRange) {')
497 print(' _glGetBufferParameteriv%s(target, GL_BUFFER_MAP_LENGTH, &length);' % suffix)
498 print(' if (length == -1) {')
499 print(' // Mesa drivers refuse GL_BUFFER_MAP_LENGTH without GL 3.0 up-to')
500 print(' // http://cgit.freedesktop.org/mesa/mesa/commit/?id=ffee498fb848b253a7833373fe5430f8c7ca0c5f')
501 print(' static bool warned = false;')
502 print(' if (!warned) {')
503 print(' os::log("apitrace: warning: glGetBufferParameteriv%s(GL_BUFFER_MAP_LENGTH) failed\\n");' % suffix)
504 print(' warned = true;')
505 print(' }')
506 print(' }')
507 print(' } else {')
508 print(' length = 0;')
509 print(' _glGetBufferParameteriv%s(target, GL_BUFFER_SIZE, &length);' % suffix)
510 print(' }')
511 print(' if (_checkBufferFlushingUnmapAPPLE) {')
512 print(' GLint flushing_unmap = GL_TRUE;')
513 print(' _glGetBufferParameteriv%s(target, GL_BUFFER_FLUSHING_UNMAP_APPLE, &flushing_unmap);' % suffix)
514 print(' flush = flush && flushing_unmap;')
515 print(' }')
516 print(' if (flush && length > 0) {')
José Fonseca6f0e3032014-06-25 01:00:35 +0100517 self.emit_memcpy('map', 'length')
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100518 print(' }')
519 print(' }')
520 print(' }')
José Fonsecacdc322c2012-02-29 19:29:51 +0000521 if function.name == 'glUnmapBufferOES':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100522 print(' GLint access_flags = 0;')
523 print(' GLint access = 0;')
524 print(' bool flush;')
525 print(' // GLES3 does not have GL_BUFFER_ACCESS;')
526 print(' if (_checkBufferMapRange) {')
527 print(' _glGetBufferParameteriv(target, GL_BUFFER_ACCESS_FLAGS, &access_flags);')
528 print(' flush = (access_flags & GL_MAP_WRITE_BIT) && !(access_flags & (GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_PERSISTENT_BIT));')
529 print(' } else {')
530 print(' _glGetBufferParameteriv(target, GL_BUFFER_ACCESS, &access);')
531 print(' flush = access != GL_READ_ONLY;')
532 print(' }')
533 print(' if (flush) {')
534 print(' GLvoid *map = NULL;')
535 print(' _glGetBufferPointervOES(target, GL_BUFFER_MAP_POINTER, &map);')
536 print(' if (map) {')
537 print(' GLint length = 0;')
538 print(' GLint offset = 0;')
539 print(' if (_checkBufferMapRange) {')
540 print(' _glGetBufferParameteriv(target, GL_BUFFER_MAP_LENGTH, &length);')
541 print(' _glGetBufferParameteriv(target, GL_BUFFER_MAP_OFFSET, &offset);')
542 print(' } else {')
543 print(' _glGetBufferParameteriv(target, GL_BUFFER_SIZE, &length);')
544 print(' }')
545 print(' if (flush && length > 0) {')
Jose Fonsecad2fb3402015-01-24 13:42:52 +0000546 self.emit_memcpy('map', 'length')
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100547 print(' }')
548 print(' }')
549 print(' }')
José Fonseca4920c302014-08-13 18:35:57 +0100550 if function.name == 'glUnmapNamedBuffer':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100551 print(' GLint access_flags = 0;')
552 print(' _glGetNamedBufferParameteriv(buffer, GL_BUFFER_ACCESS_FLAGS, &access_flags);')
553 print(' if ((access_flags & GL_MAP_WRITE_BIT) &&')
554 print(' !(access_flags & (GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_PERSISTENT_BIT))) {')
555 print(' GLvoid *map = NULL;')
556 print(' _glGetNamedBufferPointerv(buffer, GL_BUFFER_MAP_POINTER, &map);')
557 print(' GLint length = 0;')
558 print(' _glGetNamedBufferParameteriv(buffer, GL_BUFFER_MAP_LENGTH, &length);')
559 print(' if (map && length > 0) {')
José Fonseca4920c302014-08-13 18:35:57 +0100560 self.emit_memcpy('map', 'length')
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100561 print(' }')
562 print(' }')
José Fonsecafb3bd602012-01-15 13:56:28 +0000563 if function.name == 'glUnmapNamedBufferEXT':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100564 print(' GLint access_flags = 0;')
565 print(' _glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_ACCESS_FLAGS, &access_flags);')
566 print(' if ((access_flags & GL_MAP_WRITE_BIT) &&')
567 print(' !(access_flags & (GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_PERSISTENT_BIT))) {')
568 print(' GLvoid *map = NULL;')
569 print(' _glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &map);')
570 print(' GLint length = 0;')
571 print(' _glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_MAP_LENGTH, &length);')
572 print(' if (map && length > 0) {')
José Fonseca6f0e3032014-06-25 01:00:35 +0100573 self.emit_memcpy('map', 'length')
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100574 print(' }')
575 print(' }')
José Fonseca77ef0ce2012-02-29 18:08:48 +0000576 if function.name == 'glFlushMappedBufferRange':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100577 print(' GLvoid *map = NULL;')
578 print(' _glGetBufferPointerv(target, GL_BUFFER_MAP_POINTER, &map);')
579 print(' if (map && length > 0) {')
José Fonseca6f0e3032014-06-25 01:00:35 +0100580 self.emit_memcpy('(const char *)map + offset', 'length')
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100581 print(' }')
Jose Fonsecad2fb3402015-01-24 13:42:52 +0000582 if function.name == 'glFlushMappedBufferRangeEXT':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100583 print(' GLvoid *map = NULL;')
584 print(' _glGetBufferPointervOES(target, GL_BUFFER_MAP_POINTER_OES, &map);')
585 print(' if (map && length > 0) {')
Jose Fonsecad2fb3402015-01-24 13:42:52 +0000586 self.emit_memcpy('(const char *)map + offset', 'length')
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100587 print(' }')
José Fonseca77ef0ce2012-02-29 18:08:48 +0000588 if function.name == 'glFlushMappedBufferRangeAPPLE':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100589 print(' GLvoid *map = NULL;')
590 print(' _glGetBufferPointerv(target, GL_BUFFER_MAP_POINTER, &map);')
591 print(' if (map && size > 0) {')
José Fonseca6f0e3032014-06-25 01:00:35 +0100592 self.emit_memcpy('(const char *)map + offset', 'size')
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100593 print(' }')
José Fonseca4920c302014-08-13 18:35:57 +0100594 if function.name == 'glFlushMappedNamedBufferRange':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100595 print(' GLvoid *map = NULL;')
596 print(' _glGetNamedBufferPointerv(buffer, GL_BUFFER_MAP_POINTER, &map);')
597 print(' if (map && length > 0) {')
José Fonseca4920c302014-08-13 18:35:57 +0100598 self.emit_memcpy('(const char *)map + offset', 'length')
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100599 print(' }')
José Fonsecafb3bd602012-01-15 13:56:28 +0000600 if function.name == 'glFlushMappedNamedBufferRangeEXT':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100601 print(' GLvoid *map = NULL;')
602 print(' _glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &map);')
603 print(' if (map && length > 0) {')
José Fonseca6f0e3032014-06-25 01:00:35 +0100604 self.emit_memcpy('(const char *)map + offset', 'length')
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100605 print(' }')
José Fonseca867b1b72011-04-24 11:58:04 +0100606
José Fonseca3522cbd2014-02-28 14:45:32 +0000607 # FIXME: We don't support coherent/pinned memory mappings
José Fonseca631dbd12014-12-15 16:34:45 +0000608 if function.name in ('glBufferStorage', 'glNamedBufferStorage', 'glNamedBufferStorageEXT'):
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100609 print(r' if (flags & GL_MAP_NOTIFY_EXPLICIT_BIT_VMWX) {')
610 print(r' if (!(flags & GL_MAP_PERSISTENT_BIT)) {')
611 print(r' os::log("apitrace: warning: %s: MAP_NOTIFY_EXPLICIT_BIT_VMWX set w/o MAP_PERSISTENT_BIT\n", __FUNCTION__);')
612 print(r' }')
613 print(r' if (!(flags & GL_MAP_WRITE_BIT)) {')
614 print(r' os::log("apitrace: warning: %s: MAP_NOTIFY_EXPLICIT_BIT_VMWX set w/o MAP_WRITE_BIT\n", __FUNCTION__);')
615 print(r' }')
616 print(r' flags &= ~GL_MAP_NOTIFY_EXPLICIT_BIT_VMWX;')
617 print(r' }')
Jose Fonsecad2fb3402015-01-24 13:42:52 +0000618 if function.name in ('glMapBufferRange', 'glMapBufferRangeEXT', 'glMapNamedBufferRange', 'glMapNamedBufferRangeEXT'):
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100619 print(r' if (access & GL_MAP_NOTIFY_EXPLICIT_BIT_VMWX) {')
620 print(r' if (!(access & GL_MAP_PERSISTENT_BIT)) {')
621 print(r' os::log("apitrace: warning: %s: MAP_NOTIFY_EXPLICIT_BIT_VMWX set w/o MAP_PERSISTENT_BIT\n", __FUNCTION__);')
622 print(r' }')
623 print(r' if (!(access & GL_MAP_WRITE_BIT)) {')
624 print(r' os::log("apitrace: warning: %s: MAP_NOTIFY_EXPLICIT_BIT_VMWX set w/o MAP_WRITE_BIT\n", __FUNCTION__);')
625 print(r' }')
626 print(r' if (access & GL_MAP_FLUSH_EXPLICIT_BIT) {')
627 print(r' os::log("apitrace: warning: %s: MAP_NOTIFY_EXPLICIT_BIT_VMWX set w/ MAP_FLUSH_EXPLICIT_BIT\n", __FUNCTION__);')
628 print(r' }')
629 print(r' access &= ~GL_MAP_NOTIFY_EXPLICIT_BIT_VMWX;')
630 print(r' } else if (access & GL_MAP_WRITE_BIT) {')
631 print(r' if (access & GL_MAP_COHERENT_BIT) {')
632 print(r' os::log("apitrace: warning: %s: MAP_COHERENT_BIT|MAP_WRITE_BIT unsupported <https://git.io/vV9kM>\n", __FUNCTION__);')
633 print(r' } else if ((access & GL_MAP_PERSISTENT_BIT) &&')
634 print(r' !(access & GL_MAP_FLUSH_EXPLICIT_BIT)) {')
635 print(r' os::log("apitrace: warning: %s: MAP_PERSISTENT_BIT|MAP_WRITE_BIT w/o MAP_FLUSH_EXPLICIT_BIT unsupported <https://git.io/vV9kM>\n", __FUNCTION__);')
636 print(r' }')
637 print(r' }')
José Fonseca3522cbd2014-02-28 14:45:32 +0000638 if function.name in ('glBufferData', 'glBufferDataARB'):
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100639 print(r' if (target == GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD) {')
640 print(r' os::log("apitrace: warning: GL_AMD_pinned_memory not fully supported\n");')
641 print(r' }')
José Fonseca3522cbd2014-02-28 14:45:32 +0000642
José Fonsecad0f1e292014-11-13 13:21:51 +0000643 # TODO: We don't track GL_INTEL_map_texture mappings
644 if function.name == 'glMapTexture2DINTEL':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100645 print(r' if (access & GL_MAP_WRITE_BIT) {')
646 print(r' os::log("apitrace: warning: GL_INTEL_map_texture not fully supported\n");')
647 print(r' }')
José Fonsecad0f1e292014-11-13 13:21:51 +0000648
José Fonseca91492d22011-05-23 21:20:31 +0100649 # Don't leave vertex attrib locations to chance. Instead emit fake
650 # glBindAttribLocation calls to ensure that the same locations will be
651 # used when retracing. Trying to remap locations after the fact would
652 # be an herculian task given that vertex attrib locations appear in
653 # many entry-points, including non-shader related ones.
654 if function.name == 'glLinkProgram':
José Fonseca54f304a2012-01-14 19:33:08 +0000655 Tracer.invokeFunction(self, function)
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100656 print(' GLint active_attributes = 0;')
657 print(' _glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &active_attributes);')
658 print(' for (GLint attrib = 0; attrib < active_attributes; ++attrib) {')
659 print(' GLint size = 0;')
660 print(' GLenum type = 0;')
661 print(' GLchar name[256];')
José Fonseca91492d22011-05-23 21:20:31 +0100662 # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100663 print(' _glGetActiveAttrib(program, attrib, sizeof name, NULL, &size, &type, name);')
664 print(" if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {")
665 print(' GLint location = _glGetAttribLocation(program, name);')
666 print(' if (location >= 0) {')
667 print(' _fake_glBindAttribLocation(program, location, name);')
668 print(' }')
669 print(' }')
670 print(' }')
José Fonseca91492d22011-05-23 21:20:31 +0100671 if function.name == 'glLinkProgramARB':
José Fonseca54f304a2012-01-14 19:33:08 +0000672 Tracer.invokeFunction(self, function)
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100673 print(' GLint active_attributes = 0;')
674 print(' _glGetObjectParameterivARB(programObj, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB, &active_attributes);')
675 print(' for (GLint attrib = 0; attrib < active_attributes; ++attrib) {')
676 print(' GLint size = 0;')
677 print(' GLenum type = 0;')
678 print(' GLcharARB name[256];')
José Fonseca91492d22011-05-23 21:20:31 +0100679 # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100680 print(' _glGetActiveAttribARB(programObj, attrib, sizeof name, NULL, &size, &type, name);')
681 print(" if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {")
682 print(' GLint location = _glGetAttribLocationARB(programObj, name);')
683 print(' if (location >= 0) {')
684 print(' _fake_glBindAttribLocationARB(programObj, location, name);')
685 print(' }')
686 print(' }')
687 print(' }')
José Fonseca91492d22011-05-23 21:20:31 +0100688
José Fonseca54f304a2012-01-14 19:33:08 +0000689 Tracer.traceFunctionImplBody(self, function)
José Fonseca73373602011-05-20 17:45:26 +0100690
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700691 # These entrypoints are only expected to be implemented by tools;
692 # drivers will probably not implement them.
José Fonsecaf028a8f2012-02-15 23:33:35 +0000693 marker_functions = [
694 # GL_GREMEDY_string_marker
José Fonseca8f34d342011-07-15 20:16:40 +0100695 'glStringMarkerGREMEDY',
José Fonsecaf028a8f2012-02-15 23:33:35 +0000696 # GL_GREMEDY_frame_terminator
José Fonseca8f34d342011-07-15 20:16:40 +0100697 'glFrameTerminatorGREMEDY',
698 ]
699
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700700 # These entrypoints may be implemented by drivers, but are also very useful
701 # for debugging / analysis tools.
702 debug_functions = [
703 # GL_KHR_debug
704 'glDebugMessageControl',
705 'glDebugMessageInsert',
706 'glDebugMessageCallback',
707 'glGetDebugMessageLog',
708 'glPushDebugGroup',
709 'glPopDebugGroup',
710 'glObjectLabel',
711 'glGetObjectLabel',
712 'glObjectPtrLabel',
713 'glGetObjectPtrLabel',
Jose Fonsecae01aa3b2015-06-27 11:07:05 +0100714 # GL_KHR_debug (for OpenGL ES)
715 'glDebugMessageControlKHR',
716 'glDebugMessageInsertKHR',
717 'glDebugMessageCallbackKHR',
718 'glGetDebugMessageLogKHR',
719 'glPushDebugGroupKHR',
720 'glPopDebugGroupKHR',
721 'glObjectLabelKHR',
722 'glGetObjectLabelKHR',
723 'glObjectPtrLabelKHR',
724 'glGetObjectPtrLabelKHR',
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700725 # GL_ARB_debug_output
726 'glDebugMessageControlARB',
727 'glDebugMessageInsertARB',
728 'glDebugMessageCallbackARB',
729 'glGetDebugMessageLogARB',
730 # GL_AMD_debug_output
731 'glDebugMessageEnableAMD',
732 'glDebugMessageInsertAMD',
733 'glDebugMessageCallbackAMD',
734 'glGetDebugMessageLogAMD',
José Fonseca71f5a352014-07-28 12:19:50 +0100735 # GL_EXT_debug_label
736 'glLabelObjectEXT',
737 'glGetObjectLabelEXT',
738 # GL_EXT_debug_marker
739 'glInsertEventMarkerEXT',
740 'glPushGroupMarkerEXT',
741 'glPopGroupMarkerEXT',
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700742 ]
743
José Fonseca54f304a2012-01-14 19:33:08 +0000744 def invokeFunction(self, function):
José Fonseca91492d22011-05-23 21:20:31 +0100745 if function.name in ('glLinkProgram', 'glLinkProgramARB'):
746 # These functions have been dispatched already
747 return
748
José Fonsecae0c55fd2015-01-26 22:46:13 +0000749 # Force glProgramBinary to fail. Per ARB_get_program_binary this
750 # should signal the app that it needs to recompile.
751 if function.name in ('glProgramBinary', 'glProgramBinaryOES'):
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100752 print(r' binaryFormat = 0xDEADDEAD;')
753 print(r' binary = &binaryFormat;')
754 print(r' length = sizeof binaryFormat;')
José Fonsecae0c55fd2015-01-26 22:46:13 +0000755
José Fonseca2cfa02c2013-06-10 08:05:29 +0100756 Tracer.invokeFunction(self, function)
757
758 def doInvokeFunction(self, function):
759 # Same as invokeFunction() but called both when trace is enabled or disabled.
760 #
761 # Used to modify the behavior of GL entry-points.
762
763 # Override GL extensions
764 if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'):
765 Tracer.doInvokeFunction(self, function, prefix = 'gltrace::_', suffix = '_override')
766 return
767
José Fonseca71f5a352014-07-28 12:19:50 +0100768 # We implement GL_GREMEDY_*, etc., and not the driver
José Fonsecaf028a8f2012-02-15 23:33:35 +0000769 if function.name in self.marker_functions:
José Fonseca8f34d342011-07-15 20:16:40 +0100770 return
771
Peter Lohrmann9d9eb812013-07-12 16:15:25 -0400772 # We may be faking KHR_debug, so ensure the pointer queries result is
773 # always zeroed to prevent dereference of unitialized pointers
774 if function.name == 'glGetPointerv':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100775 print(' if (params &&')
776 print(' (pname == GL_DEBUG_CALLBACK_FUNCTION ||')
777 print(' pname == GL_DEBUG_CALLBACK_USER_PARAM)) {')
778 print(' *params = NULL;')
779 print(' }')
Peter Lohrmann9d9eb812013-07-12 16:15:25 -0400780
José Fonseca2cfa02c2013-06-10 08:05:29 +0100781 if function.name in self.getProcAddressFunctionNames:
José Fonseca631dbd12014-12-15 16:34:45 +0000782 nameArg = function.args[0].name
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100783 print(' if (strcmp("glNotifyMappedBufferRangeVMWX", (const char *)%s) == 0) {' % (nameArg,))
784 print(' _result = (%s)&glNotifyMappedBufferRangeVMWX;' % (function.type,))
José Fonsecaf028a8f2012-02-15 23:33:35 +0000785 for marker_function in self.marker_functions:
José Fonseca1b6c8752012-04-15 14:33:00 +0100786 if self.api.getFunctionByName(marker_function):
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100787 print(' } else if (strcmp("%s", (const char *)%s) == 0) {' % (marker_function, nameArg))
788 print(' _result = (%s)&%s;' % (function.type, marker_function))
789 print(' } else {')
José Fonseca2cfa02c2013-06-10 08:05:29 +0100790 Tracer.doInvokeFunction(self, function)
791
792 # Replace function addresses with ours
793 # XXX: Doing this here instead of wrapRet means that the trace will
794 # contain the addresses of the wrapper functions, and not the real
795 # functions, but in practice this should make no difference.
796 if function.name in self.getProcAddressFunctionNames:
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100797 print(' _result = _wrapProcAddress(%s, _result);' % (nameArg,))
José Fonseca2cfa02c2013-06-10 08:05:29 +0100798
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100799 print(' }')
José Fonseca1b3d3752011-07-15 10:15:19 +0100800 return
801
José Fonsecae0c55fd2015-01-26 22:46:13 +0000802 if function.name in ('glGetProgramBinary', 'glGetProgramBinaryOES'):
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100803 print(r' bufSize = 0;')
José Fonsecae0c55fd2015-01-26 22:46:13 +0000804
José Fonseca2cfa02c2013-06-10 08:05:29 +0100805 Tracer.doInvokeFunction(self, function)
José Fonseca91492d22011-05-23 21:20:31 +0100806
José Fonsecae0c55fd2015-01-26 22:46:13 +0000807 if function.name == 'glGetProgramiv':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100808 print(r' if (params && pname == GL_PROGRAM_BINARY_LENGTH) {')
809 print(r' *params = 0;')
810 print(r' }')
José Fonsecae0c55fd2015-01-26 22:46:13 +0000811 if function.name in ('glGetProgramBinary', 'glGetProgramBinaryOES'):
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100812 print(r' if (length) {')
813 print(r' *length = 0;')
814 print(r' }')
José Fonsecae0c55fd2015-01-26 22:46:13 +0000815
José Fonseca867b1b72011-04-24 11:58:04 +0100816 buffer_targets = [
817 'ARRAY_BUFFER',
818 'ELEMENT_ARRAY_BUFFER',
819 'PIXEL_PACK_BUFFER',
820 'PIXEL_UNPACK_BUFFER',
José Fonseca7b20d672012-01-10 19:13:58 +0000821 'UNIFORM_BUFFER',
822 'TEXTURE_BUFFER',
823 'TRANSFORM_FEEDBACK_BUFFER',
824 'COPY_READ_BUFFER',
825 'COPY_WRITE_BUFFER',
826 'DRAW_INDIRECT_BUFFER',
827 'ATOMIC_COUNTER_BUFFER',
José Fonseca867b1b72011-04-24 11:58:04 +0100828 ]
829
José Fonseca54f304a2012-01-14 19:33:08 +0000830 def wrapRet(self, function, instance):
831 Tracer.wrapRet(self, function, instance)
José Fonseca1b3d3752011-07-15 10:15:19 +0100832
José Fonsecacdc322c2012-02-29 19:29:51 +0000833 # Keep track of buffer mappings
Jose Fonsecad2fb3402015-01-24 13:42:52 +0000834 if function.name in ('glMapBufferRange', 'glMapBufferRangeEXT'):
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100835 print(' if (access & GL_MAP_WRITE_BIT) {')
836 print(' _checkBufferMapRange = true;')
837 print(' }')
José Fonseca669b1222011-02-20 09:05:10 +0000838
José Fonsecac9f12232011-03-25 20:07:42 +0000839 boolean_names = [
840 'GL_FALSE',
841 'GL_TRUE',
842 ]
843
844 def gl_boolean(self, value):
845 return self.boolean_names[int(bool(value))]
846
José Fonsecaa442a462014-11-12 21:16:22 +0000847 # Regular expression for the names of the functions that unpack from a
848 # pixel buffer object. See the ARB_pixel_buffer_object specification.
849 unpack_function_regex = re.compile(r'^gl(' + r'|'.join([
850 r'Bitmap',
851 r'PolygonStipple',
852 r'PixelMap[a-z]+v',
853 r'DrawPixels',
854 r'Color(Sub)?Table',
855 r'(Convolution|Separable)Filter[12]D',
856 r'(Compressed)?(Multi)?Tex(ture)?(Sub)?Image[1-4]D',
857 ]) + r')[0-9A-Z]*$')
José Fonsecae97bab92011-06-02 23:15:11 +0100858
José Fonseca54f304a2012-01-14 19:33:08 +0000859 def serializeArgValue(self, function, arg):
José Fonsecae97bab92011-06-02 23:15:11 +0100860 # Recognize offsets instead of blobs when a PBO is bound
José Fonsecaa442a462014-11-12 21:16:22 +0000861 if self.unpack_function_regex.match(function.name) \
José Fonsecae97bab92011-06-02 23:15:11 +0100862 and (isinstance(arg.type, stdapi.Blob) \
863 or (isinstance(arg.type, stdapi.Const) \
864 and isinstance(arg.type.type, stdapi.Blob))):
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100865 print(' {')
866 print(' gltrace::Context *_ctx = gltrace::getContext();')
867 print(' GLint _unpack_buffer = 0;')
868 print(' if (_ctx->features.pixel_buffer_object)')
869 print(' _glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &_unpack_buffer);')
870 print(' if (_unpack_buffer) {')
871 print(' trace::localWriter.writePointer((uintptr_t)%s);' % arg.name)
872 print(' } else {')
José Fonseca54f304a2012-01-14 19:33:08 +0000873 Tracer.serializeArgValue(self, function, arg)
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100874 print(' }')
875 print(' }')
José Fonsecae97bab92011-06-02 23:15:11 +0100876 return
877
Jose Fonseca0a676c52016-04-04 23:24:32 +0100878 # Recognize offsets instead of pointers when query buffer is bound
879 if function.name.startswith('glGetQueryObject') and arg.output:
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100880 print(r' gltrace::Context *_ctx = gltrace::getContext();')
881 print(r' GLint _query_buffer = 0;')
882 print(r' if (_ctx->features.query_buffer_object) {')
883 print(r' _query_buffer = _glGetInteger(GL_QUERY_BUFFER_BINDING);')
884 print(r' }')
885 print(r' if (_query_buffer) {')
886 print(r' trace::localWriter.writePointer((uintptr_t)%s);' % arg.name)
887 print(r' } else {')
Jose Fonseca0a676c52016-04-04 23:24:32 +0100888 Tracer.serializeArgValue(self, function, arg)
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100889 print(r' }')
Jose Fonseca0a676c52016-04-04 23:24:32 +0100890 return
891
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100892 # Several GL state functions take GLenum symbolic names as
893 # integer/floats; so dump the symbolic name whenever possible
José Fonseca3bcb33c2011-05-27 20:14:31 +0100894 if function.name.startswith('gl') \
José Fonsecae3571092011-10-13 08:26:27 +0100895 and arg.type in (glapi.GLint, glapi.GLfloat, glapi.GLdouble) \
José Fonseca3bcb33c2011-05-27 20:14:31 +0100896 and arg.name == 'param':
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100897 assert arg.index > 0
898 assert function.args[arg.index - 1].name == 'pname'
899 assert function.args[arg.index - 1].type == glapi.GLenum
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100900 print(' if (is_symbolic_pname(pname) && is_symbolic_param(%s)) {' % arg.name)
José Fonseca54f304a2012-01-14 19:33:08 +0000901 self.serializeValue(glapi.GLenum, arg.name)
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100902 print(' } else {')
José Fonseca54f304a2012-01-14 19:33:08 +0000903 Tracer.serializeArgValue(self, function, arg)
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100904 print(' }')
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100905 return
906
José Fonseca54f304a2012-01-14 19:33:08 +0000907 Tracer.serializeArgValue(self, function, arg)
José Fonseca99221832011-03-22 22:15:46 +0000908
Jose Fonseca27b8d812016-05-13 07:09:09 -0700909 fake_function_names = [
910 'glBindAttribLocation',
911 'glBindAttribLocationARB',
912 'glBindBuffer',
913 'glBitmap',
914 'glClientActiveTexture',
915 'glDisableClientState',
916 'glEnableClientState',
917 'glEndList',
918 'glNewList',
919 'glScissor',
920 'glStringMarkerGREMEDY',
921 'glTexImage2D',
922 'glViewport',
923 ]
924
José Fonseca4c938c22011-04-30 22:44:38 +0100925 def footer(self, api):
926 Tracer.footer(self, api)
José Fonseca669b1222011-02-20 09:05:10 +0000927
Jose Fonseca27b8d812016-05-13 07:09:09 -0700928 # Generate helper functions to emit fake function calls into the trace
929 for function in api.getAllFunctions():
930 if function.name in self.fake_function_names:
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100931 print(function.prototype('_fake_' + function.name))
932 print(r'{')
Jose Fonseca27b8d812016-05-13 07:09:09 -0700933 self.fake_call(function, function.argNames())
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100934 print(r'}')
935 print()
Jose Fonseca27b8d812016-05-13 07:09:09 -0700936
José Fonseca4c938c22011-04-30 22:44:38 +0100937 # A simple state tracker to track the pointer values
José Fonseca669b1222011-02-20 09:05:10 +0000938 # update the state
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100939 print('static void _trace_user_arrays(gltrace::Context *_ctx, GLuint count)')
940 print('{')
941 print(' glfeatures::Profile profile = _ctx->profile;')
942 print(' bool es1 = profile.es() && profile.major == 1;')
943 print()
José Fonseca8d1408b2014-02-03 19:57:18 +0000944
Jose Fonseca97d22a72016-05-10 04:47:08 -0700945 # Some apps, in particular Quake3, can tell the driver to lock more
946 # vertices than those actually required for the draw call.
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100947 print(' count = std::max(count, _ctx->lockedArrayCount);')
948 print()
Jose Fonseca97d22a72016-05-10 04:47:08 -0700949
José Fonseca8d1408b2014-02-03 19:57:18 +0000950 # Temporarily unbind the array buffer
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100951 print(' GLint _array_buffer = _glGetInteger(GL_ARRAY_BUFFER_BINDING);')
952 print(' if (_array_buffer) {')
953 print(' _fake_glBindBuffer(GL_ARRAY_BUFFER, 0);')
954 print(' }')
955 print()
José Fonseca1a2fdd22011-04-01 00:55:09 +0100956
José Fonseca99221832011-03-22 22:15:46 +0000957 for camelcase_name, uppercase_name in self.arrays:
Chia-I Wub3d218d2011-11-03 01:37:36 +0800958 # in which profile is the array available?
José Fonseca34ea6162015-01-08 23:45:43 +0000959 profile_check = 'profile.desktop()'
Chia-I Wub3d218d2011-11-03 01:37:36 +0800960 if camelcase_name in self.arrays_es1:
José Fonsecab0c59722015-01-05 20:45:41 +0000961 profile_check = '(' + profile_check + ' || es1)';
Chia-I Wub3d218d2011-11-03 01:37:36 +0800962
José Fonseca99221832011-03-22 22:15:46 +0000963 function_name = 'gl%sPointer' % camelcase_name
964 enable_name = 'GL_%s_ARRAY' % uppercase_name
965 binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name
José Fonseca1b6c8752012-04-15 14:33:00 +0100966 function = api.getFunctionByName(function_name)
José Fonseca99221832011-03-22 22:15:46 +0000967
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100968 print(' // %s' % function.prototype())
969 print(' if (%s) {' % profile_check)
José Fonsecafb6744f2011-04-15 11:18:37 +0100970 self.array_trace_prolog(api, uppercase_name)
971 self.array_prolog(api, uppercase_name)
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100972 print(' if (_glIsEnabled(%s)) {' % enable_name)
973 print(' GLint _binding = _glGetInteger(%s);' % binding_name)
974 print(' if (!_binding) {')
José Fonseca99221832011-03-22 22:15:46 +0000975
976 # Get the arguments via glGet*
977 for arg in function.args:
978 arg_get_enum = 'GL_%s_ARRAY_%s' % (uppercase_name, arg.name.upper())
979 arg_get_function, arg_type = TypeGetter().visit(arg.type)
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100980 print(' %s %s = 0;' % (arg_type, arg.name))
981 print(' _%s(%s, &%s);' % (arg_get_function, arg_get_enum, arg.name))
José Fonseca99221832011-03-22 22:15:46 +0000982
983 arg_names = ', '.join([arg.name for arg in function.args[:-1]])
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100984 print(' size_t _size = _%s_size(%s, count);' % (function.name, arg_names))
José Fonseca99221832011-03-22 22:15:46 +0000985
986 # Emit a fake function
José Fonsecafb6744f2011-04-15 11:18:37 +0100987 self.array_trace_intermezzo(api, uppercase_name)
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100988 print(' unsigned _call = trace::localWriter.beginEnter(&_%s_sig, true);' % (function.name,))
José Fonseca669b1222011-02-20 09:05:10 +0000989 for arg in function.args:
990 assert not arg.output
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100991 print(' trace::localWriter.beginArg(%u);' % (arg.index,))
José Fonseca14c21bc2011-02-20 23:32:22 +0000992 if arg.name != 'pointer':
José Fonseca54f304a2012-01-14 19:33:08 +0000993 self.serializeValue(arg.type, arg.name)
José Fonseca14c21bc2011-02-20 23:32:22 +0000994 else:
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100995 print(' trace::localWriter.writeBlob((const void *)%s, _size);' % (arg.name))
996 print(' trace::localWriter.endArg();')
José Fonseca99221832011-03-22 22:15:46 +0000997
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100998 print(' trace::localWriter.endEnter();')
999 print(' trace::localWriter.beginLeave(_call);')
1000 print(' trace::localWriter.endLeave();')
1001 print(' }')
1002 print(' }')
José Fonsecafb6744f2011-04-15 11:18:37 +01001003 self.array_epilog(api, uppercase_name)
1004 self.array_trace_epilog(api, uppercase_name)
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +01001005 print(' }')
1006 print()
José Fonseca1a2fdd22011-04-01 00:55:09 +01001007
José Fonseca1601c412011-05-10 10:38:19 +01001008 # Samething, but for glVertexAttribPointer*
1009 #
1010 # Some variants of glVertexAttribPointer alias conventional and generic attributes:
1011 # - glVertexAttribPointer: no
1012 # - glVertexAttribPointerARB: implementation dependent
1013 # - glVertexAttribPointerNV: yes
1014 #
1015 # This means that the implementations of these functions do not always
1016 # alias, and they need to be considered independently.
1017 #
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +01001018 print(' // ES1 does not support generic vertex attributes')
1019 print(' if (es1)')
1020 print(' return;')
1021 print()
Jose Fonsecaef45b1f2016-05-08 23:31:24 +01001022
1023 function_name = 'glVertexAttribPointer'
1024 function = api.getFunctionByName(function_name)
1025
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +01001026 print(' // %s' % function.prototype())
1027 print(' GLint _max_vertex_attribs = _glGetInteger(GL_MAX_VERTEX_ATTRIBS);')
1028 print(' for (GLint index = 0; index < _max_vertex_attribs; ++index) {')
1029 print(' GLint _enabled = 0;')
1030 print(' _glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &_enabled);')
1031 print(' if (_enabled) {')
1032 print(' GLint _binding = 0;')
1033 print(' _glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &_binding);')
1034 print(' if (!_binding) {')
Jose Fonsecaef45b1f2016-05-08 23:31:24 +01001035
1036 # Get the arguments via glGet*
1037 for arg in function.args[1:]:
1038 arg_get_enum = 'GL_VERTEX_ATTRIB_ARRAY_%s' % (arg.name.upper())
1039 arg_get_function, arg_type = TypeGetter('glGetVertexAttrib', False).visit(arg.type)
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +01001040 print(' %s %s = 0;' % (arg_type, arg.name))
1041 print(' _%s(index, %s, &%s);' % (arg_get_function, arg_get_enum, arg.name))
Jose Fonsecaef45b1f2016-05-08 23:31:24 +01001042
1043 arg_names = ', '.join([arg.name for arg in function.args[1:-1]])
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +01001044 print(' size_t _size = _%s_size(%s, count);' % (function.name, arg_names))
Jose Fonsecaef45b1f2016-05-08 23:31:24 +01001045
1046 # Emit a fake function
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +01001047 print(' unsigned _call = trace::localWriter.beginEnter(&_%s_sig, true);' % (function.name,))
Jose Fonsecaef45b1f2016-05-08 23:31:24 +01001048 for arg in function.args:
1049 assert not arg.output
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +01001050 print(' trace::localWriter.beginArg(%u);' % (arg.index,))
Jose Fonsecaef45b1f2016-05-08 23:31:24 +01001051 if arg.name != 'pointer':
1052 self.serializeValue(arg.type, arg.name)
1053 else:
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +01001054 print(' trace::localWriter.writeBlob((const void *)%s, _size);' % (arg.name))
1055 print(' trace::localWriter.endArg();')
Jose Fonsecaef45b1f2016-05-08 23:31:24 +01001056
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +01001057 print(' trace::localWriter.endEnter();')
1058 print(' trace::localWriter.beginLeave(_call);')
1059 print(' trace::localWriter.endLeave();')
1060 print(' }')
1061 print(' }')
1062 print(' }')
1063 print()
José Fonseca1a2fdd22011-04-01 00:55:09 +01001064
José Fonseca8d1408b2014-02-03 19:57:18 +00001065 # Restore the original array_buffer
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +01001066 print(' if (_array_buffer) {')
1067 print(' _fake_glBindBuffer(GL_ARRAY_BUFFER, _array_buffer);')
1068 print(' }')
1069 print()
José Fonseca8d1408b2014-02-03 19:57:18 +00001070
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +01001071 print('}')
1072 print()
José Fonseca669b1222011-02-20 09:05:10 +00001073
José Fonsecafb6744f2011-04-15 11:18:37 +01001074 #
1075 # Hooks for glTexCoordPointer, which is identical to the other array
1076 # pointers except the fact that it is indexed by glClientActiveTexture.
1077 #
1078
1079 def array_prolog(self, api, uppercase_name):
1080 if uppercase_name == 'TEXTURE_COORD':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +01001081 print(' GLint max_units = 0;')
1082 print(' if (_ctx->profile.desktop())')
1083 print(' _glGetIntegerv(GL_MAX_TEXTURE_COORDS, &max_units);')
1084 print(' else')
1085 print(' _glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_units);')
1086 print(' GLint client_active_texture = GL_TEXTURE0;')
1087 print(' if (max_units > 0) {')
1088 print(' _glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE, &client_active_texture);')
1089 print(' }')
1090 print(' GLint unit = 0;')
1091 print(' do {')
1092 print(' GLint texture = GL_TEXTURE0 + unit;')
1093 print(' if (max_units > 0) {')
1094 print(' _glClientActiveTexture(texture);')
1095 print(' }')
José Fonsecafb6744f2011-04-15 11:18:37 +01001096
1097 def array_trace_prolog(self, api, uppercase_name):
1098 if uppercase_name == 'TEXTURE_COORD':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +01001099 print(' bool client_active_texture_dirty = false;')
José Fonsecafb6744f2011-04-15 11:18:37 +01001100
1101 def array_epilog(self, api, uppercase_name):
1102 if uppercase_name == 'TEXTURE_COORD':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +01001103 print(' } while (++unit < max_units);')
José Fonsecafb6744f2011-04-15 11:18:37 +01001104 self.array_cleanup(api, uppercase_name)
1105
1106 def array_cleanup(self, api, uppercase_name):
1107 if uppercase_name == 'TEXTURE_COORD':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +01001108 print(' if (max_units > 0) {')
1109 print(' _glClientActiveTexture(client_active_texture);')
1110 print(' }')
José Fonsecafb6744f2011-04-15 11:18:37 +01001111
1112 def array_trace_intermezzo(self, api, uppercase_name):
1113 if uppercase_name == 'TEXTURE_COORD':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +01001114 print(' if (texture != client_active_texture || client_active_texture_dirty) {')
1115 print(' client_active_texture_dirty = true;')
1116 print(' _fake_glClientActiveTexture(texture);')
1117 print(' }')
José Fonsecafb6744f2011-04-15 11:18:37 +01001118
1119 def array_trace_epilog(self, api, uppercase_name):
1120 if uppercase_name == 'TEXTURE_COORD':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +01001121 print(' if (client_active_texture_dirty) {')
1122 print(' _fake_glClientActiveTexture(client_active_texture);')
1123 print(' }')
José Fonsecafb6744f2011-04-15 11:18:37 +01001124
José Fonseca151c3702013-05-10 08:28:15 +01001125 def emitFakeTexture2D(self):
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +01001126 print(r' _fake_glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);')
José Fonseca669b1222011-02-20 09:05:10 +00001127