diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 8c443feb1fc..827365adbac 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -5941,6 +5941,11 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetDepthStencilSurface(IWineD3DDevice * IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_ZENABLE)); IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_STENCILENABLE)); IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_STENCILWRITEMASK)); + IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_DEPTHBIAS)); + } + else if (tmp && tmp->resource.format->depth_size != This->depth_stencil->resource.format->depth_size) + { + IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_DEPTHBIAS)); } return WINED3D_OK; diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index 88ccd1b4094..801563e8dc5 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -1743,14 +1743,17 @@ static void state_scissor(DWORD state, struct wined3d_stateblock *stateblock, st * convert from D3D to GL we need to divide the D3D depth bias by that value. * There's no practical way to retrieve that value from a given GL * implementation, but the D3D application has essentially the same problem, - * which makes a guess of 1e-6f seem reasonable here. Note that - * SLOPESCALEDEPTHBIAS is a scaling factor for the depth slope, and doesn't - * need to be scaled. */ + * which makes a guess of the depth buffer format's highest possible value a + * reasonable guess. Note that SLOPESCALEDEPTHBIAS is a scaling factor for the + * depth slope, and doesn't need to be scaled. */ static void state_depthbias(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context) { if (stateblock->state.render_states[WINED3DRS_SLOPESCALEDEPTHBIAS] || stateblock->state.render_states[WINED3DRS_DEPTHBIAS]) { + IWineD3DSurfaceImpl *depth = stateblock->device->depth_stencil; + float scale; + union { DWORD d; @@ -1763,7 +1766,21 @@ static void state_depthbias(DWORD state, struct wined3d_stateblock *stateblock, glEnable(GL_POLYGON_OFFSET_FILL); checkGLcall("glEnable(GL_POLYGON_OFFSET_FILL)"); - glPolygonOffset(scale_bias.f, const_bias.f * 1e6f); + if (depth) + { + const struct wined3d_format *fmt = depth->resource.format; + scale = powf(2, fmt->depth_size) - 1; + TRACE("Depth format %s, using depthbias scale of %f\n", + debug_d3dformat(fmt->id), scale); + } + else + { + /* The context manager will reapply this state on a depth stencil change */ + TRACE("No depth stencil, using depthbias scale of 0.0\n"); + scale = 0; + } + + glPolygonOffset(scale_bias.f, const_bias.f * scale); checkGLcall("glPolygonOffset(...)"); } else { glDisable(GL_POLYGON_OFFSET_FILL);