gallium: check vertex shaders for samplers/texture usage as we do for fragment shaders
[mesa.git] / src / mesa / state_tracker / st_atom_sampler.c
index 3ba6a971f6f1dbdd1ec109d956f6f7b213b87f9c..d7b904354f2e402e800109ece15a6d56a85c22ca 100644 (file)
@@ -35,6 +35,7 @@
 #include "main/macros.h"
 
 #include "st_context.h"
+#include "st_cb_texture.h"
 #include "st_atom.h"
 #include "st_program.h"
 #include "pipe/p_context.h"
@@ -120,7 +121,10 @@ gl_filter_to_img_filter(GLenum filter)
 static void 
 update_samplers(struct st_context *st)
 {
-   const struct st_fragment_program *fs = st->fp;
+   struct gl_vertex_program *vprog = st->ctx->VertexProgram._Current;
+   struct gl_fragment_program *fprog = st->ctx->FragmentProgram._Current;
+   const GLbitfield samplersUsed = (vprog->Base.SamplersUsed |
+                                    fprog->Base.SamplersUsed);
    GLuint su;
 
    st->state.num_samplers = 0;
@@ -131,13 +135,19 @@ update_samplers(struct st_context *st)
 
       memset(sampler, 0, sizeof(*sampler));
 
-      if (fs->Base.Base.SamplersUsed & (1 << su)) {
-         GLuint texUnit = fs->Base.Base.SamplerUnits[su];
-         const struct gl_texture_object *texobj
-            = st->ctx->Texture.Unit[texUnit]._Current;
+      if (samplersUsed & (1 << su)) {
+         struct gl_texture_object *texobj;
+         GLuint texUnit;
 
-         if (!texobj)
-            continue;
+         if (fprog->Base.SamplersUsed & (1 << su))
+            texUnit = fprog->Base.SamplerUnits[su];
+         else
+            texUnit = vprog->Base.SamplerUnits[su];
+
+         texobj = st->ctx->Texture.Unit[texUnit]._Current;
+         if (!texobj) {
+            texobj = st_get_default_texture(st);
+         }
 
          sampler->wrap_s = gl_wrap_to_sp(texobj->WrapS);
          sampler->wrap_t = gl_wrap_to_sp(texobj->WrapT);
@@ -184,11 +194,11 @@ update_samplers(struct st_context *st)
 
          st->state.num_samplers = su + 1;
 
-         /* XXX more sampler state here */
-
+         /*printf("%s su=%u non-null\n", __FUNCTION__, su);*/
          cso_single_sampler(st->cso_context, su, sampler);
       }
       else {
+         /*printf("%s su=%u null\n", __FUNCTION__, su);*/
          cso_single_sampler(st->cso_context, su, NULL);
       }
    }