mojoshader_opengl.c
changeset 774 9ac0e5ad0205
parent 773 3e3638be6e2b
child 775 2c93dcb14687
--- a/mojoshader_opengl.c	Thu Aug 13 22:29:33 2009 -0400
+++ b/mojoshader_opengl.c	Thu Aug 13 22:51:40 2009 -0400
@@ -68,6 +68,7 @@
     MOJOSHADER_glShader *vertex;
     MOJOSHADER_glShader *fragment;
     GLuint handle;
+    uint32 generation;
     uint32 uniform_count;
     UniformMap *uniforms;
     uint32 attribute_count;
@@ -127,6 +128,9 @@
     uint8 ps_reg_file_b[MAX_REG_FILE_B];
     GLuint sampler_reg_file[16];
 
+    // This increments every time we change the register files.
+    uint32 generation;
+
     // GL stuff...
     int opengl_major;
     int opengl_minor;
@@ -1485,6 +1489,7 @@
     retval->handle = program;
     retval->vertex = vshader;
     retval->fragment = pshader;
+    retval->generation = ctx->generation - 1;
     retval->refcount = 1;
 
     if (vshader != NULL)
@@ -1597,6 +1602,7 @@
         assert(sizeof (GLfloat) == sizeof (float));
         const uint cpy = (minuint(maxregs - idx, vec4n) * sizeof (*data)) * 4;
         memcpy(ctx->vs_reg_file_f + (idx * 4), data, cpy);
+        ctx->generation++;
     } // if
 } // MOJOSHADER_glSetVertexShaderUniformF
 
@@ -1610,6 +1616,7 @@
         assert(sizeof (GLint) == sizeof (int));
         const uint cpy = (minuint(maxregs - idx, ivec4n) * sizeof (*data)) * 4;
         memcpy(ctx->vs_reg_file_i + (idx * 4), data, cpy);
+        ctx->generation++;
     } // if
 } // MOJOSHADER_glSetVertexShaderUniformI
 
@@ -1624,6 +1631,7 @@
         uint8 *endptr = wptr + minuint(maxregs - idx, bcount);
         while (wptr != endptr)
             *(wptr++) = *(data++) ? 1 : 0;
+        ctx->generation++;
     } // if
 } // MOJOSHADER_glSetVertexShaderUniformB
 
@@ -1637,6 +1645,7 @@
         assert(sizeof (GLfloat) == sizeof (float));
         const uint cpy = (minuint(maxregs - idx, vec4n) * sizeof (*data)) * 4;
         memcpy(ctx->ps_reg_file_f + (idx * 4), data, cpy);
+        ctx->generation++;
     } // if
 } // MOJOSHADER_glSetPixelShaderUniformF
 
@@ -1650,6 +1659,7 @@
         assert(sizeof (GLint) == sizeof (int));
         const uint cpy = (minuint(maxregs - idx, ivec4n) * sizeof (*data)) * 4;
         memcpy(ctx->ps_reg_file_i + (idx * 4), data, cpy);
+        ctx->generation++;
     } // if
 } // MOJOSHADER_glSetPixelShaderUniformI
 
@@ -1664,6 +1674,7 @@
         uint8 *endptr = wptr + minuint(maxregs - idx, bcount);
         while (wptr != endptr)
             *(wptr++) = *(data++) ? 1 : 0;
+        ctx->generation++;
     } // if
 } // MOJOSHADER_glSetPixelShaderUniformB
 
@@ -1739,13 +1750,13 @@
 
 void MOJOSHADER_glProgramReady(void)
 {
-    const MOJOSHADER_glProgram *program = ctx->bound_program;
+    MOJOSHADER_glProgram *program = ctx->bound_program;
 
     if (program == NULL)
         return;  // nothing to do.
 
     // push Uniforms to the program from our register files...
-    if (program->uniform_count > 0)
+    if ((program->uniform_count) && (program->generation != ctx->generation))
     {
         // vertex shader uniforms come first in program->uniforms array.
         const uint32 count = program->uniform_count;
@@ -1758,6 +1769,8 @@
         GLint *dstb = program->vs_uniforms_bool;
         uint32 i;
 
+        program->generation = ctx->generation;
+
         for (i = 0; i < count; i++)
         {
             UniformMap *map = &program->uniforms[i];