From 8739fa62b41d54455447a27c4185371366bd726e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Thu, 15 Nov 2012 13:36:09 +0000 Subject: [PATCH] retrace: Use different methods for writing int/floats. More efficient code, less compiler warnings. --- retrace/glstate_images.cpp | 16 ++++++++-------- retrace/glstate_params.py | 16 +++++++++------- retrace/glstate_shaders.cpp | 24 ++++++++++++------------ retrace/json.hpp | 17 ++++++++++++----- 4 files changed, 41 insertions(+), 32 deletions(-) diff --git a/retrace/glstate_images.cpp b/retrace/glstate_images.cpp index e534a65..e5e1451 100644 --- a/retrace/glstate_images.cpp +++ b/retrace/glstate_images.cpp @@ -409,9 +409,9 @@ dumpActiveTextureLevel(JSONWriter &json, Context &context, GLenum target, GLint // Tell the GUI this is no ordinary object, but an image json.writeStringMember("__class__", "image"); - json.writeNumberMember("__width__", desc.width); - json.writeNumberMember("__height__", desc.height); - json.writeNumberMember("__depth__", desc.depth); + json.writeIntMember("__width__", desc.width); + json.writeIntMember("__height__", desc.height); + json.writeIntMember("__depth__", desc.depth); json.writeStringMember("__format__", formatToString(desc.internalFormat)); @@ -419,7 +419,7 @@ dumpActiveTextureLevel(JSONWriter &json, Context &context, GLenum target, GLint // texture internal format json.writeStringMember("__type__", "uint8"); json.writeBoolMember("__normalized__", true); - json.writeNumberMember("__channels__", channels); + json.writeIntMember("__channels__", channels); GLubyte *pixels = new GLubyte[desc.depth*desc.width*desc.height*channels]; @@ -859,9 +859,9 @@ dumpReadBufferImage(JSONWriter &json, GLint width, GLint height, GLenum format, // Tell the GUI this is no ordinary object, but an image json.writeStringMember("__class__", "image"); - json.writeNumberMember("__width__", width); - json.writeNumberMember("__height__", height); - json.writeNumberMember("__depth__", 1); + json.writeIntMember("__width__", width); + json.writeIntMember("__height__", height); + json.writeIntMember("__depth__", 1); json.writeStringMember("__format__", formatToString(internalFormat)); @@ -869,7 +869,7 @@ dumpReadBufferImage(JSONWriter &json, GLint width, GLint height, GLenum format, // texture internal format json.writeStringMember("__type__", "uint8"); json.writeBoolMember("__normalized__", true); - json.writeNumberMember("__channels__", channels); + json.writeIntMember("__channels__", channels); GLenum type = GL_UNSIGNED_BYTE; diff --git a/retrace/glstate_params.py b/retrace/glstate_params.py index a87457f..c88b6f0 100644 --- a/retrace/glstate_params.py +++ b/retrace/glstate_params.py @@ -203,8 +203,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 @@ -219,7 +221,7 @@ class JsonWriter(Visitor): print ' dumpEnum(json, %s);' % instance else: assert False - print ' json.writeNumber(%s);' % instance + print ' json.writeInt(%s);' % instance def visitBitmask(self, bitmask, instance): raise NotImplementedError @@ -228,7 +230,7 @@ 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 @@ -273,7 +275,7 @@ class StateDumper: print ' json.writeString("GL_TRUE");' print ' break;' print ' default:' - print ' json.writeNumber(static_cast(value));' + print ' json.writeInt(static_cast(value));' print ' break;' print ' }' print '}' @@ -299,7 +301,7 @@ class StateDumper: print ' if (s) {' print ' json.writeString(s);' print ' } else {' - print ' json.writeNumber(pname);' + print ' json.writeInt(pname);' print ' }' print '}' print @@ -433,7 +435,7 @@ class StateDumper: 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();' diff --git a/retrace/glstate_shaders.cpp b/retrace/glstate_shaders.cpp index a651d99..d32a7b4 100644 --- a/retrace/glstate_shaders.cpp +++ b/retrace/glstate_shaders.cpp @@ -245,16 +245,16 @@ dumpUniformValues(JSONWriter &json, GLenum type, const void *values, GLint matri switch (elemType) { case GL_FLOAT: - json.writeNumber(*u.fvalue); + json.writeFloat(*u.fvalue); break; case GL_DOUBLE: - json.writeNumber(*u.dvalue); + json.writeFloat(*u.dvalue); break; case GL_INT: - json.writeNumber(*u.ivalue); + json.writeInt(*u.ivalue); break; case GL_UNSIGNED_INT: - json.writeNumber(*u.uivalue); + json.writeInt(*u.uivalue); break; case GL_BOOL: json.writeBool(*u.uivalue); @@ -625,10 +625,10 @@ dumpArbProgramUniforms(JSONWriter &json, GLenum target, const char *prefix) json.beginMember(name); json.beginArray(); - json.writeNumber(params[0]); - json.writeNumber(params[1]); - json.writeNumber(params[2]); - json.writeNumber(params[3]); + json.writeFloat(params[0]); + json.writeFloat(params[1]); + json.writeFloat(params[2]); + json.writeFloat(params[3]); json.endArray(); json.endMember(); } @@ -648,10 +648,10 @@ dumpArbProgramUniforms(JSONWriter &json, GLenum target, const char *prefix) json.beginMember(name); json.beginArray(); - json.writeNumber(params[0]); - json.writeNumber(params[1]); - json.writeNumber(params[2]); - json.writeNumber(params[3]); + json.writeFloat(params[0]); + json.writeFloat(params[1]); + json.writeFloat(params[2]); + json.writeFloat(params[3]); json.endArray(); json.endMember(); } diff --git a/retrace/json.hpp b/retrace/json.hpp index 4ad2ab3..0431cf7 100644 --- a/retrace/json.hpp +++ b/retrace/json.hpp @@ -320,14 +320,14 @@ public: * Special case for char to prevent it to be written as a literal * character. */ - inline void writeNumber(char n) { + inline void writeInt(signed char n) { separator(); os << std::dec << static_cast(n); value = true; space = ' '; } - inline void writeNumber(unsigned char n) { + inline void writeInt(unsigned char n) { separator(); os << std::dec << static_cast(n); value = true; @@ -335,7 +335,14 @@ public: } template - inline void writeNumber(T n) { + inline void writeInt(T n) { + separator(); + os << std::dec << n; + value = true; + space = ' '; + } + template + inline void writeFloat(T n) { separator(); if (isnan(n)) { // NaN is non-standard but widely supported @@ -366,9 +373,9 @@ public: } template - inline void writeNumberMember(const char *name, T n) { + inline void writeIntMember(const char *name, T n) { beginMember(name); - writeNumber(n); + writeInt(n); endMember(); } }; -- 2.43.0