mesa: add support for GL_OES_compressed_ETC1_RGB8_texture
authorChia-I Wu <olv@lunarg.com>
Mon, 28 Nov 2011 08:57:02 +0000 (16:57 +0800)
committerChia-I Wu <olv@lunarg.com>
Fri, 2 Dec 2011 00:43:46 +0000 (08:43 +0800)
Add support for GL_OES_compressed_ETC1_RGB8_texture to core mesa.  There is no
driver support yet.

Unlike desktop GL compressed texture formats, GLES compressed texture formats
usually can only be used with glCompressedTexImage2D.  All other gl*Tex*Image*
functions are updated to check for that.

Reviewed-by: Brian Paul <brianp@vmware.com>
13 files changed:
src/mesa/main/APIspec.xml
src/mesa/main/extensions.c
src/mesa/main/format_unpack.c
src/mesa/main/formats.c
src/mesa/main/formats.h
src/mesa/main/glheader.h
src/mesa/main/image.c
src/mesa/main/mtypes.h
src/mesa/main/texcompress.c
src/mesa/main/texformat.c
src/mesa/main/teximage.c
src/mesa/main/texstore.c
src/mesa/swrast/s_texfetch.c

index 99c726c83addca304a63d69a30fbcfb89a105e2a..eeae599298fdc9ca3d9cfb89bb50df395ee5f196 100644 (file)
        <category name="OES_matrix_get"/>
        <category name="OES_read_format"/>
        <category name="OES_compressed_paletted_texture"/>
+       <category name="OES_compressed_ETC1_RGB8_texture"/>
        <category name="OES_point_size_array"/>
        <category name="OES_point_sprite"/>
        <category name="OES_query_matrix"/>
        <category name="GLES2.0"/>
 
        <category name="OES_compressed_paletted_texture"/>
+       <category name="OES_compressed_ETC1_RGB8_texture"/>
        <category name="OES_depth24"/>
        <category name="OES_depth32"/>
        <category name="OES_fbo_render_mipmap"/>
index 8ebc05139970bab4e6a60d4cc1f51cdbe4f0a335..b02a49de46efa72db96add44f32d9dc130cb7c23 100644 (file)
@@ -219,6 +219,7 @@ static const struct extension extension_table[] = {
    { "GL_OES_blend_func_separate",                 o(EXT_blend_func_separate),                      ES1,       2009 },
    { "GL_OES_blend_subtract",                      o(dummy_true),                                   ES1,       2009 },
    { "GL_OES_byte_coordinates",                    o(dummy_true),                                   ES1,       2002 },
+   { "GL_OES_compressed_ETC1_RGB8_texture",        o(OES_compressed_ETC1_RGB8_texture),             ES1 | ES2, 2005 },
    { "GL_OES_compressed_paletted_texture",         o(dummy_true),                                   ES1,       2003 },
    { "GL_OES_depth24",                             o(EXT_framebuffer_object),                       ES1 | ES2, 2005 },
    { "GL_OES_depth32",                             o(dummy_false),                     DISABLE,                2005 },
index b4e4ac4bb78f918d41d335c1d164e240966f0903..7da95465b4e646f81223fd3212ab78eea8ea9666 100644 (file)
@@ -1289,6 +1289,12 @@ unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
    /* XXX to do */
 }
 
+static void
+unpack_ETC1_RGB8(const void *src, GLfloat dst[][4], GLuint n)
+{
+   /* XXX to do */
+}
+
 static void
 unpack_SIGNED_A8(const void *src, GLfloat dst[][4], GLuint n)
 {
@@ -1536,6 +1542,8 @@ get_unpack_rgba_function(gl_format format)
       table[MESA_FORMAT_LA_LATC2] = unpack_LA_LATC2;
       table[MESA_FORMAT_SIGNED_LA_LATC2] = unpack_SIGNED_LA_LATC2;
 
+      table[MESA_FORMAT_ETC1_RGB8] = unpack_ETC1_RGB8;
+
       table[MESA_FORMAT_SIGNED_A8] = unpack_SIGNED_A8;
       table[MESA_FORMAT_SIGNED_L8] = unpack_SIGNED_L8;
       table[MESA_FORMAT_SIGNED_AL88] = unpack_SIGNED_AL88;
index 873fedc653987adda46d90a23b35d8a9ab96fc48..4b163d16289f19df7e0fbec0f3f3b5c857ee880d 100644 (file)
@@ -1386,6 +1386,16 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
      4, 4, 16                     /* 16 bytes per 4x4 block */
    },
 
+   {
+      MESA_FORMAT_ETC1_RGB8,
+      "MESA_FORMAT_ETC1_RGB8",
+      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,
@@ -1790,6 +1800,8 @@ _mesa_get_uncompressed_format(gl_format format)
       return MESA_FORMAT_AL88;
    case MESA_FORMAT_SIGNED_LA_LATC2:
       return MESA_FORMAT_SIGNED_AL88;
+   case MESA_FORMAT_ETC1_RGB8:
+      return MESA_FORMAT_RGB888;
    default:
 #ifdef DEBUG
       assert(!_mesa_is_format_compressed(format));
@@ -2240,6 +2252,7 @@ _mesa_format_to_type_and_comps(gl_format format,
    case MESA_FORMAT_SIGNED_L_LATC1:
    case MESA_FORMAT_LA_LATC2:
    case MESA_FORMAT_SIGNED_LA_LATC2:
+   case MESA_FORMAT_ETC1_RGB8:
       /* XXX generate error instead? */
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 0;
@@ -2777,6 +2790,9 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
    case MESA_FORMAT_SIGNED_LA_LATC2:
       return GL_FALSE;
 
+   case MESA_FORMAT_ETC1_RGB8:
+      return GL_FALSE;
+
    case MESA_FORMAT_SIGNED_A8:
    case MESA_FORMAT_SIGNED_L8:
    case MESA_FORMAT_SIGNED_AL88:
index b22b07338b38bf9d9e4bcf888211e76eacf89497..fc2bb9ac5d6da943c2fbf87306948c2128c7091a 100644 (file)
@@ -250,6 +250,8 @@ typedef enum
    MESA_FORMAT_SIGNED_LA_LATC2,
    /*@}*/
 
+   MESA_FORMAT_ETC1_RGB8,
+
    MESA_FORMAT_SIGNED_A8,         /*                               AAAA AAAA */
    MESA_FORMAT_SIGNED_L8,         /*                               LLLL LLLL */
    MESA_FORMAT_SIGNED_AL88,       /*                     AAAA AAAA LLLL LLLL */
index 7980111b52b1c9b1ec97951b7e3752c002f6bac8..315232371ed18dadc3bb72b7f181975663cc793a 100644 (file)
@@ -139,6 +139,10 @@ typedef void *GLeglImageOES;
 #define GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI 0x8837
 #endif
 
+#ifndef GL_OES_compressed_ETC1_RGB8_texture
+#define GL_ETC1_RGB8_OES                                        0x8D64
+#endif
+
 
 /**
  * Internal token to represent a GLSL shader program (a collection of
index 446d52e255953cc2d55a064dad5e957e345a974d..b266e26c6795a21e917ea0abad2b38aa5622580c 100644 (file)
@@ -741,6 +741,7 @@ _mesa_is_color_format(GLenum format)
       case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
       case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
       case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
+      case GL_ETC1_RGB8_OES:
       /* generic integer formats */
       case GL_RED_INTEGER_EXT:
       case GL_GREEN_INTEGER_EXT:
@@ -1050,6 +1051,8 @@ _mesa_is_compressed_format(struct gl_context *ctx, GLenum format)
       return ctx->Extensions.EXT_texture_compression_latc;
    case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
       return ctx->Extensions.ATI_texture_compression_3dc;
+   case GL_ETC1_RGB8_OES:
+      return ctx->Extensions.OES_compressed_ETC1_RGB8_texture;
 #if FEATURE_ES
    case GL_PALETTE4_RGB8_OES:
    case GL_PALETTE4_RGBA8_OES:
index 08cd80a7f1a0f9913ba1a31660266f81fec2f9dc..33b00c680001435c5019523aa8843b161fc2bfec 100644 (file)
@@ -2979,6 +2979,7 @@ struct gl_extensions
    GLboolean OES_EGL_image;
    GLboolean OES_draw_texture;
    GLboolean OES_EGL_image_external;
+   GLboolean OES_compressed_ETC1_RGB8_texture;
    GLboolean extension_sentinel;
    /** The extension string */
    const GLubyte *String;
index 0458b9b689ef1786905cd9a4756c0298f95f99ca..5045aef06cc1db820569e481351ff02b4d6c3aee 100644 (file)
@@ -40,6 +40,7 @@
 #include "texcompress_fxt1.h"
 #include "texcompress_rgtc.h"
 #include "texcompress_s3tc.h"
+#include "texcompress_etc.h"
 #include "swrast/s_context.h"
 
 
@@ -90,6 +91,7 @@ _mesa_gl_compressed_format_base_format(GLenum format)
    case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
    case GL_COMPRESSED_RGB_FXT1_3DFX:
    case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
+   case GL_ETC1_RGB8_OES:
       return GL_RGB;
 
    case GL_COMPRESSED_RGBA:
@@ -264,6 +266,15 @@ _mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats)
       }
    }
 
+   if (ctx->Extensions.OES_compressed_ETC1_RGB8_texture) {
+      if (formats) {
+         formats[n++] = GL_ETC1_RGB8_OES;
+      }
+      else {
+         n += 1;
+      }
+   }
+
 #if FEATURE_ES1
    if (ctx->API == API_OPENGLES) {
       if (formats) {
@@ -341,6 +352,9 @@ _mesa_glenum_to_compressed_format(GLenum format)
    case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
       return MESA_FORMAT_SIGNED_LA_LATC2;
 
+   case GL_ETC1_RGB8_OES:
+      return MESA_FORMAT_ETC1_RGB8;
+
    default:
       return MESA_FORMAT_NONE;
    }
@@ -406,6 +420,9 @@ _mesa_compressed_format_to_glenum(struct gl_context *ctx, GLuint mesaFormat)
    case MESA_FORMAT_SIGNED_LA_LATC2:
       return GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT;
 
+   case MESA_FORMAT_ETC1_RGB8:
+      return GL_ETC1_RGB8_OES;
+
    default:
       _mesa_problem(ctx, "Unexpected mesa texture format in"
                     " _mesa_compressed_format_to_glenum()");
@@ -515,6 +532,11 @@ _mesa_decompress_image(gl_format format, GLuint width, GLuint height,
       fetch = _mesa_fetch_texel_2d_f_signed_la_latc2;
       break;
 
+   /* ETC1 formats */
+   case MESA_FORMAT_ETC1_RGB8:
+      fetch = _mesa_fetch_texel_2d_f_etc1_rgb8;
+      break;
+
    default:
       _mesa_problem(NULL, "Unexpected format in _mesa_decompress_image()");
       return;
index 6d8e272ba081b38bc1a6bf9ab9f118b9d62d0328..868913873e6aca434f370edfdd96e99d26e0a5e6 100644 (file)
@@ -919,6 +919,16 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
       }
    }
 
+   if (ctx->Extensions.OES_compressed_ETC1_RGB8_texture) {
+      switch (internalFormat) {
+         case GL_ETC1_RGB8_OES:
+            RETURN_IF_SUPPORTED(MESA_FORMAT_ETC1_RGB8);
+            break;
+         default:
+            ; /* fallthrough */
+      }
+   }
+
    _mesa_problem(ctx, "unexpected format %s in _mesa_choose_tex_format()",
                  _mesa_lookup_enum_by_nr(internalFormat));
    return MESA_FORMAT_NONE;
index 2bc7abdc2470c18dde525b1a728773f320f6a524..2bdcedc8c134338ec2d544a24cc25fcede2e7a05 100644 (file)
@@ -493,6 +493,15 @@ _mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat )
       }
    }
 
+   if (ctx->Extensions.OES_compressed_ETC1_RGB8_texture) {
+      switch (internalFormat) {
+      case GL_ETC1_RGB8_OES:
+         return GL_RGB;
+      default:
+         ; /* fallthrough */
+      }
+   }
+
    if (ctx->API == API_OPENGLES) {
       switch (internalFormat) {
       case GL_PALETTE4_RGB8_OES:
@@ -1292,6 +1301,20 @@ legal_texture_size(struct gl_context *ctx, gl_format format,
 }
 
 
+/**
+ * Return true if the format is only valid for glCompressedTexImage.
+ */
+static GLboolean
+compressedteximage_only_format(const struct gl_context *ctx, GLenum format)
+{
+   switch (format) {
+   case GL_ETC1_RGB8_OES:
+      return GL_TRUE;
+   default:
+      return GL_FALSE;
+   }
+}
+
 
 /**
  * Helper function to determine whether a target and specific compression
@@ -1639,6 +1662,11 @@ texture_error_check( struct gl_context *ctx,
                         "glTexImage%dD(target)", dimensions);
          return GL_TRUE;
       }
+      if (compressedteximage_only_format(ctx, internalFormat)) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+               "glTexImage%dD(no compression for format)", dimensions);
+         return GL_TRUE;
+      }
       if (border != 0) {
          if (!isProxy) {
             _mesa_error(ctx, GL_INVALID_OPERATION,
@@ -1793,6 +1821,12 @@ subtexture_error_check2( struct gl_context *ctx, GLuint dimensions,
    if (_mesa_is_format_compressed(destTex->TexFormat)) {
       GLuint bw, bh;
 
+      if (compressedteximage_only_format(ctx, destTex->InternalFormat)) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+               "glTexSubImage%dD(no compression for format)", dimensions);
+         return GL_TRUE;
+      }
+
       /* do tests which depend on compression block size */
       _mesa_get_format_block_size(destTex->TexFormat, &bw, &bh);
 
@@ -1922,6 +1956,11 @@ copytexture_error_check( struct gl_context *ctx, GLuint dimensions,
                      "glCopyTexImage%dD(target)", dimensions);
          return GL_TRUE;
       }
+      if (compressedteximage_only_format(ctx, internalFormat)) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+               "glCopyTexImage%dD(no compression for format)", dimensions);
+         return GL_TRUE;
+      }
       if (border != 0) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "glCopyTexImage%dD(border!=0)", dimensions);
@@ -2061,6 +2100,11 @@ copytexsubimage_error_check2( struct gl_context *ctx, GLuint dimensions,
    }
 
    if (_mesa_is_format_compressed(teximage->TexFormat)) {
+      if (compressedteximage_only_format(ctx, teximage->InternalFormat)) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+               "glCopyTexSubImage%dD(no compression for format)", dimensions);
+         return GL_TRUE;
+      }
       /* offset must be multiple of 4 */
       if ((xoffset & 3) || (yoffset & 3)) {
          _mesa_error(ctx, GL_INVALID_VALUE,
@@ -3244,6 +3288,13 @@ compressed_subtexture_error_check2(struct gl_context *ctx, GLuint dims,
       return GL_TRUE;
    }
 
+   if (compressedteximage_only_format(ctx, format)) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
+                  , dims, format);
+      return GL_TRUE;
+   }
+
    if (((width == 1 || width == 2) &&
         width != (GLsizei) texImage->Width) ||
        (width > (GLsizei) texImage->Width)) {
index 0079590775ce49bf77962d58fbbf2c9645f22bd4..1e1c749679d9a84cdd6c87cb49f091d6cee15aa2 100644 (file)
@@ -67,6 +67,7 @@
 #include "texcompress_fxt1.h"
 #include "texcompress_rgtc.h"
 #include "texcompress_s3tc.h"
+#include "texcompress_etc.h"
 #include "teximage.h"
 #include "texstore.h"
 #include "enums.h"
@@ -4437,6 +4438,7 @@ _mesa_get_texstore_func(gl_format format)
       table[MESA_FORMAT_SIGNED_L_LATC1] = _mesa_texstore_signed_red_rgtc1;
       table[MESA_FORMAT_LA_LATC2] = _mesa_texstore_rg_rgtc2;
       table[MESA_FORMAT_SIGNED_LA_LATC2] = _mesa_texstore_signed_rg_rgtc2;
+      table[MESA_FORMAT_ETC1_RGB8] = _mesa_texstore_etc1_rgb8;
       table[MESA_FORMAT_SIGNED_A8] = _mesa_texstore_snorm8;
       table[MESA_FORMAT_SIGNED_L8] = _mesa_texstore_snorm8;
       table[MESA_FORMAT_SIGNED_AL88] = _mesa_texstore_snorm88;
index ab7cfb50f946990bc3380c57b7b351998a5b3b2a..158752d736bed811a72348fb7d80e8d155459bda 100644 (file)
@@ -39,6 +39,7 @@
 #include "main/texcompress_fxt1.h"
 #include "main/texcompress_s3tc.h"
 #include "main/texcompress_rgtc.h"
+#include "main/texcompress_etc.h"
 #include "main/teximage.h"
 #include "s_context.h"
 #include "s_texfetch.h"
@@ -1177,6 +1178,13 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       NULL,
       NULL
    },
+   {
+      MESA_FORMAT_ETC1_RGB8,
+      NULL,
+      _mesa_fetch_texel_2d_f_etc1_rgb8,
+      NULL,
+      NULL
+   },
    {
       MESA_FORMAT_SIGNED_A8,
       fetch_texel_1d_signed_a8,