Commit f47f9f7c authored by Matteo Bruni's avatar Matteo Bruni Committed by Alexandre Julliard

wined3d: Store currently active texture in the wined3d context.

parent e53ae83d
...@@ -6875,7 +6875,7 @@ static GLuint gen_p8_shader(struct arbfp_blit_priv *priv, ...@@ -6875,7 +6875,7 @@ static GLuint gen_p8_shader(struct arbfp_blit_priv *priv,
} }
/* Context activation is done by the caller. */ /* Context activation is done by the caller. */
static void upload_palette(struct wined3d_surface *surface) static void upload_palette(struct wined3d_surface *surface, struct wined3d_context *context)
{ {
BYTE table[256][4]; BYTE table[256][4];
struct wined3d_device *device = surface->resource.device; struct wined3d_device *device = surface->resource.device;
...@@ -6903,7 +6903,7 @@ static void upload_palette(struct wined3d_surface *surface) ...@@ -6903,7 +6903,7 @@ static void upload_palette(struct wined3d_surface *surface)
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, table); glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, table);
/* Switch back to unit 0 in which the 2D texture will be stored. */ /* Switch back to unit 0 in which the 2D texture will be stored. */
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0)); context_active_texture(context, gl_info, 0);
LEAVE_GL(); LEAVE_GL();
} }
...@@ -7105,7 +7105,7 @@ static HRESULT arbfp_blit_set(void *blit_priv, struct wined3d_context *context, ...@@ -7105,7 +7105,7 @@ static HRESULT arbfp_blit_set(void *blit_priv, struct wined3d_context *context,
shader = textype == GL_TEXTURE_RECTANGLE_ARB ? priv->p8_rect_shader : priv->p8_2d_shader; shader = textype == GL_TEXTURE_RECTANGLE_ARB ? priv->p8_rect_shader : priv->p8_2d_shader;
if (!shader) shader = gen_p8_shader(priv, gl_info, textype); if (!shader) shader = gen_p8_shader(priv, gl_info, textype);
upload_palette(surface); upload_palette(surface, context);
break; break;
default: default:
......
...@@ -837,8 +837,7 @@ static void set_tex_op_atifs(struct wined3d_context *context, const struct wined ...@@ -837,8 +837,7 @@ static void set_tex_op_atifs(struct wined3d_context *context, const struct wined
mapped_stage = device->texUnitMap[i]; mapped_stage = device->texUnitMap[i];
if (mapped_stage != WINED3D_UNMAPPED_STAGE) if (mapped_stage != WINED3D_UNMAPPED_STAGE)
{ {
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); context_active_texture(context, gl_info, mapped_stage);
checkGLcall("glActiveTextureARB");
texture_activate_dimensions(state->textures[i], gl_info); texture_activate_dimensions(state->textures[i], gl_info);
} }
} }
......
...@@ -1498,7 +1498,7 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, ...@@ -1498,7 +1498,7 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain,
*/ */
for (s = 1; s < gl_info->limits.textures; ++s) for (s = 1; s < gl_info->limits.textures; ++s)
{ {
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + s)); context_active_texture(ret, gl_info, s);
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB + s - 1); glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB + s - 1);
checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, ..."); checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, ...");
} }
...@@ -1527,7 +1527,7 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, ...@@ -1527,7 +1527,7 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain,
{ {
for (s = 0; s < gl_info->limits.textures; ++s) for (s = 0; s < gl_info->limits.textures; ++s)
{ {
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + s)); context_active_texture(ret, gl_info, s);
glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE); glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
checkGLcall("glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE)"); checkGLcall("glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE)");
} }
...@@ -1667,8 +1667,7 @@ static void SetupForBlit(struct wined3d_device *device, struct wined3d_context * ...@@ -1667,8 +1667,7 @@ static void SetupForBlit(struct wined3d_device *device, struct wined3d_context *
for (i = gl_info->limits.textures - 1; i > 0 ; --i) for (i = gl_info->limits.textures - 1; i > 0 ; --i)
{ {
sampler = device->rev_tex_unit_map[i]; sampler = device->rev_tex_unit_map[i];
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + i)); context_active_texture(context, gl_info, i);
checkGLcall("glActiveTextureARB");
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP]) if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
{ {
...@@ -1695,8 +1694,7 @@ static void SetupForBlit(struct wined3d_device *device, struct wined3d_context * ...@@ -1695,8 +1694,7 @@ static void SetupForBlit(struct wined3d_device *device, struct wined3d_context *
context_invalidate_state(context, STATE_SAMPLER(sampler)); context_invalidate_state(context, STATE_SAMPLER(sampler));
} }
} }
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB)); context_active_texture(context, gl_info, 0);
checkGLcall("glActiveTextureARB");
sampler = device->rev_tex_unit_map[0]; sampler = device->rev_tex_unit_map[0];
...@@ -1882,6 +1880,14 @@ void context_set_draw_buffer(struct wined3d_context *context, GLenum buffer) ...@@ -1882,6 +1880,14 @@ void context_set_draw_buffer(struct wined3d_context *context, GLenum buffer)
context->draw_buffers_mask = context_generate_rt_mask(buffer); context->draw_buffers_mask = context_generate_rt_mask(buffer);
} }
/* GL locking is done by the caller. */
void context_active_texture(struct wined3d_context *context, const struct wined3d_gl_info *gl_info, unsigned int unit)
{
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0 + unit));
checkGLcall("glActiveTextureARB");
context->active_texture = unit;
}
static void context_set_render_offscreen(struct wined3d_context *context, BOOL offscreen) static void context_set_render_offscreen(struct wined3d_context *context, BOOL offscreen)
{ {
if (context->render_offscreen == offscreen) return; if (context->render_offscreen == offscreen) return;
......
...@@ -967,7 +967,7 @@ out: ...@@ -967,7 +967,7 @@ out:
} }
/* Context activation is done by the caller. */ /* Context activation is done by the caller. */
static void create_dummy_textures(struct wined3d_device *device) static void create_dummy_textures(struct wined3d_device *device, struct wined3d_context *context)
{ {
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
unsigned int i; unsigned int i;
...@@ -989,8 +989,7 @@ static void create_dummy_textures(struct wined3d_device *device) ...@@ -989,8 +989,7 @@ static void create_dummy_textures(struct wined3d_device *device)
DWORD color = 0x000000ff; DWORD color = 0x000000ff;
/* Make appropriate texture active */ /* Make appropriate texture active */
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + i)); context_active_texture(context, gl_info, i);
checkGLcall("glActiveTextureARB");
/* Generate an opengl texture name */ /* Generate an opengl texture name */
glGenTextures(1, &device->dummyTextureName[i]); glGenTextures(1, &device->dummyTextureName[i]);
...@@ -1272,7 +1271,7 @@ HRESULT CDECL wined3d_device_init_3d(struct wined3d_device *device, ...@@ -1272,7 +1271,7 @@ HRESULT CDECL wined3d_device_init_3d(struct wined3d_device *device,
context = context_acquire(device, swapchain->front_buffer); context = context_acquire(device, swapchain->front_buffer);
create_dummy_textures(device); create_dummy_textures(device, context);
ENTER_GL(); ENTER_GL();
...@@ -4833,8 +4832,7 @@ HRESULT CDECL wined3d_device_update_surface(struct wined3d_device *device, ...@@ -4833,8 +4832,7 @@ HRESULT CDECL wined3d_device_update_surface(struct wined3d_device *device,
gl_info = context->gl_info; gl_info = context->gl_info;
ENTER_GL(); ENTER_GL();
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB)); context_active_texture(context, gl_info, 0);
checkGLcall("glActiveTextureARB");
LEAVE_GL(); LEAVE_GL();
/* Only load the surface for partial updates. For newly allocated texture /* Only load the surface for partial updates. For newly allocated texture
...@@ -5281,8 +5279,7 @@ HRESULT CDECL wined3d_device_set_cursor_properties(struct wined3d_device *device ...@@ -5281,8 +5279,7 @@ HRESULT CDECL wined3d_device_set_cursor_properties(struct wined3d_device *device
} }
/* Make sure that a proper texture unit is selected */ /* Make sure that a proper texture unit is selected */
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB)); context_active_texture(context, gl_info, 0);
checkGLcall("glActiveTextureARB");
sampler = device->rev_tex_unit_map[0]; sampler = device->rev_tex_unit_map[0];
if (sampler != WINED3D_UNMAPPED_STAGE) if (sampler != WINED3D_UNMAPPED_STAGE)
context_invalidate_state(context, STATE_SAMPLER(sampler)); context_invalidate_state(context, STATE_SAMPLER(sampler));
...@@ -5588,7 +5585,7 @@ static HRESULT create_primary_opengl_context(struct wined3d_device *device, stru ...@@ -5588,7 +5585,7 @@ static HRESULT create_primary_opengl_context(struct wined3d_device *device, stru
swapchain->context[0] = context; swapchain->context[0] = context;
swapchain->num_contexts = 1; swapchain->num_contexts = 1;
create_dummy_textures(device); create_dummy_textures(device, context);
context_release(context); context_release(context);
hr = device->shader_backend->shader_alloc_private(device); hr = device->shader_backend->shader_alloc_private(device);
......
...@@ -479,8 +479,7 @@ static void nvrc_colorop(struct wined3d_context *context, const struct wined3d_s ...@@ -479,8 +479,7 @@ static void nvrc_colorop(struct wined3d_context *context, const struct wined3d_s
FIXME("Attempt to enable unsupported stage!\n"); FIXME("Attempt to enable unsupported stage!\n");
return; return;
} }
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); context_active_texture(context, gl_info, mapped_stage);
checkGLcall("glActiveTextureARB");
} }
if (state->lowest_disabled_stage > 0) if (state->lowest_disabled_stage > 0)
...@@ -558,11 +557,9 @@ static void nvrc_colorop(struct wined3d_context *context, const struct wined3d_s ...@@ -558,11 +557,9 @@ static void nvrc_colorop(struct wined3d_context *context, const struct wined3d_s
BOOL usedBump = !!(context->texShaderBumpMap & 1 << (stage + 1)); BOOL usedBump = !!(context->texShaderBumpMap & 1 << (stage + 1));
if (usesBump != usedBump) if (usesBump != usedBump)
{ {
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage + 1)); context_active_texture(context, gl_info, mapped_stage + 1);
checkGLcall("glActiveTextureARB");
nvts_activate_dimensions(state, stage + 1, context); nvts_activate_dimensions(state, stage + 1, context);
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); context_active_texture(context, gl_info, mapped_stage);
checkGLcall("glActiveTextureARB");
} }
} }
} }
...@@ -598,8 +595,7 @@ static void nvts_bumpenvmat(struct wined3d_context *context, const struct wined3 ...@@ -598,8 +595,7 @@ static void nvts_bumpenvmat(struct wined3d_context *context, const struct wined3
*/ */
if (mapped_stage < gl_info->limits.textures) if (mapped_stage < gl_info->limits.textures)
{ {
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); context_active_texture(context, gl_info, mapped_stage);
checkGLcall("GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage))");
/* We can't just pass a pointer to the state to GL due to the /* We can't just pass a pointer to the state to GL due to the
* different matrix format (column major vs row major). */ * different matrix format (column major vs row major). */
......
...@@ -753,8 +753,7 @@ static void state_texfactor(struct wined3d_context *context, const struct wined3 ...@@ -753,8 +753,7 @@ static void state_texfactor(struct wined3d_context *context, const struct wined3
/* Note the WINED3DRS value applies to all textures, but GL has one /* Note the WINED3DRS value applies to all textures, but GL has one
* per texture, so apply it now ready to be used! * per texture, so apply it now ready to be used!
*/ */
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + i)); context_active_texture(context, gl_info, i);
checkGLcall("glActiveTextureARB");
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &col[0]); glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &col[0]);
checkGLcall("glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);"); checkGLcall("glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);");
...@@ -3031,8 +3030,7 @@ static void tex_colorop(struct wined3d_context *context, const struct wined3d_st ...@@ -3031,8 +3030,7 @@ static void tex_colorop(struct wined3d_context *context, const struct wined3d_st
FIXME("Attempt to enable unsupported stage!\n"); FIXME("Attempt to enable unsupported stage!\n");
return; return;
} }
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); context_active_texture(context, gl_info, mapped_stage);
checkGLcall("glActiveTextureARB");
} }
if (stage >= state->lowest_disabled_stage) if (stage >= state->lowest_disabled_stage)
...@@ -3090,8 +3088,7 @@ void tex_alphaop(struct wined3d_context *context, const struct wined3d_state *st ...@@ -3090,8 +3088,7 @@ void tex_alphaop(struct wined3d_context *context, const struct wined3d_state *st
FIXME("Attempt to enable unsupported stage!\n"); FIXME("Attempt to enable unsupported stage!\n");
return; return;
} }
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); context_active_texture(context, gl_info, mapped_stage);
checkGLcall("glActiveTextureARB");
} }
op = state->texture_states[stage][WINED3DTSS_ALPHAOP]; op = state->texture_states[stage][WINED3DTSS_ALPHAOP];
...@@ -3193,8 +3190,7 @@ static void transform_texture(struct wined3d_context *context, const struct wine ...@@ -3193,8 +3190,7 @@ static void transform_texture(struct wined3d_context *context, const struct wine
if (mapped_stage == WINED3D_UNMAPPED_STAGE) return; if (mapped_stage == WINED3D_UNMAPPED_STAGE) return;
if (mapped_stage >= gl_info->limits.textures) return; if (mapped_stage >= gl_info->limits.textures) return;
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); context_active_texture(context, gl_info, mapped_stage);
checkGLcall("glActiveTextureARB");
generated = (state->texture_states[texUnit][WINED3DTSS_TEXCOORDINDEX] & 0xffff0000) != WINED3DTSS_TCI_PASSTHRU; generated = (state->texture_states[texUnit][WINED3DTSS_TEXCOORDINDEX] & 0xffff0000) != WINED3DTSS_TCI_PASSTHRU;
coordIdx = min(state->texture_states[texUnit][WINED3DTSS_TEXCOORDINDEX & 0x0000ffff], MAX_TEXTURES - 1); coordIdx = min(state->texture_states[texUnit][WINED3DTSS_TEXCOORDINDEX & 0x0000ffff], MAX_TEXTURES - 1);
...@@ -3309,8 +3305,7 @@ static void tex_coordindex(struct wined3d_context *context, const struct wined3d ...@@ -3309,8 +3305,7 @@ static void tex_coordindex(struct wined3d_context *context, const struct wined3d
WARN("stage %u not mapped to a valid texture unit (%u)\n", stage, mapped_stage); WARN("stage %u not mapped to a valid texture unit (%u)\n", stage, mapped_stage);
return; return;
} }
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); context_active_texture(context, gl_info, mapped_stage);
checkGLcall("glActiveTextureARB");
/* Values 0-7 are indexes into the FVF tex coords - See comments in DrawPrimitive /* Values 0-7 are indexes into the FVF tex coords - See comments in DrawPrimitive
* *
...@@ -3538,8 +3533,7 @@ static void sampler(struct wined3d_context *context, const struct wined3d_state ...@@ -3538,8 +3533,7 @@ static void sampler(struct wined3d_context *context, const struct wined3d_state
{ {
return; return;
} }
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); context_active_texture(context, gl_info, mapped_stage);
checkGLcall("glActiveTextureARB");
if (state->textures[sampler]) if (state->textures[sampler])
{ {
......
...@@ -5602,7 +5602,7 @@ static void surface_depth_blt(const struct wined3d_surface *surface, struct wine ...@@ -5602,7 +5602,7 @@ static void surface_depth_blt(const struct wined3d_surface *surface, struct wine
SetRect(&rect, 0, h, w, 0); SetRect(&rect, 0, h, w, 0);
surface_get_blt_info(target, &rect, surface->pow2Width, surface->pow2Height, &info); surface_get_blt_info(target, &rect, surface->pow2Width, surface->pow2Height, &info);
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB)); context_active_texture(context, context->gl_info, 0);
glGetIntegerv(info.binding, &old_binding); glGetIntegerv(info.binding, &old_binding);
glBindTexture(info.bind_target, texture); glBindTexture(info.bind_target, texture);
if (gl_info->supported[ARB_SHADOW]) if (gl_info->supported[ARB_SHADOW])
......
...@@ -1088,6 +1088,7 @@ struct wined3d_context ...@@ -1088,6 +1088,7 @@ struct wined3d_context
GLenum untracked_materials[2]; GLenum untracked_materials[2];
UINT blit_w, blit_h; UINT blit_w, blit_h;
enum fogsource fog_source; enum fogsource fog_source;
DWORD active_texture;
char *vshader_const_dirty, *pshader_const_dirty; char *vshader_const_dirty, *pshader_const_dirty;
...@@ -1234,6 +1235,8 @@ BOOL context_apply_clear_state(struct wined3d_context *context, struct wined3d_d ...@@ -1234,6 +1235,8 @@ BOOL context_apply_clear_state(struct wined3d_context *context, struct wined3d_d
BOOL context_apply_draw_state(struct wined3d_context *context, struct wined3d_device *device) DECLSPEC_HIDDEN; BOOL context_apply_draw_state(struct wined3d_context *context, struct wined3d_device *device) DECLSPEC_HIDDEN;
void context_apply_fbo_state_blit(struct wined3d_context *context, GLenum target, void context_apply_fbo_state_blit(struct wined3d_context *context, GLenum target,
struct wined3d_surface *render_target, struct wined3d_surface *depth_stencil, DWORD location) DECLSPEC_HIDDEN; struct wined3d_surface *render_target, struct wined3d_surface *depth_stencil, DWORD location) DECLSPEC_HIDDEN;
void context_active_texture(struct wined3d_context *context, const struct wined3d_gl_info *gl_info,
unsigned int unit) DECLSPEC_HIDDEN;
void context_check_fbo_status(const struct wined3d_context *context, GLenum target) DECLSPEC_HIDDEN; void context_check_fbo_status(const struct wined3d_context *context, GLenum target) DECLSPEC_HIDDEN;
struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, struct wined3d_surface *target, struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, struct wined3d_surface *target,
const struct wined3d_format *ds_format) DECLSPEC_HIDDEN; const struct wined3d_format *ds_format) DECLSPEC_HIDDEN;
......
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