X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=retrace%2Fglstate_params.py;h=50693a97d5bd43676010c815a23ea3b7251428cf;hb=ddf6d2c5e347f8ca25dad4d9be4a1494d8929d30;hp=32f7f7ca50da65fda2a20fd5a5316b55bd1b41d7;hpb=162bbecced029b25c9f7119ccdc2615eb0496bc5;p=apitrace diff --git a/retrace/glstate_params.py b/retrace/glstate_params.py index 32f7f7c..50693a9 100644 --- a/retrace/glstate_params.py +++ b/retrace/glstate_params.py @@ -144,7 +144,7 @@ class StateGetter(Visitor): return self.visitScalar(alias, args) def visitEnum(self, enum, args): - return self.visit(GLint, args) + return self.visitScalar(enum, args) def visitBitmask(self, bitmask, args): return self.visit(GLint, args) @@ -156,12 +156,21 @@ class StateGetter(Visitor): elem_type = self.inflector.reduced_type(array.type) inflection = self.inflector.inflect(array.type) assert inflection.endswith('v') - print ' %s %s[%s + 1];' % (elem_type, temp_name, array.length) - print ' memset(%s, 0, %s * sizeof *%s);' % (temp_name, array.length, temp_name) - print ' %s[%s] = (%s)0xdeadc0de;' % (temp_name, array.length, elem_type) + array_length = array.length + if array_length.isdigit(): + # Static integer length + print ' %s %s[%s + 1];' % (elem_type, temp_name, array_length) + else: + # Put the length in a variable to avoid recomputing it every time + print ' size_t _%s_length = %s;' % (temp_name, array_length) + array_length = '_%s_length' % temp_name + # Allocate a dynamic sized array + print ' %s *%s = _allocator.alloc<%s>(%s + 1);' % (elem_type, temp_name, elem_type, array_length) + print ' memset(%s, 0, %s * sizeof *%s);' % (temp_name, array_length, temp_name) + print ' %s[%s] = (%s)0xdeadc0de;' % (temp_name, array_length, elem_type) print ' %s(%s, %s);' % (inflection + self.suffix, ', '.join(args), temp_name) # Simple buffer overflow detection - print ' assert(%s[%s] == (%s)0xdeadc0de);' % (temp_name, array.length, elem_type) + print ' assert(%s[%s] == (%s)0xdeadc0de);' % (temp_name, array_length, elem_type) return temp_name def visitOpaque(self, pointer, args): @@ -203,8 +212,10 @@ class JsonWriter(Visitor): def visitLiteral(self, literal, instance): if literal.kind == 'Bool': print ' json.writeBool(%s);' % instance - elif literal.kind in ('SInt', 'Uint', 'Float', 'Double'): - print ' json.writeNumber(%s);' % instance + elif literal.kind in ('SInt', 'Uint'): + print ' json.writeInt(%s);' % instance + elif literal.kind in ('Float', 'Double'): + print ' json.writeFloat(%s);' % instance else: raise NotImplementedError @@ -213,10 +224,13 @@ class JsonWriter(Visitor): print ' json.writeString((const char *)%s);' % instance def visitEnum(self, enum, instance): - if enum.expr == 'GLenum': + if enum is GLboolean: + print ' dumpBoolean(json, %s);' % instance + elif enum is GLenum: print ' dumpEnum(json, %s);' % instance else: - print ' json.writeNumber(%s);' % instance + assert False + print ' json.writeInt(%s);' % instance def visitBitmask(self, bitmask, instance): raise NotImplementedError @@ -225,12 +239,12 @@ class JsonWriter(Visitor): self.visit(alias.type, instance) def visitOpaque(self, opaque, instance): - print ' json.writeNumber((size_t)%s);' % instance + print ' json.writeInt((size_t)%s);' % instance __index = 0 def visitArray(self, array, instance): - index = '__i%u' % JsonWriter.__index + index = '_i%u' % JsonWriter.__index JsonWriter.__index += 1 print ' json.beginArray();' print ' for (unsigned %s = 0; %s < %s; ++%s) {' % (index, index, array.length, index) @@ -248,9 +262,11 @@ class StateDumper: pass def dump(self): + print '#include ' print '#include ' print print '#include "json.hpp"' + print '#include "scoped_allocator.hpp"' print '#include "glproc.hpp"' print '#include "glsize.hpp"' print '#include "glstate.hpp"' @@ -259,6 +275,23 @@ class StateDumper: print 'namespace glstate {' print + print 'void' + print 'dumpBoolean(JSONWriter &json, GLboolean value)' + print '{' + print ' switch (value) {' + print ' case GL_FALSE:' + print ' json.writeString("GL_FALSE");' + print ' break;' + print ' case GL_TRUE:' + print ' json.writeString("GL_TRUE");' + print ' break;' + print ' default:' + print ' json.writeInt(static_cast(value));' + print ' break;' + print ' }' + print '}' + print + print 'const char *' print 'enumToString(GLenum pname)' print '{' @@ -272,13 +305,6 @@ class StateDumper: print '}' print - print 'static void' - print 'dumpFramebufferAttachementParameters(JSONWriter &json, GLenum target, GLenum attachment)' - print '{' - self.dump_attachment_parameters('target', 'attachment') - print '}' - print - print 'void' print 'dumpEnum(JSONWriter &json, GLenum pname)' print '{' @@ -286,13 +312,23 @@ class StateDumper: print ' if (s) {' print ' json.writeString(s);' print ' } else {' - print ' json.writeNumber(pname);' + print ' json.writeInt(pname);' print ' }' print '}' print + print 'static void' + print 'dumpFramebufferAttachementParameters(JSONWriter &json, GLenum target, GLenum attachment)' + print '{' + self.dump_attachment_parameters('target', 'attachment') + print '}' + print + print 'void dumpParameters(JSONWriter &json, Context &context)' print '{' + print ' ScopedAllocator _allocator;' + print ' (void)_allocator;' + print print ' json.beginMember("parameters");' print ' json.beginObject();' @@ -324,7 +360,7 @@ class StateDumper: def dump_light_params(self): print ' GLint max_lights = 0;' - print ' __glGetIntegerv(GL_MAX_LIGHTS, &max_lights);' + print ' _glGetIntegerv(GL_MAX_LIGHTS, &max_lights);' print ' for (GLint index = 0; index < max_lights; ++index) {' print ' GLenum light = GL_LIGHT0 + index;' print ' if (glIsEnabled(light)) {' @@ -360,7 +396,7 @@ class StateDumper: def dump_vertex_attribs(self): print ' GLint max_vertex_attribs = 0;' - print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &max_vertex_attribs);' + print ' _glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &max_vertex_attribs);' print ' for (GLint index = 0; index < max_vertex_attribs; ++index) {' print ' char name[32];' print ' snprintf(name, sizeof name, "GL_VERTEX_ATTRIB_ARRAY%i", index);' @@ -408,10 +444,12 @@ class StateDumper: print ' // %s' % target print ' enabled = GL_FALSE;' print ' glGetBooleanv(%s, &enabled);' % target - print ' json.writeBoolMember("%s", enabled);' % target + print ' json.beginMember("%s");' % target + print ' dumpBoolean(json, enabled);' + print ' json.endMember();' print ' binding = 0;' print ' glGetIntegerv(%s, &binding);' % binding - print ' json.writeNumberMember("%s", binding);' % binding + print ' json.writeIntMember("%s", binding);' % binding print ' if (enabled || binding) {' print ' json.beginMember("%s");' % target print ' json.beginObject();'