From 42b5d88f2e081d90195bd3cd1931929f84b26f45 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Mon, 8 Oct 2018 21:55:39 +0330 Subject: [PATCH] wined3d: Implement depth bias clamp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based on a patch by Michael Müller. Signed-off-by: Zebediah Figura Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/d3d11/state.c | 1 + dlls/wined3d/adapter_gl.c | 8 +++++++- dlls/wined3d/state.c | 18 ++++++++++++++++-- dlls/wined3d/wined3d_gl.h | 1 + include/wine/wined3d.h | 1 + 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/dlls/d3d11/state.c b/dlls/d3d11/state.c index c36b87fbbd3..6de35029556 100644 --- a/dlls/d3d11/state.c +++ b/dlls/d3d11/state.c @@ -1081,6 +1081,7 @@ static HRESULT d3d_rasterizer_state_init(struct d3d_rasterizer_state *state, str wined3d_desc.front_ccw = desc->FrontCounterClockwise; wined3d_desc.depth_clip = desc->DepthClipEnable; + wined3d_desc.depth_bias_clamp = desc->DepthBiasClamp; /* We cannot fail after creating a wined3d_rasterizer_state object. It * would lead to double free. */ diff --git a/dlls/wined3d/adapter_gl.c b/dlls/wined3d/adapter_gl.c index b62c86a8d0c..16a26b88ba6 100644 --- a/dlls/wined3d/adapter_gl.c +++ b/dlls/wined3d/adapter_gl.c @@ -103,6 +103,7 @@ static const struct wined3d_extension_map gl_extension_map[] = {"GL_ARB_pixel_buffer_object", ARB_PIXEL_BUFFER_OBJECT }, {"GL_ARB_point_parameters", ARB_POINT_PARAMETERS }, {"GL_ARB_point_sprite", ARB_POINT_SPRITE }, + {"GL_ARB_polygon_offset_clamp", ARB_POLYGON_OFFSET_CLAMP }, {"GL_ARB_provoking_vertex", ARB_PROVOKING_VERTEX }, {"GL_ARB_query_buffer_object", ARB_QUERY_BUFFER_OBJECT }, {"GL_ARB_sample_shading", ARB_SAMPLE_SHADING }, @@ -1254,7 +1255,9 @@ static enum wined3d_feature_level feature_level_from_caps(const struct wined3d_g shader_model = min(shader_model, max(shader_caps->hs_version, 4)); shader_model = min(shader_model, max(shader_caps->ds_version, 4)); - if (gl_info->supported[WINED3D_GL_VERSION_3_2] && gl_info->supported[ARB_SAMPLER_OBJECTS]) + if (gl_info->supported[WINED3D_GL_VERSION_3_2] + && gl_info->supported[ARB_POLYGON_OFFSET_CLAMP] + && gl_info->supported[ARB_SAMPLER_OBJECTS]) { if (shader_model >= 5 && gl_info->supported[ARB_DRAW_INDIRECT] @@ -2172,6 +2175,8 @@ static void load_gl_funcs(struct wined3d_gl_info *gl_info) /* GL_ARB_point_parameters */ USE_GL_FUNC(glPointParameterfARB) USE_GL_FUNC(glPointParameterfvARB) + /* GL_ARB_polgyon_offset_clamp */ + USE_GL_FUNC(glPolygonOffsetClamp) /* GL_ARB_provoking_vertex */ USE_GL_FUNC(glProvokingVertex) /* GL_ARB_sample_shading */ @@ -3316,6 +3321,7 @@ static BOOL wined3d_adapter_init_gl_caps(struct wined3d_adapter *adapter, {ARB_SHADER_TEXTURE_IMAGE_SAMPLES, MAKEDWORD_VERSION(4, 5)}, {ARB_PIPELINE_STATISTICS_QUERY, MAKEDWORD_VERSION(4, 6)}, + {ARB_POLYGON_OFFSET_CLAMP, MAKEDWORD_VERSION(4, 6)}, {ARB_TEXTURE_FILTER_ANISOTROPIC, MAKEDWORD_VERSION(4, 6)}, }; struct wined3d_driver_info *driver_info = &adapter->driver_info; diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index 3b2f84538db..375bc6562ab 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -1775,7 +1775,7 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3 || state->render_states[WINED3D_RS_DEPTHBIAS]) { const struct wined3d_rendertarget_view *depth = state->fb->depth_stencil; - float factor, units, scale; + float factor, units, scale, clamp; union { @@ -1783,6 +1783,7 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3 float f; } scale_bias, const_bias; + clamp = state->rasterizer_state ? state->rasterizer_state->desc.depth_bias_clamp : 0.0f; scale_bias.d = state->render_states[WINED3D_RS_SLOPESCALEDEPTHBIAS]; const_bias.d = state->render_states[WINED3D_RS_DEPTHBIAS]; @@ -1811,7 +1812,16 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3 } gl_info->gl_ops.gl.p_glEnable(GL_POLYGON_OFFSET_FILL); - gl_info->gl_ops.gl.p_glPolygonOffset(factor, units); + if (gl_info->supported[ARB_POLYGON_OFFSET_CLAMP]) + { + gl_info->gl_ops.ext.p_glPolygonOffsetClamp(factor, units, clamp); + } + else + { + if (clamp != 0.0f) + WARN("Ignoring depth bias clamp %.8e.\n", clamp); + gl_info->gl_ops.gl.p_glPolygonOffset(factor, units); + } } else { @@ -4345,6 +4355,8 @@ static void rasterizer(struct wined3d_context *context, const struct wined3d_sta gl_info->gl_ops.gl.p_glFrontFace(mode); checkGLcall("glFrontFace"); + if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_DEPTHBIAS))) + state_depthbias(context, state, STATE_RENDER(WINED3D_RS_DEPTHBIAS)); depth_clip(state->rasterizer_state, gl_info); } @@ -4357,6 +4369,8 @@ static void rasterizer_cc(struct wined3d_context *context, const struct wined3d_ gl_info->gl_ops.gl.p_glFrontFace(mode); checkGLcall("glFrontFace"); + if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_DEPTHBIAS))) + state_depthbias(context, state, STATE_RENDER(WINED3D_RS_DEPTHBIAS)); depth_clip(state->rasterizer_state, gl_info); } diff --git a/dlls/wined3d/wined3d_gl.h b/dlls/wined3d/wined3d_gl.h index 2a985da9faf..a02073c28af 100644 --- a/dlls/wined3d/wined3d_gl.h +++ b/dlls/wined3d/wined3d_gl.h @@ -89,6 +89,7 @@ enum wined3d_gl_extension ARB_PIXEL_BUFFER_OBJECT, ARB_POINT_PARAMETERS, ARB_POINT_SPRITE, + ARB_POLYGON_OFFSET_CLAMP, ARB_PROVOKING_VERTEX, ARB_QUERY_BUFFER_OBJECT, ARB_SAMPLE_SHADING, diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index 8197a8682ae..c62d3640e58 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -2012,6 +2012,7 @@ struct wined3d_blend_state_desc struct wined3d_rasterizer_state_desc { BOOL front_ccw; + float depth_bias_clamp; BOOL depth_clip; };