Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 528 lines (448 sloc) 20.342 kB
589082d @jrfonseca Basic state dumping.
jrfonseca authored
1 ##########################################################################
2 #
3 # Copyright 2011 Jose Fonseca
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
5ea9187 @jrfonseca Unify glenum.py and glstate.py parameter table into a single one.
jrfonseca authored
27 '''Generate code to dump most GL state into JSON.'''
589082d @jrfonseca Basic state dumping.
jrfonseca authored
28
29
9d27a54 @jrfonseca Move retracers to their own directory.
jrfonseca authored
30 import retrace # to adjust sys.path
31
bd86a22 @jrfonseca Move all API specs to a separate dir.
jrfonseca authored
32 from specs.stdapi import *
3c8ce56 @jrfonseca More gl parameter cleanup.
jrfonseca authored
33
bd86a22 @jrfonseca Move all API specs to a separate dir.
jrfonseca authored
34 from specs.gltypes import *
35 from specs.glparams import *
3c8ce56 @jrfonseca More gl parameter cleanup.
jrfonseca authored
36
589082d @jrfonseca Basic state dumping.
jrfonseca authored
37
fc92b76 @jrfonseca Dump the enabled textures.
jrfonseca authored
38 texture_targets = [
42c122a @zackr Make texture dumping work with new applications.
zackr authored
39 ('GL_TEXTURE_1D', 'GL_TEXTURE_BINDING_1D'),
40 ('GL_TEXTURE_2D', 'GL_TEXTURE_BINDING_2D'),
41 ('GL_TEXTURE_3D', 'GL_TEXTURE_BINDING_3D'),
fe89e12 @jrfonseca Dump rectangle textures too.
jrfonseca authored
42 ('GL_TEXTURE_RECTANGLE', 'GL_TEXTURE_BINDING_RECTANGLE'),
e1c3a5f @jrfonseca Dump (the first face of) cube map textures.
jrfonseca authored
43 ('GL_TEXTURE_CUBE_MAP', 'GL_TEXTURE_BINDING_CUBE_MAP')
fc92b76 @jrfonseca Dump the enabled textures.
jrfonseca authored
44 ]
45
f7bd923 @jrfonseca Dump framebuffer parameters.
jrfonseca authored
46 framebuffer_targets = [
47 ('GL_DRAW_FRAMEBUFFER', 'GL_DRAW_FRAMEBUFFER_BINDING'),
48 ('GL_READ_FRAMEBUFFER', 'GL_READ_FRAMEBUFFER_BINDING'),
49 ]
589082d @jrfonseca Basic state dumping.
jrfonseca authored
50
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
51 class GetInflector:
52 '''Objects that describes how to inflect.'''
c2d9f8a @jrfonseca Dump current program and attached shaders into JSON output.
jrfonseca authored
53
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
54 reduced_types = {
55 B: I,
56 E: I,
57 I: F,
58 }
c2d9f8a @jrfonseca Dump current program and attached shaders into JSON output.
jrfonseca authored
59
7bb97ac @jrfonseca Dump arb program parameters.
jrfonseca authored
60 def __init__(self, radical, inflections, suffix = ''):
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
61 self.radical = radical
7bb97ac @jrfonseca Dump arb program parameters.
jrfonseca authored
62 self.inflections = inflections
63 self.suffix = suffix
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
64
65 def reduced_type(self, type):
7bb97ac @jrfonseca Dump arb program parameters.
jrfonseca authored
66 if type in self.inflections:
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
67 return type
68 if type in self.reduced_types:
69 return self.reduced_type(self.reduced_types[type])
70 raise NotImplementedError
71
72 def inflect(self, type):
7bb97ac @jrfonseca Dump arb program parameters.
jrfonseca authored
73 return self.radical + self.inflection(type) + self.suffix
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
74
7bb97ac @jrfonseca Dump arb program parameters.
jrfonseca authored
75 def inflection(self, type):
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
76 type = self.reduced_type(type)
7bb97ac @jrfonseca Dump arb program parameters.
jrfonseca authored
77 assert type in self.inflections
78 return self.inflections[type]
79
80 def __str__(self):
81 return self.radical + self.suffix
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
82
83
84 class StateGetter(Visitor):
85 '''Type visitor that is able to extract the state via one of the glGet*
86 functions.
87
88 It will declare any temporary variable
89 '''
90
f336ed5 @jrfonseca Dump more program states.
jrfonseca authored
91 def __init__(self, radical, inflections, suffix=''):
92 self.inflector = GetInflector(radical, inflections)
93 self.suffix = suffix
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
94
6cba345 @jrfonseca Cleanup texture environment state dumping.
jrfonseca authored
95 def iter(self):
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
96 for function, type, count, name in parameters:
6cba345 @jrfonseca Cleanup texture environment state dumping.
jrfonseca authored
97 inflection = self.inflector.radical + self.suffix
98 if inflection not in function.split(','):
99 continue
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
100 if type is X:
101 continue
6cba345 @jrfonseca Cleanup texture environment state dumping.
jrfonseca authored
102 yield type, count, name
103
104 def __call__(self, *args):
105 pname = args[-1]
106
107 for type, count, name in self.iter():
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
108 if name == pname:
109 if count != 1:
110 type = Array(type, str(count))
111
112 return type, self.visit(type, args)
113
114 raise NotImplementedError
115
116 def temp_name(self, args):
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
117 '''Return the name of a temporary variable to hold the state.'''
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
118 pname = args[-1]
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
119
120 return pname[3:].lower()
121
54f304a @jrfonseca Cleanup/comment/format code.
jrfonseca authored
122 def visitConst(self, const, args):
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
123 return self.visit(const.type, args)
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
124
54f304a @jrfonseca Cleanup/comment/format code.
jrfonseca authored
125 def visitScalar(self, type, args):
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
126 temp_name = self.temp_name(args)
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
127 elem_type = self.inflector.reduced_type(type)
128 inflection = self.inflector.inflect(type)
129 if inflection.endswith('v'):
130 print ' %s %s = 0;' % (elem_type, temp_name)
f336ed5 @jrfonseca Dump more program states.
jrfonseca authored
131 print ' %s(%s, &%s);' % (inflection + self.suffix, ', '.join(args), temp_name)
c2d9f8a @jrfonseca Dump current program and attached shaders into JSON output.
jrfonseca authored
132 else:
f336ed5 @jrfonseca Dump more program states.
jrfonseca authored
133 print ' %s %s = %s(%s);' % (elem_type, temp_name, inflection + self.suffix, ', '.join(args))
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
134 return temp_name
135
54f304a @jrfonseca Cleanup/comment/format code.
jrfonseca authored
136 def visitString(self, string, args):
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
137 temp_name = self.temp_name(args)
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
138 inflection = self.inflector.inflect(string)
139 assert not inflection.endswith('v')
f336ed5 @jrfonseca Dump more program states.
jrfonseca authored
140 print ' %s %s = (%s)%s(%s);' % (string, temp_name, string, inflection + self.suffix, ', '.join(args))
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
141 return temp_name
142
54f304a @jrfonseca Cleanup/comment/format code.
jrfonseca authored
143 def visitAlias(self, alias, args):
144 return self.visitScalar(alias, args)
c2d9f8a @jrfonseca Dump current program and attached shaders into JSON output.
jrfonseca authored
145
54f304a @jrfonseca Cleanup/comment/format code.
jrfonseca authored
146 def visitEnum(self, enum, args):
7ec9050 @jrfonseca Dump GLboolean as enum.
jrfonseca authored
147 return self.visitScalar(enum, args)
c2d9f8a @jrfonseca Dump current program and attached shaders into JSON output.
jrfonseca authored
148
54f304a @jrfonseca Cleanup/comment/format code.
jrfonseca authored
149 def visitBitmask(self, bitmask, args):
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
150 return self.visit(GLint, args)
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
151
54f304a @jrfonseca Cleanup/comment/format code.
jrfonseca authored
152 def visitArray(self, array, args):
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
153 temp_name = self.temp_name(args)
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
154 if array.length == '1':
155 return self.visit(array.type)
156 elem_type = self.inflector.reduced_type(array.type)
157 inflection = self.inflector.inflect(array.type)
158 assert inflection.endswith('v')
f7dd5a0 @jrfonseca Simple buffer overflow detection on glGet*.
jrfonseca authored
159 print ' %s %s[%s + 1];' % (elem_type, temp_name, array.length)
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
160 print ' memset(%s, 0, %s * sizeof *%s);' % (temp_name, array.length, temp_name)
f7dd5a0 @jrfonseca Simple buffer overflow detection on glGet*.
jrfonseca authored
161 print ' %s[%s] = (%s)0xdeadc0de;' % (temp_name, array.length, elem_type)
f336ed5 @jrfonseca Dump more program states.
jrfonseca authored
162 print ' %s(%s, %s);' % (inflection + self.suffix, ', '.join(args), temp_name)
f7dd5a0 @jrfonseca Simple buffer overflow detection on glGet*.
jrfonseca authored
163 # Simple buffer overflow detection
164 print ' assert(%s[%s] == (%s)0xdeadc0de);' % (temp_name, array.length, elem_type)
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
165 return temp_name
166
54f304a @jrfonseca Cleanup/comment/format code.
jrfonseca authored
167 def visitOpaque(self, pointer, args):
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
168 temp_name = self.temp_name(args)
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
169 inflection = self.inflector.inflect(pointer)
170 assert inflection.endswith('v')
171 print ' GLvoid *%s;' % temp_name
f336ed5 @jrfonseca Dump more program states.
jrfonseca authored
172 print ' %s(%s, &%s);' % (inflection + self.suffix, ', '.join(args), temp_name)
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
173 return temp_name
c2d9f8a @jrfonseca Dump current program and attached shaders into JSON output.
jrfonseca authored
174
175
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
176 glGet = StateGetter('glGet', {
177 B: 'Booleanv',
178 I: 'Integerv',
179 F: 'Floatv',
180 D: 'Doublev',
181 S: 'String',
182 P: 'Pointerv',
183 })
184
24e9a5f @jrfonseca Dump more state: lights, materials.
jrfonseca authored
185 glGetMaterial = StateGetter('glGetMaterial', {I: 'iv', F: 'fv'})
186 glGetLight = StateGetter('glGetLight', {I: 'iv', F: 'fv'})
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
187 glGetVertexAttrib = StateGetter('glGetVertexAttrib', {I: 'iv', F: 'fv', D: 'dv', P: 'Pointerv'})
188 glGetTexParameter = StateGetter('glGetTexParameter', {I: 'iv', F: 'fv'})
188af34 @jrfonseca More state: texenv.
jrfonseca authored
189 glGetTexEnv = StateGetter('glGetTexEnv', {I: 'iv', F: 'fv'})
4ea3f91 @jrfonseca Dump vertex attribs in a more GL-like manner.
jrfonseca authored
190 glGetTexLevelParameter = StateGetter('glGetTexLevelParameter', {I: 'iv', F: 'fv'})
90ab708 @jrfonseca Describe glGetShader params.
jrfonseca authored
191 glGetShader = StateGetter('glGetShaderiv', {I: 'iv'})
e8e1725 @jrfonseca Describe glGetProgram params.
jrfonseca authored
192 glGetProgram = StateGetter('glGetProgram', {I: 'iv'})
f336ed5 @jrfonseca Dump more program states.
jrfonseca authored
193 glGetProgramARB = StateGetter('glGetProgram', {I: 'iv', F: 'fv', S: 'Stringv'}, 'ARB')
f7bd923 @jrfonseca Dump framebuffer parameters.
jrfonseca authored
194 glGetFramebufferAttachmentParameter = StateGetter('glGetFramebufferAttachmentParameter', {I: 'iv'})
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
195
196
c2d9f8a @jrfonseca Dump current program and attached shaders into JSON output.
jrfonseca authored
197 class JsonWriter(Visitor):
198 '''Type visitor that will dump a value of the specified type through the
199 JSON writer.
9bdd508 @jrfonseca Use a type visitor to dump JSON values instead of ad-hoc code.
jrfonseca authored
200
201 It expects a previously declared JSONWriter instance named "json".'''
4a7f226 @jrfonseca More state.
jrfonseca authored
202
54f304a @jrfonseca Cleanup/comment/format code.
jrfonseca authored
203 def visitLiteral(self, literal, instance):
2f2ea48 @jrfonseca Cleanup Literal class.
jrfonseca authored
204 if literal.kind == 'Bool':
4a7f226 @jrfonseca More state.
jrfonseca authored
205 print ' json.writeBool(%s);' % instance
2f2ea48 @jrfonseca Cleanup Literal class.
jrfonseca authored
206 elif literal.kind in ('SInt', 'Uint', 'Float', 'Double'):
4a7f226 @jrfonseca More state.
jrfonseca authored
207 print ' json.writeNumber(%s);' % instance
208 else:
209 raise NotImplementedError
210
54f304a @jrfonseca Cleanup/comment/format code.
jrfonseca authored
211 def visitString(self, string, instance):
4a7f226 @jrfonseca More state.
jrfonseca authored
212 assert string.length is None
213 print ' json.writeString((const char *)%s);' % instance
214
54f304a @jrfonseca Cleanup/comment/format code.
jrfonseca authored
215 def visitEnum(self, enum, instance):
7ec9050 @jrfonseca Dump GLboolean as enum.
jrfonseca authored
216 if enum is GLboolean:
217 print ' dumpBoolean(json, %s);' % instance
218 elif enum is GLenum:
2e3fff6 @jrfonseca Reorganize glstate code.
jrfonseca authored
219 print ' dumpEnum(json, %s);' % instance
9bdd508 @jrfonseca Use a type visitor to dump JSON values instead of ad-hoc code.
jrfonseca authored
220 else:
7ec9050 @jrfonseca Dump GLboolean as enum.
jrfonseca authored
221 assert False
9bdd508 @jrfonseca Use a type visitor to dump JSON values instead of ad-hoc code.
jrfonseca authored
222 print ' json.writeNumber(%s);' % instance
4a7f226 @jrfonseca More state.
jrfonseca authored
223
54f304a @jrfonseca Cleanup/comment/format code.
jrfonseca authored
224 def visitBitmask(self, bitmask, instance):
4a7f226 @jrfonseca More state.
jrfonseca authored
225 raise NotImplementedError
226
54f304a @jrfonseca Cleanup/comment/format code.
jrfonseca authored
227 def visitAlias(self, alias, instance):
4a7f226 @jrfonseca More state.
jrfonseca authored
228 self.visit(alias.type, instance)
229
54f304a @jrfonseca Cleanup/comment/format code.
jrfonseca authored
230 def visitOpaque(self, opaque, instance):
9bdd508 @jrfonseca Use a type visitor to dump JSON values instead of ad-hoc code.
jrfonseca authored
231 print ' json.writeNumber((size_t)%s);' % instance
232
233 __index = 0
234
54f304a @jrfonseca Cleanup/comment/format code.
jrfonseca authored
235 def visitArray(self, array, instance):
632a78d @jrfonseca Don't abuse double-underscore prefix.
jrfonseca authored
236 index = '_i%u' % JsonWriter.__index
c2d9f8a @jrfonseca Dump current program and attached shaders into JSON output.
jrfonseca authored
237 JsonWriter.__index += 1
9bdd508 @jrfonseca Use a type visitor to dump JSON values instead of ad-hoc code.
jrfonseca authored
238 print ' json.beginArray();'
fc92b76 @jrfonseca Dump the enabled textures.
jrfonseca authored
239 print ' for (unsigned %s = 0; %s < %s; ++%s) {' % (index, index, array.length, index)
9bdd508 @jrfonseca Use a type visitor to dump JSON values instead of ad-hoc code.
jrfonseca authored
240 self.visit(array.type, '%s[%s]' % (instance, index))
241 print ' }'
242 print ' json.endArray();'
243
244
4a7f226 @jrfonseca More state.
jrfonseca authored
245
589082d @jrfonseca Basic state dumping.
jrfonseca authored
246 class StateDumper:
56eb358 @jrfonseca Abstract glGet* function inflection.
jrfonseca authored
247 '''Class to generate code to dump all GL state in JSON format via
248 stdout.'''
589082d @jrfonseca Basic state dumping.
jrfonseca authored
249
250 def __init__(self):
b51c6d3 @jrfonseca Remove dead code.
jrfonseca authored
251 pass
589082d @jrfonseca Basic state dumping.
jrfonseca authored
252
253 def dump(self):
254 print '#include <string.h>'
255 print
256 print '#include "json.hpp"'
c2d9f8a @jrfonseca Dump current program and attached shaders into JSON output.
jrfonseca authored
257 print '#include "glproc.hpp"'
b794df1 @jrfonseca Dump stencil buffer too.
jrfonseca authored
258 print '#include "glsize.hpp"'
05c3d03 @jrfonseca Start making glstate an independent module.
jrfonseca authored
259 print '#include "glstate.hpp"'
1627e88 @hantempo Enable framebuffer dump during replay for GLES.
hantempo authored
260 print '#include "glstate_internal.hpp"'
589082d @jrfonseca Basic state dumping.
jrfonseca authored
261 print
2e3fff6 @jrfonseca Reorganize glstate code.
jrfonseca authored
262 print 'namespace glstate {'
263 print
ed2167c @jrfonseca Dump enums and pointers correctly.
jrfonseca authored
264
7ec9050 @jrfonseca Dump GLboolean as enum.
jrfonseca authored
265 print 'void'
266 print 'dumpBoolean(JSONWriter &json, GLboolean value)'
267 print '{'
268 print ' switch (value) {'
269 print ' case GL_FALSE:'
270 print ' json.writeString("GL_FALSE");'
271 print ' break;'
272 print ' case GL_TRUE:'
273 print ' json.writeString("GL_TRUE");'
274 print ' break;'
275 print ' default:'
276 print ' json.writeNumber(static_cast<GLint>(value));'
277 print ' break;'
278 print ' }'
279 print '}'
280 print
281
2e3fff6 @jrfonseca Reorganize glstate code.
jrfonseca authored
282 print 'const char *'
283 print 'enumToString(GLenum pname)'
ed2167c @jrfonseca Dump enums and pointers correctly.
jrfonseca authored
284 print '{'
06e8519 @jrfonseca Generated code formatting improvements.
jrfonseca authored
285 print ' switch (pname) {'
c2d9f8a @jrfonseca Dump current program and attached shaders into JSON output.
jrfonseca authored
286 for name in GLenum.values:
ed2167c @jrfonseca Dump enums and pointers correctly.
jrfonseca authored
287 print ' case %s:' % name
f7a6b62 @jrfonseca Show shader type in the combo box.
jrfonseca authored
288 print ' return "%s";' % name
ed2167c @jrfonseca Dump enums and pointers correctly.
jrfonseca authored
289 print ' default:'
f7a6b62 @jrfonseca Show shader type in the combo box.
jrfonseca authored
290 print ' return NULL;'
ed2167c @jrfonseca Dump enums and pointers correctly.
jrfonseca authored
291 print ' }'
292 print '}'
293 print
294
2e3fff6 @jrfonseca Reorganize glstate code.
jrfonseca authored
295 print 'void'
296 print 'dumpEnum(JSONWriter &json, GLenum pname)'
c2d9f8a @jrfonseca Dump current program and attached shaders into JSON output.
jrfonseca authored
297 print '{'
2e3fff6 @jrfonseca Reorganize glstate code.
jrfonseca authored
298 print ' const char *s = enumToString(pname);'
f7a6b62 @jrfonseca Show shader type in the combo box.
jrfonseca authored
299 print ' if (s) {'
300 print ' json.writeString(s);'
c2d9f8a @jrfonseca Dump current program and attached shaders into JSON output.
jrfonseca authored
301 print ' } else {'
f7a6b62 @jrfonseca Show shader type in the combo box.
jrfonseca authored
302 print ' json.writeNumber(pname);'
c2d9f8a @jrfonseca Dump current program and attached shaders into JSON output.
jrfonseca authored
303 print ' }'
304 print '}'
305 print
306
7ec9050 @jrfonseca Dump GLboolean as enum.
jrfonseca authored
307 print 'static void'
308 print 'dumpFramebufferAttachementParameters(JSONWriter &json, GLenum target, GLenum attachment)'
309 print '{'
310 self.dump_attachment_parameters('target', 'attachment')
311 print '}'
312 print
313
1627e88 @hantempo Enable framebuffer dump during replay for GLES.
hantempo authored
314 print 'void dumpParameters(JSONWriter &json, Context &context)'
589082d @jrfonseca Basic state dumping.
jrfonseca authored
315 print '{'
316 print ' json.beginMember("parameters");'
317 print ' json.beginObject();'
fa6d049 @jrfonseca Share more code.
jrfonseca authored
318
319 self.dump_atoms(glGet)
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
320
24e9a5f @jrfonseca Dump more state: lights, materials.
jrfonseca authored
321 self.dump_material_params()
322 self.dump_light_params()
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
323 self.dump_vertex_attribs()
f336ed5 @jrfonseca Dump more program states.
jrfonseca authored
324 self.dump_program_params()
4c3e8c6 @jrfonseca Move texture paramaters to JSON parameter object.
jrfonseca authored
325 self.dump_texture_parameters()
f7bd923 @jrfonseca Dump framebuffer parameters.
jrfonseca authored
326 self.dump_framebuffer_parameters()
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
327
589082d @jrfonseca Basic state dumping.
jrfonseca authored
328 print ' json.endObject();'
329 print ' json.endMember(); // parameters'
2e3fff6 @jrfonseca Reorganize glstate code.
jrfonseca authored
330 print '}'
589082d @jrfonseca Basic state dumping.
jrfonseca authored
331 print
2e3fff6 @jrfonseca Reorganize glstate code.
jrfonseca authored
332
333 print '} /*namespace glstate */'
4a7f226 @jrfonseca More state.
jrfonseca authored
334
24e9a5f @jrfonseca Dump more state: lights, materials.
jrfonseca authored
335 def dump_material_params(self):
1627e88 @hantempo Enable framebuffer dump during replay for GLES.
hantempo authored
336 print ' if (!context.ES) {'
24e9a5f @jrfonseca Dump more state: lights, materials.
jrfonseca authored
337 for face in ['GL_FRONT', 'GL_BACK']:
338 print ' json.beginMember("%s");' % face
339 print ' json.beginObject();'
340 self.dump_atoms(glGetMaterial, face)
341 print ' json.endObject();'
1627e88 @hantempo Enable framebuffer dump during replay for GLES.
hantempo authored
342 print ' }'
24e9a5f @jrfonseca Dump more state: lights, materials.
jrfonseca authored
343 print
344
345 def dump_light_params(self):
346 print ' GLint max_lights = 0;'
632a78d @jrfonseca Don't abuse double-underscore prefix.
jrfonseca authored
347 print ' _glGetIntegerv(GL_MAX_LIGHTS, &max_lights);'
24e9a5f @jrfonseca Dump more state: lights, materials.
jrfonseca authored
348 print ' for (GLint index = 0; index < max_lights; ++index) {'
349 print ' GLenum light = GL_LIGHT0 + index;'
350 print ' if (glIsEnabled(light)) {'
351 print ' char name[32];'
352 print ' snprintf(name, sizeof name, "GL_LIGHT%i", index);'
353 print ' json.beginMember(name);'
354 print ' json.beginObject();'
355 self.dump_atoms(glGetLight, ' GL_LIGHT0 + index')
356 print ' json.endObject();'
357 print ' json.endMember(); // GL_LIGHTi'
358 print ' }'
359 print ' }'
360 print
361
6cba345 @jrfonseca Cleanup texture environment state dumping.
jrfonseca authored
362 def texenv_param_target(self, name):
363 if name == 'GL_TEXTURE_LOD_BIAS':
364 return 'GL_TEXTURE_FILTER_CONTROL'
365 elif name == 'GL_COORD_REPLACE':
366 return 'GL_POINT_SPRITE'
367 else:
368 return 'GL_TEXTURE_ENV'
369
188af34 @jrfonseca More state: texenv.
jrfonseca authored
370 def dump_texenv_params(self):
371 for target in ['GL_TEXTURE_ENV', 'GL_TEXTURE_FILTER_CONTROL', 'GL_POINT_SPRITE']:
1627e88 @hantempo Enable framebuffer dump during replay for GLES.
hantempo authored
372 print ' if (!context.ES) {'
639abec @jrfonseca More state dump cleanup.
jrfonseca authored
373 print ' json.beginMember("%s");' % target
374 print ' json.beginObject();'
6cba345 @jrfonseca Cleanup texture environment state dumping.
jrfonseca authored
375 for _, _, name in glGetTexEnv.iter():
376 if self.texenv_param_target(name) == target:
377 self.dump_atom(glGetTexEnv, target, name)
639abec @jrfonseca More state dump cleanup.
jrfonseca authored
378 print ' json.endObject();'
379 print ' }'
188af34 @jrfonseca More state: texenv.
jrfonseca authored
380
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
381 def dump_vertex_attribs(self):
382 print ' GLint max_vertex_attribs = 0;'
632a78d @jrfonseca Don't abuse double-underscore prefix.
jrfonseca authored
383 print ' _glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &max_vertex_attribs);'
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
384 print ' for (GLint index = 0; index < max_vertex_attribs; ++index) {'
4ea3f91 @jrfonseca Dump vertex attribs in a more GL-like manner.
jrfonseca authored
385 print ' char name[32];'
386 print ' snprintf(name, sizeof name, "GL_VERTEX_ATTRIB_ARRAY%i", index);'
387 print ' json.beginMember(name);'
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
388 print ' json.beginObject();'
fa6d049 @jrfonseca Share more code.
jrfonseca authored
389 self.dump_atoms(glGetVertexAttrib, 'index')
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
390 print ' json.endObject();'
4ea3f91 @jrfonseca Dump vertex attribs in a more GL-like manner.
jrfonseca authored
391 print ' json.endMember(); // GL_VERTEX_ATTRIB_ARRAYi'
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
392 print ' }'
393 print
4c3e8c6 @jrfonseca Move texture paramaters to JSON parameter object.
jrfonseca authored
394
f336ed5 @jrfonseca Dump more program states.
jrfonseca authored
395 program_targets = [
396 'GL_FRAGMENT_PROGRAM_ARB',
397 'GL_VERTEX_PROGRAM_ARB',
398 ]
399
400 def dump_program_params(self):
401 for target in self.program_targets:
7bb97ac @jrfonseca Dump arb program parameters.
jrfonseca authored
402 print ' if (glIsEnabled(%s)) {' % target
403 print ' json.beginMember("%s");' % target
404 print ' json.beginObject();'
f336ed5 @jrfonseca Dump more program states.
jrfonseca authored
405 self.dump_atoms(glGetProgramARB, target)
7bb97ac @jrfonseca Dump arb program parameters.
jrfonseca authored
406 print ' json.endObject();'
407 print ' }'
f336ed5 @jrfonseca Dump more program states.
jrfonseca authored
408
4c3e8c6 @jrfonseca Move texture paramaters to JSON parameter object.
jrfonseca authored
409 def dump_texture_parameters(self):
410 print ' {'
411 print ' GLint active_texture = GL_TEXTURE0;'
412 print ' glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);'
413 print ' GLint max_texture_coords = 0;'
414 print ' glGetIntegerv(GL_MAX_TEXTURE_COORDS, &max_texture_coords);'
415 print ' GLint max_combined_texture_image_units = 0;'
416 print ' glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &max_combined_texture_image_units);'
162bbec @jrfonseca Fix max units computation.
jrfonseca authored
417 print ' GLint max_units = std::max(std::max(max_combined_texture_image_units, max_texture_coords), 2);'
4c3e8c6 @jrfonseca Move texture paramaters to JSON parameter object.
jrfonseca authored
418 print ' for (GLint unit = 0; unit < max_units; ++unit) {'
419 print ' char name[32];'
420 print ' snprintf(name, sizeof name, "GL_TEXTURE%i", unit);'
421 print ' json.beginMember(name);'
422 print ' glActiveTexture(GL_TEXTURE0 + unit);'
423 print ' json.beginObject();'
7ca8367 @jrfonseca List GL_TEXTURE_xxx and GL_TEXTURE_BINDING_xxx params per texture unit.
jrfonseca authored
424 print ' GLboolean enabled;'
425 print ' GLint binding;'
4c3e8c6 @jrfonseca Move texture paramaters to JSON parameter object.
jrfonseca authored
426 print
427 for target, binding in texture_targets:
428 print ' // %s' % target
7ca8367 @jrfonseca List GL_TEXTURE_xxx and GL_TEXTURE_BINDING_xxx params per texture unit.
jrfonseca authored
429 print ' enabled = GL_FALSE;'
430 print ' glGetBooleanv(%s, &enabled);' % target
7ec9050 @jrfonseca Dump GLboolean as enum.
jrfonseca authored
431 print ' json.beginMember("%s");' % target
432 print ' dumpBoolean(json, enabled);'
433 print ' json.endMember();'
7ca8367 @jrfonseca List GL_TEXTURE_xxx and GL_TEXTURE_BINDING_xxx params per texture unit.
jrfonseca authored
434 print ' binding = 0;'
435 print ' glGetIntegerv(%s, &binding);' % binding
436 print ' json.writeNumberMember("%s", binding);' % binding
437 print ' if (enabled || binding) {'
4c3e8c6 @jrfonseca Move texture paramaters to JSON parameter object.
jrfonseca authored
438 print ' json.beginMember("%s");' % target
439 print ' json.beginObject();'
440 self.dump_atoms(glGetTexParameter, target)
1627e88 @hantempo Enable framebuffer dump during replay for GLES.
hantempo authored
441 print ' if (!context.ES) {'
4c3e8c6 @jrfonseca Move texture paramaters to JSON parameter object.
jrfonseca authored
442 # We only dump the first level parameters
443 self.dump_atoms(glGetTexLevelParameter, target, "0")
1627e88 @hantempo Enable framebuffer dump during replay for GLES.
hantempo authored
444 print ' }'
4c3e8c6 @jrfonseca Move texture paramaters to JSON parameter object.
jrfonseca authored
445 print ' json.endObject();'
446 print ' json.endMember(); // %s' % target
447 print ' }'
448 print
6cba345 @jrfonseca Cleanup texture environment state dumping.
jrfonseca authored
449 print ' if (unit < max_texture_coords) {'
450 self.dump_texenv_params()
451 print ' }'
4c3e8c6 @jrfonseca Move texture paramaters to JSON parameter object.
jrfonseca authored
452 print ' json.endObject();'
453 print ' json.endMember(); // GL_TEXTUREi'
454 print ' }'
455 print ' glActiveTexture(active_texture);'
456 print ' }'
5eb7e70 @jrfonseca Dump vertex attribute parameters.
jrfonseca authored
457 print
458
f7bd923 @jrfonseca Dump framebuffer parameters.
jrfonseca authored
459 def dump_framebuffer_parameters(self):
460 print ' {'
461 print ' GLint max_color_attachments = 0;'
462 print ' glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &max_color_attachments);'
463 print ' GLint framebuffer;'
464 for target, binding in framebuffer_targets:
465 print ' // %s' % target
466 print ' framebuffer = 0;'
467 print ' glGetIntegerv(%s, &framebuffer);' % binding
468 print ' if (framebuffer) {'
469 print ' json.beginMember("%s");' % target
470 print ' json.beginObject();'
471 print ' for (GLint i = 0; i < max_color_attachments; ++i) {'
472 print ' GLint color_attachment = GL_COLOR_ATTACHMENT0 + i;'
b0a4a36 @jrfonseca Dump framebuffer images with their true size.
jrfonseca authored
473 print ' dumpFramebufferAttachementParameters(json, %s, color_attachment);' % target
f7bd923 @jrfonseca Dump framebuffer parameters.
jrfonseca authored
474 print ' }'
b0a4a36 @jrfonseca Dump framebuffer images with their true size.
jrfonseca authored
475 print ' dumpFramebufferAttachementParameters(json, %s, GL_DEPTH_ATTACHMENT);' % target
476 print ' dumpFramebufferAttachementParameters(json, %s, GL_STENCIL_ATTACHMENT);' % target
f7bd923 @jrfonseca Dump framebuffer parameters.
jrfonseca authored
477 print ' json.endObject();'
478 print ' json.endMember(); // %s' % target
479 print ' }'
480 print
481 print ' }'
482 print
483
484 def dump_attachment_parameters(self, target, attachment):
485 print ' {'
486 print ' GLint object_type = GL_NONE;'
487 print ' glGetFramebufferAttachmentParameteriv(%s, %s, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &object_type);' % (target, attachment)
488 print ' if (object_type != GL_NONE) {'
489 print ' json.beginMember(enumToString(%s));' % attachment
490 print ' json.beginObject();'
491 self.dump_atoms(glGetFramebufferAttachmentParameter, target, attachment)
492 print ' json.endObject();'
493 print ' json.endMember(); // GL_x_ATTACHMENT'
494 print ' }'
495 print ' }'
496
fa6d049 @jrfonseca Share more code.
jrfonseca authored
497 def dump_atoms(self, getter, *args):
6cba345 @jrfonseca Cleanup texture environment state dumping.
jrfonseca authored
498 for _, _, name in getter.iter():
499 self.dump_atom(getter, *(args + (name,)))
500
501 def dump_atom(self, getter, *args):
87445ce @jrfonseca Workaround a crash on MacOSX when reading the SAMPLER_BINDING state.
jrfonseca authored
502 name = args[-1]
503
504 # Avoid crash on MacOSX
505 # XXX: The right fix would be to look at the support extensions..
506 import platform
507 if name == 'GL_SAMPLER_BINDING' and platform.system() == 'Darwin':
508 return
509
510 print ' // %s' % name
511 print ' {'
512 #print ' assert(glGetError() == GL_NO_ERROR);'
513 type, value = getter(*args)
514 print ' if (glGetError() != GL_NO_ERROR) {'
515 #print ' std::cerr << "warning: %s(%s) failed\\n";' % (inflection, name)
516 print ' while (glGetError() != GL_NO_ERROR) {}'
517 print ' } else {'
518 print ' json.beginMember("%s");' % name
519 JsonWriter().visit(type, value)
520 print ' json.endMember();'
521 print ' }'
522 print ' }'
523 print
fa6d049 @jrfonseca Share more code.
jrfonseca authored
524
589082d @jrfonseca Basic state dumping.
jrfonseca authored
525
526 if __name__ == '__main__':
527 StateDumper().dump()
Something went wrong with that request. Please try again.