[Mesa-dev] [PATCH 1/4] mesa: Rework depth range setting in preparation for NV_depth_buffer_float.
Ian Romanick
idr at freedesktop.org
Mon Sep 15 14:58:02 PDT 2014
This patch is
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
On 09/14/2014 10:07 AM, Mathias.Froehlich at gmx.net wrote:
> From: Mathias Froehlich <Mathias.Froehlich at web.de>
>
> Factor out some functions that will get additional callers
> with the implementation of NV_depth_buffer_float.
>
> Signed-off-by: Mathias Froehlich <Mathias.Froehlich at web.de>
> ---
> src/mesa/main/attrib.c | 2 +-
> src/mesa/main/depth.c | 66 ++++++++++++++++++++++++++++++------------------
> src/mesa/main/viewport.c | 64 +++++++++++++++++++++++++++-------------------
> src/mesa/main/viewport.h | 2 +-
> 4 files changed, 82 insertions(+), 52 deletions(-)
>
> diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
> index 2e289b6..97115a1 100644
> --- a/src/mesa/main/attrib.c
> +++ b/src/mesa/main/attrib.c
> @@ -1364,7 +1364,7 @@ _mesa_PopAttrib(void)
> for (i = 0; i < ctx->Const.MaxViewports; i++) {
> _mesa_set_viewport(ctx, i, vp[i].X, vp[i].Y, vp[i].Width,
> vp[i].Height);
> - _mesa_set_depth_range(ctx, i, vp[i].Near, vp[i].Far);
> + _mesa_set_depth_range(ctx, i, vp[i].Near, vp[i].Far, false);
> }
> }
> break;
> diff --git a/src/mesa/main/depth.c b/src/mesa/main/depth.c
> index 29851ec..8ae3cb6 100644
> --- a/src/mesa/main/depth.c
> +++ b/src/mesa/main/depth.c
> @@ -32,6 +32,44 @@
> #include "mtypes.h"
>
>
> +static void
> +set_clear_depth( struct gl_context *ctx, const char* fcn,
> + GLdouble depth, bool clamp )
> +{
> + if (MESA_VERBOSE & VERBOSE_API)
> + _mesa_debug(ctx, "%s(%f)\n", fcn, depth);
> +
> + if (clamp)
> + depth = CLAMP( depth, 0.0, 1.0 );
> +
> + ctx->Depth.Clear = depth;
> +}
> +
> +static void
> +set_depth_bounds( struct gl_context *ctx, const char* fcn,
> + GLdouble zmin, GLdouble zmax, bool clamp )
> +{
> + if (MESA_VERBOSE & VERBOSE_API)
> + _mesa_debug(ctx, "%s(%f, %f)\n", fcn, zmin, zmax);
> +
> + if (zmin > zmax) {
> + _mesa_error(ctx, GL_INVALID_VALUE, "%s(zmin > zmax)", fcn);
> + return;
> + }
> +
> + if (clamp) {
> + zmin = CLAMP(zmin, 0.0, 1.0);
> + zmax = CLAMP(zmax, 0.0, 1.0);
> + }
> +
> + if (ctx->Depth.BoundsMin == zmin && ctx->Depth.BoundsMax == zmax)
> + return;
> +
> + FLUSH_VERTICES(ctx, _NEW_DEPTH);
> + ctx->Depth.BoundsMin = (GLfloat) zmin;
> + ctx->Depth.BoundsMax = (GLfloat) zmax;
> +}
> +
> /**********************************************************************/
> /***** API Functions *****/
> /**********************************************************************/
> @@ -42,18 +80,15 @@ void GLAPIENTRY
> _mesa_ClearDepth( GLclampd depth )
> {
> GET_CURRENT_CONTEXT(ctx);
> -
> - if (MESA_VERBOSE & VERBOSE_API)
> - _mesa_debug(ctx, "glClearDepth(%f)\n", depth);
> -
> - ctx->Depth.Clear = CLAMP( depth, 0.0, 1.0 );
> + set_clear_depth(ctx, "glClearDepth", depth, true);
> }
>
>
> void GLAPIENTRY
> _mesa_ClearDepthf( GLclampf depth )
> {
> - _mesa_ClearDepth(depth);
> + GET_CURRENT_CONTEXT(ctx);
> + set_clear_depth(ctx, "glClearDepthf", depth, true);
> }
>
>
> @@ -123,24 +158,7 @@ void GLAPIENTRY
> _mesa_DepthBoundsEXT( GLclampd zmin, GLclampd zmax )
> {
> GET_CURRENT_CONTEXT(ctx);
> -
> - if (MESA_VERBOSE & VERBOSE_API)
> - _mesa_debug(ctx, "glDepthBounds(%f, %f)\n", zmin, zmax);
> -
> - if (zmin > zmax) {
> - _mesa_error(ctx, GL_INVALID_VALUE, "glDepthBoundsEXT(zmin > zmax)");
> - return;
> - }
> -
> - zmin = CLAMP(zmin, 0.0, 1.0);
> - zmax = CLAMP(zmax, 0.0, 1.0);
> -
> - if (ctx->Depth.BoundsMin == zmin && ctx->Depth.BoundsMax == zmax)
> - return;
> -
> - FLUSH_VERTICES(ctx, _NEW_DEPTH);
> - ctx->Depth.BoundsMin = (GLfloat) zmin;
> - ctx->Depth.BoundsMax = (GLfloat) zmax;
> + set_depth_bounds(ctx, "glDepthBoundsEXT", zmin, zmax, true);
> }
>
>
> diff --git a/src/mesa/main/viewport.c b/src/mesa/main/viewport.c
> index 6545bf6..e86a77c 100644
> --- a/src/mesa/main/viewport.c
> +++ b/src/mesa/main/viewport.c
> @@ -240,14 +240,19 @@ _mesa_ViewportIndexedfv(GLuint index, const GLfloat *v)
>
> static void
> set_depth_range_no_notify(struct gl_context *ctx, unsigned idx,
> - GLclampd nearval, GLclampd farval)
> + GLdouble nearval, GLdouble farval, bool clamp)
> {
> + if (clamp) {
> + nearval = CLAMP(nearval, 0.0, 1.0);
> + farval = CLAMP(farval, 0.0, 1.0);
> + }
> +
> if (ctx->ViewportArray[idx].Near == nearval &&
> ctx->ViewportArray[idx].Far == farval)
> return;
>
> - ctx->ViewportArray[idx].Near = CLAMP(nearval, 0.0, 1.0);
> - ctx->ViewportArray[idx].Far = CLAMP(farval, 0.0, 1.0);
> + ctx->ViewportArray[idx].Near = nearval;
> + ctx->ViewportArray[idx].Far = farval;
> ctx->NewState |= _NEW_VIEWPORT;
>
> #if 1
> @@ -268,32 +273,19 @@ set_depth_range_no_notify(struct gl_context *ctx, unsigned idx,
>
> void
> _mesa_set_depth_range(struct gl_context *ctx, unsigned idx,
> - GLclampd nearval, GLclampd farval)
> + GLdouble nearval, GLdouble farval, bool clamp)
> {
> - set_depth_range_no_notify(ctx, idx, nearval, farval);
> + set_depth_range_no_notify(ctx, idx, nearval, farval, clamp);
>
> if (ctx->Driver.DepthRange)
> ctx->Driver.DepthRange(ctx);
> }
>
> -/**
> - * Called by glDepthRange
> - *
> - * \param nearval specifies the Z buffer value which should correspond to
> - * the near clip plane
> - * \param farval specifies the Z buffer value which should correspond to
> - * the far clip plane
> - */
> -void GLAPIENTRY
> -_mesa_DepthRange(GLclampd nearval, GLclampd farval)
> +static void
> +set_all_depth_range(struct gl_context *ctx,
> + GLdouble nearval, GLdouble farval, bool clamp)
> {
> unsigned i;
> - GET_CURRENT_CONTEXT(ctx);
> -
> - FLUSH_VERTICES(ctx, 0);
> -
> - if (MESA_VERBOSE&VERBOSE_API)
> - _mesa_debug(ctx, "glDepthRange %f %f\n", nearval, farval);
>
> /* The GL_ARB_viewport_array spec says:
> *
> @@ -307,11 +299,31 @@ _mesa_DepthRange(GLclampd nearval, GLclampd farval)
> * implementation, but only signal the driver once at the end.
> */
> for (i = 0; i < ctx->Const.MaxViewports; i++)
> - set_depth_range_no_notify(ctx, i, nearval, farval);
> + set_depth_range_no_notify(ctx, i, nearval, farval, clamp);
>
> - if (ctx->Driver.DepthRange) {
> + if (ctx->Driver.DepthRange)
> ctx->Driver.DepthRange(ctx);
> - }
> +}
> +
> +/**
> + * Called by glDepthRange
> + *
> + * \param nearval specifies the Z buffer value which should correspond to
> + * the near clip plane
> + * \param farval specifies the Z buffer value which should correspond to
> + * the far clip plane
> + */
> +void
> +_mesa_DepthRange(GLclampd nearval, GLclampd farval)
> +{
> + GET_CURRENT_CONTEXT(ctx);
> +
> + FLUSH_VERTICES(ctx, 0);
> +
> + if (MESA_VERBOSE&VERBOSE_API)
> + _mesa_debug(ctx, "glDepthRange %f %f\n", nearval, farval);
> +
> + set_all_depth_range(ctx, nearval, farval, true);
> }
>
> void GLAPIENTRY
> @@ -347,7 +359,7 @@ _mesa_DepthRangeArrayv(GLuint first, GLsizei count, const GLclampd *v)
> }
>
> for (i = 0; i < count; i++)
> - set_depth_range_no_notify(ctx, i + first, p[i].Near, p[i].Far);
> + set_depth_range_no_notify(ctx, i + first, p[i].Near, p[i].Far, true);
>
> if (ctx->Driver.DepthRange)
> ctx->Driver.DepthRange(ctx);
> @@ -378,7 +390,7 @@ _mesa_DepthRangeIndexed(GLuint index, GLclampd nearval, GLclampd farval)
> return;
> }
>
> - _mesa_set_depth_range(ctx, index, nearval, farval);
> + _mesa_set_depth_range(ctx, index, nearval, farval, true);
> }
>
> /**
> diff --git a/src/mesa/main/viewport.h b/src/mesa/main/viewport.h
> index f2311c0..6324cab 100644
> --- a/src/mesa/main/viewport.h
> +++ b/src/mesa/main/viewport.h
> @@ -62,7 +62,7 @@ _mesa_DepthRangeIndexed(GLuint index, GLclampd n, GLclampd f);
>
> extern void
> _mesa_set_depth_range(struct gl_context *ctx, unsigned idx,
> - GLclampd nearval, GLclampd farval);
> + GLdouble nearval, GLdouble farval, bool clamp);
>
> extern void
> _mesa_init_viewport(struct gl_context *ctx);
>
More information about the mesa-dev
mailing list