[PATCH 3/5] wined3d: Replace wined3d_texture_apply_state_changes() with wined3d_texture_apply_sampler_desc().
Henri Verbeet
hverbeet at codeweavers.com
Thu Jan 15 10:19:05 CST 2015
---
dlls/wined3d/directx.c | 22 -----
dlls/wined3d/state.c | 132 ++++++++++++++++++++++-----
dlls/wined3d/surface.c | 10 +-
dlls/wined3d/texture.c | 196 ++++++++++------------------------------
dlls/wined3d/wined3d_private.h | 22 ++---
5 files changed, 170 insertions(+), 212 deletions(-)
diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c
index f42769b..26910b1 100644
--- a/dlls/wined3d/directx.c
+++ b/dlls/wined3d/directx.c
@@ -247,34 +247,12 @@ const struct min_lookup minMipLookup[] =
{{GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR}}, /* LINEAR */
};
-const struct min_lookup minMipLookup_noFilter[] =
-{
- /* NONE POINT LINEAR */
- {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* NONE */
- {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* POINT */
- {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* LINEAR */
-};
-
-const struct min_lookup minMipLookup_noMip[] =
-{
- /* NONE POINT LINEAR */
- {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* NONE */
- {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* POINT */
- {{GL_LINEAR, GL_LINEAR, GL_LINEAR }}, /* LINEAR */
-};
-
const GLenum magLookup[] =
{
/* NONE POINT LINEAR */
GL_NEAREST, GL_NEAREST, GL_LINEAR,
};
-const GLenum magLookup_noFilter[] =
-{
- /* NONE POINT LINEAR */
- GL_NEAREST, GL_NEAREST, GL_NEAREST,
-};
-
struct wined3d_caps_gl_ctx
{
HDC dc;
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
index 048ec13..a6d9b16 100644
--- a/dlls/wined3d/state.c
+++ b/dlls/wined3d/state.c
@@ -3603,24 +3603,92 @@ void sampler_texmatrix(struct wined3d_context *context, const struct wined3d_sta
}
}
-static void sampler(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
+static enum wined3d_texture_address wined3d_texture_address_mode(const struct wined3d_texture *texture,
+ enum wined3d_texture_address t)
{
- DWORD sampler = state_id - STATE_SAMPLER(0);
- DWORD mapped_stage = context->tex_unit_map[sampler];
- const struct wined3d_gl_info *gl_info = context->gl_info;
- union {
+ if (t < WINED3D_TADDRESS_WRAP || t > WINED3D_TADDRESS_MIRROR_ONCE)
+ {
+ FIXME("Unrecognized or unsupported texture address mode %#x.\n", t);
+ return WINED3D_TADDRESS_WRAP;
+ }
+
+ /* Cubemaps are always set to clamp, regardless of the sampler state. */
+ if (texture->target == GL_TEXTURE_CUBE_MAP_ARB || ((texture->flags & WINED3D_TEXTURE_COND_NP2)
+ && t == WINED3D_TADDRESS_WRAP))
+ return WINED3D_TADDRESS_CLAMP;
+
+ return t;
+}
+
+static void wined3d_sampler_desc_from_sampler_states(struct wined3d_sampler_desc *desc,
+ const struct wined3d_gl_info *gl_info, const DWORD *sampler_states, const struct wined3d_texture *texture)
+{
+ union
+ {
float f;
DWORD d;
- } tmpvalue;
+ } lod_bias;
+
+ desc->address_u = wined3d_texture_address_mode(texture, sampler_states[WINED3D_SAMP_ADDRESS_U]);
+ desc->address_v = wined3d_texture_address_mode(texture, sampler_states[WINED3D_SAMP_ADDRESS_V]);
+ desc->address_w = wined3d_texture_address_mode(texture, sampler_states[WINED3D_SAMP_ADDRESS_W]);
+ D3DCOLORTOGLFLOAT4(sampler_states[WINED3D_SAMP_BORDER_COLOR], desc->border_color);
+ if (sampler_states[WINED3D_SAMP_MAG_FILTER] > WINED3D_TEXF_ANISOTROPIC)
+ FIXME("Unrecognized or unsupported WINED3D_SAMP_MAG_FILTER %#x.\n",
+ sampler_states[WINED3D_SAMP_MAG_FILTER]);
+ desc->mag_filter = min(max(sampler_states[WINED3D_SAMP_MAG_FILTER], WINED3D_TEXF_POINT), WINED3D_TEXF_LINEAR);
+ if (sampler_states[WINED3D_SAMP_MIN_FILTER] > WINED3D_TEXF_ANISOTROPIC)
+ FIXME("Unrecognized or unsupported WINED3D_SAMP_MIN_FILTER %#x.\n",
+ sampler_states[WINED3D_SAMP_MIN_FILTER]);
+ desc->min_filter = min(max(sampler_states[WINED3D_SAMP_MIN_FILTER], WINED3D_TEXF_POINT), WINED3D_TEXF_LINEAR);
+ if (sampler_states[WINED3D_SAMP_MIP_FILTER] > WINED3D_TEXF_ANISOTROPIC)
+ FIXME("Unrecognized or unsupported WINED3D_SAMP_MIP_FILTER %#x.\n",
+ sampler_states[WINED3D_SAMP_MIP_FILTER]);
+ desc->mip_filter = min(max(sampler_states[WINED3D_SAMP_MIP_FILTER], WINED3D_TEXF_NONE), WINED3D_TEXF_LINEAR);
+ lod_bias.d = sampler_states[WINED3D_SAMP_MIPMAP_LOD_BIAS];
+ desc->lod_bias = lod_bias.f;
+ desc->min_lod = -1000.0f;
+ desc->max_lod = 1000.0f;
+ 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
+ && sampler_states[WINED3D_SAMP_MIP_FILTER] != WINED3D_TEXF_ANISOTROPIC)
+ || (texture->flags & WINED3D_TEXTURE_COND_NP2))
+ desc->max_anisotropy = 1;
+ desc->compare = texture->resource.format->flags & WINED3DFMT_FLAG_SHADOW;
+ desc->comparison_func = WINED3D_CMP_LESSEQUAL;
+ desc->srgb_decode = sampler_states[WINED3D_SAMP_SRGB_TEXTURE];
+
+ if (!(texture->resource.format->flags & WINED3DFMT_FLAG_FILTERING))
+ {
+ desc->mag_filter = WINED3D_TEXF_POINT;
+ desc->min_filter = WINED3D_TEXF_POINT;
+ desc->mip_filter = WINED3D_TEXF_NONE;
+ }
+
+ if (texture->flags & WINED3D_TEXTURE_COND_NP2)
+ {
+ desc->mip_filter = WINED3D_TEXF_NONE;
+ if (gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT])
+ desc->min_filter = WINED3D_TEXF_POINT;
+ }
+}
+
+/* Enabling and disabling texture dimensions is done by texture stage state /
+ * pixel shader setup, this function only has to bind textures and set the per
+ * texture states. */
+static void sampler(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
+{
+ DWORD sampler_idx = state_id - STATE_SAMPLER(0);
+ DWORD mapped_stage = context->tex_unit_map[sampler_idx];
+ const struct wined3d_gl_info *gl_info = context->gl_info;
+
+ TRACE("Sampler %u.\n", sampler_idx);
- TRACE("Sampler: %d\n", sampler);
- /* Enabling and disabling texture dimensions is done by texture stage state / pixel shader setup, this function
- * only has to bind textures and set the per texture states
- */
if (mapped_stage == WINED3D_UNMAPPED_STAGE)
{
- TRACE("No sampler mapped to stage %d. Returning.\n", sampler);
+ TRACE("No sampler mapped to stage %u. Returning.\n", sampler_idx);
return;
}
@@ -3630,25 +3698,41 @@ static void sampler(struct wined3d_context *context, const struct wined3d_state
}
context_active_texture(context, gl_info, mapped_stage);
- if (state->textures[sampler])
+ if (state->textures[sampler_idx])
{
- struct wined3d_texture *texture = state->textures[sampler];
- BOOL srgb = state->sampler_states[sampler][WINED3D_SAMP_SRGB_TEXTURE];
+ struct wined3d_texture *texture = state->textures[sampler_idx];
+ BOOL srgb = state->sampler_states[sampler_idx][WINED3D_SAMP_SRGB_TEXTURE];
+ const DWORD *sampler_states = state->sampler_states[sampler_idx];
+ struct wined3d_sampler_desc desc;
+ struct gl_texture *gl_tex;
+ unsigned int base_level;
+ wined3d_sampler_desc_from_sampler_states(&desc, gl_info, sampler_states, texture);
wined3d_texture_bind(texture, context, srgb);
- wined3d_texture_apply_state_changes(texture, state->sampler_states[sampler], gl_info);
+ wined3d_texture_apply_sampler_desc(texture, &desc, gl_info);
+
+ 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);
- if (gl_info->supported[EXT_TEXTURE_LOD_BIAS])
+ gl_tex = wined3d_texture_get_gl_texture(texture, texture->flags & WINED3D_TEXTURE_IS_SRGB);
+ if (base_level != gl_tex->base_level)
{
- tmpvalue.d = state->sampler_states[sampler][WINED3D_SAMP_MIPMAP_LOD_BIAS];
- gl_info->gl_ops.gl.p_glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
- GL_TEXTURE_LOD_BIAS_EXT, tmpvalue.f);
- checkGLcall("glTexEnvf(GL_TEXTURE_LOD_BIAS_EXT, ...)");
+ /* Note that WINED3D_SAMP_MAX_MIP_LEVEL specifies the largest mipmap
+ * (default 0), while GL_TEXTURE_MAX_LEVEL specifies the smallest
+ * mimap 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;
}
- if (!use_ps(state) && sampler < context->lowest_disabled_stage)
+ if (!use_ps(state) && sampler_idx < context->lowest_disabled_stage)
{
- if (state->render_states[WINED3D_RS_COLORKEYENABLE] && !sampler)
+ if (state->render_states[WINED3D_RS_COLORKEYENABLE] && !sampler_idx)
{
/* If color keying is enabled update the alpha test, it
* depends on the existence of a color key in stage 0. */
@@ -3662,10 +3746,10 @@ static void sampler(struct wined3d_context *context, const struct wined3d_state
}
else
{
- if (sampler < context->lowest_disabled_stage)
+ if (sampler_idx < context->lowest_disabled_stage)
{
/* TODO: What should I do with pixel shaders here ??? */
- if (state->render_states[WINED3D_RS_COLORKEYENABLE] && !sampler)
+ if (state->render_states[WINED3D_RS_COLORKEYENABLE] && !sampler_idx)
{
/* If color keying is enabled update the alpha test, it
* depends on the existence of a color key in stage 0. */
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index b368e28..974b415 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -310,11 +310,10 @@ void draw_textured_quad(const struct wined3d_surface *src_surface, struct wined3
context_bind_texture(context, info.bind_target, texture->texture_rgb.name);
/* Filtering for StretchRect */
- gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_MAG_FILTER,
- wined3d_gl_mag_filter(magLookup, filter));
+ gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_MAG_FILTER, wined3d_gl_mag_filter(filter));
checkGLcall("glTexParameteri");
gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_MIN_FILTER,
- wined3d_gl_min_mip_filter(minMipLookup, filter, WINED3D_TEXF_NONE));
+ wined3d_gl_min_mip_filter(filter, WINED3D_TEXF_NONE));
checkGLcall("glTexParameteri");
gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_WRAP_S, GL_CLAMP);
gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_WRAP_T, GL_CLAMP);
@@ -3239,11 +3238,10 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st
checkGLcall("glCopyTexSubImage2D");
/* No issue with overriding these - the sampler is dirty due to blit usage */
- gl_info->gl_ops.gl.p_glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER,
- wined3d_gl_mag_filter(magLookup, filter));
+ gl_info->gl_ops.gl.p_glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, wined3d_gl_mag_filter(filter));
checkGLcall("glTexParameteri");
gl_info->gl_ops.gl.p_glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER,
- wined3d_gl_min_mip_filter(minMipLookup, filter, WINED3D_TEXF_NONE));
+ wined3d_gl_min_mip_filter(filter, WINED3D_TEXF_NONE));
checkGLcall("glTexParameteri");
if (!src_surface->container->swapchain
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index 9da8cec..f63f84b 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -85,17 +85,6 @@ static HRESULT wined3d_texture_init(struct wined3d_texture *texture, const struc
if (surface_flags & WINED3D_SURFACE_PIN_SYSMEM)
texture->flags |= WINED3D_TEXTURE_PIN_SYSMEM;
- if (texture->resource.format->flags & WINED3DFMT_FLAG_FILTERING)
- {
- texture->min_mip_lookup = minMipLookup;
- texture->mag_lookup = magLookup;
- }
- else
- {
- texture->min_mip_lookup = minMipLookup_noFilter;
- texture->mag_lookup = magLookup_noFilter;
- }
-
return WINED3D_OK;
}
@@ -301,187 +290,106 @@ void wined3d_texture_bind_and_dirtify(struct wined3d_texture *texture,
wined3d_texture_bind(texture, context, srgb);
}
-/* Context activation is done by the caller. */
-static void apply_wrap(const struct wined3d_gl_info *gl_info, GLenum target,
- enum wined3d_texture_address d3d_wrap, GLenum param, BOOL cond_np2)
-{
- GLint gl_wrap;
-
- if (d3d_wrap < WINED3D_TADDRESS_WRAP || d3d_wrap > WINED3D_TADDRESS_MIRROR_ONCE)
- {
- FIXME("Unrecognized or unsupported texture address mode %#x.\n", d3d_wrap);
- return;
- }
-
- /* Cubemaps are always set to clamp, regardless of the sampler state. */
- if (target == GL_TEXTURE_CUBE_MAP_ARB
- || (cond_np2 && d3d_wrap == WINED3D_TADDRESS_WRAP))
- gl_wrap = GL_CLAMP_TO_EDGE;
- else
- gl_wrap = gl_info->wrap_lookup[d3d_wrap - WINED3D_TADDRESS_WRAP];
-
- TRACE("Setting param %#x to %#x for target %#x.\n", param, gl_wrap, target);
- gl_info->gl_ops.gl.p_glTexParameteri(target, param, gl_wrap);
- checkGLcall("glTexParameteri(target, param, gl_wrap)");
-}
-
/* Context activation is done by the caller (state handler). */
-void wined3d_texture_apply_state_changes(struct wined3d_texture *texture,
- const DWORD sampler_states[WINED3D_HIGHEST_SAMPLER_STATE + 1],
- const struct wined3d_gl_info *gl_info)
+/* This function relies on the correct texture being bound and loaded. */
+void wined3d_texture_apply_sampler_desc(struct wined3d_texture *texture,
+ const struct wined3d_sampler_desc *sampler_desc, const struct wined3d_gl_info *gl_info)
{
- BOOL cond_np2 = texture->flags & WINED3D_TEXTURE_COND_NP2;
GLenum target = texture->target;
struct gl_texture *gl_tex;
- float border_color[4];
DWORD state;
- DWORD aniso;
- TRACE("texture %p, sampler_states %p.\n", texture, sampler_states);
+ TRACE("texture %p, sampler_desc %p, gl_info %p.\n", texture, sampler_desc, gl_info);
gl_tex = wined3d_texture_get_gl_texture(texture, texture->flags & WINED3D_TEXTURE_IS_SRGB);
- /* This function relies on the correct texture being bound and loaded. */
-
- if (sampler_states[WINED3D_SAMP_ADDRESS_U] != gl_tex->sampler_desc.address_u)
+ state = sampler_desc->address_u;
+ if (state != gl_tex->sampler_desc.address_u)
{
- state = sampler_states[WINED3D_SAMP_ADDRESS_U];
- apply_wrap(gl_info, target, state, GL_TEXTURE_WRAP_S, cond_np2);
+ gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_S,
+ gl_info->wrap_lookup[state - WINED3D_TADDRESS_WRAP]);
gl_tex->sampler_desc.address_u = state;
}
- if (sampler_states[WINED3D_SAMP_ADDRESS_V] != gl_tex->sampler_desc.address_v)
+ state = sampler_desc->address_v;
+ if (state != gl_tex->sampler_desc.address_v)
{
- state = sampler_states[WINED3D_SAMP_ADDRESS_V];
- apply_wrap(gl_info, target, state, GL_TEXTURE_WRAP_T, cond_np2);
+ gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_T,
+ gl_info->wrap_lookup[state - WINED3D_TADDRESS_WRAP]);
gl_tex->sampler_desc.address_v = state;
}
- if (sampler_states[WINED3D_SAMP_ADDRESS_W] != gl_tex->sampler_desc.address_w)
+ state = sampler_desc->address_w;
+ if (state != gl_tex->sampler_desc.address_w)
{
- state = sampler_states[WINED3D_SAMP_ADDRESS_W];
- apply_wrap(gl_info, target, state, GL_TEXTURE_WRAP_R, cond_np2);
+ gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_R,
+ gl_info->wrap_lookup[state - WINED3D_TADDRESS_WRAP]);
gl_tex->sampler_desc.address_w = state;
}
- D3DCOLORTOGLFLOAT4(sampler_states[WINED3D_SAMP_BORDER_COLOR], border_color);
- if (memcmp(gl_tex->sampler_desc.border_color, border_color, sizeof(gl_tex->sampler_desc.border_color)))
+ if (memcmp(gl_tex->sampler_desc.border_color, sampler_desc->border_color,
+ sizeof(gl_tex->sampler_desc.border_color)))
{
- TRACE("Setting border color for %#x to {%.8e, %.8e, %.8e, %.8e}.\n",
- target, border_color[0], border_color[1], border_color[2], border_color[3]);
- gl_info->gl_ops.gl.p_glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, &border_color[0]);
- checkGLcall("glTexParameterfv(..., GL_TEXTURE_BORDER_COLOR, ...)");
- memcpy(gl_tex->sampler_desc.border_color, border_color, sizeof(gl_tex->sampler_desc.border_color));
+ gl_info->gl_ops.gl.p_glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, &sampler_desc->border_color[0]);
+ memcpy(gl_tex->sampler_desc.border_color, sampler_desc->border_color,
+ sizeof(gl_tex->sampler_desc.border_color));
}
- if (sampler_states[WINED3D_SAMP_MAG_FILTER] != gl_tex->sampler_desc.mag_filter)
+ state = sampler_desc->mag_filter;
+ if (state != gl_tex->sampler_desc.mag_filter)
{
- GLint gl_value;
-
- state = sampler_states[WINED3D_SAMP_MAG_FILTER];
- if (state > WINED3D_TEXF_ANISOTROPIC)
- FIXME("Unrecognized or unsupported MAGFILTER* value %d.\n", state);
-
- gl_value = wined3d_gl_mag_filter(texture->mag_lookup,
- min(max(state, WINED3D_TEXF_POINT), WINED3D_TEXF_LINEAR));
- TRACE("ValueMAG=%#x setting MAGFILTER to %#x.\n", state, gl_value);
- gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAG_FILTER, gl_value);
-
+ gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAG_FILTER, wined3d_gl_mag_filter(state));
gl_tex->sampler_desc.mag_filter = state;
}
- if (sampler_states[WINED3D_SAMP_MIN_FILTER] != gl_tex->sampler_desc.min_filter
- || sampler_states[WINED3D_SAMP_MIP_FILTER] != gl_tex->sampler_desc.mip_filter
- || sampler_states[WINED3D_SAMP_MAX_MIP_LEVEL] != gl_tex->base_level)
+ if (sampler_desc->min_filter != gl_tex->sampler_desc.min_filter
+ || sampler_desc->mip_filter != gl_tex->sampler_desc.mip_filter)
{
- GLint gl_value;
-
- gl_tex->sampler_desc.mip_filter = sampler_states[WINED3D_SAMP_MIP_FILTER];
- gl_tex->sampler_desc.min_filter = sampler_states[WINED3D_SAMP_MIN_FILTER];
- gl_tex->base_level = sampler_states[WINED3D_SAMP_MAX_MIP_LEVEL];
-
- if (gl_tex->sampler_desc.min_filter > WINED3D_TEXF_ANISOTROPIC
- || gl_tex->sampler_desc.mip_filter > WINED3D_TEXF_ANISOTROPIC)
- FIXME("Unrecognized or unsupported MIN_FILTER value %#x MIP_FILTER value %#x.\n",
- gl_tex->sampler_desc.min_filter, gl_tex->sampler_desc.mip_filter);
-
- gl_value = wined3d_gl_min_mip_filter(texture->min_mip_lookup,
- min(max(sampler_states[WINED3D_SAMP_MIN_FILTER], WINED3D_TEXF_POINT), WINED3D_TEXF_LINEAR),
- min(max(sampler_states[WINED3D_SAMP_MIP_FILTER], WINED3D_TEXF_NONE), WINED3D_TEXF_LINEAR));
-
- TRACE("ValueMIN=%#x, ValueMIP=%#x, setting MINFILTER to %#x.\n",
- sampler_states[WINED3D_SAMP_MIN_FILTER],
- sampler_states[WINED3D_SAMP_MIP_FILTER], gl_value);
- gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MIN_FILTER, gl_value);
- checkGLcall("glTexParameter GL_TEXTURE_MIN_FILTER, ...");
-
- if (!cond_np2)
- {
- if (gl_tex->sampler_desc.mip_filter == WINED3D_TEXF_NONE)
- gl_value = texture->lod;
- else if (gl_tex->base_level >= texture->level_count)
- gl_value = texture->level_count - 1;
- else if (gl_tex->base_level < texture->lod)
- /* texture->lod is already clamped in the setter. */
- gl_value = texture->lod;
- else
- gl_value = 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
- * mimap used (default 1000). So WINED3D_SAMP_MAX_MIP_LEVEL
- * corresponds to GL_TEXTURE_BASE_LEVEL. */
- gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, gl_value);
- }
+ gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
+ wined3d_gl_min_mip_filter(sampler_desc->min_filter, sampler_desc->mip_filter));
+ gl_tex->sampler_desc.min_filter = sampler_desc->min_filter;
+ gl_tex->sampler_desc.mip_filter = sampler_desc->mip_filter;
}
- if ((gl_tex->sampler_desc.mag_filter != WINED3D_TEXF_ANISOTROPIC
- && gl_tex->sampler_desc.min_filter != WINED3D_TEXF_ANISOTROPIC
- && gl_tex->sampler_desc.mip_filter != WINED3D_TEXF_ANISOTROPIC)
- || cond_np2)
- aniso = 1;
- else
- aniso = sampler_states[WINED3D_SAMP_MAX_ANISOTROPY];
-
- if (gl_tex->sampler_desc.max_anisotropy != aniso)
+ state = sampler_desc->max_anisotropy;
+ if (state != gl_tex->sampler_desc.max_anisotropy)
{
if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
- {
- gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso);
- checkGLcall("glTexParameteri(GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso)");
- }
+ gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, state);
else
- {
WARN("Anisotropic filtering not supported.\n");
- }
- gl_tex->sampler_desc.max_anisotropy = aniso;
+ gl_tex->sampler_desc.max_anisotropy = state;
}
/* These should always be the same unless EXT_texture_sRGB_decode is supported. */
- if (!sampler_states[WINED3D_SAMP_SRGB_TEXTURE] != !gl_tex->sampler_desc.srgb_decode)
+ if (!sampler_desc->srgb_decode != !gl_tex->sampler_desc.srgb_decode)
{
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_SRGB_DECODE_EXT,
- sampler_states[WINED3D_SAMP_SRGB_TEXTURE] ? GL_DECODE_EXT : GL_SKIP_DECODE_EXT);
- checkGLcall("glTexParameteri(GL_TEXTURE_SRGB_DECODE_EXT)");
- gl_tex->sampler_desc.srgb_decode = sampler_states[WINED3D_SAMP_SRGB_TEXTURE];
+ sampler_desc->srgb_decode ? GL_DECODE_EXT : GL_SKIP_DECODE_EXT);
+ gl_tex->sampler_desc.srgb_decode = sampler_desc->srgb_decode;
}
- if (!(texture->resource.format->flags & WINED3DFMT_FLAG_SHADOW)
- != !gl_tex->sampler_desc.compare)
+ if (!sampler_desc->compare != !gl_tex->sampler_desc.compare)
{
- if (texture->resource.format->flags & WINED3DFMT_FLAG_SHADOW)
+ if (sampler_desc->compare)
{
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE);
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
- checkGLcall("glTexParameteri(target, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB)");
- gl_tex->sampler_desc.compare = TRUE;
}
else
{
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
- checkGLcall("glTexParameteri(target, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE)");
- gl_tex->sampler_desc.compare = FALSE;
}
+ gl_tex->sampler_desc.compare = sampler_desc->compare;
+ }
+
+ checkGLcall("Texture parameter application");
+
+ if (gl_info->supported[EXT_TEXTURE_LOD_BIAS])
+ {
+ gl_info->gl_ops.gl.p_glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
+ GL_TEXTURE_LOD_BIAS_EXT, sampler_desc->lod_bias);
+ checkGLcall("glTexEnvf(GL_TEXTURE_LOD_BIAS_EXT, ...)");
}
}
@@ -1238,7 +1146,6 @@ static HRESULT texture_init(struct wined3d_texture *texture, const struct wined3
texture->pow2_matrix[15] = 1.0f;
texture->target = GL_TEXTURE_2D;
texture->flags |= WINED3D_TEXTURE_COND_NP2;
- texture->min_mip_lookup = minMipLookup_noFilter;
}
else if (gl_info->supported[ARB_TEXTURE_RECTANGLE]
&& (desc->width != pow2_width || desc->height != pow2_height))
@@ -1250,11 +1157,6 @@ static HRESULT texture_init(struct wined3d_texture *texture, const struct wined3
texture->target = GL_TEXTURE_RECTANGLE_ARB;
texture->flags |= WINED3D_TEXTURE_COND_NP2;
texture->flags &= ~(WINED3D_TEXTURE_POW2_MAT_IDENT | WINED3D_TEXTURE_NORMALIZED_COORDS);
-
- if (texture->resource.format->flags & WINED3DFMT_FLAG_FILTERING)
- texture->min_mip_lookup = minMipLookup_noMip;
- else
- texture->min_mip_lookup = minMipLookup_noFilter;
}
else
{
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 1593bd9..bee7f61 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -186,20 +186,19 @@ struct min_lookup
};
extern const struct min_lookup minMipLookup[WINED3D_TEXF_LINEAR + 1] DECLSPEC_HIDDEN;
-extern const struct min_lookup minMipLookup_noFilter[WINED3D_TEXF_LINEAR + 1] DECLSPEC_HIDDEN;
-extern const struct min_lookup minMipLookup_noMip[WINED3D_TEXF_LINEAR + 1] DECLSPEC_HIDDEN;
extern const GLenum magLookup[WINED3D_TEXF_LINEAR + 1] DECLSPEC_HIDDEN;
-extern const GLenum magLookup_noFilter[WINED3D_TEXF_LINEAR + 1] DECLSPEC_HIDDEN;
-static inline GLenum wined3d_gl_mag_filter(const GLenum mag_lookup[], enum wined3d_texture_filter_type mag_filter)
+GLenum wined3d_gl_compare_func(enum wined3d_cmp_func f) DECLSPEC_HIDDEN;
+
+static inline GLenum wined3d_gl_mag_filter(enum wined3d_texture_filter_type mag_filter)
{
- return mag_lookup[mag_filter];
+ return magLookup[mag_filter];
}
-static inline GLenum wined3d_gl_min_mip_filter(const struct min_lookup min_mip_lookup[],
- enum wined3d_texture_filter_type min_filter, enum wined3d_texture_filter_type mip_filter)
+static inline GLenum wined3d_gl_min_mip_filter(enum wined3d_texture_filter_type min_filter,
+ enum wined3d_texture_filter_type mip_filter)
{
- return min_mip_lookup[min_filter].mip[mip_filter];
+ return minMipLookup[min_filter].mip[mip_filter];
}
/* float_16_to_32() and float_32_to_16() (see implementation in
@@ -2175,8 +2174,6 @@ struct wined3d_texture
enum wined3d_texture_filter_type filter_type;
DWORD sampler;
DWORD flags;
- const struct min_lookup *min_mip_lookup;
- const GLenum *mag_lookup;
GLenum target;
/* Color keys for DDraw */
@@ -2198,9 +2195,8 @@ static inline struct gl_texture *wined3d_texture_get_gl_texture(struct wined3d_t
return srgb ? &texture->texture_srgb : &texture->texture_rgb;
}
-void wined3d_texture_apply_state_changes(struct wined3d_texture *texture,
- const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1],
- const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
+void wined3d_texture_apply_sampler_desc(struct wined3d_texture *texture,
+ const struct wined3d_sampler_desc *sampler_desc, const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
void wined3d_texture_bind(struct wined3d_texture *texture,
struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
void wined3d_texture_bind_and_dirtify(struct wined3d_texture *texture,
--
1.7.10.4
More information about the wine-patches
mailing list