summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/shaders.c
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2009-10-29 08:28:52 -0600
committerBrian Paul <[email protected]>2009-10-29 10:50:26 -0600
commitc89f5b6ac86d46af4f0311fa76db6186825fbf1e (patch)
tree8062259f8a35486fe201908ffc856d83f71de0e4 /src/mesa/main/shaders.c
parent41892e9b17e4e252ce1e73bc2dbc9d24eb13001b (diff)
glsl: make shader substitution a little better
Diffstat (limited to 'src/mesa/main/shaders.c')
-rw-r--r--src/mesa/main/shaders.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/mesa/main/shaders.c b/src/mesa/main/shaders.c
index 96fd8695a59..d0dc7e551c9 100644
--- a/src/mesa/main/shaders.c
+++ b/src/mesa/main/shaders.c
@@ -26,6 +26,12 @@
#include "glheader.h"
#include "context.h"
#include "shaders.h"
+#include "shader/shader_api.h"
+
+
+/** Define this to enable shader substitution (see below) */
+#define SHADER_SUBST 0
+
/**
@@ -404,7 +410,6 @@ _mesa_read_shader(const char *fname)
}
-
/**
* Called via glShaderSource() and glShaderSourceARB() API functions.
* Basically, concatenate the source code strings into one long string
@@ -418,6 +423,7 @@ _mesa_ShaderSourceARB(GLhandleARB shaderObj, GLsizei count,
GLint *offsets;
GLsizei i, totalLength;
GLcharARB *source;
+ GLuint checksum;
if (!shaderObj || string == NULL) {
_mesa_error(ctx, GL_INVALID_VALUE, "glShaderSourceARB");
@@ -469,15 +475,16 @@ _mesa_ShaderSourceARB(GLhandleARB shaderObj, GLsizei count,
source[totalLength - 1] = '\0';
source[totalLength - 2] = '\0';
- if (0) {
+ if (SHADER_SUBST) {
/* Compute the shader's source code checksum then try to open a file
* named newshader_<CHECKSUM>. If it exists, use it in place of the
* original shader source code. For debugging.
*/
- const GLuint checksum = _mesa_str_checksum(source);
char filename[100];
GLcharARB *newSource;
+ checksum = _mesa_str_checksum(source);
+
sprintf(filename, "newshader_%d", checksum);
newSource = _mesa_read_shader(filename);
@@ -491,6 +498,12 @@ _mesa_ShaderSourceARB(GLhandleARB shaderObj, GLsizei count,
ctx->Driver.ShaderSource(ctx, shaderObj, source);
+ if (SHADER_SUBST) {
+ struct gl_shader *sh = _mesa_lookup_shader(ctx, shaderObj);
+ if (sh)
+ sh->SourceChecksum = checksum; /* save original checksum */
+ }
+
_mesa_free(offsets);
}