]> git.cworth.org Git - apitrace/commitdiff
Handle uniform locations correctly.
authorJosé Fonseca <jfonseca@vmware.com>
Mon, 6 Dec 2010 18:50:52 +0000 (18:50 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Mon, 6 Dec 2010 18:51:49 +0000 (18:51 +0000)
It requires a two-level table.

glapi.py
glretrace.py
retrace.py
stdapi.py

index 2b66810850f1d2a8b5a0861e0432d799de5b0e14..8d437e6887e5505fc22e972804a18273451e46df 100644 (file)
--- a/glapi.py
+++ b/glapi.py
@@ -76,7 +76,7 @@ GLquery = Handle("query", GLuint)
 GLfenceNV = Handle("fenceNV", GLuint)
 GLprogram = Handle("program", GLuint)
 GLshader = Handle("shader", GLuint)
-GLlocation = Handle("location", GLint)
+GLlocation = Handle("location", GLint, key=('program', GLuint))
 GLlocationARB = Handle("locationARB", GLint)
 GLprogramARB = Handle("programARB", GLuint)
 GLprogramEXT = Handle("programEXT", GLuint)
index e047ed0c47e4c4222747ff7d598d80d000224865..f8b425b4db090d00b8d9bca872e5fc89e1ddde47 100644 (file)
@@ -132,15 +132,18 @@ class GlRetracer(Retracer):
         if (function.name in self.pointer_function_names and arg.name == 'pointer' or
             function.name in self.draw_elements_function_names and arg.name == 'indices'):
             self.extract_pointer(function, arg, arg_type, lvalue, rvalue)
-        else:
-            Retracer.extract_arg(self, function, arg, arg_type, lvalue, rvalue)
-
-    def extract_pointer(self, function, arg, arg_type, lvalue, rvalue):
-        print '    if (dynamic_cast<Trace::Null *>(&%s)) {' % rvalue
-        print '        %s = 0;' % (lvalue)
-        print '    } else {'
-        print '        %s = (%s)(uintptr_t)(%s);' % (lvalue, arg_type, rvalue)
-        print '    }'
+            print '    if (dynamic_cast<Trace::Null *>(&%s)) {' % rvalue
+            print '        %s = 0;' % (lvalue)
+            print '    } else {'
+            print '        %s = (%s)(uintptr_t)(%s);' % (lvalue, arg_type, rvalue)
+            print '    }'
+            return
+
+        if function.name.startswith('glUniform') and function.args[0].name == arg.name == 'location':
+            print '    GLint program = -1;'
+            print '    glGetIntegerv(GL_CURRENT_PROGRAM, &program);'
+
+        Retracer.extract_arg(self, function, arg, arg_type, lvalue, rvalue)
 
 
 if __name__ == '__main__':
index 5326457e1963b0490260724081203547bdc5fda7..ea2377ccf91c29c4aceb0485515959cbd6868cd3 100644 (file)
@@ -43,6 +43,14 @@ class ConstRemover(stdapi.Rebuilder):
         return stdapi.Opaque(expr)
 
 
+def handle_entry(handle, value):
+    if handle.key is None:
+        return "__%s_map[%s]" % (handle.name, value)
+    else:
+        key_name, key_type = handle.key
+        return "__%s_map[%s][%s]" % (handle.name, key_name, value)
+
+
 class ValueExtractor(stdapi.Visitor):
 
     def visit_literal(self, literal, lvalue, rvalue):
@@ -90,7 +98,7 @@ class ValueExtractor(stdapi.Visitor):
             print '    }'
 
     def visit_handle(self, handle, lvalue, rvalue):
-        self.visit(handle.type, lvalue, "__%s_map[%s]" %(handle.name, rvalue));
+        self.visit(handle.type, lvalue, handle_entry(handle, rvalue));
         print '    if (verbosity >= 2)'
         print '        std::cout << "%s " << static_cast<%s>(%s) << " <- " << %s << "\\n";' % (handle.name, handle.type, rvalue, lvalue)
     
@@ -139,15 +147,20 @@ class ValueWrapper(stdapi.Visitor):
 
     def visit_handle(self, handle, lvalue, rvalue):
         if handle.range is None:
-            print "    __{handle.name}_map[static_cast<{handle.type}>({rvalue})] = {lvalue};".format(**locals())
+            rvalue = "static_cast<%s>(%s)" % (handle.type, rvalue)
+            entry = handle_entry(handle, rvalue) 
+            print "    %s = %s;" % (entry, lvalue)
             print '    if (verbosity >= 2)'
-            print '        std::cout << "{handle.name} " << static_cast<{handle.type}>({rvalue}) << " -> " << {lvalue} << "\\n";'.format(**locals())
+            print '        std::cout << "{handle.name} " << {rvalue} << " -> " << {lvalue} << "\\n";'.format(**locals())
         else:
             i = '__h' + handle.id
+            lvalue = "%s + %s" % (lvalue, i)
+            rvalue = "static_cast<%s>(%s) + %s" % (handle.type, rvalue, i)
+            entry = handle_entry(handle, rvalue) 
             print '    for({handle.type} {i} = 0; {i} < {handle.range}; ++{i}) {{'.format(**locals())
-            print '        __{handle.name}_map[static_cast<{handle.type}>({rvalue}) + {i}] = {lvalue} + {i};'.format(**locals())
+            print '        {entry} = {lvalue};'.format(**locals())
             print '        if (verbosity >= 2)'
-            print '            std::cout << "{handle.name} " << (static_cast<{handle.type}>({rvalue}) + {i}) << " -> " << ({lvalue} + {i}) << "\\n";'.format(**locals())
+            print '            std::cout << "{handle.name} " << ({rvalue}) << " -> " << ({lvalue}) << "\\n";'.format(**locals())
             print '    }'
     
     def visit_blob(self, blob, lvalue, rvalue):
@@ -157,7 +170,6 @@ class ValueWrapper(stdapi.Visitor):
         pass
 
 
-
 class Retracer:
 
     def retrace_function(self, function):
@@ -256,7 +268,11 @@ class Retracer:
         handle_names = set()
         for handle in handles:
             if handle.name not in handle_names:
-                print 'static std::map<%s, %s> __%s_map;' % (handle.type, handle.type, handle.name)
+                if handle.key is None:
+                    print 'static std::map<%s, %s> __%s_map;' % (handle.type, handle.type, handle.name)
+                else:
+                    key_name, key_type = handle.key
+                    print 'static std::map<%s, std::map<%s, %s> > __%s_map;' % (key_type, handle.type, handle.type, handle.name)
                 handle_names.add(handle.name)
         print
 
index 122b89f84821d099c2d6754169a35925161fdea0..79df2c3c837aa1944074b248375bcab265ec571f 100644 (file)
--- a/stdapi.py
+++ b/stdapi.py
@@ -109,11 +109,12 @@ class Pointer(Type):
 
 class Handle(Type):
 
-    def __init__(self, name, type, range=None):
+    def __init__(self, name, type, range=None, key=None):
         Type.__init__(self, type.expr, 'P' + type.id)
         self.name = name
         self.type = type
         self.range = range
+        self.key = key
 
     def visit(self, visitor, *args, **kwargs):
         return visitor.visit_handle(self, *args, **kwargs)
@@ -434,7 +435,7 @@ class Rebuilder(Visitor):
 
     def visit_handle(self, handle):
         type = self.visit(handle.type)
-        return Handle(handle.name, type, handle.range)
+        return Handle(handle.name, type, range=handle.range, key=handle.key)
 
     def visit_alias(self, alias):
         type = self.visit(alias.type)