From 7ec9050b3b96f7a6c663361c7d8000eef5418667 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Mon, 16 Apr 2012 20:09:42 +0100 Subject: [PATCH] Dump GLboolean as enum. More readable. --- common/json.hpp | 19 ++++++++++++++++ retrace/glstate_internal.hpp | 2 ++ retrace/glstate_params.py | 42 +++++++++++++++++++++++++++--------- specs/__init__.py | 0 specs/gltypes.py | 6 +++++- specs/glxapi.py | 2 ++ 6 files changed, 60 insertions(+), 11 deletions(-) delete mode 100644 specs/__init__.py diff --git a/common/json.hpp b/common/json.hpp index 621610a..14ff501 100644 --- a/common/json.hpp +++ b/common/json.hpp @@ -306,6 +306,25 @@ public: space = ' '; } + + /** + * Special case for char to prevent it to be written as a literal + * character. + */ + inline void writeNumber(char n) { + separator(); + os << std::dec << static_cast(n); + value = true; + space = ' '; + } + + inline void writeNumber(unsigned char n) { + separator(); + os << std::dec << static_cast(n); + value = true; + space = ' '; + } + template inline void writeNumber(T n) { if (n != n) { diff --git a/retrace/glstate_internal.hpp b/retrace/glstate_internal.hpp index aab7f98..a709da3 100644 --- a/retrace/glstate_internal.hpp +++ b/retrace/glstate_internal.hpp @@ -54,6 +54,8 @@ struct Context }; +void dumpBoolean(JSONWriter &json, GLboolean value); + void dumpEnum(JSONWriter &json, GLenum pname); void dumpParameters(JSONWriter &json, Context &context); diff --git a/retrace/glstate_params.py b/retrace/glstate_params.py index 32f7f7c..1b578ee 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) @@ -213,9 +213,12 @@ 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: + assert False print ' json.writeNumber(%s);' % instance def visitBitmask(self, bitmask, instance): @@ -259,6 +262,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.writeNumber(static_cast(value));' + print ' break;' + print ' }' + print '}' + print + print 'const char *' print 'enumToString(GLenum pname)' print '{' @@ -272,13 +292,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 '{' @@ -291,6 +304,13 @@ 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 dumpParameters(JSONWriter &json, Context &context)' print '{' print ' json.beginMember("parameters");' @@ -408,7 +428,9 @@ 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 diff --git a/specs/__init__.py b/specs/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/specs/gltypes.py b/specs/gltypes.py index 2200a88..71d7cd6 100644 --- a/specs/gltypes.py +++ b/specs/gltypes.py @@ -32,7 +32,11 @@ import platform from stdapi import * -GLboolean = Alias("GLboolean", Bool) +GLboolean = Enum("GLboolean", [ + "GL_TRUE", + "GL_FALSE", +]) + GLvoid = Alias("GLvoid", Void) GLbyte = Alias("GLbyte", SChar) GLshort = Alias("GLshort", Short) diff --git a/specs/glxapi.py b/specs/glxapi.py index 7119cc6..d7353a0 100644 --- a/specs/glxapi.py +++ b/specs/glxapi.py @@ -454,3 +454,5 @@ glxapi.addFunctions([ ]) +# To prevent collision with stdapi.Bool +del Bool -- 2.43.0