Merge commit 'origin/master' into gallium-sampler-view
[mesa.git] / src / mesa / state_tracker / st_atom_texture.c
index 1ec671ed48fc9b436e356604f85751dad508bb7f..241c001f94fa5b865876e83d8f45c0aee28cdb13 100644 (file)
   */
  
 
+#include "main/macros.h"
+
 #include "st_context.h"
 #include "st_atom.h"
 #include "st_texture.h"
 #include "st_cb_texture.h"
 #include "pipe/p_context.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
 #include "cso_cache/cso_context.h"
 
 
 static void 
 update_textures(struct st_context *st)
 {
+   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_textures = 0;
 
-   for (su = 0; su < st->ctx->Const.MaxTextureCoordUnits; su++) {
-      struct pipe_texture *pt = NULL;
+   /* loop over sampler units (aka tex image units) */
+   for (su = 0; su < st->ctx->Const.MaxTextureImageUnits; su++) {
+      struct pipe_sampler_view *sampler_view = NULL;
 
-      if (fprog->Base.SamplersUsed & (1 << su)) {
-         const GLuint texUnit = fprog->Base.SamplerUnits[su];
-         struct gl_texture_object *texObj
-            = st->ctx->Texture.Unit[texUnit]._Current;
-         struct st_texture_object *stObj = st_texture_object(texObj);
+      if (samplersUsed & (1 << su)) {
+         struct gl_texture_object *texObj;
+         struct st_texture_object *stObj;
+         GLboolean flush, retval;
+         GLuint texUnit;
 
-         if (texObj) {
-            GLboolean flush, retval;
+         if (fprog->Base.SamplersUsed & (1 << su))
+            texUnit = fprog->Base.SamplerUnits[su];
+         else
+            texUnit = vprog->Base.SamplerUnits[su];
 
-            retval = st_finalize_texture(st->ctx, st->pipe, texObj, &flush);
-            if (!retval) {
-               /* out of mem */
-               /* missing texture */
-               continue;
-            }
+         texObj = st->ctx->Texture.Unit[texUnit]._Current;
+
+         if (!texObj) {
+            texObj = st_get_default_texture(st);
+         }
+         stObj = st_texture_object(texObj);
 
-            st->state.num_textures = su + 1;
+         retval = st_finalize_texture(st->ctx, st->pipe, texObj, &flush);
+         if (!retval) {
+            /* out of mem */
+            continue;
          }
 
-         pt = st_get_stobj_texture(stObj);
+         st->state.num_textures = su + 1;
+
+         sampler_view = st_get_stobj_sampler_view(stObj);
       }
 
-      pipe_texture_reference(&st->state.sampler_texture[su], pt);
+      /*
+      if (pt) {
+         printf("%s su=%u non-null\n", __FUNCTION__, su);
+      }
+      else {
+         printf("%s su=%u null\n", __FUNCTION__, su);
+      }
+      */
+
+      pipe_sampler_view_reference(&st->state.sampler_views[su], sampler_view);
    }
 
-   cso_set_sampler_textures(st->cso_context,
-                            st->state.num_textures,
-                            st->state.sampler_texture);
+   cso_set_fragment_sampler_views(st->cso_context,
+                                  st->state.num_textures,
+                                  st->state.sampler_views);
+   if (st->ctx->Const.MaxVertexTextureImageUnits > 0) {
+      cso_set_vertex_sampler_views(st->cso_context,
+                                   MIN2(st->state.num_textures,
+                                        st->ctx->Const.MaxVertexTextureImageUnits),
+                                   st->state.sampler_views);
+   }
 }