add some glsl example testing different arrays of uniforms
authorZack Rusin <zack@tungstengraphics.com>
Thu, 12 Jun 2008 04:04:30 +0000 (00:04 -0400)
committerZack Rusin <zack@tungstengraphics.com>
Thu, 12 Jun 2008 18:15:37 +0000 (14:15 -0400)
progs/vpglsl/off2f.glsl [new file with mode: 0644]
progs/vpglsl/varfor1f.glsl [new file with mode: 0644]
progs/vpglsl/varfor2f.glsl [new file with mode: 0644]
progs/vpglsl/varfor4f.glsl [new file with mode: 0644]
progs/vpglsl/vp-tris.c

diff --git a/progs/vpglsl/off2f.glsl b/progs/vpglsl/off2f.glsl
new file mode 100644 (file)
index 0000000..e06cb42
--- /dev/null
@@ -0,0 +1,18 @@
+const int KernelSize = 8;
+uniform vec2 Offset2f[KernelSize];
+uniform vec4 KernelValue4f[KernelSize];
+
+void main(void)
+{
+    int i;
+    vec4 sum = vec4(0.0);
+    vec4 tmp = gl_Color;
+    vec2 rg, ba;
+    gl_Position = gl_Vertex;
+
+    rg = Offset2f[4];
+    ba = Offset2f[5];
+
+
+    gl_FrontColor = KernelValue4f[0] * vec4(rg, ba);
+}
diff --git a/progs/vpglsl/varfor1f.glsl b/progs/vpglsl/varfor1f.glsl
new file mode 100644 (file)
index 0000000..9c3e8f2
--- /dev/null
@@ -0,0 +1,22 @@
+const int KernelSize = 16;
+uniform float KernelValue1f[KernelSize];
+
+void main(void)
+{
+    int i;
+    vec4 sum = vec4(0.0);
+    vec4 tmp = gl_Color;
+    gl_Position = gl_Vertex;
+
+    for (i = 0; i < KernelSize; ++i) {
+        float x, y, z, w;
+
+        x = KernelValue1f[i]; ++i;
+        y = KernelValue1f[i]; ++i;
+        z = KernelValue1f[i]; ++i;
+        w = KernelValue1f[i];
+
+        sum += tmp * vec4(x, y, z, w);
+    }
+    gl_FrontColor = sum;
+}
diff --git a/progs/vpglsl/varfor2f.glsl b/progs/vpglsl/varfor2f.glsl
new file mode 100644 (file)
index 0000000..d98a110
--- /dev/null
@@ -0,0 +1,24 @@
+const int KernelSize = 9;
+uniform vec2 KernelValue2f[KernelSize];
+
+void main(void)
+{
+    int i;
+    vec4 sum = vec4(0.0);
+    vec4 tmp = gl_Color;
+    gl_Position = gl_Vertex;
+
+    for (i = 0; i < KernelSize; ++i) {
+        vec2 rg, ba;
+
+        rg = KernelValue2f[i];
+        ++i;
+        if (i < KernelSize)
+           ba = KernelValue2f[i];
+       else
+           ba = vec2(0, 0);
+
+        sum += tmp * vec4(rg, ba);
+    }
+    gl_FrontColor = sum;
+}
diff --git a/progs/vpglsl/varfor4f.glsl b/progs/vpglsl/varfor4f.glsl
new file mode 100644 (file)
index 0000000..c70ba03
--- /dev/null
@@ -0,0 +1,19 @@
+const int KernelSize = 4;
+uniform vec4 KernelValue4f[KernelSize];
+
+void main(void)
+{
+    int i;
+    vec4 sum = vec4(0.0);
+    vec4 tmp = gl_Color;
+    gl_Position = gl_Vertex;
+
+    for (i = 0; i < KernelSize; ++i) {
+        vec4 rgba;
+
+        rgba = KernelValue4f[i];
+
+        sum += tmp * rgba;
+    }
+    gl_FrontColor = sum;
+}
index 3c2830773a3d6998c7ba633807691bfcd1257fc0..9108d3f1978f5f9dbe2fd8e5b9b972d43ab180c0 100644 (file)
@@ -76,6 +76,52 @@ static void check_link(GLuint prog)
    }
 }
 
+static void setup_uniforms()
+{
+   {
+      GLuint loc1f = glGetUniformLocationARB(program, "Offset1f");
+      GLuint loc2f = glGetUniformLocationARB(program, "Offset2f");
+      GLuint loc4f = glGetUniformLocationARB(program, "Offset4f");
+      GLfloat vecKer[] =
+         { 1.0, 0.0, 0.0,  1.0,
+           0.0, 1.0, 0.0,  1.0,
+           1.0, 0.0, 0.0,  1.0,
+           0.0, 0.0, 0.0,  1.0
+         };
+      if (loc1f >= 0)
+         glUniform1fv(loc1f, 16, vecKer);
+
+      if (loc2f >= 0)
+         glUniform2fv(loc2f, 8, vecKer);
+
+      if (loc4f >= 0)
+         glUniform4fv(loc4f, 4, vecKer);
+
+   }
+
+   GLuint loc1f = glGetUniformLocationARB(program, "KernelValue1f");
+   GLuint loc2f = glGetUniformLocationARB(program, "KernelValue2f");
+   GLuint loc4f = glGetUniformLocationARB(program, "KernelValue4f");
+   GLfloat vecKer[] =
+      { 1.0, 0.0, 0.0,  0.25,
+        0.0, 1.0, 0.0,  0.25,
+        0.0, 0.0, 1.0,  0.25,
+        0.0, 0.0, 0.0,  0.25,
+        0.5, 0.0, 0.0,  0.35,
+        0.0, 0.5, 0.0,  0.35,
+        0.0, 0.0, 0.5,  0.35,
+        0.0, 0.0, 0.0,  0.35
+      };
+   if (loc1f >= 0)
+      glUniform1fv(loc1f, 16, vecKer);
+
+   if (loc2f >= 0)
+      glUniform2fv(loc2f, 8, vecKer);
+
+   if (loc4f >= 0)
+      glUniform4fv(loc4f, 4, vecKer);
+}
+
 static void prepare_shaders()
 {
    static const char *fragShaderText =
@@ -103,6 +149,8 @@ static void prepare_shaders()
    glLinkProgram(program);
    check_link(program);
    glUseProgram(program);
+
+   setup_uniforms();
 }
 
 static void args(int argc, char *argv[])