wined3d: Present does not clear the depth stencil.

This commit is contained in:
Stefan Dösinger 2007-06-14 11:18:03 +02:00 committed by Alexandre Julliard
parent c9b8a79e0b
commit 078523f73e
3 changed files with 113 additions and 15 deletions

View File

@ -116,6 +116,8 @@ static IDirect3DDevice8 *init_d3d8(void)
present_parameters.BackBufferWidth = 640; present_parameters.BackBufferWidth = 640;
present_parameters.BackBufferHeight = 480; present_parameters.BackBufferHeight = 480;
present_parameters.BackBufferFormat = D3DFMT_X8R8G8B8; present_parameters.BackBufferFormat = D3DFMT_X8R8G8B8;
present_parameters.EnableAutoDepthStencil = TRUE;
present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
hr = IDirect3D8_CreateDevice(d3d8_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr); hr = IDirect3D8_CreateDevice(d3d8_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
ok(hr == D3D_OK, "IDirect3D_CreateDevice returned: %s\n", DXGetErrorString8(hr)); ok(hr == D3D_OK, "IDirect3D_CreateDevice returned: %s\n", DXGetErrorString8(hr));
@ -441,6 +443,58 @@ static void fog_test(IDirect3DDevice8 *device)
ok(hr == D3D_OK, "Turning off fog calculations returned %s\n", DXGetErrorString8(hr)); ok(hr == D3D_OK, "Turning off fog calculations returned %s\n", DXGetErrorString8(hr));
} }
static void present_test(IDirect3DDevice8 *device)
{
struct vertex quad[] =
{
{-1.0f, -1.0f, 0.9f, 0xffff0000},
{-1.0f, 1.0f, 0.9f, 0xffff0000},
{ 1.0f, -1.0f, 0.1f, 0xffff0000},
{ 1.0f, 1.0f, 0.1f, 0xffff0000},
};
HRESULT hr;
DWORD color;
/* Does the Present clear the depth stencil? Clear the depth buffer with some value != 0,
* then call Present. Then clear the color buffer to make sure it has some defined content
* after the Present with D3DSWAPEFFECT_DISCARD. After that draw a plane that is somewhere cut
* by the depth value.
*/
hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.75, 0);
ok(hr == D3D_OK, "IDirect3DDevice8_Clear returned %s\n", DXGetErrorString8(hr));
hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.4, 0);
hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr));
hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_GREATER);
ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr));
hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
ok(hr == D3D_OK, "IDirect3DDevice8_SetFVF returned %s\n", DXGetErrorString8(hr));
hr = IDirect3DDevice8_BeginScene(device);
ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %s\n", DXGetErrorString8(hr));
if(hr == D3D_OK)
{
/* No lights are defined... That means, lit vertices should be entirely black */
hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2 /*PrimCount */, quad, sizeof(quad[0]));
ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %s\n", DXGetErrorString8(hr));
hr = IDirect3DDevice8_EndScene(device);
ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %s\n", DXGetErrorString8(hr));
}
hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr));
hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
color = getPixelColor(device, 512, 240);
ok(color == 0x00ffffff, "Present failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
color = getPixelColor(device, 64, 240);
ok(color == 0x00ff0000, "Present failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
}
START_TEST(visual) START_TEST(visual)
{ {
IDirect3DDevice8 *device_ptr; IDirect3DDevice8 *device_ptr;
@ -492,6 +546,7 @@ START_TEST(visual)
lighting_test(device_ptr); lighting_test(device_ptr);
clear_test(device_ptr); clear_test(device_ptr);
fog_test(device_ptr); fog_test(device_ptr);
present_test(device_ptr);
cleanup: cleanup:
if(device_ptr) IDirect3DDevice8_Release(device_ptr); if(device_ptr) IDirect3DDevice8_Release(device_ptr);

View File

@ -116,6 +116,8 @@ static IDirect3DDevice9 *init_d3d9(void)
present_parameters.BackBufferWidth = 640; present_parameters.BackBufferWidth = 640;
present_parameters.BackBufferHeight = 480; present_parameters.BackBufferHeight = 480;
present_parameters.BackBufferFormat = D3DFMT_X8R8G8B8; present_parameters.BackBufferFormat = D3DFMT_X8R8G8B8;
present_parameters.EnableAutoDepthStencil = TRUE;
present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
hr = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr); hr = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
ok(hr == D3D_OK, "IDirect3D_CreateDevice returned: %s\n", DXGetErrorString9(hr)); ok(hr == D3D_OK, "IDirect3D_CreateDevice returned: %s\n", DXGetErrorString9(hr));
@ -1114,6 +1116,58 @@ static void texbem_test(IDirect3DDevice9 *device)
} }
} }
static void present_test(IDirect3DDevice9 *device)
{
struct vertex quad[] =
{
{-1.0f, -1.0f, 0.9f, 0xffff0000},
{-1.0f, 1.0f, 0.9f, 0xffff0000},
{ 1.0f, -1.0f, 0.1f, 0xffff0000},
{ 1.0f, 1.0f, 0.1f, 0xffff0000},
};
HRESULT hr;
DWORD color;
/* Does the Present clear the depth stencil? Clear the depth buffer with some value != 0,
* then call Present. Then clear the color buffer to make sure it has some defined content
* after the Present with D3DSWAPEFFECT_DISCARD. After that draw a plane that is somewhere cut
* by the depth value.
*/
hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.75, 0);
ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr));
hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.4, 0);
hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr));
hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_GREATER);
ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr));
hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF returned %s\n", DXGetErrorString9(hr));
hr = IDirect3DDevice9_BeginScene(device);
ok(hr == D3D_OK, "IDirect3DDevice9_BeginScene failed with %s\n", DXGetErrorString9(hr));
if(hr == D3D_OK)
{
/* No lights are defined... That means, lit vertices should be entirely black */
hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2 /*PrimCount */, quad, sizeof(quad[0]));
ok(hr == D3D_OK, "IDirect3DDevice9_DrawIndexedPrimitiveUP failed with %s\n", DXGetErrorString9(hr));
hr = IDirect3DDevice9_EndScene(device);
ok(hr == D3D_OK, "IDirect3DDevice9_EndScene failed with %s\n", DXGetErrorString9(hr));
}
hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr));
hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
color = getPixelColor(device, 512, 240);
ok(color == 0x00ffffff, "Present failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
color = getPixelColor(device, 64, 240);
ok(color == 0x00ff0000, "Present failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
}
START_TEST(visual) START_TEST(visual)
{ {
IDirect3DDevice9 *device_ptr; IDirect3DDevice9 *device_ptr;
@ -1169,6 +1223,7 @@ START_TEST(visual)
clear_test(device_ptr); clear_test(device_ptr);
fog_test(device_ptr); fog_test(device_ptr);
test_cube_wrap(device_ptr); test_cube_wrap(device_ptr);
present_test(device_ptr);
if (caps.VertexShaderVersion >= D3DVS_VERSION(2, 0)) if (caps.VertexShaderVersion >= D3DVS_VERSION(2, 0))
{ {

View File

@ -148,7 +148,6 @@ static void WINAPI IWineD3DSwapChainImpl_Destroy(IWineD3DSwapChain *iface, D3DCB
static HRESULT WINAPI IWineD3DSwapChainImpl_Present(IWineD3DSwapChain *iface, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) { static HRESULT WINAPI IWineD3DSwapChainImpl_Present(IWineD3DSwapChain *iface, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) {
IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface; IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
DWORD clear_flags = 0;
unsigned int sync; unsigned int sync;
int retval; int retval;
@ -298,22 +297,11 @@ static HRESULT WINAPI IWineD3DSwapChainImpl_Present(IWineD3DSwapChain *iface, CO
LEAVE_GL(); LEAVE_GL();
if (This->wineD3DDevice->stencilBufferTarget) {
clear_flags |= WINED3DCLEAR_STENCIL|WINED3DCLEAR_ZBUFFER;
}
/* Although this is not strictly required, a simple demo showed this does occur
on (at least non-debug) d3d */
if (This->presentParms.SwapEffect == WINED3DSWAPEFFECT_DISCARD) { if (This->presentParms.SwapEffect == WINED3DSWAPEFFECT_DISCARD) {
TRACE("Clearing the color buffer with pink color\n");
TRACE("Clearing\n"); IWineD3DDevice_Clear((IWineD3DDevice*)This->wineD3DDevice, 0, NULL,
WINED3DCLEAR_TARGET, 0xff00ffff, 1.0, 0);
IWineD3DDevice_Clear((IWineD3DDevice*)This->wineD3DDevice, 0, NULL, clear_flags|WINED3DCLEAR_TARGET, 0x00, 1.0, 0);
} else if (clear_flags) {
TRACE("Clearing z/stencil buffer\n");
IWineD3DDevice_Clear((IWineD3DDevice*)This->wineD3DDevice, 0, NULL, clear_flags, 0x00, 1.0, 0);
} }
if(((IWineD3DSurfaceImpl *) This->frontBuffer)->Flags & SFLAG_INSYSMEM || if(((IWineD3DSurfaceImpl *) This->frontBuffer)->Flags & SFLAG_INSYSMEM ||