[Mesa-dev] [PATCH] mesa: fix BlitFramebuffer between linear and sRGB formats

Brian Paul brian.e.paul at gmail.com
Sun Nov 25 09:20:00 PST 2012


On Thu, Nov 22, 2012 at 7:03 PM, Marek Olšák <maraeo at gmail.com> wrote:
> ---
>  src/mesa/main/fbobject.c |   42 +++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 39 insertions(+), 3 deletions(-)
>
> diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
> index 223aef1..891ec5d 100644
> --- a/src/mesa/main/fbobject.c
> +++ b/src/mesa/main/fbobject.c
> @@ -2799,11 +2799,41 @@ get_nongeneric_internalformat(GLenum format)
>  }
>
>
> +static GLenum
> +get_linear_internalformat(GLenum format)
> +{
> +   switch (format) {
> +   case GL_SRGB:
> +      return GL_RGB;
> +
> +   case GL_SRGB_ALPHA:
> +      return GL_RGBA;
> +
> +   case GL_SRGB8:
> +      return GL_RGB8;
> +
> +   case GL_SRGB8_ALPHA8:
> +      return GL_RGBA8;
> +
> +   case GL_SLUMINANCE:
> +      return GL_LUMINANCE8;
> +
> +   case GL_SLUMINANCE_ALPHA:
> +      return GL_LUMINANCE8_ALPHA8;
> +
> +   default:
> +      return format;
> +   }
> +}

I'd put this helper function in the glformats.c file in case it's
needed elsewhere someday.


> +
> +
>  static GLboolean
>  compatible_resolve_formats(const struct gl_renderbuffer *colorReadRb,
>                             const struct gl_renderbuffer *colorDrawRb)
>  {
> -   /* The simple case where we know the backing formats are the same.
> +   GLenum readFormat, drawFormat;
> +
> +   /* The simple case where we know the backing Mesa formats are the same.
>      */
>     if (_mesa_get_srgb_format_linear(colorReadRb->Format) ==
>         _mesa_get_srgb_format_linear(colorDrawRb->Format)) {
> @@ -2817,9 +2847,15 @@ compatible_resolve_formats(const struct gl_renderbuffer *colorReadRb,
>      * textures and get two entirely different Mesa formats like RGBA8888 and
>      * ARGB8888. Drivers behaving like that should be able to cope with
>      * non-matching formats by themselves, because it's not the user's fault.
> +    *
> +    * Blits between linear and sRGB formats are also allowed.
>      */
> -   if (get_nongeneric_internalformat(colorReadRb->InternalFormat) ==
> -       get_nongeneric_internalformat(colorDrawRb->InternalFormat)) {
> +   readFormat = get_nongeneric_internalformat(colorReadRb->InternalFormat);
> +   drawFormat = get_nongeneric_internalformat(colorDrawRb->InternalFormat);
> +   readFormat = get_linear_internalformat(readFormat);
> +   drawFormat = get_linear_internalformat(drawFormat);
> +
> +   if (readFormat == drawFormat) {
>        return GL_TRUE;
>     }
>

Looks OK otherwise.

Reviewed-by: Brian Paul <brianp at vmware.com>


More information about the mesa-dev mailing list