[PATCH 1/3] ddraw: Store _TEXTUREMAPBLEND state instead of guessing it from wined3d states.

Paul Gofman gofmanp at gmail.com
Tue Jun 18 12:52:24 CDT 2019


Signed-off-by: Paul Gofman <gofmanp at gmail.com>
---
 dlls/ddraw/ddraw_private.h |  1 +
 dlls/ddraw/device.c        | 73 +++++---------------------------------
 dlls/ddraw/tests/ddraw4.c  |  5 +++
 3 files changed, 14 insertions(+), 65 deletions(-)

diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h
index b08f66564c..9e98d81c8e 100644
--- a/dlls/ddraw/ddraw_private.h
+++ b/dlls/ddraw/ddraw_private.h
@@ -327,6 +327,7 @@ struct d3d_device
 
     /* Required to keep track which of two available texture blending modes in d3ddevice3 is used */
     BOOL legacyTextureBlending;
+    D3DTEXTUREBLEND texture_map_blend;
 
     D3DMATRIX legacy_projection;
     D3DMATRIX legacy_clipspace;
diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c
index ac4da191a2..2de9941249 100644
--- a/dlls/ddraw/device.c
+++ b/dlls/ddraw/device.c
@@ -2463,62 +2463,7 @@ static HRESULT WINAPI d3d_device3_GetRenderState(IDirect3DDevice3 *iface,
 
         case D3DRENDERSTATE_TEXTUREMAPBLEND:
         {
-            /* D3DRENDERSTATE_TEXTUREMAPBLEND is mapped to texture state stages in SetRenderState; reverse
-               the mapping to get the value. */
-            DWORD colorop, colorarg1, colorarg2;
-            DWORD alphaop, alphaarg1, alphaarg2;
-
-            wined3d_mutex_lock();
-
-            device->legacyTextureBlending = TRUE;
-
-            colorop = wined3d_device_get_texture_stage_state(device->wined3d_device, 0, WINED3D_TSS_COLOR_OP);
-            colorarg1 = wined3d_device_get_texture_stage_state(device->wined3d_device, 0, WINED3D_TSS_COLOR_ARG1);
-            colorarg2 = wined3d_device_get_texture_stage_state(device->wined3d_device, 0, WINED3D_TSS_COLOR_ARG2);
-            alphaop = wined3d_device_get_texture_stage_state(device->wined3d_device, 0, WINED3D_TSS_ALPHA_OP);
-            alphaarg1 = wined3d_device_get_texture_stage_state(device->wined3d_device, 0, WINED3D_TSS_ALPHA_ARG1);
-            alphaarg2 = wined3d_device_get_texture_stage_state(device->wined3d_device, 0, WINED3D_TSS_ALPHA_ARG2);
-
-            if (colorop == WINED3D_TOP_SELECT_ARG1 && colorarg1 == WINED3DTA_TEXTURE
-                    && alphaop == WINED3D_TOP_SELECT_ARG1 && alphaarg1 == WINED3DTA_TEXTURE)
-                *value = D3DTBLEND_DECAL;
-            else if (colorop == WINED3D_TOP_SELECT_ARG1 && colorarg1 == WINED3DTA_TEXTURE
-                    && alphaop == WINED3D_TOP_MODULATE
-                    && alphaarg1 == WINED3DTA_TEXTURE && alphaarg2 == WINED3DTA_CURRENT)
-                *value = D3DTBLEND_DECALALPHA;
-            else if (colorop == WINED3D_TOP_MODULATE
-                    && colorarg1 == WINED3DTA_TEXTURE && colorarg2 == WINED3DTA_CURRENT
-                    && alphaop == WINED3D_TOP_MODULATE
-                    && alphaarg1 == WINED3DTA_TEXTURE && alphaarg2 == WINED3DTA_CURRENT)
-                *value = D3DTBLEND_MODULATEALPHA;
-            else
-            {
-                struct wined3d_texture *tex = NULL;
-                BOOL tex_alpha = FALSE;
-                DDPIXELFORMAT ddfmt;
-
-                if ((tex = wined3d_device_get_texture(device->wined3d_device, 0)))
-                {
-                    struct wined3d_resource_desc desc;
-
-                    wined3d_resource_get_desc(wined3d_texture_get_resource(tex), &desc);
-                    ddfmt.dwSize = sizeof(ddfmt);
-                    ddrawformat_from_wined3dformat(&ddfmt, desc.format);
-                    if (ddfmt.u5.dwRGBAlphaBitMask)
-                        tex_alpha = TRUE;
-                }
-
-                if (!(colorop == WINED3D_TOP_MODULATE
-                        && colorarg1 == WINED3DTA_TEXTURE && colorarg2 == WINED3DTA_CURRENT
-                        && alphaop == (tex_alpha ? WINED3D_TOP_SELECT_ARG1 : WINED3D_TOP_SELECT_ARG2)
-                        && alphaarg1 == WINED3DTA_TEXTURE && alphaarg2 == WINED3DTA_CURRENT))
-                    ERR("Unexpected texture stage state setup, returning D3DTBLEND_MODULATE - likely erroneous.\n");
-
-                *value = D3DTBLEND_MODULATE;
-            }
-
-            wined3d_mutex_unlock();
-
+            *value = device->texture_map_blend;
             return D3D_OK;
         }
 
@@ -2738,8 +2683,7 @@ static HRESULT WINAPI d3d_device3_SetRenderState(IDirect3DDevice3 *iface,
     in device - TRUE if the app is using TEXTUREMAPBLEND.
 
     Tests show that setting TEXTUREMAPBLEND on native doesn't seem to change values returned by
-    GetTextureStageState and vice versa. Not so on Wine, but it is 'undefined' anyway so, probably, ok,
-    unless some broken game will be found that cares. */
+    GetTextureStageState and vice versa. */
 
     struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
     HRESULT hr;
@@ -2877,7 +2821,7 @@ static HRESULT WINAPI d3d_device3_SetRenderState(IDirect3DDevice3 *iface,
                 default:
                     FIXME("Unhandled texture environment %#x.\n", value);
             }
-
+            device->texture_map_blend = value;
             hr = D3D_OK;
             break;
         }
@@ -4948,19 +4892,15 @@ static HRESULT WINAPI d3d_device3_SetTexture(IDirect3DDevice3 *iface,
 {
     struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
     struct ddraw_surface *tex = unsafe_impl_from_IDirect3DTexture2(texture);
-    DWORD texmapblend;
     HRESULT hr;
 
     TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
 
     wined3d_mutex_lock();
 
-    if (device->legacyTextureBlending)
-        IDirect3DDevice3_GetRenderState(iface, D3DRENDERSTATE_TEXTUREMAPBLEND, &texmapblend);
-
     hr = IDirect3DDevice7_SetTexture(&device->IDirect3DDevice7_iface, stage, &tex->IDirectDrawSurface7_iface);
 
-    if (device->legacyTextureBlending && texmapblend == D3DTBLEND_MODULATE)
+    if (device->legacyTextureBlending && device->texture_map_blend == D3DTBLEND_MODULATE)
     {
         /* This fixup is required by the way D3DTBLEND_MODULATE maps to texture stage states.
            See d3d_device3_SetRenderState() for details. */
@@ -7131,8 +7071,11 @@ static HRESULT d3d_device_init(struct d3d_device *device, struct ddraw *ddraw,
     else if (version == 2)
         wined3d_device_set_render_state(ddraw->wined3d_device, WINED3D_RS_SPECULARENABLE, TRUE);
     if (version < 7)
+    {
         wined3d_device_set_render_state(ddraw->wined3d_device, WINED3D_RS_NORMALIZENORMALS, TRUE);
-
+        IDirect3DDevice3_SetRenderState(&device->IDirect3DDevice3_iface,
+                D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATE);
+    }
     return D3D_OK;
 }
 
diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c
index 7822bbaaf1..d12b0f015a 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -9500,6 +9500,7 @@ static void test_texturemapblend(void)
     DDSURFACEDESC2 surface_desc;
     IDirect3DTexture2 *texture;
     IDirect3DDevice3 *device;
+    DWORD texturemapblend;
     IDirectDraw4 *ddraw;
     IDirect3D3 *d3d;
     DDCOLORKEY ckey;
@@ -9557,6 +9558,10 @@ static void test_texturemapblend(void)
     hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
     ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
 
+    hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_TEXTUREMAPBLEND, &texturemapblend);
+    ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+    ok(texturemapblend == D3DTBLEND_MODULATE, "Got unexpected texture map blend %#x.\n", texturemapblend);
+
     /* Test alpha with DDPF_ALPHAPIXELS texture - should be taken from texture
      * alpha channel.
      *
-- 
2.21.0




More information about the wine-devel mailing list