]> git.cworth.org Git - apitrace/blobdiff - glstate.py
Generated code formatting improvements.
[apitrace] / glstate.py
index c09e4fc9d3f8b5ad5c4a33a40286583154433bf9..7ab2dd14def421e0f6214fd9766eef55d2e08137 100644 (file)
 '''Generate code to dump most GL state into JSON.'''
 
 
-from stdapi import *
+from specs.stdapi import *
 
-from gltypes import *
-from glparams import *
+from specs.gltypes import *
+from specs.glparams import *
 
 
 texture_targets = [
@@ -189,9 +189,9 @@ class JsonWriter(Visitor):
     It expects a previously declared JSONWriter instance named "json".'''
 
     def visit_literal(self, literal, instance):
-        if literal.format == 'Bool':
+        if literal.kind == 'Bool':
             print '    json.writeBool(%s);' % instance
-        elif literal.format in ('SInt', 'Uint', 'Float', 'Double'):
+        elif literal.kind in ('SInt', 'Uint', 'Float', 'Double'):
             print '    json.writeNumber(%s);' % instance
         else:
             raise NotImplementedError
@@ -249,7 +249,7 @@ class StateDumper:
         print 'const char *'
         print 'enumToString(GLenum pname)'
         print '{'
-        print '    switch(pname) {'
+        print '    switch (pname) {'
         for name in GLenum.values:
             print '    case %s:' % name
             print '        return "%s";' % name
@@ -259,6 +259,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'
         print 'dumpEnum(JSONWriter &json, GLenum pname)'
         print '{'
@@ -373,13 +380,18 @@ class StateDumper:
         print '            json.beginMember(name);'
         print '            glActiveTexture(GL_TEXTURE0 + unit);'
         print '            json.beginObject();'
-        print '            GLint texture;'
+        print '            GLboolean enabled;'
+        print '            GLint binding;'
         print
         for target, binding in texture_targets:
             print '            // %s' % target
-            print '            texture = 0;'
-            print '            glGetIntegerv(%s, &texture);' % binding
-            print '            if (glIsEnabled(%s) || texture) {' % target
+            print '            enabled = GL_FALSE;'
+            print '            glGetBooleanv(%s, &enabled);' % target
+            print '            json.writeBoolMember("%s", enabled);' % target
+            print '            binding = 0;'
+            print '            glGetIntegerv(%s, &binding);' % binding
+            print '            json.writeNumberMember("%s", binding);' % binding
+            print '            if (enabled || binding) {'
             print '                json.beginMember("%s");' % target
             print '                json.beginObject();'
             self.dump_atoms(glGetTexParameter, target)
@@ -410,11 +422,10 @@ class StateDumper:
             print '                json.beginObject();'
             print '                for (GLint i = 0; i < max_color_attachments; ++i) {'
             print '                    GLint color_attachment = GL_COLOR_ATTACHMENT0 + i;'
-            self.dump_attachment_parameters(target, 'color_attachment')
+            print '                    dumpFramebufferAttachementParameters(json, %s, color_attachment);' % target
             print '                }'
-            self.dump_attachment_parameters(target, 'GL_DEPTH_ATTACHMENT')
-            self.dump_attachment_parameters(target, 'GL_STENCIL_ATTACHMENT')
-            #self.dump_attachment_parameters(target, 'GL_DEPTH_STENCIL_ATTACHMENT')
+            print '                dumpFramebufferAttachementParameters(json, %s, GL_DEPTH_ATTACHMENT);' % target
+            print '                dumpFramebufferAttachementParameters(json, %s, GL_STENCIL_ATTACHMENT);' % target
             print '                json.endObject();'
             print '                json.endMember(); // %s' % target
             print '            }'