Merge branch '7.8'
[mesa.git] / src / mesa / state_tracker / st_texture.h
index 60868ce06738917d7c32665b489f70c4b40cd4a1..c62f7f2cc0d172834e519f3bddee0a72c08e5c35 100644 (file)
@@ -29,6 +29,9 @@
 #define ST_TEXTURE_H
 
 
+#include "pipe/p_context.h"
+#include "util/u_sampler.h"
+
 #include "main/mtypes.h"
 
 struct pipe_context;
@@ -68,6 +71,13 @@ struct st_texture_object
     */
    struct pipe_texture *pt;
 
+   /* Default sampler view attached to this texture object. Created lazily
+    * on first binding.
+    */
+   struct pipe_sampler_view *sampler_view;
+
+   struct pipe_context *pipe;
+
    GLboolean teximage_realloc;
 
    /* True if there is/was a surface bound to this texture object.  It helps
@@ -105,6 +115,35 @@ st_get_stobj_texture(struct st_texture_object *stObj)
 }
 
 
+static INLINE struct pipe_sampler_view *
+st_sampler_view_from_texture(struct pipe_context *pipe,
+                             struct pipe_texture *texture)
+{
+   struct pipe_sampler_view templ;
+
+   u_sampler_view_default_template(&templ,
+                                   texture,
+                                   texture->format);
+
+   return pipe->create_sampler_view(pipe, texture, &templ);
+}
+
+
+static INLINE struct pipe_sampler_view *
+st_get_stobj_sampler_view(struct st_texture_object *stObj)
+{
+   if (!stObj || !stObj->pt) {
+      return NULL;
+   }
+
+   if (!stObj->sampler_view) {
+      stObj->sampler_view = st_sampler_view_from_texture(stObj->pipe, stObj->pt);
+   }
+
+   return stObj->sampler_view;
+}
+
+
 extern struct pipe_texture *
 st_texture_create(struct st_context *st,
                   enum pipe_texture_target target,