From 9224751a13dae4efbc809f4319c0de264712abcb Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Tue, 28 Sep 2010 12:00:23 +0200 Subject: [PATCH] wined3d: Pass a wined3d_state structure to use_vs(). --- dlls/wined3d/arb_program_shader.c | 34 +++++---- dlls/wined3d/ati_fragment_shader.c | 5 +- dlls/wined3d/buffer.c | 5 +- dlls/wined3d/device.c | 9 ++- dlls/wined3d/drawprim.c | 25 +++--- dlls/wined3d/glsl_shader.c | 5 +- dlls/wined3d/shader.c | 15 ++-- dlls/wined3d/state.c | 118 +++++++++++++++-------------- dlls/wined3d/utils.c | 4 +- dlls/wined3d/wined3d_private.h | 5 +- 10 files changed, 121 insertions(+), 104 deletions(-) diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c index ed80577ddca..d2d5bdb01a5 100644 --- a/dlls/wined3d/arb_program_shader.c +++ b/dlls/wined3d/arb_program_shader.c @@ -4396,6 +4396,8 @@ static inline void find_arb_ps_compile_args(IWineD3DPixelShaderImpl *shader, IWi int i; WORD int_skip; const struct wined3d_gl_info *gl_info = &((IWineD3DDeviceImpl *)shader->baseShader.device)->adapter->gl_info; + const struct wined3d_state *state = &stateblock->state; + find_ps_compile_args(shader, stateblock, &args->super); /* This forces all local boolean constants to 1 to make them stateblock independent */ @@ -4403,7 +4405,7 @@ static inline void find_arb_ps_compile_args(IWineD3DPixelShaderImpl *shader, IWi for(i = 0; i < MAX_CONST_B; i++) { - if (stateblock->state.ps_consts_b[i]) + if (state->ps_consts_b[i]) args->bools |= ( 1 << i); } @@ -4411,9 +4413,9 @@ static inline void find_arb_ps_compile_args(IWineD3DPixelShaderImpl *shader, IWi * is quite expensive because it forces the driver to disable early Z discards. It is cheaper to * duplicate the shader than have a no-op KIL instruction in every shader */ - if ((!((IWineD3DDeviceImpl *)shader->baseShader.device)->vs_clipping) && use_vs(stateblock) - && stateblock->state.render_states[WINED3DRS_CLIPPING] - && stateblock->state.render_states[WINED3DRS_CLIPPLANEENABLE]) + if ((!((IWineD3DDeviceImpl *)shader->baseShader.device)->vs_clipping) && use_vs(state) + && state->render_states[WINED3DRS_CLIPPING] + && state->render_states[WINED3DRS_CLIPPLANEENABLE]) args->clip = 1; else args->clip = 0; @@ -4436,9 +4438,9 @@ static inline void find_arb_ps_compile_args(IWineD3DPixelShaderImpl *shader, IWi } else { - args->loop_ctrl[i][0] = stateblock->state.ps_consts_i[i * 4]; - args->loop_ctrl[i][1] = stateblock->state.ps_consts_i[i * 4 + 1]; - args->loop_ctrl[i][2] = stateblock->state.ps_consts_i[i * 4 + 2]; + args->loop_ctrl[i][0] = state->ps_consts_i[i * 4]; + args->loop_ctrl[i][1] = state->ps_consts_i[i * 4 + 1]; + args->loop_ctrl[i][2] = state->ps_consts_i[i * 4 + 2]; } } } @@ -6152,8 +6154,8 @@ static void fragment_prog_arbfp(DWORD state, IWineD3DStateBlockImpl *stateblock, const struct wined3d_gl_info *gl_info = context->gl_info; IWineD3DDeviceImpl *device = stateblock->device; struct shader_arb_priv *priv = device->fragment_priv; + BOOL use_vshader = use_vs(&stateblock->state); BOOL use_pshader = use_ps(stateblock); - BOOL use_vshader = use_vs(stateblock); struct ffp_frag_settings settings; const struct arbfp_ffp_desc *desc; unsigned int i; @@ -6244,26 +6246,28 @@ static void fragment_prog_arbfp(DWORD state, IWineD3DStateBlockImpl *stateblock, * is that changing the fog start and fog end(which links to FOGENABLE in vertex) results in the * fragment_prog_arbfp function being called because FOGENABLE is dirty, which calls this function here */ -static void state_arbfp_fog(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context) +static void state_arbfp_fog(DWORD state_id, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context) { + const struct wined3d_state *state = &stateblock->state; enum fogsource new_source; - TRACE("state %#x, stateblock %p, context %p\n", state, stateblock, context); + TRACE("state_id %#x, stateblock %p, context %p\n", state_id, stateblock, context); if(!isStateDirty(context, STATE_PIXELSHADER)) { - fragment_prog_arbfp(state, stateblock, context); + fragment_prog_arbfp(state_id, stateblock, context); } - if (!stateblock->state.render_states[WINED3DRS_FOGENABLE]) return; + if (!state->render_states[WINED3DRS_FOGENABLE]) return; - if (stateblock->state.render_states[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE) + if (state->render_states[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE) { - if(use_vs(stateblock)) { + if (use_vs(state)) + { new_source = FOGSOURCE_VS; } else { - if (stateblock->state.render_states[WINED3DRS_FOGVERTEXMODE] == WINED3DFOG_NONE || context->last_was_rhw) + if (state->render_states[WINED3DRS_FOGVERTEXMODE] == WINED3DFOG_NONE || context->last_was_rhw) new_source = FOGSOURCE_COORD; else new_source = FOGSOURCE_FFP; diff --git a/dlls/wined3d/ati_fragment_shader.c b/dlls/wined3d/ati_fragment_shader.c index cf856080b98..5cecb7159d0 100644 --- a/dlls/wined3d/ati_fragment_shader.c +++ b/dlls/wined3d/ati_fragment_shader.c @@ -887,10 +887,11 @@ static void textransform(DWORD state, IWineD3DStateBlockImpl *stateblock, struct } } -static void atifs_apply_pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context) +static void atifs_apply_pixelshader(DWORD state_id, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context) { + const struct wined3d_state *state = &stateblock->state; IWineD3DDeviceImpl *device = stateblock->device; - BOOL use_vshader = use_vs(stateblock); + BOOL use_vshader = use_vs(state); context->last_was_pshader = use_ps(stateblock); /* The ATIFS code does not support pixel shaders currently, but we have to provide a state handler diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index 2a89b8467d7..23b4a4ad67c 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -401,6 +401,7 @@ static BOOL buffer_find_decl(struct wined3d_buffer *This) IWineD3DDeviceImpl *device = This->resource.device; const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; const struct wined3d_stream_info *si = &device->strided_streams; + const struct wined3d_state *state = &device->stateBlock->state; UINT stride_this_run = 0; BOOL float16_used = FALSE; BOOL ret = FALSE; @@ -460,14 +461,14 @@ static BOOL buffer_find_decl(struct wined3d_buffer *This) * conversion types depend on the semantic as well, for example a FLOAT4 * texcoord needs no conversion while a FLOAT4 positiont needs one */ - if (use_vs(device->stateBlock)) + if (use_vs(state)) { TRACE("vshader\n"); /* If the current vertex declaration is marked for no half float conversion don't bother to * analyse the strided streams in depth, just set them up for no conversion. Return decl changed * if we used conversion before */ - if (!device->stateBlock->state.vertex_declaration->half_float_conv_needed) + if (!state->vertex_declaration->half_float_conv_needed) { if (This->conversion_map) { diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index c1ce5f85a9b..955f440c1e3 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -466,13 +466,14 @@ static void device_preload_texture(IWineD3DStateBlockImpl *stateblock, unsigned void device_preload_textures(IWineD3DDeviceImpl *device) { IWineD3DStateBlockImpl *stateblock = device->stateBlock; + const struct wined3d_state *state = &stateblock->state; unsigned int i; - if (use_vs(stateblock)) + if (use_vs(state)) { for (i = 0; i < MAX_VERTEX_SAMPLERS; ++i) { - if (stateblock->state.vertex_shader->baseShader.reg_maps.sampler_type[i]) + if (state->vertex_shader->baseShader.reg_maps.sampler_type[i]) device_preload_texture(stateblock, MAX_FRAGMENT_SAMPLERS + i); } } @@ -481,7 +482,7 @@ void device_preload_textures(IWineD3DDeviceImpl *device) { for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i) { - if (stateblock->state.pixel_shader->baseShader.reg_maps.sampler_type[i]) + if (state->pixel_shader->baseShader.reg_maps.sampler_type[i]) device_preload_texture(stateblock, i); } } @@ -3585,7 +3586,7 @@ static void device_map_vsamplers(IWineD3DDeviceImpl *This, BOOL ps, const struct void IWineD3DDeviceImpl_FindTexUnitMap(IWineD3DDeviceImpl *This) { const struct wined3d_gl_info *gl_info = &This->adapter->gl_info; - BOOL vs = use_vs(This->stateBlock); + BOOL vs = use_vs(&This->stateBlock->state); BOOL ps = use_ps(This->stateBlock); /* * Rules are: diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c index 6ff8b32062a..a98e9ed892f 100644 --- a/dlls/wined3d/drawprim.c +++ b/dlls/wined3d/drawprim.c @@ -576,12 +576,13 @@ void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT StartIdx, UINT { IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; + const struct wined3d_state *state = &This->stateBlock->state; struct wined3d_context *context; unsigned int i; if (!index_count) return; - if (This->stateBlock->state.render_states[WINED3DRS_COLORWRITEENABLE]) + if (state->render_states[WINED3DRS_COLORWRITEENABLE]) { /* Invalidate the back buffer memory so LockRect will read it the next time */ for (i = 0; i < This->adapter->gl_info.limits.buffers; ++i) @@ -616,8 +617,7 @@ void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT StartIdx, UINT * depthstencil for D3DCMP_NEVER and D3DCMP_ALWAYS as well. Also note * that we never copy the stencil data.*/ DWORD location = context->render_offscreen ? SFLAG_DS_OFFSCREEN : SFLAG_DS_ONSCREEN; - if (This->stateBlock->state.render_states[WINED3DRS_ZWRITEENABLE] - || This->stateBlock->state.render_states[WINED3DRS_ZENABLE]) + if (state->render_states[WINED3DRS_ZWRITEENABLE] || state->render_states[WINED3DRS_ZENABLE]) { RECT current_rect, draw_rect, r; @@ -637,7 +637,7 @@ void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT StartIdx, UINT if (!EqualRect(&r, &draw_rect)) surface_load_ds_location(This->depth_stencil, context, location); - if (This->stateBlock->state.render_states[WINED3DRS_ZWRITEENABLE]) + if (state->render_states[WINED3DRS_ZWRITEENABLE]) { surface_modify_ds_location(This->depth_stencil, location, This->depth_stencil->ds_current_size.cx, @@ -650,8 +650,8 @@ void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT StartIdx, UINT if ((!context->gl_info->supported[WINED3D_GL_VERSION_2_0] || (!glPointParameteri && !context->gl_info->supported[NV_POINT_SPRITE])) && context->render_offscreen - && This->stateBlock->state.render_states[WINED3DRS_POINTSPRITEENABLE] - && This->stateBlock->state.gl_primitive_type == GL_POINTS) + && state->render_states[WINED3DRS_POINTSPRITEENABLE] + && state->gl_primitive_type == GL_POINTS) { FIXME("Point sprite coordinate origin switching not supported.\n"); } @@ -659,15 +659,15 @@ void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT StartIdx, UINT /* Ok, we will be updating the screen from here onwards so grab the lock */ ENTER_GL(); { - GLenum glPrimType = This->stateBlock->state.gl_primitive_type; + GLenum glPrimType = state->gl_primitive_type; BOOL emulation = FALSE; const struct wined3d_stream_info *stream_info = &This->strided_streams; struct wined3d_stream_info stridedlcl; - if (!use_vs(This->stateBlock)) + if (!use_vs(state)) { if (!This->strided_streams.position_transformed && context->num_untracked_materials - && This->stateBlock->state.render_states[WINED3DRS_LIGHTING]) + && state->render_states[WINED3DRS_LIGHTING]) { static BOOL warned; if (!warned) { @@ -678,7 +678,7 @@ void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT StartIdx, UINT } emulation = TRUE; } - else if (context->fog_coord && This->stateBlock->state.render_states[WINED3DRS_FOGENABLE]) + else if (context->fog_coord && state->render_states[WINED3DRS_FOGENABLE]) { /* Either write a pipeline replacement shader or convert the specular alpha from unsigned byte * to a float in the vertex buffer @@ -700,9 +700,10 @@ void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT StartIdx, UINT } } - if (This->useDrawStridedSlow || emulation) { + if (This->useDrawStridedSlow || emulation) + { /* Immediate mode drawing */ - if (use_vs(This->stateBlock)) + if (use_vs(state)) { static BOOL warned; if (!warned) { diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index b5f87263dbe..a731d782cbe 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -917,6 +917,7 @@ static void shader_generate_glsl_declarations(const struct wined3d_context *cont { IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface; IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) This->baseShader.device; + const struct wined3d_state *state = &device->stateBlock->state; const struct ps_compile_args *ps_args = ctx_priv->cur_ps_args; const struct wined3d_gl_info *gl_info = context->gl_info; unsigned int i, extra_constants_needed = 0; @@ -1062,7 +1063,7 @@ static void shader_generate_glsl_declarations(const struct wined3d_context *cont shader_addline(buffer, "uniform sampler1D %csampler%u;\n", prefix, i); break; case WINED3DSTT_2D: - texture = device->stateBlock->state.textures[i]; + texture = state->textures[i]; if (pshader && ps_args->shadow & (1 << i)) { if (texture && texture->baseTexture.target == GL_TEXTURE_RECTANGLE_ARB) @@ -1142,7 +1143,7 @@ static void shader_generate_glsl_declarations(const struct wined3d_context *cont */ if (pshader && reg_maps->shader_version.major >= 3) { - if (use_vs(device->stateBlock)) + if (use_vs(state)) { shader_addline(buffer, "varying vec4 IN[%u];\n", vec4_varyings(reg_maps->shader_version.major, gl_info)); } else { diff --git a/dlls/wined3d/shader.c b/dlls/wined3d/shader.c index 969d93a3a4f..8d380b74867 100644 --- a/dlls/wined3d/shader.c +++ b/dlls/wined3d/shader.c @@ -2070,12 +2070,13 @@ static const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl = void find_ps_compile_args(IWineD3DPixelShaderImpl *shader, IWineD3DStateBlockImpl *stateblock, struct ps_compile_args *args) { + const struct wined3d_state *state = &stateblock->state; IWineD3DBaseTextureImpl *texture; IWineD3DDeviceImpl *device = stateblock->device; UINT i; memset(args, 0, sizeof(*args)); /* FIXME: Make sure all bits are set. */ - if (stateblock->state.render_states[WINED3DRS_SRGBWRITEENABLE]) + if (state->render_states[WINED3DRS_SRGBWRITEENABLE]) { IWineD3DSurfaceImpl *rt = device->render_targets[0]; if(rt->resource.format->Flags & WINED3DFMT_FLAG_SRGB_WRITE) args->srgb_correction = 1; @@ -2086,7 +2087,7 @@ void find_ps_compile_args(IWineD3DPixelShaderImpl *shader, for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i) { if (!shader->baseShader.reg_maps.sampler_type[i]) continue; - texture = stateblock->state.textures[i]; + texture = state->textures[i]; if (!texture) { args->color_fixup[i] = COLOR_FIXUP_IDENTITY; @@ -2109,7 +2110,7 @@ void find_ps_compile_args(IWineD3DPixelShaderImpl *shader, { args->vp_mode = pretransformed; } - else if (use_vs(stateblock)) + else if (use_vs(state)) { args->vp_mode = vertexshader; } @@ -2122,18 +2123,18 @@ void find_ps_compile_args(IWineD3DPixelShaderImpl *shader, else { args->vp_mode = vertexshader; - if (stateblock->state.render_states[WINED3DRS_FOGENABLE]) + if (state->render_states[WINED3DRS_FOGENABLE]) { - switch (stateblock->state.render_states[WINED3DRS_FOGTABLEMODE]) + switch (state->render_states[WINED3DRS_FOGTABLEMODE]) { case WINED3DFOG_NONE: - if (device->strided_streams.position_transformed || use_vs(stateblock)) + if (device->strided_streams.position_transformed || use_vs(state)) { args->fog = FOG_LINEAR; break; } - switch (stateblock->state.render_states[WINED3DRS_FOGVERTEXMODE]) + switch (state->render_states[WINED3DRS_FOGVERTEXMODE]) { case WINED3DFOG_NONE: /* Fall through. */ case WINED3DFOG_LINEAR: args->fog = FOG_LINEAR; break; diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index 991b0686cc7..6c306543387 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -547,20 +547,21 @@ static void state_alpha(DWORD state, IWineD3DStateBlockImpl *stateblock, struct } } -static void state_clipping(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context) +static void state_clipping(DWORD state_id, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context) { const struct wined3d_gl_info *gl_info = context->gl_info; + const struct wined3d_state *state = &stateblock->state; DWORD enable = 0xFFFFFFFF; DWORD disable = 0x00000000; - if (!stateblock->device->vs_clipping && use_vs(stateblock)) + if (!stateblock->device->vs_clipping && use_vs(state)) { /* The spec says that opengl clipping planes are disabled when using shaders. Direct3D planes aren't, * so that is an issue. The MacOS ATI driver keeps clipping planes activated with shaders in some * conditions I got sick of tracking down. The shader state handler disables all clip planes because * of that - don't do anything here and keep them disabled */ - if (stateblock->state.render_states[WINED3DRS_CLIPPLANEENABLE]) + if (state->render_states[WINED3DRS_CLIPPLANEENABLE]) { static BOOL warned = FALSE; if(!warned) { @@ -578,10 +579,10 @@ static void state_clipping(DWORD state, IWineD3DStateBlockImpl *stateblock, stru /* If enabling / disabling all * TODO: Is this correct? Doesn't D3DRS_CLIPPING disable clipping on the viewport frustrum? */ - if (stateblock->state.render_states[WINED3DRS_CLIPPING]) + if (state->render_states[WINED3DRS_CLIPPING]) { - enable = stateblock->state.render_states[WINED3DRS_CLIPPLANEENABLE]; - disable = ~stateblock->state.render_states[WINED3DRS_CLIPPLANEENABLE]; + enable = state->render_states[WINED3DRS_CLIPPLANEENABLE]; + disable = ~state->render_states[WINED3DRS_CLIPPLANEENABLE]; if (gl_info->supported[ARB_DEPTH_CLAMP]) { glDisable(GL_DEPTH_CLAMP); @@ -1049,13 +1050,14 @@ void state_fogstartend(DWORD state, IWineD3DStateBlockImpl *stateblock, struct w TRACE("Fog End == %f\n", fogend); } -void state_fog_fragpart(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context) +void state_fog_fragpart(DWORD state_id, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context) { + const struct wined3d_state *state = &stateblock->state; enum fogsource new_source; - TRACE("state %#x, stateblock %p, context %p\n", state, stateblock, context); + TRACE("state_id %#x, stateblock %p, context %p\n", state_id, stateblock, context); - if (!stateblock->state.render_states[WINED3DRS_FOGENABLE]) + if (!state->render_states[WINED3DRS_FOGENABLE]) { /* No fog? Disable it, and we're done :-) */ glDisableWINE(GL_FOG); @@ -1109,14 +1111,17 @@ void state_fog_fragpart(DWORD state, IWineD3DStateBlockImpl *stateblock, struct /* DX 7 sdk: "If both render states(vertex and table fog) are set to valid modes, * the system will apply only pixel(=table) fog effects." */ - if (stateblock->state.render_states[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE) + if (state->render_states[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE) { - if(use_vs(stateblock)) { + if (use_vs(state)) + { glFogi(GL_FOG_MODE, GL_LINEAR); checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)"); new_source = FOGSOURCE_VS; - } else { - switch (stateblock->state.render_states[WINED3DRS_FOGVERTEXMODE]) + } + else + { + switch (state->render_states[WINED3DRS_FOGVERTEXMODE]) { /* If processed vertices are used, fall through to the NONE case */ case WINED3DFOG_EXP: @@ -1158,14 +1163,14 @@ void state_fog_fragpart(DWORD state, IWineD3DStateBlockImpl *stateblock, struct default: FIXME("Unexpected WINED3DRS_FOGVERTEXMODE %#x.\n", - stateblock->state.render_states[WINED3DRS_FOGVERTEXMODE]); + state->render_states[WINED3DRS_FOGVERTEXMODE]); new_source = FOGSOURCE_FFP; /* Make the compiler happy */ } } } else { new_source = FOGSOURCE_FFP; - switch (stateblock->state.render_states[WINED3DRS_FOGTABLEMODE]) + switch (state->render_states[WINED3DRS_FOGTABLEMODE]) { case WINED3DFOG_EXP: glFogi(GL_FOG_MODE, GL_EXP); @@ -1185,7 +1190,7 @@ void state_fog_fragpart(DWORD state, IWineD3DStateBlockImpl *stateblock, struct case WINED3DFOG_NONE: /* Won't happen */ default: FIXME("Unexpected WINED3DRS_FOGTABLEMODE %#x.\n", - stateblock->state.render_states[WINED3DRS_FOGTABLEMODE]); + state->render_states[WINED3DRS_FOGTABLEMODE]); } } @@ -3257,16 +3262,17 @@ void tex_alphaop(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d } } -static void transform_texture(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context) +static void transform_texture(DWORD state_id, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context) { - DWORD texUnit = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); + DWORD texUnit = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); DWORD mapped_stage = stateblock->device->texUnitMap[texUnit]; const struct wined3d_gl_info *gl_info = context->gl_info; + const struct wined3d_state *state = &stateblock->state; BOOL generated; int coordIdx; /* Ignore this when a vertex shader is used, or if the streams aren't sorted out yet */ - if (use_vs(stateblock) || isStateDirty(context, STATE_VDECL)) + if (use_vs(state) || isStateDirty(context, STATE_VDECL)) { TRACE("Using a vertex shader, or stream sources not sorted out yet, skipping\n"); return; @@ -3277,12 +3283,11 @@ static void transform_texture(DWORD state, IWineD3DStateBlockImpl *stateblock, s GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); checkGLcall("glActiveTextureARB"); - generated = (stateblock->state.texture_states[texUnit][WINED3DTSS_TEXCOORDINDEX] & 0xffff0000) - != WINED3DTSS_TCI_PASSTHRU; - coordIdx = min(stateblock->state.texture_states[texUnit][WINED3DTSS_TEXCOORDINDEX & 0x0000ffff], MAX_TEXTURES - 1); + generated = (state->texture_states[texUnit][WINED3DTSS_TEXCOORDINDEX] & 0xffff0000) != WINED3DTSS_TCI_PASSTHRU; + coordIdx = min(state->texture_states[texUnit][WINED3DTSS_TEXCOORDINDEX & 0x0000ffff], MAX_TEXTURES - 1); - set_texture_matrix(&stateblock->state.transforms[WINED3DTS_TEXTURE0 + texUnit].u.m[0][0], - stateblock->state.texture_states[texUnit][WINED3DTSS_TEXTURETRANSFORMFLAGS], + set_texture_matrix(&state->transforms[WINED3DTS_TEXTURE0 + texUnit].u.m[0][0], + state->texture_states[texUnit][WINED3DTSS_TEXTURETRANSFORMFLAGS], generated, context->last_was_rhw, stateblock->device->strided_streams.use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coordIdx)) ? stateblock->device->strided_streams.elements[WINED3D_FFP_TEXCOORD0 + coordIdx].format->id @@ -3290,7 +3295,7 @@ static void transform_texture(DWORD state, IWineD3DStateBlockImpl *stateblock, s stateblock->device->frag_pipe->ffp_proj_control); /* The sampler applying function calls us if this changes */ - if ((context->lastWasPow2Texture & (1 << texUnit)) && stateblock->state.textures[texUnit]) + if ((context->lastWasPow2Texture & (1 << texUnit)) && state->textures[texUnit]) { if(generated) { FIXME("Non-power2 texture being used with generated texture coords\n"); @@ -3299,7 +3304,7 @@ static void transform_texture(DWORD state, IWineD3DStateBlockImpl *stateblock, s fixed-function-pipeline fixup via pow2Matrix when no PS is used. */ if (!use_ps(stateblock)) { TRACE("Non power two matrix multiply fixup\n"); - glMultMatrixf(stateblock->state.textures[texUnit]->baseTexture.pow2Matrix); + glMultMatrixf(state->textures[texUnit]->baseTexture.pow2Matrix); } } } @@ -3554,7 +3559,7 @@ static void shaderconstant(DWORD state, IWineD3DStateBlockImpl *stateblock, stru return; } - device->shader_backend->shader_load_constants(context, use_ps(stateblock), use_vs(stateblock)); + device->shader_backend->shader_load_constants(context, use_ps(stateblock), use_vs(&stateblock->state)); } static void tex_bumpenvlscale(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context) @@ -3602,11 +3607,12 @@ static void sampler_texmatrix(DWORD state, IWineD3DStateBlockImpl *stateblock, s } } -static void sampler(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context) +static void sampler(DWORD state_id, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context) { - DWORD sampler = state - STATE_SAMPLER(0); + DWORD sampler = state_id - STATE_SAMPLER(0); DWORD mapped_stage = stateblock->device->texUnitMap[sampler]; const struct wined3d_gl_info *gl_info = context->gl_info; + const struct wined3d_state *state = &stateblock->state; union { float f; DWORD d; @@ -3630,28 +3636,28 @@ static void sampler(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wine GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); checkGLcall("glActiveTextureARB"); - if (stateblock->state.textures[sampler]) + if (state->textures[sampler]) { - IWineD3DBaseTexture *texture = (IWineD3DBaseTexture *)stateblock->state.textures[sampler]; - BOOL srgb = stateblock->state.sampler_states[sampler][WINED3DSAMP_SRGBTEXTURE]; + IWineD3DBaseTexture *texture = (IWineD3DBaseTexture *)state->textures[sampler]; + BOOL srgb = state->sampler_states[sampler][WINED3DSAMP_SRGBTEXTURE]; IWineD3DBaseTexture_BindTexture(texture, srgb); basetexture_apply_state_changes(texture, - stateblock->state.texture_states[sampler], - stateblock->state.sampler_states[sampler], gl_info); + state->texture_states[sampler], + state->sampler_states[sampler], gl_info); if (gl_info->supported[EXT_TEXTURE_LOD_BIAS]) { - tmpvalue.d = stateblock->state.sampler_states[sampler][WINED3DSAMP_MIPMAPLODBIAS]; + tmpvalue.d = state->sampler_states[sampler][WINED3DSAMP_MIPMAPLODBIAS]; glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, tmpvalue.f); checkGLcall("glTexEnvi(GL_TEXTURE_LOD_BIAS_EXT, ...)"); } - if (!use_ps(stateblock) && sampler < stateblock->state.lowest_disabled_stage) + if (!use_ps(stateblock) && sampler < state->lowest_disabled_stage) { - if (stateblock->state.render_states[WINED3DRS_COLORKEYENABLE] && !sampler) + if (state->render_states[WINED3DRS_COLORKEYENABLE] && !sampler) { /* If color keying is enabled update the alpha test, it depends on the existence * of a color key in stage 0 @@ -3661,19 +3667,19 @@ static void sampler(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wine } /* Trigger shader constant reloading (for NP2 texcoord fixup) */ - if (!stateblock->state.textures[sampler]->baseTexture.pow2Matrix_identity) + if (!state->textures[sampler]->baseTexture.pow2Matrix_identity) { IWineD3DDeviceImpl *d3ddevice = stateblock->device; d3ddevice->shader_backend->shader_load_np2fixup_constants( - (IWineD3DDevice*)d3ddevice, use_ps(stateblock), use_vs(stateblock)); + (IWineD3DDevice*)d3ddevice, use_ps(stateblock), use_vs(state)); } } else if (mapped_stage < gl_info->limits.textures) { - if (sampler < stateblock->state.lowest_disabled_stage) + if (sampler < state->lowest_disabled_stage) { /* TODO: What should I do with pixel shaders here ??? */ - if (stateblock->state.render_states[WINED3DRS_COLORKEYENABLE] && !sampler) + if (state->render_states[WINED3DRS_COLORKEYENABLE] && !sampler) { /* If color keying is enabled update the alpha test, it depends on the existence * of a color key in stage 0 @@ -3689,8 +3695,8 @@ static void sampler(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wine void apply_pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context) { IWineD3DDeviceImpl *device = stateblock->device; + BOOL use_vshader = use_vs(&stateblock->state); BOOL use_pshader = use_ps(stateblock); - BOOL use_vshader = use_vs(stateblock); unsigned int i; if (use_pshader) { @@ -3779,9 +3785,10 @@ static void transform_world(DWORD state, IWineD3DStateBlockImpl *stateblock, str } } -static void clipplane(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context) +static void clipplane(DWORD state_id, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context) { - UINT index = state - STATE_CLIPPLANE(0); + const struct wined3d_state *state = &stateblock->state; + UINT index = state_id - STATE_CLIPPLANE(0); if (isStateDirty(context, STATE_TRANSFORM(WINED3DTS_VIEW)) || index >= context->gl_info->limits.clipplanes) { @@ -3789,10 +3796,11 @@ static void clipplane(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wi } /* Clip Plane settings are affected by the model view in OpenGL, the View transform in direct3d */ - if(!use_vs(stateblock)) { + if (!use_vs(state)) + { glMatrixMode(GL_MODELVIEW); glPushMatrix(); - glLoadMatrixf(&stateblock->state.transforms[WINED3DTS_VIEW].u.m[0][0]); + glLoadMatrixf(&state->transforms[WINED3DTS_VIEW].u.m[0][0]); } else { @@ -3806,12 +3814,12 @@ static void clipplane(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wi if (context->render_offscreen) glScalef(1.0f, -1.0f, 1.0f); } - TRACE("Clipplane [%f,%f,%f,%f]\n", - stateblock->state.clip_planes[index][0], - stateblock->state.clip_planes[index][1], - stateblock->state.clip_planes[index][2], - stateblock->state.clip_planes[index][3]); - glClipPlane(GL_CLIP_PLANE0 + index, stateblock->state.clip_planes[index]); + TRACE("Clipplane [%.8e, %.8e, %.8e, %.8e]\n", + state->clip_planes[index][0], + state->clip_planes[index][1], + state->clip_planes[index][2], + state->clip_planes[index][3]); + glClipPlane(GL_CLIP_PLANE0 + index, state->clip_planes[index]); checkGLcall("glClipPlane"); glPopMatrix(); @@ -4573,8 +4581,8 @@ static void loadVertexData(const struct wined3d_context *context, IWineD3DStateB static void streamsrc(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context) { IWineD3DDeviceImpl *device = stateblock->device; - BOOL load_numbered = use_vs(stateblock) && !device->useDrawStridedSlow; - BOOL load_named = !use_vs(stateblock) && !device->useDrawStridedSlow; + BOOL load_numbered = use_vs(&stateblock->state) && !device->useDrawStridedSlow; + BOOL load_named = !use_vs(&stateblock->state) && !device->useDrawStridedSlow; if (context->numberedArraysLoaded && !load_numbered) { @@ -4606,7 +4614,7 @@ static void vertexdeclaration(DWORD state, IWineD3DStateBlockImpl *stateblock, s { const struct wined3d_gl_info *gl_info = context->gl_info; BOOL updateFog = FALSE; - BOOL useVertexShaderFunction = use_vs(stateblock); + BOOL useVertexShaderFunction = use_vs(&stateblock->state); BOOL usePixelShaderFunction = use_ps(stateblock); IWineD3DDeviceImpl *device = stateblock->device; BOOL transformed; diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index 1317abd9344..2957c5a3e4e 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -2901,7 +2901,7 @@ void gen_ffp_frag_op(IWineD3DStateBlockImpl *stateblock, struct ffp_frag_setting } else if (stateblock->state.render_states[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE) { - if (use_vs(stateblock) || stateblock->state.vertex_declaration->position_transformed) + if (use_vs(&stateblock->state) || stateblock->state.vertex_declaration->position_transformed) { settings->fog = FOG_LINEAR; } @@ -2944,7 +2944,7 @@ void gen_ffp_frag_op(IWineD3DStateBlockImpl *stateblock, struct ffp_frag_setting } else { settings->sRGB_write = 0; } - if (device->vs_clipping || !use_vs(stateblock) || !stateblock->state.render_states[WINED3DRS_CLIPPING] + if (device->vs_clipping || !use_vs(&stateblock->state) || !stateblock->state.render_states[WINED3DRS_CLIPPING] || !stateblock->state.render_states[WINED3DRS_CLIPPLANEENABLE]) { /* No need to emulate clipplanes if GL supports native vertex shader clipping or if diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 036d6f419bd..bb57127caa6 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -3017,14 +3017,13 @@ UINT wined3d_format_calculate_size(const struct wined3d_format *format, DWORD wined3d_format_convert_from_float(const struct wined3d_format *format, const WINED3DCOLORVALUE *color) DECLSPEC_HIDDEN; -static inline BOOL use_vs(IWineD3DStateBlockImpl *stateblock) +static inline BOOL use_vs(const struct wined3d_state *state) { /* Check stateblock->vertexDecl to allow this to be used from * IWineD3DDeviceImpl_FindTexUnitMap(). This is safe because * stateblock->vertexShader implies a vertex declaration instead of ddraw * style strided data. */ - return stateblock->state.vertex_shader - && !stateblock->state.vertex_declaration->position_transformed; + return state->vertex_shader && !state->vertex_declaration->position_transformed; } static inline BOOL use_ps(IWineD3DStateBlockImpl *stateblock)