Signed-off-by: Paul Gofman gofmanp@gmail.com --- dlls/ddraw/device.c | 78 +++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 48 deletions(-)
diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c index e07fe007f0..266499df4d 100644 --- a/dlls/ddraw/device.c +++ b/dlls/ddraw/device.c @@ -2664,6 +2664,33 @@ static HRESULT WINAPI d3d_device7_SetRenderState_FPUPreserve(IDirect3DDevice7 *i return hr; }
+static void fixup_texture_alpha_op(struct d3d_device *device) +{ + /* This fixup is required by the way D3DTBLEND_MODULATE maps to texture stage states. + See d3d_device3_SetRenderState() for details. */ + struct wined3d_texture *tex; + BOOL tex_alpha = FALSE; + DDPIXELFORMAT ddfmt; + + if (!(device->legacyTextureBlending && device->texture_map_blend == D3DTBLEND_MODULATE)) + return; + + 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; + } + + /* Args 1 and 2 are already set to WINED3DTA_TEXTURE/WINED3DTA_CURRENT in case of D3DTBLEND_MODULATE */ + wined3d_device_set_texture_stage_state(device->wined3d_device, + 0, WINED3D_TSS_ALPHA_OP, tex_alpha ? WINED3D_TOP_SELECT_ARG1 : WINED3D_TOP_SELECT_ARG2); +} + static HRESULT WINAPI d3d_device3_SetRenderState(IDirect3DDevice3 *iface, D3DRENDERSTATETYPE state, DWORD value) { @@ -2734,32 +2761,14 @@ static HRESULT WINAPI d3d_device3_SetRenderState(IDirect3DDevice3 *iface, }
device->legacyTextureBlending = TRUE; + device->texture_map_blend = value;
switch (value) { case D3DTBLEND_MODULATE: { - 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; + fixup_texture_alpha_op(device);
- 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 (tex_alpha) - wined3d_device_set_texture_stage_state(device->wined3d_device, - 0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_SELECT_ARG1); - else - wined3d_device_set_texture_stage_state(device->wined3d_device, - 0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_SELECT_ARG2); wined3d_device_set_texture_stage_state(device->wined3d_device, 0, WINED3D_TSS_ALPHA_ARG1, WINED3DTA_TEXTURE); wined3d_device_set_texture_stage_state(device->wined3d_device, @@ -2829,7 +2838,6 @@ 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; } @@ -4908,33 +4916,7 @@ static HRESULT WINAPI d3d_device3_SetTexture(IDirect3DDevice3 *iface,
hr = IDirect3DDevice7_SetTexture(&device->IDirect3DDevice7_iface, stage, &tex->IDirectDrawSurface7_iface);
- 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. */ - 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; - } - - /* Args 1 and 2 are already set to WINED3DTA_TEXTURE/WINED3DTA_CURRENT in case of D3DTBLEND_MODULATE */ - if (tex_alpha) - wined3d_device_set_texture_stage_state(device->wined3d_device, - 0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_SELECT_ARG1); - else - wined3d_device_set_texture_stage_state(device->wined3d_device, - 0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_SELECT_ARG2); - } + fixup_texture_alpha_op(device);
wined3d_mutex_unlock();
Signed-off-by: Paul Gofman gofmanp@gmail.com --- dlls/ddraw/device.c | 6 ++-- dlls/ddraw/tests/ddraw4.c | 65 +++++++++++++++++++++++++++------------ 2 files changed, 49 insertions(+), 22 deletions(-)
diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c index 266499df4d..5f86450eec 100644 --- a/dlls/ddraw/device.c +++ b/dlls/ddraw/device.c @@ -2669,7 +2669,7 @@ static void fixup_texture_alpha_op(struct d3d_device *device) /* This fixup is required by the way D3DTBLEND_MODULATE maps to texture stage states. See d3d_device3_SetRenderState() for details. */ struct wined3d_texture *tex; - BOOL tex_alpha = FALSE; + BOOL tex_alpha = TRUE; DDPIXELFORMAT ddfmt;
if (!(device->legacyTextureBlending && device->texture_map_blend == D3DTBLEND_MODULATE)) @@ -2682,8 +2682,8 @@ static void fixup_texture_alpha_op(struct d3d_device *device) 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 (!ddfmt.u5.dwRGBAlphaBitMask) + tex_alpha = FALSE; }
/* Args 1 and 2 are already set to WINED3DTA_TEXTURE/WINED3DTA_CURRENT in case of D3DTBLEND_MODULATE */ diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c index 6121f4f2c1..139566dbca 100644 --- a/dlls/ddraw/tests/ddraw4.c +++ b/dlls/ddraw/tests/ddraw4.c @@ -9506,6 +9506,7 @@ static void test_texturemapblend(void) DDCOLORKEY ckey; D3DCOLOR color; ULONG refcount; + DWORD value; HWND window; DDBLTFX fx; HRESULT hr; @@ -9548,20 +9549,24 @@ static void test_texturemapblend(void) }
hr = IDirect3DDevice3_GetDirect3D(device, &d3d); - ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw); - ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); hr = IDirect3DDevice3_GetRenderTarget(device, &rt); - ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
viewport = create_viewport(device, 0, 0, 640, 480); hr = IDirect3DDevice3_SetCurrentViewport(device, viewport); - ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected 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);
+ hr = IDirect3DDevice3_GetTextureStageState(device, 0, D3DTSS_ALPHAOP, &value); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(value == D3DTOP_SELECTARG1, "Got unexpected D3DTSS_ALPHAOP value %#x.\n", value); + /* Test alpha with DDPF_ALPHAPIXELS texture - should be taken from texture * alpha channel. * @@ -9582,15 +9587,29 @@ static void test_texturemapblend(void) U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff; U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000; hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL); - ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture); - ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); hr = IDirect3DDevice3_SetTexture(device, 0, texture); - ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice3_GetTextureStageState(device, 0, D3DTSS_ALPHAOP, &value); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(value == D3DTOP_SELECTARG1, "Got unexpected D3DTSS_ALPHAOP value %#x.\n", value); + + hr = IDirect3DDevice3_SetTexture(device, 0, NULL); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice3_GetTextureStageState(device, 0, D3DTSS_ALPHAOP, &value); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(value == D3DTOP_SELECTARG1, "Got unexpected D3DTSS_ALPHAOP value %#x.\n", value); + + hr = IDirect3DDevice3_SetTexture(device, 0, texture); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DViewport3_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET); - ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
memset(&fx, 0, sizeof(fx)); fx.dwSize = sizeof(fx); @@ -9615,8 +9634,12 @@ static void test_texturemapblend(void) ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE); ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + +#if 0 + /* Disable the call to test that the device has this state by default. */ hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATE); ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); +#endif
/* Texture stage state does not change so legacy texture blending stays enabled. */ hr = IDirect3DDevice3_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); @@ -9727,7 +9750,7 @@ static void test_texturemapblend(void) ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
hr = IDirect3DDevice3_SetTexture(device, 0, NULL); - ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); IDirect3DTexture2_Release(texture); refcount = IDirectDrawSurface4_Release(surface); ok(!refcount, "Surface not properly released, refcount %u.\n", refcount); @@ -9748,33 +9771,37 @@ static void test_texturemapblend(void) U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL); - ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture); - ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); hr = IDirect3DDevice3_SetTexture(device, 0, texture); - ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice3_GetTextureStageState(device, 0, D3DTSS_ALPHAOP, &value); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(value == D3DTOP_SELECTARG2, "Got unexpected D3DTSS_ALPHAOP value %#x.\n", value);
hr = IDirect3DViewport3_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET); - ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
U5(fx).dwFillColor = 0xff0000ff; hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx); - ok(SUCCEEDED(hr), "Failed to clear texture, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); U5(fx).dwFillColor = 0x800000ff; hr = IDirectDrawSurface4_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx); - ok(SUCCEEDED(hr), "Failed to clear texture, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DDevice3_BeginScene(device); - ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, &test1_quads[0], 4, 0); - ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, &test1_quads[4], 4, 0); - ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); hr = IDirect3DDevice3_EndScene(device); - ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
color = get_surface_color(rt, 5, 5); ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=54034
Your paranoid android.
=== debian9 (32 bit Chinese:China report) ===
ddraw: ddraw2.c:3030: Test failed: Expected message 0x7e, but didn't receive it.