summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGert Wollny <[email protected]>2019-07-25 10:38:24 +0200
committerGert Wollny <[email protected]>2019-08-01 05:58:53 +0000
commitd004fcc04a52dd53c4e7008f55c5a9a2d8101ad5 (patch)
tree598b4cd6ca363c7fe8e1f27b511dbc6921243000 /src
parent57361d89fa1085b953ef7618817f752c3cc824ef (diff)
mesa/st: Add depth clamping to rasterizer code
implemented by Erik Faye-Lund <[email protected]> v2: Use current depth range values for clamping (Erik) v3: fix scons-win64 build Signed-off-by: Gert Wollny <[email protected]> Reviewed-by: Reviewed-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/mesa/state_tracker/st_atom_rasterizer.c6
-rw-r--r--src/mesa/state_tracker/st_cb_drawpixels.c39
2 files changed, 39 insertions, 6 deletions
diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c b/src/mesa/state_tracker/st_atom_rasterizer.c
index 0d7d4c16fa6..b1ac4b3f133 100644
--- a/src/mesa/state_tracker/st_atom_rasterizer.c
+++ b/src/mesa/state_tracker/st_atom_rasterizer.c
@@ -295,8 +295,10 @@ st_update_rasterizer(struct st_context *st)
}
/* _NEW_TRANSFORM */
- raster->depth_clip_near = !ctx->Transform.DepthClampNear;
- raster->depth_clip_far = !ctx->Transform.DepthClampFar;
+ raster->depth_clip_near = st->clamp_frag_depth_in_shader ||
+ !ctx->Transform.DepthClampNear;
+ raster->depth_clip_far = st->clamp_frag_depth_in_shader ||
+ !ctx->Transform.DepthClampFar;
raster->clip_plane_enable = ctx->Transform.ClipPlanesEnabled;
raster->clip_halfz = (ctx->Transform.ClipDepthMode == GL_ZERO_TO_ONE);
diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
index ffbeae9fd7a..6c650fd1962 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -787,8 +787,10 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
ctx->Color._ClampFragmentColor;
rasterizer.half_pixel_center = 1;
rasterizer.bottom_edge_rule = 1;
- rasterizer.depth_clip_near = !ctx->Transform.DepthClampNear;
- rasterizer.depth_clip_far = !ctx->Transform.DepthClampFar;
+ rasterizer.depth_clip_near = st->clamp_frag_depth_in_shader ||
+ !ctx->Transform.DepthClampNear;
+ rasterizer.depth_clip_far = st->clamp_frag_depth_in_shader ||
+ !ctx->Transform.DepthClampFar;
rasterizer.scissor = ctx->Scissor.EnableFlags;
cso_set_rasterizer(cso, &rasterizer);
}
@@ -1261,6 +1263,34 @@ setup_sampler_swizzle(struct pipe_sampler_view *sv, GLenum format, GLenum type)
/**
+ * Compute the effective raster z position. This performs depth-clamping
+ * if needed.
+ */
+static float
+get_effective_raster_z(struct gl_context *ctx)
+{
+ float z = ctx->Current.RasterPos[2];
+ if (st_context(ctx)->clamp_frag_depth_in_shader) {
+ GLfloat depth_near;
+ GLfloat depth_far;
+ if (ctx->ViewportArray[0].Near < ctx->ViewportArray[0].Far) {
+ depth_near = ctx->ViewportArray[0].Near;
+ depth_far = ctx->ViewportArray[0].Far;
+ } else {
+ depth_near = ctx->ViewportArray[0].Far;
+ depth_far = ctx->ViewportArray[0].Near;
+ }
+
+ if (ctx->Transform.DepthClampNear)
+ z = MAX2(z, depth_near);
+ if (ctx->Transform.DepthClampFar)
+ z = MIN2(z, depth_far);
+ }
+ return z;
+}
+
+
+/**
* Called via ctx->Driver.DrawPixels()
*/
static void
@@ -1376,7 +1406,7 @@ st_DrawPixels(struct gl_context *ctx, GLint x, GLint y,
num_sampler_view++;
}
- draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2],
+ draw_textured_quad(ctx, x, y, get_effective_raster_z(ctx),
width, height,
ctx->Pixel.ZoomX, ctx->Pixel.ZoomY,
sv,
@@ -1851,7 +1881,8 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
/* OK, the texture 'pt' contains the src image/pixels. Now draw a
* textured quad with that texture.
*/
- draw_textured_quad(ctx, dstx, dsty, ctx->Current.RasterPos[2],
+
+ draw_textured_quad(ctx, dstx, dsty, get_effective_raster_z(ctx),
width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY,
sv,
num_sampler_view,