mesa: added _mesa_read_shader() function to read shaders from files

Useful for debugging to override an application's shader.
This commit is contained in:
Brian Paul 2009-03-06 15:55:33 -07:00
parent 2eacc4aafa
commit d42cfa6e6e
1 changed files with 51 additions and 0 deletions

View File

@ -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);