]> git.cworth.org Git - apitrace/commitdiff
glretrace: swizzle locations into uniform arrays.
authorCass Everitt <cass@xyzw.us>
Thu, 20 Jun 2013 00:30:32 +0000 (19:30 -0500)
committerJosé Fonseca <jfonseca@vmware.com>
Thu, 20 Jun 2013 21:58:34 +0000 (22:58 +0100)
Where slot number is inferred.

Fixes issue #139.

v2: Prevent dereference of end() iterator -- Jose

retrace/retrace.py
retrace/retrace_swizzle.hpp

index aa2036455ebff631451f0c912051f8bcc0973e7d..25fa62a51f4644c7141b9a664c359d9d81ddbed1 100644 (file)
@@ -40,12 +40,15 @@ class UnsupportedType(Exception):
     pass
 
 
-def lookupHandle(handle, value):
+def lookupHandle(handle, value, lval=False):
     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)
+        if handle.name == "location" and lval == False:
+            return "_location_map[%s].lookupUniformLocation(%s)" % (key_name, value)
+        else:
+            return "_%s_map[%s][%s]" % (handle.name, key_name, value)
 
 
 class ValueAllocator(stdapi.Visitor):
@@ -286,7 +289,7 @@ class SwizzledValueRegistrator(stdapi.Visitor, stdapi.ExpanderMixin):
         OpaqueValueDeserializer().visit(handle.type, '_origResult', rvalue);
         if handle.range is None:
             rvalue = "_origResult"
-            entry = lookupHandle(handle, rvalue)
+            entry = lookupHandle(handle, rvalue, True)
             if (entry.startswith('_program_map') or entry.startswith('_shader_map')):
                 print 'if (glretrace::supportsARBShaderObjects) {'
                 print '    _handleARB_map[%s] = %s;' % (rvalue, lvalue)
index 42e5bf6484a344e31f4b80d35cf93c3759a3b23d..f013b6a0697bbf3ba9eb8ab24675d20342c4fdd0 100644 (file)
@@ -74,6 +74,27 @@ public:
         }
         return it->second;
     }
+
+    /*
+     * Handle situations where the application declares an array like
+     *
+     *   uniform vec4 myMatrix[4];
+     *
+     * then calls glGetUniformLocation(..., "myMatrix") and then infer the slot
+     * numbers rather than explicitly calling glGetUniformLocation(...,
+     * "myMatrix[0]"), etc.
+     */
+    T lookupUniformLocation(const T &key) {
+        typename base_type::const_iterator it;
+        it = base.upper_bound(key);
+        if (it != base.begin()) {
+            --it;
+        } else {
+            return (base[key] = key);
+        }
+        T t = it->second + (key - it->first);
+        return t;
+    }
 };
 
 
@@ -100,3 +121,4 @@ toObjPointer(trace::Call &call, trace::Value &value);
 } /* namespace retrace */
 
 #endif /* _RETRACE_SWIZZLE_HPP_ */
+