José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 1 | ########################################################################## |
| 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é Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 30 | import stdapi |
| 31 | import glapi |
José Fonseca | 5ea9187 | 2011-05-04 09:41:55 +0100 | [diff] [blame] | 32 | import glparams |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 33 | from glxapi import glxapi |
| 34 | from trace import Tracer, dump_instance |
| 35 | |
| 36 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 37 | class TypeGetter(stdapi.Visitor): |
| 38 | '''Determine which glGet*v function that matches the specified type.''' |
| 39 | |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 40 | def __init__(self, prefix = 'glGet', long_suffix = True): |
| 41 | self.prefix = prefix |
| 42 | self.long_suffix = long_suffix |
| 43 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 44 | def visit_const(self, const): |
| 45 | return self.visit(const.type) |
| 46 | |
| 47 | def visit_alias(self, alias): |
| 48 | if alias.expr == 'GLboolean': |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 49 | if self.long_suffix: |
| 50 | return self.prefix + 'Booleanv', alias.expr |
| 51 | else: |
| 52 | return self.prefix + 'iv', 'GLint' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 53 | elif alias.expr == 'GLdouble': |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 54 | if self.long_suffix: |
| 55 | return self.prefix + 'Doublev', alias.expr |
| 56 | else: |
| 57 | return self.prefix + 'dv', alias.expr |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 58 | elif alias.expr == 'GLfloat': |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 59 | if self.long_suffix: |
| 60 | return self.prefix + 'Floatv', alias.expr |
| 61 | else: |
| 62 | return self.prefix + 'fv', alias.expr |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 63 | elif alias.expr in ('GLint', 'GLuint', 'GLsizei'): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 64 | if self.long_suffix: |
| 65 | return self.prefix + 'Integerv', 'GLint' |
| 66 | else: |
| 67 | return self.prefix + 'iv', 'GLint' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 68 | else: |
| 69 | print alias.expr |
| 70 | assert False |
| 71 | |
| 72 | def visit_enum(self, enum): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 73 | return self.visit(glapi.GLint) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 74 | |
| 75 | def visit_bitmask(self, bitmask): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 76 | return self.visit(glapi.GLint) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 77 | |
| 78 | def visit_opaque(self, pointer): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 79 | return self.prefix + 'Pointerv', 'GLvoid *' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 80 | |
| 81 | |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 82 | class GlTracer(Tracer): |
| 83 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 84 | arrays = [ |
| 85 | ("Vertex", "VERTEX"), |
| 86 | ("Normal", "NORMAL"), |
| 87 | ("Color", "COLOR"), |
| 88 | ("Index", "INDEX"), |
| 89 | ("TexCoord", "TEXTURE_COORD"), |
| 90 | ("EdgeFlag", "EDGE_FLAG"), |
| 91 | ("FogCoord", "FOG_COORD"), |
| 92 | ("SecondaryColor", "SECONDARY_COLOR"), |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 93 | ] |
José Fonseca | c9f1223 | 2011-03-25 20:07:42 +0000 | [diff] [blame] | 94 | arrays.reverse() |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 95 | |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 96 | def header(self, api): |
| 97 | Tracer.header(self, api) |
| 98 | |
José Fonseca | 25ebe54 | 2011-04-24 10:08:22 +0100 | [diff] [blame] | 99 | print '// Whether user arrays were used' |
| 100 | print 'static bool __user_arrays = false;' |
| 101 | print |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 102 | # Whether we need user arrays |
| 103 | print 'static inline bool __need_user_arrays(void)' |
| 104 | print '{' |
José Fonseca | 25ebe54 | 2011-04-24 10:08:22 +0100 | [diff] [blame] | 105 | print ' if (!__user_arrays) {' |
| 106 | print ' return false;' |
| 107 | print ' }' |
| 108 | print |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 109 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 110 | for camelcase_name, uppercase_name in self.arrays: |
| 111 | function_name = 'gl%sPointer' % camelcase_name |
| 112 | enable_name = 'GL_%s_ARRAY' % uppercase_name |
| 113 | binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name |
| 114 | print ' // %s' % function_name |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 115 | self.array_prolog(api, uppercase_name) |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 116 | print ' if (__glIsEnabled(%s)) {' % enable_name |
| 117 | print ' GLint __binding = 0;' |
| 118 | print ' __glGetIntegerv(%s, &__binding);' % binding_name |
| 119 | print ' if (!__binding) {' |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 120 | self.array_cleanup(api, uppercase_name) |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 121 | print ' return true;' |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 122 | print ' }' |
| 123 | print ' }' |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 124 | self.array_epilog(api, uppercase_name) |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 125 | print |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 126 | |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 127 | print ' // glVertexAttribPointer' |
José Fonseca | 0a96525 | 2011-04-14 09:21:15 +0100 | [diff] [blame] | 128 | print ' GLint __max_vertex_attribs = 0;' |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 129 | print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &__max_vertex_attribs);' |
| 130 | print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' |
| 131 | print ' GLint __enabled = 0;' |
| 132 | print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &__enabled);' |
| 133 | print ' if (__enabled) {' |
| 134 | print ' GLint __binding = 0;' |
| 135 | print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &__binding);' |
| 136 | print ' if (!__binding) {' |
| 137 | print ' return true;' |
| 138 | print ' }' |
| 139 | print ' }' |
| 140 | print ' }' |
| 141 | print |
| 142 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 143 | print ' return false;' |
| 144 | print '}' |
| 145 | print |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 146 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 147 | print 'static void __trace_user_arrays(GLuint maxindex);' |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 148 | print |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 149 | |
| 150 | print 'struct buffer_mapping {' |
| 151 | print ' void *map;' |
| 152 | print ' GLint length;' |
| 153 | print ' bool write;' |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 154 | print ' bool explicit_flush;' |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 155 | print '};' |
| 156 | print |
| 157 | for target in self.buffer_targets: |
| 158 | print 'struct buffer_mapping __%s_mapping;' % target.lower(); |
| 159 | print |
| 160 | print 'static inline struct buffer_mapping *' |
| 161 | print 'get_buffer_mapping(GLenum target) {' |
| 162 | print ' switch(target) {' |
| 163 | for target in self.buffer_targets: |
| 164 | print ' case GL_%s:' % target |
| 165 | print ' return & __%s_mapping;' % target.lower() |
| 166 | print ' default:' |
| 167 | print ' OS::DebugMessage("warning: unknown buffer target 0x%04X\\n", target);' |
| 168 | print ' return NULL;' |
| 169 | print ' }' |
| 170 | print '}' |
| 171 | print |
| 172 | |
| 173 | # Generate memcpy's signature |
| 174 | self.trace_function_decl(glapi.memcpy) |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 175 | |
| 176 | # Generate a helper function to determine whether a parameter name |
| 177 | # refers to a symbolic value or not |
| 178 | print 'static bool' |
| 179 | print 'is_symbolic_pname(GLenum pname) {' |
| 180 | print ' switch(pname) {' |
José Fonseca | 5ea9187 | 2011-05-04 09:41:55 +0100 | [diff] [blame] | 181 | for function, type, count, name in glparams.parameters: |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 182 | if type is glapi.GLenum: |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 183 | print ' case %s:' % name |
| 184 | print ' return true;' |
| 185 | print ' default:' |
| 186 | print ' return false;' |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 187 | print ' }' |
| 188 | print '}' |
| 189 | print |
| 190 | |
| 191 | # Generate a helper function to determine whether a parameter value is |
| 192 | # potentially symbolic or not; i.e., if the value can be represented in |
| 193 | # an enum or not |
| 194 | print 'template<class T>' |
| 195 | print 'static inline bool' |
| 196 | print 'is_symbolic_param(T param) {' |
| 197 | print ' return static_cast<T>(static_cast<GLenum>(param)) == param;' |
| 198 | print '}' |
| 199 | print |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 200 | |
| 201 | # Generate a helper function to know how many elements a parameter has |
| 202 | print 'static size_t' |
José Fonseca | f4aca5d | 2011-05-08 08:29:30 +0100 | [diff] [blame] | 203 | print '__gl_param_size(GLenum pname) {' |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 204 | print ' switch(pname) {' |
José Fonseca | 5ea9187 | 2011-05-04 09:41:55 +0100 | [diff] [blame] | 205 | for function, type, count, name in glparams.parameters: |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 206 | if type is not None: |
| 207 | print ' case %s: return %u;' % (name, count) |
| 208 | print ' case GL_COMPRESSED_TEXTURE_FORMATS: {' |
| 209 | print ' GLint num_compressed_texture_formats = 0;' |
| 210 | print ' __glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &num_compressed_texture_formats);' |
| 211 | print ' return num_compressed_texture_formats;' |
| 212 | print ' }' |
| 213 | print ' default:' |
| 214 | print r' OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);' |
| 215 | print ' return 1;' |
| 216 | print ' }' |
| 217 | print '}' |
| 218 | print |
| 219 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 220 | array_pointer_function_names = set(( |
| 221 | "glVertexPointer", |
| 222 | "glNormalPointer", |
| 223 | "glColorPointer", |
| 224 | "glIndexPointer", |
| 225 | "glTexCoordPointer", |
| 226 | "glEdgeFlagPointer", |
| 227 | "glFogCoordPointer", |
| 228 | "glSecondaryColorPointer", |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 229 | |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 230 | "glInterleavedArrays", |
| 231 | |
José Fonseca | 7e0bfd9 | 2011-04-30 23:09:03 +0100 | [diff] [blame] | 232 | "glVertexPointerEXT", |
| 233 | "glNormalPointerEXT", |
| 234 | "glColorPointerEXT", |
| 235 | "glIndexPointerEXT", |
| 236 | "glTexCoordPointerEXT", |
| 237 | "glEdgeFlagPointerEXT", |
| 238 | "glFogCoordPointerEXT", |
| 239 | "glSecondaryColorPointerEXT", |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 240 | |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 241 | "glVertexAttribPointer", |
| 242 | "glVertexAttribPointerARB", |
| 243 | "glVertexAttribPointerNV", |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 244 | "glVertexAttribIPointer", |
| 245 | "glVertexAttribIPointerEXT", |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 246 | "glVertexAttribLPointer", |
| 247 | "glVertexAttribLPointerEXT", |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 248 | |
| 249 | #"glMatrixIndexPointerARB", |
| 250 | )) |
| 251 | |
| 252 | draw_function_names = set(( |
| 253 | 'glDrawArrays', |
| 254 | 'glDrawElements', |
| 255 | 'glDrawRangeElements', |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 256 | 'glMultiDrawArrays', |
| 257 | 'glMultiDrawElements', |
| 258 | 'glDrawArraysInstanced', |
| 259 | 'glDrawElementsInstanced', |
| 260 | 'glDrawArraysInstancedARB', |
| 261 | 'glDrawElementsInstancedARB', |
| 262 | 'glDrawElementsBaseVertex', |
| 263 | 'glDrawRangeElementsBaseVertex', |
| 264 | 'glDrawElementsInstancedBaseVertex', |
| 265 | 'glMultiDrawElementsBaseVertex', |
| 266 | 'glDrawArraysIndirect', |
| 267 | 'glDrawElementsIndirect', |
| 268 | 'glDrawArraysEXT', |
José Fonseca | 7e0bfd9 | 2011-04-30 23:09:03 +0100 | [diff] [blame] | 269 | 'glDrawRangeElementsEXT', |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 270 | 'glDrawRangeElementsEXT_size', |
| 271 | 'glMultiDrawArraysEXT', |
| 272 | 'glMultiDrawElementsEXT', |
| 273 | 'glMultiModeDrawArraysIBM', |
| 274 | 'glMultiModeDrawElementsIBM', |
| 275 | 'glDrawArraysInstancedEXT', |
| 276 | 'glDrawElementsInstancedEXT', |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 277 | )) |
| 278 | |
José Fonseca | c9f1223 | 2011-03-25 20:07:42 +0000 | [diff] [blame] | 279 | interleaved_formats = [ |
| 280 | 'GL_V2F', |
| 281 | 'GL_V3F', |
| 282 | 'GL_C4UB_V2F', |
| 283 | 'GL_C4UB_V3F', |
| 284 | 'GL_C3F_V3F', |
| 285 | 'GL_N3F_V3F', |
| 286 | 'GL_C4F_N3F_V3F', |
| 287 | 'GL_T2F_V3F', |
| 288 | 'GL_T4F_V4F', |
| 289 | 'GL_T2F_C4UB_V3F', |
| 290 | 'GL_T2F_C3F_V3F', |
| 291 | 'GL_T2F_N3F_V3F', |
| 292 | 'GL_T2F_C4F_N3F_V3F', |
| 293 | 'GL_T4F_C4F_N3F_V4F', |
| 294 | ] |
| 295 | |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 296 | def trace_function_impl_body(self, function): |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 297 | # Defer tracing of user array pointers... |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 298 | if function.name in self.array_pointer_function_names: |
| 299 | print ' GLint __array_buffer = 0;' |
| 300 | print ' __glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);' |
| 301 | print ' if (!__array_buffer) {' |
José Fonseca | 25ebe54 | 2011-04-24 10:08:22 +0100 | [diff] [blame] | 302 | print ' __user_arrays = true;' |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 303 | self.dispatch_function(function) |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 304 | |
| 305 | # And also break down glInterleavedArrays into the individual calls |
| 306 | if function.name == 'glInterleavedArrays': |
| 307 | print |
| 308 | |
| 309 | # Initialize the enable flags |
| 310 | for camelcase_name, uppercase_name in self.arrays: |
| 311 | flag_name = '__' + uppercase_name.lower() |
| 312 | print ' GLboolean %s = GL_FALSE;' % flag_name |
| 313 | print |
| 314 | |
| 315 | # Switch for the interleaved formats |
| 316 | print ' switch (format) {' |
| 317 | for format in self.interleaved_formats: |
| 318 | print ' case %s:' % format |
| 319 | for camelcase_name, uppercase_name in self.arrays: |
| 320 | flag_name = '__' + uppercase_name.lower() |
| 321 | if format.find('_' + uppercase_name[0]) >= 0: |
| 322 | print ' %s = GL_TRUE;' % flag_name |
| 323 | print ' break;' |
| 324 | print ' default:' |
| 325 | print ' return;' |
| 326 | print ' }' |
| 327 | print |
| 328 | |
| 329 | # Emit fake glEnableClientState/glDisableClientState flags |
| 330 | for camelcase_name, uppercase_name in self.arrays: |
| 331 | flag_name = '__' + uppercase_name.lower() |
| 332 | enable_name = 'GL_%s_ARRAY' % uppercase_name |
| 333 | |
| 334 | # Emit a fake function |
| 335 | print ' {' |
| 336 | print ' static const Trace::FunctionSig &__sig = %s ? __glEnableClientState_sig : __glDisableClientState_sig;' % flag_name |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame^] | 337 | print ' unsigned __call = __writer.beginEnter(__sig);' |
| 338 | print ' __writer.beginArg(0);' |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 339 | dump_instance(glapi.GLenum, enable_name) |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame^] | 340 | print ' __writer.endArg();' |
| 341 | print ' __writer.endEnter();' |
| 342 | print ' __writer.beginLeave(__call);' |
| 343 | print ' __writer.endLeave();' |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 344 | print ' }' |
| 345 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 346 | print ' return;' |
| 347 | print ' }' |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 348 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 349 | # ... to the draw calls |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 350 | if function.name in self.draw_function_names: |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 351 | print ' if (__need_user_arrays()) {' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 352 | arg_names = ', '.join([arg.name for arg in function.args[1:]]) |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 353 | print ' GLuint maxindex = __%s_maxindex(%s);' % (function.name, arg_names) |
| 354 | print ' __trace_user_arrays(maxindex);' |
| 355 | print ' }' |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 356 | |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 357 | # Emit a fake memcpy on buffer uploads |
| 358 | if function.name in ('glUnmapBuffer', 'glUnmapBufferARB', ): |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 359 | print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 360 | print ' if (mapping && mapping->write && !mapping->explicit_flush) {' |
| 361 | self.emit_memcpy('mapping->map', 'mapping->map', 'mapping->length') |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 362 | print ' }' |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 363 | if function.name in ('glFlushMappedBufferRange', 'glFlushMappedBufferRangeAPPLE'): |
| 364 | # TODO: avoid copying [0, offset] bytes |
| 365 | print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' |
| 366 | print ' if (mapping) {' |
| 367 | if function.name.endswith('APPLE'): |
| 368 | print ' GLsizeiptr length = size;' |
| 369 | print ' mapping->explicit_flush = true;' |
| 370 | print ' //assert(offset + length <= mapping->length);' |
| 371 | self.emit_memcpy('mapping->map', 'mapping->map', 'offset + length') |
| 372 | print ' }' |
| 373 | # FIXME: glFlushMappedNamedBufferRangeEXT |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 374 | |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 375 | # Don't leave vertex attrib locations to chance. Instead emit fake |
| 376 | # glBindAttribLocation calls to ensure that the same locations will be |
| 377 | # used when retracing. Trying to remap locations after the fact would |
| 378 | # be an herculian task given that vertex attrib locations appear in |
| 379 | # many entry-points, including non-shader related ones. |
| 380 | if function.name == 'glLinkProgram': |
| 381 | Tracer.dispatch_function(self, function) |
| 382 | print ' GLint active_attributes = 0;' |
| 383 | print ' __glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &active_attributes);' |
| 384 | print ' for (GLuint attrib = 0; attrib < active_attributes; ++attrib) {' |
| 385 | print ' GLint size = 0;' |
| 386 | print ' GLenum type = 0;' |
| 387 | print ' GLchar name[256];' |
| 388 | # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256 |
| 389 | print ' __glGetActiveAttrib(program, attrib, sizeof name, NULL, &size, &type, name);' |
José Fonseca | 2a794f5 | 2011-05-26 20:54:29 +0100 | [diff] [blame] | 390 | print " if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {" |
| 391 | print ' GLint location = __glGetAttribLocation(program, name);' |
| 392 | print ' if (location >= 0) {' |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 393 | bind_function = glapi.glapi.get_function_by_name('glBindAttribLocation') |
| 394 | self.fake_call(bind_function, ['program', 'location', 'name']) |
José Fonseca | 2a794f5 | 2011-05-26 20:54:29 +0100 | [diff] [blame] | 395 | print ' }' |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 396 | print ' }' |
| 397 | print ' }' |
| 398 | if function.name == 'glLinkProgramARB': |
| 399 | Tracer.dispatch_function(self, function) |
| 400 | print ' GLint active_attributes = 0;' |
| 401 | print ' __glGetObjectParameterivARB(programObj, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB, &active_attributes);' |
| 402 | print ' for (GLuint attrib = 0; attrib < active_attributes; ++attrib) {' |
| 403 | print ' GLint size = 0;' |
| 404 | print ' GLenum type = 0;' |
| 405 | print ' GLcharARB name[256];' |
| 406 | # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256 |
| 407 | print ' __glGetActiveAttribARB(programObj, attrib, sizeof name, NULL, &size, &type, name);' |
José Fonseca | 2a794f5 | 2011-05-26 20:54:29 +0100 | [diff] [blame] | 408 | print " if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {" |
| 409 | print ' GLint location = __glGetAttribLocationARB(programObj, name);' |
| 410 | print ' if (location >= 0) {' |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 411 | bind_function = glapi.glapi.get_function_by_name('glBindAttribLocationARB') |
| 412 | self.fake_call(bind_function, ['programObj', 'location', 'name']) |
José Fonseca | 2a794f5 | 2011-05-26 20:54:29 +0100 | [diff] [blame] | 413 | print ' }' |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 414 | print ' }' |
| 415 | print ' }' |
| 416 | |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 417 | Tracer.trace_function_impl_body(self, function) |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 418 | |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 419 | def dispatch_function(self, function): |
| 420 | if function.name in ('glLinkProgram', 'glLinkProgramARB'): |
| 421 | # These functions have been dispatched already |
| 422 | return |
| 423 | |
| 424 | Tracer.dispatch_function(self, function) |
| 425 | |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 426 | def emit_memcpy(self, dest, src, length): |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame^] | 427 | print ' unsigned __call = __writer.beginEnter(__memcpy_sig);' |
| 428 | print ' __writer.beginArg(0);' |
| 429 | print ' __writer.writeOpaque(%s);' % dest |
| 430 | print ' __writer.endArg();' |
| 431 | print ' __writer.beginArg(1);' |
| 432 | print ' __writer.writeBlob(%s, %s);' % (src, length) |
| 433 | print ' __writer.endArg();' |
| 434 | print ' __writer.beginArg(2);' |
| 435 | print ' __writer.writeUInt(%s);' % length |
| 436 | print ' __writer.endArg();' |
| 437 | print ' __writer.endEnter();' |
| 438 | print ' __writer.beginLeave(__call);' |
| 439 | print ' __writer.endLeave();' |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 440 | |
| 441 | buffer_targets = [ |
| 442 | 'ARRAY_BUFFER', |
| 443 | 'ELEMENT_ARRAY_BUFFER', |
| 444 | 'PIXEL_PACK_BUFFER', |
| 445 | 'PIXEL_UNPACK_BUFFER', |
| 446 | ] |
| 447 | |
| 448 | def wrap_ret(self, function, instance): |
| 449 | Tracer.wrap_ret(self, function, instance) |
| 450 | |
| 451 | if function.name in ('glMapBuffer', 'glMapBufferARB'): |
| 452 | print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' |
| 453 | print ' if (mapping) {' |
| 454 | print ' mapping->map = %s;' % (instance) |
| 455 | print ' mapping->length = 0;' |
| 456 | print ' __glGetBufferParameteriv(target, GL_BUFFER_SIZE, &mapping->length);' |
| 457 | print ' mapping->write = (access != GL_READ_ONLY);' |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 458 | print ' mapping->explicit_flush = false;' |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 459 | print ' }' |
| 460 | |
| 461 | if function.name == 'glMapBufferRange': |
| 462 | print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' |
| 463 | print ' if (mapping) {' |
| 464 | print ' mapping->map = %s;' % (instance) |
| 465 | print ' mapping->length = length;' |
| 466 | print ' mapping->write = access & GL_MAP_WRITE_BIT;' |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 467 | print ' mapping->explicit_flush = access & GL_MAP_FLUSH_EXPLICIT_BIT;' |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 468 | print ' }' |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 469 | |
José Fonseca | c9f1223 | 2011-03-25 20:07:42 +0000 | [diff] [blame] | 470 | boolean_names = [ |
| 471 | 'GL_FALSE', |
| 472 | 'GL_TRUE', |
| 473 | ] |
| 474 | |
| 475 | def gl_boolean(self, value): |
| 476 | return self.boolean_names[int(bool(value))] |
| 477 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 478 | def dump_arg_instance(self, function, arg): |
| 479 | if function.name in self.draw_function_names and arg.name == 'indices': |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 480 | print ' GLint __element_array_buffer = 0;' |
| 481 | print ' __glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &__element_array_buffer);' |
| 482 | print ' if (!__element_array_buffer) {' |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 483 | if isinstance(arg.type, stdapi.Array): |
| 484 | Tracer.dump_arg_instance(self, function, arg) |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame^] | 485 | print ' __writer.beginArray(%s);' % arg.type.length |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 486 | print ' for(GLsizei i = 0; i < %s; ++i) {' % arg.type.length |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame^] | 487 | print ' __writer.beginElement();' |
| 488 | print ' __writer.writeBlob((const void *)%s, count[i]*__gl_type_size(type));' % (arg.name) |
| 489 | print ' __writer.endElement();' |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 490 | print ' }' |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame^] | 491 | print ' __writer.endArray();' |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 492 | else: |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame^] | 493 | print ' __writer.writeBlob((const void *)%s, count*__gl_type_size(type));' % (arg.name) |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 494 | print ' } else {' |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 495 | Tracer.dump_arg_instance(self, function, arg) |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 496 | print ' }' |
| 497 | return |
| 498 | |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 499 | # Several GL state functions take GLenum symbolic names as |
| 500 | # integer/floats; so dump the symbolic name whenever possible |
José Fonseca | 3bcb33c | 2011-05-27 20:14:31 +0100 | [diff] [blame] | 501 | if function.name.startswith('gl') \ |
| 502 | and arg.type in (glapi.GLint, glapi.GLfloat) \ |
| 503 | and arg.name == 'param': |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 504 | assert arg.index > 0 |
| 505 | assert function.args[arg.index - 1].name == 'pname' |
| 506 | assert function.args[arg.index - 1].type == glapi.GLenum |
| 507 | print ' if (is_symbolic_pname(pname) && is_symbolic_param(%s)) {' % arg.name |
| 508 | dump_instance(glapi.GLenum, arg.name) |
| 509 | print ' } else {' |
| 510 | Tracer.dump_arg_instance(self, function, arg) |
| 511 | print ' }' |
| 512 | return |
| 513 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 514 | Tracer.dump_arg_instance(self, function, arg) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 515 | |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 516 | def footer(self, api): |
| 517 | Tracer.footer(self, api) |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 518 | |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 519 | # A simple state tracker to track the pointer values |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 520 | # update the state |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 521 | print 'static void __trace_user_arrays(GLuint maxindex)' |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 522 | print '{' |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 523 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 524 | for camelcase_name, uppercase_name in self.arrays: |
| 525 | function_name = 'gl%sPointer' % camelcase_name |
| 526 | enable_name = 'GL_%s_ARRAY' % uppercase_name |
| 527 | binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 528 | function = api.get_function_by_name(function_name) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 529 | |
| 530 | print ' // %s' % function.name |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 531 | self.array_trace_prolog(api, uppercase_name) |
| 532 | self.array_prolog(api, uppercase_name) |
| 533 | print ' if (__glIsEnabled(%s)) {' % enable_name |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 534 | print ' GLint __binding = 0;' |
| 535 | print ' __glGetIntegerv(%s, &__binding);' % binding_name |
| 536 | print ' if (!__binding) {' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 537 | |
| 538 | # Get the arguments via glGet* |
| 539 | for arg in function.args: |
| 540 | arg_get_enum = 'GL_%s_ARRAY_%s' % (uppercase_name, arg.name.upper()) |
| 541 | arg_get_function, arg_type = TypeGetter().visit(arg.type) |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 542 | print ' %s %s = 0;' % (arg_type, arg.name) |
| 543 | print ' __%s(%s, &%s);' % (arg_get_function, arg_get_enum, arg.name) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 544 | |
| 545 | arg_names = ', '.join([arg.name for arg in function.args[:-1]]) |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 546 | print ' size_t __size = __%s_size(%s, maxindex);' % (function.name, arg_names) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 547 | |
| 548 | # Emit a fake function |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 549 | self.array_trace_intermezzo(api, uppercase_name) |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame^] | 550 | print ' unsigned __call = __writer.beginEnter(__%s_sig);' % (function.name,) |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 551 | for arg in function.args: |
| 552 | assert not arg.output |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame^] | 553 | print ' __writer.beginArg(%u);' % (arg.index,) |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 554 | if arg.name != 'pointer': |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 555 | dump_instance(arg.type, arg.name) |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 556 | else: |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame^] | 557 | print ' __writer.writeBlob((const void *)%s, __size);' % (arg.name) |
| 558 | print ' __writer.endArg();' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 559 | |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame^] | 560 | print ' __writer.endEnter();' |
| 561 | print ' __writer.beginLeave(__call);' |
| 562 | print ' __writer.endLeave();' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 563 | print ' }' |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 564 | print ' }' |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 565 | self.array_epilog(api, uppercase_name) |
| 566 | self.array_trace_epilog(api, uppercase_name) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 567 | print |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 568 | |
| 569 | # Samething, but for glVertexAttribPointer |
| 570 | print ' // glVertexAttribPointer' |
José Fonseca | 0a96525 | 2011-04-14 09:21:15 +0100 | [diff] [blame] | 571 | print ' GLint __max_vertex_attribs = 0;' |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 572 | print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &__max_vertex_attribs);' |
| 573 | print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' |
| 574 | print ' GLint __enabled = 0;' |
| 575 | print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &__enabled);' |
| 576 | print ' if (__enabled) {' |
| 577 | print ' GLint __binding = 0;' |
| 578 | print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &__binding);' |
| 579 | print ' if (!__binding) {' |
| 580 | |
| 581 | function = api.get_function_by_name('glVertexAttribPointer') |
| 582 | |
| 583 | # Get the arguments via glGet* |
| 584 | for arg in function.args[1:]: |
| 585 | arg_get_enum = 'GL_VERTEX_ATTRIB_ARRAY_%s' % (arg.name.upper(),) |
| 586 | arg_get_function, arg_type = TypeGetter('glGetVertexAttrib', False).visit(arg.type) |
| 587 | print ' %s %s = 0;' % (arg_type, arg.name) |
| 588 | print ' __%s(index, %s, &%s);' % (arg_get_function, arg_get_enum, arg.name) |
| 589 | |
| 590 | arg_names = ', '.join([arg.name for arg in function.args[1:-1]]) |
| 591 | print ' size_t __size = __%s_size(%s, maxindex);' % (function.name, arg_names) |
| 592 | |
| 593 | # Emit a fake function |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame^] | 594 | print ' unsigned __call = __writer.beginEnter(__%s_sig);' % (function.name,) |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 595 | for arg in function.args: |
| 596 | assert not arg.output |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame^] | 597 | print ' __writer.beginArg(%u);' % (arg.index,) |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 598 | if arg.name != 'pointer': |
| 599 | dump_instance(arg.type, arg.name) |
| 600 | else: |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame^] | 601 | print ' __writer.writeBlob((const void *)%s, __size);' % (arg.name) |
| 602 | print ' __writer.endArg();' |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 603 | |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame^] | 604 | print ' __writer.endEnter();' |
| 605 | print ' __writer.beginLeave(__call);' |
| 606 | print ' __writer.endLeave();' |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 607 | print ' }' |
| 608 | print ' }' |
| 609 | print ' }' |
| 610 | print |
| 611 | |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 612 | print '}' |
| 613 | print |
| 614 | |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 615 | # |
| 616 | # Hooks for glTexCoordPointer, which is identical to the other array |
| 617 | # pointers except the fact that it is indexed by glClientActiveTexture. |
| 618 | # |
| 619 | |
| 620 | def array_prolog(self, api, uppercase_name): |
| 621 | if uppercase_name == 'TEXTURE_COORD': |
| 622 | print ' GLint client_active_texture = 0;' |
| 623 | print ' __glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE, &client_active_texture);' |
| 624 | print ' GLint max_texture_coords = 0;' |
| 625 | print ' __glGetIntegerv(GL_MAX_TEXTURE_COORDS, &max_texture_coords);' |
| 626 | print ' for (GLint unit = 0; unit < max_texture_coords; ++unit) {' |
| 627 | print ' GLenum texture = GL_TEXTURE0 + unit;' |
| 628 | print ' __glClientActiveTexture(texture);' |
| 629 | |
| 630 | def array_trace_prolog(self, api, uppercase_name): |
| 631 | if uppercase_name == 'TEXTURE_COORD': |
| 632 | print ' bool client_active_texture_dirty = false;' |
| 633 | |
| 634 | def array_epilog(self, api, uppercase_name): |
| 635 | if uppercase_name == 'TEXTURE_COORD': |
| 636 | print ' }' |
| 637 | self.array_cleanup(api, uppercase_name) |
| 638 | |
| 639 | def array_cleanup(self, api, uppercase_name): |
| 640 | if uppercase_name == 'TEXTURE_COORD': |
| 641 | print ' __glClientActiveTexture(client_active_texture);' |
| 642 | |
| 643 | def array_trace_intermezzo(self, api, uppercase_name): |
| 644 | if uppercase_name == 'TEXTURE_COORD': |
| 645 | print ' if (texture != client_active_texture || client_active_texture_dirty) {' |
| 646 | print ' client_active_texture_dirty = true;' |
| 647 | self.fake_glClientActiveTexture_call(api, "texture"); |
| 648 | print ' }' |
| 649 | |
| 650 | def array_trace_epilog(self, api, uppercase_name): |
| 651 | if uppercase_name == 'TEXTURE_COORD': |
| 652 | print ' if (client_active_texture_dirty) {' |
| 653 | self.fake_glClientActiveTexture_call(api, "client_active_texture"); |
| 654 | print ' }' |
| 655 | |
| 656 | def fake_glClientActiveTexture_call(self, api, texture): |
| 657 | function = api.get_function_by_name('glClientActiveTexture') |
| 658 | self.fake_call(function, [texture]) |
| 659 | |
| 660 | def fake_call(self, function, args): |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame^] | 661 | print ' unsigned __fake_call = __writer.beginEnter(__%s_sig);' % (function.name,) |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 662 | for arg, instance in zip(function.args, args): |
| 663 | assert not arg.output |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame^] | 664 | print ' __writer.beginArg(%u);' % (arg.index,) |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 665 | dump_instance(arg.type, instance) |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame^] | 666 | print ' __writer.endArg();' |
| 667 | print ' __writer.endEnter();' |
| 668 | print ' __writer.beginLeave(__fake_call);' |
| 669 | print ' __writer.endLeave();' |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 670 | |
| 671 | |
| 672 | |
| 673 | |
| 674 | |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 675 | |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | |