gallium/identity: consolidate sampler, sampler_view code
authorBrian Paul <brianp@vmware.com>
Fri, 10 Aug 2012 02:59:44 +0000 (20:59 -0600)
committerBrian Paul <brianp@vmware.com>
Thu, 16 Aug 2012 15:01:31 +0000 (09:01 -0600)
This will simplify things when the pipe_context functions are consolidated.

src/gallium/drivers/identity/id_context.c

index 794e62ca1f2f06063854fadd33c85a73df1858ae..026793484db2a184609195b3e8f254413452ec14 100644 (file)
@@ -158,17 +158,37 @@ identity_create_sampler_state(struct pipe_context *_pipe,
                                      sampler);
 }
 
+static void
+identity_bind_sampler_states(struct pipe_context *_pipe,
+                             unsigned shader,
+                             unsigned num_samplers,
+                             void **samplers)
+{
+   struct identity_context *id_pipe = identity_context(_pipe);
+   struct pipe_context *pipe = id_pipe->pipe;
+
+   switch (shader) {
+   case PIPE_SHADER_VERTEX:
+      pipe->bind_vertex_sampler_states(pipe, num_samplers, samplers);
+      break;
+   case PIPE_SHADER_GEOMETRY:
+      pipe->bind_geometry_sampler_states(pipe, num_samplers, samplers);
+      break;
+   case PIPE_SHADER_FRAGMENT:
+      pipe->bind_fragment_sampler_states(pipe, num_samplers, samplers);
+      break;
+   default:
+      debug_error("Unexpected shader in identity_bind_sampler_states()");
+   }
+}
+
 static void
 identity_bind_fragment_sampler_states(struct pipe_context *_pipe,
                                       unsigned num_samplers,
                                       void **samplers)
 {
-   struct identity_context *id_pipe = identity_context(_pipe);
-   struct pipe_context *pipe = id_pipe->pipe;
-
-   pipe->bind_fragment_sampler_states(pipe,
-                                      num_samplers,
-                                      samplers);
+   identity_bind_sampler_states(_pipe, PIPE_SHADER_FRAGMENT,
+                                num_samplers, samplers);
 }
 
 static void
@@ -176,12 +196,8 @@ identity_bind_vertex_sampler_states(struct pipe_context *_pipe,
                                     unsigned num_samplers,
                                     void **samplers)
 {
-   struct identity_context *id_pipe = identity_context(_pipe);
-   struct pipe_context *pipe = id_pipe->pipe;
-
-   pipe->bind_vertex_sampler_states(pipe,
-                                    num_samplers,
-                                    samplers);
+   identity_bind_sampler_states(_pipe, PIPE_SHADER_VERTEX,
+                                num_samplers, samplers);
 }
 
 static void
@@ -488,9 +504,10 @@ identity_set_viewport_state(struct pipe_context *_pipe,
 }
 
 static void
-identity_set_fragment_sampler_views(struct pipe_context *_pipe,
-                                    unsigned num,
-                                    struct pipe_sampler_view **_views)
+identity_set_sampler_views(struct pipe_context *_pipe,
+                           unsigned shader,
+                           unsigned num,
+                           struct pipe_sampler_view **_views)
 {
    struct identity_context *id_pipe = identity_context(_pipe);
    struct pipe_context *pipe = id_pipe->pipe;
@@ -507,7 +524,27 @@ identity_set_fragment_sampler_views(struct pipe_context *_pipe,
       views = unwrapped_views;
    }
 
-   pipe->set_fragment_sampler_views(pipe, num, views);
+   switch (shader) {
+   case PIPE_SHADER_VERTEX:
+      pipe->set_vertex_sampler_views(pipe, num, views);
+      break;
+   case PIPE_SHADER_GEOMETRY:
+      pipe->set_geometry_sampler_views(pipe, num, views);
+      break;
+   case PIPE_SHADER_FRAGMENT:
+      pipe->set_fragment_sampler_views(pipe, num, views);
+      break;
+   default:
+      debug_error("Unexpected shader in identity_set_sampler_views()");
+   }
+}
+
+static void
+identity_set_fragment_sampler_views(struct pipe_context *_pipe,
+                                    unsigned num,
+                                    struct pipe_sampler_view **_views)
+{
+   identity_set_sampler_views(_pipe, PIPE_SHADER_FRAGMENT, num, _views);
 }
 
 static void
@@ -515,22 +552,7 @@ identity_set_vertex_sampler_views(struct pipe_context *_pipe,
                                   unsigned num,
                                   struct pipe_sampler_view **_views)
 {
-   struct identity_context *id_pipe = identity_context(_pipe);
-   struct pipe_context *pipe = id_pipe->pipe;
-   struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS];
-   struct pipe_sampler_view **views = NULL;
-   unsigned i;
-
-   if (_views) {
-      for (i = 0; i < num; i++)
-         unwrapped_views[i] = identity_sampler_view_unwrap(_views[i]);
-      for (; i < Elements(unwrapped_views); i++)
-         unwrapped_views[i] = NULL;
-
-      views = unwrapped_views;
-   }
-
-   pipe->set_vertex_sampler_views(pipe, num, views);
+   identity_set_sampler_views(_pipe, PIPE_SHADER_VERTEX, num, _views);
 }
 
 static void