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 | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 40 | def __init__(self, prefix = 'glGet', long_suffix = True, ext_suffix = ''): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 41 | self.prefix = prefix |
| 42 | self.long_suffix = long_suffix |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 43 | self.ext_suffix = ext_suffix |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 44 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 45 | def visit_const(self, const): |
| 46 | return self.visit(const.type) |
| 47 | |
| 48 | def visit_alias(self, alias): |
| 49 | if alias.expr == 'GLboolean': |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 50 | if self.long_suffix: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 51 | suffix = 'Booleanv' |
| 52 | arg_type = alias.expr |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 53 | else: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 54 | suffix = 'iv' |
| 55 | arg_type = 'GLint' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 56 | elif alias.expr == 'GLdouble': |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 57 | if self.long_suffix: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 58 | suffix = 'Doublev' |
| 59 | arg_type = alias.expr |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 60 | else: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 61 | suffix = 'dv' |
| 62 | arg_type = alias.expr |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 63 | elif alias.expr == 'GLfloat': |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 64 | if self.long_suffix: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 65 | suffix = 'Floatv' |
| 66 | arg_type = alias.expr |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 67 | else: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 68 | suffix = 'fv' |
| 69 | arg_type = alias.expr |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 70 | elif alias.expr in ('GLint', 'GLuint', 'GLsizei'): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 71 | if self.long_suffix: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 72 | suffix = 'Integerv' |
| 73 | arg_type = 'GLint' |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 74 | else: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 75 | suffix = 'iv' |
| 76 | arg_type = 'GLint' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 77 | else: |
| 78 | print alias.expr |
| 79 | assert False |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 80 | function_name = self.prefix + suffix + self.ext_suffix |
| 81 | return function_name, arg_type |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 82 | |
| 83 | def visit_enum(self, enum): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 84 | return self.visit(glapi.GLint) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 85 | |
| 86 | def visit_bitmask(self, bitmask): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 87 | return self.visit(glapi.GLint) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 88 | |
| 89 | def visit_opaque(self, pointer): |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 90 | return self.prefix + 'Pointerv' + self.ext_suffix, 'GLvoid *' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 91 | |
| 92 | |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 93 | class GlTracer(Tracer): |
| 94 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 95 | arrays = [ |
| 96 | ("Vertex", "VERTEX"), |
| 97 | ("Normal", "NORMAL"), |
| 98 | ("Color", "COLOR"), |
| 99 | ("Index", "INDEX"), |
| 100 | ("TexCoord", "TEXTURE_COORD"), |
| 101 | ("EdgeFlag", "EDGE_FLAG"), |
| 102 | ("FogCoord", "FOG_COORD"), |
| 103 | ("SecondaryColor", "SECONDARY_COLOR"), |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 104 | ] |
José Fonseca | c9f1223 | 2011-03-25 20:07:42 +0000 | [diff] [blame] | 105 | arrays.reverse() |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 106 | |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 107 | def header(self, api): |
| 108 | Tracer.header(self, api) |
| 109 | |
José Fonseca | 1b3d375 | 2011-07-15 10:15:19 +0100 | [diff] [blame^] | 110 | print '#include "gltrace.hpp"' |
| 111 | print |
José Fonseca | 25ebe54 | 2011-04-24 10:08:22 +0100 | [diff] [blame] | 112 | print '// Whether user arrays were used' |
| 113 | print 'static bool __user_arrays = false;' |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 114 | print 'static bool __user_arrays_arb = false;' |
| 115 | print 'static bool __user_arrays_nv = false;' |
José Fonseca | 25ebe54 | 2011-04-24 10:08:22 +0100 | [diff] [blame] | 116 | print |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 117 | |
| 118 | # Which glVertexAttrib* variant to use |
| 119 | print 'enum vertex_attrib {' |
| 120 | print ' VERTEX_ATTRIB,' |
| 121 | print ' VERTEX_ATTRIB_ARB,' |
| 122 | print ' VERTEX_ATTRIB_NV,' |
| 123 | print '};' |
| 124 | print |
| 125 | print 'static vertex_attrib __get_vertex_attrib(void) {' |
José Fonseca | d5b95b3 | 2011-06-29 17:41:02 +0100 | [diff] [blame] | 126 | print ' if (__user_arrays_arb || __user_arrays_nv) {' |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 127 | print ' GLboolean __vertex_program = GL_FALSE;' |
| 128 | print ' __glGetBooleanv(GL_VERTEX_PROGRAM_ARB, &__vertex_program);' |
| 129 | print ' if (__vertex_program) {' |
| 130 | print ' if (__user_arrays_nv) {' |
| 131 | print ' GLint __vertex_program_binding_nv = 0;' |
| 132 | print ' __glGetIntegerv(GL_VERTEX_PROGRAM_BINDING_NV, &__vertex_program_binding_nv);' |
| 133 | print ' if (__vertex_program_binding_nv) {' |
| 134 | print ' return VERTEX_ATTRIB_NV;' |
| 135 | print ' }' |
| 136 | print ' }' |
| 137 | print ' return VERTEX_ATTRIB_ARB;' |
| 138 | print ' }' |
| 139 | print ' }' |
| 140 | print ' return VERTEX_ATTRIB;' |
| 141 | print '}' |
| 142 | print |
| 143 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 144 | # Whether we need user arrays |
| 145 | print 'static inline bool __need_user_arrays(void)' |
| 146 | print '{' |
José Fonseca | 25ebe54 | 2011-04-24 10:08:22 +0100 | [diff] [blame] | 147 | print ' if (!__user_arrays) {' |
| 148 | print ' return false;' |
| 149 | print ' }' |
| 150 | print |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 151 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 152 | for camelcase_name, uppercase_name in self.arrays: |
| 153 | function_name = 'gl%sPointer' % camelcase_name |
| 154 | enable_name = 'GL_%s_ARRAY' % uppercase_name |
| 155 | binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name |
| 156 | print ' // %s' % function_name |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 157 | self.array_prolog(api, uppercase_name) |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 158 | print ' if (__glIsEnabled(%s)) {' % enable_name |
| 159 | print ' GLint __binding = 0;' |
| 160 | print ' __glGetIntegerv(%s, &__binding);' % binding_name |
| 161 | print ' if (!__binding) {' |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 162 | self.array_cleanup(api, uppercase_name) |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 163 | print ' return true;' |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 164 | print ' }' |
| 165 | print ' }' |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 166 | self.array_epilog(api, uppercase_name) |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 167 | print |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 168 | |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 169 | print ' vertex_attrib __vertex_attrib = __get_vertex_attrib();' |
| 170 | print |
| 171 | print ' // glVertexAttribPointer' |
| 172 | print ' if (__vertex_attrib == VERTEX_ATTRIB) {' |
| 173 | print ' GLint __max_vertex_attribs = 0;' |
| 174 | print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &__max_vertex_attribs);' |
| 175 | print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' |
| 176 | print ' GLint __enabled = 0;' |
| 177 | print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &__enabled);' |
| 178 | print ' if (__enabled) {' |
| 179 | print ' GLint __binding = 0;' |
| 180 | print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &__binding);' |
| 181 | print ' if (!__binding) {' |
| 182 | print ' return true;' |
| 183 | print ' }' |
| 184 | print ' }' |
| 185 | print ' }' |
| 186 | print ' }' |
| 187 | print |
| 188 | print ' // glVertexAttribPointerARB' |
| 189 | print ' if (__vertex_attrib == VERTEX_ATTRIB_ARB) {' |
José Fonseca | d94aaac | 2011-06-28 20:50:49 +0100 | [diff] [blame] | 190 | print ' GLint __max_vertex_attribs = 0;' |
| 191 | print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &__max_vertex_attribs);' |
| 192 | print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' |
| 193 | print ' GLint __enabled = 0;' |
| 194 | print ' __glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB, &__enabled);' |
| 195 | print ' if (__enabled) {' |
| 196 | print ' GLint __binding = 0;' |
| 197 | print ' __glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB, &__binding);' |
| 198 | print ' if (!__binding) {' |
| 199 | print ' return true;' |
| 200 | print ' }' |
| 201 | print ' }' |
| 202 | print ' }' |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 203 | print ' }' |
| 204 | print |
| 205 | print ' // glVertexAttribPointerNV' |
| 206 | print ' if (__vertex_attrib == VERTEX_ATTRIB_NV) {' |
| 207 | print ' for (GLint index = 0; index < 16; ++index) {' |
José Fonseca | d94aaac | 2011-06-28 20:50:49 +0100 | [diff] [blame] | 208 | print ' GLint __enabled = 0;' |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 209 | print ' __glGetIntegerv(GL_VERTEX_ATTRIB_ARRAY0_NV + index, &__enabled);' |
José Fonseca | d94aaac | 2011-06-28 20:50:49 +0100 | [diff] [blame] | 210 | print ' if (__enabled) {' |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 211 | print ' return true;' |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 212 | print ' }' |
| 213 | print ' }' |
| 214 | print ' }' |
| 215 | print |
| 216 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 217 | print ' return false;' |
| 218 | print '}' |
| 219 | print |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 220 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 221 | print 'static void __trace_user_arrays(GLuint maxindex);' |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 222 | print |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 223 | |
| 224 | print 'struct buffer_mapping {' |
| 225 | print ' void *map;' |
| 226 | print ' GLint length;' |
| 227 | print ' bool write;' |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 228 | print ' bool explicit_flush;' |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 229 | print '};' |
| 230 | print |
| 231 | for target in self.buffer_targets: |
| 232 | print 'struct buffer_mapping __%s_mapping;' % target.lower(); |
| 233 | print |
| 234 | print 'static inline struct buffer_mapping *' |
| 235 | print 'get_buffer_mapping(GLenum target) {' |
| 236 | print ' switch(target) {' |
| 237 | for target in self.buffer_targets: |
| 238 | print ' case GL_%s:' % target |
| 239 | print ' return & __%s_mapping;' % target.lower() |
| 240 | print ' default:' |
José Fonseca | cbd225f | 2011-06-09 00:07:18 +0100 | [diff] [blame] | 241 | print ' OS::DebugMessage("apitrace: warning: unknown buffer target 0x%04X\\n", target);' |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 242 | print ' return NULL;' |
| 243 | print ' }' |
| 244 | print '}' |
| 245 | print |
| 246 | |
| 247 | # Generate memcpy's signature |
| 248 | self.trace_function_decl(glapi.memcpy) |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 249 | |
| 250 | # Generate a helper function to determine whether a parameter name |
| 251 | # refers to a symbolic value or not |
| 252 | print 'static bool' |
| 253 | print 'is_symbolic_pname(GLenum pname) {' |
| 254 | print ' switch(pname) {' |
José Fonseca | 5ea9187 | 2011-05-04 09:41:55 +0100 | [diff] [blame] | 255 | for function, type, count, name in glparams.parameters: |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 256 | if type is glapi.GLenum: |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 257 | print ' case %s:' % name |
| 258 | print ' return true;' |
| 259 | print ' default:' |
| 260 | print ' return false;' |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 261 | print ' }' |
| 262 | print '}' |
| 263 | print |
| 264 | |
| 265 | # Generate a helper function to determine whether a parameter value is |
| 266 | # potentially symbolic or not; i.e., if the value can be represented in |
| 267 | # an enum or not |
| 268 | print 'template<class T>' |
| 269 | print 'static inline bool' |
| 270 | print 'is_symbolic_param(T param) {' |
| 271 | print ' return static_cast<T>(static_cast<GLenum>(param)) == param;' |
| 272 | print '}' |
| 273 | print |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 274 | |
| 275 | # Generate a helper function to know how many elements a parameter has |
| 276 | print 'static size_t' |
José Fonseca | f4aca5d | 2011-05-08 08:29:30 +0100 | [diff] [blame] | 277 | print '__gl_param_size(GLenum pname) {' |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 278 | print ' switch(pname) {' |
José Fonseca | 5ea9187 | 2011-05-04 09:41:55 +0100 | [diff] [blame] | 279 | for function, type, count, name in glparams.parameters: |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 280 | if type is not None: |
| 281 | print ' case %s: return %u;' % (name, count) |
| 282 | print ' case GL_COMPRESSED_TEXTURE_FORMATS: {' |
| 283 | print ' GLint num_compressed_texture_formats = 0;' |
| 284 | print ' __glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &num_compressed_texture_formats);' |
| 285 | print ' return num_compressed_texture_formats;' |
| 286 | print ' }' |
| 287 | print ' default:' |
José Fonseca | cbd225f | 2011-06-09 00:07:18 +0100 | [diff] [blame] | 288 | print r' OS::DebugMessage("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);' |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 289 | print ' return 1;' |
| 290 | print ' }' |
| 291 | print '}' |
| 292 | print |
| 293 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 294 | array_pointer_function_names = set(( |
| 295 | "glVertexPointer", |
| 296 | "glNormalPointer", |
| 297 | "glColorPointer", |
| 298 | "glIndexPointer", |
| 299 | "glTexCoordPointer", |
| 300 | "glEdgeFlagPointer", |
| 301 | "glFogCoordPointer", |
| 302 | "glSecondaryColorPointer", |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 303 | |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 304 | "glInterleavedArrays", |
| 305 | |
José Fonseca | 7e0bfd9 | 2011-04-30 23:09:03 +0100 | [diff] [blame] | 306 | "glVertexPointerEXT", |
| 307 | "glNormalPointerEXT", |
| 308 | "glColorPointerEXT", |
| 309 | "glIndexPointerEXT", |
| 310 | "glTexCoordPointerEXT", |
| 311 | "glEdgeFlagPointerEXT", |
| 312 | "glFogCoordPointerEXT", |
| 313 | "glSecondaryColorPointerEXT", |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 314 | |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 315 | "glVertexAttribPointer", |
| 316 | "glVertexAttribPointerARB", |
| 317 | "glVertexAttribPointerNV", |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 318 | "glVertexAttribIPointer", |
| 319 | "glVertexAttribIPointerEXT", |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 320 | "glVertexAttribLPointer", |
| 321 | "glVertexAttribLPointerEXT", |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 322 | |
| 323 | #"glMatrixIndexPointerARB", |
| 324 | )) |
| 325 | |
| 326 | draw_function_names = set(( |
| 327 | 'glDrawArrays', |
| 328 | 'glDrawElements', |
| 329 | 'glDrawRangeElements', |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 330 | 'glMultiDrawArrays', |
| 331 | 'glMultiDrawElements', |
| 332 | 'glDrawArraysInstanced', |
| 333 | 'glDrawElementsInstanced', |
| 334 | 'glDrawArraysInstancedARB', |
| 335 | 'glDrawElementsInstancedARB', |
| 336 | 'glDrawElementsBaseVertex', |
| 337 | 'glDrawRangeElementsBaseVertex', |
| 338 | 'glDrawElementsInstancedBaseVertex', |
| 339 | 'glMultiDrawElementsBaseVertex', |
| 340 | 'glDrawArraysIndirect', |
| 341 | 'glDrawElementsIndirect', |
| 342 | 'glDrawArraysEXT', |
José Fonseca | 7e0bfd9 | 2011-04-30 23:09:03 +0100 | [diff] [blame] | 343 | 'glDrawRangeElementsEXT', |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 344 | 'glDrawRangeElementsEXT_size', |
| 345 | 'glMultiDrawArraysEXT', |
| 346 | 'glMultiDrawElementsEXT', |
| 347 | 'glMultiModeDrawArraysIBM', |
| 348 | 'glMultiModeDrawElementsIBM', |
| 349 | 'glDrawArraysInstancedEXT', |
| 350 | 'glDrawElementsInstancedEXT', |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 351 | )) |
| 352 | |
José Fonseca | c9f1223 | 2011-03-25 20:07:42 +0000 | [diff] [blame] | 353 | interleaved_formats = [ |
| 354 | 'GL_V2F', |
| 355 | 'GL_V3F', |
| 356 | 'GL_C4UB_V2F', |
| 357 | 'GL_C4UB_V3F', |
| 358 | 'GL_C3F_V3F', |
| 359 | 'GL_N3F_V3F', |
| 360 | 'GL_C4F_N3F_V3F', |
| 361 | 'GL_T2F_V3F', |
| 362 | 'GL_T4F_V4F', |
| 363 | 'GL_T2F_C4UB_V3F', |
| 364 | 'GL_T2F_C3F_V3F', |
| 365 | 'GL_T2F_N3F_V3F', |
| 366 | 'GL_T2F_C4F_N3F_V3F', |
| 367 | 'GL_T4F_C4F_N3F_V4F', |
| 368 | ] |
| 369 | |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 370 | def trace_function_impl_body(self, function): |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 371 | # Defer tracing of user array pointers... |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 372 | if function.name in self.array_pointer_function_names: |
| 373 | print ' GLint __array_buffer = 0;' |
| 374 | print ' __glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);' |
| 375 | print ' if (!__array_buffer) {' |
José Fonseca | 25ebe54 | 2011-04-24 10:08:22 +0100 | [diff] [blame] | 376 | print ' __user_arrays = true;' |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 377 | if function.name == "glVertexAttribPointerARB": |
| 378 | print ' __user_arrays_arb = true;' |
| 379 | if function.name == "glVertexAttribPointerNV": |
| 380 | print ' __user_arrays_nv = true;' |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 381 | self.dispatch_function(function) |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 382 | |
| 383 | # And also break down glInterleavedArrays into the individual calls |
| 384 | if function.name == 'glInterleavedArrays': |
| 385 | print |
| 386 | |
| 387 | # Initialize the enable flags |
| 388 | for camelcase_name, uppercase_name in self.arrays: |
| 389 | flag_name = '__' + uppercase_name.lower() |
| 390 | print ' GLboolean %s = GL_FALSE;' % flag_name |
| 391 | print |
| 392 | |
| 393 | # Switch for the interleaved formats |
| 394 | print ' switch (format) {' |
| 395 | for format in self.interleaved_formats: |
| 396 | print ' case %s:' % format |
| 397 | for camelcase_name, uppercase_name in self.arrays: |
| 398 | flag_name = '__' + uppercase_name.lower() |
| 399 | if format.find('_' + uppercase_name[0]) >= 0: |
| 400 | print ' %s = GL_TRUE;' % flag_name |
| 401 | print ' break;' |
| 402 | print ' default:' |
| 403 | print ' return;' |
| 404 | print ' }' |
| 405 | print |
| 406 | |
| 407 | # Emit fake glEnableClientState/glDisableClientState flags |
| 408 | for camelcase_name, uppercase_name in self.arrays: |
| 409 | flag_name = '__' + uppercase_name.lower() |
| 410 | enable_name = 'GL_%s_ARRAY' % uppercase_name |
| 411 | |
| 412 | # Emit a fake function |
| 413 | print ' {' |
| 414 | print ' static const Trace::FunctionSig &__sig = %s ? __glEnableClientState_sig : __glDisableClientState_sig;' % flag_name |
José Fonseca | 466753b | 2011-05-28 13:25:55 +0100 | [diff] [blame] | 415 | print ' unsigned __call = __writer.beginEnter(&__sig);' |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame] | 416 | print ' __writer.beginArg(0);' |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 417 | dump_instance(glapi.GLenum, enable_name) |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame] | 418 | print ' __writer.endArg();' |
| 419 | print ' __writer.endEnter();' |
| 420 | print ' __writer.beginLeave(__call);' |
| 421 | print ' __writer.endLeave();' |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 422 | print ' }' |
| 423 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 424 | print ' return;' |
| 425 | print ' }' |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 426 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 427 | # ... to the draw calls |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 428 | if function.name in self.draw_function_names: |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 429 | print ' if (__need_user_arrays()) {' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 430 | arg_names = ', '.join([arg.name for arg in function.args[1:]]) |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 431 | print ' GLuint maxindex = __%s_maxindex(%s);' % (function.name, arg_names) |
| 432 | print ' __trace_user_arrays(maxindex);' |
| 433 | print ' }' |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 434 | |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 435 | # Emit a fake memcpy on buffer uploads |
| 436 | if function.name in ('glUnmapBuffer', 'glUnmapBufferARB', ): |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 437 | print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 438 | print ' if (mapping && mapping->write && !mapping->explicit_flush) {' |
| 439 | self.emit_memcpy('mapping->map', 'mapping->map', 'mapping->length') |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 440 | print ' }' |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 441 | if function.name in ('glFlushMappedBufferRange', 'glFlushMappedBufferRangeAPPLE'): |
| 442 | # TODO: avoid copying [0, offset] bytes |
| 443 | print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' |
| 444 | print ' if (mapping) {' |
| 445 | if function.name.endswith('APPLE'): |
| 446 | print ' GLsizeiptr length = size;' |
| 447 | print ' mapping->explicit_flush = true;' |
| 448 | print ' //assert(offset + length <= mapping->length);' |
| 449 | self.emit_memcpy('mapping->map', 'mapping->map', 'offset + length') |
| 450 | print ' }' |
| 451 | # FIXME: glFlushMappedNamedBufferRangeEXT |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 452 | |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 453 | # Don't leave vertex attrib locations to chance. Instead emit fake |
| 454 | # glBindAttribLocation calls to ensure that the same locations will be |
| 455 | # used when retracing. Trying to remap locations after the fact would |
| 456 | # be an herculian task given that vertex attrib locations appear in |
| 457 | # many entry-points, including non-shader related ones. |
| 458 | if function.name == 'glLinkProgram': |
| 459 | Tracer.dispatch_function(self, function) |
| 460 | print ' GLint active_attributes = 0;' |
| 461 | print ' __glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &active_attributes);' |
| 462 | print ' for (GLuint attrib = 0; attrib < active_attributes; ++attrib) {' |
| 463 | print ' GLint size = 0;' |
| 464 | print ' GLenum type = 0;' |
| 465 | print ' GLchar name[256];' |
| 466 | # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256 |
| 467 | print ' __glGetActiveAttrib(program, attrib, sizeof name, NULL, &size, &type, name);' |
José Fonseca | 2a794f5 | 2011-05-26 20:54:29 +0100 | [diff] [blame] | 468 | print " if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {" |
| 469 | print ' GLint location = __glGetAttribLocation(program, name);' |
| 470 | print ' if (location >= 0) {' |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 471 | bind_function = glapi.glapi.get_function_by_name('glBindAttribLocation') |
| 472 | self.fake_call(bind_function, ['program', 'location', 'name']) |
José Fonseca | 2a794f5 | 2011-05-26 20:54:29 +0100 | [diff] [blame] | 473 | print ' }' |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 474 | print ' }' |
| 475 | print ' }' |
| 476 | if function.name == 'glLinkProgramARB': |
| 477 | Tracer.dispatch_function(self, function) |
| 478 | print ' GLint active_attributes = 0;' |
| 479 | print ' __glGetObjectParameterivARB(programObj, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB, &active_attributes);' |
| 480 | print ' for (GLuint attrib = 0; attrib < active_attributes; ++attrib) {' |
| 481 | print ' GLint size = 0;' |
| 482 | print ' GLenum type = 0;' |
| 483 | print ' GLcharARB name[256];' |
| 484 | # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256 |
| 485 | print ' __glGetActiveAttribARB(programObj, attrib, sizeof name, NULL, &size, &type, name);' |
José Fonseca | 2a794f5 | 2011-05-26 20:54:29 +0100 | [diff] [blame] | 486 | print " if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {" |
| 487 | print ' GLint location = __glGetAttribLocationARB(programObj, name);' |
| 488 | print ' if (location >= 0) {' |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 489 | bind_function = glapi.glapi.get_function_by_name('glBindAttribLocationARB') |
| 490 | self.fake_call(bind_function, ['programObj', 'location', 'name']) |
José Fonseca | 2a794f5 | 2011-05-26 20:54:29 +0100 | [diff] [blame] | 491 | print ' }' |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 492 | print ' }' |
| 493 | print ' }' |
| 494 | |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 495 | Tracer.trace_function_impl_body(self, function) |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 496 | |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 497 | def dispatch_function(self, function): |
| 498 | if function.name in ('glLinkProgram', 'glLinkProgramARB'): |
| 499 | # These functions have been dispatched already |
| 500 | return |
| 501 | |
José Fonseca | 1b3d375 | 2011-07-15 10:15:19 +0100 | [diff] [blame^] | 502 | # We implement the GREMEDY extensions, not the driver |
| 503 | if function.name in ('glStringMarkerGREMEDY', 'glFrameTerminatorGREMEDY'): |
| 504 | return |
| 505 | |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 506 | Tracer.dispatch_function(self, function) |
| 507 | |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 508 | def emit_memcpy(self, dest, src, length): |
José Fonseca | 466753b | 2011-05-28 13:25:55 +0100 | [diff] [blame] | 509 | print ' unsigned __call = __writer.beginEnter(&__memcpy_sig);' |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame] | 510 | print ' __writer.beginArg(0);' |
| 511 | print ' __writer.writeOpaque(%s);' % dest |
| 512 | print ' __writer.endArg();' |
| 513 | print ' __writer.beginArg(1);' |
| 514 | print ' __writer.writeBlob(%s, %s);' % (src, length) |
| 515 | print ' __writer.endArg();' |
| 516 | print ' __writer.beginArg(2);' |
| 517 | print ' __writer.writeUInt(%s);' % length |
| 518 | print ' __writer.endArg();' |
| 519 | print ' __writer.endEnter();' |
| 520 | print ' __writer.beginLeave(__call);' |
| 521 | print ' __writer.endLeave();' |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 522 | |
| 523 | buffer_targets = [ |
| 524 | 'ARRAY_BUFFER', |
| 525 | 'ELEMENT_ARRAY_BUFFER', |
| 526 | 'PIXEL_PACK_BUFFER', |
| 527 | 'PIXEL_UNPACK_BUFFER', |
| 528 | ] |
| 529 | |
| 530 | def wrap_ret(self, function, instance): |
| 531 | Tracer.wrap_ret(self, function, instance) |
José Fonseca | 1b3d375 | 2011-07-15 10:15:19 +0100 | [diff] [blame^] | 532 | |
| 533 | if function.name == 'glGetString': |
| 534 | print ' if (__result) {' |
| 535 | print ' switch (name) {' |
| 536 | print ' case GL_EXTENSIONS:' |
| 537 | print ' __result = gltrace::translateExtensionsString(__result);' |
| 538 | print ' break;' |
| 539 | print ' default:' |
| 540 | print ' break;' |
| 541 | print ' }' |
| 542 | print ' }' |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 543 | |
| 544 | if function.name in ('glMapBuffer', 'glMapBufferARB'): |
| 545 | print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' |
| 546 | print ' if (mapping) {' |
| 547 | print ' mapping->map = %s;' % (instance) |
| 548 | print ' mapping->length = 0;' |
| 549 | print ' __glGetBufferParameteriv(target, GL_BUFFER_SIZE, &mapping->length);' |
| 550 | print ' mapping->write = (access != GL_READ_ONLY);' |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 551 | print ' mapping->explicit_flush = false;' |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 552 | print ' }' |
| 553 | |
| 554 | if function.name == 'glMapBufferRange': |
| 555 | print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' |
| 556 | print ' if (mapping) {' |
| 557 | print ' mapping->map = %s;' % (instance) |
| 558 | print ' mapping->length = length;' |
| 559 | print ' mapping->write = access & GL_MAP_WRITE_BIT;' |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 560 | print ' mapping->explicit_flush = access & GL_MAP_FLUSH_EXPLICIT_BIT;' |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 561 | print ' }' |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 562 | |
José Fonseca | c9f1223 | 2011-03-25 20:07:42 +0000 | [diff] [blame] | 563 | boolean_names = [ |
| 564 | 'GL_FALSE', |
| 565 | 'GL_TRUE', |
| 566 | ] |
| 567 | |
| 568 | def gl_boolean(self, value): |
| 569 | return self.boolean_names[int(bool(value))] |
| 570 | |
José Fonseca | c29f4f1 | 2011-06-11 12:19:05 +0100 | [diff] [blame] | 571 | # Names of the functions that unpack from a pixel buffer object. See the |
| 572 | # ARB_pixel_buffer_object specification. |
José Fonseca | e97bab9 | 2011-06-02 23:15:11 +0100 | [diff] [blame] | 573 | unpack_function_names = set([ |
| 574 | 'glBitmap', |
José Fonseca | c29f4f1 | 2011-06-11 12:19:05 +0100 | [diff] [blame] | 575 | 'glColorSubTable', |
| 576 | 'glColorTable', |
| 577 | 'glCompressedTexImage1D', |
| 578 | 'glCompressedTexImage2D', |
| 579 | 'glCompressedTexImage3D', |
| 580 | 'glCompressedTexSubImage1D', |
| 581 | 'glCompressedTexSubImage2D', |
| 582 | 'glCompressedTexSubImage3D', |
| 583 | 'glConvolutionFilter1D', |
| 584 | 'glConvolutionFilter2D', |
José Fonseca | e97bab9 | 2011-06-02 23:15:11 +0100 | [diff] [blame] | 585 | 'glDrawPixels', |
| 586 | 'glMultiTexImage1DEXT', |
| 587 | 'glMultiTexImage2DEXT', |
| 588 | 'glMultiTexImage3DEXT', |
| 589 | 'glMultiTexSubImage1DEXT', |
| 590 | 'glMultiTexSubImage2DEXT', |
| 591 | 'glMultiTexSubImage3DEXT', |
José Fonseca | c29f4f1 | 2011-06-11 12:19:05 +0100 | [diff] [blame] | 592 | 'glPixelMapfv', |
| 593 | 'glPixelMapuiv', |
| 594 | 'glPixelMapusv', |
José Fonseca | e97bab9 | 2011-06-02 23:15:11 +0100 | [diff] [blame] | 595 | 'glPolygonStipple', |
José Fonseca | c29f4f1 | 2011-06-11 12:19:05 +0100 | [diff] [blame] | 596 | 'glSeparableFilter2D', |
José Fonseca | e97bab9 | 2011-06-02 23:15:11 +0100 | [diff] [blame] | 597 | 'glTexImage1D', |
| 598 | 'glTexImage1DEXT', |
| 599 | 'glTexImage2D', |
| 600 | 'glTexImage2DEXT', |
| 601 | 'glTexImage3D', |
| 602 | 'glTexImage3DEXT', |
| 603 | 'glTexSubImage1D', |
| 604 | 'glTexSubImage1DEXT', |
| 605 | 'glTexSubImage2D', |
| 606 | 'glTexSubImage2DEXT', |
| 607 | 'glTexSubImage3D', |
| 608 | 'glTexSubImage3DEXT', |
| 609 | 'glTextureImage1DEXT', |
| 610 | 'glTextureImage2DEXT', |
| 611 | 'glTextureImage3DEXT', |
| 612 | 'glTextureSubImage1DEXT', |
| 613 | 'glTextureSubImage2DEXT', |
| 614 | 'glTextureSubImage3DEXT', |
| 615 | ]) |
| 616 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 617 | def dump_arg_instance(self, function, arg): |
| 618 | if function.name in self.draw_function_names and arg.name == 'indices': |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 619 | print ' GLint __element_array_buffer = 0;' |
| 620 | print ' __glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &__element_array_buffer);' |
| 621 | print ' if (!__element_array_buffer) {' |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 622 | if isinstance(arg.type, stdapi.Array): |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame] | 623 | print ' __writer.beginArray(%s);' % arg.type.length |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 624 | print ' for(GLsizei i = 0; i < %s; ++i) {' % arg.type.length |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame] | 625 | print ' __writer.beginElement();' |
José Fonseca | fd34e4e | 2011-06-03 19:34:29 +0100 | [diff] [blame] | 626 | print ' __writer.writeBlob(%s[i], count[i]*__gl_type_size(type));' % (arg.name) |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame] | 627 | print ' __writer.endElement();' |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 628 | print ' }' |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame] | 629 | print ' __writer.endArray();' |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 630 | else: |
José Fonseca | fd34e4e | 2011-06-03 19:34:29 +0100 | [diff] [blame] | 631 | print ' __writer.writeBlob(%s, count*__gl_type_size(type));' % (arg.name) |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 632 | print ' } else {' |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 633 | Tracer.dump_arg_instance(self, function, arg) |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 634 | print ' }' |
| 635 | return |
| 636 | |
José Fonseca | e97bab9 | 2011-06-02 23:15:11 +0100 | [diff] [blame] | 637 | # Recognize offsets instead of blobs when a PBO is bound |
| 638 | if function.name in self.unpack_function_names \ |
| 639 | and (isinstance(arg.type, stdapi.Blob) \ |
| 640 | or (isinstance(arg.type, stdapi.Const) \ |
| 641 | and isinstance(arg.type.type, stdapi.Blob))): |
José Fonseca | c29f4f1 | 2011-06-11 12:19:05 +0100 | [diff] [blame] | 642 | print ' {' |
| 643 | print ' GLint __unpack_buffer = 0;' |
| 644 | print ' __glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &__unpack_buffer);' |
| 645 | print ' if (__unpack_buffer) {' |
| 646 | print ' __writer.writeOpaque(%s);' % arg.name |
| 647 | print ' } else {' |
José Fonseca | e97bab9 | 2011-06-02 23:15:11 +0100 | [diff] [blame] | 648 | Tracer.dump_arg_instance(self, function, arg) |
José Fonseca | c29f4f1 | 2011-06-11 12:19:05 +0100 | [diff] [blame] | 649 | print ' }' |
José Fonseca | e97bab9 | 2011-06-02 23:15:11 +0100 | [diff] [blame] | 650 | print ' }' |
| 651 | return |
| 652 | |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 653 | # Several GL state functions take GLenum symbolic names as |
| 654 | # integer/floats; so dump the symbolic name whenever possible |
José Fonseca | 3bcb33c | 2011-05-27 20:14:31 +0100 | [diff] [blame] | 655 | if function.name.startswith('gl') \ |
| 656 | and arg.type in (glapi.GLint, glapi.GLfloat) \ |
| 657 | and arg.name == 'param': |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 658 | assert arg.index > 0 |
| 659 | assert function.args[arg.index - 1].name == 'pname' |
| 660 | assert function.args[arg.index - 1].type == glapi.GLenum |
| 661 | print ' if (is_symbolic_pname(pname) && is_symbolic_param(%s)) {' % arg.name |
| 662 | dump_instance(glapi.GLenum, arg.name) |
| 663 | print ' } else {' |
| 664 | Tracer.dump_arg_instance(self, function, arg) |
| 665 | print ' }' |
| 666 | return |
| 667 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 668 | Tracer.dump_arg_instance(self, function, arg) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 669 | |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 670 | def footer(self, api): |
| 671 | Tracer.footer(self, api) |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 672 | |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 673 | # A simple state tracker to track the pointer values |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 674 | # update the state |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 675 | print 'static void __trace_user_arrays(GLuint maxindex)' |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 676 | print '{' |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 677 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 678 | for camelcase_name, uppercase_name in self.arrays: |
| 679 | function_name = 'gl%sPointer' % camelcase_name |
| 680 | enable_name = 'GL_%s_ARRAY' % uppercase_name |
| 681 | binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 682 | function = api.get_function_by_name(function_name) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 683 | |
| 684 | print ' // %s' % function.name |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 685 | self.array_trace_prolog(api, uppercase_name) |
| 686 | self.array_prolog(api, uppercase_name) |
| 687 | print ' if (__glIsEnabled(%s)) {' % enable_name |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 688 | print ' GLint __binding = 0;' |
| 689 | print ' __glGetIntegerv(%s, &__binding);' % binding_name |
| 690 | print ' if (!__binding) {' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 691 | |
| 692 | # Get the arguments via glGet* |
| 693 | for arg in function.args: |
| 694 | arg_get_enum = 'GL_%s_ARRAY_%s' % (uppercase_name, arg.name.upper()) |
| 695 | arg_get_function, arg_type = TypeGetter().visit(arg.type) |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 696 | print ' %s %s = 0;' % (arg_type, arg.name) |
| 697 | print ' __%s(%s, &%s);' % (arg_get_function, arg_get_enum, arg.name) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 698 | |
| 699 | arg_names = ', '.join([arg.name for arg in function.args[:-1]]) |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 700 | print ' size_t __size = __%s_size(%s, maxindex);' % (function.name, arg_names) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 701 | |
| 702 | # Emit a fake function |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 703 | self.array_trace_intermezzo(api, uppercase_name) |
José Fonseca | 466753b | 2011-05-28 13:25:55 +0100 | [diff] [blame] | 704 | print ' unsigned __call = __writer.beginEnter(&__%s_sig);' % (function.name,) |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 705 | for arg in function.args: |
| 706 | assert not arg.output |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame] | 707 | print ' __writer.beginArg(%u);' % (arg.index,) |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 708 | if arg.name != 'pointer': |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 709 | dump_instance(arg.type, arg.name) |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 710 | else: |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame] | 711 | print ' __writer.writeBlob((const void *)%s, __size);' % (arg.name) |
| 712 | print ' __writer.endArg();' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 713 | |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame] | 714 | print ' __writer.endEnter();' |
| 715 | print ' __writer.beginLeave(__call);' |
| 716 | print ' __writer.endLeave();' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 717 | print ' }' |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 718 | print ' }' |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 719 | self.array_epilog(api, uppercase_name) |
| 720 | self.array_trace_epilog(api, uppercase_name) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 721 | print |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 722 | |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 723 | # Samething, but for glVertexAttribPointer* |
| 724 | # |
| 725 | # Some variants of glVertexAttribPointer alias conventional and generic attributes: |
| 726 | # - glVertexAttribPointer: no |
| 727 | # - glVertexAttribPointerARB: implementation dependent |
| 728 | # - glVertexAttribPointerNV: yes |
| 729 | # |
| 730 | # This means that the implementations of these functions do not always |
| 731 | # alias, and they need to be considered independently. |
| 732 | # |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 733 | print ' vertex_attrib __vertex_attrib = __get_vertex_attrib();' |
| 734 | print |
| 735 | for suffix in ['', 'ARB', 'NV']: |
| 736 | if suffix: |
José Fonseca | d94aaac | 2011-06-28 20:50:49 +0100 | [diff] [blame] | 737 | SUFFIX = '_' + suffix |
José Fonseca | d94aaac | 2011-06-28 20:50:49 +0100 | [diff] [blame] | 738 | else: |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 739 | SUFFIX = suffix |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 740 | function_name = 'glVertexAttribPointer' + suffix |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 741 | print ' // %s' % function_name |
| 742 | print ' if (__vertex_attrib == VERTEX_ATTRIB%s) {' % SUFFIX |
| 743 | if suffix == 'NV': |
| 744 | print ' GLint __max_vertex_attribs = 16;' |
| 745 | else: |
| 746 | print ' GLint __max_vertex_attribs = 0;' |
| 747 | print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &__max_vertex_attribs);' |
| 748 | print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' |
| 749 | print ' GLint __enabled = 0;' |
| 750 | if suffix == 'NV': |
| 751 | print ' __glGetIntegerv(GL_VERTEX_ATTRIB_ARRAY0_NV + index, &__enabled);' |
| 752 | else: |
| 753 | print ' __glGetVertexAttribiv%s(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED%s, &__enabled);' % (suffix, SUFFIX) |
| 754 | print ' if (__enabled) {' |
| 755 | print ' GLint __binding = 0;' |
| 756 | if suffix != 'NV': |
| 757 | # It doesn't seem possible to use VBOs with NV_vertex_program. |
| 758 | print ' __glGetVertexAttribiv%s(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING%s, &__binding);' % (suffix, SUFFIX) |
| 759 | print ' if (!__binding) {' |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 760 | |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 761 | function = api.get_function_by_name(function_name) |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 762 | |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 763 | # Get the arguments via glGet* |
| 764 | for arg in function.args[1:]: |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 765 | if suffix == 'NV': |
| 766 | arg_get_enum = 'GL_ATTRIB_ARRAY_%s%s' % (arg.name.upper(), SUFFIX) |
| 767 | else: |
| 768 | arg_get_enum = 'GL_VERTEX_ATTRIB_ARRAY_%s%s' % (arg.name.upper(), SUFFIX) |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 769 | arg_get_function, arg_type = TypeGetter('glGetVertexAttrib', False, suffix).visit(arg.type) |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 770 | print ' %s %s = 0;' % (arg_type, arg.name) |
| 771 | print ' __%s(index, %s, &%s);' % (arg_get_function, arg_get_enum, arg.name) |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 772 | |
| 773 | arg_names = ', '.join([arg.name for arg in function.args[1:-1]]) |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 774 | print ' size_t __size = __%s_size(%s, maxindex);' % (function.name, arg_names) |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 775 | |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 776 | # Emit a fake function |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 777 | print ' unsigned __call = __writer.beginEnter(&__%s_sig);' % (function.name,) |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 778 | for arg in function.args: |
| 779 | assert not arg.output |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 780 | print ' __writer.beginArg(%u);' % (arg.index,) |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 781 | if arg.name != 'pointer': |
| 782 | dump_instance(arg.type, arg.name) |
| 783 | else: |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 784 | print ' __writer.writeBlob((const void *)%s, __size);' % (arg.name) |
| 785 | print ' __writer.endArg();' |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 786 | |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 787 | print ' __writer.endEnter();' |
| 788 | print ' __writer.beginLeave(__call);' |
| 789 | print ' __writer.endLeave();' |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 790 | print ' }' |
| 791 | print ' }' |
| 792 | print ' }' |
| 793 | print ' }' |
| 794 | print |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 795 | |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 796 | print '}' |
| 797 | print |
| 798 | |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 799 | # |
| 800 | # Hooks for glTexCoordPointer, which is identical to the other array |
| 801 | # pointers except the fact that it is indexed by glClientActiveTexture. |
| 802 | # |
| 803 | |
| 804 | def array_prolog(self, api, uppercase_name): |
| 805 | if uppercase_name == 'TEXTURE_COORD': |
| 806 | print ' GLint client_active_texture = 0;' |
| 807 | print ' __glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE, &client_active_texture);' |
| 808 | print ' GLint max_texture_coords = 0;' |
| 809 | print ' __glGetIntegerv(GL_MAX_TEXTURE_COORDS, &max_texture_coords);' |
| 810 | print ' for (GLint unit = 0; unit < max_texture_coords; ++unit) {' |
| 811 | print ' GLenum texture = GL_TEXTURE0 + unit;' |
| 812 | print ' __glClientActiveTexture(texture);' |
| 813 | |
| 814 | def array_trace_prolog(self, api, uppercase_name): |
| 815 | if uppercase_name == 'TEXTURE_COORD': |
| 816 | print ' bool client_active_texture_dirty = false;' |
| 817 | |
| 818 | def array_epilog(self, api, uppercase_name): |
| 819 | if uppercase_name == 'TEXTURE_COORD': |
| 820 | print ' }' |
| 821 | self.array_cleanup(api, uppercase_name) |
| 822 | |
| 823 | def array_cleanup(self, api, uppercase_name): |
| 824 | if uppercase_name == 'TEXTURE_COORD': |
| 825 | print ' __glClientActiveTexture(client_active_texture);' |
| 826 | |
| 827 | def array_trace_intermezzo(self, api, uppercase_name): |
| 828 | if uppercase_name == 'TEXTURE_COORD': |
| 829 | print ' if (texture != client_active_texture || client_active_texture_dirty) {' |
| 830 | print ' client_active_texture_dirty = true;' |
| 831 | self.fake_glClientActiveTexture_call(api, "texture"); |
| 832 | print ' }' |
| 833 | |
| 834 | def array_trace_epilog(self, api, uppercase_name): |
| 835 | if uppercase_name == 'TEXTURE_COORD': |
| 836 | print ' if (client_active_texture_dirty) {' |
| 837 | self.fake_glClientActiveTexture_call(api, "client_active_texture"); |
| 838 | print ' }' |
| 839 | |
| 840 | def fake_glClientActiveTexture_call(self, api, texture): |
| 841 | function = api.get_function_by_name('glClientActiveTexture') |
| 842 | self.fake_call(function, [texture]) |
| 843 | |
| 844 | def fake_call(self, function, args): |
José Fonseca | 466753b | 2011-05-28 13:25:55 +0100 | [diff] [blame] | 845 | print ' unsigned __fake_call = __writer.beginEnter(&__%s_sig);' % (function.name,) |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 846 | for arg, instance in zip(function.args, args): |
| 847 | assert not arg.output |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame] | 848 | print ' __writer.beginArg(%u);' % (arg.index,) |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 849 | dump_instance(arg.type, instance) |
José Fonseca | eced747 | 2011-05-28 10:37:12 +0100 | [diff] [blame] | 850 | print ' __writer.endArg();' |
| 851 | print ' __writer.endEnter();' |
| 852 | print ' __writer.beginLeave(__fake_call);' |
| 853 | print ' __writer.endLeave();' |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 854 | |
| 855 | |
| 856 | |
| 857 | |
| 858 | |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 859 | |
| 860 | |
| 861 | |
| 862 | |
| 863 | |
| 864 | |