Don't spend time iterating samplers after we know we've set them up.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 19 Jul 2009 16:23:39 -0400
changeset 757 29b25b4c7aeb
parent 756 9e06e970a730
child 758 f25ef1cca5e2
Don't spend time iterating samplers after we know we've set them up.
mojoshader_opengl.c
--- a/mojoshader_opengl.c	Fri Apr 17 04:15:47 2009 -0400
+++ b/mojoshader_opengl.c	Sun Jul 19 16:23:39 2009 -0400
@@ -82,6 +82,7 @@
     MOJOSHADER_glShader *vertex;
     MOJOSHADER_glShader *fragment;
     GLuint handle;
+    int must_set_samplers;
     uint32 uniform_count;
     UniformMap *uniforms;
     uint32 sampler_count;
@@ -1330,6 +1331,10 @@
     retval->fragment = pshader;
     retval->refcount = 1;
 
+    // we set the samplers on first call to MOJOSHADER_glProgramReady(), even
+    //  though it's only done once, so we don't have to bind the program here.
+    retval->must_set_samplers = 1;
+
     if (vshader != NULL)
     {
         if (vshader->parseData->attribute_count > 0)
@@ -1662,21 +1667,23 @@
         } // if
     } // for
 
-    // push Samplers to the program from our register files...
-    // !!! FIXME: just push these once at link time...they never change, since
-    // !!! FIXME:  they are meant to be constant texture unit ids and not
-    // !!! FIXME:  textures.
-    count = ctx->bound_program->sampler_count;
-    for (i = 0; i < count; i++)
+    // Link up the Samplers. These never change after link time, since they
+    //  are meant to be constant texture unit ids and not textures.
+    if (ctx->bound_program->must_set_samplers)
     {
-        SamplerMap *map = &ctx->bound_program->samplers[i];
-        const MOJOSHADER_sampler *s = map->sampler;
-        if (s->index != map->value)
+        count = ctx->bound_program->sampler_count;
+        for (i = 0; i < count; i++)
         {
-            map->value = s->index;
-            ctx->profileSetSampler(map->location, s->index);
-        } // if
-    } // for
+            SamplerMap *map = &ctx->bound_program->samplers[i];
+            const MOJOSHADER_sampler *s = map->sampler;
+            if (s->index != map->value)
+            {
+                map->value = s->index;
+                ctx->profileSetSampler(map->location, s->index);
+            } // if
+        } // for
+        ctx->bound_program->must_set_samplers = 0;  // it's done!
+    } // if
 } // MOJOSHADER_glProgramReady