Commit e4d2d785 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Pass a wined3d_state pointer to state handlers.

Instead of an entire stateblock. This is mainly useful is we ever want to call state handlers on state not stored in a stateblock.
parent 9375a87c
...@@ -5601,17 +5601,15 @@ static void arbfp_get_caps(const struct wined3d_gl_info *gl_info, struct fragmen ...@@ -5601,17 +5601,15 @@ static void arbfp_get_caps(const struct wined3d_gl_info *gl_info, struct fragmen
caps->MaxSimultaneousTextures = min(gl_info->limits.fragment_samplers, 8); caps->MaxSimultaneousTextures = min(gl_info->limits.fragment_samplers, 8);
} }
static void state_texfactor_arbfp(DWORD state_id, static void state_texfactor_arbfp(struct wined3d_context *context,
struct wined3d_stateblock *stateblock, struct wined3d_context *context) const struct wined3d_state *state, DWORD state_id)
{ {
struct wined3d_device *device = context->swapchain->device;
const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_gl_info *gl_info = context->gl_info;
const struct wined3d_state *state = &stateblock->state;
struct wined3d_device *device = stateblock->device;
float col[4]; float col[4];
/* Don't load the parameter if we're using an arbfp pixel shader, otherwise we'll overwrite /* Don't load the parameter if we're using an arbfp pixel shader,
* application provided constants * otherwise we'll overwrite application provided constants. */
*/
if (device->shader_backend == &arb_program_shader_backend) if (device->shader_backend == &arb_program_shader_backend)
{ {
if (use_ps(state)) return; if (use_ps(state)) return;
...@@ -5623,15 +5621,13 @@ static void state_texfactor_arbfp(DWORD state_id, ...@@ -5623,15 +5621,13 @@ static void state_texfactor_arbfp(DWORD state_id,
D3DCOLORTOGLFLOAT4(state->render_states[WINED3DRS_TEXTUREFACTOR], col); D3DCOLORTOGLFLOAT4(state->render_states[WINED3DRS_TEXTUREFACTOR], col);
GL_EXTCALL(glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_TFACTOR, col)); GL_EXTCALL(glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_TFACTOR, col));
checkGLcall("glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_TFACTOR, col)"); checkGLcall("glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_TFACTOR, col)");
} }
static void state_arb_specularenable(DWORD state_id, static void state_arb_specularenable(struct wined3d_context *context,
struct wined3d_stateblock *stateblock, struct wined3d_context *context) const struct wined3d_state *state, DWORD state_id)
{ {
struct wined3d_device *device = context->swapchain->device;
const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_gl_info *gl_info = context->gl_info;
const struct wined3d_state *state = &stateblock->state;
struct wined3d_device *device = stateblock->device;
float col[4]; float col[4];
/* Don't load the parameter if we're using an arbfp pixel shader, otherwise we'll overwrite /* Don't load the parameter if we're using an arbfp pixel shader, otherwise we'll overwrite
...@@ -5658,12 +5654,11 @@ static void state_arb_specularenable(DWORD state_id, ...@@ -5658,12 +5654,11 @@ static void state_arb_specularenable(DWORD state_id,
checkGLcall("glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_SPECULAR_ENABLE, col)"); checkGLcall("glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_SPECULAR_ENABLE, col)");
} }
static void set_bumpmat_arbfp(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) static void set_bumpmat_arbfp(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 stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
struct wined3d_device *device = context->swapchain->device;
const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_gl_info *gl_info = context->gl_info;
const struct wined3d_state *state = &stateblock->state;
struct wined3d_device *device = stateblock->device;
float mat[2][2]; float mat[2][2];
if (use_ps(state)) if (use_ps(state))
...@@ -5674,7 +5669,7 @@ static void set_bumpmat_arbfp(DWORD state_id, struct wined3d_stateblock *statebl ...@@ -5674,7 +5669,7 @@ static void set_bumpmat_arbfp(DWORD state_id, struct wined3d_stateblock *statebl
* anyway * anyway
*/ */
if (!isStateDirty(context, STATE_PIXELSHADERCONSTANT)) if (!isStateDirty(context, STATE_PIXELSHADERCONSTANT))
stateblock_apply_state(STATE_PIXELSHADERCONSTANT, stateblock, context); context_apply_state(context, state, STATE_PIXELSHADERCONSTANT);
} }
if(device->shader_backend == &arb_program_shader_backend) { if(device->shader_backend == &arb_program_shader_backend) {
...@@ -5695,13 +5690,12 @@ static void set_bumpmat_arbfp(DWORD state_id, struct wined3d_stateblock *statebl ...@@ -5695,13 +5690,12 @@ static void set_bumpmat_arbfp(DWORD state_id, struct wined3d_stateblock *statebl
checkGLcall("glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_BUMPMAT(stage), &mat[0][0])"); checkGLcall("glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_BUMPMAT(stage), &mat[0][0])");
} }
static void tex_bumpenvlum_arbfp(DWORD state_id, static void tex_bumpenvlum_arbfp(struct wined3d_context *context,
struct wined3d_stateblock *stateblock, 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 stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
struct wined3d_device *device = context->swapchain->device;
const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_gl_info *gl_info = context->gl_info;
const struct wined3d_state *state = &stateblock->state;
struct wined3d_device *device = stateblock->device;
float param[4]; float param[4];
if (use_ps(state)) if (use_ps(state))
...@@ -5712,7 +5706,7 @@ static void tex_bumpenvlum_arbfp(DWORD state_id, ...@@ -5712,7 +5706,7 @@ static void tex_bumpenvlum_arbfp(DWORD state_id,
* isn't scheduled anyway * isn't scheduled anyway
*/ */
if (!isStateDirty(context, STATE_PIXELSHADERCONSTANT)) if (!isStateDirty(context, STATE_PIXELSHADERCONSTANT))
stateblock_apply_state(STATE_PIXELSHADERCONSTANT, stateblock, context); context_apply_state(context, state, STATE_PIXELSHADERCONSTANT);
} }
if(device->shader_backend == &arb_program_shader_backend) { if(device->shader_backend == &arb_program_shader_backend) {
...@@ -6230,11 +6224,10 @@ static GLuint gen_arbfp_ffp_shader(const struct ffp_frag_settings *settings, con ...@@ -6230,11 +6224,10 @@ static GLuint gen_arbfp_ffp_shader(const struct ffp_frag_settings *settings, con
return ret; return ret;
} }
static void fragment_prog_arbfp(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) static void fragment_prog_arbfp(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{ {
const struct wined3d_device *device = context->swapchain->device;
const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_gl_info *gl_info = context->gl_info;
const struct wined3d_state *state = &stateblock->state;
struct wined3d_device *device = stateblock->device;
struct shader_arb_priv *priv = device->fragment_priv; struct shader_arb_priv *priv = device->fragment_priv;
BOOL use_vshader = use_vs(state); BOOL use_vshader = use_vs(state);
BOOL use_pshader = use_ps(state); BOOL use_pshader = use_ps(state);
...@@ -6242,17 +6235,23 @@ static void fragment_prog_arbfp(DWORD state_id, struct wined3d_stateblock *state ...@@ -6242,17 +6235,23 @@ static void fragment_prog_arbfp(DWORD state_id, struct wined3d_stateblock *state
const struct arbfp_ffp_desc *desc; const struct arbfp_ffp_desc *desc;
unsigned int i; unsigned int i;
TRACE("state_id %#x, stateblock %p, context %p\n", state_id, stateblock, context); TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
if(isStateDirty(context, STATE_RENDER(WINED3DRS_FOGENABLE))) { if (isStateDirty(context, STATE_RENDER(WINED3DRS_FOGENABLE)))
if(!use_pshader && device->shader_backend == &arb_program_shader_backend && context->last_was_pshader) { {
/* Reload fixed function constants since they collide with the pixel shader constants */ if (!use_pshader && device->shader_backend == &arb_program_shader_backend && context->last_was_pshader)
for(i = 0; i < MAX_TEXTURES; i++) { {
set_bumpmat_arbfp(STATE_TEXTURESTAGE(i, WINED3DTSS_BUMPENVMAT00), stateblock, context); /* Reload fixed function constants since they collide with the
* pixel shader constants. */
for (i = 0; i < MAX_TEXTURES; ++i)
{
set_bumpmat_arbfp(context, state, STATE_TEXTURESTAGE(i, WINED3DTSS_BUMPENVMAT00));
} }
state_texfactor_arbfp(STATE_RENDER(WINED3DRS_TEXTUREFACTOR), stateblock, context); state_texfactor_arbfp(context, state, STATE_RENDER(WINED3DRS_TEXTUREFACTOR));
state_arb_specularenable(STATE_RENDER(WINED3DRS_SPECULARENABLE), stateblock, context); state_arb_specularenable(context, state, STATE_RENDER(WINED3DRS_SPECULARENABLE));
} else if(use_pshader && !isStateDirty(context, device->StateTable[STATE_VSHADER].representative)) { }
else if(use_pshader && !isStateDirty(context, device->StateTable[STATE_VSHADER].representative))
{
device->shader_backend->shader_select(context, use_pshader, use_vshader); device->shader_backend->shader_select(context, use_pshader, use_vshader);
} }
return; return;
...@@ -6293,13 +6292,16 @@ static void fragment_prog_arbfp(DWORD state_id, struct wined3d_stateblock *state ...@@ -6293,13 +6292,16 @@ static void fragment_prog_arbfp(DWORD state_id, struct wined3d_stateblock *state
checkGLcall("glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, desc->shader)"); checkGLcall("glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, desc->shader)");
priv->current_fprogram_id = desc->shader; priv->current_fprogram_id = desc->shader;
if(device->shader_backend == &arb_program_shader_backend && context->last_was_pshader) { if (device->shader_backend == &arb_program_shader_backend && context->last_was_pshader)
/* Reload fixed function constants since they collide with the pixel shader constants */ {
for(i = 0; i < MAX_TEXTURES; i++) { /* Reload fixed function constants since they collide with the
set_bumpmat_arbfp(STATE_TEXTURESTAGE(i, WINED3DTSS_BUMPENVMAT00), stateblock, context); * pixel shader constants. */
for (i = 0; i < MAX_TEXTURES; ++i)
{
set_bumpmat_arbfp(context, state, STATE_TEXTURESTAGE(i, WINED3DTSS_BUMPENVMAT00));
} }
state_texfactor_arbfp(STATE_RENDER(WINED3DRS_TEXTUREFACTOR), stateblock, context); state_texfactor_arbfp(context, state, STATE_RENDER(WINED3DRS_TEXTUREFACTOR));
state_arb_specularenable(STATE_RENDER(WINED3DRS_SPECULARENABLE), stateblock, context); state_arb_specularenable(context, state, STATE_RENDER(WINED3DRS_SPECULARENABLE));
} }
context->last_was_pshader = FALSE; context->last_was_pshader = FALSE;
} else { } else {
...@@ -6319,29 +6321,30 @@ static void fragment_prog_arbfp(DWORD state_id, struct wined3d_stateblock *state ...@@ -6319,29 +6321,30 @@ static void fragment_prog_arbfp(DWORD state_id, struct wined3d_stateblock *state
device->shader_backend->shader_select(context, use_pshader, use_vshader); device->shader_backend->shader_select(context, use_pshader, use_vshader);
if (!isStateDirty(context, STATE_VERTEXSHADERCONSTANT) && (use_vshader || use_pshader)) if (!isStateDirty(context, STATE_VERTEXSHADERCONSTANT) && (use_vshader || use_pshader))
stateblock_apply_state(STATE_VERTEXSHADERCONSTANT, stateblock, context); context_apply_state(context, state, STATE_VERTEXSHADERCONSTANT);
} }
if (use_pshader) stateblock_apply_state(STATE_PIXELSHADERCONSTANT, stateblock, context); if (use_pshader)
context_apply_state(context, state, STATE_PIXELSHADERCONSTANT);
} }
/* We can't link the fog states to the fragment state directly since the vertex pipeline links them /* We can't link the fog states to the fragment state directly since the
* to FOGENABLE. A different linking in different pipeline parts can't be expressed in the combined * vertex pipeline links them to FOGENABLE. A different linking in different
* state table, so we need to handle that with a forwarding function. The other invisible side effect * pipeline parts can't be expressed in the combined state table, so we need
* is that changing the fog start and fog end(which links to FOGENABLE in vertex) results in the * to handle that with a forwarding function. The other invisible side effect
* fragment_prog_arbfp function being called because FOGENABLE is dirty, which calls this function here * 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
static void state_arbfp_fog(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) * FOGENABLE is dirty, which calls this function here. */
static void state_arbfp_fog(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{ {
const struct wined3d_state *state = &stateblock->state;
enum fogsource new_source; enum fogsource new_source;
TRACE("state_id %#x, stateblock %p, context %p\n", state_id, stateblock, context); TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
if(!isStateDirty(context, STATE_PIXELSHADER)) { if (!isStateDirty(context, STATE_PIXELSHADER))
fragment_prog_arbfp(state_id, stateblock, context); fragment_prog_arbfp(context, state, state_id);
}
if (!state->render_states[WINED3DRS_FOGENABLE]) return; if (!state->render_states[WINED3DRS_FOGENABLE])
return;
if (state->render_states[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE) if (state->render_states[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE)
{ {
...@@ -6356,19 +6359,23 @@ static void state_arbfp_fog(DWORD state_id, struct wined3d_stateblock *statebloc ...@@ -6356,19 +6359,23 @@ static void state_arbfp_fog(DWORD state_id, struct wined3d_stateblock *statebloc
else else
new_source = FOGSOURCE_FFP; new_source = FOGSOURCE_FFP;
} }
} else { }
else
{
new_source = FOGSOURCE_FFP; new_source = FOGSOURCE_FFP;
} }
if(new_source != context->fog_source) {
if (new_source != context->fog_source)
{
context->fog_source = new_source; context->fog_source = new_source;
state_fogstartend(STATE_RENDER(WINED3DRS_FOGSTART), stateblock, context); state_fogstartend(context, state, STATE_RENDER(WINED3DRS_FOGSTART));
} }
} }
static void textransform(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) static void textransform(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{ {
if (!isStateDirty(context, STATE_PIXELSHADER)) if (!isStateDirty(context, STATE_PIXELSHADER))
fragment_prog_arbfp(state, stateblock, context); fragment_prog_arbfp(context, state, state_id);
} }
static const struct StateEntryTemplate arbfp_fragmentstate_template[] = { static const struct StateEntryTemplate arbfp_fragmentstate_template[] = {
......
...@@ -796,17 +796,17 @@ static GLuint gen_ati_shader(const struct texture_stage_op op[MAX_TEXTURES], con ...@@ -796,17 +796,17 @@ static GLuint gen_ati_shader(const struct texture_stage_op op[MAX_TEXTURES], con
return ret; return ret;
} }
static void set_tex_op_atifs(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) static void set_tex_op_atifs(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{ {
const struct wined3d_device *device = context->swapchain->device;
const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_gl_info *gl_info = context->gl_info;
struct wined3d_device *device = stateblock->device;
const struct atifs_ffp_desc *desc; const struct atifs_ffp_desc *desc;
struct ffp_frag_settings settings; struct ffp_frag_settings settings;
struct atifs_private_data *priv = device->fragment_priv; struct atifs_private_data *priv = device->fragment_priv;
DWORD mapped_stage; DWORD mapped_stage;
unsigned int i; unsigned int i;
gen_ffp_frag_op(device, &stateblock->state, &settings, TRUE); gen_ffp_frag_op(device, state, &settings, TRUE);
desc = (const struct atifs_ffp_desc *)find_ffp_frag_shader(&priv->fragment_shaders, &settings); desc = (const struct atifs_ffp_desc *)find_ffp_frag_shader(&priv->fragment_shaders, &settings);
if(!desc) { if(!desc) {
struct atifs_ffp_desc *new_desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_desc)); struct atifs_ffp_desc *new_desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_desc));
...@@ -839,33 +839,33 @@ static void set_tex_op_atifs(DWORD state, struct wined3d_stateblock *stateblock, ...@@ -839,33 +839,33 @@ static void set_tex_op_atifs(DWORD state, struct wined3d_stateblock *stateblock,
{ {
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
checkGLcall("glActiveTextureARB"); checkGLcall("glActiveTextureARB");
texture_activate_dimensions(stateblock->state.textures[i], gl_info); texture_activate_dimensions(state->textures[i], gl_info);
} }
} }
GL_EXTCALL(glBindFragmentShaderATI(desc->shader)); GL_EXTCALL(glBindFragmentShaderATI(desc->shader));
} }
static void state_texfactor_atifs(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) static void state_texfactor_atifs(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{ {
const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_gl_info *gl_info = context->gl_info;
float col[4]; float col[4];
D3DCOLORTOGLFLOAT4(stateblock->state.render_states[WINED3DRS_TEXTUREFACTOR], col); D3DCOLORTOGLFLOAT4(state->render_states[WINED3DRS_TEXTUREFACTOR], col);
GL_EXTCALL(glSetFragmentShaderConstantATI(ATI_FFP_CONST_TFACTOR, col)); GL_EXTCALL(glSetFragmentShaderConstantATI(ATI_FFP_CONST_TFACTOR, col));
checkGLcall("glSetFragmentShaderConstantATI(ATI_FFP_CONST_TFACTOR, col)"); checkGLcall("glSetFragmentShaderConstantATI(ATI_FFP_CONST_TFACTOR, col)");
} }
static void set_bumpmat(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) static void set_bumpmat(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{ {
DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_gl_info *gl_info = context->gl_info;
float mat[2][2]; float mat[2][2];
mat[0][0] = *((float *)&stateblock->state.texture_states[stage][WINED3DTSS_BUMPENVMAT00]); mat[0][0] = *((float *)&state->texture_states[stage][WINED3DTSS_BUMPENVMAT00]);
mat[1][0] = *((float *)&stateblock->state.texture_states[stage][WINED3DTSS_BUMPENVMAT01]); mat[1][0] = *((float *)&state->texture_states[stage][WINED3DTSS_BUMPENVMAT01]);
mat[0][1] = *((float *)&stateblock->state.texture_states[stage][WINED3DTSS_BUMPENVMAT10]); mat[0][1] = *((float *)&state->texture_states[stage][WINED3DTSS_BUMPENVMAT10]);
mat[1][1] = *((float *)&stateblock->state.texture_states[stage][WINED3DTSS_BUMPENVMAT11]); mat[1][1] = *((float *)&state->texture_states[stage][WINED3DTSS_BUMPENVMAT11]);
/* GL_ATI_fragment_shader allows only constants from 0.0 to 1.0, but the bumpmat /* GL_ATI_fragment_shader allows only constants from 0.0 to 1.0, but the bumpmat
* constants can be in any range. While they should stay between [-1.0 and 1.0] because * constants can be in any range. While they should stay between [-1.0 and 1.0] because
* Shader Model 1.x pixel shaders are clamped to that range negative values are used occasionally, * Shader Model 1.x pixel shaders are clamped to that range negative values are used occasionally,
...@@ -881,42 +881,43 @@ static void set_bumpmat(DWORD state, struct wined3d_stateblock *stateblock, stru ...@@ -881,42 +881,43 @@ static void set_bumpmat(DWORD state, struct wined3d_stateblock *stateblock, stru
checkGLcall("glSetFragmentShaderConstantATI(ATI_FFP_CONST_BUMPMAT(stage), mat)"); checkGLcall("glSetFragmentShaderConstantATI(ATI_FFP_CONST_BUMPMAT(stage), mat)");
} }
static void textransform(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) static void textransform(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{ {
if (!isStateDirty(context, STATE_PIXELSHADER)) if (!isStateDirty(context, STATE_PIXELSHADER))
set_tex_op_atifs(state, stateblock, context); set_tex_op_atifs(context, state, state_id);
} }
static void atifs_apply_pixelshader(DWORD state_id, static void atifs_apply_pixelshader(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
struct wined3d_stateblock *stateblock, struct wined3d_context *context)
{ {
const struct wined3d_state *state = &stateblock->state; const struct wined3d_device *device = context->swapchain->device;
struct wined3d_device *device = stateblock->device;
BOOL use_vshader = use_vs(state); BOOL use_vshader = use_vs(state);
context->last_was_pshader = use_ps(state); context->last_was_pshader = use_ps(state);
/* The ATIFS code does not support pixel shaders currently, but we have to provide a state handler /* The ATIFS code does not support pixel shaders currently, but we have to
* to call shader_select to select a vertex shader if one is applied because the vertex shader state * provide a state handler to call shader_select to select a vertex shader
* may defer calling the shader backend if the pshader state is dirty. * if one is applied because the vertex shader state may defer calling the
* shader backend if the pshader state is dirty.
* *
* In theory the application should not be able to mark the pixel shader dirty because it cannot * In theory the application should not be able to mark the pixel shader
* create a shader, and thus has no way to set the state to something != NULL. However, a different * dirty because it cannot create a shader, and thus has no way to set the
* pipeline part may link a different state to its pixelshader handler, thus a pshader state exists * state to something != NULL. However, a different pipeline part may link
* and can be dirtified. Also the pshader is always dirtified at startup, and blitting disables all * a different state to its pixelshader handler, thus a pshader state
* shaders and dirtifies all shader states. If atifs can deal with this it keeps the rest of the code * exists and can be dirtified. Also the pshader is always dirtified at
* simpler. * startup, and blitting disables all shaders and dirtifies all shader
*/ * states. If atifs can deal with this it keeps the rest of the code
if(!isStateDirty(context, device->StateTable[STATE_VSHADER].representative)) { * simpler. */
if (!isStateDirty(context, device->StateTable[STATE_VSHADER].representative))
{
device->shader_backend->shader_select(context, FALSE, use_vshader); device->shader_backend->shader_select(context, FALSE, use_vshader);
if (!isStateDirty(context, STATE_VERTEXSHADERCONSTANT) && use_vshader) if (!isStateDirty(context, STATE_VERTEXSHADERCONSTANT) && use_vshader)
stateblock_apply_state(STATE_VERTEXSHADERCONSTANT, stateblock, context); context_apply_state(context, state, STATE_VERTEXSHADERCONSTANT);
} }
} }
static void atifs_srgbwriteenable(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) static void atifs_srgbwriteenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{ {
if (stateblock->state.render_states[WINED3DRS_SRGBWRITEENABLE]) if (state->render_states[WINED3DRS_SRGBWRITEENABLE])
WARN("sRGB writes are not supported by this fragment pipe.\n"); WARN("sRGB writes are not supported by this fragment pipe.\n");
} }
......
...@@ -2177,10 +2177,9 @@ static DWORD find_draw_buffers_mask(const struct wined3d_context *context, const ...@@ -2177,10 +2177,9 @@ static DWORD find_draw_buffers_mask(const struct wined3d_context *context, const
} }
/* GL locking and context activation are done by the caller */ /* GL locking and context activation are done by the caller */
void context_state_fb(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) void context_state_fb(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{ {
const struct wined3d_state *state = &stateblock->state; const struct wined3d_device *device = context->swapchain->device;
struct wined3d_device *device = stateblock->device;
const struct wined3d_fb_state *fb = state->fb; const struct wined3d_fb_state *fb = state->fb;
DWORD rt_mask = find_draw_buffers_mask(context, device); DWORD rt_mask = find_draw_buffers_mask(context, device);
...@@ -2206,10 +2205,10 @@ void context_state_fb(DWORD state_id, struct wined3d_stateblock *stateblock, str ...@@ -2206,10 +2205,10 @@ void context_state_fb(DWORD state_id, struct wined3d_stateblock *stateblock, str
} }
/* GL locking and context activation are done by the caller */ /* GL locking and context activation are done by the caller */
void context_state_drawbuf(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) void context_state_drawbuf(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{ {
const struct wined3d_device *device = context->swapchain->device;
DWORD rt_mask; DWORD rt_mask;
struct wined3d_device *device = stateblock->device;
if (isStateDirty(context, STATE_FRAMEBUFFER)) return; if (isStateDirty(context, STATE_FRAMEBUFFER)) return;
...@@ -2224,9 +2223,9 @@ void context_state_drawbuf(DWORD state, struct wined3d_stateblock *stateblock, s ...@@ -2224,9 +2223,9 @@ void context_state_drawbuf(DWORD state, struct wined3d_stateblock *stateblock, s
/* Context activation is done by the caller. */ /* Context activation is done by the caller. */
BOOL context_apply_draw_state(struct wined3d_context *context, struct wined3d_device *device) BOOL context_apply_draw_state(struct wined3d_context *context, struct wined3d_device *device)
{ {
struct wined3d_stateblock *stateblock = device->stateBlock; const struct wined3d_state *state = &device->stateBlock->state;
const struct StateEntry *state_table = device->StateTable; const struct StateEntry *state_table = device->StateTable;
const struct wined3d_fb_state *fb = stateblock->state.fb; const struct wined3d_fb_state *fb = state->fb;
unsigned int i; unsigned int i;
if (!context_validate_rt_config(context->gl_info->limits.buffers, if (!context_validate_rt_config(context->gl_info->limits.buffers,
...@@ -2253,7 +2252,7 @@ BOOL context_apply_draw_state(struct wined3d_context *context, struct wined3d_de ...@@ -2253,7 +2252,7 @@ BOOL context_apply_draw_state(struct wined3d_context *context, struct wined3d_de
DWORD idx = rep / (sizeof(*context->isStateDirty) * CHAR_BIT); DWORD idx = rep / (sizeof(*context->isStateDirty) * CHAR_BIT);
BYTE shift = rep & ((sizeof(*context->isStateDirty) * CHAR_BIT) - 1); BYTE shift = rep & ((sizeof(*context->isStateDirty) * CHAR_BIT) - 1);
context->isStateDirty[idx] &= ~(1 << shift); context->isStateDirty[idx] &= ~(1 << shift);
state_table[rep].apply(rep, stateblock, context); state_table[rep].apply(context, state, rep);
} }
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
......
...@@ -457,13 +457,13 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d ...@@ -457,13 +457,13 @@ void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d
} }
static void nvrc_colorop(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) 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); DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
BOOL tex_used = stateblock->device->fixed_function_usage_map & (1 << stage); const struct wined3d_device *device = context->swapchain->device;
DWORD mapped_stage = stateblock->device->texUnitMap[stage]; BOOL tex_used = device->fixed_function_usage_map & (1 << stage);
DWORD mapped_stage = device->texUnitMap[stage];
const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_gl_info *gl_info = context->gl_info;
const struct wined3d_state *state = &stateblock->state;
TRACE("Setting color op for stage %u.\n", stage); TRACE("Setting color op for stage %u.\n", stage);
...@@ -567,11 +567,10 @@ static void nvrc_colorop(DWORD state_id, struct wined3d_stateblock *stateblock, ...@@ -567,11 +567,10 @@ static void nvrc_colorop(DWORD state_id, struct wined3d_stateblock *stateblock,
} }
} }
static void nvts_texdim(DWORD state_id, struct wined3d_stateblock *stateblock, struct wined3d_context *context) static void nvts_texdim(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{ {
DWORD sampler = state_id - STATE_SAMPLER(0); DWORD sampler = state_id - STATE_SAMPLER(0);
DWORD mapped_stage = stateblock->device->texUnitMap[sampler]; DWORD mapped_stage = context->swapchain->device->texUnitMap[sampler];
const struct wined3d_state *state = &stateblock->state;
/* No need to enable / disable anything here for unused samplers. The tex_colorop /* 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 * handler takes care. Also no action is needed with pixel shaders, or if tex_colorop
...@@ -584,10 +583,10 @@ static void nvts_texdim(DWORD state_id, struct wined3d_stateblock *stateblock, s ...@@ -584,10 +583,10 @@ static void nvts_texdim(DWORD state_id, struct wined3d_stateblock *stateblock, s
nvts_activate_dimensions(state, sampler, context); nvts_activate_dimensions(state, sampler, context);
} }
static void nvts_bumpenvmat(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) static void nvts_bumpenvmat(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{ {
DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1); DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
DWORD mapped_stage = stateblock->device->texUnitMap[stage + 1]; DWORD mapped_stage = context->swapchain->device->texUnitMap[stage + 1];
const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_gl_info *gl_info = context->gl_info;
float mat[2][2]; float mat[2][2];
...@@ -602,22 +601,22 @@ static void nvts_bumpenvmat(DWORD state, struct wined3d_stateblock *stateblock, ...@@ -602,22 +601,22 @@ static void nvts_bumpenvmat(DWORD state, struct wined3d_stateblock *stateblock,
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage)); GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
checkGLcall("GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage))"); checkGLcall("GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage))");
/* We can't just pass a pointer to the stateblock 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). */
mat[0][0] = *((float *)&stateblock->state.texture_states[stage][WINED3DTSS_BUMPENVMAT00]); mat[0][0] = *((float *)&state->texture_states[stage][WINED3DTSS_BUMPENVMAT00]);
mat[1][0] = *((float *)&stateblock->state.texture_states[stage][WINED3DTSS_BUMPENVMAT01]); mat[1][0] = *((float *)&state->texture_states[stage][WINED3DTSS_BUMPENVMAT01]);
mat[0][1] = *((float *)&stateblock->state.texture_states[stage][WINED3DTSS_BUMPENVMAT10]); mat[0][1] = *((float *)&state->texture_states[stage][WINED3DTSS_BUMPENVMAT10]);
mat[1][1] = *((float *)&stateblock->state.texture_states[stage][WINED3DTSS_BUMPENVMAT11]); mat[1][1] = *((float *)&state->texture_states[stage][WINED3DTSS_BUMPENVMAT11]);
glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, (float *)mat); glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, (float *)mat);
checkGLcall("glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, mat)"); checkGLcall("glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, mat)");
} }
} }
static void nvrc_texfactor(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) static void nvrc_texfactor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{ {
const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_gl_info *gl_info = context->gl_info;
float col[4]; float col[4];
D3DCOLORTOGLFLOAT4(stateblock->state.render_states[WINED3DRS_TEXTUREFACTOR], col); D3DCOLORTOGLFLOAT4(state->render_states[WINED3DRS_TEXTUREFACTOR], col);
GL_EXTCALL(glCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, &col[0])); GL_EXTCALL(glCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, &col[0]));
} }
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -3126,20 +3126,22 @@ void texture_activate_dimensions(const struct wined3d_texture *texture, const st ...@@ -3126,20 +3126,22 @@ void texture_activate_dimensions(const struct wined3d_texture *texture, const st
} }
/* GL locking is done by the caller (state handler) */ /* GL locking is done by the caller (state handler) */
void sampler_texdim(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) void sampler_texdim(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{ {
DWORD sampler = state - STATE_SAMPLER(0); DWORD sampler = state_id - STATE_SAMPLER(0);
DWORD mapped_stage = stateblock->device->texUnitMap[sampler]; DWORD mapped_stage = context->swapchain->device->texUnitMap[sampler];
/* No need to enable / disable anything here for unused samplers. The tex_colorop /* No need to enable / disable anything here for unused samplers. The
* handler takes care. Also no action is needed with pixel shaders, or if tex_colorop * tex_colorop handler takes care. Also no action is needed with pixel
* will take care of this business * shaders, or if tex_colorop will take care of this business. */
*/ if (mapped_stage == WINED3D_UNMAPPED_STAGE || mapped_stage >= context->gl_info->limits.textures)
if (mapped_stage == WINED3D_UNMAPPED_STAGE || mapped_stage >= context->gl_info->limits.textures) return; return;
if (sampler >= stateblock->state.lowest_disabled_stage) return; if (sampler >= state->lowest_disabled_stage)
if (isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3DTSS_COLOROP))) return; return;
if (isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3DTSS_COLOROP)))
return;
texture_activate_dimensions(stateblock->state.textures[sampler], context->gl_info); texture_activate_dimensions(state->textures[sampler], context->gl_info);
} }
void *wined3d_rb_alloc(size_t size) void *wined3d_rb_alloc(size_t size)
......
...@@ -1136,7 +1136,7 @@ struct wined3d_fb_state ...@@ -1136,7 +1136,7 @@ struct wined3d_fb_state
struct wined3d_surface *depth_stencil; struct wined3d_surface *depth_stencil;
}; };
typedef void (*APPLYSTATEFUNC)(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *ctx); typedef void (*APPLYSTATEFUNC)(struct wined3d_context *ctx, const struct wined3d_state *state, DWORD state_id);
struct StateEntry struct StateEntry
{ {
...@@ -1252,10 +1252,10 @@ void context_resource_unloaded(const struct wined3d_device *device, ...@@ -1252,10 +1252,10 @@ void context_resource_unloaded(const struct wined3d_device *device,
BOOL context_set_current(struct wined3d_context *ctx) DECLSPEC_HIDDEN; BOOL context_set_current(struct wined3d_context *ctx) DECLSPEC_HIDDEN;
void context_set_draw_buffer(struct wined3d_context *context, GLenum buffer) DECLSPEC_HIDDEN; void context_set_draw_buffer(struct wined3d_context *context, GLenum buffer) DECLSPEC_HIDDEN;
void context_set_tls_idx(DWORD idx) DECLSPEC_HIDDEN; void context_set_tls_idx(DWORD idx) DECLSPEC_HIDDEN;
void context_state_drawbuf(DWORD state, struct wined3d_stateblock *stateblock, void context_state_drawbuf(struct wined3d_context *context,
struct wined3d_context *context) DECLSPEC_HIDDEN; const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
void context_state_fb(DWORD state, struct wined3d_stateblock *stateblock, void context_state_fb(struct wined3d_context *context,
struct wined3d_context *context) DECLSPEC_HIDDEN; const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
void context_surface_update(struct wined3d_context *context, const struct wined3d_surface *surface) DECLSPEC_HIDDEN; void context_surface_update(struct wined3d_context *context, const struct wined3d_surface *surface) DECLSPEC_HIDDEN;
/***************************************************************************** /*****************************************************************************
...@@ -2314,14 +2314,6 @@ struct wined3d_stateblock ...@@ -2314,14 +2314,6 @@ struct wined3d_stateblock
void stateblock_init_contained_states(struct wined3d_stateblock *stateblock) DECLSPEC_HIDDEN; void stateblock_init_contained_states(struct wined3d_stateblock *stateblock) DECLSPEC_HIDDEN;
void stateblock_init_default_state(struct wined3d_stateblock *stateblock) DECLSPEC_HIDDEN; void stateblock_init_default_state(struct wined3d_stateblock *stateblock) DECLSPEC_HIDDEN;
static inline void stateblock_apply_state(DWORD state, struct wined3d_stateblock *stateblock,
struct wined3d_context *context)
{
const struct StateEntry *statetable = stateblock->device->StateTable;
DWORD rep = statetable[state].representative;
statetable[rep].apply(rep, stateblock, context);
}
/* Direct3D terminology with little modifications. We do not have an issued state /* Direct3D terminology with little modifications. We do not have an issued state
* because only the driver knows about it, but we have a created state because d3d * because only the driver knows about it, but we have a created state because d3d
* allows GetData on a created issue, but opengl doesn't * allows GetData on a created issue, but opengl doesn't
...@@ -2499,20 +2491,20 @@ void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords, ...@@ -2499,20 +2491,20 @@ void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords,
BOOL transformed, enum wined3d_format_id coordtype, BOOL ffp_can_disable_proj) DECLSPEC_HIDDEN; BOOL transformed, enum wined3d_format_id coordtype, BOOL ffp_can_disable_proj) DECLSPEC_HIDDEN;
void texture_activate_dimensions(const struct wined3d_texture *texture, void texture_activate_dimensions(const struct wined3d_texture *texture,
const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN; const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
void sampler_texdim(DWORD state, struct wined3d_stateblock *stateblock, void sampler_texdim(struct wined3d_context *context,
struct wined3d_context *context) DECLSPEC_HIDDEN; const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
void tex_alphaop(DWORD state, struct wined3d_stateblock *stateblock, void tex_alphaop(struct wined3d_context *context,
struct wined3d_context *context) DECLSPEC_HIDDEN; const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
void apply_pixelshader(DWORD state, struct wined3d_stateblock *stateblock, void apply_pixelshader(struct wined3d_context *context,
struct wined3d_context *context) DECLSPEC_HIDDEN; const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
void state_fogcolor(DWORD state, struct wined3d_stateblock *stateblock, void state_fogcolor(struct wined3d_context *context,
struct wined3d_context *context) DECLSPEC_HIDDEN; const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
void state_fogdensity(DWORD state, struct wined3d_stateblock *stateblock, void state_fogdensity(struct wined3d_context *context,
struct wined3d_context *context) DECLSPEC_HIDDEN; const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
void state_fogstartend(DWORD state, struct wined3d_stateblock *stateblock, void state_fogstartend(struct wined3d_context *context,
struct wined3d_context *context) DECLSPEC_HIDDEN; const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
void state_fog_fragpart(DWORD state, struct wined3d_stateblock *stateblock, void state_fog_fragpart(struct wined3d_context *context,
struct wined3d_context *context) DECLSPEC_HIDDEN; const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
BOOL getColorBits(const struct wined3d_format *format, BOOL getColorBits(const struct wined3d_format *format,
BYTE *redSize, BYTE *greenSize, BYTE *blueSize, BYTE *alphaSize, BYTE *totalSize) DECLSPEC_HIDDEN; BYTE *redSize, BYTE *greenSize, BYTE *blueSize, BYTE *alphaSize, BYTE *totalSize) DECLSPEC_HIDDEN;
...@@ -2834,6 +2826,14 @@ static inline BOOL use_ps(const struct wined3d_state *state) ...@@ -2834,6 +2826,14 @@ static inline BOOL use_ps(const struct wined3d_state *state)
return !!state->pixel_shader; return !!state->pixel_shader;
} }
static inline void context_apply_state(struct wined3d_context *context,
const struct wined3d_state *state, DWORD state_id)
{
const struct StateEntry *statetable = context->swapchain->device->StateTable;
DWORD rep = statetable[state_id].representative;
statetable[rep].apply(context, state, rep);
}
/* The WNDCLASS-Name for the fake window which we use to retrieve the GL capabilities */ /* The WNDCLASS-Name for the fake window which we use to retrieve the GL capabilities */
#define WINED3D_OPENGL_WINDOW_CLASS_NAME "WineD3D_OpenGL" #define WINED3D_OPENGL_WINDOW_CLASS_NAME "WineD3D_OpenGL"
......
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