summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2009-03-06 15:55:33 -0700
committerBrian Paul <brianp@vmware.com>2009-03-06 16:21:21 -0700
commitd42cfa6e6ea458a3eb05310d4c25acc777820fea (patch)
treec7ad72f9372bda888052101636f295548bdcca52 /src
parent2eacc4aafaa1a00135255f6025e82102dd4adbaa (diff)
mesa: added _mesa_read_shader() function to read shaders from files
Useful for debugging to override an application's shader.
Diffstat (limited to 'src')
-rw-r--r--src/mesa/main/shaders.c51
1 files changed, 51 insertions, 0 deletions
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);