X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fshaders.c;h=bc76b912913a08083294f7b3917c5112eec70a83;hb=8130375e775bd5ba6a47412b0ea8ec9f23dc5972;hp=f0db0d2a81833c886b81c189637646241c68cc37;hpb=2f1b5ffcda283cebc97bd440b5af44168a9c8b00;p=mesa.git diff --git a/src/mesa/main/shaders.c b/src/mesa/main/shaders.c index f0db0d2a818..bc76b912913 100644 --- a/src/mesa/main/shaders.c +++ b/src/mesa/main/shaders.c @@ -1,6 +1,6 @@ /* * Mesa 3-D graphics library - * Version: 7.1 + * Version: 7.3 * * Copyright (C) 2004-2008 Brian Paul All Rights Reserved. * @@ -233,13 +233,23 @@ _mesa_GetObjectParameterivARB(GLhandleARB object, GLenum pname, GLint *params) GET_CURRENT_CONTEXT(ctx); /* Implement in terms of GetProgramiv, GetShaderiv */ if (ctx->Driver.IsProgram(ctx, object)) { - ctx->Driver.GetProgramiv(ctx, object, pname, params); + if (pname == GL_OBJECT_TYPE_ARB) { + *params = GL_PROGRAM_OBJECT_ARB; + } + else { + ctx->Driver.GetProgramiv(ctx, object, pname, params); + } } else if (ctx->Driver.IsShader(ctx, object)) { - ctx->Driver.GetShaderiv(ctx, object, pname, params); + if (pname == GL_OBJECT_TYPE_ARB) { + *params = GL_SHADER_OBJECT_ARB; + } + else { + ctx->Driver.GetShaderiv(ctx, object, pname, params); + } } else { - _mesa_error(ctx, GL_INVALID_OPERATION, "glGetObjectParameterivARB"); + _mesa_error(ctx, GL_INVALID_VALUE, "glGetObjectParameterivARB"); } } @@ -364,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 @@ -428,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); @@ -577,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 @@ -586,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 @@ -595,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); } @@ -608,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 @@ -617,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 @@ -626,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 @@ -635,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 @@ -644,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 @@ -653,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); }