blob: 57f376a09334526d69f23901ee12c49e3873051a [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:
82 print alias.expr
83 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
José Fonseca707630d2014-03-07 14:20:35 +0000117 print '#include <algorithm>'
118 print
José Fonseca1b3d3752011-07-15 10:15:19 +0100119 print '#include "gltrace.hpp"'
120 print
José Fonseca5a568a92011-06-29 16:43:36 +0100121
122 # Which glVertexAttrib* variant to use
123 print 'enum vertex_attrib {'
124 print ' VERTEX_ATTRIB,'
José Fonseca5a568a92011-06-29 16:43:36 +0100125 print ' VERTEX_ATTRIB_NV,'
126 print '};'
127 print
José Fonseca632a78d2012-04-19 07:18:59 +0100128 print 'static vertex_attrib _get_vertex_attrib(void) {'
José Fonsecaf028a8f2012-02-15 23:33:35 +0000129 print ' gltrace::Context *ctx = gltrace::getContext();'
José Fonseca74b661a2014-07-17 19:10:24 +0100130 print ' if (ctx->user_arrays_nv) {'
José Fonseca632a78d2012-04-19 07:18:59 +0100131 print ' GLboolean _vertex_program = GL_FALSE;'
132 print ' _glGetBooleanv(GL_VERTEX_PROGRAM_ARB, &_vertex_program);'
133 print ' if (_vertex_program) {'
Chia-I Wu8ef66972011-11-03 01:19:46 +0800134 print ' if (ctx->user_arrays_nv) {'
José Fonseca26be8f92014-03-07 14:08:50 +0000135 print ' GLint _vertex_program_binding_nv = _glGetInteger(GL_VERTEX_PROGRAM_BINDING_NV);'
José Fonseca632a78d2012-04-19 07:18:59 +0100136 print ' if (_vertex_program_binding_nv) {'
José Fonseca5a568a92011-06-29 16:43:36 +0100137 print ' return VERTEX_ATTRIB_NV;'
138 print ' }'
139 print ' }'
José Fonseca5a568a92011-06-29 16:43:36 +0100140 print ' }'
141 print ' }'
142 print ' return VERTEX_ATTRIB;'
143 print '}'
144 print
145
Imre Deakd4937372012-04-24 14:06:48 +0300146 self.defineShadowBufferHelper()
147
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000148 # Whether we need user arrays
José Fonseca632a78d2012-04-19 07:18:59 +0100149 print 'static inline bool _need_user_arrays(void)'
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000150 print '{'
José Fonsecaf028a8f2012-02-15 23:33:35 +0000151 print ' gltrace::Context *ctx = gltrace::getContext();'
Chia-I Wu8ef66972011-11-03 01:19:46 +0800152 print ' if (!ctx->user_arrays) {'
José Fonseca25ebe542011-04-24 10:08:22 +0100153 print ' return false;'
154 print ' }'
155 print
José Fonsecab0c59722015-01-05 20:45:41 +0000156 print ' glprofile::Profile profile = ctx->profile;'
157 print ' bool es1 = profile.es() && profile.major == 1;'
José Fonseca8b04b5a2014-07-17 19:25:21 +0100158 print
José Fonseca1a2fdd22011-04-01 00:55:09 +0100159
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000160 for camelcase_name, uppercase_name in self.arrays:
Chia-I Wub3d218d2011-11-03 01:37:36 +0800161 # in which profile is the array available?
José Fonseca34ea6162015-01-08 23:45:43 +0000162 profile_check = 'profile.desktop()'
Chia-I Wub3d218d2011-11-03 01:37:36 +0800163 if camelcase_name in self.arrays_es1:
José Fonsecab0c59722015-01-05 20:45:41 +0000164 profile_check = '(' + profile_check + ' || es1)';
Chia-I Wub3d218d2011-11-03 01:37:36 +0800165
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000166 function_name = 'gl%sPointer' % camelcase_name
167 enable_name = 'GL_%s_ARRAY' % uppercase_name
168 binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name
169 print ' // %s' % function_name
Chia-I Wub3d218d2011-11-03 01:37:36 +0800170 print ' if (%s) {' % profile_check
José Fonsecafb6744f2011-04-15 11:18:37 +0100171 self.array_prolog(api, uppercase_name)
José Fonseca8b04b5a2014-07-17 19:25:21 +0100172 print ' if (_glIsEnabled(%s) &&' % enable_name
173 print ' _glGetInteger(%s) == 0) {' % binding_name
José Fonsecafb6744f2011-04-15 11:18:37 +0100174 self.array_cleanup(api, uppercase_name)
José Fonseca8b04b5a2014-07-17 19:25:21 +0100175 print ' return true;'
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000176 print ' }'
José Fonsecafb6744f2011-04-15 11:18:37 +0100177 self.array_epilog(api, uppercase_name)
Chia-I Wub3d218d2011-11-03 01:37:36 +0800178 print ' }'
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000179 print
José Fonseca7f5163e2011-03-31 23:37:26 +0100180
Chia-I Wub3d218d2011-11-03 01:37:36 +0800181 print ' // ES1 does not support generic vertex attributes'
José Fonsecab0c59722015-01-05 20:45:41 +0000182 print ' if (es1)'
Chia-I Wub3d218d2011-11-03 01:37:36 +0800183 print ' return false;'
184 print
José Fonseca632a78d2012-04-19 07:18:59 +0100185 print ' vertex_attrib _vertex_attrib = _get_vertex_attrib();'
José Fonseca5a568a92011-06-29 16:43:36 +0100186 print
187 print ' // glVertexAttribPointer'
José Fonseca632a78d2012-04-19 07:18:59 +0100188 print ' if (_vertex_attrib == VERTEX_ATTRIB) {'
José Fonseca26be8f92014-03-07 14:08:50 +0000189 print ' GLint _max_vertex_attribs = _glGetInteger(GL_MAX_VERTEX_ATTRIBS);'
José Fonseca632a78d2012-04-19 07:18:59 +0100190 print ' for (GLint index = 0; index < _max_vertex_attribs; ++index) {'
José Fonseca8b04b5a2014-07-17 19:25:21 +0100191 print ' if (_glGetVertexAttribi(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED) &&'
192 print ' _glGetVertexAttribi(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING) == 0) {'
193 print ' return true;'
José Fonseca5a568a92011-06-29 16:43:36 +0100194 print ' }'
195 print ' }'
196 print ' }'
197 print
José Fonseca5a568a92011-06-29 16:43:36 +0100198 print ' // glVertexAttribPointerNV'
José Fonseca632a78d2012-04-19 07:18:59 +0100199 print ' if (_vertex_attrib == VERTEX_ATTRIB_NV) {'
José Fonseca5a568a92011-06-29 16:43:36 +0100200 print ' for (GLint index = 0; index < 16; ++index) {'
José Fonseca8b04b5a2014-07-17 19:25:21 +0100201 print ' if (_glIsEnabled(GL_VERTEX_ATTRIB_ARRAY0_NV + index)) {'
José Fonseca5a568a92011-06-29 16:43:36 +0100202 print ' return true;'
José Fonseca1a2fdd22011-04-01 00:55:09 +0100203 print ' }'
204 print ' }'
205 print ' }'
206 print
207
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000208 print ' return false;'
209 print '}'
210 print
José Fonseca669b1222011-02-20 09:05:10 +0000211
José Fonseca14cb9ef2012-05-17 21:33:14 +0100212 print 'static void _trace_user_arrays(GLuint count);'
José Fonseca14c21bc2011-02-20 23:32:22 +0000213 print
José Fonseca867b1b72011-04-24 11:58:04 +0100214
José Fonseca707630d2014-03-07 14:20:35 +0000215 print '// whether glLockArraysEXT() has ever been called'
216 print 'static bool _checkLockArraysEXT = false;'
217 print
218
José Fonseca9c536b02012-02-29 20:54:13 +0000219 # Buffer mappings
220 print '// whether glMapBufferRange(GL_MAP_WRITE_BIT) has ever been called'
José Fonseca632a78d2012-04-19 07:18:59 +0100221 print 'static bool _checkBufferMapRange = false;'
José Fonseca9c536b02012-02-29 20:54:13 +0000222 print
223 print '// whether glBufferParameteriAPPLE(GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE) has ever been called'
José Fonseca632a78d2012-04-19 07:18:59 +0100224 print 'static bool _checkBufferFlushingUnmapAPPLE = false;'
José Fonseca9c536b02012-02-29 20:54:13 +0000225 print
José Fonseca867b1b72011-04-24 11:58:04 +0100226
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100227 # Generate a helper function to determine whether a parameter name
228 # refers to a symbolic value or not
229 print 'static bool'
230 print 'is_symbolic_pname(GLenum pname) {'
José Fonseca06e85192011-10-16 14:15:36 +0100231 print ' switch (pname) {'
José Fonseca5ea91872011-05-04 09:41:55 +0100232 for function, type, count, name in glparams.parameters:
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100233 if type is glapi.GLenum:
José Fonseca4c938c22011-04-30 22:44:38 +0100234 print ' case %s:' % name
235 print ' return true;'
236 print ' default:'
237 print ' return false;'
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100238 print ' }'
239 print '}'
240 print
241
242 # Generate a helper function to determine whether a parameter value is
243 # potentially symbolic or not; i.e., if the value can be represented in
244 # an enum or not
245 print 'template<class T>'
246 print 'static inline bool'
247 print 'is_symbolic_param(T param) {'
248 print ' return static_cast<T>(static_cast<GLenum>(param)) == param;'
249 print '}'
250 print
José Fonseca4c938c22011-04-30 22:44:38 +0100251
252 # Generate a helper function to know how many elements a parameter has
253 print 'static size_t'
José Fonseca632a78d2012-04-19 07:18:59 +0100254 print '_gl_param_size(GLenum pname) {'
José Fonseca06e85192011-10-16 14:15:36 +0100255 print ' switch (pname) {'
José Fonseca5ea91872011-05-04 09:41:55 +0100256 for function, type, count, name in glparams.parameters:
José Fonseca4c938c22011-04-30 22:44:38 +0100257 if type is not None:
José Fonsecaddf6d2c2012-12-20 15:34:50 +0000258 print ' case %s: return %s;' % (name, count)
José Fonseca4c938c22011-04-30 22:44:38 +0100259 print ' default:'
José Fonseca559d5342011-10-27 08:10:56 +0100260 print r' os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);'
José Fonseca4c938c22011-04-30 22:44:38 +0100261 print ' return 1;'
262 print ' }'
263 print '}'
264 print
265
Chia-I Wu335efb42011-11-03 01:59:22 +0800266 # states such as GL_UNPACK_ROW_LENGTH are not available in GLES
267 print 'static inline bool'
268 print 'can_unpack_subimage(void) {'
José Fonsecaf028a8f2012-02-15 23:33:35 +0000269 print ' gltrace::Context *ctx = gltrace::getContext();'
José Fonseca34ea6162015-01-08 23:45:43 +0000270 print ' return ctx->profile.desktop();'
Chia-I Wu335efb42011-11-03 01:59:22 +0800271 print '}'
272 print
273
José Fonseca631dbd12014-12-15 16:34:45 +0000274 # VMWX_map_buffer_debug
275 print r'extern "C" PUBLIC'
276 print r'void APIENTRY'
277 print r'glNotifyMappedBufferRangeVMWX(const void * start, GLsizeiptr length) {'
278 self.emit_memcpy('start', 'length')
279 print r'}'
280 print
281
José Fonseca1b6c8752012-04-15 14:33:00 +0100282 getProcAddressFunctionNames = []
283
284 def traceApi(self, api):
285 if self.getProcAddressFunctionNames:
286 # Generate a function to wrap proc addresses
287 getProcAddressFunction = api.getFunctionByName(self.getProcAddressFunctionNames[0])
288 argType = getProcAddressFunction.args[0].type
289 retType = getProcAddressFunction.type
290
291 print 'static %s _wrapProcAddress(%s procName, %s procPtr);' % (retType, argType, retType)
292 print
293
294 Tracer.traceApi(self, api)
295
296 print 'static %s _wrapProcAddress(%s procName, %s procPtr) {' % (retType, argType, retType)
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700297
298 # Provide fallback functions to missing debug functions
José Fonseca1b6c8752012-04-15 14:33:00 +0100299 print ' if (!procPtr) {'
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700300 else_ = ''
301 for function_name in self.debug_functions:
302 if self.api.getFunctionByName(function_name):
303 print ' %sif (strcmp("%s", (const char *)procName) == 0) {' % (else_, function_name)
304 print ' return (%s)&%s;' % (retType, function_name)
305 print ' }'
306 else_ = 'else '
307 print ' %s{' % else_
308 print ' return NULL;'
309 print ' }'
José Fonseca1b6c8752012-04-15 14:33:00 +0100310 print ' }'
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700311
José Fonseca81301932012-11-11 00:10:20 +0000312 for function in api.getAllFunctions():
José Fonseca1b6c8752012-04-15 14:33:00 +0100313 ptype = function_pointer_type(function)
314 pvalue = function_pointer_value(function)
315 print ' if (strcmp("%s", (const char *)procName) == 0) {' % function.name
316 print ' %s = (%s)procPtr;' % (pvalue, ptype)
317 print ' return (%s)&%s;' % (retType, function.name,)
318 print ' }'
319 print ' os::log("apitrace: warning: unknown function \\"%s\\"\\n", (const char *)procName);'
320 print ' return procPtr;'
321 print '}'
322 print
323 else:
324 Tracer.traceApi(self, api)
325
Imre Deakd4937372012-04-24 14:06:48 +0300326 def defineShadowBufferHelper(self):
327 print 'void _shadow_glGetBufferSubData(GLenum target, GLintptr offset,'
328 print ' GLsizeiptr size, GLvoid *data)'
329 print '{'
José Fonsecaa33d0bb2012-11-10 09:11:42 +0000330 print ' gltrace::Context *ctx = gltrace::getContext();'
Imre Deakd4937372012-04-24 14:06:48 +0300331 print ' if (!ctx->needsShadowBuffers() || target != GL_ELEMENT_ARRAY_BUFFER) {'
José Fonseca219c9f22012-11-03 10:13:17 +0000332 print ' _glGetBufferSubData(target, offset, size, data);'
Imre Deakd4937372012-04-24 14:06:48 +0300333 print ' return;'
334 print ' }'
335 print
José Fonseca26be8f92014-03-07 14:08:50 +0000336 print ' GLint buffer_binding = _glGetInteger(GL_ELEMENT_ARRAY_BUFFER_BINDING);'
José Fonseca219c9f22012-11-03 10:13:17 +0000337 print ' if (buffer_binding > 0) {'
338 print ' gltrace::Buffer & buf = ctx->buffers[buffer_binding];'
339 print ' buf.getSubData(offset, size, data);'
340 print ' }'
Imre Deakd4937372012-04-24 14:06:48 +0300341 print '}'
342
José Fonseca219c9f22012-11-03 10:13:17 +0000343 def shadowBufferMethod(self, method):
344 # Emit code to fetch the shadow buffer, and invoke a method
345 print ' gltrace::Context *ctx = gltrace::getContext();'
346 print ' if (ctx->needsShadowBuffers() && target == GL_ELEMENT_ARRAY_BUFFER) {'
José Fonseca26be8f92014-03-07 14:08:50 +0000347 print ' GLint buffer_binding = _glGetInteger(GL_ELEMENT_ARRAY_BUFFER_BINDING);'
José Fonseca219c9f22012-11-03 10:13:17 +0000348 print ' if (buffer_binding > 0) {'
349 print ' gltrace::Buffer & buf = ctx->buffers[buffer_binding];'
350 print ' buf.' + method + ';'
351 print ' }'
352 print ' }'
353 print
354
Imre Deakd4937372012-04-24 14:06:48 +0300355 def shadowBufferProlog(self, function):
356 if function.name == 'glBufferData':
José Fonseca219c9f22012-11-03 10:13:17 +0000357 self.shadowBufferMethod('bufferData(size, data)')
Imre Deakd4937372012-04-24 14:06:48 +0300358
359 if function.name == 'glBufferSubData':
José Fonseca219c9f22012-11-03 10:13:17 +0000360 self.shadowBufferMethod('bufferSubData(offset, size, data)')
Imre Deakd4937372012-04-24 14:06:48 +0300361
362 if function.name == 'glDeleteBuffers':
363 print ' gltrace::Context *ctx = gltrace::getContext();'
364 print ' if (ctx->needsShadowBuffers()) {'
José Fonseca219c9f22012-11-03 10:13:17 +0000365 print ' for (GLsizei i = 0; i < n; i++) {'
366 print ' ctx->buffers.erase(buffer[i]);'
Imre Deakd4937372012-04-24 14:06:48 +0300367 print ' }'
368 print ' }'
369
José Fonseca99221832011-03-22 22:15:46 +0000370 array_pointer_function_names = set((
371 "glVertexPointer",
372 "glNormalPointer",
373 "glColorPointer",
374 "glIndexPointer",
375 "glTexCoordPointer",
376 "glEdgeFlagPointer",
377 "glFogCoordPointer",
378 "glSecondaryColorPointer",
José Fonseca7f5163e2011-03-31 23:37:26 +0100379
José Fonsecaac5285b2011-05-04 11:09:08 +0100380 "glInterleavedArrays",
381
José Fonseca7e0bfd92011-04-30 23:09:03 +0100382 "glVertexPointerEXT",
383 "glNormalPointerEXT",
384 "glColorPointerEXT",
385 "glIndexPointerEXT",
386 "glTexCoordPointerEXT",
387 "glEdgeFlagPointerEXT",
388 "glFogCoordPointerEXT",
389 "glSecondaryColorPointerEXT",
José Fonseca99221832011-03-22 22:15:46 +0000390
José Fonseca7f5163e2011-03-31 23:37:26 +0100391 "glVertexAttribPointer",
392 "glVertexAttribPointerARB",
393 "glVertexAttribPointerNV",
José Fonsecaac5285b2011-05-04 11:09:08 +0100394 "glVertexAttribIPointer",
395 "glVertexAttribIPointerEXT",
José Fonseca7f5163e2011-03-31 23:37:26 +0100396 "glVertexAttribLPointer",
397 "glVertexAttribLPointerEXT",
José Fonseca99221832011-03-22 22:15:46 +0000398
399 #"glMatrixIndexPointerARB",
400 ))
401
José Fonsecac5bf77a2014-08-14 16:10:02 +0100402 # XXX: We currently ignore the gl*Draw*ElementArray* functions
403 draw_function_regex = re.compile(r'^gl([A-Z][a-z]+)*Draw(Range)?(Arrays|Elements)([A-Z][a-zA-Z]*)?$' )
José Fonseca99221832011-03-22 22:15:46 +0000404
José Fonsecac9f12232011-03-25 20:07:42 +0000405 interleaved_formats = [
406 'GL_V2F',
407 'GL_V3F',
408 'GL_C4UB_V2F',
409 'GL_C4UB_V3F',
410 'GL_C3F_V3F',
411 'GL_N3F_V3F',
412 'GL_C4F_N3F_V3F',
413 'GL_T2F_V3F',
414 'GL_T4F_V4F',
415 'GL_T2F_C4UB_V3F',
416 'GL_T2F_C3F_V3F',
417 'GL_T2F_N3F_V3F',
418 'GL_T2F_C4F_N3F_V3F',
419 'GL_T4F_C4F_N3F_V4F',
420 ]
421
José Fonseca54f304a2012-01-14 19:33:08 +0000422 def traceFunctionImplBody(self, function):
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000423 # Defer tracing of user array pointers...
José Fonseca99221832011-03-22 22:15:46 +0000424 if function.name in self.array_pointer_function_names:
José Fonseca26be8f92014-03-07 14:08:50 +0000425 print ' GLint _array_buffer = _glGetInteger(GL_ARRAY_BUFFER_BINDING);'
José Fonseca632a78d2012-04-19 07:18:59 +0100426 print ' if (!_array_buffer) {'
José Fonsecaf15546b2015-01-20 13:37:45 +0000427 print ' static bool warned = false;'
428 print ' if (!warned) {'
429 print ' warned = true;'
José Fonsecafe91ec32015-01-20 18:17:34 +0000430 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__);'
José Fonsecaf15546b2015-01-20 13:37:45 +0000431 print ' }'
José Fonsecaf028a8f2012-02-15 23:33:35 +0000432 print ' gltrace::Context *ctx = gltrace::getContext();'
Chia-I Wu8ef66972011-11-03 01:19:46 +0800433 print ' ctx->user_arrays = true;'
José Fonseca5a568a92011-06-29 16:43:36 +0100434 if function.name == "glVertexAttribPointerNV":
Chia-I Wu8ef66972011-11-03 01:19:46 +0800435 print ' ctx->user_arrays_nv = true;'
José Fonseca54f304a2012-01-14 19:33:08 +0000436 self.invokeFunction(function)
José Fonsecaac5285b2011-05-04 11:09:08 +0100437
438 # And also break down glInterleavedArrays into the individual calls
439 if function.name == 'glInterleavedArrays':
440 print
441
442 # Initialize the enable flags
443 for camelcase_name, uppercase_name in self.arrays:
José Fonseca632a78d2012-04-19 07:18:59 +0100444 flag_name = '_' + uppercase_name.lower()
José Fonsecaac5285b2011-05-04 11:09:08 +0100445 print ' GLboolean %s = GL_FALSE;' % flag_name
446 print
447
448 # Switch for the interleaved formats
449 print ' switch (format) {'
450 for format in self.interleaved_formats:
451 print ' case %s:' % format
452 for camelcase_name, uppercase_name in self.arrays:
José Fonseca632a78d2012-04-19 07:18:59 +0100453 flag_name = '_' + uppercase_name.lower()
José Fonsecaac5285b2011-05-04 11:09:08 +0100454 if format.find('_' + uppercase_name[0]) >= 0:
455 print ' %s = GL_TRUE;' % flag_name
456 print ' break;'
457 print ' default:'
458 print ' return;'
459 print ' }'
460 print
461
462 # Emit fake glEnableClientState/glDisableClientState flags
463 for camelcase_name, uppercase_name in self.arrays:
José Fonseca632a78d2012-04-19 07:18:59 +0100464 flag_name = '_' + uppercase_name.lower()
José Fonsecaac5285b2011-05-04 11:09:08 +0100465 enable_name = 'GL_%s_ARRAY' % uppercase_name
466
467 # Emit a fake function
468 print ' {'
José Fonseca632a78d2012-04-19 07:18:59 +0100469 print ' static const trace::FunctionSig &_sig = %s ? _glEnableClientState_sig : _glDisableClientState_sig;' % flag_name
José Fonseca7a5f23a2014-06-24 19:20:36 +0100470 print ' unsigned _call = trace::localWriter.beginEnter(&_sig, true);'
José Fonsecab4a3d142011-10-27 07:43:19 +0100471 print ' trace::localWriter.beginArg(0);'
José Fonseca54f304a2012-01-14 19:33:08 +0000472 self.serializeValue(glapi.GLenum, enable_name)
José Fonsecab4a3d142011-10-27 07:43:19 +0100473 print ' trace::localWriter.endArg();'
474 print ' trace::localWriter.endEnter();'
José Fonseca632a78d2012-04-19 07:18:59 +0100475 print ' trace::localWriter.beginLeave(_call);'
José Fonsecab4a3d142011-10-27 07:43:19 +0100476 print ' trace::localWriter.endLeave();'
José Fonsecaac5285b2011-05-04 11:09:08 +0100477 print ' }'
478
José Fonsecac629a8c2014-06-01 21:12:27 +0100479 # Warn about buggy glGet(GL_*ARRAY_SIZE) not returning GL_BGRA
480 buggyFunctions = {
481 'glColorPointer': ('glGetIntegerv', '', 'GL_COLOR_ARRAY_SIZE'),
482 'glSecondaryColorPointer': ('glGetIntegerv', '', 'GL_SECONDARY_COLOR_ARRAY_SIZE'),
483 'glVertexAttribPointer': ('glGetVertexAttribiv', 'index, ', 'GL_VERTEX_ATTRIB_ARRAY_SIZE'),
484 'glVertexAttribPointerARB': ('glGetVertexAttribivARB', 'index, ', 'GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB'),
485 }
486 if function.name in buggyFunctions:
487 getter, extraArg, pname = buggyFunctions[function.name]
488 print r' static bool _checked = false;'
489 print r' if (!_checked && size == GL_BGRA) {'
490 print r' GLint _size = 0;'
491 print r' _%s(%s%s, &_size);' % (getter, extraArg, pname)
492 print r' if (_size != GL_BGRA) {'
493 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)
494 print r' }'
495 print r' _checked = true;'
496 print r' }'
497
José Fonseca99221832011-03-22 22:15:46 +0000498 print ' return;'
499 print ' }'
José Fonseca14c21bc2011-02-20 23:32:22 +0000500
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000501 # ... to the draw calls
José Fonsecac5bf77a2014-08-14 16:10:02 +0100502 if self.draw_function_regex.match(function.name):
José Fonseca632a78d2012-04-19 07:18:59 +0100503 print ' if (_need_user_arrays()) {'
José Fonseca246508e2014-08-14 16:07:46 +0100504 if 'Indirect' in function.name:
505 print r' os::log("apitrace: warning: %s: indirect user arrays not supported\n");' % (function.name,)
506 else:
507 arg_names = ', '.join([arg.name for arg in function.args[1:]])
508 print ' GLuint _count = _%s_count(%s);' % (function.name, arg_names)
509 # Some apps, in particular Quake3, can tell the driver to lock more
510 # vertices than those actually required for the draw call.
511 print ' if (_checkLockArraysEXT) {'
512 print ' GLuint _locked_count = _glGetInteger(GL_ARRAY_ELEMENT_LOCK_FIRST_EXT)'
513 print ' + _glGetInteger(GL_ARRAY_ELEMENT_LOCK_COUNT_EXT);'
514 print ' _count = std::max(_count, _locked_count);'
515 print ' }'
516 print ' _trace_user_arrays(_count);'
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000517 print ' }'
José Fonseca707630d2014-03-07 14:20:35 +0000518 if function.name == 'glLockArraysEXT':
519 print ' _checkLockArraysEXT = true;'
José Fonseca4a7d8602014-06-18 16:03:44 +0100520
521 # Warn if user arrays are used with glBegin/glArrayElement/glEnd.
522 if function.name == 'glBegin':
José Fonseca7c39d012014-11-07 19:46:53 +0000523 print r' gltrace::Context *ctx = gltrace::getContext();'
524 print r' ctx->userArraysOnBegin = _need_user_arrays();'
525 if function.name.startswith('glArrayElement'):
526 print r' gltrace::Context *ctx = gltrace::getContext();'
527 print r' if (ctx->userArraysOnBegin) {'
José Fonseca4a7d8602014-06-18 16:03:44 +0100528 print r' os::log("apitrace: warning: user arrays with glArrayElement not supported (https://github.com/apitrace/apitrace/issues/276)\n");'
José Fonseca7c39d012014-11-07 19:46:53 +0000529 print r' ctx->userArraysOnBegin = false;'
José Fonseca4a7d8602014-06-18 16:03:44 +0100530 print r' }'
José Fonseca14c21bc2011-02-20 23:32:22 +0000531
José Fonseca73373602011-05-20 17:45:26 +0100532 # Emit a fake memcpy on buffer uploads
José Fonseca9c536b02012-02-29 20:54:13 +0000533 if function.name == 'glBufferParameteriAPPLE':
534 print ' if (pname == GL_BUFFER_FLUSHING_UNMAP_APPLE && param == GL_FALSE) {'
José Fonseca632a78d2012-04-19 07:18:59 +0100535 print ' _checkBufferFlushingUnmapAPPLE = true;'
José Fonseca9c536b02012-02-29 20:54:13 +0000536 print ' }'
José Fonsecacdc322c2012-02-29 19:29:51 +0000537 if function.name in ('glUnmapBuffer', 'glUnmapBufferARB'):
José Fonseca9c536b02012-02-29 20:54:13 +0000538 if function.name.endswith('ARB'):
539 suffix = 'ARB'
540 else:
541 suffix = ''
542 print ' GLint access = 0;'
José Fonseca632a78d2012-04-19 07:18:59 +0100543 print ' _glGetBufferParameteriv%s(target, GL_BUFFER_ACCESS, &access);' % suffix
José Fonseca9c536b02012-02-29 20:54:13 +0000544 print ' if (access != GL_READ_ONLY) {'
545 print ' GLvoid *map = NULL;'
José Fonseca632a78d2012-04-19 07:18:59 +0100546 print ' _glGetBufferPointerv%s(target, GL_BUFFER_MAP_POINTER, &map);' % suffix
José Fonseca9c536b02012-02-29 20:54:13 +0000547 print ' if (map) {'
548 print ' GLint length = -1;'
549 print ' bool flush = true;'
José Fonseca632a78d2012-04-19 07:18:59 +0100550 print ' if (_checkBufferMapRange) {'
551 print ' _glGetBufferParameteriv%s(target, GL_BUFFER_MAP_LENGTH, &length);' % suffix
José Fonseca9c536b02012-02-29 20:54:13 +0000552 print ' GLint access_flags = 0;'
José Fonseca632a78d2012-04-19 07:18:59 +0100553 print ' _glGetBufferParameteriv(target, GL_BUFFER_ACCESS_FLAGS, &access_flags);'
José Fonsecaa4210e22014-12-13 15:49:37 +0000554 print ' flush = flush && !(access_flags & (GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_PERSISTENT_BIT));'
José Fonseca9c536b02012-02-29 20:54:13 +0000555 print ' if (length == -1) {'
José Fonsecacb07e2d2014-02-04 15:14:09 +0000556 print ' // Mesa drivers refuse GL_BUFFER_MAP_LENGTH without GL 3.0 up-to'
557 print ' // http://cgit.freedesktop.org/mesa/mesa/commit/?id=ffee498fb848b253a7833373fe5430f8c7ca0c5f'
José Fonsecadb1ccce2012-02-29 21:09:24 +0000558 print ' static bool warned = false;'
559 print ' if (!warned) {'
560 print ' os::log("apitrace: warning: glGetBufferParameteriv%s(GL_BUFFER_MAP_LENGTH) failed\\n");' % suffix
561 print ' warned = true;'
562 print ' }'
José Fonseca9c536b02012-02-29 20:54:13 +0000563 print ' }'
564 print ' } else {'
565 print ' length = 0;'
José Fonseca632a78d2012-04-19 07:18:59 +0100566 print ' _glGetBufferParameteriv%s(target, GL_BUFFER_SIZE, &length);' % suffix
José Fonseca9c536b02012-02-29 20:54:13 +0000567 print ' }'
José Fonseca632a78d2012-04-19 07:18:59 +0100568 print ' if (_checkBufferFlushingUnmapAPPLE) {'
José Fonseca9c536b02012-02-29 20:54:13 +0000569 print ' GLint flushing_unmap = GL_TRUE;'
José Fonseca632a78d2012-04-19 07:18:59 +0100570 print ' _glGetBufferParameteriv%s(target, GL_BUFFER_FLUSHING_UNMAP_APPLE, &flushing_unmap);' % suffix
José Fonseca9c536b02012-02-29 20:54:13 +0000571 print ' flush = flush && flushing_unmap;'
572 print ' }'
573 print ' if (flush && length > 0) {'
José Fonseca6f0e3032014-06-25 01:00:35 +0100574 self.emit_memcpy('map', 'length')
José Fonseca9c536b02012-02-29 20:54:13 +0000575 print ' }'
576 print ' }'
577 print ' }'
José Fonsecacdc322c2012-02-29 19:29:51 +0000578 if function.name == 'glUnmapBufferOES':
579 print ' GLint access = 0;'
José Fonseca632a78d2012-04-19 07:18:59 +0100580 print ' _glGetBufferParameteriv(target, GL_BUFFER_ACCESS_OES, &access);'
José Fonsecacdc322c2012-02-29 19:29:51 +0000581 print ' if (access == GL_WRITE_ONLY_OES) {'
582 print ' GLvoid *map = NULL;'
José Fonseca632a78d2012-04-19 07:18:59 +0100583 print ' _glGetBufferPointervOES(target, GL_BUFFER_MAP_POINTER_OES, &map);'
José Fonsecacdc322c2012-02-29 19:29:51 +0000584 print ' GLint size = 0;'
José Fonseca632a78d2012-04-19 07:18:59 +0100585 print ' _glGetBufferParameteriv(target, GL_BUFFER_SIZE, &size);'
José Fonsecacdc322c2012-02-29 19:29:51 +0000586 print ' if (map && size > 0) {'
José Fonseca6f0e3032014-06-25 01:00:35 +0100587 self.emit_memcpy('map', 'size')
José Fonseca219c9f22012-11-03 10:13:17 +0000588 self.shadowBufferMethod('bufferSubData(0, size, map)')
José Fonsecacdc322c2012-02-29 19:29:51 +0000589 print ' }'
José Fonseca867b1b72011-04-24 11:58:04 +0100590 print ' }'
José Fonseca4920c302014-08-13 18:35:57 +0100591 if function.name == 'glUnmapNamedBuffer':
592 print ' GLint access_flags = 0;'
593 print ' _glGetNamedBufferParameteriv(buffer, GL_BUFFER_ACCESS_FLAGS, &access_flags);'
José Fonsecaa4210e22014-12-13 15:49:37 +0000594 print ' if ((access_flags & GL_MAP_WRITE_BIT) &&'
595 print ' !(access_flags & (GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_PERSISTENT_BIT))) {'
José Fonseca4920c302014-08-13 18:35:57 +0100596 print ' GLvoid *map = NULL;'
597 print ' _glGetNamedBufferPointerv(buffer, GL_BUFFER_MAP_POINTER, &map);'
598 print ' GLint length = 0;'
599 print ' _glGetNamedBufferParameteriv(buffer, GL_BUFFER_MAP_LENGTH, &length);'
600 print ' if (map && length > 0) {'
601 self.emit_memcpy('map', 'length')
602 print ' }'
603 print ' }'
José Fonsecafb3bd602012-01-15 13:56:28 +0000604 if function.name == 'glUnmapNamedBufferEXT':
José Fonseca024aff42012-02-29 18:00:06 +0000605 print ' GLint access_flags = 0;'
José Fonseca632a78d2012-04-19 07:18:59 +0100606 print ' _glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_ACCESS_FLAGS, &access_flags);'
José Fonsecaa4210e22014-12-13 15:49:37 +0000607 print ' if ((access_flags & GL_MAP_WRITE_BIT) &&'
608 print ' !(access_flags & (GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_PERSISTENT_BIT))) {'
José Fonsecafb3bd602012-01-15 13:56:28 +0000609 print ' GLvoid *map = NULL;'
José Fonseca632a78d2012-04-19 07:18:59 +0100610 print ' _glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &map);'
José Fonsecafb3bd602012-01-15 13:56:28 +0000611 print ' GLint length = 0;'
José Fonseca632a78d2012-04-19 07:18:59 +0100612 print ' _glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_MAP_LENGTH, &length);'
José Fonseca024aff42012-02-29 18:00:06 +0000613 print ' if (map && length > 0) {'
José Fonseca6f0e3032014-06-25 01:00:35 +0100614 self.emit_memcpy('map', 'length')
José Fonseca024aff42012-02-29 18:00:06 +0000615 print ' }'
José Fonsecafb3bd602012-01-15 13:56:28 +0000616 print ' }'
José Fonseca77ef0ce2012-02-29 18:08:48 +0000617 if function.name == 'glFlushMappedBufferRange':
618 print ' GLvoid *map = NULL;'
José Fonseca632a78d2012-04-19 07:18:59 +0100619 print ' _glGetBufferPointerv(target, GL_BUFFER_MAP_POINTER, &map);'
José Fonseca77ef0ce2012-02-29 18:08:48 +0000620 print ' if (map && length > 0) {'
José Fonseca6f0e3032014-06-25 01:00:35 +0100621 self.emit_memcpy('(const char *)map + offset', 'length')
José Fonseca77ef0ce2012-02-29 18:08:48 +0000622 print ' }'
623 if function.name == 'glFlushMappedBufferRangeAPPLE':
624 print ' GLvoid *map = NULL;'
José Fonseca632a78d2012-04-19 07:18:59 +0100625 print ' _glGetBufferPointerv(target, GL_BUFFER_MAP_POINTER, &map);'
José Fonseca77ef0ce2012-02-29 18:08:48 +0000626 print ' if (map && size > 0) {'
José Fonseca6f0e3032014-06-25 01:00:35 +0100627 self.emit_memcpy('(const char *)map + offset', 'size')
José Fonseca73373602011-05-20 17:45:26 +0100628 print ' }'
José Fonseca4920c302014-08-13 18:35:57 +0100629 if function.name == 'glFlushMappedNamedBufferRange':
630 print ' GLvoid *map = NULL;'
631 print ' _glGetNamedBufferPointerv(buffer, GL_BUFFER_MAP_POINTER, &map);'
632 print ' if (map && length > 0) {'
633 self.emit_memcpy('(const char *)map + offset', 'length')
634 print ' }'
José Fonsecafb3bd602012-01-15 13:56:28 +0000635 if function.name == 'glFlushMappedNamedBufferRangeEXT':
636 print ' GLvoid *map = NULL;'
José Fonseca632a78d2012-04-19 07:18:59 +0100637 print ' _glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &map);'
José Fonseca024aff42012-02-29 18:00:06 +0000638 print ' if (map && length > 0) {'
José Fonseca6f0e3032014-06-25 01:00:35 +0100639 self.emit_memcpy('(const char *)map + offset', 'length')
José Fonsecafb3bd602012-01-15 13:56:28 +0000640 print ' }'
José Fonseca867b1b72011-04-24 11:58:04 +0100641
José Fonseca3522cbd2014-02-28 14:45:32 +0000642 # FIXME: We don't support coherent/pinned memory mappings
José Fonseca631dbd12014-12-15 16:34:45 +0000643 if function.name in ('glBufferStorage', 'glNamedBufferStorage', 'glNamedBufferStorageEXT'):
644 print r' if (!(flags & GL_MAP_PERSISTENT_BIT)) {'
645 print r' os::log("apitrace: warning: %s: MAP_NOTIFY_EXPLICIT_BIT_VMWX set w/o MAP_PERSISTENT_BIT\n", __FUNCTION__);'
646 print r' }'
647 print r' flags &= ~GL_MAP_NOTIFY_EXPLICIT_BIT_VMWX;'
José Fonsecaa4210e22014-12-13 15:49:37 +0000648 if function.name in ('glMapBufferRange', 'glMapNamedBufferRange', 'glMapNamedBufferRangeEXT'):
José Fonseca631dbd12014-12-15 16:34:45 +0000649 print r' if (access & GL_MAP_NOTIFY_EXPLICIT_BIT_VMWX) {'
650 print r' if (!(access & GL_MAP_PERSISTENT_BIT)) {'
651 print r' os::log("apitrace: warning: %s: MAP_NOTIFY_EXPLICIT_BIT_VMWX set w/o MAP_PERSISTENT_BIT\n", __FUNCTION__);'
652 print r' }'
653 print r' if (access & GL_MAP_FLUSH_EXPLICIT_BIT) {'
654 print r' os::log("apitrace: warning: %s: MAP_NOTIFY_EXPLICIT_BIT_VMWX set w/ MAP_FLUSH_EXPLICIT_BIT\n", __FUNCTION__);'
655 print r' }'
656 print r' access &= ~GL_MAP_NOTIFY_EXPLICIT_BIT_VMWX;'
657 print r' } else if (access & GL_MAP_COHERENT_BIT) {'
José Fonsecaa4210e22014-12-13 15:49:37 +0000658 print r' os::log("apitrace: warning: %s: MAP_COHERENT_BIT unsupported (https://github.com/apitrace/apitrace/issues/232)\n", __FUNCTION__);'
659 print r' } else if ((access & GL_MAP_PERSISTENT_BIT) &&'
660 print r' !(access & GL_MAP_FLUSH_EXPLICIT_BIT)) {'
661 print r' os::log("apitrace: warning: %s: MAP_PERSISTENT_BIT w/o FLUSH_EXPLICIT_BIT unsupported (https://github.com/apitrace/apitrace/issues/232)\n", __FUNCTION__);'
José Fonseca3522cbd2014-02-28 14:45:32 +0000662 print r' }'
663 if function.name in ('glBufferData', 'glBufferDataARB'):
664 print r' if (target == GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD) {'
665 print r' os::log("apitrace: warning: GL_AMD_pinned_memory not fully supported\n");'
666 print r' }'
667
José Fonsecad0f1e292014-11-13 13:21:51 +0000668 # TODO: We don't track GL_INTEL_map_texture mappings
669 if function.name == 'glMapTexture2DINTEL':
670 print r' if (access & GL_MAP_WRITE_BIT) {'
671 print r' os::log("apitrace: warning: GL_INTEL_map_texture not fully supported\n");'
672 print r' }'
673
José Fonseca91492d22011-05-23 21:20:31 +0100674 # Don't leave vertex attrib locations to chance. Instead emit fake
675 # glBindAttribLocation calls to ensure that the same locations will be
676 # used when retracing. Trying to remap locations after the fact would
677 # be an herculian task given that vertex attrib locations appear in
678 # many entry-points, including non-shader related ones.
679 if function.name == 'glLinkProgram':
José Fonseca54f304a2012-01-14 19:33:08 +0000680 Tracer.invokeFunction(self, function)
José Fonseca91492d22011-05-23 21:20:31 +0100681 print ' GLint active_attributes = 0;'
José Fonseca632a78d2012-04-19 07:18:59 +0100682 print ' _glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &active_attributes);'
José Fonseca7525e6f2011-09-28 09:04:56 +0100683 print ' for (GLint attrib = 0; attrib < active_attributes; ++attrib) {'
José Fonseca91492d22011-05-23 21:20:31 +0100684 print ' GLint size = 0;'
685 print ' GLenum type = 0;'
686 print ' GLchar name[256];'
687 # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256
José Fonseca632a78d2012-04-19 07:18:59 +0100688 print ' _glGetActiveAttrib(program, attrib, sizeof name, NULL, &size, &type, name);'
José Fonseca2a794f52011-05-26 20:54:29 +0100689 print " if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {"
José Fonseca632a78d2012-04-19 07:18:59 +0100690 print ' GLint location = _glGetAttribLocation(program, name);'
José Fonseca2a794f52011-05-26 20:54:29 +0100691 print ' if (location >= 0) {'
José Fonseca1b6c8752012-04-15 14:33:00 +0100692 bind_function = glapi.glapi.getFunctionByName('glBindAttribLocation')
José Fonseca91492d22011-05-23 21:20:31 +0100693 self.fake_call(bind_function, ['program', 'location', 'name'])
José Fonseca2a794f52011-05-26 20:54:29 +0100694 print ' }'
José Fonseca91492d22011-05-23 21:20:31 +0100695 print ' }'
696 print ' }'
697 if function.name == 'glLinkProgramARB':
José Fonseca54f304a2012-01-14 19:33:08 +0000698 Tracer.invokeFunction(self, function)
José Fonseca91492d22011-05-23 21:20:31 +0100699 print ' GLint active_attributes = 0;'
José Fonseca632a78d2012-04-19 07:18:59 +0100700 print ' _glGetObjectParameterivARB(programObj, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB, &active_attributes);'
José Fonseca7525e6f2011-09-28 09:04:56 +0100701 print ' for (GLint attrib = 0; attrib < active_attributes; ++attrib) {'
José Fonseca91492d22011-05-23 21:20:31 +0100702 print ' GLint size = 0;'
703 print ' GLenum type = 0;'
704 print ' GLcharARB name[256];'
705 # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256
José Fonseca632a78d2012-04-19 07:18:59 +0100706 print ' _glGetActiveAttribARB(programObj, attrib, sizeof name, NULL, &size, &type, name);'
José Fonseca2a794f52011-05-26 20:54:29 +0100707 print " if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {"
José Fonseca632a78d2012-04-19 07:18:59 +0100708 print ' GLint location = _glGetAttribLocationARB(programObj, name);'
José Fonseca2a794f52011-05-26 20:54:29 +0100709 print ' if (location >= 0) {'
José Fonseca1b6c8752012-04-15 14:33:00 +0100710 bind_function = glapi.glapi.getFunctionByName('glBindAttribLocationARB')
José Fonseca91492d22011-05-23 21:20:31 +0100711 self.fake_call(bind_function, ['programObj', 'location', 'name'])
José Fonseca2a794f52011-05-26 20:54:29 +0100712 print ' }'
José Fonseca91492d22011-05-23 21:20:31 +0100713 print ' }'
714 print ' }'
715
Imre Deakd4937372012-04-24 14:06:48 +0300716 self.shadowBufferProlog(function)
717
José Fonseca54f304a2012-01-14 19:33:08 +0000718 Tracer.traceFunctionImplBody(self, function)
José Fonseca73373602011-05-20 17:45:26 +0100719
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700720 # These entrypoints are only expected to be implemented by tools;
721 # drivers will probably not implement them.
José Fonsecaf028a8f2012-02-15 23:33:35 +0000722 marker_functions = [
723 # GL_GREMEDY_string_marker
José Fonseca8f34d342011-07-15 20:16:40 +0100724 'glStringMarkerGREMEDY',
José Fonsecaf028a8f2012-02-15 23:33:35 +0000725 # GL_GREMEDY_frame_terminator
José Fonseca8f34d342011-07-15 20:16:40 +0100726 'glFrameTerminatorGREMEDY',
727 ]
728
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700729 # These entrypoints may be implemented by drivers, but are also very useful
730 # for debugging / analysis tools.
731 debug_functions = [
732 # GL_KHR_debug
733 'glDebugMessageControl',
734 'glDebugMessageInsert',
735 'glDebugMessageCallback',
736 'glGetDebugMessageLog',
737 'glPushDebugGroup',
738 'glPopDebugGroup',
739 'glObjectLabel',
740 'glGetObjectLabel',
741 'glObjectPtrLabel',
742 'glGetObjectPtrLabel',
743 # GL_ARB_debug_output
744 'glDebugMessageControlARB',
745 'glDebugMessageInsertARB',
746 'glDebugMessageCallbackARB',
747 'glGetDebugMessageLogARB',
748 # GL_AMD_debug_output
749 'glDebugMessageEnableAMD',
750 'glDebugMessageInsertAMD',
751 'glDebugMessageCallbackAMD',
752 'glGetDebugMessageLogAMD',
José Fonseca71f5a352014-07-28 12:19:50 +0100753 # GL_EXT_debug_label
754 'glLabelObjectEXT',
755 'glGetObjectLabelEXT',
756 # GL_EXT_debug_marker
757 'glInsertEventMarkerEXT',
758 'glPushGroupMarkerEXT',
759 'glPopGroupMarkerEXT',
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700760 ]
761
José Fonseca54f304a2012-01-14 19:33:08 +0000762 def invokeFunction(self, function):
José Fonseca91492d22011-05-23 21:20:31 +0100763 if function.name in ('glLinkProgram', 'glLinkProgramARB'):
764 # These functions have been dispatched already
765 return
766
José Fonseca2cfa02c2013-06-10 08:05:29 +0100767 Tracer.invokeFunction(self, function)
768
769 def doInvokeFunction(self, function):
770 # Same as invokeFunction() but called both when trace is enabled or disabled.
771 #
772 # Used to modify the behavior of GL entry-points.
773
774 # Override GL extensions
775 if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'):
776 Tracer.doInvokeFunction(self, function, prefix = 'gltrace::_', suffix = '_override')
777 return
778
José Fonseca71f5a352014-07-28 12:19:50 +0100779 # We implement GL_GREMEDY_*, etc., and not the driver
José Fonsecaf028a8f2012-02-15 23:33:35 +0000780 if function.name in self.marker_functions:
José Fonseca8f34d342011-07-15 20:16:40 +0100781 return
782
Peter Lohrmann9d9eb812013-07-12 16:15:25 -0400783 # We may be faking KHR_debug, so ensure the pointer queries result is
784 # always zeroed to prevent dereference of unitialized pointers
785 if function.name == 'glGetPointerv':
786 print ' if (params &&'
787 print ' (pname == GL_DEBUG_CALLBACK_FUNCTION ||'
788 print ' pname == GL_DEBUG_CALLBACK_USER_PARAM)) {'
789 print ' *params = NULL;'
790 print ' }'
791
José Fonseca2cfa02c2013-06-10 08:05:29 +0100792 if function.name in self.getProcAddressFunctionNames:
José Fonseca631dbd12014-12-15 16:34:45 +0000793 nameArg = function.args[0].name
794 print ' if (strcmp("glNotifyMappedBufferRangeVMWX", (const char *)%s) == 0) {' % (nameArg,)
795 print ' _result = (%s)&glNotifyMappedBufferRangeVMWX;' % (function.type,)
José Fonsecaf028a8f2012-02-15 23:33:35 +0000796 for marker_function in self.marker_functions:
José Fonseca1b6c8752012-04-15 14:33:00 +0100797 if self.api.getFunctionByName(marker_function):
José Fonseca631dbd12014-12-15 16:34:45 +0000798 print ' } else if (strcmp("%s", (const char *)%s) == 0) {' % (marker_function, nameArg)
José Fonseca632a78d2012-04-19 07:18:59 +0100799 print ' _result = (%s)&%s;' % (function.type, marker_function)
José Fonseca631dbd12014-12-15 16:34:45 +0000800 print ' } else {'
José Fonseca2cfa02c2013-06-10 08:05:29 +0100801 Tracer.doInvokeFunction(self, function)
802
803 # Replace function addresses with ours
804 # XXX: Doing this here instead of wrapRet means that the trace will
805 # contain the addresses of the wrapper functions, and not the real
806 # functions, but in practice this should make no difference.
807 if function.name in self.getProcAddressFunctionNames:
José Fonseca631dbd12014-12-15 16:34:45 +0000808 print ' _result = _wrapProcAddress(%s, _result);' % (nameArg,)
José Fonseca2cfa02c2013-06-10 08:05:29 +0100809
José Fonseca8f34d342011-07-15 20:16:40 +0100810 print ' }'
José Fonseca1b3d3752011-07-15 10:15:19 +0100811 return
812
José Fonseca2cfa02c2013-06-10 08:05:29 +0100813 Tracer.doInvokeFunction(self, function)
José Fonseca91492d22011-05-23 21:20:31 +0100814
José Fonseca867b1b72011-04-24 11:58:04 +0100815 buffer_targets = [
816 'ARRAY_BUFFER',
817 'ELEMENT_ARRAY_BUFFER',
818 'PIXEL_PACK_BUFFER',
819 'PIXEL_UNPACK_BUFFER',
José Fonseca7b20d672012-01-10 19:13:58 +0000820 'UNIFORM_BUFFER',
821 'TEXTURE_BUFFER',
822 'TRANSFORM_FEEDBACK_BUFFER',
823 'COPY_READ_BUFFER',
824 'COPY_WRITE_BUFFER',
825 'DRAW_INDIRECT_BUFFER',
826 'ATOMIC_COUNTER_BUFFER',
José Fonseca867b1b72011-04-24 11:58:04 +0100827 ]
828
José Fonseca54f304a2012-01-14 19:33:08 +0000829 def wrapRet(self, function, instance):
830 Tracer.wrapRet(self, function, instance)
José Fonseca1b3d3752011-07-15 10:15:19 +0100831
José Fonsecacdc322c2012-02-29 19:29:51 +0000832 # Keep track of buffer mappings
José Fonseca867b1b72011-04-24 11:58:04 +0100833 if function.name == 'glMapBufferRange':
José Fonseca9c536b02012-02-29 20:54:13 +0000834 print ' if (access & GL_MAP_WRITE_BIT) {'
José Fonseca632a78d2012-04-19 07:18:59 +0100835 print ' _checkBufferMapRange = true;'
José Fonseca9c536b02012-02-29 20:54:13 +0000836 print ' }'
José Fonseca669b1222011-02-20 09:05:10 +0000837
José Fonsecac9f12232011-03-25 20:07:42 +0000838 boolean_names = [
839 'GL_FALSE',
840 'GL_TRUE',
841 ]
842
843 def gl_boolean(self, value):
844 return self.boolean_names[int(bool(value))]
845
José Fonsecaa442a462014-11-12 21:16:22 +0000846 # Regular expression for the names of the functions that unpack from a
847 # pixel buffer object. See the ARB_pixel_buffer_object specification.
848 unpack_function_regex = re.compile(r'^gl(' + r'|'.join([
849 r'Bitmap',
850 r'PolygonStipple',
851 r'PixelMap[a-z]+v',
852 r'DrawPixels',
853 r'Color(Sub)?Table',
854 r'(Convolution|Separable)Filter[12]D',
855 r'(Compressed)?(Multi)?Tex(ture)?(Sub)?Image[1-4]D',
856 ]) + r')[0-9A-Z]*$')
José Fonsecae97bab92011-06-02 23:15:11 +0100857
José Fonseca54f304a2012-01-14 19:33:08 +0000858 def serializeArgValue(self, function, arg):
José Fonsecae97bab92011-06-02 23:15:11 +0100859 # Recognize offsets instead of blobs when a PBO is bound
José Fonsecaa442a462014-11-12 21:16:22 +0000860 if self.unpack_function_regex.match(function.name) \
José Fonsecae97bab92011-06-02 23:15:11 +0100861 and (isinstance(arg.type, stdapi.Blob) \
862 or (isinstance(arg.type, stdapi.Const) \
863 and isinstance(arg.type.type, stdapi.Blob))):
José Fonsecac29f4f12011-06-11 12:19:05 +0100864 print ' {'
José Fonsecaf028a8f2012-02-15 23:33:35 +0000865 print ' gltrace::Context *ctx = gltrace::getContext();'
José Fonseca632a78d2012-04-19 07:18:59 +0100866 print ' GLint _unpack_buffer = 0;'
José Fonseca34ea6162015-01-08 23:45:43 +0000867 print ' if (ctx->profile.desktop())'
José Fonseca632a78d2012-04-19 07:18:59 +0100868 print ' _glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &_unpack_buffer);'
869 print ' if (_unpack_buffer) {'
José Fonsecad559f022012-04-15 16:13:51 +0100870 print ' trace::localWriter.writePointer((uintptr_t)%s);' % arg.name
José Fonsecac29f4f12011-06-11 12:19:05 +0100871 print ' } else {'
José Fonseca54f304a2012-01-14 19:33:08 +0000872 Tracer.serializeArgValue(self, function, arg)
José Fonsecac29f4f12011-06-11 12:19:05 +0100873 print ' }'
José Fonsecae97bab92011-06-02 23:15:11 +0100874 print ' }'
875 return
876
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100877 # Several GL state functions take GLenum symbolic names as
878 # integer/floats; so dump the symbolic name whenever possible
José Fonseca3bcb33c2011-05-27 20:14:31 +0100879 if function.name.startswith('gl') \
José Fonsecae3571092011-10-13 08:26:27 +0100880 and arg.type in (glapi.GLint, glapi.GLfloat, glapi.GLdouble) \
José Fonseca3bcb33c2011-05-27 20:14:31 +0100881 and arg.name == 'param':
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100882 assert arg.index > 0
883 assert function.args[arg.index - 1].name == 'pname'
884 assert function.args[arg.index - 1].type == glapi.GLenum
885 print ' if (is_symbolic_pname(pname) && is_symbolic_param(%s)) {' % arg.name
José Fonseca54f304a2012-01-14 19:33:08 +0000886 self.serializeValue(glapi.GLenum, arg.name)
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100887 print ' } else {'
José Fonseca54f304a2012-01-14 19:33:08 +0000888 Tracer.serializeArgValue(self, function, arg)
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100889 print ' }'
890 return
891
José Fonseca54f304a2012-01-14 19:33:08 +0000892 Tracer.serializeArgValue(self, function, arg)
José Fonseca99221832011-03-22 22:15:46 +0000893
José Fonseca4c938c22011-04-30 22:44:38 +0100894 def footer(self, api):
895 Tracer.footer(self, api)
José Fonseca669b1222011-02-20 09:05:10 +0000896
José Fonseca4c938c22011-04-30 22:44:38 +0100897 # A simple state tracker to track the pointer values
José Fonseca669b1222011-02-20 09:05:10 +0000898 # update the state
José Fonseca14cb9ef2012-05-17 21:33:14 +0100899 print 'static void _trace_user_arrays(GLuint count)'
José Fonseca669b1222011-02-20 09:05:10 +0000900 print '{'
José Fonsecaf028a8f2012-02-15 23:33:35 +0000901 print ' gltrace::Context *ctx = gltrace::getContext();'
José Fonseca8d1408b2014-02-03 19:57:18 +0000902 print
José Fonsecab0c59722015-01-05 20:45:41 +0000903 print ' glprofile::Profile profile = ctx->profile;'
904 print ' bool es1 = profile.es() && profile.major == 1;'
905 print
José Fonseca8d1408b2014-02-03 19:57:18 +0000906
907 # Temporarily unbind the array buffer
José Fonseca26be8f92014-03-07 14:08:50 +0000908 print ' GLint _array_buffer = _glGetInteger(GL_ARRAY_BUFFER_BINDING);'
José Fonseca8d1408b2014-02-03 19:57:18 +0000909 print ' if (_array_buffer) {'
910 self.fake_glBindBuffer(api, 'GL_ARRAY_BUFFER', '0')
911 print ' }'
912 print
José Fonseca1a2fdd22011-04-01 00:55:09 +0100913
José Fonseca99221832011-03-22 22:15:46 +0000914 for camelcase_name, uppercase_name in self.arrays:
Chia-I Wub3d218d2011-11-03 01:37:36 +0800915 # in which profile is the array available?
José Fonseca34ea6162015-01-08 23:45:43 +0000916 profile_check = 'profile.desktop()'
Chia-I Wub3d218d2011-11-03 01:37:36 +0800917 if camelcase_name in self.arrays_es1:
José Fonsecab0c59722015-01-05 20:45:41 +0000918 profile_check = '(' + profile_check + ' || es1)';
Chia-I Wub3d218d2011-11-03 01:37:36 +0800919
José Fonseca99221832011-03-22 22:15:46 +0000920 function_name = 'gl%sPointer' % camelcase_name
921 enable_name = 'GL_%s_ARRAY' % uppercase_name
922 binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name
José Fonseca1b6c8752012-04-15 14:33:00 +0100923 function = api.getFunctionByName(function_name)
José Fonseca99221832011-03-22 22:15:46 +0000924
José Fonseca06e85192011-10-16 14:15:36 +0100925 print ' // %s' % function.prototype()
Chia-I Wub3d218d2011-11-03 01:37:36 +0800926 print ' if (%s) {' % profile_check
José Fonsecafb6744f2011-04-15 11:18:37 +0100927 self.array_trace_prolog(api, uppercase_name)
928 self.array_prolog(api, uppercase_name)
José Fonseca632a78d2012-04-19 07:18:59 +0100929 print ' if (_glIsEnabled(%s)) {' % enable_name
José Fonseca26be8f92014-03-07 14:08:50 +0000930 print ' GLint _binding = _glGetInteger(%s);' % binding_name
José Fonseca632a78d2012-04-19 07:18:59 +0100931 print ' if (!_binding) {'
José Fonseca99221832011-03-22 22:15:46 +0000932
933 # Get the arguments via glGet*
934 for arg in function.args:
935 arg_get_enum = 'GL_%s_ARRAY_%s' % (uppercase_name, arg.name.upper())
936 arg_get_function, arg_type = TypeGetter().visit(arg.type)
José Fonseca7f5163e2011-03-31 23:37:26 +0100937 print ' %s %s = 0;' % (arg_type, arg.name)
José Fonseca632a78d2012-04-19 07:18:59 +0100938 print ' _%s(%s, &%s);' % (arg_get_function, arg_get_enum, arg.name)
José Fonseca99221832011-03-22 22:15:46 +0000939
940 arg_names = ', '.join([arg.name for arg in function.args[:-1]])
José Fonseca14cb9ef2012-05-17 21:33:14 +0100941 print ' size_t _size = _%s_size(%s, count);' % (function.name, arg_names)
José Fonseca99221832011-03-22 22:15:46 +0000942
943 # Emit a fake function
José Fonsecafb6744f2011-04-15 11:18:37 +0100944 self.array_trace_intermezzo(api, uppercase_name)
José Fonseca7a5f23a2014-06-24 19:20:36 +0100945 print ' unsigned _call = trace::localWriter.beginEnter(&_%s_sig, true);' % (function.name,)
José Fonseca669b1222011-02-20 09:05:10 +0000946 for arg in function.args:
947 assert not arg.output
José Fonsecab4a3d142011-10-27 07:43:19 +0100948 print ' trace::localWriter.beginArg(%u);' % (arg.index,)
José Fonseca14c21bc2011-02-20 23:32:22 +0000949 if arg.name != 'pointer':
José Fonseca54f304a2012-01-14 19:33:08 +0000950 self.serializeValue(arg.type, arg.name)
José Fonseca14c21bc2011-02-20 23:32:22 +0000951 else:
José Fonseca632a78d2012-04-19 07:18:59 +0100952 print ' trace::localWriter.writeBlob((const void *)%s, _size);' % (arg.name)
José Fonsecab4a3d142011-10-27 07:43:19 +0100953 print ' trace::localWriter.endArg();'
José Fonseca99221832011-03-22 22:15:46 +0000954
José Fonsecab4a3d142011-10-27 07:43:19 +0100955 print ' trace::localWriter.endEnter();'
José Fonseca632a78d2012-04-19 07:18:59 +0100956 print ' trace::localWriter.beginLeave(_call);'
José Fonsecab4a3d142011-10-27 07:43:19 +0100957 print ' trace::localWriter.endLeave();'
José Fonseca99221832011-03-22 22:15:46 +0000958 print ' }'
José Fonseca669b1222011-02-20 09:05:10 +0000959 print ' }'
José Fonsecafb6744f2011-04-15 11:18:37 +0100960 self.array_epilog(api, uppercase_name)
961 self.array_trace_epilog(api, uppercase_name)
Chia-I Wub3d218d2011-11-03 01:37:36 +0800962 print ' }'
José Fonseca99221832011-03-22 22:15:46 +0000963 print
José Fonseca1a2fdd22011-04-01 00:55:09 +0100964
José Fonseca1601c412011-05-10 10:38:19 +0100965 # Samething, but for glVertexAttribPointer*
966 #
967 # Some variants of glVertexAttribPointer alias conventional and generic attributes:
968 # - glVertexAttribPointer: no
969 # - glVertexAttribPointerARB: implementation dependent
970 # - glVertexAttribPointerNV: yes
971 #
972 # This means that the implementations of these functions do not always
973 # alias, and they need to be considered independently.
974 #
Chia-I Wub3d218d2011-11-03 01:37:36 +0800975 print ' // ES1 does not support generic vertex attributes'
José Fonsecab0c59722015-01-05 20:45:41 +0000976 print ' if (es1)'
Chia-I Wub3d218d2011-11-03 01:37:36 +0800977 print ' return;'
978 print
José Fonseca632a78d2012-04-19 07:18:59 +0100979 print ' vertex_attrib _vertex_attrib = _get_vertex_attrib();'
José Fonseca5a568a92011-06-29 16:43:36 +0100980 print
José Fonseca74b661a2014-07-17 19:10:24 +0100981 for suffix in ['', 'NV']:
José Fonseca5a568a92011-06-29 16:43:36 +0100982 if suffix:
José Fonsecad94aaac2011-06-28 20:50:49 +0100983 SUFFIX = '_' + suffix
José Fonsecad94aaac2011-06-28 20:50:49 +0100984 else:
José Fonseca5a568a92011-06-29 16:43:36 +0100985 SUFFIX = suffix
José Fonseca1601c412011-05-10 10:38:19 +0100986 function_name = 'glVertexAttribPointer' + suffix
José Fonseca1b6c8752012-04-15 14:33:00 +0100987 function = api.getFunctionByName(function_name)
José Fonseca06e85192011-10-16 14:15:36 +0100988
989 print ' // %s' % function.prototype()
José Fonseca632a78d2012-04-19 07:18:59 +0100990 print ' if (_vertex_attrib == VERTEX_ATTRIB%s) {' % SUFFIX
José Fonseca5a568a92011-06-29 16:43:36 +0100991 if suffix == 'NV':
José Fonseca632a78d2012-04-19 07:18:59 +0100992 print ' GLint _max_vertex_attribs = 16;'
José Fonseca5a568a92011-06-29 16:43:36 +0100993 else:
José Fonseca26be8f92014-03-07 14:08:50 +0000994 print ' GLint _max_vertex_attribs = _glGetInteger(GL_MAX_VERTEX_ATTRIBS);'
José Fonseca632a78d2012-04-19 07:18:59 +0100995 print ' for (GLint index = 0; index < _max_vertex_attribs; ++index) {'
996 print ' GLint _enabled = 0;'
José Fonseca5a568a92011-06-29 16:43:36 +0100997 if suffix == 'NV':
José Fonseca632a78d2012-04-19 07:18:59 +0100998 print ' _glGetIntegerv(GL_VERTEX_ATTRIB_ARRAY0_NV + index, &_enabled);'
José Fonseca5a568a92011-06-29 16:43:36 +0100999 else:
José Fonseca632a78d2012-04-19 07:18:59 +01001000 print ' _glGetVertexAttribiv%s(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED%s, &_enabled);' % (suffix, SUFFIX)
1001 print ' if (_enabled) {'
1002 print ' GLint _binding = 0;'
José Fonseca5a568a92011-06-29 16:43:36 +01001003 if suffix != 'NV':
1004 # It doesn't seem possible to use VBOs with NV_vertex_program.
José Fonseca632a78d2012-04-19 07:18:59 +01001005 print ' _glGetVertexAttribiv%s(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING%s, &_binding);' % (suffix, SUFFIX)
1006 print ' if (!_binding) {'
José Fonseca1a2fdd22011-04-01 00:55:09 +01001007
José Fonseca1601c412011-05-10 10:38:19 +01001008 # Get the arguments via glGet*
1009 for arg in function.args[1:]:
José Fonseca5a568a92011-06-29 16:43:36 +01001010 if suffix == 'NV':
1011 arg_get_enum = 'GL_ATTRIB_ARRAY_%s%s' % (arg.name.upper(), SUFFIX)
1012 else:
1013 arg_get_enum = 'GL_VERTEX_ATTRIB_ARRAY_%s%s' % (arg.name.upper(), SUFFIX)
José Fonsecac493e3e2011-06-29 12:57:06 +01001014 arg_get_function, arg_type = TypeGetter('glGetVertexAttrib', False, suffix).visit(arg.type)
José Fonseca5a568a92011-06-29 16:43:36 +01001015 print ' %s %s = 0;' % (arg_type, arg.name)
José Fonseca632a78d2012-04-19 07:18:59 +01001016 print ' _%s(index, %s, &%s);' % (arg_get_function, arg_get_enum, arg.name)
José Fonseca1601c412011-05-10 10:38:19 +01001017
1018 arg_names = ', '.join([arg.name for arg in function.args[1:-1]])
José Fonseca14cb9ef2012-05-17 21:33:14 +01001019 print ' size_t _size = _%s_size(%s, count);' % (function.name, arg_names)
José Fonseca1a2fdd22011-04-01 00:55:09 +01001020
José Fonseca1601c412011-05-10 10:38:19 +01001021 # Emit a fake function
José Fonseca7a5f23a2014-06-24 19:20:36 +01001022 print ' unsigned _call = trace::localWriter.beginEnter(&_%s_sig, true);' % (function.name,)
José Fonseca1601c412011-05-10 10:38:19 +01001023 for arg in function.args:
1024 assert not arg.output
José Fonsecab4a3d142011-10-27 07:43:19 +01001025 print ' trace::localWriter.beginArg(%u);' % (arg.index,)
José Fonseca1601c412011-05-10 10:38:19 +01001026 if arg.name != 'pointer':
José Fonseca54f304a2012-01-14 19:33:08 +00001027 self.serializeValue(arg.type, arg.name)
José Fonseca1601c412011-05-10 10:38:19 +01001028 else:
José Fonseca632a78d2012-04-19 07:18:59 +01001029 print ' trace::localWriter.writeBlob((const void *)%s, _size);' % (arg.name)
José Fonsecab4a3d142011-10-27 07:43:19 +01001030 print ' trace::localWriter.endArg();'
José Fonseca1601c412011-05-10 10:38:19 +01001031
José Fonsecab4a3d142011-10-27 07:43:19 +01001032 print ' trace::localWriter.endEnter();'
José Fonseca632a78d2012-04-19 07:18:59 +01001033 print ' trace::localWriter.beginLeave(_call);'
José Fonsecab4a3d142011-10-27 07:43:19 +01001034 print ' trace::localWriter.endLeave();'
José Fonseca1601c412011-05-10 10:38:19 +01001035 print ' }'
1036 print ' }'
1037 print ' }'
1038 print ' }'
1039 print
José Fonseca1a2fdd22011-04-01 00:55:09 +01001040
José Fonseca8d1408b2014-02-03 19:57:18 +00001041 # Restore the original array_buffer
1042 print ' if (_array_buffer) {'
1043 self.fake_glBindBuffer(api, 'GL_ARRAY_BUFFER', '_array_buffer')
1044 print ' }'
1045 print
1046
José Fonseca669b1222011-02-20 09:05:10 +00001047 print '}'
1048 print
1049
José Fonsecafb6744f2011-04-15 11:18:37 +01001050 #
1051 # Hooks for glTexCoordPointer, which is identical to the other array
1052 # pointers except the fact that it is indexed by glClientActiveTexture.
1053 #
1054
1055 def array_prolog(self, api, uppercase_name):
1056 if uppercase_name == 'TEXTURE_COORD':
José Fonseca26be8f92014-03-07 14:08:50 +00001057 print ' GLint client_active_texture = _glGetInteger(GL_CLIENT_ACTIVE_TEXTURE);'
José Fonsecafb6744f2011-04-15 11:18:37 +01001058 print ' GLint max_texture_coords = 0;'
José Fonseca34ea6162015-01-08 23:45:43 +00001059 print ' if (ctx->profile.desktop())'
José Fonseca632a78d2012-04-19 07:18:59 +01001060 print ' _glGetIntegerv(GL_MAX_TEXTURE_COORDS, &max_texture_coords);'
Chia-I Wub3d218d2011-11-03 01:37:36 +08001061 print ' else'
José Fonseca632a78d2012-04-19 07:18:59 +01001062 print ' _glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_texture_coords);'
José Fonsecafb6744f2011-04-15 11:18:37 +01001063 print ' for (GLint unit = 0; unit < max_texture_coords; ++unit) {'
José Fonseca7525e6f2011-09-28 09:04:56 +01001064 print ' GLint texture = GL_TEXTURE0 + unit;'
José Fonseca632a78d2012-04-19 07:18:59 +01001065 print ' _glClientActiveTexture(texture);'
José Fonsecafb6744f2011-04-15 11:18:37 +01001066
1067 def array_trace_prolog(self, api, uppercase_name):
1068 if uppercase_name == 'TEXTURE_COORD':
1069 print ' bool client_active_texture_dirty = false;'
1070
1071 def array_epilog(self, api, uppercase_name):
1072 if uppercase_name == 'TEXTURE_COORD':
1073 print ' }'
1074 self.array_cleanup(api, uppercase_name)
1075
1076 def array_cleanup(self, api, uppercase_name):
1077 if uppercase_name == 'TEXTURE_COORD':
José Fonseca632a78d2012-04-19 07:18:59 +01001078 print ' _glClientActiveTexture(client_active_texture);'
José Fonsecafb6744f2011-04-15 11:18:37 +01001079
1080 def array_trace_intermezzo(self, api, uppercase_name):
1081 if uppercase_name == 'TEXTURE_COORD':
1082 print ' if (texture != client_active_texture || client_active_texture_dirty) {'
1083 print ' client_active_texture_dirty = true;'
1084 self.fake_glClientActiveTexture_call(api, "texture");
1085 print ' }'
1086
1087 def array_trace_epilog(self, api, uppercase_name):
1088 if uppercase_name == 'TEXTURE_COORD':
1089 print ' if (client_active_texture_dirty) {'
1090 self.fake_glClientActiveTexture_call(api, "client_active_texture");
1091 print ' }'
1092
José Fonseca8d1408b2014-02-03 19:57:18 +00001093 def fake_glBindBuffer(self, api, target, buffer):
1094 function = api.getFunctionByName('glBindBuffer')
1095 self.fake_call(function, [target, buffer])
1096
José Fonsecafb6744f2011-04-15 11:18:37 +01001097 def fake_glClientActiveTexture_call(self, api, texture):
José Fonseca1b6c8752012-04-15 14:33:00 +01001098 function = api.getFunctionByName('glClientActiveTexture')
José Fonsecafb6744f2011-04-15 11:18:37 +01001099 self.fake_call(function, [texture])
1100
José Fonseca151c3702013-05-10 08:28:15 +01001101 def emitFakeTexture2D(self):
1102 function = glapi.glapi.getFunctionByName('glTexImage2D')
1103 instances = function.argNames()
José Fonseca7a5f23a2014-06-24 19:20:36 +01001104 print ' unsigned _fake_call = trace::localWriter.beginEnter(&_%s_sig, true);' % (function.name,)
José Fonseca151c3702013-05-10 08:28:15 +01001105 for arg in function.args:
1106 assert not arg.output
1107 self.serializeArg(function, arg)
1108 print ' trace::localWriter.endEnter();'
1109 print ' trace::localWriter.beginLeave(_fake_call);'
1110 print ' trace::localWriter.endLeave();'
José Fonsecafb6744f2011-04-15 11:18:37 +01001111
1112
1113
1114
1115
José Fonseca669b1222011-02-20 09:05:10 +00001116
1117
1118
1119
1120
1121