From: Brian Paul Date: Fri, 6 Mar 2009 22:55:33 +0000 (-0700) Subject: mesa: added _mesa_read_shader() function to read shaders from files X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d42cfa6e6ea458a3eb05310d4c25acc777820fea;p=mesa.git mesa: added _mesa_read_shader() function to read shaders from files Useful for debugging to override an application's shader. --- diff --git a/src/mesa/main/shaders.c b/src/mesa/main/shaders.c index 7491d00c357..be93b45a7da 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);