From 6886b237ad71c58023a59caeba3c8ed177f4ebcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20D=C3=B6singer?= Date: Tue, 6 Mar 2007 13:54:05 +0100 Subject: [PATCH] wined3d: Disable depth stencil related states without a depth stencil buffer. Except with fbos, it is not possible to remove the depth stencil buffer from the opengl frame buffer, so when the d3d app sets a NULL depth stencil disable all states that work with the depth stencil buffer. --- dlls/wined3d/device.c | 7 +++++++ dlls/wined3d/state.c | 20 +++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 7436ecb7d83..654bf13a359 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -5175,6 +5175,13 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetDepthStencilSurface(IWineD3DDevice * if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) { set_depth_stencil_fbo(iface, pNewZStencil); } + + if((!tmp && pNewZStencil) || (!pNewZStencil && tmp)) { + /* Swapping NULL / non NULL depth stencil affects the depth and tests */ + IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_ZENABLE)); + IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_STENCILENABLE)); + IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_STENCILWRITEMASK)); + } } return hr; diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index c56ce675f0e..00f4876f75d 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -105,6 +105,13 @@ static void state_lighting(DWORD state, IWineD3DStateBlockImpl *stateblock, Wine } static void state_zenable(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) { + /* No z test without depth stencil buffers */ + if(stateblock->wineD3DDevice->stencilBufferTarget == NULL) { + glDisable(GL_DEPTH_TEST); /* This also disables z writing in gl */ + checkGLcall("glDisable GL_DEPTH_TEST"); + return; + } + switch ((WINED3DZBUFFERTYPE) stateblock->renderState[WINED3DRS_ZENABLE]) { case WINED3DZB_FALSE: glDisable(GL_DEPTH_TEST); @@ -611,6 +618,13 @@ state_stencil(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *c GLint depthFail_ccw = GL_KEEP; GLint stencilPass_ccw = GL_KEEP; + /* No stencil test without a stencil buffer */ + if(stateblock->wineD3DDevice->stencilBufferTarget == NULL) { + glDisable(GL_STENCIL_TEST); + checkGLcall("glDisable GL_STENCIL_TEST"); + return; + } + if( stateblock->set.renderState[WINED3DRS_STENCILENABLE] ) onesided_enable = stateblock->renderState[WINED3DRS_STENCILENABLE]; if( stateblock->set.renderState[WINED3DRS_TWOSIDEDSTENCILMODE] ) @@ -664,7 +678,11 @@ state_stencil(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *c } static void state_stencilwrite(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) { - glStencilMask(stateblock->renderState[WINED3DRS_STENCILWRITEMASK]); + if(stateblock->wineD3DDevice->stencilBufferTarget) { + glStencilMask(stateblock->renderState[WINED3DRS_STENCILWRITEMASK]); + } else { + glStencilMask(0); + } checkGLcall("glStencilMask"); }