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 | 452d325 | 2012-04-14 15:55:40 +0100 | [diff] [blame] | 30 | from trace import Tracer |
José Fonseca | 1b6c875 | 2012-04-15 14:33:00 +0100 | [diff] [blame^] | 31 | from dispatch import function_pointer_type, function_pointer_value |
José Fonseca | bd86a22 | 2011-09-27 09:21:38 +0100 | [diff] [blame] | 32 | import specs.stdapi as stdapi |
| 33 | import specs.glapi as glapi |
| 34 | import specs.glparams as glparams |
| 35 | from specs.glxapi import glxapi |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 36 | |
| 37 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 38 | class TypeGetter(stdapi.Visitor): |
| 39 | '''Determine which glGet*v function that matches the specified type.''' |
| 40 | |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 41 | def __init__(self, prefix = 'glGet', long_suffix = True, ext_suffix = ''): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 42 | self.prefix = prefix |
| 43 | self.long_suffix = long_suffix |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 44 | self.ext_suffix = ext_suffix |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 45 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 46 | def visitConst(self, const): |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 47 | return self.visit(const.type) |
| 48 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 49 | def visitAlias(self, alias): |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 50 | if alias.expr == 'GLboolean': |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 51 | if self.long_suffix: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 52 | suffix = 'Booleanv' |
| 53 | arg_type = alias.expr |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 54 | else: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 55 | suffix = 'iv' |
| 56 | arg_type = 'GLint' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 57 | elif alias.expr == 'GLdouble': |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 58 | if self.long_suffix: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 59 | suffix = 'Doublev' |
| 60 | arg_type = alias.expr |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 61 | else: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 62 | suffix = 'dv' |
| 63 | arg_type = alias.expr |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 64 | elif alias.expr == 'GLfloat': |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 65 | if self.long_suffix: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 66 | suffix = 'Floatv' |
| 67 | arg_type = alias.expr |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 68 | else: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 69 | suffix = 'fv' |
| 70 | arg_type = alias.expr |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 71 | elif alias.expr in ('GLint', 'GLuint', 'GLsizei'): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 72 | if self.long_suffix: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 73 | suffix = 'Integerv' |
| 74 | arg_type = 'GLint' |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 75 | else: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 76 | suffix = 'iv' |
| 77 | arg_type = 'GLint' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 78 | else: |
| 79 | print alias.expr |
| 80 | assert False |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 81 | function_name = self.prefix + suffix + self.ext_suffix |
| 82 | return function_name, arg_type |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 83 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 84 | def visitEnum(self, enum): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 85 | return self.visit(glapi.GLint) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 86 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 87 | def visitBitmask(self, bitmask): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 88 | return self.visit(glapi.GLint) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 89 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 90 | def visitOpaque(self, pointer): |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 91 | return self.prefix + 'Pointerv' + self.ext_suffix, 'GLvoid *' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 92 | |
| 93 | |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 94 | class GlTracer(Tracer): |
| 95 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 96 | arrays = [ |
| 97 | ("Vertex", "VERTEX"), |
| 98 | ("Normal", "NORMAL"), |
| 99 | ("Color", "COLOR"), |
| 100 | ("Index", "INDEX"), |
| 101 | ("TexCoord", "TEXTURE_COORD"), |
| 102 | ("EdgeFlag", "EDGE_FLAG"), |
| 103 | ("FogCoord", "FOG_COORD"), |
| 104 | ("SecondaryColor", "SECONDARY_COLOR"), |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 105 | ] |
José Fonseca | c9f1223 | 2011-03-25 20:07:42 +0000 | [diff] [blame] | 106 | arrays.reverse() |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 107 | |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 108 | # arrays available in PROFILE_ES1 |
| 109 | arrays_es1 = ("Vertex", "Normal", "Color", "TexCoord") |
| 110 | |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 111 | def header(self, api): |
| 112 | Tracer.header(self, api) |
| 113 | |
José Fonseca | 1b3d375 | 2011-07-15 10:15:19 +0100 | [diff] [blame] | 114 | print '#include "gltrace.hpp"' |
| 115 | print |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 116 | |
| 117 | # Which glVertexAttrib* variant to use |
| 118 | print 'enum vertex_attrib {' |
| 119 | print ' VERTEX_ATTRIB,' |
| 120 | print ' VERTEX_ATTRIB_ARB,' |
| 121 | print ' VERTEX_ATTRIB_NV,' |
| 122 | print '};' |
| 123 | print |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 124 | print 'gltrace::Context *' |
| 125 | print 'gltrace::getContext(void)' |
Chia-I Wu | 8ef6697 | 2011-11-03 01:19:46 +0800 | [diff] [blame] | 126 | print '{' |
| 127 | print ' // TODO return the context set by other APIs (GLX, EGL, and etc.)' |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 128 | print ' static gltrace::Context __ctx = { gltrace::PROFILE_COMPAT, false, false, false };' |
Chia-I Wu | 8ef6697 | 2011-11-03 01:19:46 +0800 | [diff] [blame] | 129 | print ' return &__ctx;' |
| 130 | print '}' |
| 131 | print |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 132 | print 'static vertex_attrib __get_vertex_attrib(void) {' |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 133 | print ' gltrace::Context *ctx = gltrace::getContext();' |
Chia-I Wu | 8ef6697 | 2011-11-03 01:19:46 +0800 | [diff] [blame] | 134 | print ' if (ctx->user_arrays_arb || ctx->user_arrays_nv) {' |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 135 | print ' GLboolean __vertex_program = GL_FALSE;' |
| 136 | print ' __glGetBooleanv(GL_VERTEX_PROGRAM_ARB, &__vertex_program);' |
| 137 | print ' if (__vertex_program) {' |
Chia-I Wu | 8ef6697 | 2011-11-03 01:19:46 +0800 | [diff] [blame] | 138 | print ' if (ctx->user_arrays_nv) {' |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 139 | print ' GLint __vertex_program_binding_nv = 0;' |
| 140 | print ' __glGetIntegerv(GL_VERTEX_PROGRAM_BINDING_NV, &__vertex_program_binding_nv);' |
| 141 | print ' if (__vertex_program_binding_nv) {' |
| 142 | print ' return VERTEX_ATTRIB_NV;' |
| 143 | print ' }' |
| 144 | print ' }' |
| 145 | print ' return VERTEX_ATTRIB_ARB;' |
| 146 | print ' }' |
| 147 | print ' }' |
| 148 | print ' return VERTEX_ATTRIB;' |
| 149 | print '}' |
| 150 | print |
| 151 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 152 | # Whether we need user arrays |
| 153 | print 'static inline bool __need_user_arrays(void)' |
| 154 | print '{' |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 155 | print ' gltrace::Context *ctx = gltrace::getContext();' |
Chia-I Wu | 8ef6697 | 2011-11-03 01:19:46 +0800 | [diff] [blame] | 156 | print ' if (!ctx->user_arrays) {' |
José Fonseca | 25ebe54 | 2011-04-24 10:08:22 +0100 | [diff] [blame] | 157 | print ' return false;' |
| 158 | print ' }' |
| 159 | print |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 160 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 161 | for camelcase_name, uppercase_name in self.arrays: |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 162 | # in which profile is the array available? |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 163 | profile_check = 'ctx->profile == gltrace::PROFILE_COMPAT' |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 164 | if camelcase_name in self.arrays_es1: |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 165 | profile_check = '(' + profile_check + ' || ctx->profile == gltrace::PROFILE_ES1)'; |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 166 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 167 | function_name = 'gl%sPointer' % camelcase_name |
| 168 | enable_name = 'GL_%s_ARRAY' % uppercase_name |
| 169 | binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name |
| 170 | print ' // %s' % function_name |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 171 | print ' if (%s) {' % profile_check |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 172 | self.array_prolog(api, uppercase_name) |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 173 | print ' if (__glIsEnabled(%s)) {' % enable_name |
| 174 | print ' GLint __binding = 0;' |
| 175 | print ' __glGetIntegerv(%s, &__binding);' % binding_name |
| 176 | print ' if (!__binding) {' |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 177 | self.array_cleanup(api, uppercase_name) |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 178 | print ' return true;' |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 179 | print ' }' |
| 180 | print ' }' |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 181 | self.array_epilog(api, uppercase_name) |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 182 | print ' }' |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 183 | print |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 184 | |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 185 | print ' // ES1 does not support generic vertex attributes' |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 186 | print ' if (ctx->profile == gltrace::PROFILE_ES1)' |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 187 | print ' return false;' |
| 188 | print |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 189 | print ' vertex_attrib __vertex_attrib = __get_vertex_attrib();' |
| 190 | print |
| 191 | print ' // glVertexAttribPointer' |
| 192 | print ' if (__vertex_attrib == VERTEX_ATTRIB) {' |
| 193 | print ' GLint __max_vertex_attribs = 0;' |
| 194 | print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &__max_vertex_attribs);' |
| 195 | print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' |
| 196 | print ' GLint __enabled = 0;' |
| 197 | print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &__enabled);' |
| 198 | print ' if (__enabled) {' |
| 199 | print ' GLint __binding = 0;' |
| 200 | print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &__binding);' |
| 201 | print ' if (!__binding) {' |
| 202 | print ' return true;' |
| 203 | print ' }' |
| 204 | print ' }' |
| 205 | print ' }' |
| 206 | print ' }' |
| 207 | print |
| 208 | print ' // glVertexAttribPointerARB' |
| 209 | print ' if (__vertex_attrib == VERTEX_ATTRIB_ARB) {' |
José Fonseca | d94aaac | 2011-06-28 20:50:49 +0100 | [diff] [blame] | 210 | print ' GLint __max_vertex_attribs = 0;' |
| 211 | print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &__max_vertex_attribs);' |
| 212 | print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' |
| 213 | print ' GLint __enabled = 0;' |
| 214 | print ' __glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB, &__enabled);' |
| 215 | print ' if (__enabled) {' |
| 216 | print ' GLint __binding = 0;' |
| 217 | print ' __glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB, &__binding);' |
| 218 | print ' if (!__binding) {' |
| 219 | print ' return true;' |
| 220 | print ' }' |
| 221 | print ' }' |
| 222 | print ' }' |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 223 | print ' }' |
| 224 | print |
| 225 | print ' // glVertexAttribPointerNV' |
| 226 | print ' if (__vertex_attrib == VERTEX_ATTRIB_NV) {' |
| 227 | print ' for (GLint index = 0; index < 16; ++index) {' |
José Fonseca | d94aaac | 2011-06-28 20:50:49 +0100 | [diff] [blame] | 228 | print ' GLint __enabled = 0;' |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 229 | print ' __glGetIntegerv(GL_VERTEX_ATTRIB_ARRAY0_NV + index, &__enabled);' |
José Fonseca | d94aaac | 2011-06-28 20:50:49 +0100 | [diff] [blame] | 230 | print ' if (__enabled) {' |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 231 | print ' return true;' |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 232 | print ' }' |
| 233 | print ' }' |
| 234 | print ' }' |
| 235 | print |
| 236 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 237 | print ' return false;' |
| 238 | print '}' |
| 239 | print |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 240 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 241 | print 'static void __trace_user_arrays(GLuint maxindex);' |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 242 | print |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 243 | |
José Fonseca | 9c536b0 | 2012-02-29 20:54:13 +0000 | [diff] [blame] | 244 | # Buffer mappings |
| 245 | print '// whether glMapBufferRange(GL_MAP_WRITE_BIT) has ever been called' |
| 246 | print 'static bool __checkBufferMapRange = false;' |
| 247 | print |
| 248 | print '// whether glBufferParameteriAPPLE(GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE) has ever been called' |
| 249 | print 'static bool __checkBufferFlushingUnmapAPPLE = false;' |
| 250 | print |
| 251 | # Buffer mapping information, necessary for old Mesa 2.1 drivers which |
| 252 | # do not support glGetBufferParameteriv(GL_BUFFER_ACCESS_FLAGS/GL_BUFFER_MAP_LENGTH) |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 253 | print 'struct buffer_mapping {' |
| 254 | print ' void *map;' |
| 255 | print ' GLint length;' |
| 256 | print ' bool write;' |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 257 | print ' bool explicit_flush;' |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 258 | print '};' |
| 259 | print |
| 260 | for target in self.buffer_targets: |
| 261 | print 'struct buffer_mapping __%s_mapping;' % target.lower(); |
| 262 | print |
| 263 | print 'static inline struct buffer_mapping *' |
| 264 | print 'get_buffer_mapping(GLenum target) {' |
José Fonseca | 06e8519 | 2011-10-16 14:15:36 +0100 | [diff] [blame] | 265 | print ' switch (target) {' |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 266 | for target in self.buffer_targets: |
| 267 | print ' case GL_%s:' % target |
| 268 | print ' return & __%s_mapping;' % target.lower() |
| 269 | print ' default:' |
José Fonseca | 559d534 | 2011-10-27 08:10:56 +0100 | [diff] [blame] | 270 | print ' os::log("apitrace: warning: unknown buffer target 0x%04X\\n", target);' |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 271 | print ' return NULL;' |
| 272 | print ' }' |
| 273 | print '}' |
| 274 | print |
| 275 | |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 276 | # Generate a helper function to determine whether a parameter name |
| 277 | # refers to a symbolic value or not |
| 278 | print 'static bool' |
| 279 | print 'is_symbolic_pname(GLenum pname) {' |
José Fonseca | 06e8519 | 2011-10-16 14:15:36 +0100 | [diff] [blame] | 280 | print ' switch (pname) {' |
José Fonseca | 5ea9187 | 2011-05-04 09:41:55 +0100 | [diff] [blame] | 281 | for function, type, count, name in glparams.parameters: |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 282 | if type is glapi.GLenum: |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 283 | print ' case %s:' % name |
| 284 | print ' return true;' |
| 285 | print ' default:' |
| 286 | print ' return false;' |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 287 | print ' }' |
| 288 | print '}' |
| 289 | print |
| 290 | |
| 291 | # Generate a helper function to determine whether a parameter value is |
| 292 | # potentially symbolic or not; i.e., if the value can be represented in |
| 293 | # an enum or not |
| 294 | print 'template<class T>' |
| 295 | print 'static inline bool' |
| 296 | print 'is_symbolic_param(T param) {' |
| 297 | print ' return static_cast<T>(static_cast<GLenum>(param)) == param;' |
| 298 | print '}' |
| 299 | print |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 300 | |
| 301 | # Generate a helper function to know how many elements a parameter has |
| 302 | print 'static size_t' |
José Fonseca | f4aca5d | 2011-05-08 08:29:30 +0100 | [diff] [blame] | 303 | print '__gl_param_size(GLenum pname) {' |
José Fonseca | 06e8519 | 2011-10-16 14:15:36 +0100 | [diff] [blame] | 304 | print ' switch (pname) {' |
José Fonseca | 5ea9187 | 2011-05-04 09:41:55 +0100 | [diff] [blame] | 305 | for function, type, count, name in glparams.parameters: |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 306 | if type is not None: |
| 307 | print ' case %s: return %u;' % (name, count) |
| 308 | print ' case GL_COMPRESSED_TEXTURE_FORMATS: {' |
| 309 | print ' GLint num_compressed_texture_formats = 0;' |
| 310 | print ' __glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &num_compressed_texture_formats);' |
| 311 | print ' return num_compressed_texture_formats;' |
| 312 | print ' }' |
| 313 | print ' default:' |
José Fonseca | 559d534 | 2011-10-27 08:10:56 +0100 | [diff] [blame] | 314 | print r' os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);' |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 315 | print ' return 1;' |
| 316 | print ' }' |
| 317 | print '}' |
| 318 | print |
| 319 | |
Chia-I Wu | 335efb4 | 2011-11-03 01:59:22 +0800 | [diff] [blame] | 320 | # states such as GL_UNPACK_ROW_LENGTH are not available in GLES |
| 321 | print 'static inline bool' |
| 322 | print 'can_unpack_subimage(void) {' |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 323 | print ' gltrace::Context *ctx = gltrace::getContext();' |
| 324 | print ' return (ctx->profile == gltrace::PROFILE_COMPAT);' |
Chia-I Wu | 335efb4 | 2011-11-03 01:59:22 +0800 | [diff] [blame] | 325 | print '}' |
| 326 | print |
| 327 | |
José Fonseca | 1b6c875 | 2012-04-15 14:33:00 +0100 | [diff] [blame^] | 328 | getProcAddressFunctionNames = [] |
| 329 | |
| 330 | def traceApi(self, api): |
| 331 | if self.getProcAddressFunctionNames: |
| 332 | # Generate a function to wrap proc addresses |
| 333 | getProcAddressFunction = api.getFunctionByName(self.getProcAddressFunctionNames[0]) |
| 334 | argType = getProcAddressFunction.args[0].type |
| 335 | retType = getProcAddressFunction.type |
| 336 | |
| 337 | print 'static %s _wrapProcAddress(%s procName, %s procPtr);' % (retType, argType, retType) |
| 338 | print |
| 339 | |
| 340 | Tracer.traceApi(self, api) |
| 341 | |
| 342 | print 'static %s _wrapProcAddress(%s procName, %s procPtr) {' % (retType, argType, retType) |
| 343 | print ' if (!procPtr) {' |
| 344 | print ' return procPtr;' |
| 345 | print ' }' |
| 346 | for function in api.functions: |
| 347 | ptype = function_pointer_type(function) |
| 348 | pvalue = function_pointer_value(function) |
| 349 | print ' if (strcmp("%s", (const char *)procName) == 0) {' % function.name |
| 350 | print ' %s = (%s)procPtr;' % (pvalue, ptype) |
| 351 | print ' return (%s)&%s;' % (retType, function.name,) |
| 352 | print ' }' |
| 353 | print ' os::log("apitrace: warning: unknown function \\"%s\\"\\n", (const char *)procName);' |
| 354 | print ' return procPtr;' |
| 355 | print '}' |
| 356 | print |
| 357 | else: |
| 358 | Tracer.traceApi(self, api) |
| 359 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 360 | array_pointer_function_names = set(( |
| 361 | "glVertexPointer", |
| 362 | "glNormalPointer", |
| 363 | "glColorPointer", |
| 364 | "glIndexPointer", |
| 365 | "glTexCoordPointer", |
| 366 | "glEdgeFlagPointer", |
| 367 | "glFogCoordPointer", |
| 368 | "glSecondaryColorPointer", |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 369 | |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 370 | "glInterleavedArrays", |
| 371 | |
José Fonseca | 7e0bfd9 | 2011-04-30 23:09:03 +0100 | [diff] [blame] | 372 | "glVertexPointerEXT", |
| 373 | "glNormalPointerEXT", |
| 374 | "glColorPointerEXT", |
| 375 | "glIndexPointerEXT", |
| 376 | "glTexCoordPointerEXT", |
| 377 | "glEdgeFlagPointerEXT", |
| 378 | "glFogCoordPointerEXT", |
| 379 | "glSecondaryColorPointerEXT", |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 380 | |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 381 | "glVertexAttribPointer", |
| 382 | "glVertexAttribPointerARB", |
| 383 | "glVertexAttribPointerNV", |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 384 | "glVertexAttribIPointer", |
| 385 | "glVertexAttribIPointerEXT", |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 386 | "glVertexAttribLPointer", |
| 387 | "glVertexAttribLPointerEXT", |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 388 | |
| 389 | #"glMatrixIndexPointerARB", |
| 390 | )) |
| 391 | |
| 392 | draw_function_names = set(( |
| 393 | 'glDrawArrays', |
| 394 | 'glDrawElements', |
| 395 | 'glDrawRangeElements', |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 396 | 'glMultiDrawArrays', |
| 397 | 'glMultiDrawElements', |
| 398 | 'glDrawArraysInstanced', |
José Fonseca | ff8848b | 2011-10-09 01:04:17 +0100 | [diff] [blame] | 399 | "glDrawArraysInstancedBaseInstance", |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 400 | 'glDrawElementsInstanced', |
| 401 | 'glDrawArraysInstancedARB', |
| 402 | 'glDrawElementsInstancedARB', |
| 403 | 'glDrawElementsBaseVertex', |
| 404 | 'glDrawRangeElementsBaseVertex', |
| 405 | 'glDrawElementsInstancedBaseVertex', |
José Fonseca | ff8848b | 2011-10-09 01:04:17 +0100 | [diff] [blame] | 406 | "glDrawElementsInstancedBaseInstance", |
| 407 | "glDrawElementsInstancedBaseVertexBaseInstance", |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 408 | 'glMultiDrawElementsBaseVertex', |
| 409 | 'glDrawArraysIndirect', |
| 410 | 'glDrawElementsIndirect', |
| 411 | 'glDrawArraysEXT', |
José Fonseca | 7e0bfd9 | 2011-04-30 23:09:03 +0100 | [diff] [blame] | 412 | 'glDrawRangeElementsEXT', |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 413 | 'glDrawRangeElementsEXT_size', |
| 414 | 'glMultiDrawArraysEXT', |
| 415 | 'glMultiDrawElementsEXT', |
| 416 | 'glMultiModeDrawArraysIBM', |
| 417 | 'glMultiModeDrawElementsIBM', |
| 418 | 'glDrawArraysInstancedEXT', |
| 419 | 'glDrawElementsInstancedEXT', |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 420 | )) |
| 421 | |
José Fonseca | c9f1223 | 2011-03-25 20:07:42 +0000 | [diff] [blame] | 422 | interleaved_formats = [ |
| 423 | 'GL_V2F', |
| 424 | 'GL_V3F', |
| 425 | 'GL_C4UB_V2F', |
| 426 | 'GL_C4UB_V3F', |
| 427 | 'GL_C3F_V3F', |
| 428 | 'GL_N3F_V3F', |
| 429 | 'GL_C4F_N3F_V3F', |
| 430 | 'GL_T2F_V3F', |
| 431 | 'GL_T4F_V4F', |
| 432 | 'GL_T2F_C4UB_V3F', |
| 433 | 'GL_T2F_C3F_V3F', |
| 434 | 'GL_T2F_N3F_V3F', |
| 435 | 'GL_T2F_C4F_N3F_V3F', |
| 436 | 'GL_T4F_C4F_N3F_V4F', |
| 437 | ] |
| 438 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 439 | def traceFunctionImplBody(self, function): |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 440 | # Defer tracing of user array pointers... |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 441 | if function.name in self.array_pointer_function_names: |
| 442 | print ' GLint __array_buffer = 0;' |
| 443 | print ' __glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);' |
| 444 | print ' if (!__array_buffer) {' |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 445 | print ' gltrace::Context *ctx = gltrace::getContext();' |
Chia-I Wu | 8ef6697 | 2011-11-03 01:19:46 +0800 | [diff] [blame] | 446 | print ' ctx->user_arrays = true;' |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 447 | if function.name == "glVertexAttribPointerARB": |
Chia-I Wu | 8ef6697 | 2011-11-03 01:19:46 +0800 | [diff] [blame] | 448 | print ' ctx->user_arrays_arb = true;' |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 449 | if function.name == "glVertexAttribPointerNV": |
Chia-I Wu | 8ef6697 | 2011-11-03 01:19:46 +0800 | [diff] [blame] | 450 | print ' ctx->user_arrays_nv = true;' |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 451 | self.invokeFunction(function) |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 452 | |
| 453 | # And also break down glInterleavedArrays into the individual calls |
| 454 | if function.name == 'glInterleavedArrays': |
| 455 | print |
| 456 | |
| 457 | # Initialize the enable flags |
| 458 | for camelcase_name, uppercase_name in self.arrays: |
| 459 | flag_name = '__' + uppercase_name.lower() |
| 460 | print ' GLboolean %s = GL_FALSE;' % flag_name |
| 461 | print |
| 462 | |
| 463 | # Switch for the interleaved formats |
| 464 | print ' switch (format) {' |
| 465 | for format in self.interleaved_formats: |
| 466 | print ' case %s:' % format |
| 467 | for camelcase_name, uppercase_name in self.arrays: |
| 468 | flag_name = '__' + uppercase_name.lower() |
| 469 | if format.find('_' + uppercase_name[0]) >= 0: |
| 470 | print ' %s = GL_TRUE;' % flag_name |
| 471 | print ' break;' |
| 472 | print ' default:' |
| 473 | print ' return;' |
| 474 | print ' }' |
| 475 | print |
| 476 | |
| 477 | # Emit fake glEnableClientState/glDisableClientState flags |
| 478 | for camelcase_name, uppercase_name in self.arrays: |
| 479 | flag_name = '__' + uppercase_name.lower() |
| 480 | enable_name = 'GL_%s_ARRAY' % uppercase_name |
| 481 | |
| 482 | # Emit a fake function |
| 483 | print ' {' |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 484 | print ' static const trace::FunctionSig &__sig = %s ? __glEnableClientState_sig : __glDisableClientState_sig;' % flag_name |
| 485 | print ' unsigned __call = trace::localWriter.beginEnter(&__sig);' |
| 486 | print ' trace::localWriter.beginArg(0);' |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 487 | self.serializeValue(glapi.GLenum, enable_name) |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 488 | print ' trace::localWriter.endArg();' |
| 489 | print ' trace::localWriter.endEnter();' |
| 490 | print ' trace::localWriter.beginLeave(__call);' |
| 491 | print ' trace::localWriter.endLeave();' |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 492 | print ' }' |
| 493 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 494 | print ' return;' |
| 495 | print ' }' |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 496 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 497 | # ... to the draw calls |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 498 | if function.name in self.draw_function_names: |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 499 | print ' if (__need_user_arrays()) {' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 500 | arg_names = ', '.join([arg.name for arg in function.args[1:]]) |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 501 | print ' GLuint maxindex = __%s_maxindex(%s);' % (function.name, arg_names) |
| 502 | print ' __trace_user_arrays(maxindex);' |
| 503 | print ' }' |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 504 | |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 505 | # Emit a fake memcpy on buffer uploads |
José Fonseca | 9c536b0 | 2012-02-29 20:54:13 +0000 | [diff] [blame] | 506 | if function.name == 'glBufferParameteriAPPLE': |
| 507 | print ' if (pname == GL_BUFFER_FLUSHING_UNMAP_APPLE && param == GL_FALSE) {' |
| 508 | print ' __checkBufferFlushingUnmapAPPLE = true;' |
| 509 | print ' }' |
José Fonseca | cdc322c | 2012-02-29 19:29:51 +0000 | [diff] [blame] | 510 | if function.name in ('glUnmapBuffer', 'glUnmapBufferARB'): |
José Fonseca | 9c536b0 | 2012-02-29 20:54:13 +0000 | [diff] [blame] | 511 | if function.name.endswith('ARB'): |
| 512 | suffix = 'ARB' |
| 513 | else: |
| 514 | suffix = '' |
| 515 | print ' GLint access = 0;' |
| 516 | print ' __glGetBufferParameteriv%s(target, GL_BUFFER_ACCESS, &access);' % suffix |
| 517 | print ' if (access != GL_READ_ONLY) {' |
| 518 | print ' GLvoid *map = NULL;' |
| 519 | print ' __glGetBufferPointerv%s(target, GL_BUFFER_MAP_POINTER, &map);' % suffix |
| 520 | print ' if (map) {' |
| 521 | print ' GLint length = -1;' |
| 522 | print ' bool flush = true;' |
| 523 | print ' if (__checkBufferMapRange) {' |
| 524 | print ' __glGetBufferParameteriv%s(target, GL_BUFFER_MAP_LENGTH, &length);' % suffix |
| 525 | print ' GLint access_flags = 0;' |
| 526 | print ' __glGetBufferParameteriv(target, GL_BUFFER_ACCESS_FLAGS, &access_flags);' |
| 527 | print ' flush = flush && !(access_flags & GL_MAP_FLUSH_EXPLICIT_BIT);' |
| 528 | print ' if (length == -1) {' |
| 529 | print ' // Mesa drivers refuse GL_BUFFER_MAP_LENGTH without GL 3.0' |
José Fonseca | db1ccce | 2012-02-29 21:09:24 +0000 | [diff] [blame] | 530 | print ' static bool warned = false;' |
| 531 | print ' if (!warned) {' |
| 532 | print ' os::log("apitrace: warning: glGetBufferParameteriv%s(GL_BUFFER_MAP_LENGTH) failed\\n");' % suffix |
| 533 | print ' warned = true;' |
| 534 | print ' }' |
José Fonseca | 9c536b0 | 2012-02-29 20:54:13 +0000 | [diff] [blame] | 535 | print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' |
| 536 | print ' if (mapping) {' |
| 537 | print ' length = mapping->length;' |
| 538 | print ' flush = flush && !mapping->explicit_flush;' |
| 539 | print ' } else {' |
| 540 | print ' length = 0;' |
| 541 | print ' flush = false;' |
| 542 | print ' }' |
| 543 | print ' }' |
| 544 | print ' } else {' |
| 545 | print ' length = 0;' |
| 546 | print ' __glGetBufferParameteriv%s(target, GL_BUFFER_SIZE, &length);' % suffix |
| 547 | print ' }' |
| 548 | print ' if (__checkBufferFlushingUnmapAPPLE) {' |
| 549 | print ' GLint flushing_unmap = GL_TRUE;' |
| 550 | print ' __glGetBufferParameteriv%s(target, GL_BUFFER_FLUSHING_UNMAP_APPLE, &flushing_unmap);' % suffix |
| 551 | print ' flush = flush && flushing_unmap;' |
| 552 | print ' }' |
| 553 | print ' if (flush && length > 0) {' |
| 554 | self.emit_memcpy('map', 'map', 'length') |
| 555 | print ' }' |
| 556 | print ' }' |
| 557 | print ' }' |
José Fonseca | cdc322c | 2012-02-29 19:29:51 +0000 | [diff] [blame] | 558 | if function.name == 'glUnmapBufferOES': |
| 559 | print ' GLint access = 0;' |
| 560 | print ' __glGetBufferParameteriv(target, GL_BUFFER_ACCESS_OES, &access);' |
| 561 | print ' if (access == GL_WRITE_ONLY_OES) {' |
| 562 | print ' GLvoid *map = NULL;' |
| 563 | print ' __glGetBufferPointervOES(target, GL_BUFFER_MAP_POINTER_OES, &map);' |
| 564 | print ' GLint size = 0;' |
| 565 | print ' __glGetBufferParameteriv(target, GL_BUFFER_SIZE, &size);' |
| 566 | print ' if (map && size > 0) {' |
| 567 | self.emit_memcpy('map', 'map', 'size') |
| 568 | print ' }' |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 569 | print ' }' |
José Fonseca | fb3bd60 | 2012-01-15 13:56:28 +0000 | [diff] [blame] | 570 | if function.name == 'glUnmapNamedBufferEXT': |
José Fonseca | 024aff4 | 2012-02-29 18:00:06 +0000 | [diff] [blame] | 571 | print ' GLint access_flags = 0;' |
| 572 | print ' __glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_ACCESS_FLAGS, &access_flags);' |
| 573 | print ' if ((access_flags & GL_MAP_WRITE_BIT) && !(access_flags & GL_MAP_FLUSH_EXPLICIT_BIT)) {' |
José Fonseca | fb3bd60 | 2012-01-15 13:56:28 +0000 | [diff] [blame] | 574 | print ' GLvoid *map = NULL;' |
José Fonseca | 024aff4 | 2012-02-29 18:00:06 +0000 | [diff] [blame] | 575 | print ' __glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &map);' |
José Fonseca | fb3bd60 | 2012-01-15 13:56:28 +0000 | [diff] [blame] | 576 | print ' GLint length = 0;' |
José Fonseca | 024aff4 | 2012-02-29 18:00:06 +0000 | [diff] [blame] | 577 | print ' __glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_MAP_LENGTH, &length);' |
| 578 | print ' if (map && length > 0) {' |
José Fonseca | fb3bd60 | 2012-01-15 13:56:28 +0000 | [diff] [blame] | 579 | self.emit_memcpy('map', 'map', 'length') |
José Fonseca | 024aff4 | 2012-02-29 18:00:06 +0000 | [diff] [blame] | 580 | print ' }' |
José Fonseca | fb3bd60 | 2012-01-15 13:56:28 +0000 | [diff] [blame] | 581 | print ' }' |
José Fonseca | 77ef0ce | 2012-02-29 18:08:48 +0000 | [diff] [blame] | 582 | if function.name == 'glFlushMappedBufferRange': |
| 583 | print ' GLvoid *map = NULL;' |
| 584 | print ' __glGetBufferPointerv(target, GL_BUFFER_MAP_POINTER, &map);' |
| 585 | print ' if (map && length > 0) {' |
| 586 | self.emit_memcpy('(char *)map + offset', '(const char *)map + offset', 'length') |
| 587 | print ' }' |
| 588 | if function.name == 'glFlushMappedBufferRangeAPPLE': |
| 589 | print ' GLvoid *map = NULL;' |
| 590 | print ' __glGetBufferPointerv(target, GL_BUFFER_MAP_POINTER, &map);' |
| 591 | print ' if (map && size > 0) {' |
| 592 | self.emit_memcpy('(char *)map + offset', '(const char *)map + offset', 'size') |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 593 | print ' }' |
José Fonseca | fb3bd60 | 2012-01-15 13:56:28 +0000 | [diff] [blame] | 594 | if function.name == 'glFlushMappedNamedBufferRangeEXT': |
| 595 | print ' GLvoid *map = NULL;' |
José Fonseca | 024aff4 | 2012-02-29 18:00:06 +0000 | [diff] [blame] | 596 | print ' __glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &map);' |
| 597 | print ' if (map && length > 0) {' |
José Fonseca | fb3bd60 | 2012-01-15 13:56:28 +0000 | [diff] [blame] | 598 | self.emit_memcpy('(char *)map + offset', '(const char *)map + offset', 'length') |
| 599 | print ' }' |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 600 | |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 601 | # Don't leave vertex attrib locations to chance. Instead emit fake |
| 602 | # glBindAttribLocation calls to ensure that the same locations will be |
| 603 | # used when retracing. Trying to remap locations after the fact would |
| 604 | # be an herculian task given that vertex attrib locations appear in |
| 605 | # many entry-points, including non-shader related ones. |
| 606 | if function.name == 'glLinkProgram': |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 607 | Tracer.invokeFunction(self, function) |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 608 | print ' GLint active_attributes = 0;' |
| 609 | print ' __glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &active_attributes);' |
José Fonseca | 7525e6f | 2011-09-28 09:04:56 +0100 | [diff] [blame] | 610 | print ' for (GLint attrib = 0; attrib < active_attributes; ++attrib) {' |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 611 | print ' GLint size = 0;' |
| 612 | print ' GLenum type = 0;' |
| 613 | print ' GLchar name[256];' |
| 614 | # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256 |
| 615 | print ' __glGetActiveAttrib(program, attrib, sizeof name, NULL, &size, &type, name);' |
José Fonseca | 2a794f5 | 2011-05-26 20:54:29 +0100 | [diff] [blame] | 616 | print " if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {" |
| 617 | print ' GLint location = __glGetAttribLocation(program, name);' |
| 618 | print ' if (location >= 0) {' |
José Fonseca | 1b6c875 | 2012-04-15 14:33:00 +0100 | [diff] [blame^] | 619 | bind_function = glapi.glapi.getFunctionByName('glBindAttribLocation') |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 620 | self.fake_call(bind_function, ['program', 'location', 'name']) |
José Fonseca | 2a794f5 | 2011-05-26 20:54:29 +0100 | [diff] [blame] | 621 | print ' }' |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 622 | print ' }' |
| 623 | print ' }' |
| 624 | if function.name == 'glLinkProgramARB': |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 625 | Tracer.invokeFunction(self, function) |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 626 | print ' GLint active_attributes = 0;' |
| 627 | print ' __glGetObjectParameterivARB(programObj, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB, &active_attributes);' |
José Fonseca | 7525e6f | 2011-09-28 09:04:56 +0100 | [diff] [blame] | 628 | print ' for (GLint attrib = 0; attrib < active_attributes; ++attrib) {' |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 629 | print ' GLint size = 0;' |
| 630 | print ' GLenum type = 0;' |
| 631 | print ' GLcharARB name[256];' |
| 632 | # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256 |
| 633 | print ' __glGetActiveAttribARB(programObj, attrib, sizeof name, NULL, &size, &type, name);' |
José Fonseca | 2a794f5 | 2011-05-26 20:54:29 +0100 | [diff] [blame] | 634 | print " if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {" |
| 635 | print ' GLint location = __glGetAttribLocationARB(programObj, name);' |
| 636 | print ' if (location >= 0) {' |
José Fonseca | 1b6c875 | 2012-04-15 14:33:00 +0100 | [diff] [blame^] | 637 | bind_function = glapi.glapi.getFunctionByName('glBindAttribLocationARB') |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 638 | self.fake_call(bind_function, ['programObj', 'location', 'name']) |
José Fonseca | 2a794f5 | 2011-05-26 20:54:29 +0100 | [diff] [blame] | 639 | print ' }' |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 640 | print ' }' |
| 641 | print ' }' |
| 642 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 643 | Tracer.traceFunctionImplBody(self, function) |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 644 | |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 645 | marker_functions = [ |
| 646 | # GL_GREMEDY_string_marker |
José Fonseca | 8f34d34 | 2011-07-15 20:16:40 +0100 | [diff] [blame] | 647 | 'glStringMarkerGREMEDY', |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 648 | # GL_GREMEDY_frame_terminator |
José Fonseca | 8f34d34 | 2011-07-15 20:16:40 +0100 | [diff] [blame] | 649 | 'glFrameTerminatorGREMEDY', |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 650 | # GL_EXT_debug_marker |
| 651 | 'glInsertEventMarkerEXT', |
| 652 | 'glPushGroupMarkerEXT', |
| 653 | 'glPopGroupMarkerEXT', |
José Fonseca | 8f34d34 | 2011-07-15 20:16:40 +0100 | [diff] [blame] | 654 | ] |
| 655 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 656 | def invokeFunction(self, function): |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 657 | if function.name in ('glLinkProgram', 'glLinkProgramARB'): |
| 658 | # These functions have been dispatched already |
| 659 | return |
| 660 | |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 661 | # We implement GL_EXT_debug_marker, GL_GREMEDY_*, etc., and not the |
| 662 | # driver |
| 663 | if function.name in self.marker_functions: |
José Fonseca | 8f34d34 | 2011-07-15 20:16:40 +0100 | [diff] [blame] | 664 | return |
| 665 | |
| 666 | if function.name in ('glXGetProcAddress', 'glXGetProcAddressARB', 'wglGetProcAddress'): |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 667 | else_ = '' |
| 668 | for marker_function in self.marker_functions: |
José Fonseca | 1b6c875 | 2012-04-15 14:33:00 +0100 | [diff] [blame^] | 669 | if self.api.getFunctionByName(marker_function): |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 670 | print ' %sif (strcmp("%s", (const char *)%s) == 0) {' % (else_, marker_function, function.args[0].name) |
| 671 | print ' __result = (%s)&%s;' % (function.type, marker_function) |
| 672 | print ' }' |
| 673 | else_ = 'else ' |
| 674 | print ' %s{' % else_ |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 675 | Tracer.invokeFunction(self, function) |
José Fonseca | 8f34d34 | 2011-07-15 20:16:40 +0100 | [diff] [blame] | 676 | print ' }' |
José Fonseca | 1b3d375 | 2011-07-15 10:15:19 +0100 | [diff] [blame] | 677 | return |
| 678 | |
José Fonseca | a08d275 | 2011-08-25 13:26:43 +0100 | [diff] [blame] | 679 | # Override GL extensions |
| 680 | if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'): |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 681 | Tracer.invokeFunction(self, function, prefix = 'gltrace::__', suffix = '_override') |
José Fonseca | a08d275 | 2011-08-25 13:26:43 +0100 | [diff] [blame] | 682 | return |
| 683 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 684 | Tracer.invokeFunction(self, function) |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 685 | |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 686 | buffer_targets = [ |
| 687 | 'ARRAY_BUFFER', |
| 688 | 'ELEMENT_ARRAY_BUFFER', |
| 689 | 'PIXEL_PACK_BUFFER', |
| 690 | 'PIXEL_UNPACK_BUFFER', |
José Fonseca | 7b20d67 | 2012-01-10 19:13:58 +0000 | [diff] [blame] | 691 | 'UNIFORM_BUFFER', |
| 692 | 'TEXTURE_BUFFER', |
| 693 | 'TRANSFORM_FEEDBACK_BUFFER', |
| 694 | 'COPY_READ_BUFFER', |
| 695 | 'COPY_WRITE_BUFFER', |
| 696 | 'DRAW_INDIRECT_BUFFER', |
| 697 | 'ATOMIC_COUNTER_BUFFER', |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 698 | ] |
| 699 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 700 | def wrapRet(self, function, instance): |
| 701 | Tracer.wrapRet(self, function, instance) |
José Fonseca | 1b3d375 | 2011-07-15 10:15:19 +0100 | [diff] [blame] | 702 | |
José Fonseca | 1b6c875 | 2012-04-15 14:33:00 +0100 | [diff] [blame^] | 703 | # Replace function addresses with ours |
| 704 | if function.name in self.getProcAddressFunctionNames: |
| 705 | print ' %s = _wrapProcAddress(%s, %s);' % (instance, function.args[0].name, instance) |
| 706 | |
José Fonseca | cdc322c | 2012-02-29 19:29:51 +0000 | [diff] [blame] | 707 | # Keep track of buffer mappings |
| 708 | if function.name in ('glMapBuffer', 'glMapBufferARB'): |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 709 | print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' |
| 710 | print ' if (mapping) {' |
| 711 | print ' mapping->map = %s;' % (instance) |
| 712 | print ' mapping->length = 0;' |
| 713 | print ' __glGetBufferParameteriv(target, GL_BUFFER_SIZE, &mapping->length);' |
| 714 | print ' mapping->write = (access != GL_READ_ONLY);' |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 715 | print ' mapping->explicit_flush = false;' |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 716 | print ' }' |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 717 | if function.name == 'glMapBufferRange': |
José Fonseca | 9c536b0 | 2012-02-29 20:54:13 +0000 | [diff] [blame] | 718 | print ' if (access & GL_MAP_WRITE_BIT) {' |
| 719 | print ' __checkBufferMapRange = true;' |
| 720 | print ' }' |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 721 | print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' |
| 722 | print ' if (mapping) {' |
| 723 | print ' mapping->map = %s;' % (instance) |
| 724 | print ' mapping->length = length;' |
| 725 | print ' mapping->write = access & GL_MAP_WRITE_BIT;' |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 726 | print ' mapping->explicit_flush = access & GL_MAP_FLUSH_EXPLICIT_BIT;' |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 727 | print ' }' |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 728 | |
José Fonseca | c9f1223 | 2011-03-25 20:07:42 +0000 | [diff] [blame] | 729 | boolean_names = [ |
| 730 | 'GL_FALSE', |
| 731 | 'GL_TRUE', |
| 732 | ] |
| 733 | |
| 734 | def gl_boolean(self, value): |
| 735 | return self.boolean_names[int(bool(value))] |
| 736 | |
José Fonseca | c29f4f1 | 2011-06-11 12:19:05 +0100 | [diff] [blame] | 737 | # Names of the functions that unpack from a pixel buffer object. See the |
| 738 | # ARB_pixel_buffer_object specification. |
José Fonseca | e97bab9 | 2011-06-02 23:15:11 +0100 | [diff] [blame] | 739 | unpack_function_names = set([ |
| 740 | 'glBitmap', |
José Fonseca | c29f4f1 | 2011-06-11 12:19:05 +0100 | [diff] [blame] | 741 | 'glColorSubTable', |
| 742 | 'glColorTable', |
| 743 | 'glCompressedTexImage1D', |
| 744 | 'glCompressedTexImage2D', |
| 745 | 'glCompressedTexImage3D', |
| 746 | 'glCompressedTexSubImage1D', |
| 747 | 'glCompressedTexSubImage2D', |
| 748 | 'glCompressedTexSubImage3D', |
| 749 | 'glConvolutionFilter1D', |
| 750 | 'glConvolutionFilter2D', |
José Fonseca | e97bab9 | 2011-06-02 23:15:11 +0100 | [diff] [blame] | 751 | 'glDrawPixels', |
| 752 | 'glMultiTexImage1DEXT', |
| 753 | 'glMultiTexImage2DEXT', |
| 754 | 'glMultiTexImage3DEXT', |
| 755 | 'glMultiTexSubImage1DEXT', |
| 756 | 'glMultiTexSubImage2DEXT', |
| 757 | 'glMultiTexSubImage3DEXT', |
José Fonseca | c29f4f1 | 2011-06-11 12:19:05 +0100 | [diff] [blame] | 758 | 'glPixelMapfv', |
| 759 | 'glPixelMapuiv', |
| 760 | 'glPixelMapusv', |
José Fonseca | e97bab9 | 2011-06-02 23:15:11 +0100 | [diff] [blame] | 761 | 'glPolygonStipple', |
José Fonseca | c29f4f1 | 2011-06-11 12:19:05 +0100 | [diff] [blame] | 762 | 'glSeparableFilter2D', |
José Fonseca | e97bab9 | 2011-06-02 23:15:11 +0100 | [diff] [blame] | 763 | 'glTexImage1D', |
| 764 | 'glTexImage1DEXT', |
| 765 | 'glTexImage2D', |
| 766 | 'glTexImage2DEXT', |
| 767 | 'glTexImage3D', |
| 768 | 'glTexImage3DEXT', |
| 769 | 'glTexSubImage1D', |
| 770 | 'glTexSubImage1DEXT', |
| 771 | 'glTexSubImage2D', |
| 772 | 'glTexSubImage2DEXT', |
| 773 | 'glTexSubImage3D', |
| 774 | 'glTexSubImage3DEXT', |
| 775 | 'glTextureImage1DEXT', |
| 776 | 'glTextureImage2DEXT', |
| 777 | 'glTextureImage3DEXT', |
| 778 | 'glTextureSubImage1DEXT', |
| 779 | 'glTextureSubImage2DEXT', |
| 780 | 'glTextureSubImage3DEXT', |
| 781 | ]) |
| 782 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 783 | def serializeArgValue(self, function, arg): |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 784 | if function.name in self.draw_function_names and arg.name == 'indices': |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 785 | print ' GLint __element_array_buffer = 0;' |
| 786 | print ' __glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &__element_array_buffer);' |
| 787 | print ' if (!__element_array_buffer) {' |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 788 | if isinstance(arg.type, stdapi.Array): |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 789 | print ' trace::localWriter.beginArray(%s);' % arg.type.length |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 790 | print ' for(GLsizei i = 0; i < %s; ++i) {' % arg.type.length |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 791 | print ' trace::localWriter.beginElement();' |
| 792 | print ' trace::localWriter.writeBlob(%s[i], count[i]*__gl_type_size(type));' % (arg.name) |
| 793 | print ' trace::localWriter.endElement();' |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 794 | print ' }' |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 795 | print ' trace::localWriter.endArray();' |
José Fonseca | 5c749e3 | 2011-05-09 11:11:37 +0100 | [diff] [blame] | 796 | else: |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 797 | print ' trace::localWriter.writeBlob(%s, count*__gl_type_size(type));' % (arg.name) |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 798 | print ' } else {' |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 799 | Tracer.serializeArgValue(self, function, arg) |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 800 | print ' }' |
| 801 | return |
| 802 | |
José Fonseca | e97bab9 | 2011-06-02 23:15:11 +0100 | [diff] [blame] | 803 | # Recognize offsets instead of blobs when a PBO is bound |
| 804 | if function.name in self.unpack_function_names \ |
| 805 | and (isinstance(arg.type, stdapi.Blob) \ |
| 806 | or (isinstance(arg.type, stdapi.Const) \ |
| 807 | and isinstance(arg.type.type, stdapi.Blob))): |
José Fonseca | c29f4f1 | 2011-06-11 12:19:05 +0100 | [diff] [blame] | 808 | print ' {' |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 809 | print ' gltrace::Context *ctx = gltrace::getContext();' |
José Fonseca | c29f4f1 | 2011-06-11 12:19:05 +0100 | [diff] [blame] | 810 | print ' GLint __unpack_buffer = 0;' |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 811 | print ' if (ctx->profile == gltrace::PROFILE_COMPAT)' |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 812 | print ' __glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &__unpack_buffer);' |
José Fonseca | c29f4f1 | 2011-06-11 12:19:05 +0100 | [diff] [blame] | 813 | print ' if (__unpack_buffer) {' |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 814 | print ' trace::localWriter.writeOpaque(%s);' % arg.name |
José Fonseca | c29f4f1 | 2011-06-11 12:19:05 +0100 | [diff] [blame] | 815 | print ' } else {' |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 816 | Tracer.serializeArgValue(self, function, arg) |
José Fonseca | c29f4f1 | 2011-06-11 12:19:05 +0100 | [diff] [blame] | 817 | print ' }' |
José Fonseca | e97bab9 | 2011-06-02 23:15:11 +0100 | [diff] [blame] | 818 | print ' }' |
| 819 | return |
| 820 | |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 821 | # Several GL state functions take GLenum symbolic names as |
| 822 | # integer/floats; so dump the symbolic name whenever possible |
José Fonseca | 3bcb33c | 2011-05-27 20:14:31 +0100 | [diff] [blame] | 823 | if function.name.startswith('gl') \ |
José Fonseca | e357109 | 2011-10-13 08:26:27 +0100 | [diff] [blame] | 824 | and arg.type in (glapi.GLint, glapi.GLfloat, glapi.GLdouble) \ |
José Fonseca | 3bcb33c | 2011-05-27 20:14:31 +0100 | [diff] [blame] | 825 | and arg.name == 'param': |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 826 | assert arg.index > 0 |
| 827 | assert function.args[arg.index - 1].name == 'pname' |
| 828 | assert function.args[arg.index - 1].type == glapi.GLenum |
| 829 | print ' if (is_symbolic_pname(pname) && is_symbolic_param(%s)) {' % arg.name |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 830 | self.serializeValue(glapi.GLenum, arg.name) |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 831 | print ' } else {' |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 832 | Tracer.serializeArgValue(self, function, arg) |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 833 | print ' }' |
| 834 | return |
| 835 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 836 | Tracer.serializeArgValue(self, function, arg) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 837 | |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 838 | def footer(self, api): |
| 839 | Tracer.footer(self, api) |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 840 | |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 841 | # A simple state tracker to track the pointer values |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 842 | # update the state |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 843 | print 'static void __trace_user_arrays(GLuint maxindex)' |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 844 | print '{' |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 845 | print ' gltrace::Context *ctx = gltrace::getContext();' |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 846 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 847 | for camelcase_name, uppercase_name in self.arrays: |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 848 | # in which profile is the array available? |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 849 | profile_check = 'ctx->profile == gltrace::PROFILE_COMPAT' |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 850 | if camelcase_name in self.arrays_es1: |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 851 | profile_check = '(' + profile_check + ' || ctx->profile == gltrace::PROFILE_ES1)'; |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 852 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 853 | function_name = 'gl%sPointer' % camelcase_name |
| 854 | enable_name = 'GL_%s_ARRAY' % uppercase_name |
| 855 | binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name |
José Fonseca | 1b6c875 | 2012-04-15 14:33:00 +0100 | [diff] [blame^] | 856 | function = api.getFunctionByName(function_name) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 857 | |
José Fonseca | 06e8519 | 2011-10-16 14:15:36 +0100 | [diff] [blame] | 858 | print ' // %s' % function.prototype() |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 859 | print ' if (%s) {' % profile_check |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 860 | self.array_trace_prolog(api, uppercase_name) |
| 861 | self.array_prolog(api, uppercase_name) |
| 862 | print ' if (__glIsEnabled(%s)) {' % enable_name |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 863 | print ' GLint __binding = 0;' |
| 864 | print ' __glGetIntegerv(%s, &__binding);' % binding_name |
| 865 | print ' if (!__binding) {' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 866 | |
| 867 | # Get the arguments via glGet* |
| 868 | for arg in function.args: |
| 869 | arg_get_enum = 'GL_%s_ARRAY_%s' % (uppercase_name, arg.name.upper()) |
| 870 | arg_get_function, arg_type = TypeGetter().visit(arg.type) |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 871 | print ' %s %s = 0;' % (arg_type, arg.name) |
| 872 | print ' __%s(%s, &%s);' % (arg_get_function, arg_get_enum, arg.name) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 873 | |
| 874 | arg_names = ', '.join([arg.name for arg in function.args[:-1]]) |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 875 | print ' size_t __size = __%s_size(%s, maxindex);' % (function.name, arg_names) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 876 | |
| 877 | # Emit a fake function |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 878 | self.array_trace_intermezzo(api, uppercase_name) |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 879 | print ' unsigned __call = trace::localWriter.beginEnter(&__%s_sig);' % (function.name,) |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 880 | for arg in function.args: |
| 881 | assert not arg.output |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 882 | print ' trace::localWriter.beginArg(%u);' % (arg.index,) |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 883 | if arg.name != 'pointer': |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 884 | self.serializeValue(arg.type, arg.name) |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 885 | else: |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 886 | print ' trace::localWriter.writeBlob((const void *)%s, __size);' % (arg.name) |
| 887 | print ' trace::localWriter.endArg();' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 888 | |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 889 | print ' trace::localWriter.endEnter();' |
| 890 | print ' trace::localWriter.beginLeave(__call);' |
| 891 | print ' trace::localWriter.endLeave();' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 892 | print ' }' |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 893 | print ' }' |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 894 | self.array_epilog(api, uppercase_name) |
| 895 | self.array_trace_epilog(api, uppercase_name) |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 896 | print ' }' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 897 | print |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 898 | |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 899 | # Samething, but for glVertexAttribPointer* |
| 900 | # |
| 901 | # Some variants of glVertexAttribPointer alias conventional and generic attributes: |
| 902 | # - glVertexAttribPointer: no |
| 903 | # - glVertexAttribPointerARB: implementation dependent |
| 904 | # - glVertexAttribPointerNV: yes |
| 905 | # |
| 906 | # This means that the implementations of these functions do not always |
| 907 | # alias, and they need to be considered independently. |
| 908 | # |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 909 | print ' // ES1 does not support generic vertex attributes' |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 910 | print ' if (ctx->profile == gltrace::PROFILE_ES1)' |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 911 | print ' return;' |
| 912 | print |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 913 | print ' vertex_attrib __vertex_attrib = __get_vertex_attrib();' |
| 914 | print |
| 915 | for suffix in ['', 'ARB', 'NV']: |
| 916 | if suffix: |
José Fonseca | d94aaac | 2011-06-28 20:50:49 +0100 | [diff] [blame] | 917 | SUFFIX = '_' + suffix |
José Fonseca | d94aaac | 2011-06-28 20:50:49 +0100 | [diff] [blame] | 918 | else: |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 919 | SUFFIX = suffix |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 920 | function_name = 'glVertexAttribPointer' + suffix |
José Fonseca | 1b6c875 | 2012-04-15 14:33:00 +0100 | [diff] [blame^] | 921 | function = api.getFunctionByName(function_name) |
José Fonseca | 06e8519 | 2011-10-16 14:15:36 +0100 | [diff] [blame] | 922 | |
| 923 | print ' // %s' % function.prototype() |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 924 | print ' if (__vertex_attrib == VERTEX_ATTRIB%s) {' % SUFFIX |
| 925 | if suffix == 'NV': |
| 926 | print ' GLint __max_vertex_attribs = 16;' |
| 927 | else: |
| 928 | print ' GLint __max_vertex_attribs = 0;' |
| 929 | print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &__max_vertex_attribs);' |
| 930 | print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' |
| 931 | print ' GLint __enabled = 0;' |
| 932 | if suffix == 'NV': |
| 933 | print ' __glGetIntegerv(GL_VERTEX_ATTRIB_ARRAY0_NV + index, &__enabled);' |
| 934 | else: |
| 935 | print ' __glGetVertexAttribiv%s(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED%s, &__enabled);' % (suffix, SUFFIX) |
| 936 | print ' if (__enabled) {' |
| 937 | print ' GLint __binding = 0;' |
| 938 | if suffix != 'NV': |
| 939 | # It doesn't seem possible to use VBOs with NV_vertex_program. |
| 940 | print ' __glGetVertexAttribiv%s(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING%s, &__binding);' % (suffix, SUFFIX) |
| 941 | print ' if (!__binding) {' |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 942 | |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 943 | # Get the arguments via glGet* |
| 944 | for arg in function.args[1:]: |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 945 | if suffix == 'NV': |
| 946 | arg_get_enum = 'GL_ATTRIB_ARRAY_%s%s' % (arg.name.upper(), SUFFIX) |
| 947 | else: |
| 948 | 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] | 949 | arg_get_function, arg_type = TypeGetter('glGetVertexAttrib', False, suffix).visit(arg.type) |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 950 | print ' %s %s = 0;' % (arg_type, arg.name) |
| 951 | 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] | 952 | |
| 953 | arg_names = ', '.join([arg.name for arg in function.args[1:-1]]) |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 954 | print ' size_t __size = __%s_size(%s, maxindex);' % (function.name, arg_names) |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 955 | |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 956 | # Emit a fake function |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 957 | print ' unsigned __call = trace::localWriter.beginEnter(&__%s_sig);' % (function.name,) |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 958 | for arg in function.args: |
| 959 | assert not arg.output |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 960 | print ' trace::localWriter.beginArg(%u);' % (arg.index,) |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 961 | if arg.name != 'pointer': |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 962 | self.serializeValue(arg.type, arg.name) |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 963 | else: |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 964 | print ' trace::localWriter.writeBlob((const void *)%s, __size);' % (arg.name) |
| 965 | print ' trace::localWriter.endArg();' |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 966 | |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 967 | print ' trace::localWriter.endEnter();' |
| 968 | print ' trace::localWriter.beginLeave(__call);' |
| 969 | print ' trace::localWriter.endLeave();' |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 970 | print ' }' |
| 971 | print ' }' |
| 972 | print ' }' |
| 973 | print ' }' |
| 974 | print |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 975 | |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 976 | print '}' |
| 977 | print |
| 978 | |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 979 | # |
| 980 | # Hooks for glTexCoordPointer, which is identical to the other array |
| 981 | # pointers except the fact that it is indexed by glClientActiveTexture. |
| 982 | # |
| 983 | |
| 984 | def array_prolog(self, api, uppercase_name): |
| 985 | if uppercase_name == 'TEXTURE_COORD': |
| 986 | print ' GLint client_active_texture = 0;' |
| 987 | print ' __glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE, &client_active_texture);' |
| 988 | print ' GLint max_texture_coords = 0;' |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 989 | print ' if (ctx->profile == gltrace::PROFILE_COMPAT)' |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 990 | print ' __glGetIntegerv(GL_MAX_TEXTURE_COORDS, &max_texture_coords);' |
| 991 | print ' else' |
| 992 | print ' __glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_texture_coords);' |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 993 | print ' for (GLint unit = 0; unit < max_texture_coords; ++unit) {' |
José Fonseca | 7525e6f | 2011-09-28 09:04:56 +0100 | [diff] [blame] | 994 | print ' GLint texture = GL_TEXTURE0 + unit;' |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 995 | print ' __glClientActiveTexture(texture);' |
| 996 | |
| 997 | def array_trace_prolog(self, api, uppercase_name): |
| 998 | if uppercase_name == 'TEXTURE_COORD': |
| 999 | print ' bool client_active_texture_dirty = false;' |
| 1000 | |
| 1001 | def array_epilog(self, api, uppercase_name): |
| 1002 | if uppercase_name == 'TEXTURE_COORD': |
| 1003 | print ' }' |
| 1004 | self.array_cleanup(api, uppercase_name) |
| 1005 | |
| 1006 | def array_cleanup(self, api, uppercase_name): |
| 1007 | if uppercase_name == 'TEXTURE_COORD': |
| 1008 | print ' __glClientActiveTexture(client_active_texture);' |
| 1009 | |
| 1010 | def array_trace_intermezzo(self, api, uppercase_name): |
| 1011 | if uppercase_name == 'TEXTURE_COORD': |
| 1012 | print ' if (texture != client_active_texture || client_active_texture_dirty) {' |
| 1013 | print ' client_active_texture_dirty = true;' |
| 1014 | self.fake_glClientActiveTexture_call(api, "texture"); |
| 1015 | print ' }' |
| 1016 | |
| 1017 | def array_trace_epilog(self, api, uppercase_name): |
| 1018 | if uppercase_name == 'TEXTURE_COORD': |
| 1019 | print ' if (client_active_texture_dirty) {' |
| 1020 | self.fake_glClientActiveTexture_call(api, "client_active_texture"); |
| 1021 | print ' }' |
| 1022 | |
| 1023 | def fake_glClientActiveTexture_call(self, api, texture): |
José Fonseca | 1b6c875 | 2012-04-15 14:33:00 +0100 | [diff] [blame^] | 1024 | function = api.getFunctionByName('glClientActiveTexture') |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 1025 | self.fake_call(function, [texture]) |
| 1026 | |
| 1027 | def fake_call(self, function, args): |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 1028 | print ' unsigned __fake_call = trace::localWriter.beginEnter(&__%s_sig);' % (function.name,) |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 1029 | for arg, instance in zip(function.args, args): |
| 1030 | assert not arg.output |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 1031 | print ' trace::localWriter.beginArg(%u);' % (arg.index,) |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 1032 | self.serializeValue(arg.type, instance) |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 1033 | print ' trace::localWriter.endArg();' |
| 1034 | print ' trace::localWriter.endEnter();' |
| 1035 | print ' trace::localWriter.beginLeave(__fake_call);' |
| 1036 | print ' trace::localWriter.endLeave();' |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 1037 | |
| 1038 | |
| 1039 | |
| 1040 | |
| 1041 | |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 1042 | |
| 1043 | |
| 1044 | |
| 1045 | |
| 1046 | |
| 1047 | |