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:
parent
2eacc4aafa
commit
d42cfa6e6e
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue