Mesa (master): vpglsl: add some simple tests with function calls

Zack Rusin zack at kemper.freedesktop.org
Fri May 14 21:53:38 PDT 2010


Module: Mesa
Branch: master
Commit: b93fa7e2e807271dd51b9c4ec47b2f86311a61a8
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b93fa7e2e807271dd51b9c4ec47b2f86311a61a8

Author: Zack Rusin <zack at kde.org>
Date:   Sat May 15 00:58:02 2010 -0400

vpglsl: add some simple tests with function calls

---

 progs/vpglsl/func.glsl  |   33 ++++++++++++++++++++++++++++
 progs/vpglsl/func2.glsl |   54 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/progs/vpglsl/func.glsl b/progs/vpglsl/func.glsl
new file mode 100644
index 0000000..0553988
--- /dev/null
+++ b/progs/vpglsl/func.glsl
@@ -0,0 +1,33 @@
+#version 120
+const int KernelSize = 16;
+uniform float KernelValue1f[KernelSize];
+
+
+float add_two(float a, float b)
+{
+    if (a > b)
+        return a - b;
+    else
+        return a + b;
+}
+
+vec4 func(vec4 x)
+{
+    int i;
+    vec4 tmp = gl_Color;
+    vec4 sum = x;
+
+    for (i = 0; i < KernelSize; ++i) {
+        sum = vec4( add_two(sum.x, KernelValue1f[i]) );
+    }
+    return sum;
+}
+
+void main(void)
+{
+    vec4 sum = vec4(0.0);
+
+    sum = func(sum);
+    gl_Position = gl_Vertex;
+    gl_FrontColor = sum;
+}
diff --git a/progs/vpglsl/func2.glsl b/progs/vpglsl/func2.glsl
new file mode 100644
index 0000000..df964ed
--- /dev/null
+++ b/progs/vpglsl/func2.glsl
@@ -0,0 +1,54 @@
+#version 120
+const int KernelSize = 16;
+uniform float KernelValue1f[KernelSize];
+
+
+float add_two(float a, float b)
+{
+    if (a > b)
+        return a - b;
+    else
+        return a + b;
+}
+
+vec4 myfunc(vec4 x, vec4 mult, vec4 c)
+{
+   if (x.x >= 0.5) {
+      return mult * c;
+   } else {
+      return mult + c;
+   }
+}
+
+vec4 func2(vec4 x)
+{
+    int i;
+    vec4 color = vec4(0);
+       for (i = 0; i < KernelSize; ++i) {
+           vec4 tmp = vec4(1./KernelSize);
+           color += myfunc(x, tmp, gl_Color);
+       }
+    return x * color;
+}
+
+vec4 func(vec4 x)
+{
+    int i;
+    vec4 tmp = gl_Color;
+    vec4 sum = x;
+
+    for (i = 0; i < KernelSize; ++i) {
+        sum = vec4( add_two(sum.x, KernelValue1f[i]) );
+    }
+    sum = func2(sum);
+    return sum;
+}
+
+void main(void)
+{
+    vec4 sum = vec4(0.0);
+
+    sum = func(sum);
+    gl_Position = gl_Vertex;
+    gl_FrontColor = sum;
+}



More information about the mesa-commit mailing list