Commit 3171193b authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Move the texture unit map from struct wined3d_context to struct wined3d_context_gl.

parent 045f9b51
......@@ -4476,6 +4476,7 @@ static void find_arb_vs_compile_args(const struct wined3d_state *state,
const struct wined3d_context *context, const struct wined3d_shader *shader,
struct arb_vs_compile_args *args)
{
const struct wined3d_context_gl *context_gl = wined3d_context_gl_const(context);
const struct wined3d_device *device = shader->device;
const struct wined3d_adapter *adapter = device->adapter;
const struct wined3d_gl_info *gl_info = context->gl_info;
......@@ -4518,9 +4519,9 @@ static void find_arb_vs_compile_args(const struct wined3d_state *state,
args->clip.boolclip.bools |= (1u << i);
}
args->vertex.samplers[0] = context->tex_unit_map[WINED3D_MAX_FRAGMENT_SAMPLERS + 0];
args->vertex.samplers[1] = context->tex_unit_map[WINED3D_MAX_FRAGMENT_SAMPLERS + 1];
args->vertex.samplers[2] = context->tex_unit_map[WINED3D_MAX_FRAGMENT_SAMPLERS + 2];
args->vertex.samplers[0] = context_gl->tex_unit_map[WINED3D_MAX_FRAGMENT_SAMPLERS + 0];
args->vertex.samplers[1] = context_gl->tex_unit_map[WINED3D_MAX_FRAGMENT_SAMPLERS + 1];
args->vertex.samplers[2] = context_gl->tex_unit_map[WINED3D_MAX_FRAGMENT_SAMPLERS + 2];
args->vertex.samplers[3] = 0;
/* Skip if unused or local */
......
......@@ -1010,13 +1010,14 @@ static void atifs_stage_constant(struct wined3d_context *context, const struct w
static void set_tex_op_atifs(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{
const struct wined3d_device *device = context->device;
const struct wined3d_gl_info *gl_info = context->gl_info;
const struct wined3d_d3d_info *d3d_info = context->d3d_info;
struct atifs_context_private_data *ctx_priv = context->fragment_pipe_data;
const struct atifs_ffp_desc *desc, *last_shader = ctx_priv->last_shader;
struct ffp_frag_settings settings;
struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
const struct wined3d_d3d_info *d3d_info = context->d3d_info;
const struct wined3d_gl_info *gl_info = context->gl_info;
const struct wined3d_device *device = context->device;
struct atifs_private_data *priv = device->fragment_priv;
struct ffp_frag_settings settings;
DWORD mapped_stage;
unsigned int i;
......@@ -1051,7 +1052,7 @@ static void set_tex_op_atifs(struct wined3d_context *context, const struct wined
*/
for (i = 0; i < desc->num_textures_used; ++i)
{
mapped_stage = context->tex_unit_map[i];
mapped_stage = context_gl->tex_unit_map[i];
if (mapped_stage != WINED3D_UNMAPPED_STAGE)
{
context_active_texture(context, gl_info, mapped_stage);
......
......@@ -1994,37 +1994,37 @@ HRESULT wined3d_context_gl_init(struct wined3d_context_gl *context_gl, struct wi
gl_info = context->gl_info;
d3d_info = context->d3d_info;
for (i = 0; i < ARRAY_SIZE(context->tex_unit_map); ++i)
context->tex_unit_map[i] = WINED3D_UNMAPPED_STAGE;
for (i = 0; i < ARRAY_SIZE(context->rev_tex_unit_map); ++i)
context->rev_tex_unit_map[i] = WINED3D_UNMAPPED_STAGE;
for (i = 0; i < ARRAY_SIZE(context_gl->tex_unit_map); ++i)
context_gl->tex_unit_map[i] = WINED3D_UNMAPPED_STAGE;
for (i = 0; i < ARRAY_SIZE(context_gl->rev_tex_unit_map); ++i)
context_gl->rev_tex_unit_map[i] = WINED3D_UNMAPPED_STAGE;
if (gl_info->limits.graphics_samplers >= WINED3D_MAX_COMBINED_SAMPLERS)
{
/* Initialize the texture unit mapping to a 1:1 mapping. */
unsigned int base, count;
wined3d_gl_limits_get_texture_unit_range(&gl_info->limits, WINED3D_SHADER_TYPE_PIXEL, &base, &count);
if (base + WINED3D_MAX_FRAGMENT_SAMPLERS > ARRAY_SIZE(context->rev_tex_unit_map))
if (base + WINED3D_MAX_FRAGMENT_SAMPLERS > ARRAY_SIZE(context_gl->rev_tex_unit_map))
{
ERR("Unexpected texture unit base index %u.\n", base);
return E_FAIL;
}
for (i = 0; i < min(count, WINED3D_MAX_FRAGMENT_SAMPLERS); ++i)
{
context->tex_unit_map[i] = base + i;
context->rev_tex_unit_map[base + i] = i;
context_gl->tex_unit_map[i] = base + i;
context_gl->rev_tex_unit_map[base + i] = i;
}
wined3d_gl_limits_get_texture_unit_range(&gl_info->limits, WINED3D_SHADER_TYPE_VERTEX, &base, &count);
if (base + WINED3D_MAX_VERTEX_SAMPLERS > ARRAY_SIZE(context->rev_tex_unit_map))
if (base + WINED3D_MAX_VERTEX_SAMPLERS > ARRAY_SIZE(context_gl->rev_tex_unit_map))
{
ERR("Unexpected texture unit base index %u.\n", base);
return E_FAIL;
}
for (i = 0; i < min(count, WINED3D_MAX_VERTEX_SAMPLERS); ++i)
{
context->tex_unit_map[WINED3D_MAX_FRAGMENT_SAMPLERS + i] = base + i;
context->rev_tex_unit_map[base + i] = WINED3D_MAX_FRAGMENT_SAMPLERS + i;
context_gl->tex_unit_map[WINED3D_MAX_FRAGMENT_SAMPLERS + i] = base + i;
context_gl->rev_tex_unit_map[base + i] = WINED3D_MAX_FRAGMENT_SAMPLERS + i;
}
}
......@@ -2378,7 +2378,7 @@ const unsigned int *wined3d_context_gl_get_tex_unit_mapping(const struct wined3d
{
*base = 0;
*count = WINED3D_MAX_TEXTURES;
return context_gl->c.tex_unit_map;
return context_gl->tex_unit_map;
}
if (shader_version->major >= 4)
......@@ -2403,7 +2403,7 @@ const unsigned int *wined3d_context_gl_get_tex_unit_mapping(const struct wined3d
*count = 0;
}
return context_gl->c.tex_unit_map;
return context_gl->tex_unit_map;
}
static void context_get_rt_size(const struct wined3d_context *context, SIZE *size)
......@@ -2826,7 +2826,7 @@ void wined3d_context_gl_apply_blit_state(struct wined3d_context_gl *context_gl,
GL_EXTCALL(glBindSampler(0, 0));
context_active_texture(context, gl_info, 0);
sampler = context->rev_tex_unit_map[0];
sampler = context_gl->rev_tex_unit_map[0];
if (sampler != WINED3D_UNMAPPED_STAGE)
{
if (sampler < WINED3D_MAX_TEXTURES)
......@@ -2950,7 +2950,7 @@ void wined3d_context_gl_apply_ffp_blit_state(struct wined3d_context_gl *context_
gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
sampler = context->rev_tex_unit_map[i];
sampler = context_gl->rev_tex_unit_map[i];
if (sampler != WINED3D_UNMAPPED_STAGE)
{
if (sampler < WINED3D_MAX_TEXTURES)
......@@ -3226,17 +3226,17 @@ void context_state_fb(struct wined3d_context *context, const struct wined3d_stat
static void wined3d_context_gl_map_stage(struct wined3d_context_gl *context_gl, unsigned int stage, unsigned int unit)
{
unsigned int i = context_gl->c.rev_tex_unit_map[unit];
unsigned int j = context_gl->c.tex_unit_map[stage];
unsigned int i = context_gl->rev_tex_unit_map[unit];
unsigned int j = context_gl->tex_unit_map[stage];
TRACE("Mapping stage %u to unit %u.\n", stage, unit);
context_gl->c.tex_unit_map[stage] = unit;
context_gl->tex_unit_map[stage] = unit;
if (i != WINED3D_UNMAPPED_STAGE && i != stage)
context_gl->c.tex_unit_map[i] = WINED3D_UNMAPPED_STAGE;
context_gl->tex_unit_map[i] = WINED3D_UNMAPPED_STAGE;
context_gl->c.rev_tex_unit_map[unit] = stage;
context_gl->rev_tex_unit_map[unit] = stage;
if (j != WINED3D_UNMAPPED_STAGE && j != unit)
context_gl->c.rev_tex_unit_map[j] = WINED3D_UNMAPPED_STAGE;
context_gl->rev_tex_unit_map[j] = WINED3D_UNMAPPED_STAGE;
}
static void context_invalidate_texture_stage(struct wined3d_context *context, DWORD stage)
......@@ -3318,7 +3318,7 @@ static void wined3d_context_gl_map_fixed_function_samplers(struct wined3d_contex
if (!(ffu_map & 1))
continue;
if (context_gl->c.tex_unit_map[i] != i)
if (context_gl->tex_unit_map[i] != i)
{
wined3d_context_gl_map_stage(context_gl, i, i);
context_invalidate_state(&context_gl->c, STATE_SAMPLER(i));
......@@ -3335,7 +3335,7 @@ static void wined3d_context_gl_map_fixed_function_samplers(struct wined3d_contex
if (!(ffu_map & 1))
continue;
if (context_gl->c.tex_unit_map[i] != tex)
if (context_gl->tex_unit_map[i] != tex)
{
wined3d_context_gl_map_stage(context_gl, i, tex);
context_invalidate_state(&context_gl->c, STATE_SAMPLER(i));
......@@ -3355,7 +3355,7 @@ static void wined3d_context_gl_map_psamplers(struct wined3d_context_gl *context_
for (i = 0; i < WINED3D_MAX_FRAGMENT_SAMPLERS; ++i)
{
if (resource_info[i].type && context_gl->c.tex_unit_map[i] != i)
if (resource_info[i].type && context_gl->tex_unit_map[i] != i)
{
wined3d_context_gl_map_stage(context_gl, i, i);
context_invalidate_state(&context_gl->c, STATE_SAMPLER(i));
......@@ -3368,7 +3368,7 @@ static void wined3d_context_gl_map_psamplers(struct wined3d_context_gl *context_
static BOOL wined3d_context_gl_unit_free_for_vs(const struct wined3d_context_gl *context_gl,
const struct wined3d_shader_resource_info *ps_resource_info, unsigned int unit)
{
unsigned int current_mapping = context_gl->c.rev_tex_unit_map[unit];
unsigned int current_mapping = context_gl->rev_tex_unit_map[unit];
/* Not currently used */
if (current_mapping == WINED3D_UNMAPPED_STAGE)
......@@ -3417,7 +3417,7 @@ static void wined3d_context_gl_map_vsamplers(struct wined3d_context_gl *context_
{
if (wined3d_context_gl_unit_free_for_vs(context_gl, ps_resource_info, start))
{
if (context_gl->c.tex_unit_map[vsampler_idx] != start)
if (context_gl->tex_unit_map[vsampler_idx] != start)
{
wined3d_context_gl_map_stage(context_gl, vsampler_idx, start);
context_invalidate_state(&context_gl->c, STATE_SAMPLER(vsampler_idx));
......@@ -3429,7 +3429,7 @@ static void wined3d_context_gl_map_vsamplers(struct wined3d_context_gl *context_
--start;
}
if (context_gl->c.tex_unit_map[vsampler_idx] == WINED3D_UNMAPPED_STAGE)
if (context_gl->tex_unit_map[vsampler_idx] == WINED3D_UNMAPPED_STAGE)
WARN("Couldn't find a free texture unit for vertex sampler %u.\n", i);
}
}
......@@ -4636,7 +4636,7 @@ static void draw_primitive_immediate_mode(struct wined3d_context_gl *context_gl,
if (!ps && !state->textures[texture_idx])
continue;
texture_unit = context_gl->c.tex_unit_map[texture_idx];
texture_unit = context_gl->tex_unit_map[texture_idx];
if (texture_unit == WINED3D_UNMAPPED_STAGE)
continue;
......@@ -4714,7 +4714,7 @@ static void draw_primitive_immediate_mode(struct wined3d_context_gl *context_gl,
coord_idx = state->texture_states[texture_idx][WINED3D_TSS_TEXCOORD_INDEX];
ptr = tex_coords[coord_idx] + (stride_idx * si->elements[WINED3D_FFP_TEXCOORD0 + coord_idx].stride);
ops->texcoord[si->elements[WINED3D_FFP_TEXCOORD0 + coord_idx].format->emit_idx](
GL_TEXTURE0_ARB + context_gl->c.tex_unit_map[texture_idx], ptr);
GL_TEXTURE0_ARB + context_gl->tex_unit_map[texture_idx], ptr);
}
if (position)
......@@ -5060,7 +5060,7 @@ void wined3d_context_gl_load_tex_coords(const struct wined3d_context_gl *context
{
unsigned int coord_idx = state->texture_states[texture_idx][WINED3D_TSS_TEXCOORD_INDEX];
if ((mapped_stage = context_gl->c.tex_unit_map[texture_idx]) == WINED3D_UNMAPPED_STAGE)
if ((mapped_stage = context_gl->tex_unit_map[texture_idx]) == WINED3D_UNMAPPED_STAGE)
continue;
if (mapped_stage >= gl_info->limits.texture_coords)
......
......@@ -482,8 +482,9 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d
static void nvrc_colorop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{
DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
BOOL tex_used = context->fixed_function_usage_map & (1u << stage);
DWORD mapped_stage = context->tex_unit_map[stage];
unsigned int mapped_stage = context_gl->tex_unit_map[stage];
const struct wined3d_gl_info *gl_info = context->gl_info;
TRACE("Setting color op for stage %u.\n", stage);
......@@ -603,8 +604,11 @@ static void nvrc_resultarg(struct wined3d_context *context, const struct wined3d
static void nvts_texdim(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{
DWORD sampler = state_id - STATE_SAMPLER(0);
DWORD mapped_stage = context->tex_unit_map[sampler];
struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
unsigned int sampler, mapped_stage;
sampler = state_id - STATE_SAMPLER(0);
mapped_stage = context_gl->tex_unit_map[sampler];
/* No need to enable / disable anything here for unused samplers. The tex_colorop
* handler takes care. Also no action is needed with pixel shaders, or if tex_colorop
......@@ -622,7 +626,8 @@ static void nvts_texdim(struct wined3d_context *context, const struct wined3d_st
static void nvts_bumpenvmat(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{
DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
DWORD mapped_stage = context->tex_unit_map[stage + 1];
struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
unsigned int mapped_stage = context_gl->tex_unit_map[stage + 1];
const struct wined3d_gl_info *gl_info = context->gl_info;
float mat[2][2];
......
......@@ -3127,9 +3127,9 @@ static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined
static void tex_colorop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{
DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
unsigned int stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
unsigned int mapped_stage = wined3d_context_gl(context)->tex_unit_map[stage];
BOOL tex_used = context->fixed_function_usage_map & (1u << stage);
DWORD mapped_stage = context->tex_unit_map[stage];
const struct wined3d_gl_info *gl_info = context->gl_info;
TRACE("Setting color op for stage %d\n", stage);
......@@ -3188,9 +3188,9 @@ static void tex_colorop(struct wined3d_context *context, const struct wined3d_st
void tex_alphaop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{
DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
unsigned int stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
unsigned int mapped_stage = wined3d_context_gl(context)->tex_unit_map[stage];
BOOL tex_used = context->fixed_function_usage_map & (1u << stage);
DWORD mapped_stage = context->tex_unit_map[stage];
const struct wined3d_gl_info *gl_info = context->gl_info;
DWORD op, arg1, arg2, arg0;
......@@ -3287,9 +3287,9 @@ void tex_alphaop(struct wined3d_context *context, const struct wined3d_state *st
static void transform_texture(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{
const struct wined3d_gl_info *gl_info = context->gl_info;
unsigned int tex = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
unsigned int mapped_stage = context->tex_unit_map[tex];
unsigned int mapped_stage = wined3d_context_gl(context)->tex_unit_map[tex];
const struct wined3d_gl_info *gl_info = context->gl_info;
struct wined3d_matrix mat;
/* Ignore this when a vertex shader is used, or if the streams aren't sorted out yet */
......@@ -3314,14 +3314,15 @@ static void transform_texture(struct wined3d_context *context, const struct wine
static void tex_coordindex(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{
DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
unsigned int stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
unsigned int mapped_stage = context_gl->tex_unit_map[stage];
const struct wined3d_gl_info *gl_info = context->gl_info;
static const GLfloat s_plane[] = { 1.0f, 0.0f, 0.0f, 0.0f };
static const GLfloat t_plane[] = { 0.0f, 1.0f, 0.0f, 0.0f };
static const GLfloat r_plane[] = { 0.0f, 0.0f, 1.0f, 0.0f };
static const GLfloat q_plane[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const struct wined3d_gl_info *gl_info = context->gl_info;
DWORD mapped_stage = context->tex_unit_map[stage];
if (mapped_stage == WINED3D_UNMAPPED_STAGE)
{
......@@ -3598,8 +3599,8 @@ static void wined3d_sampler_desc_from_sampler_states(struct wined3d_sampler_desc
static void sampler(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{
struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
DWORD sampler_idx = state_id - STATE_SAMPLER(0);
DWORD mapped_stage = context->tex_unit_map[sampler_idx];
unsigned int sampler_idx = state_id - STATE_SAMPLER(0);
unsigned int mapped_stage = context_gl->tex_unit_map[sampler_idx];
const struct wined3d_gl_info *gl_info = context->gl_info;
TRACE("Sampler %u.\n", sampler_idx);
......
......@@ -1061,9 +1061,9 @@ void wined3d_texture_gl_bind_and_dirtify(struct wined3d_texture_gl *texture_gl,
* called from sampler() in state.c. This means we can't touch anything
* other than whatever happens to be the currently active texture, or we
* would risk marking already applied sampler states dirty again. */
if (context_gl->c.active_texture < ARRAY_SIZE(context_gl->c.rev_tex_unit_map))
if (context_gl->c.active_texture < ARRAY_SIZE(context_gl->rev_tex_unit_map))
{
DWORD active_sampler = context_gl->c.rev_tex_unit_map[context_gl->c.active_texture];
unsigned int active_sampler = context_gl->rev_tex_unit_map[context_gl->c.active_texture];
if (active_sampler != WINED3D_UNMAPPED_STAGE)
context_invalidate_state(&context_gl->c, STATE_SAMPLER(active_sampler));
}
......
......@@ -6354,8 +6354,8 @@ void texture_activate_dimensions(struct wined3d_texture *texture, const struct w
/* Context activation is done by the caller (state handler). */
void sampler_texdim(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{
DWORD sampler = state_id - STATE_SAMPLER(0);
DWORD mapped_stage = context->tex_unit_map[sampler];
unsigned int sampler = state_id - STATE_SAMPLER(0);
unsigned int mapped_stage = wined3d_context_gl(context)->tex_unit_map[sampler];
/* No need to enable / disable anything here for unused samplers. The
* tex_colorop handler takes care. Also no action is needed with pixel
......
......@@ -860,9 +860,9 @@ static void shader_resource_view_gl_bind_and_dirtify(struct wined3d_shader_resou
{
struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
if (context->active_texture < ARRAY_SIZE(context->rev_tex_unit_map))
if (context->active_texture < ARRAY_SIZE(context_gl->rev_tex_unit_map))
{
DWORD active_sampler = context->rev_tex_unit_map[context->active_texture];
unsigned int active_sampler = context_gl->rev_tex_unit_map[context->active_texture];
if (active_sampler != WINED3D_UNMAPPED_STAGE)
context_invalidate_state(context, STATE_SAMPLER(active_sampler));
}
......
......@@ -2015,9 +2015,6 @@ struct wined3d_context
GLuint blit_vbo;
DWORD tex_unit_map[WINED3D_MAX_COMBINED_SAMPLERS];
DWORD rev_tex_unit_map[MAX_GL_FRAGMENT_SAMPLERS + WINED3D_MAX_VERTEX_SAMPLERS];
unsigned int viewport_count;
unsigned int scissor_rect_count;
};
......@@ -2036,6 +2033,9 @@ struct wined3d_context_gl
GLenum *texture_type;
unsigned int tex_unit_map[WINED3D_MAX_COMBINED_SAMPLERS];
unsigned int rev_tex_unit_map[MAX_GL_FRAGMENT_SAMPLERS + WINED3D_MAX_VERTEX_SAMPLERS];
/* Extension emulation. */
GLint gl_fog_source;
GLfloat fog_coord_value;
......
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