[Mesa-dev] [PATCH 07/27] mesa: Add a new texture format GL_COMPRESSED_SRGB8_ETC2

Ian Romanick idr at freedesktop.org
Tue Nov 6 15:21:09 PST 2012


On 10/19/2012 04:28 PM, Anuj Phogat wrote:
> Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
> ---
>   src/mesa/main/format_unpack.c |    6 ++++++
>   src/mesa/main/formats.c       |   13 +++++++++++++
>   src/mesa/main/formats.h       |    1 +
>   src/mesa/main/glformats.c     |    2 ++
>   src/mesa/main/texcompress.c   |    9 +++++++++
>   src/mesa/main/texformat.c     |    3 +++
>   src/mesa/main/teximage.c      |    1 +
>   src/mesa/main/texstore.c      |    1 +
>   8 files changed, 36 insertions(+), 0 deletions(-)
>
> diff --git a/src/mesa/main/format_unpack.c b/src/mesa/main/format_unpack.c
> index d0029ab..fc339a9 100644
> --- a/src/mesa/main/format_unpack.c
> +++ b/src/mesa/main/format_unpack.c
> @@ -1343,6 +1343,11 @@ unpack_ETC2_RGB8(const void *src, GLfloat dst[][4], GLuint n)
>   }
>
>   static void
> +unpack_ETC2_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
> +{
> +   /* XXX to do */
> +}
> +static void

There should be a blank line between functions.

>   unpack_SIGNED_A8(const void *src, GLfloat dst[][4], GLuint n)
>   {
>      const GLbyte *s = ((const GLbyte *) src);
> @@ -1592,6 +1597,7 @@ get_unpack_rgba_function(gl_format format)
>
>         table[MESA_FORMAT_ETC1_RGB8] = unpack_ETC1_RGB8;
>         table[MESA_FORMAT_ETC2_RGB8] = unpack_ETC2_RGB8;
> +      table[MESA_FORMAT_ETC2_SRGB8] = unpack_ETC2_SRGB8;
>
>         table[MESA_FORMAT_SIGNED_A8] = unpack_SIGNED_A8;
>         table[MESA_FORMAT_SIGNED_L8] = unpack_SIGNED_L8;
> diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
> index f9c9fd8..d4b1d09 100644
> --- a/src/mesa/main/formats.c
> +++ b/src/mesa/main/formats.c
> @@ -1408,6 +1408,16 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
>         4, 4, 8                     /* 8 bytes per 4x4 block */
>      },
>
> +   {
> +      MESA_FORMAT_ETC2_SRGB8,
> +      "MESA_FORMAT_ETC2_SRGB8",
> +      GL_RGB,
> +      GL_UNSIGNED_NORMALIZED,
> +      8, 8, 8, 0,
> +      0, 0, 0, 0, 0,
> +      4, 4, 8                     /* 8 bytes per 4x4 block */
> +   },
> +
>      /* Signed formats from EXT_texture_snorm that are not in GL3.1 */
>      {
>         MESA_FORMAT_SIGNED_A8,
> @@ -1851,6 +1861,7 @@ _mesa_get_uncompressed_format(gl_format format)
>         return MESA_FORMAT_SIGNED_AL88;
>      case MESA_FORMAT_ETC1_RGB8:
>      case MESA_FORMAT_ETC2_RGB8:
> +   case MESA_FORMAT_ETC2_SRGB8:
>         return MESA_FORMAT_RGB888;

I don't think this is correct.  This drops the sRGB-ness of the format. 
  I'm pretty sure this should be MESA_FORMAT_SRGB8.  At least some of 
the other places that treat GL_COMPRESSED_SRGB8_ETC2 as GL_RGB have the 
same problem.

>      default:
>   #ifdef DEBUG
> @@ -2302,6 +2313,7 @@ _mesa_format_to_type_and_comps(gl_format format,
>      case MESA_FORMAT_SIGNED_LA_LATC2:
>      case MESA_FORMAT_ETC1_RGB8:
>      case MESA_FORMAT_ETC2_RGB8:
> +   case MESA_FORMAT_ETC2_SRGB8:
>         /* XXX generate error instead? */
>         *datatype = GL_UNSIGNED_BYTE;
>         *comps = 0;
> @@ -2933,6 +2945,7 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
>
>      case MESA_FORMAT_ETC1_RGB8:
>      case MESA_FORMAT_ETC2_RGB8:
> +   case MESA_FORMAT_ETC2_SRGB8:
>         return GL_FALSE;
>
>      case MESA_FORMAT_SIGNED_A8:
> diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h
> index 1d3cc35..eb82c1b 100644
> --- a/src/mesa/main/formats.h
> +++ b/src/mesa/main/formats.h
> @@ -260,6 +260,7 @@ typedef enum
>
>      MESA_FORMAT_ETC1_RGB8,
>      MESA_FORMAT_ETC2_RGB8,
> +   MESA_FORMAT_ETC2_SRGB8,
>
>      MESA_FORMAT_SIGNED_A8,         /*                               AAAA AAAA */
>      MESA_FORMAT_SIGNED_L8,         /*                               LLLL LLLL */
> diff --git a/src/mesa/main/glformats.c b/src/mesa/main/glformats.c
> index 522d2ac..a9cb0a7 100644
> --- a/src/mesa/main/glformats.c
> +++ b/src/mesa/main/glformats.c
> @@ -573,6 +573,7 @@ _mesa_is_color_format(GLenum format)
>         case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
>         case GL_ETC1_RGB8_OES:
>         case GL_COMPRESSED_RGB8_ETC2:
> +      case GL_COMPRESSED_SRGB8_ETC2:
>         /* generic integer formats */
>         case GL_RED_INTEGER_EXT:
>         case GL_GREEN_INTEGER_EXT:
> @@ -831,6 +832,7 @@ _mesa_is_compressed_format(struct gl_context *ctx, GLenum format)
>         return _mesa_is_gles(ctx)
>            && ctx->Extensions.OES_compressed_ETC1_RGB8_texture;
>      case GL_COMPRESSED_RGB8_ETC2:
> +   case GL_COMPRESSED_SRGB8_ETC2:
>         return _mesa_is_gles3(ctx);
>   #if FEATURE_ES
>      case GL_PALETTE4_RGB8_OES:
> diff --git a/src/mesa/main/texcompress.c b/src/mesa/main/texcompress.c
> index 1d38066..9c9d50c 100644
> --- a/src/mesa/main/texcompress.c
> +++ b/src/mesa/main/texcompress.c
> @@ -94,6 +94,7 @@ _mesa_gl_compressed_format_base_format(GLenum format)
>      case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
>      case GL_ETC1_RGB8_OES:
>      case GL_COMPRESSED_RGB8_ETC2:
> +   case GL_COMPRESSED_SRGB8_ETC2:
>         return GL_RGB;
>
>      case GL_COMPRESSED_RGBA:
> @@ -280,6 +281,7 @@ _mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats)
>      if (_mesa_is_gles3(ctx)) {
>         if (formats) {
>            formats[n++] = GL_COMPRESSED_RGB8_ETC2;
> +         formats[n++] = GL_COMPRESSED_SRGB8_ETC2;
>         }
>         else {
>            n += 1;
> @@ -367,6 +369,8 @@ _mesa_glenum_to_compressed_format(GLenum format)
>         return MESA_FORMAT_ETC1_RGB8;
>      case GL_COMPRESSED_RGB8_ETC2:
>         return MESA_FORMAT_ETC2_RGB8;
> +   case GL_COMPRESSED_SRGB8_ETC2:
> +      return MESA_FORMAT_ETC2_SRGB8;
>
>      default:
>         return MESA_FORMAT_NONE;
> @@ -437,6 +441,8 @@ _mesa_compressed_format_to_glenum(struct gl_context *ctx, gl_format mesaFormat)
>         return GL_ETC1_RGB8_OES;
>      case MESA_FORMAT_ETC2_RGB8:
>         return GL_COMPRESSED_RGB8_ETC2;
> +   case MESA_FORMAT_ETC2_SRGB8:
> +      return GL_COMPRESSED_SRGB8_ETC2;
>
>      default:
>         _mesa_problem(ctx, "Unexpected mesa texture format in"
> @@ -566,6 +572,9 @@ _mesa_decompress_image(gl_format format, GLuint width, GLuint height,
>      case MESA_FORMAT_ETC2_RGB8:
>         fetch = _mesa_fetch_texel_2d_f_etc2_rgb8;
>         break;
> +   case MESA_FORMAT_ETC2_SRGB8:
> +      fetch = _mesa_fetch_texel_2d_f_etc2_srgb8;
> +      break;
>
>      default:
>         _mesa_problem(NULL, "Unexpected format in _mesa_decompress_image()");
> diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c
> index 162f027..384d6a5 100644
> --- a/src/mesa/main/texformat.c
> +++ b/src/mesa/main/texformat.c
> @@ -983,6 +983,9 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
>            case GL_COMPRESSED_RGB8_ETC2:
>               RETURN_IF_SUPPORTED(MESA_FORMAT_ETC2_RGB8);
>               break;
> +         case GL_COMPRESSED_SRGB8_ETC2:
> +            RETURN_IF_SUPPORTED(MESA_FORMAT_ETC2_SRGB8);
> +            break;
>            default:
>               ; /* fallthrough */
>         }
> diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
> index 1f6fa89..6f76261 100644
> --- a/src/mesa/main/teximage.c
> +++ b/src/mesa/main/teximage.c
> @@ -528,6 +528,7 @@ _mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat )
>      if (_mesa_is_gles3(ctx)) {
>         switch (internalFormat) {
>         case GL_COMPRESSED_RGB8_ETC2:
> +      case GL_COMPRESSED_SRGB8_ETC2:
>            return GL_RGB;
>         default:
>            ; /* fallthrough */
> diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
> index 88b25b5..be0646d 100644
> --- a/src/mesa/main/texstore.c
> +++ b/src/mesa/main/texstore.c
> @@ -4139,6 +4139,7 @@ _mesa_get_texstore_func(gl_format format)
>         table[MESA_FORMAT_SIGNED_LA_LATC2] = _mesa_texstore_signed_rg_rgtc2;
>         table[MESA_FORMAT_ETC1_RGB8] = _mesa_texstore_etc1_rgb8;
>         table[MESA_FORMAT_ETC2_RGB8] = _mesa_texstore_etc2_rgb8;
> +      table[MESA_FORMAT_ETC2_SRGB8] = _mesa_texstore_etc2_srgb8;
>         table[MESA_FORMAT_SIGNED_A8] = _mesa_texstore_snorm8;
>         table[MESA_FORMAT_SIGNED_L8] = _mesa_texstore_snorm8;
>         table[MESA_FORMAT_SIGNED_AL88] = _mesa_texstore_snorm88;
>



More information about the mesa-dev mailing list