[Mesa-dev] [PATCH 1/3] mesa: Introduce a _mesa_format_has_color_component() helper.

Eric Anholt eric at anholt.net
Mon Mar 24 13:49:20 PDT 2014


Kenneth Graunke <kenneth at whitecape.org> writes:

> When considering color write masks, we often want to know whether an
> RGBA component actually contains any meaningful data.  This function
> provides an easy way to answer that question, and handles luminance,
> intensity, and alpha formats correctly.
>
> Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
> ---
>  src/mesa/main/formats.c | 29 +++++++++++++++++++++++++++++
>  src/mesa/main/formats.h |  4 ++++
>  2 files changed, 33 insertions(+)
>
> diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
> index c3e8049..4fb1f11 100644
> --- a/src/mesa/main/formats.c
> +++ b/src/mesa/main/formats.c
> @@ -2207,6 +2207,35 @@ _mesa_format_num_components(mesa_format format)
>  
>  
>  /**
> + * Returns true if a color format has data stored in the R/G/B/A channels,
> + * given an index from 0 to 3.
> + */
> +bool
> +_mesa_format_has_color_component(mesa_format format, int component)
> +{
> +   const struct gl_format_info *info = _mesa_get_format_info(format);
> +
> +   assert(info->BaseFormat != GL_DEPTH_COMPONENT &&
> +          info->BaseFormat != GL_DEPTH_STENCIL &&
> +          info->BaseFormat != GL_STENCIL_INDEX);
> +
> +   switch (component) {
> +   case 0:
> +      return (info->RedBits + info->IntensityBits + info->LuminanceBits) > 0;
> +   case 1:
> +      return (info->GreenBits + info->IntensityBits + info->LuminanceBits) > 0;
> +   case 2:
> +      return (info->BlueBits + info->IntensityBits + info->LuminanceBits) > 0;
> +   case 3:
> +      return (info->AlphaBits + info->IntensityBits) > 0;
> +   default:
> +      assert(!"Invalid color component: must be 0..3");
> +      return false;
> +   }
> +}

It would be possible to catch more cases by having the BaseFormat passed
in from the outseide, so we'd answer false when asked about the A
channel of an RGB texture that got stored in an ARGB mesa_format.

However, this all appears correct now, and it's a big win, so the series
is:

Reviewed-by: Eric Anholt <eric at anholt.net>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20140324/33404612/attachment-0001.sig>


More information about the mesa-dev mailing list