From d42cfa6e6ea458a3eb05310d4c25acc777820fea Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 6 Mar 2009 15:55:33 -0700 Subject: mesa: added _mesa_read_shader() function to read shaders from files Useful for debugging to override an application's shader. --- src/mesa/main/shaders.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'src/mesa/main/shaders.c') diff --git a/src/mesa/main/shaders.c b/src/mesa/main/shaders.c index 7491d00c35..be93b45a7d 100644 --- a/src/mesa/main/shaders.c +++ b/src/mesa/main/shaders.c @@ -374,6 +374,43 @@ _mesa_LinkProgramARB(GLhandleARB programObj) } + +/** + * Read shader source code from a file. + * Useful for debugging to override an app's shader. + */ +static GLcharARB * +_mesa_read_shader(const char *fname) +{ + const int max = 50*1000; + FILE *f = fopen(fname, "r"); + GLcharARB *buffer, *shader; + int len; + + if (!f) { + _mesa_fprintf(stderr, "Unable to open shader file %s\n", fname); + return NULL; + } + + buffer = (char *) malloc(max); + len = fread(buffer, 1, max, f); + buffer[len] = 0; + + fclose(f); + + shader = _mesa_strdup(buffer); + free(buffer); + + if (0) { + _mesa_fprintf(stderr, "Read shader %s:\n", fname); + _mesa_fprintf(stderr, "%s\n", shader); + } + + return shader; +} + + + /** * Called via glShaderSource() and glShaderSourceARB() API functions. * Basically, concatenate the source code strings into one long string @@ -438,6 +475,20 @@ _mesa_ShaderSourceARB(GLhandleARB shaderObj, GLsizei count, source[totalLength - 1] = '\0'; source[totalLength - 2] = '\0'; +#if 0 + if (0) { + GLcharARB *newSource; + + newSource = _mesa_read_shader("newshader.frag"); + if (newSource) { + _mesa_free(source); + source = newSource; + } + } +#else + (void) _mesa_read_shader; +#endif + ctx->Driver.ShaderSource(ctx, shaderObj, source); _mesa_free(offsets); -- cgit v1.2.3 From 0115a4f8f1952b166eaad09f317ff8bc465e0f28 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 14 Apr 2009 20:00:28 -0600 Subject: mesa: remove unused matrixType param from ctx->Driver.UniformMatrix() functions --- src/mesa/main/dd.h | 2 +- src/mesa/main/shaders.c | 27 +++++++++------------------ src/mesa/shader/shader_api.c | 2 +- 3 files changed, 11 insertions(+), 20 deletions(-) (limited to 'src/mesa/main/shaders.c') diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h index d994401e55..32b1d4e9fa 100644 --- a/src/mesa/main/dd.h +++ b/src/mesa/main/dd.h @@ -911,7 +911,7 @@ struct dd_function_table { void (*Uniform)(GLcontext *ctx, GLint location, GLsizei count, const GLvoid *values, GLenum type); void (*UniformMatrix)(GLcontext *ctx, GLint cols, GLint rows, - GLenum matrixType, GLint location, GLsizei count, + GLint location, GLsizei count, GLboolean transpose, const GLfloat *values); void (*UseProgram)(GLcontext *ctx, GLuint program); void (*ValidateProgram)(GLcontext *ctx, GLuint program); diff --git a/src/mesa/main/shaders.c b/src/mesa/main/shaders.c index be93b45a7d..bc76b91291 100644 --- a/src/mesa/main/shaders.c +++ b/src/mesa/main/shaders.c @@ -638,8 +638,7 @@ _mesa_UniformMatrix2fvARB(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) { GET_CURRENT_CONTEXT(ctx); - ctx->Driver.UniformMatrix(ctx, 2, 2, GL_FLOAT_MAT2, - location, count, transpose, value); + ctx->Driver.UniformMatrix(ctx, 2, 2, location, count, transpose, value); } void GLAPIENTRY @@ -647,8 +646,7 @@ _mesa_UniformMatrix3fvARB(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) { GET_CURRENT_CONTEXT(ctx); - ctx->Driver.UniformMatrix(ctx, 3, 3, GL_FLOAT_MAT3, - location, count, transpose, value); + ctx->Driver.UniformMatrix(ctx, 3, 3, location, count, transpose, value); } void GLAPIENTRY @@ -656,8 +654,7 @@ _mesa_UniformMatrix4fvARB(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) { GET_CURRENT_CONTEXT(ctx); - ctx->Driver.UniformMatrix(ctx, 4, 4, GL_FLOAT_MAT4, - location, count, transpose, value); + ctx->Driver.UniformMatrix(ctx, 4, 4, location, count, transpose, value); } @@ -669,8 +666,7 @@ _mesa_UniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { GET_CURRENT_CONTEXT(ctx); - ctx->Driver.UniformMatrix(ctx, 2, 3, GL_FLOAT_MAT2x3, - location, count, transpose, value); + ctx->Driver.UniformMatrix(ctx, 2, 3, location, count, transpose, value); } void GLAPIENTRY @@ -678,8 +674,7 @@ _mesa_UniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { GET_CURRENT_CONTEXT(ctx); - ctx->Driver.UniformMatrix(ctx, 3, 2, GL_FLOAT_MAT3x2, - location, count, transpose, value); + ctx->Driver.UniformMatrix(ctx, 3, 2, location, count, transpose, value); } void GLAPIENTRY @@ -687,8 +682,7 @@ _mesa_UniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { GET_CURRENT_CONTEXT(ctx); - ctx->Driver.UniformMatrix(ctx, 2, 4, GL_FLOAT_MAT2x4, - location, count, transpose, value); + ctx->Driver.UniformMatrix(ctx, 2, 4, location, count, transpose, value); } void GLAPIENTRY @@ -696,8 +690,7 @@ _mesa_UniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { GET_CURRENT_CONTEXT(ctx); - ctx->Driver.UniformMatrix(ctx, 4, 2, GL_FLOAT_MAT4x2, - location, count, transpose, value); + ctx->Driver.UniformMatrix(ctx, 4, 2, location, count, transpose, value); } void GLAPIENTRY @@ -705,8 +698,7 @@ _mesa_UniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { GET_CURRENT_CONTEXT(ctx); - ctx->Driver.UniformMatrix(ctx, 3, 4, GL_FLOAT_MAT3x4, - location, count, transpose, value); + ctx->Driver.UniformMatrix(ctx, 3, 4, location, count, transpose, value); } void GLAPIENTRY @@ -714,8 +706,7 @@ _mesa_UniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { GET_CURRENT_CONTEXT(ctx); - ctx->Driver.UniformMatrix(ctx, 4, 3, GL_FLOAT_MAT4x3, - location, count, transpose, value); + ctx->Driver.UniformMatrix(ctx, 4, 3, location, count, transpose, value); } diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c index 75e38960e9..9038f7d1de 100644 --- a/src/mesa/shader/shader_api.c +++ b/src/mesa/shader/shader_api.c @@ -1897,7 +1897,7 @@ set_program_uniform_matrix(GLcontext *ctx, struct gl_program *program, */ static void _mesa_uniform_matrix(GLcontext *ctx, GLint cols, GLint rows, - GLenum matrixType, GLint location, GLsizei count, + GLint location, GLsizei count, GLboolean transpose, const GLfloat *values) { struct gl_shader_program *shProg = ctx->Shader.CurrentProgram; -- cgit v1.2.3