Stefan Dösinger : wined3d: Scale the depthbias factor by the depth buffer's depth.

Alexandre Julliard julliard at winehq.org
Fri Apr 22 12:27:44 CDT 2011


Module: wine
Branch: master
Commit: dbc8702e44a987b77cdf9af31b964bb27e86fa92
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=dbc8702e44a987b77cdf9af31b964bb27e86fa92

Author: Stefan Dösinger <stefan at codeweavers.com>
Date:   Wed Apr 20 16:28:05 2011 +0200

wined3d: Scale the depthbias factor by the depth buffer's depth.

---

 dlls/wined3d/device.c |    5 +++++
 dlls/wined3d/state.c  |   25 +++++++++++++++++++++----
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 8c443fe..827365a 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 88ccd1b..801563e 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);




More information about the wine-cvs mailing list