[Mesa-dev] [PATCH 19/38] main: Refactor _mesa_[update|get]_clamp_fragment_color.

Fredrik Höglund fredrik at kde.org
Sun Apr 12 08:58:17 PDT 2015


Reviewed-by: Fredrik Höglund <fredrik at kde.org>

On Wednesday 04 March 2015, Laura Ekstrand wrote:
> ---
>  src/mesa/main/blend.c             | 19 ++++++++++---------
>  src/mesa/main/blend.h             |  6 ++++--
>  src/mesa/main/framebuffer.c       |  2 +-
>  src/mesa/main/get.c               |  8 ++++----
>  src/mesa/main/texenv.c            |  2 +-
>  src/mesa/main/texparam.c          |  2 +-
>  src/mesa/program/prog_statevars.c |  4 ++--
>  7 files changed, 23 insertions(+), 20 deletions(-)
> 
> diff --git a/src/mesa/main/blend.c b/src/mesa/main/blend.c
> index ee76b47..2342555 100644
> --- a/src/mesa/main/blend.c
> +++ b/src/mesa/main/blend.c
> @@ -778,7 +778,7 @@ _mesa_ClampColor(GLenum target, GLenum clamp)
>        }
>        FLUSH_VERTICES(ctx, _NEW_FRAG_CLAMP);
>        ctx->Color.ClampFragmentColor = clamp;
> -      _mesa_update_clamp_fragment_color(ctx);
> +      _mesa_update_clamp_fragment_color(ctx, ctx->DrawBuffer);
>        break;
>     case GL_CLAMP_READ_COLOR_ARB:
>        ctx->Color.ClampReadColor = clamp;
> @@ -807,10 +807,10 @@ get_clamp_color(const struct gl_framebuffer *fb, GLenum clamp)
>  }
>  
>  GLboolean
> -_mesa_get_clamp_fragment_color(const struct gl_context *ctx)
> +_mesa_get_clamp_fragment_color(const struct gl_context *ctx,
> +                               const struct gl_framebuffer *drawFb)
>  {
> -   return get_clamp_color(ctx->DrawBuffer,
> -                                ctx->Color.ClampFragmentColor);
> +   return get_clamp_color(drawFb, ctx->Color.ClampFragmentColor);
>  }
>  
>  GLboolean
> @@ -830,19 +830,20 @@ _mesa_get_clamp_read_color(const struct gl_context *ctx)
>   * Update the ctx->Color._ClampFragmentColor field
>   */
>  void
> -_mesa_update_clamp_fragment_color(struct gl_context *ctx)
> +_mesa_update_clamp_fragment_color(struct gl_context *ctx,
> +                                  const struct gl_framebuffer *drawFb)
>  {
> -   struct gl_framebuffer *fb = ctx->DrawBuffer;
> -
>     /* Don't clamp if:
>      * - there is no colorbuffer
>      * - all colorbuffers are unsigned normalized, so clamping has no effect
>      * - there is an integer colorbuffer
>      */
> -   if (!fb || !fb->_HasSNormOrFloatColorBuffer || fb->_IntegerColor)
> +   if (!drawFb || !drawFb->_HasSNormOrFloatColorBuffer ||
> +       drawFb->_IntegerColor)
>        ctx->Color._ClampFragmentColor = GL_FALSE;
>     else
> -      ctx->Color._ClampFragmentColor = _mesa_get_clamp_fragment_color(ctx);
> +      ctx->Color._ClampFragmentColor =
> +         _mesa_get_clamp_fragment_color(ctx, drawFb);
>  }
>  
>  /**
> diff --git a/src/mesa/main/blend.h b/src/mesa/main/blend.h
> index 9c1ef7e..58e6673 100644
> --- a/src/mesa/main/blend.h
> +++ b/src/mesa/main/blend.h
> @@ -102,7 +102,8 @@ extern void GLAPIENTRY
>  _mesa_ClampColor(GLenum target, GLenum clamp);
>  
>  extern GLboolean
> -_mesa_get_clamp_fragment_color(const struct gl_context *ctx);
> +_mesa_get_clamp_fragment_color(const struct gl_context *ctx,
> +                               const struct gl_framebuffer *drawFb);
>  
>  extern GLboolean
>  _mesa_get_clamp_vertex_color(const struct gl_context *ctx,
> @@ -112,7 +113,8 @@ extern GLboolean
>  _mesa_get_clamp_read_color(const struct gl_context *ctx);
>  
>  extern void
> -_mesa_update_clamp_fragment_color(struct gl_context *ctx);
> +_mesa_update_clamp_fragment_color(struct gl_context *ctx,
> +                                  const struct gl_framebuffer *drawFb);
>  
>  extern void
>  _mesa_update_clamp_vertex_color(struct gl_context *ctx,
> diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c
> index 22db72a..eee457d 100644
> --- a/src/mesa/main/framebuffer.c
> +++ b/src/mesa/main/framebuffer.c
> @@ -692,7 +692,7 @@ _mesa_update_framebuffer(struct gl_context *ctx,
>        update_framebuffer(ctx, readFb);
>  
>     _mesa_update_clamp_vertex_color(ctx, drawFb);
> -   _mesa_update_clamp_fragment_color(ctx);
> +   _mesa_update_clamp_fragment_color(ctx, drawFb);
>  }
>  
>  
> diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
> index a881bc5..c37d9db 100644
> --- a/src/mesa/main/get.c
> +++ b/src/mesa/main/get.c
> @@ -909,13 +909,13 @@ find_custom_value(struct gl_context *ctx, const struct value_desc *d, union valu
>        break;
>  
>     case GL_FOG_COLOR:
> -      if (_mesa_get_clamp_fragment_color(ctx))
> +      if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
>           COPY_4FV(v->value_float_4, ctx->Fog.Color);
>        else
>           COPY_4FV(v->value_float_4, ctx->Fog.ColorUnclamped);
>        break;
>     case GL_COLOR_CLEAR_VALUE:
> -      if (_mesa_get_clamp_fragment_color(ctx)) {
> +      if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer)) {
>           v->value_float_4[0] = CLAMP(ctx->Color.ClearColor.f[0], 0.0F, 1.0F);
>           v->value_float_4[1] = CLAMP(ctx->Color.ClearColor.f[1], 0.0F, 1.0F);
>           v->value_float_4[2] = CLAMP(ctx->Color.ClearColor.f[2], 0.0F, 1.0F);
> @@ -924,13 +924,13 @@ find_custom_value(struct gl_context *ctx, const struct value_desc *d, union valu
>           COPY_4FV(v->value_float_4, ctx->Color.ClearColor.f);
>        break;
>     case GL_BLEND_COLOR_EXT:
> -      if (_mesa_get_clamp_fragment_color(ctx))
> +      if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
>           COPY_4FV(v->value_float_4, ctx->Color.BlendColor);
>        else
>           COPY_4FV(v->value_float_4, ctx->Color.BlendColorUnclamped);
>        break;
>     case GL_ALPHA_TEST_REF:
> -      if (_mesa_get_clamp_fragment_color(ctx))
> +      if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
>           v->value_float = ctx->Color.AlphaRef;
>        else
>           v->value_float = ctx->Color.AlphaRefUnclamped;
> diff --git a/src/mesa/main/texenv.c b/src/mesa/main/texenv.c
> index ec521e6..3edafc0 100644
> --- a/src/mesa/main/texenv.c
> +++ b/src/mesa/main/texenv.c
> @@ -646,7 +646,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
>        if (pname == GL_TEXTURE_ENV_COLOR) {
>           if(ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
>              _mesa_update_state(ctx);
> -         if (_mesa_get_clamp_fragment_color(ctx))
> +         if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
>              COPY_4FV( params, texUnit->EnvColor );
>           else
>              COPY_4FV( params, texUnit->EnvColorUnclamped );
> diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c
> index 1ef7286..dfc8a0a 100644
> --- a/src/mesa/main/texparam.c
> +++ b/src/mesa/main/texparam.c
> @@ -1710,7 +1710,7 @@ get_tex_parameterfv(struct gl_context *ctx,
>  
>           if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
>              _mesa_update_state_locked(ctx);
> -         if (_mesa_get_clamp_fragment_color(ctx)) {
> +         if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer)) {
>              params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
>              params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
>              params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
> diff --git a/src/mesa/program/prog_statevars.c b/src/mesa/program/prog_statevars.c
> index 4cde744..19a55c3 100644
> --- a/src/mesa/program/prog_statevars.c
> +++ b/src/mesa/program/prog_statevars.c
> @@ -243,14 +243,14 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
>        {
>           /* state[1] is the texture unit */
>           const GLuint unit = (GLuint) state[1];
> -         if (_mesa_get_clamp_fragment_color(ctx))
> +         if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
>              COPY_4V(value, ctx->Texture.Unit[unit].EnvColor);
>           else
>              COPY_4V(value, ctx->Texture.Unit[unit].EnvColorUnclamped);
>        }
>        return;
>     case STATE_FOG_COLOR:
> -      if (_mesa_get_clamp_fragment_color(ctx))
> +      if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
>           COPY_4V(value, ctx->Fog.Color);
>        else
>           COPY_4V(value, ctx->Fog.ColorUnclamped);
> 



More information about the mesa-dev mailing list