From 378bff0eddf004d131a4c83194fb3e83492c4c37 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 12 Aug 2009 13:50:26 -0600 Subject: progs/util: added more shader utility functions --- progs/util/shaderutil.c | 197 +++++++++++++++++++++++++++++++++++++++++++----- progs/util/shaderutil.h | 22 +++++- 2 files changed, 200 insertions(+), 19 deletions(-) (limited to 'progs/util') diff --git a/progs/util/shaderutil.c b/progs/util/shaderutil.c index 13b68d90e0b..bd04ce5c6ad 100644 --- a/progs/util/shaderutil.c +++ b/progs/util/shaderutil.c @@ -9,21 +9,12 @@ #include #include #include +#include #include #include #include "shaderutil.h" -static void -Init(void) -{ - static GLboolean firstCall = GL_TRUE; - if (firstCall) { - firstCall = GL_FALSE; - } -} - - GLboolean ShadersSupported(void) { @@ -47,8 +38,6 @@ CompileShaderText(GLenum shaderType, const char *text) GLuint shader; GLint stat; - Init(); - shader = glCreateShader(shaderType); glShaderSource(shader, 1, (const GLchar **) &text, NULL); glCompileShader(shader); @@ -79,9 +68,6 @@ CompileShaderFile(GLenum shaderType, const char *filename) GLuint shader; FILE *f; - Init(); - - f = fopen(filename, "r"); if (!f) { fprintf(stderr, "Unable to open shader file %s\n", filename); @@ -144,9 +130,6 @@ InitUniforms(GLuint program, struct uniform_info uniforms[]) uniforms[i].location = glGetUniformLocation(program, uniforms[i].name); - printf("Uniform %s location: %d\n", uniforms[i].name, - uniforms[i].location); - switch (uniforms[i].size) { case 1: if (uniforms[i].type == GL_INT) @@ -169,3 +152,181 @@ InitUniforms(GLuint program, struct uniform_info uniforms[]) } } } + + +/** Get list of uniforms used in the program */ +GLuint +GetUniforms(GLuint program, struct uniform_info uniforms[]) +{ + GLint n, max, i; + + glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &n); + glGetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max); + + for (i = 0; i < n; i++) { + GLint size, len; + GLenum type; + char name[100]; + + glGetActiveUniform(program, i, 100, &len, &size, &type, name); + + uniforms[i].name = strdup(name); + switch (type) { + case GL_FLOAT: + size = 1; + type = GL_FLOAT; + break; + case GL_FLOAT_VEC2: + size = 2; + type = GL_FLOAT; + break; + case GL_FLOAT_VEC3: + size = 3; + type = GL_FLOAT; + break; + case GL_FLOAT_VEC4: + size = 4; + type = GL_FLOAT; + break; + case GL_INT: + size = 1; + type = GL_INT; + break; + case GL_INT_VEC2: + size = 2; + type = GL_INT; + break; + case GL_INT_VEC3: + size = 3; + type = GL_INT; + break; + case GL_INT_VEC4: + size = 4; + type = GL_INT; + break; + case GL_FLOAT_MAT3: + /* XXX fix me */ + size = 3; + type = GL_FLOAT; + break; + case GL_FLOAT_MAT4: + /* XXX fix me */ + size = 4; + type = GL_FLOAT; + break; + default: + abort(); + } + uniforms[i].size = size; + uniforms[i].type = type; + uniforms[i].location = glGetUniformLocation(program, name); + } + + uniforms[i].name = NULL; /* end of list */ + + return n; +} + + +void +PrintUniforms(const struct uniform_info uniforms[]) +{ + GLint i; + + printf("Uniforms:\n"); + + for (i = 0; uniforms[i].name; i++) { + printf(" %d: %s size=%d type=0x%x loc=%d value=%g, %g, %g, %g\n", + i, + uniforms[i].name, + uniforms[i].size, + uniforms[i].type, + uniforms[i].location, + uniforms[i].value[0], + uniforms[i].value[1], + uniforms[i].value[2], + uniforms[i].value[3]); + } +} + + +/** Get list of attribs used in the program */ +GLuint +GetAttribs(GLuint program, struct attrib_info attribs[]) +{ + GLint n, max, i; + + glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &n); + glGetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max); + + for (i = 0; i < n; i++) { + GLint size, len; + GLenum type; + char name[100]; + + glGetActiveAttrib(program, i, 100, &len, &size, &type, name); + + attribs[i].name = strdup(name); + switch (type) { + case GL_FLOAT: + size = 1; + type = GL_FLOAT; + break; + case GL_FLOAT_VEC2: + size = 2; + type = GL_FLOAT; + break; + case GL_FLOAT_VEC3: + size = 3; + type = GL_FLOAT; + break; + case GL_FLOAT_VEC4: + size = 4; + type = GL_FLOAT; + break; + case GL_INT: + size = 1; + type = GL_INT; + break; + case GL_INT_VEC2: + size = 2; + type = GL_INT; + break; + case GL_INT_VEC3: + size = 3; + type = GL_INT; + break; + case GL_INT_VEC4: + size = 4; + type = GL_INT; + break; + default: + abort(); + } + attribs[i].size = size; + attribs[i].type = type; + attribs[i].location = glGetAttribLocation(program, name); + } + + attribs[i].name = NULL; /* end of list */ + + return n; +} + + +void +PrintAttribs(const struct attrib_info attribs[]) +{ + GLint i; + + printf("Attribs:\n"); + + for (i = 0; attribs[i].name; i++) { + printf(" %d: %s size=%d type=0x%x loc=%d\n", + i, + attribs[i].name, + attribs[i].size, + attribs[i].type, + attribs[i].location); + } +} diff --git a/progs/util/shaderutil.h b/progs/util/shaderutil.h index cfb8c1f3b06..607ed284915 100644 --- a/progs/util/shaderutil.h +++ b/progs/util/shaderutil.h @@ -6,7 +6,7 @@ struct uniform_info { const char *name; - GLuint size; + GLuint size; /**< number of value[] elements: 1, 2, 3 or 4 */ GLenum type; /**< GL_FLOAT or GL_INT */ GLfloat value[4]; GLint location; /**< filled in by InitUniforms() */ @@ -15,6 +15,15 @@ struct uniform_info #define END_OF_UNIFORMS { NULL, 0, GL_NONE, { 0, 0, 0, 0 }, -1 } +struct attrib_info +{ + const char *name; + GLuint size; /**< number of value[] elements: 1, 2, 3 or 4 */ + GLenum type; /**< GL_FLOAT or GL_INT */ + GLint location; +}; + + extern GLboolean ShadersSupported(void); @@ -30,5 +39,16 @@ LinkShaders(GLuint vertShader, GLuint fragShader); extern void InitUniforms(GLuint program, struct uniform_info uniforms[]); +extern GLuint +GetUniforms(GLuint program, struct uniform_info uniforms[]); + +extern void +PrintUniforms(const struct uniform_info uniforms[]); + +extern GLuint +GetAttribs(GLuint program, struct attrib_info attribs[]); + +extern void +PrintAttribs(const struct attrib_info attribs[]); #endif /* SHADER_UTIL_H */ -- cgit v1.2.3 From 684049d97d423a5a873aefc5313d0c4b22528b95 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 12 Aug 2009 13:53:56 -0600 Subject: demos: rename InitUniforms() to SetUniformValues() And call new PrintUniforms() in demos. --- progs/glsl/brick.c | 3 ++- progs/glsl/bump.c | 3 ++- progs/glsl/mandelbrot.c | 3 ++- progs/glsl/multitex.c | 3 ++- progs/glsl/noise.c | 3 ++- progs/glsl/texdemo1.c | 3 ++- progs/glsl/toyball.c | 3 ++- progs/util/shaderutil.c | 2 +- progs/util/shaderutil.h | 2 +- 9 files changed, 16 insertions(+), 9 deletions(-) (limited to 'progs/util') diff --git a/progs/glsl/brick.c b/progs/glsl/brick.c index 1d08b231e7e..e5f5c96607d 100644 --- a/progs/glsl/brick.c +++ b/progs/glsl/brick.c @@ -148,7 +148,8 @@ Init(void) glUseProgram(program); - InitUniforms(program, Uniforms); + SetUniformValues(program, Uniforms); + PrintUniforms(Uniforms); assert(glGetError() == 0); diff --git a/progs/glsl/bump.c b/progs/glsl/bump.c index ddb986abcb5..29af26f7a1f 100644 --- a/progs/glsl/bump.c +++ b/progs/glsl/bump.c @@ -242,7 +242,8 @@ Init(void) CheckError(__LINE__); - InitUniforms(program, Uniforms); + SetUniformValues(program, Uniforms); + PrintUniforms(Uniforms); CheckError(__LINE__); diff --git a/progs/glsl/mandelbrot.c b/progs/glsl/mandelbrot.c index 38dffc3e741..09c65d2c2b7 100644 --- a/progs/glsl/mandelbrot.c +++ b/progs/glsl/mandelbrot.c @@ -159,7 +159,8 @@ Init(void) glUseProgram(program); - InitUniforms(program, Uniforms); + SetUniformValues(program, Uniforms); + PrintUniforms(Uniforms); uZoom = glGetUniformLocation(program, "Zoom"); uXcenter = glGetUniformLocation(program, "Xcenter"); diff --git a/progs/glsl/multitex.c b/progs/glsl/multitex.c index a4a8bbe38fa..ce79bc1b4d5 100644 --- a/progs/glsl/multitex.c +++ b/progs/glsl/multitex.c @@ -328,7 +328,8 @@ CreateProgram(const char *vertProgFile, const char *fragProgFile, glUseProgram(program); - InitUniforms(program, uniforms); + SetUniformValues(program, uniforms); + PrintUniforms(Uniforms); VertCoord_attr = glGetAttribLocation(program, "VertCoord"); if (VertCoord_attr > 0) { diff --git a/progs/glsl/noise.c b/progs/glsl/noise.c index 59f594e78bf..6ef2a80f78d 100644 --- a/progs/glsl/noise.c +++ b/progs/glsl/noise.c @@ -179,7 +179,8 @@ Init(void) glUseProgram(program); - InitUniforms(program, Uniforms); + SetUniformValues(program, Uniforms); + PrintUniforms(Uniforms); assert(glGetError() == 0); diff --git a/progs/glsl/texdemo1.c b/progs/glsl/texdemo1.c index d55f9e7dd97..f0dce8555e7 100644 --- a/progs/glsl/texdemo1.c +++ b/progs/glsl/texdemo1.c @@ -382,7 +382,8 @@ CreateProgram(const char *vertProgFile, const char *fragProgFile, glUseProgram(program); - InitUniforms(program, uniforms); + SetUniformValues(program, uniforms); + PrintUniforms(uniforms); return program; } diff --git a/progs/glsl/toyball.c b/progs/glsl/toyball.c index 7fe27aebfe6..13f57766844 100644 --- a/progs/glsl/toyball.c +++ b/progs/glsl/toyball.c @@ -173,7 +173,8 @@ Init(void) glUseProgram(program); - InitUniforms(program, Uniforms); + SetUniformValues(program, Uniforms); + PrintUniforms(Uniforms); assert(glGetError() == 0); diff --git a/progs/util/shaderutil.c b/progs/util/shaderutil.c index bd04ce5c6ad..f057adf5c73 100644 --- a/progs/util/shaderutil.c +++ b/progs/util/shaderutil.c @@ -122,7 +122,7 @@ LinkShaders(GLuint vertShader, GLuint fragShader) void -InitUniforms(GLuint program, struct uniform_info uniforms[]) +SetUniformValues(GLuint program, struct uniform_info uniforms[]) { GLuint i; diff --git a/progs/util/shaderutil.h b/progs/util/shaderutil.h index 607ed284915..22dc4dc4319 100644 --- a/progs/util/shaderutil.h +++ b/progs/util/shaderutil.h @@ -37,7 +37,7 @@ extern GLuint LinkShaders(GLuint vertShader, GLuint fragShader); extern void -InitUniforms(GLuint program, struct uniform_info uniforms[]); +SetUniformValues(GLuint program, struct uniform_info uniforms[]); extern GLuint GetUniforms(GLuint program, struct uniform_info uniforms[]); -- cgit v1.2.3 From fdfb0d4b0e04bff2f3dbae2d1f8e3765fb4b0dce Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 12 Aug 2009 17:25:49 -0600 Subject: progs/glsl: change uniform_info::type field to use GLSL vector types --- progs/glsl/brick.c | 10 ++--- progs/glsl/bump.c | 10 ++--- progs/glsl/mandelbrot.c | 8 ++-- progs/glsl/multitex.c | 4 +- progs/glsl/noise.c | 4 +- progs/glsl/texdemo1.c | 8 ++-- progs/glsl/toyball.c | 24 +++++------ progs/glsl/vert-tex.c | 2 +- progs/tests/floattex.c | 2 +- progs/util/shaderutil.c | 107 +++++++----------------------------------------- progs/util/shaderutil.h | 4 +- 11 files changed, 53 insertions(+), 130 deletions(-) (limited to 'progs/util') diff --git a/progs/glsl/brick.c b/progs/glsl/brick.c index e5f5c96607d..0653c592e53 100644 --- a/progs/glsl/brick.c +++ b/progs/glsl/brick.c @@ -24,12 +24,12 @@ static GLuint program; static struct uniform_info Uniforms[] = { /* vert */ - { "LightPosition", 3, GL_FLOAT, { 0.1, 0.1, 9.0, 0}, -1 }, + { "LightPosition", 1, GL_FLOAT_VEC3, { 0.1, 0.1, 9.0, 0}, -1 }, /* frag */ - { "BrickColor", 3, GL_FLOAT, { 0.8, 0.2, 0.2, 0 }, -1 }, - { "MortarColor", 3, GL_FLOAT, { 0.6, 0.6, 0.6, 0 }, -1 }, - { "BrickSize", 2, GL_FLOAT, { 1.0, 0.3, 0, 0 }, -1 }, - { "BrickPct", 2, GL_FLOAT, { 0.9, 0.8, 0, 0 }, -1 }, + { "BrickColor", 1, GL_FLOAT_VEC3, { 0.8, 0.2, 0.2, 0 }, -1 }, + { "MortarColor", 1, GL_FLOAT_VEC3, { 0.6, 0.6, 0.6, 0 }, -1 }, + { "BrickSize", 1, GL_FLOAT_VEC2, { 1.0, 0.3, 0, 0 }, -1 }, + { "BrickPct", 1, GL_FLOAT_VEC2, { 0.9, 0.8, 0, 0 }, -1 }, END_OF_UNIFORMS }; diff --git a/progs/glsl/bump.c b/progs/glsl/bump.c index 29af26f7a1f..c0d39c049d3 100644 --- a/progs/glsl/bump.c +++ b/progs/glsl/bump.c @@ -24,11 +24,11 @@ static GLuint program; static struct uniform_info Uniforms[] = { - { "LightPosition", 3, GL_FLOAT, { 0.57737, 0.57735, 0.57735, 0.0 }, -1 }, - { "SurfaceColor", 3, GL_FLOAT, { 0.8, 0.8, 0.2, 0 }, -1 }, - { "BumpDensity", 1, GL_FLOAT, { 10.0, 0, 0, 0 }, -1 }, - { "BumpSize", 1, GL_FLOAT, { 0.125, 0, 0, 0 }, -1 }, - { "SpecularFactor", 1, GL_FLOAT, { 0.5, 0, 0, 0 }, -1 }, + { "LightPosition", 1, GL_FLOAT_VEC3, { 0.57737, 0.57735, 0.57735, 0.0 }, -1 }, + { "SurfaceColor", 1, GL_FLOAT_VEC3, { 0.8, 0.8, 0.2, 0 }, -1 }, + { "BumpDensity", 1, GL_FLOAT, { 10.0, 0, 0, 0 }, -1 }, + { "BumpSize", 1, GL_FLOAT, { 0.125, 0, 0, 0 }, -1 }, + { "SpecularFactor", 1, GL_FLOAT, { 0.5, 0, 0, 0 }, -1 }, END_OF_UNIFORMS }; diff --git a/progs/glsl/mandelbrot.c b/progs/glsl/mandelbrot.c index 09c65d2c2b7..729a6f125a8 100644 --- a/progs/glsl/mandelbrot.c +++ b/progs/glsl/mandelbrot.c @@ -25,7 +25,7 @@ static GLuint program; static struct uniform_info Uniforms[] = { /* vert */ - { "LightPosition", 3, GL_FLOAT, { 0.1, 0.1, 9.0, 0}, -1 }, + { "LightPosition", 1, GL_FLOAT_VEC3, { 0.1, 0.1, 9.0, 0}, -1 }, { "SpecularContribution", 1, GL_FLOAT, { 0.5, 0, 0, 0 }, -1 }, { "DiffuseContribution", 1, GL_FLOAT, { 0.5, 0, 0, 0 }, -1 }, { "Shininess", 1, GL_FLOAT, { 20.0, 0, 0, 0 }, -1 }, @@ -34,9 +34,9 @@ static struct uniform_info Uniforms[] = { { "Zoom", 1, GL_FLOAT, { 0.125, 0, 0, 0 }, -1 }, { "Xcenter", 1, GL_FLOAT, { -1.5, 0, 0, 0 }, -1 }, { "Ycenter", 1, GL_FLOAT, { .005, 0, 0, 0 }, -1 }, - { "InnerColor", 3, GL_FLOAT, { 1, 0, 0, 0 }, -1 }, - { "OuterColor1", 3, GL_FLOAT, { 0, 1, 0, 0 }, -1 }, - { "OuterColor2", 3, GL_FLOAT, { 0, 0, 1, 0 }, -1 }, + { "InnerColor", 1, GL_FLOAT_VEC3, { 1, 0, 0, 0 }, -1 }, + { "OuterColor1", 1, GL_FLOAT_VEC3, { 0, 1, 0, 0 }, -1 }, + { "OuterColor2", 1, GL_FLOAT_VEC3, { 0, 0, 1, 0 }, -1 }, END_OF_UNIFORMS }; diff --git a/progs/glsl/multitex.c b/progs/glsl/multitex.c index ce79bc1b4d5..6ec9c833e67 100644 --- a/progs/glsl/multitex.c +++ b/progs/glsl/multitex.c @@ -59,8 +59,8 @@ static GLint VertCoord_attr = -1, TexCoord0_attr = -1, TexCoord1_attr = -1; /* value[0] = tex unit */ static struct uniform_info Uniforms[] = { - { "tex1", 1, GL_INT, { 0, 0, 0, 0 }, -1 }, - { "tex2", 1, GL_INT, { 1, 0, 0, 0 }, -1 }, + { "tex1", 1, GL_SAMPLER_2D, { 0, 0, 0, 0 }, -1 }, + { "tex2", 1, GL_SAMPLER_2D, { 1, 0, 0, 0 }, -1 }, END_OF_UNIFORMS }; diff --git a/progs/glsl/noise.c b/progs/glsl/noise.c index 6ef2a80f78d..8c36e1c59b0 100644 --- a/progs/glsl/noise.c +++ b/progs/glsl/noise.c @@ -35,8 +35,8 @@ static const char *FragShaderText = static struct uniform_info Uniforms[] = { - { "Scale", 4, GL_FLOAT, { 0.5, 0.4, 0.0, 0}, -1 }, - { "Bias", 4, GL_FLOAT, { 0.5, 0.3, 0.0, 0}, -1 }, + { "Scale", 1, GL_FLOAT_VEC4, { 0.5, 0.4, 0.0, 0}, -1 }, + { "Bias", 1, GL_FLOAT_VEC4, { 0.5, 0.3, 0.0, 0}, -1 }, { "Slice", 1, GL_FLOAT, { 0.5, 0, 0, 0}, -1 }, END_OF_UNIFORMS }; diff --git a/progs/glsl/texdemo1.c b/progs/glsl/texdemo1.c index f0dce8555e7..5b1913a722b 100644 --- a/progs/glsl/texdemo1.c +++ b/progs/glsl/texdemo1.c @@ -53,14 +53,14 @@ static int win = 0; static struct uniform_info ReflectUniforms[] = { - { "cubeTex", 1, GL_INT, { 0, 0, 0, 0 }, -1 }, - { "lightPos", 3, GL_FLOAT, { 10, 10, 20, 0 }, -1 }, + { "cubeTex", 1, GL_SAMPLER_CUBE, { 0, 0, 0, 0 }, -1 }, + { "lightPos", 1, GL_FLOAT_VEC3, { 10, 10, 20, 0 }, -1 }, END_OF_UNIFORMS }; static struct uniform_info SimpleUniforms[] = { - { "tex2d", 1, GL_INT, { 1, 0, 0, 0 }, -1 }, - { "lightPos", 3, GL_FLOAT, { 10, 10, 20, 0 }, -1 }, + { "tex2d", 1, GL_SAMPLER_2D, { 1, 0, 0, 0 }, -1 }, + { "lightPos", 1, GL_FLOAT_VEC3, { 10, 10, 20, 0 }, -1 }, END_OF_UNIFORMS }; diff --git a/progs/glsl/toyball.c b/progs/glsl/toyball.c index 13f57766844..89733d6175f 100644 --- a/progs/glsl/toyball.c +++ b/progs/glsl/toyball.c @@ -24,18 +24,18 @@ static GLuint program; static struct uniform_info Uniforms[] = { - { "LightDir", 4, GL_FLOAT, { 0.57737, 0.57735, 0.57735, 0.0 }, -1 }, - { "HVector", 4, GL_FLOAT, { 0.32506, 0.32506, 0.88808, 0.0 }, -1 }, - { "BallCenter", 4, GL_FLOAT, { 0.0, 0.0, 0.0, 1.0 }, -1 }, - { "SpecularColor", 4, GL_FLOAT, { 0.4, 0.4, 0.4, 60.0 }, -1 }, - { "Red", 4, GL_FLOAT, { 0.6, 0.0, 0.0, 1.0 }, -1 }, - { "Blue", 4, GL_FLOAT, { 0.0, 0.3, 0.6, 1.0 }, -1 }, - { "Yellow", 4, GL_FLOAT, { 0.6, 0.5, 0.0, 1.0 }, -1 }, - { "HalfSpace0", 4, GL_FLOAT, { 1.0, 0.0, 0.0, 0.2 }, -1 }, - { "HalfSpace1", 4, GL_FLOAT, { 0.309016994, 0.951056516, 0.0, 0.2 }, -1 }, - { "HalfSpace2", 4, GL_FLOAT, { -0.809016994, 0.587785252, 0.0, 0.2 }, -1 }, - { "HalfSpace3", 4, GL_FLOAT, { -0.809016994, -0.587785252, 0.0, 0.2 }, -1 }, - { "HalfSpace4", 4, GL_FLOAT, { 0.309116994, -0.951056516, 0.0, 0.2 }, -1 }, + { "LightDir", 1, GL_FLOAT_VEC4, { 0.57737, 0.57735, 0.57735, 0.0 }, -1 }, + { "HVector", 1, GL_FLOAT_VEC4, { 0.32506, 0.32506, 0.88808, 0.0 }, -1 }, + { "BallCenter", 1, GL_FLOAT_VEC4, { 0.0, 0.0, 0.0, 1.0 }, -1 }, + { "SpecularColor", 1, GL_FLOAT_VEC4, { 0.4, 0.4, 0.4, 60.0 }, -1 }, + { "Red", 1, GL_FLOAT_VEC4, { 0.6, 0.0, 0.0, 1.0 }, -1 }, + { "Blue", 1, GL_FLOAT_VEC4, { 0.0, 0.3, 0.6, 1.0 }, -1 }, + { "Yellow", 1, GL_FLOAT_VEC4, { 0.6, 0.5, 0.0, 1.0 }, -1 }, + { "HalfSpace0", 1, GL_FLOAT_VEC4, { 1.0, 0.0, 0.0, 0.2 }, -1 }, + { "HalfSpace1", 1, GL_FLOAT_VEC4, { 0.309016994, 0.951056516, 0.0, 0.2 }, -1 }, + { "HalfSpace2", 1, GL_FLOAT_VEC4, { -0.809016994, 0.587785252, 0.0, 0.2 }, -1 }, + { "HalfSpace3", 1, GL_FLOAT_VEC4, { -0.809016994, -0.587785252, 0.0, 0.2 }, -1 }, + { "HalfSpace4", 1, GL_FLOAT_VEC4, { 0.309116994, -0.951056516, 0.0, 0.2 }, -1 }, { "InOrOutInit", 1, GL_FLOAT, { -3.0, 0, 0, 0 }, -1 }, { "StripeWidth", 1, GL_FLOAT, { 0.3, 0, 0, 0 }, -1 }, { "FWidth", 1, GL_FLOAT, { 0.005, 0, 0, 0 }, -1 }, diff --git a/progs/glsl/vert-tex.c b/progs/glsl/vert-tex.c index e791a5759a7..4c8bfa587aa 100644 --- a/progs/glsl/vert-tex.c +++ b/progs/glsl/vert-tex.c @@ -43,7 +43,7 @@ static GLfloat xRot = -70.0f, yRot = 0.0f, zRot = 0.0f; /* value[0] = tex unit */ static struct uniform_info Uniforms[] = { - { "tex1", 1, GL_INT, { 0, 0, 0, 0 }, -1 }, + { "tex1", 1, GL_SAMPLER_2D, { 0, 0, 0, 0 }, -1 }, END_OF_UNIFORMS }; diff --git a/progs/tests/floattex.c b/progs/tests/floattex.c index e6b7658150c..39302ce3aff 100644 --- a/progs/tests/floattex.c +++ b/progs/tests/floattex.c @@ -33,7 +33,7 @@ static const char *VertShaderText = "} \n"; static struct uniform_info Uniforms[] = { - { "tex1", 1, GL_INT, { 0, 0, 0, 0 }, -1 }, + { "tex1", 1, GL_SAMPLER_2D, { 0, 0, 0, 0 }, -1 }, END_OF_UNIFORMS }; diff --git a/progs/util/shaderutil.c b/progs/util/shaderutil.c index f057adf5c73..233252112a6 100644 --- a/progs/util/shaderutil.c +++ b/progs/util/shaderutil.c @@ -130,21 +130,26 @@ SetUniformValues(GLuint program, struct uniform_info uniforms[]) uniforms[i].location = glGetUniformLocation(program, uniforms[i].name); - switch (uniforms[i].size) { - case 1: - if (uniforms[i].type == GL_INT) - glUniform1i(uniforms[i].location, - (GLint) uniforms[i].value[0]); - else - glUniform1fv(uniforms[i].location, 1, uniforms[i].value); + switch (uniforms[i].type) { + case GL_INT: + case GL_SAMPLER_1D: + case GL_SAMPLER_2D: + case GL_SAMPLER_3D: + case GL_SAMPLER_CUBE: + case GL_SAMPLER_2D_RECT_ARB: + glUniform1i(uniforms[i].location, + (GLint) uniforms[i].value[0]); + break; + case GL_FLOAT: + glUniform1fv(uniforms[i].location, 1, uniforms[i].value); break; - case 2: + case GL_FLOAT_VEC2: glUniform2fv(uniforms[i].location, 1, uniforms[i].value); break; - case 3: + case GL_FLOAT_VEC3: glUniform3fv(uniforms[i].location, 1, uniforms[i].value); break; - case 4: + case GL_FLOAT_VEC4: glUniform4fv(uniforms[i].location, 1, uniforms[i].value); break; default: @@ -171,52 +176,6 @@ GetUniforms(GLuint program, struct uniform_info uniforms[]) glGetActiveUniform(program, i, 100, &len, &size, &type, name); uniforms[i].name = strdup(name); - switch (type) { - case GL_FLOAT: - size = 1; - type = GL_FLOAT; - break; - case GL_FLOAT_VEC2: - size = 2; - type = GL_FLOAT; - break; - case GL_FLOAT_VEC3: - size = 3; - type = GL_FLOAT; - break; - case GL_FLOAT_VEC4: - size = 4; - type = GL_FLOAT; - break; - case GL_INT: - size = 1; - type = GL_INT; - break; - case GL_INT_VEC2: - size = 2; - type = GL_INT; - break; - case GL_INT_VEC3: - size = 3; - type = GL_INT; - break; - case GL_INT_VEC4: - size = 4; - type = GL_INT; - break; - case GL_FLOAT_MAT3: - /* XXX fix me */ - size = 3; - type = GL_FLOAT; - break; - case GL_FLOAT_MAT4: - /* XXX fix me */ - size = 4; - type = GL_FLOAT; - break; - default: - abort(); - } uniforms[i].size = size; uniforms[i].type = type; uniforms[i].location = glGetUniformLocation(program, name); @@ -267,42 +226,6 @@ GetAttribs(GLuint program, struct attrib_info attribs[]) glGetActiveAttrib(program, i, 100, &len, &size, &type, name); attribs[i].name = strdup(name); - switch (type) { - case GL_FLOAT: - size = 1; - type = GL_FLOAT; - break; - case GL_FLOAT_VEC2: - size = 2; - type = GL_FLOAT; - break; - case GL_FLOAT_VEC3: - size = 3; - type = GL_FLOAT; - break; - case GL_FLOAT_VEC4: - size = 4; - type = GL_FLOAT; - break; - case GL_INT: - size = 1; - type = GL_INT; - break; - case GL_INT_VEC2: - size = 2; - type = GL_INT; - break; - case GL_INT_VEC3: - size = 3; - type = GL_INT; - break; - case GL_INT_VEC4: - size = 4; - type = GL_INT; - break; - default: - abort(); - } attribs[i].size = size; attribs[i].type = type; attribs[i].location = glGetAttribLocation(program, name); diff --git a/progs/util/shaderutil.h b/progs/util/shaderutil.h index 22dc4dc4319..0a6be026759 100644 --- a/progs/util/shaderutil.h +++ b/progs/util/shaderutil.h @@ -7,7 +7,7 @@ struct uniform_info { const char *name; GLuint size; /**< number of value[] elements: 1, 2, 3 or 4 */ - GLenum type; /**< GL_FLOAT or GL_INT */ + GLenum type; /**< GL_FLOAT, GL_FLOAT_VEC4, GL_INT, etc */ GLfloat value[4]; GLint location; /**< filled in by InitUniforms() */ }; @@ -19,7 +19,7 @@ struct attrib_info { const char *name; GLuint size; /**< number of value[] elements: 1, 2, 3 or 4 */ - GLenum type; /**< GL_FLOAT or GL_INT */ + GLenum type; /**< GL_FLOAT, GL_FLOAT_VEC4, GL_INT, etc */ GLint location; }; -- cgit v1.2.3 From 741869d73aa8c9d0d9ae8f1c4ca2df32e235960a Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 13 Aug 2009 12:53:20 -0600 Subject: progs/util: ignore pre-defined uniforms in SetUniformValues() --- progs/util/shaderutil.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'progs/util') diff --git a/progs/util/shaderutil.c b/progs/util/shaderutil.c index 233252112a6..489e71cc30c 100644 --- a/progs/util/shaderutil.c +++ b/progs/util/shaderutil.c @@ -153,7 +153,14 @@ SetUniformValues(GLuint program, struct uniform_info uniforms[]) glUniform4fv(uniforms[i].location, 1, uniforms[i].value); break; default: - abort(); + if (strncmp(uniforms[i].name, "gl_", 3) == 0) { + /* built-in uniform: ignore */ + } + else { + fprintf(stderr, + "Unexpected uniform data type in SetUniformValues\n"); + abort(); + } } } } -- cgit v1.2.3