Commit ec1da699 authored by Józef Kucia's avatar Józef Kucia Committed by Alexandre Julliard

wined3d: Make wined3d samplers responsible for setting texture base level.

parent 591a3b1b
......@@ -1205,6 +1205,7 @@ HRESULT d3d_sampler_state_init(struct d3d_sampler_state *state, struct d3d_devic
wined3d_desc.lod_bias = desc->MipLODBias;
wined3d_desc.min_lod = desc->MinLOD;
wined3d_desc.max_lod = desc->MaxLOD;
wined3d_desc.mip_base_level = 0;
wined3d_desc.max_anisotropy = D3D11_DECODE_IS_ANISOTROPIC_FILTER(desc->Filter) ? desc->MaxAnisotropy : 1;
wined3d_desc.compare = wined3d_texture_compare_from_d3d11(desc->Filter);
wined3d_desc.comparison_func = wined3d_cmp_func_from_d3d11(desc->ComparisonFunc);
......
......@@ -788,6 +788,7 @@ static void create_default_samplers(struct wined3d_device *device, struct wined3
desc.lod_bias = 0.0f;
desc.min_lod = -1000.0f;
desc.max_lod = 1000.0f;
desc.mip_base_level = 0;
desc.max_anisotropy = 1;
desc.compare = FALSE;
desc.comparison_func = WINED3D_CMP_NEVER;
......
......@@ -151,6 +151,31 @@ HRESULT CDECL wined3d_sampler_create(struct wined3d_device *device, const struct
return WINED3D_OK;
}
static void texture_apply_base_level(struct wined3d_texture *texture,
const struct wined3d_sampler_desc *desc, const struct wined3d_gl_info *gl_info)
{
struct gl_texture *gl_tex;
unsigned int base_level;
if (texture->flags & WINED3D_TEXTURE_COND_NP2)
base_level = 0;
else if (desc->mip_filter == WINED3D_TEXF_NONE)
base_level = texture->lod;
else
base_level = min(max(desc->mip_base_level, texture->lod), texture->level_count - 1);
gl_tex = wined3d_texture_get_gl_texture(texture, texture->flags & WINED3D_TEXTURE_IS_SRGB);
if (base_level != gl_tex->base_level)
{
/* Note that WINED3D_SAMP_MAX_MIP_LEVEL specifies the largest mipmap
* (default 0), while GL_TEXTURE_MAX_LEVEL specifies the smallest
* mipmap used (default 1000). So WINED3D_SAMP_MAX_MIP_LEVEL
* corresponds to GL_TEXTURE_BASE_LEVEL. */
gl_info->gl_ops.gl.p_glTexParameteri(texture->target, GL_TEXTURE_BASE_LEVEL, base_level);
gl_tex->base_level = base_level;
}
}
/* 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)
......@@ -170,4 +195,7 @@ void wined3d_sampler_bind(struct wined3d_sampler *sampler, unsigned int unit,
{
ERR("Could not apply sampler state.\n");
}
if (texture)
texture_apply_base_level(texture, &sampler->desc, gl_info);
}
......@@ -3562,6 +3562,7 @@ static void wined3d_sampler_desc_from_sampler_states(struct wined3d_sampler_desc
desc->lod_bias = lod_bias.f;
desc->min_lod = -1000.0f;
desc->max_lod = 1000.0f;
desc->mip_base_level = sampler_states[WINED3D_SAMP_MAX_MIP_LEVEL];
desc->max_anisotropy = sampler_states[WINED3D_SAMP_MAX_ANISOTROPY];
if ((sampler_states[WINED3D_SAMP_MAG_FILTER] != WINED3D_TEXF_ANISOTROPIC
&& sampler_states[WINED3D_SAMP_MIN_FILTER] != WINED3D_TEXF_ANISOTROPIC
......@@ -3618,8 +3619,6 @@ static void sampler(struct wined3d_context *context, const struct wined3d_state
struct wined3d_sampler_desc desc;
struct wined3d_sampler *sampler;
struct wine_rb_entry *entry;
struct gl_texture *gl_tex;
unsigned int base_level;
wined3d_sampler_desc_from_sampler_states(&desc, context, sampler_states, texture);
......@@ -3646,25 +3645,6 @@ static void sampler(struct wined3d_context *context, const struct wined3d_state
if (sampler)
wined3d_sampler_bind(sampler, mapped_stage, texture, context);
if (texture->flags & WINED3D_TEXTURE_COND_NP2)
base_level = 0;
else if (desc.mip_filter == WINED3D_TEXF_NONE)
base_level = texture->lod;
else
base_level = min(max(sampler_states[WINED3D_SAMP_MAX_MIP_LEVEL],
texture->lod), texture->level_count - 1);
gl_tex = wined3d_texture_get_gl_texture(texture, texture->flags & WINED3D_TEXTURE_IS_SRGB);
if (base_level != gl_tex->base_level)
{
/* Note that WINED3D_SAMP_MAX_MIP_LEVEL specifies the largest mipmap
* (default 0), while GL_TEXTURE_MAX_LEVEL specifies the smallest
* mipmap used (default 1000). So WINED3D_SAMP_MAX_MIP_LEVEL
* corresponds to GL_TEXTURE_BASE_LEVEL. */
gl_info->gl_ops.gl.p_glTexParameteri(texture->target, GL_TEXTURE_BASE_LEVEL, base_level);
gl_tex->base_level = base_level;
}
/* Trigger shader constant reloading (for NP2 texcoord fixup) */
if (!(texture->flags & WINED3D_TEXTURE_POW2_MAT_IDENT))
context->constant_update_mask |= WINED3D_SHADER_CONST_PS_NP2_FIXUP;
......
......@@ -1942,6 +1942,7 @@ struct wined3d_sampler_desc
float lod_bias;
float min_lod;
float max_lod;
unsigned int mip_base_level;
unsigned int max_anisotropy;
BOOL compare;
enum wined3d_cmp_func comparison_func;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment