Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/d3d11/device.c | 3 --- dlls/d3d11/state.c | 1 + dlls/wined3d/context.c | 10 +++---- dlls/wined3d/device.c | 2 ++ dlls/wined3d/shader.c | 2 +- dlls/wined3d/state.c | 61 +++++++++++++++++++----------------------- dlls/wined3d/utils.c | 4 +-- include/wine/wined3d.h | 1 + 8 files changed, 40 insertions(+), 44 deletions(-)
diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c index 555d998da2..76f8c821a1 100644 --- a/dlls/d3d11/device.c +++ b/dlls/d3d11/device.c @@ -721,7 +721,6 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetBlendState(ID3D11Devi { wined3d_device_set_blend_state(device->wined3d_device, NULL, (const struct wined3d_color *)blend_factor); - wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE, FALSE); wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_COLORWRITEENABLE, D3D11_COLOR_WRITE_ENABLE_ALL); wined3d_device_set_render_state(device->wined3d_device, @@ -737,8 +736,6 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetBlendState(ID3D11Devi wined3d_device_set_blend_state(device->wined3d_device, blend_state_impl->wined3d_state, (const struct wined3d_color *)blend_factor); desc = &blend_state_impl->desc; - wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE, - desc->RenderTarget[0].BlendEnable); if (desc->RenderTarget[0].BlendEnable) { const D3D11_RENDER_TARGET_BLEND_DESC *d = &desc->RenderTarget[0]; diff --git a/dlls/d3d11/state.c b/dlls/d3d11/state.c index dd2eb6306e..269ec5eb12 100644 --- a/dlls/d3d11/state.c +++ b/dlls/d3d11/state.c @@ -389,6 +389,7 @@ HRESULT d3d_blend_state_create(struct d3d_device *device, const D3D11_BLEND_DESC }
wined3d_desc.alpha_to_coverage = desc->AlphaToCoverageEnable; + wined3d_desc.enable = desc->RenderTarget[0].BlendEnable;
/* We cannot fail after creating a wined3d_blend_state object. It * would lead to double free. */ diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c index f4a5189ba1..eda09d95af 100644 --- a/dlls/wined3d/context.c +++ b/dlls/wined3d/context.c @@ -3148,7 +3148,7 @@ void wined3d_context_gl_apply_blit_state(struct wined3d_context_gl *context_gl, gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_TEST); context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ZENABLE)); gl_info->gl_ops.gl.p_glDisable(GL_BLEND); - context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE)); + context_invalidate_state(context, STATE_BLEND); gl_info->gl_ops.gl.p_glDisable(GL_CULL_FACE); gl_info->gl_ops.gl.p_glDisable(GL_SCISSOR_TEST); context_invalidate_state(context, STATE_RASTERIZER); @@ -3426,7 +3426,7 @@ BOOL wined3d_context_gl_apply_clear_state(struct wined3d_context_gl *context_gl, } checkGLcall("setting up state for clear");
- context_invalidate_state(&context_gl->c, STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE)); + context_invalidate_state(&context_gl->c, STATE_BLEND); context_invalidate_state(&context_gl->c, STATE_RASTERIZER); context_invalidate_state(&context_gl->c, STATE_SCISSORRECT);
@@ -4458,7 +4458,7 @@ static void wined3d_context_gl_setup_target(struct wined3d_context_gl *context_g * the alpha blend state changes with different render target formats. */ if (!context_gl->c.current_rt.texture) { - context_invalidate_state(&context_gl->c, STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE)); + context_invalidate_state(&context_gl->c, STATE_BLEND); } else { @@ -4470,12 +4470,12 @@ static void wined3d_context_gl_setup_target(struct wined3d_context_gl *context_g /* Disable blending when the alpha mask has changed and when a format doesn't support blending. */ if ((old->alpha_size && !new->alpha_size) || (!old->alpha_size && new->alpha_size) || !(texture->resource.format_flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING)) - context_invalidate_state(&context_gl->c, STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE)); + context_invalidate_state(&context_gl->c, STATE_BLEND);
/* Update sRGB writing when switching between formats that do/do not support sRGB writing */ if ((context_gl->c.current_rt.texture->resource.format_flags & WINED3DFMT_FLAG_SRGB_WRITE) != (texture->resource.format_flags & WINED3DFMT_FLAG_SRGB_WRITE)) - context_invalidate_state(&context_gl->c, STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE)); + context_invalidate_state(&context_gl->c, STATE_BLEND); }
/* When switching away from an offscreen render target, and we're not diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index c3775934ca..3f8bd02d1d 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -3581,6 +3581,7 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device, switch (idx) { case WINED3D_RS_BLENDFACTOR: + case WINED3D_RS_ALPHABLENDENABLE: set_blend_state = TRUE; break;
@@ -3651,6 +3652,7 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device, desc.alpha_to_coverage = state->alpha_to_coverage; if (state->rs[WINED3D_RS_ADAPTIVETESS_Y] == WINED3DFMT_ATOC) desc.alpha_to_coverage = TRUE; + desc.enable = state->rs[WINED3D_RS_ALPHABLENDENABLE];
if (wined3d_bitmap_is_set(changed->renderState, WINED3D_RS_BLENDFACTOR)) wined3d_color_from_d3dcolor(&colour, state->rs[WINED3D_RS_BLENDFACTOR]); diff --git a/dlls/wined3d/shader.c b/dlls/wined3d/shader.c index 757631a73e..13e55cff8a 100644 --- a/dlls/wined3d/shader.c +++ b/dlls/wined3d/shader.c @@ -3909,7 +3909,7 @@ void find_ps_compile_args(const struct wined3d_state *state, const struct wined3 static unsigned int warned = 0;
args->srgb_correction = 1; - if (state->render_states[WINED3D_RS_ALPHABLENDENABLE] && !warned++) + if (state->blend_state && state->blend_state->desc.enable && !warned++) WARN("Blending into a sRGB render target with no GL_ARB_framebuffer_sRGB " "support, expect rendering artifacts.\n"); } diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index ca59eba1d7..0931d60fe8 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -525,15 +525,16 @@ static void gl_blend_from_d3d(GLenum *src_blend, GLenum *dst_blend, } }
-static void state_blend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) +static void state_blend(struct wined3d_context *context, const struct wined3d_state *state) { const struct wined3d_gl_info *gl_info = wined3d_context_gl(context)->gl_info; + const struct wined3d_blend_state *b = state->blend_state; const struct wined3d_format *rt_format; GLenum src_blend, dst_blend; unsigned int rt_fmt_flags; BOOL enable_blend;
- enable_blend = state->fb->render_targets[0] && state->render_states[WINED3D_RS_ALPHABLENDENABLE]; + enable_blend = state->fb->render_targets[0] && b && b->desc.enable; if (enable_blend) { rt_format = state->fb->render_targets[0]->format; @@ -589,8 +590,8 @@ static void state_blend(struct wined3d_context *context, const struct wined3d_st checkGLcall("glBlendFunc"); }
- /* Colorkey fixup for stage 0 alphaop depends on - * WINED3D_RS_ALPHABLENDENABLE state, so it may need updating. */ + /* Colorkey fixup for stage 0 alphaop depends on blend state, so it may need + * updating. */ if (state->render_states[WINED3D_RS_COLORKEYENABLE]) context_apply_state(context, state, STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP)); } @@ -611,26 +612,21 @@ static void state_blend_factor(struct wined3d_context *context, const struct win checkGLcall("glBlendColor"); }
-static void state_blend_object(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) +static void blend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { const struct wined3d_gl_info *gl_info = wined3d_context_gl(context)->gl_info; - BOOL alpha_to_coverage = FALSE; + const struct wined3d_blend_state *b = state->blend_state;
- if (!gl_info->supported[ARB_MULTISAMPLE]) - return; - - if (state->blend_state) + if (gl_info->supported[ARB_MULTISAMPLE]) { - struct wined3d_blend_state_desc *desc = &state->blend_state->desc; - alpha_to_coverage = desc->alpha_to_coverage; + if (b && b->desc.alpha_to_coverage) + gl_info->gl_ops.gl.p_glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); + else + gl_info->gl_ops.gl.p_glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); + checkGLcall("glEnable GL_SAMPLE_ALPHA_TO_COVERAGE"); }
- if (alpha_to_coverage) - gl_info->gl_ops.gl.p_glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); - else - gl_info->gl_ops.gl.p_glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); - - checkGLcall("blend state"); + state_blend(context, state); }
void state_alpha_test(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) @@ -3222,10 +3218,9 @@ void tex_alphaop(struct wined3d_context *context, const struct wined3d_state *st * SELECTARG/CURRENT, yet puts garbage in diffuse alpha (zeroes). This works on native, because the * game disables alpha test and alpha blending. Alpha test is overwritten by wine's for purposes of * color-keying though, so this will lead to missing geometry if texture alpha is modulated (pixels - * fail alpha test). To get around this, ALPHABLENDENABLE state is checked: if the app enables alpha - * blending, it can be expected to provide meaningful values in diffuse alpha, so it should be - * modulated with texture alpha; otherwise, selecting diffuse alpha is ignored in favour of texture - * alpha. + * fail alpha test). To get around this, blend state is checked: if the app enables alpha blending, + * it can be expected to provide meaningful values in diffuse alpha, so it should be modulated with + * texture alpha; otherwise, selecting diffuse alpha is ignored in favour of texture alpha. * * What to do with multitexturing? So far no app has been found that uses color keying with * multitexturing */ @@ -3236,7 +3231,7 @@ void tex_alphaop(struct wined3d_context *context, const struct wined3d_state *st } else if (op == WINED3D_TOP_SELECT_ARG1 && arg1 != WINED3DTA_TEXTURE) { - if (state->render_states[WINED3D_RS_ALPHABLENDENABLE]) + if (state->blend_state && state->blend_state->desc.enable) { arg2 = WINED3DTA_TEXTURE; op = WINED3D_TOP_MODULATE; @@ -3245,7 +3240,7 @@ void tex_alphaop(struct wined3d_context *context, const struct wined3d_state *st } else if (op == WINED3D_TOP_SELECT_ARG2 && arg2 != WINED3DTA_TEXTURE) { - if (state->render_states[WINED3D_RS_ALPHABLENDENABLE]) + if (state->blend_state && state->blend_state->desc.enable) { arg1 = WINED3DTA_TEXTURE; op = WINED3D_TOP_MODULATE; @@ -4509,16 +4504,15 @@ const struct wined3d_state_entry_template misc_state_template[] = { STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING, { STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING, state_uav_warn }, WINED3D_GL_EXT_NONE }, { STATE_STREAM_OUTPUT, { STATE_STREAM_OUTPUT, state_so, }, WINED3D_GL_VERSION_3_2 }, { STATE_STREAM_OUTPUT, { STATE_STREAM_OUTPUT, state_so_warn, }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3D_RS_SRCBLEND), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3D_RS_DESTBLEND), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), state_blend }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_SRCBLEND), { STATE_BLEND, NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_DESTBLEND), { STATE_BLEND, NULL }, WINED3D_GL_EXT_NONE }, { STATE_RENDER(WINED3D_RS_EDGEANTIALIAS), { STATE_RENDER(WINED3D_RS_EDGEANTIALIAS), state_line_antialias}, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3D_RS_SEPARATEALPHABLENDENABLE), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3D_RS_SRCBLENDALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3D_RS_DESTBLENDALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3D_RS_DESTBLENDALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3D_RS_BLENDOPALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_BLEND, { STATE_BLEND, state_blend_object }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_SEPARATEALPHABLENDENABLE), { STATE_BLEND, NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_SRCBLENDALPHA), { STATE_BLEND, NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_DESTBLENDALPHA), { STATE_BLEND, NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_DESTBLENDALPHA), { STATE_BLEND, NULL }, WINED3D_GL_EXT_NONE }, + { STATE_RENDER(WINED3D_RS_BLENDOPALPHA), { STATE_BLEND, NULL }, WINED3D_GL_EXT_NONE }, + { STATE_BLEND, { STATE_BLEND, blend }, WINED3D_GL_EXT_NONE }, { STATE_BLEND_FACTOR, { STATE_BLEND_FACTOR, state_blend_factor }, EXT_BLEND_COLOR }, { STATE_BLEND_FACTOR, { STATE_BLEND_FACTOR, state_blend_factor_w}, WINED3D_GL_EXT_NONE }, { STATE_STREAMSRC, { STATE_STREAMSRC, streamsrc }, WINED3D_GL_EXT_NONE }, @@ -5427,6 +5421,7 @@ static void validate_state_table(struct wined3d_state_entry *state_table) { 8, 8}, { 17, 18}, { 21, 22}, + { 27, 27}, { 42, 45}, { 47, 47}, { 61, 127}, diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index f696b92214..82a4e2ca0d 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -6134,7 +6134,7 @@ void gen_ffp_frag_op(const struct wined3d_context *context, const struct wined3d } else if (aop == WINED3D_TOP_SELECT_ARG1 && aarg1 != WINED3DTA_TEXTURE) { - if (state->render_states[WINED3D_RS_ALPHABLENDENABLE]) + if (state->blend_state && state->blend_state->desc.enable) { aarg2 = WINED3DTA_TEXTURE; aop = WINED3D_TOP_MODULATE; @@ -6143,7 +6143,7 @@ void gen_ffp_frag_op(const struct wined3d_context *context, const struct wined3d } else if (aop == WINED3D_TOP_SELECT_ARG2 && aarg2 != WINED3DTA_TEXTURE) { - if (state->render_states[WINED3D_RS_ALPHABLENDENABLE]) + if (state->blend_state && state->blend_state->desc.enable) { aarg1 = WINED3DTA_TEXTURE; aop = WINED3D_TOP_MODULATE; diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index 571e3d8d35..f6353bed32 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -2029,6 +2029,7 @@ struct wined3d_buffer_desc struct wined3d_blend_state_desc { BOOL alpha_to_coverage; + BOOL enable; };
struct wined3d_rasterizer_state_desc