[PATCH 4/8] wined3d: Introduce wined3d_sampler_bind() helper function.

Józef Kucia jkucia at codeweavers.com
Mon Mar 20 06:13:06 CDT 2017


Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
 dlls/wined3d/context.c         | 16 ++++------------
 dlls/wined3d/sampler.c         | 21 +++++++++++++++++++++
 dlls/wined3d/view.c            |  7 ++++++-
 dlls/wined3d/wined3d_private.h |  7 +++++--
 4 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index baba979..c1803a4 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -3394,14 +3394,12 @@ static void context_bind_shader_resources(struct wined3d_context *context,
         const struct wined3d_state *state, enum wined3d_shader_type shader_type)
 {
     unsigned int bind_idx, shader_sampler_count, base, count, i;
-    const struct wined3d_gl_info *gl_info = context->gl_info;
     const struct wined3d_device *device = context->device;
     struct wined3d_shader_sampler_map_entry *entry;
     struct wined3d_shader_resource_view *view;
     const struct wined3d_shader *shader;
     struct wined3d_sampler *sampler;
     const DWORD *tex_unit_map;
-    GLuint sampler_name;
 
     if (!(shader = state->shader[shader_type]))
         return;
@@ -3429,16 +3427,10 @@ static void context_bind_shader_resources(struct wined3d_context *context,
         }
 
         if (entry->sampler_idx == WINED3D_SAMPLER_DEFAULT)
-            sampler_name = device->default_sampler->name;
-        else if ((sampler = state->sampler[shader_type][entry->sampler_idx]))
-            sampler_name = sampler->name;
-        else
-            sampler_name = device->null_sampler->name;
-
-        context_active_texture(context, gl_info, bind_idx);
-        GL_EXTCALL(glBindSampler(bind_idx, sampler_name));
-        checkGLcall("glBindSampler");
-        wined3d_shader_resource_view_bind(view, context);
+            sampler = device->default_sampler;
+        else if (!(sampler = state->sampler[shader_type][entry->sampler_idx]))
+            sampler = device->null_sampler;
+        wined3d_shader_resource_view_bind(view, bind_idx, sampler, context);
     }
 }
 
diff --git a/dlls/wined3d/sampler.c b/dlls/wined3d/sampler.c
index a987a35..c1364c2 100644
--- a/dlls/wined3d/sampler.c
+++ b/dlls/wined3d/sampler.c
@@ -150,3 +150,24 @@ HRESULT CDECL wined3d_sampler_create(struct wined3d_device *device, const struct
 
     return WINED3D_OK;
 }
+
+/* This function relies on the correct texture being bound and loaded. */
+void wined3d_sampler_bind(struct wined3d_sampler *sampler, unsigned int unit,
+        struct wined3d_texture *texture, const struct wined3d_context *context)
+{
+    const struct wined3d_gl_info *gl_info = context->gl_info;
+
+    if (gl_info->supported[ARB_SAMPLER_OBJECTS])
+    {
+        GL_EXTCALL(glBindSampler(unit, sampler->name));
+        checkGLcall("bind sampler");
+    }
+    else if (texture)
+    {
+        wined3d_texture_apply_sampler_desc(texture, &sampler->desc, context);
+    }
+    else
+    {
+        ERR("Could not apply sampler state.\n");
+    }
+}
diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c
index ff31de2..ac558a4 100644
--- a/dlls/wined3d/view.c
+++ b/dlls/wined3d/view.c
@@ -638,13 +638,17 @@ HRESULT CDECL wined3d_shader_resource_view_create(const struct wined3d_view_desc
 }
 
 void wined3d_shader_resource_view_bind(struct wined3d_shader_resource_view *view,
-        struct wined3d_context *context)
+        unsigned int unit, struct wined3d_sampler *sampler, struct wined3d_context *context)
 {
+    const struct wined3d_gl_info *gl_info = context->gl_info;
     struct wined3d_texture *texture;
 
+    context_active_texture(context, gl_info, unit);
+
     if (view->gl_view.name)
     {
         context_bind_texture(context, view->gl_view.target, view->gl_view.name);
+        wined3d_sampler_bind(sampler, unit, NULL, context);
         return;
     }
 
@@ -656,6 +660,7 @@ void wined3d_shader_resource_view_bind(struct wined3d_shader_resource_view *view
 
     texture = wined3d_texture_from_resource(view->resource);
     wined3d_texture_bind(texture, context, FALSE);
+    wined3d_sampler_bind(sampler, unit, texture, context);
 }
 
 ULONG CDECL wined3d_unordered_access_view_incref(struct wined3d_unordered_access_view *view)
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 3b342d8..21c5f1b 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -3087,6 +3087,9 @@ struct wined3d_sampler
     GLuint name;
 };
 
+void wined3d_sampler_bind(struct wined3d_sampler *sampler, unsigned int unit,
+        struct wined3d_texture *texture, const struct wined3d_context *context) DECLSPEC_HIDDEN;
+
 struct wined3d_vertex_declaration_element
 {
     const struct wined3d_format *format;
@@ -3415,8 +3418,8 @@ struct wined3d_shader_resource_view
     struct wined3d_gl_view gl_view;
 };
 
-void wined3d_shader_resource_view_bind(struct wined3d_shader_resource_view *view,
-        struct wined3d_context *context) DECLSPEC_HIDDEN;
+void wined3d_shader_resource_view_bind(struct wined3d_shader_resource_view *view, unsigned int unit,
+        struct wined3d_sampler *sampler, struct wined3d_context *context) DECLSPEC_HIDDEN;
 
 struct wined3d_unordered_access_view
 {
-- 
2.10.2




More information about the wine-patches mailing list