[PATCH 2/6] wined3d: Add blend_factor inside blend_state

Daniel Ansorregui mailszeros at gmail.com
Mon Oct 15 14:17:16 CDT 2018


* This is a temporary patch, where the d3d9/d3d11 are still not unified

Signed-off-by: Daniel Ansorregui <mailszeros at gmail.com>
---
 dlls/d3d11/device.c            | 14 +++++---------
 dlls/wined3d/cs.c              |  6 +++++-
 dlls/wined3d/device.c          | 17 +++++++++++++----
 dlls/wined3d/state.c           | 10 ++++++++++
 dlls/wined3d/stateblock.c      |  5 +++++
 dlls/wined3d/wined3d.spec      |  3 ++-
 dlls/wined3d/wined3d_private.h |  4 +++-
 include/wine/wined3d.h         |  4 +++-
 8 files changed, 46 insertions(+), 17 deletions(-)

diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c
index 157ff0341a..527a2f97b6 100644
--- a/dlls/d3d11/device.c
+++ b/dlls/d3d11/device.c
@@ -714,7 +714,8 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetBlendState(ID3D11Devi
     wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK, sample_mask);
     if (!(blend_state_impl = unsafe_impl_from_ID3D11BlendState(blend_state)))
     {
-        wined3d_device_set_blend_state(device->wined3d_device, NULL);
+        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);
@@ -728,7 +729,8 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetBlendState(ID3D11Devi
         return;
     }
 
-    wined3d_device_set_blend_state(device->wined3d_device, blend_state_impl->wined3d_state);
+    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);
@@ -743,13 +745,6 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetBlendState(ID3D11Devi
         wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLENDALPHA, d->SrcBlendAlpha);
         wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLENDALPHA, d->DestBlendAlpha);
         wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOPALPHA, d->BlendOpAlpha);
-
-        if (memcmp(blend_factor, default_blend_factor, sizeof(default_blend_factor))
-                && (d->SrcBlend == D3D11_BLEND_BLEND_FACTOR || d->SrcBlend == D3D11_BLEND_INV_BLEND_FACTOR
-                || d->DestBlend == D3D11_BLEND_BLEND_FACTOR || d->DestBlend == D3D11_BLEND_INV_BLEND_FACTOR
-                || d->SrcBlendAlpha == D3D11_BLEND_BLEND_FACTOR || d->SrcBlendAlpha == D3D11_BLEND_INV_BLEND_FACTOR
-                || d->DestBlendAlpha == D3D11_BLEND_BLEND_FACTOR || d->DestBlendAlpha == D3D11_BLEND_INV_BLEND_FACTOR))
-            FIXME("Ignoring blend factor %s.\n", debug_float4(blend_factor));
     }
     wined3d_device_set_render_state(device->wined3d_device,
             WINED3D_RS_COLORWRITEENABLE, desc->RenderTarget[0].RenderTargetWriteMask);
@@ -1952,6 +1947,7 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetBlendState(ID3D11Devi
         *blend_state = NULL;
     }
     memcpy(blend_factor, device->blend_factor, 4 * sizeof(*blend_factor));
+    wined3d_device_get_blend_factor(device->wined3d_device, (struct wined3d_color *)blend_factor);
     *sample_mask = wined3d_device_get_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK);
     wined3d_mutex_unlock();
 }
diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c
index af1dbef84c..48f043335d 100644
--- a/dlls/wined3d/cs.c
+++ b/dlls/wined3d/cs.c
@@ -264,6 +264,7 @@ struct wined3d_cs_set_blend_state
 {
     enum wined3d_cs_op opcode;
     struct wined3d_blend_state *state;
+    struct wined3d_color factor;
 };
 
 struct wined3d_cs_set_rasterizer_state
@@ -1541,16 +1542,19 @@ static void wined3d_cs_exec_set_blend_state(struct wined3d_cs *cs, const void *d
     const struct wined3d_cs_set_blend_state *op = data;
 
     cs->state.blend_state = op->state;
+    cs->state.blend_factor = op->factor;
     device_invalidate_state(cs->device, STATE_BLEND);
 }
 
-void wined3d_cs_emit_set_blend_state(struct wined3d_cs *cs, struct wined3d_blend_state *state)
+void wined3d_cs_emit_set_blend_state(struct wined3d_cs *cs, struct wined3d_blend_state *state,
+        const struct wined3d_color *blend_factor)
 {
     struct wined3d_cs_set_blend_state *op;
 
     op = cs->ops->require_space(cs, sizeof(*op), WINED3D_CS_QUEUE_DEFAULT);
     op->opcode = WINED3D_CS_OP_SET_BLEND_STATE;
     op->state = state;
+    op->factor = *blend_factor;
 
     cs->ops->submit(cs, WINED3D_CS_QUEUE_DEFAULT);
 }
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index abb2a89363..365a46e9d6 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -1968,20 +1968,29 @@ static void resolve_depth_buffer(struct wined3d_device *device)
             src_view->resource, src_view->sub_resource_idx, dst_resource->format->id);
 }
 
-void CDECL wined3d_device_set_blend_state(struct wined3d_device *device, struct wined3d_blend_state *blend_state)
+void CDECL wined3d_device_get_blend_factor(const struct wined3d_device *device, struct wined3d_color *blend_factor)
+{
+    TRACE("device %p, blend_factor %s.\n", device, debug_color(&device->state.blend_factor));
+
+    memcpy(blend_factor, &device->state.blend_factor, sizeof(*blend_factor));
+}
+
+void CDECL wined3d_device_set_blend_state(struct wined3d_device *device, struct wined3d_blend_state *blend_state,
+        const struct wined3d_color *blend_factor)
 {
     struct wined3d_blend_state *prev;
 
-    TRACE("device %p, blend_state %p.\n", device, blend_state);
+    TRACE("device %p, blend_state %p, blend_factor %s.\n", device, blend_state, debug_color(blend_factor));
 
     prev = device->update_state->blend_state;
-    if (prev == blend_state)
+    if (prev == blend_state && !memcmp(blend_factor, &device->update_state->blend_factor, sizeof(*blend_factor)))
         return;
 
     if (blend_state)
         wined3d_blend_state_incref(blend_state);
     device->update_state->blend_state = blend_state;
-    wined3d_cs_emit_set_blend_state(device->cs, blend_state);
+    device->update_state->blend_factor = *blend_factor;
+    wined3d_cs_emit_set_blend_state(device->cs, blend_state, blend_factor);
     if (prev)
         wined3d_blend_state_decref(prev);
 }
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
index 375bc6562a..bbc2ddc9e1 100644
--- a/dlls/wined3d/state.c
+++ b/dlls/wined3d/state.c
@@ -619,6 +619,16 @@ static void state_blend_object(struct wined3d_context *context, const struct win
     const struct wined3d_gl_info *gl_info = context->gl_info;
     BOOL alpha_to_coverage = FALSE;
 
+    if(gl_info->supported[EXT_BLEND_COLOR])
+    {
+        TRACE("Setting blend factor to %s.\n", debug_color(&state->blend_factor));
+
+        GL_EXTCALL(glBlendColor(state->blend_factor.r, state->blend_factor.g, state->blend_factor.b, state->blend_factor.a));
+        checkGLcall("glBlendColor");
+    }
+    else
+        WARN("Unsupported in local OpenGL implementation: glBlendColor.\n");
+
     if (!gl_info->supported[ARB_MULTISAMPLE])
         return;
 
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c
index 45a4008ac4..213b120752 100644
--- a/dlls/wined3d/stateblock.c
+++ b/dlls/wined3d/stateblock.c
@@ -1314,6 +1314,11 @@ static void state_init_default(struct wined3d_state *state, const struct wined3d
         /* TODO: Vertex offset in the presampled displacement map. */
         state->sampler_states[i][WINED3D_SAMP_DMAP_OFFSET] = 0;
     }
+
+    state->blend_factor.r = 1.0f;
+    state->blend_factor.g = 1.0f;
+    state->blend_factor.b = 1.0f;
+    state->blend_factor.a = 1.0f;
 }
 
 void state_init(struct wined3d_state *state, struct wined3d_fb_state *fb,
diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec
index 7944387bca..d958cd41c8 100644
--- a/dlls/wined3d/wined3d.spec
+++ b/dlls/wined3d/wined3d.spec
@@ -57,6 +57,7 @@
 @ cdecl wined3d_device_evict_managed_resources(ptr)
 @ cdecl wined3d_device_get_available_texture_mem(ptr)
 @ cdecl wined3d_device_get_base_vertex_index(ptr)
+@ cdecl wined3d_device_get_blend_factor(ptr ptr)
 @ cdecl wined3d_device_get_blend_state(ptr)
 @ cdecl wined3d_device_get_clip_plane(ptr long ptr)
 @ cdecl wined3d_device_get_clip_status(ptr ptr)
@@ -129,7 +130,7 @@
 @ cdecl wined3d_device_resolve_sub_resource(ptr ptr long ptr long long)
 @ cdecl wined3d_device_restore_fullscreen_window(ptr ptr ptr)
 @ cdecl wined3d_device_set_base_vertex_index(ptr long)
-@ cdecl wined3d_device_set_blend_state(ptr ptr)
+@ cdecl wined3d_device_set_blend_state(ptr ptr ptr)
 @ cdecl wined3d_device_set_clip_plane(ptr long ptr)
 @ cdecl wined3d_device_set_clip_status(ptr ptr)
 @ cdecl wined3d_device_set_compute_shader(ptr ptr)
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index c3761860b0..afa711f033 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2934,6 +2934,7 @@ struct wined3d_state
 
     DWORD render_states[WINEHIGHEST_RENDER_STATE + 1];
     struct wined3d_blend_state *blend_state;
+    struct wined3d_color blend_factor;
     struct wined3d_rasterizer_state *rasterizer_state;
 };
 
@@ -3646,7 +3647,8 @@ void wined3d_cs_emit_present(struct wined3d_cs *cs, struct wined3d_swapchain *sw
         const RECT *dst_rect, HWND dst_window_override, unsigned int swap_interval, DWORD flags) DECLSPEC_HIDDEN;
 void wined3d_cs_emit_query_issue(struct wined3d_cs *cs, struct wined3d_query *query, DWORD flags) DECLSPEC_HIDDEN;
 void wined3d_cs_emit_reset_state(struct wined3d_cs *cs) DECLSPEC_HIDDEN;
-void wined3d_cs_emit_set_blend_state(struct wined3d_cs *cs, struct wined3d_blend_state *state) DECLSPEC_HIDDEN;
+void wined3d_cs_emit_set_blend_state(struct wined3d_cs *cs, struct wined3d_blend_state *state,
+        const struct wined3d_color *blend_factor) DECLSPEC_HIDDEN;
 void wined3d_cs_emit_set_clip_plane(struct wined3d_cs *cs, UINT plane_idx,
         const struct wined3d_vec4 *plane) DECLSPEC_HIDDEN;
 void wined3d_cs_emit_set_color_key(struct wined3d_cs *cs, struct wined3d_texture *texture,
diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h
index c62d3640e5..286df47c77 100644
--- a/include/wine/wined3d.h
+++ b/include/wine/wined3d.h
@@ -2264,6 +2264,7 @@ HRESULT __cdecl wined3d_device_end_stateblock(struct wined3d_device *device, str
 void __cdecl wined3d_device_evict_managed_resources(struct wined3d_device *device);
 UINT __cdecl wined3d_device_get_available_texture_mem(const struct wined3d_device *device);
 INT __cdecl wined3d_device_get_base_vertex_index(const struct wined3d_device *device);
+void __cdecl wined3d_device_get_blend_factor(const struct wined3d_device *device, struct wined3d_color *factor);
 struct wined3d_blend_state * __cdecl wined3d_device_get_blend_state(const struct wined3d_device *device);
 HRESULT __cdecl wined3d_device_get_clip_plane(const struct wined3d_device *device,
         UINT plane_idx, struct wined3d_vec4 *plane);
@@ -2379,7 +2380,8 @@ void __cdecl wined3d_device_resolve_sub_resource(struct wined3d_device *device,
 void __cdecl wined3d_device_restore_fullscreen_window(struct wined3d_device *device, HWND window,
         const RECT *window_rect);
 void __cdecl wined3d_device_set_base_vertex_index(struct wined3d_device *device, INT base_index);
-void __cdecl wined3d_device_set_blend_state(struct wined3d_device *device, struct wined3d_blend_state *blend_state);
+void __cdecl wined3d_device_set_blend_state(struct wined3d_device *device, struct wined3d_blend_state *blend_state,
+        const struct wined3d_color *blend_factor);
 HRESULT __cdecl wined3d_device_set_clip_plane(struct wined3d_device *device,
         UINT plane_idx, const struct wined3d_vec4 *plane);
 HRESULT __cdecl wined3d_device_set_clip_status(struct wined3d_device *device,
-- 
2.17.1




More information about the wine-devel mailing list