texture_builtins.py: Refactor coordinate dimension calculations.
authorKenneth Graunke <kenneth@whitecape.org>
Mon, 27 Dec 2010 10:50:42 +0000 (02:50 -0800)
committerKenneth Graunke <kenneth@whitecape.org>
Mon, 31 Jan 2011 19:10:59 +0000 (11:10 -0800)
For offsets, we'll want the straight sampler dimensionality, without the
+1 for array types.  Create a new function to do that; refactor.

src/glsl/builtins/tools/texture_builtins.py

index d7ac4d3e85a2892cccf1ef00c002c949d56f3db8..63401eabe4c4531eb5d67c3d518984e80b1e7381 100755 (executable)
@@ -12,16 +12,20 @@ def vec_type(g, size):
         return "float"
     return g + "vec" + str(size)
 
-# Get the base dimension - i.e. sampler3D gives 3
-# Array samplers also get +1 here since the layer is really an extra coordinate
-def get_coord_dim(sampler_type):
+# Get the sampler dimension - i.e. sampler3D gives 3
+def get_sampler_dim(sampler_type):
     if sampler_type[0].isdigit():
-        coord_dim = int(sampler_type[0])
+        sampler_dim = int(sampler_type[0])
     elif sampler_type.startswith("Cube"):
-        coord_dim = 3
+        sampler_dim = 3
     else:
         assert False ("coord_dim: invalid sampler_type: " + sampler_type)
+    return sampler_dim
 
+# Get the coordinate dimension for a given sampler type.
+# Array samplers also get +1 here since the layer is really an extra coordinate
+def get_coord_dim(sampler_type):
+    coord_dim = get_sampler_dim(sampler_type)
     if sampler_type.find("Array") != -1:
         coord_dim += 1
     return coord_dim