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 | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 32 | from glxapi import glxapi |
| 33 | from trace import Tracer, dump_instance |
| 34 | |
| 35 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 36 | class TypeGetter(stdapi.Visitor): |
| 37 | '''Determine which glGet*v function that matches the specified type.''' |
| 38 | |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 39 | def __init__(self, prefix = 'glGet', long_suffix = True): |
| 40 | self.prefix = prefix |
| 41 | self.long_suffix = long_suffix |
| 42 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 43 | def visit_const(self, const): |
| 44 | return self.visit(const.type) |
| 45 | |
| 46 | def visit_alias(self, alias): |
| 47 | if alias.expr == 'GLboolean': |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 48 | if self.long_suffix: |
| 49 | return self.prefix + 'Booleanv', alias.expr |
| 50 | else: |
| 51 | return self.prefix + 'iv', 'GLint' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 52 | elif alias.expr == 'GLdouble': |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 53 | if self.long_suffix: |
| 54 | return self.prefix + 'Doublev', alias.expr |
| 55 | else: |
| 56 | return self.prefix + 'dv', alias.expr |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 57 | elif alias.expr == 'GLfloat': |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 58 | if self.long_suffix: |
| 59 | return self.prefix + 'Floatv', alias.expr |
| 60 | else: |
| 61 | return self.prefix + 'fv', alias.expr |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 62 | elif alias.expr in ('GLint', 'GLuint', 'GLsizei'): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 63 | if self.long_suffix: |
| 64 | return self.prefix + 'Integerv', 'GLint' |
| 65 | else: |
| 66 | return self.prefix + 'iv', 'GLint' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 67 | else: |
| 68 | print alias.expr |
| 69 | assert False |
| 70 | |
| 71 | def visit_enum(self, enum): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 72 | return self.visit(glapi.GLint) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 73 | |
| 74 | def visit_bitmask(self, bitmask): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 75 | return self.visit(glapi.GLint) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 76 | |
| 77 | def visit_opaque(self, pointer): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 78 | return self.prefix + 'Pointerv', 'GLvoid *' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 79 | |
| 80 | |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 81 | class GlTracer(Tracer): |
| 82 | |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 83 | def header(self, api): |
| 84 | Tracer.header(self, api) |
| 85 | self.state_tracker_decl(api) |
| 86 | |
| 87 | def footer(self, api): |
| 88 | Tracer.footer(self, api) |
| 89 | self.state_tracker_impl(api) |
| 90 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 91 | arrays = [ |
| 92 | ("Vertex", "VERTEX"), |
| 93 | ("Normal", "NORMAL"), |
| 94 | ("Color", "COLOR"), |
| 95 | ("Index", "INDEX"), |
| 96 | ("TexCoord", "TEXTURE_COORD"), |
| 97 | ("EdgeFlag", "EDGE_FLAG"), |
| 98 | ("FogCoord", "FOG_COORD"), |
| 99 | ("SecondaryColor", "SECONDARY_COLOR"), |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 100 | ] |
José Fonseca | c9f1223 | 2011-03-25 20:07:42 +0000 | [diff] [blame] | 101 | arrays.reverse() |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 102 | |
| 103 | def state_tracker_decl(self, api): |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 104 | # Whether we need user arrays |
| 105 | print 'static inline bool __need_user_arrays(void)' |
| 106 | print '{' |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 107 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 108 | for camelcase_name, uppercase_name in self.arrays: |
| 109 | function_name = 'gl%sPointer' % camelcase_name |
| 110 | enable_name = 'GL_%s_ARRAY' % uppercase_name |
| 111 | binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name |
| 112 | print ' // %s' % function_name |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame^] | 113 | self.array_prolog(api, uppercase_name) |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 114 | print ' if (__glIsEnabled(%s)) {' % enable_name |
| 115 | print ' GLint __binding = 0;' |
| 116 | print ' __glGetIntegerv(%s, &__binding);' % binding_name |
| 117 | print ' if (!__binding) {' |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame^] | 118 | self.array_cleanup(api, uppercase_name) |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 119 | print ' return true;' |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 120 | print ' }' |
| 121 | print ' }' |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame^] | 122 | self.array_epilog(api, uppercase_name) |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 123 | print |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 124 | |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 125 | print ' // glVertexAttribPointer' |
José Fonseca | 0a96525 | 2011-04-14 09:21:15 +0100 | [diff] [blame] | 126 | print ' GLint __max_vertex_attribs = 0;' |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 127 | print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &__max_vertex_attribs);' |
| 128 | print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' |
| 129 | print ' GLint __enabled = 0;' |
| 130 | print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &__enabled);' |
| 131 | print ' if (__enabled) {' |
| 132 | print ' GLint __binding = 0;' |
| 133 | print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &__binding);' |
| 134 | print ' if (!__binding) {' |
| 135 | print ' return true;' |
| 136 | print ' }' |
| 137 | print ' }' |
| 138 | print ' }' |
| 139 | print |
| 140 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 141 | print ' return false;' |
| 142 | print '}' |
| 143 | print |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 144 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 145 | print 'static void __trace_user_arrays(GLuint maxindex);' |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 146 | print |
| 147 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 148 | array_pointer_function_names = set(( |
| 149 | "glVertexPointer", |
| 150 | "glNormalPointer", |
| 151 | "glColorPointer", |
| 152 | "glIndexPointer", |
| 153 | "glTexCoordPointer", |
| 154 | "glEdgeFlagPointer", |
| 155 | "glFogCoordPointer", |
| 156 | "glSecondaryColorPointer", |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 157 | |
José Fonseca | 4ec1daf | 2011-04-01 09:22:22 +0100 | [diff] [blame] | 158 | #"glVertexPointerEXT", |
| 159 | #"glNormalPointerEXT", |
| 160 | #"glColorPointerEXT", |
| 161 | #"glIndexPointerEXT", |
| 162 | #"glTexCoordPointerEXT", |
| 163 | #"glEdgeFlagPointerEXT", |
| 164 | #"glFogCoordPointerEXT", |
| 165 | #"glSecondaryColorPointerEXT", |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 166 | |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 167 | "glVertexAttribPointer", |
| 168 | "glVertexAttribPointerARB", |
| 169 | "glVertexAttribPointerNV", |
| 170 | "glVertexAttribLPointer", |
| 171 | "glVertexAttribLPointerEXT", |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 172 | |
| 173 | #"glMatrixIndexPointerARB", |
| 174 | )) |
| 175 | |
| 176 | draw_function_names = set(( |
| 177 | 'glDrawArrays', |
| 178 | 'glDrawElements', |
| 179 | 'glDrawRangeElements', |
| 180 | )) |
| 181 | |
José Fonseca | c9f1223 | 2011-03-25 20:07:42 +0000 | [diff] [blame] | 182 | interleaved_formats = [ |
| 183 | 'GL_V2F', |
| 184 | 'GL_V3F', |
| 185 | 'GL_C4UB_V2F', |
| 186 | 'GL_C4UB_V3F', |
| 187 | 'GL_C3F_V3F', |
| 188 | 'GL_N3F_V3F', |
| 189 | 'GL_C4F_N3F_V3F', |
| 190 | 'GL_T2F_V3F', |
| 191 | 'GL_T4F_V4F', |
| 192 | 'GL_T2F_C4UB_V3F', |
| 193 | 'GL_T2F_C3F_V3F', |
| 194 | 'GL_T2F_N3F_V3F', |
| 195 | 'GL_T2F_C4F_N3F_V3F', |
| 196 | 'GL_T4F_C4F_N3F_V4F', |
| 197 | ] |
| 198 | |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 199 | def trace_function_impl_body(self, function): |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 200 | # Defer tracing of user array pointers... |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 201 | if function.name in self.array_pointer_function_names: |
| 202 | print ' GLint __array_buffer = 0;' |
| 203 | print ' __glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);' |
| 204 | print ' if (!__array_buffer) {' |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 205 | self.dispatch_function(function) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 206 | print ' return;' |
| 207 | print ' }' |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 208 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 209 | # ... to the draw calls |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 210 | if function.name in self.draw_function_names: |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 211 | print ' if (__need_user_arrays()) {' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 212 | arg_names = ', '.join([arg.name for arg in function.args[1:]]) |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 213 | print ' GLuint maxindex = __%s_maxindex(%s);' % (function.name, arg_names) |
| 214 | print ' __trace_user_arrays(maxindex);' |
| 215 | print ' }' |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 216 | |
José Fonseca | c9f1223 | 2011-03-25 20:07:42 +0000 | [diff] [blame] | 217 | # And also break down glInterleavedArrays into the individual calls |
| 218 | if function.name == 'glInterleavedArrays': |
| 219 | print ' GLint __array_buffer = 0;' |
| 220 | print ' __glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);' |
| 221 | print ' if (!__array_buffer) {' |
| 222 | self.dispatch_function(function) |
| 223 | print |
| 224 | |
| 225 | # Initialize the enable flags |
| 226 | for camelcase_name, uppercase_name in self.arrays: |
| 227 | flag_name = '__' + uppercase_name.lower() |
| 228 | print ' GLboolean %s = GL_FALSE;' % flag_name |
| 229 | print |
| 230 | |
| 231 | # Swicth for the interleaved formats |
| 232 | print ' switch (format) {' |
| 233 | for format in self.interleaved_formats: |
| 234 | print ' case %s:' % format |
| 235 | for camelcase_name, uppercase_name in self.arrays: |
| 236 | flag_name = '__' + uppercase_name.lower() |
| 237 | if format.find('_' + uppercase_name[0]) >= 0: |
| 238 | print ' %s = GL_TRUE;' % flag_name |
| 239 | print ' break;' |
| 240 | print ' default:' |
| 241 | print ' return;' |
| 242 | print ' }' |
| 243 | print |
| 244 | |
| 245 | # Emit fake glEnableClientState/glDisableClientState flags |
| 246 | for camelcase_name, uppercase_name in self.arrays: |
| 247 | flag_name = '__' + uppercase_name.lower() |
| 248 | enable_name = 'GL_%s_ARRAY' % uppercase_name |
| 249 | |
| 250 | # Emit a fake function |
| 251 | print ' {' |
| 252 | print ' static const Trace::FunctionSig &__sig = %s ? __glEnableClientState_sig : __glDisableClientState_sig;' % flag_name |
| 253 | print ' unsigned __call = Trace::BeginEnter(__sig);' |
| 254 | print ' Trace::BeginArg(0);' |
| 255 | dump_instance(glapi.GLenum, enable_name) |
| 256 | print ' Trace::EndArg();' |
| 257 | print ' Trace::EndEnter();' |
| 258 | print ' Trace::BeginLeave(__call);' |
| 259 | print ' Trace::EndLeave();' |
| 260 | print ' }' |
| 261 | |
| 262 | print ' return;' |
| 263 | print ' }' |
| 264 | |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 265 | Tracer.trace_function_impl_body(self, function) |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 266 | |
José Fonseca | c9f1223 | 2011-03-25 20:07:42 +0000 | [diff] [blame] | 267 | boolean_names = [ |
| 268 | 'GL_FALSE', |
| 269 | 'GL_TRUE', |
| 270 | ] |
| 271 | |
| 272 | def gl_boolean(self, value): |
| 273 | return self.boolean_names[int(bool(value))] |
| 274 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 275 | def dump_arg_instance(self, function, arg): |
| 276 | if function.name in self.draw_function_names and arg.name == 'indices': |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 277 | print ' GLint __element_array_buffer = 0;' |
| 278 | print ' __glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &__element_array_buffer);' |
| 279 | print ' if (!__element_array_buffer) {' |
| 280 | print ' Trace::LiteralBlob((const void *)%s, count*__gl_type_size(type));' % (arg.name) |
| 281 | print ' } else {' |
| 282 | print ' Trace::LiteralOpaque((const void *)%s);' % (arg.name) |
| 283 | print ' }' |
| 284 | return |
| 285 | |
| 286 | Tracer.dump_arg_instance(self, function, arg) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 287 | |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 288 | def state_tracker_impl(self, api): |
| 289 | # A simple state tracker to track the pointer values |
| 290 | |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 291 | # update the state |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 292 | print 'static void __trace_user_arrays(GLuint maxindex)' |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 293 | print '{' |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 294 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 295 | for camelcase_name, uppercase_name in self.arrays: |
| 296 | function_name = 'gl%sPointer' % camelcase_name |
| 297 | enable_name = 'GL_%s_ARRAY' % uppercase_name |
| 298 | binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 299 | function = api.get_function_by_name(function_name) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 300 | |
| 301 | print ' // %s' % function.name |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame^] | 302 | self.array_trace_prolog(api, uppercase_name) |
| 303 | self.array_prolog(api, uppercase_name) |
| 304 | print ' if (__glIsEnabled(%s)) {' % enable_name |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 305 | print ' GLint __binding = 0;' |
| 306 | print ' __glGetIntegerv(%s, &__binding);' % binding_name |
| 307 | print ' if (!__binding) {' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 308 | |
| 309 | # Get the arguments via glGet* |
| 310 | for arg in function.args: |
| 311 | arg_get_enum = 'GL_%s_ARRAY_%s' % (uppercase_name, arg.name.upper()) |
| 312 | arg_get_function, arg_type = TypeGetter().visit(arg.type) |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 313 | print ' %s %s = 0;' % (arg_type, arg.name) |
| 314 | print ' __%s(%s, &%s);' % (arg_get_function, arg_get_enum, arg.name) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 315 | |
| 316 | arg_names = ', '.join([arg.name for arg in function.args[:-1]]) |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 317 | print ' size_t __size = __%s_size(%s, maxindex);' % (function.name, arg_names) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 318 | |
| 319 | # Emit a fake function |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame^] | 320 | self.array_trace_intermezzo(api, uppercase_name) |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 321 | print ' unsigned __call = Trace::BeginEnter(__%s_sig);' % (function.name,) |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 322 | for arg in function.args: |
| 323 | assert not arg.output |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 324 | print ' Trace::BeginArg(%u);' % (arg.index,) |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 325 | if arg.name != 'pointer': |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 326 | dump_instance(arg.type, arg.name) |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 327 | else: |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 328 | print ' Trace::LiteralBlob((const void *)%s, __size);' % (arg.name) |
| 329 | print ' Trace::EndArg();' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 330 | |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 331 | print ' Trace::EndEnter();' |
| 332 | print ' Trace::BeginLeave(__call);' |
| 333 | print ' Trace::EndLeave();' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 334 | print ' }' |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 335 | print ' }' |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame^] | 336 | self.array_epilog(api, uppercase_name) |
| 337 | self.array_trace_epilog(api, uppercase_name) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 338 | print |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 339 | |
| 340 | # Samething, but for glVertexAttribPointer |
| 341 | print ' // glVertexAttribPointer' |
José Fonseca | 0a96525 | 2011-04-14 09:21:15 +0100 | [diff] [blame] | 342 | print ' GLint __max_vertex_attribs = 0;' |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 343 | print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &__max_vertex_attribs);' |
| 344 | print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' |
| 345 | print ' GLint __enabled = 0;' |
| 346 | print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &__enabled);' |
| 347 | print ' if (__enabled) {' |
| 348 | print ' GLint __binding = 0;' |
| 349 | print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &__binding);' |
| 350 | print ' if (!__binding) {' |
| 351 | |
| 352 | function = api.get_function_by_name('glVertexAttribPointer') |
| 353 | |
| 354 | # Get the arguments via glGet* |
| 355 | for arg in function.args[1:]: |
| 356 | arg_get_enum = 'GL_VERTEX_ATTRIB_ARRAY_%s' % (arg.name.upper(),) |
| 357 | arg_get_function, arg_type = TypeGetter('glGetVertexAttrib', False).visit(arg.type) |
| 358 | print ' %s %s = 0;' % (arg_type, arg.name) |
| 359 | print ' __%s(index, %s, &%s);' % (arg_get_function, arg_get_enum, arg.name) |
| 360 | |
| 361 | arg_names = ', '.join([arg.name for arg in function.args[1:-1]]) |
| 362 | print ' size_t __size = __%s_size(%s, maxindex);' % (function.name, arg_names) |
| 363 | |
| 364 | # Emit a fake function |
| 365 | print ' unsigned __call = Trace::BeginEnter(__%s_sig);' % (function.name,) |
| 366 | for arg in function.args: |
| 367 | assert not arg.output |
| 368 | print ' Trace::BeginArg(%u);' % (arg.index,) |
| 369 | if arg.name != 'pointer': |
| 370 | dump_instance(arg.type, arg.name) |
| 371 | else: |
| 372 | print ' Trace::LiteralBlob((const void *)%s, __size);' % (arg.name) |
| 373 | print ' Trace::EndArg();' |
| 374 | |
| 375 | print ' Trace::EndEnter();' |
| 376 | print ' Trace::BeginLeave(__call);' |
| 377 | print ' Trace::EndLeave();' |
| 378 | print ' }' |
| 379 | print ' }' |
| 380 | print ' }' |
| 381 | print |
| 382 | |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 383 | print '}' |
| 384 | print |
| 385 | |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame^] | 386 | # |
| 387 | # Hooks for glTexCoordPointer, which is identical to the other array |
| 388 | # pointers except the fact that it is indexed by glClientActiveTexture. |
| 389 | # |
| 390 | |
| 391 | def array_prolog(self, api, uppercase_name): |
| 392 | if uppercase_name == 'TEXTURE_COORD': |
| 393 | print ' GLint client_active_texture = 0;' |
| 394 | print ' __glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE, &client_active_texture);' |
| 395 | print ' GLint max_texture_coords = 0;' |
| 396 | print ' __glGetIntegerv(GL_MAX_TEXTURE_COORDS, &max_texture_coords);' |
| 397 | print ' for (GLint unit = 0; unit < max_texture_coords; ++unit) {' |
| 398 | print ' GLenum texture = GL_TEXTURE0 + unit;' |
| 399 | print ' __glClientActiveTexture(texture);' |
| 400 | |
| 401 | def array_trace_prolog(self, api, uppercase_name): |
| 402 | if uppercase_name == 'TEXTURE_COORD': |
| 403 | print ' bool client_active_texture_dirty = false;' |
| 404 | |
| 405 | def array_epilog(self, api, uppercase_name): |
| 406 | if uppercase_name == 'TEXTURE_COORD': |
| 407 | print ' }' |
| 408 | self.array_cleanup(api, uppercase_name) |
| 409 | |
| 410 | def array_cleanup(self, api, uppercase_name): |
| 411 | if uppercase_name == 'TEXTURE_COORD': |
| 412 | print ' __glClientActiveTexture(client_active_texture);' |
| 413 | |
| 414 | def array_trace_intermezzo(self, api, uppercase_name): |
| 415 | if uppercase_name == 'TEXTURE_COORD': |
| 416 | print ' if (texture != client_active_texture || client_active_texture_dirty) {' |
| 417 | print ' client_active_texture_dirty = true;' |
| 418 | self.fake_glClientActiveTexture_call(api, "texture"); |
| 419 | print ' }' |
| 420 | |
| 421 | def array_trace_epilog(self, api, uppercase_name): |
| 422 | if uppercase_name == 'TEXTURE_COORD': |
| 423 | print ' if (client_active_texture_dirty) {' |
| 424 | self.fake_glClientActiveTexture_call(api, "client_active_texture"); |
| 425 | print ' }' |
| 426 | |
| 427 | def fake_glClientActiveTexture_call(self, api, texture): |
| 428 | function = api.get_function_by_name('glClientActiveTexture') |
| 429 | self.fake_call(function, [texture]) |
| 430 | |
| 431 | def fake_call(self, function, args): |
| 432 | print ' unsigned __fake_call = Trace::BeginEnter(__%s_sig);' % (function.name,) |
| 433 | for arg, instance in zip(function.args, args): |
| 434 | assert not arg.output |
| 435 | print ' Trace::BeginArg(%u);' % (arg.index,) |
| 436 | dump_instance(arg.type, instance) |
| 437 | print ' Trace::EndArg();' |
| 438 | print ' Trace::EndEnter();' |
| 439 | print ' Trace::BeginLeave(__fake_call);' |
| 440 | print ' Trace::EndLeave();' |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 446 | |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | |