From a7dadf2f95d0cc1e38f76a53b35c75d3075f3b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Mon, 20 Mar 2017 12:13:04 +0100 Subject: [PATCH] wined3d: Create wined3d sampler for default sampler. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Józef Kucia Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/wined3d/context.c | 2 +- dlls/wined3d/device.c | 46 +++++++++++++++++++++++----------- dlls/wined3d/wined3d_private.h | 2 +- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c index 8029de0a087..b554b001df5 100644 --- a/dlls/wined3d/context.c +++ b/dlls/wined3d/context.c @@ -3429,7 +3429,7 @@ static void context_bind_shader_resources(struct wined3d_context *context, } if (entry->sampler_idx == WINED3D_SAMPLER_DEFAULT) - sampler_name = device->default_sampler; + sampler_name = device->default_sampler->name; else if ((sampler = state->sampler[shader_type][entry->sampler_idx])) sampler_name = sampler->name; else diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index eef9818affd..ba30d202f57 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -776,20 +776,38 @@ static void destroy_dummy_textures(struct wined3d_device *device, struct wined3d static void create_default_samplers(struct wined3d_device *device, struct wined3d_context *context) { const struct wined3d_gl_info *gl_info = context->gl_info; + struct wined3d_sampler_desc desc; + HRESULT hr; + + desc.address_u = WINED3D_TADDRESS_WRAP; + desc.address_v = WINED3D_TADDRESS_WRAP; + desc.address_w = WINED3D_TADDRESS_WRAP; + memset(desc.border_color, 0, sizeof(desc.border_color)); + desc.mag_filter = WINED3D_TEXF_POINT; + desc.min_filter = WINED3D_TEXF_POINT; + desc.mip_filter = WINED3D_TEXF_NONE; + desc.lod_bias = 0.0f; + desc.min_lod = -1000.0f; + desc.max_lod = 1000.0f; + desc.max_anisotropy = 1; + desc.compare = FALSE; + desc.comparison_func = WINED3D_CMP_NEVER; + desc.srgb_decode = TRUE; + + /* In SM4+ shaders there is a separation between resources and samplers. Some shader + * instructions allow access to resources without using samplers. + * In GLSL, resources are always accessed through sampler or image variables. The default + * sampler object is used to emulate the direct resource access when there is no sampler state + * to use. + */ + if (FAILED(hr = wined3d_sampler_create(device, &desc, NULL, &device->default_sampler))) + { + ERR("Failed to create default sampler, hr %#x.\n", hr); + device->default_sampler = NULL; + } if (gl_info->supported[ARB_SAMPLER_OBJECTS]) { - /* In SM4+ shaders there is a separation between resources and samplers. Some shader - * instructions allow access to resources without using samplers. - * In GLSL, resources are always accessed through sampler or image variables. The default - * sampler object is used to emulate the direct resource access when there is no sampler state - * to use. - */ - GL_EXTCALL(glGenSamplers(1, &device->default_sampler)); - GL_EXTCALL(glSamplerParameteri(device->default_sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); - GL_EXTCALL(glSamplerParameteri(device->default_sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); - checkGLcall("Create default sampler"); - /* In D3D10+, a NULL sampler maps to the default sampler state. */ GL_EXTCALL(glGenSamplers(1, &device->null_sampler)); GL_EXTCALL(glSamplerParameteri(device->null_sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)); @@ -800,7 +818,6 @@ static void create_default_samplers(struct wined3d_device *device, struct wined3 } else { - device->default_sampler = 0; device->null_sampler = 0; } } @@ -810,14 +827,15 @@ static void destroy_default_samplers(struct wined3d_device *device, struct wined { const struct wined3d_gl_info *gl_info = context->gl_info; + wined3d_sampler_decref(device->default_sampler); + device->default_sampler = NULL; + if (gl_info->supported[ARB_SAMPLER_OBJECTS]) { - GL_EXTCALL(glDeleteSamplers(1, &device->default_sampler)); GL_EXTCALL(glDeleteSamplers(1, &device->null_sampler)); checkGLcall("glDeleteSamplers"); } - device->default_sampler = 0; device->null_sampler = 0; } diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 64e669b7c38..6b683aa8013 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -2688,7 +2688,7 @@ struct wined3d_device } dummy_textures; /* Default sampler used to emulate the direct resource access without using wined3d_sampler */ - GLuint default_sampler; + struct wined3d_sampler *default_sampler; GLuint null_sampler; /* Command stream */