Mesa (gallium-0.2): mesa: add new samplers_array test

Alan Hourihane alanh at kemper.freedesktop.org
Wed Jan 14 17:01:52 UTC 2009


Module: Mesa
Branch: gallium-0.2
Commit: e82784559e00cb534993c01309ad1832e9b3e56b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=e82784559e00cb534993c01309ad1832e9b3e56b

Author: Alan Hourihane <alanh at vmware.com>
Date:   Wed Jan 14 17:01:16 2009 +0000

mesa: add new samplers_array test

---

 progs/glsl/Makefile   |    6 ++++++
 progs/glsl/samplers.c |   12 ++++++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile
index a39170b..7099eea 100644
--- a/progs/glsl/Makefile
+++ b/progs/glsl/Makefile
@@ -24,6 +24,7 @@ PROGS = \
 	points \
 	pointcoord \
 	samplers \
+	samplers_array \
 	skinning \
 	texdemo1 \
 	toyball \
@@ -166,6 +167,11 @@ samplers.o: samplers.c readtex.h extfuncs.h shaderutil.h
 samplers: samplers.o readtex.o shaderutil.o
 	$(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) samplers.o readtex.o shaderutil.o $(LIBS) -o $@
 
+samplers_array.o: samplers.c readtex.h extfuncs.h shaderutil.h
+	$(APP_CC) -c -DSAMPLERS_ARRAY -I$(INCDIR) $(CFLAGS) samplers.c -o samplers_array.o
+
+samplers_array: samplers_array.o readtex.o shaderutil.o
+	$(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) samplers_array.o readtex.o shaderutil.o $(LIBS) -o $@
 
 skinning.o: skinning.c readtex.h extfuncs.h shaderutil.h
 	$(APP_CC) -c -I$(INCDIR) $(CFLAGS) skinning.c
diff --git a/progs/glsl/samplers.c b/progs/glsl/samplers.c
index d214009..3fb8577 100644
--- a/progs/glsl/samplers.c
+++ b/progs/glsl/samplers.c
@@ -245,14 +245,22 @@ GenFragmentShader(GLint numSamplers)
    int s;
 
    p += sprintf(p, "// Generated fragment shader:\n");
+#ifndef SAMPLERS_ARRAY
    for (s = 0; s < numSamplers; s++) {
       p += sprintf(p, "uniform sampler2D tex%d;\n", s);
    }
+#else
+   p += sprintf(p, "uniform sampler2D tex[%d];\n", numSamplers);
+#endif
    p += sprintf(p, "void main()\n");
    p += sprintf(p, "{\n");
    p += sprintf(p, "   vec4 color = vec4(0.0);\n");
    for (s = 0; s < numSamplers; s++) {
+#ifndef SAMPLERS_ARRAY
       p += sprintf(p, "   color += texture2D(tex%d, gl_TexCoord[0].xy);\n", s);
+#else
+      p += sprintf(p, "   color += texture2D(tex[%d], gl_TexCoord[0].xy);\n", s);
+#endif
    }
    p += sprintf(p, "   gl_FragColor = color;\n");
    p += sprintf(p, "}\n");
@@ -302,7 +310,11 @@ InitProgram(void)
       char uname[10];
       GLint loc;
 
+#ifndef SAMPLERS_ARRAY
       sprintf(uname, "tex%d", s);
+#else
+      sprintf(uname, "tex[%d]", s);
+#endif
       loc = glGetUniformLocation_func(Program, uname);
       assert(loc >= 0);
 




More information about the mesa-commit mailing list