mesa: add support for GL_OES_compressed_ETC1_RGB8_texture

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>
This commit is contained in:
Chia-I Wu
2011-11-28 16:57:02 +08:00
parent 51f4d27254
commit d4a38e86d4
13 changed files with 130 additions and 0 deletions

View File

@@ -3806,6 +3806,7 @@
<category name="OES_matrix_get"/> <category name="OES_matrix_get"/>
<category name="OES_read_format"/> <category name="OES_read_format"/>
<category name="OES_compressed_paletted_texture"/> <category name="OES_compressed_paletted_texture"/>
<category name="OES_compressed_ETC1_RGB8_texture"/>
<category name="OES_point_size_array"/> <category name="OES_point_size_array"/>
<category name="OES_point_sprite"/> <category name="OES_point_sprite"/>
<category name="OES_query_matrix"/> <category name="OES_query_matrix"/>
@@ -4105,6 +4106,7 @@
<category name="GLES2.0"/> <category name="GLES2.0"/>
<category name="OES_compressed_paletted_texture"/> <category name="OES_compressed_paletted_texture"/>
<category name="OES_compressed_ETC1_RGB8_texture"/>
<category name="OES_depth24"/> <category name="OES_depth24"/>
<category name="OES_depth32"/> <category name="OES_depth32"/>
<category name="OES_fbo_render_mipmap"/> <category name="OES_fbo_render_mipmap"/>

View 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_func_separate", o(EXT_blend_func_separate), ES1, 2009 },
{ "GL_OES_blend_subtract", o(dummy_true), ES1, 2009 }, { "GL_OES_blend_subtract", o(dummy_true), ES1, 2009 },
{ "GL_OES_byte_coordinates", o(dummy_true), ES1, 2002 }, { "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_compressed_paletted_texture", o(dummy_true), ES1, 2003 },
{ "GL_OES_depth24", o(EXT_framebuffer_object), ES1 | ES2, 2005 }, { "GL_OES_depth24", o(EXT_framebuffer_object), ES1 | ES2, 2005 },
{ "GL_OES_depth32", o(dummy_false), DISABLE, 2005 }, { "GL_OES_depth32", o(dummy_false), DISABLE, 2005 },

View File

@@ -1289,6 +1289,12 @@ unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
/* XXX to do */ /* XXX to do */
} }
static void
unpack_ETC1_RGB8(const void *src, GLfloat dst[][4], GLuint n)
{
/* XXX to do */
}
static void static void
unpack_SIGNED_A8(const void *src, GLfloat dst[][4], GLuint n) 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_LA_LATC2] = unpack_LA_LATC2;
table[MESA_FORMAT_SIGNED_LA_LATC2] = unpack_SIGNED_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_A8] = unpack_SIGNED_A8;
table[MESA_FORMAT_SIGNED_L8] = unpack_SIGNED_L8; table[MESA_FORMAT_SIGNED_L8] = unpack_SIGNED_L8;
table[MESA_FORMAT_SIGNED_AL88] = unpack_SIGNED_AL88; table[MESA_FORMAT_SIGNED_AL88] = unpack_SIGNED_AL88;

View File

@@ -1386,6 +1386,16 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
4, 4, 16 /* 16 bytes per 4x4 block */ 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 */ /* Signed formats from EXT_texture_snorm that are not in GL3.1 */
{ {
MESA_FORMAT_SIGNED_A8, MESA_FORMAT_SIGNED_A8,
@@ -1790,6 +1800,8 @@ _mesa_get_uncompressed_format(gl_format format)
return MESA_FORMAT_AL88; return MESA_FORMAT_AL88;
case MESA_FORMAT_SIGNED_LA_LATC2: case MESA_FORMAT_SIGNED_LA_LATC2:
return MESA_FORMAT_SIGNED_AL88; return MESA_FORMAT_SIGNED_AL88;
case MESA_FORMAT_ETC1_RGB8:
return MESA_FORMAT_RGB888;
default: default:
#ifdef DEBUG #ifdef DEBUG
assert(!_mesa_is_format_compressed(format)); 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_SIGNED_L_LATC1:
case MESA_FORMAT_LA_LATC2: case MESA_FORMAT_LA_LATC2:
case MESA_FORMAT_SIGNED_LA_LATC2: case MESA_FORMAT_SIGNED_LA_LATC2:
case MESA_FORMAT_ETC1_RGB8:
/* XXX generate error instead? */ /* XXX generate error instead? */
*datatype = GL_UNSIGNED_BYTE; *datatype = GL_UNSIGNED_BYTE;
*comps = 0; *comps = 0;
@@ -2777,6 +2790,9 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
case MESA_FORMAT_SIGNED_LA_LATC2: case MESA_FORMAT_SIGNED_LA_LATC2:
return GL_FALSE; return GL_FALSE;
case MESA_FORMAT_ETC1_RGB8:
return GL_FALSE;
case MESA_FORMAT_SIGNED_A8: case MESA_FORMAT_SIGNED_A8:
case MESA_FORMAT_SIGNED_L8: case MESA_FORMAT_SIGNED_L8:
case MESA_FORMAT_SIGNED_AL88: case MESA_FORMAT_SIGNED_AL88:

View File

@@ -250,6 +250,8 @@ typedef enum
MESA_FORMAT_SIGNED_LA_LATC2, MESA_FORMAT_SIGNED_LA_LATC2,
/*@}*/ /*@}*/
MESA_FORMAT_ETC1_RGB8,
MESA_FORMAT_SIGNED_A8, /* AAAA AAAA */ MESA_FORMAT_SIGNED_A8, /* AAAA AAAA */
MESA_FORMAT_SIGNED_L8, /* LLLL LLLL */ MESA_FORMAT_SIGNED_L8, /* LLLL LLLL */
MESA_FORMAT_SIGNED_AL88, /* AAAA AAAA LLLL LLLL */ MESA_FORMAT_SIGNED_AL88, /* AAAA AAAA LLLL LLLL */

View File

@@ -139,6 +139,10 @@ typedef void *GLeglImageOES;
#define GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI 0x8837 #define GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI 0x8837
#endif #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 * Internal token to represent a GLSL shader program (a collection of

View File

@@ -741,6 +741,7 @@ _mesa_is_color_format(GLenum format)
case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT: case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT: case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI: case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
case GL_ETC1_RGB8_OES:
/* generic integer formats */ /* generic integer formats */
case GL_RED_INTEGER_EXT: case GL_RED_INTEGER_EXT:
case GL_GREEN_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; return ctx->Extensions.EXT_texture_compression_latc;
case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI: case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
return ctx->Extensions.ATI_texture_compression_3dc; return ctx->Extensions.ATI_texture_compression_3dc;
case GL_ETC1_RGB8_OES:
return ctx->Extensions.OES_compressed_ETC1_RGB8_texture;
#if FEATURE_ES #if FEATURE_ES
case GL_PALETTE4_RGB8_OES: case GL_PALETTE4_RGB8_OES:
case GL_PALETTE4_RGBA8_OES: case GL_PALETTE4_RGBA8_OES:

View File

@@ -2979,6 +2979,7 @@ struct gl_extensions
GLboolean OES_EGL_image; GLboolean OES_EGL_image;
GLboolean OES_draw_texture; GLboolean OES_draw_texture;
GLboolean OES_EGL_image_external; GLboolean OES_EGL_image_external;
GLboolean OES_compressed_ETC1_RGB8_texture;
GLboolean extension_sentinel; GLboolean extension_sentinel;
/** The extension string */ /** The extension string */
const GLubyte *String; const GLubyte *String;

View File

@@ -40,6 +40,7 @@
#include "texcompress_fxt1.h" #include "texcompress_fxt1.h"
#include "texcompress_rgtc.h" #include "texcompress_rgtc.h"
#include "texcompress_s3tc.h" #include "texcompress_s3tc.h"
#include "texcompress_etc.h"
#include "swrast/s_context.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_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGB_FXT1_3DFX: case GL_COMPRESSED_RGB_FXT1_3DFX:
case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
case GL_ETC1_RGB8_OES:
return GL_RGB; return GL_RGB;
case GL_COMPRESSED_RGBA: 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 FEATURE_ES1
if (ctx->API == API_OPENGLES) { if (ctx->API == API_OPENGLES) {
if (formats) { if (formats) {
@@ -341,6 +352,9 @@ _mesa_glenum_to_compressed_format(GLenum format)
case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT: case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
return MESA_FORMAT_SIGNED_LA_LATC2; return MESA_FORMAT_SIGNED_LA_LATC2;
case GL_ETC1_RGB8_OES:
return MESA_FORMAT_ETC1_RGB8;
default: default:
return MESA_FORMAT_NONE; 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: case MESA_FORMAT_SIGNED_LA_LATC2:
return GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT; return GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT;
case MESA_FORMAT_ETC1_RGB8:
return GL_ETC1_RGB8_OES;
default: default:
_mesa_problem(ctx, "Unexpected mesa texture format in" _mesa_problem(ctx, "Unexpected mesa texture format in"
" _mesa_compressed_format_to_glenum()"); " _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; fetch = _mesa_fetch_texel_2d_f_signed_la_latc2;
break; break;
/* ETC1 formats */
case MESA_FORMAT_ETC1_RGB8:
fetch = _mesa_fetch_texel_2d_f_etc1_rgb8;
break;
default: default:
_mesa_problem(NULL, "Unexpected format in _mesa_decompress_image()"); _mesa_problem(NULL, "Unexpected format in _mesa_decompress_image()");
return; return;

View 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_problem(ctx, "unexpected format %s in _mesa_choose_tex_format()",
_mesa_lookup_enum_by_nr(internalFormat)); _mesa_lookup_enum_by_nr(internalFormat));
return MESA_FORMAT_NONE; return MESA_FORMAT_NONE;

View 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) { if (ctx->API == API_OPENGLES) {
switch (internalFormat) { switch (internalFormat) {
case GL_PALETTE4_RGB8_OES: 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 * 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); "glTexImage%dD(target)", dimensions);
return GL_TRUE; 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 (border != 0) {
if (!isProxy) { if (!isProxy) {
_mesa_error(ctx, GL_INVALID_OPERATION, _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)) { if (_mesa_is_format_compressed(destTex->TexFormat)) {
GLuint bw, bh; 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 */ /* do tests which depend on compression block size */
_mesa_get_format_block_size(destTex->TexFormat, &bw, &bh); _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); "glCopyTexImage%dD(target)", dimensions);
return GL_TRUE; 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) { if (border != 0) {
_mesa_error(ctx, GL_INVALID_OPERATION, _mesa_error(ctx, GL_INVALID_OPERATION,
"glCopyTexImage%dD(border!=0)", dimensions); "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 (_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 */ /* offset must be multiple of 4 */
if ((xoffset & 3) || (yoffset & 3)) { if ((xoffset & 3) || (yoffset & 3)) {
_mesa_error(ctx, GL_INVALID_VALUE, _mesa_error(ctx, GL_INVALID_VALUE,
@@ -3244,6 +3288,13 @@ compressed_subtexture_error_check2(struct gl_context *ctx, GLuint dims,
return GL_TRUE; 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) && if (((width == 1 || width == 2) &&
width != (GLsizei) texImage->Width) || width != (GLsizei) texImage->Width) ||
(width > (GLsizei) texImage->Width)) { (width > (GLsizei) texImage->Width)) {

View File

@@ -67,6 +67,7 @@
#include "texcompress_fxt1.h" #include "texcompress_fxt1.h"
#include "texcompress_rgtc.h" #include "texcompress_rgtc.h"
#include "texcompress_s3tc.h" #include "texcompress_s3tc.h"
#include "texcompress_etc.h"
#include "teximage.h" #include "teximage.h"
#include "texstore.h" #include "texstore.h"
#include "enums.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_SIGNED_L_LATC1] = _mesa_texstore_signed_red_rgtc1;
table[MESA_FORMAT_LA_LATC2] = _mesa_texstore_rg_rgtc2; table[MESA_FORMAT_LA_LATC2] = _mesa_texstore_rg_rgtc2;
table[MESA_FORMAT_SIGNED_LA_LATC2] = _mesa_texstore_signed_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_A8] = _mesa_texstore_snorm8;
table[MESA_FORMAT_SIGNED_L8] = _mesa_texstore_snorm8; table[MESA_FORMAT_SIGNED_L8] = _mesa_texstore_snorm8;
table[MESA_FORMAT_SIGNED_AL88] = _mesa_texstore_snorm88; table[MESA_FORMAT_SIGNED_AL88] = _mesa_texstore_snorm88;

View File

@@ -39,6 +39,7 @@
#include "main/texcompress_fxt1.h" #include "main/texcompress_fxt1.h"
#include "main/texcompress_s3tc.h" #include "main/texcompress_s3tc.h"
#include "main/texcompress_rgtc.h" #include "main/texcompress_rgtc.h"
#include "main/texcompress_etc.h"
#include "main/teximage.h" #include "main/teximage.h"
#include "s_context.h" #include "s_context.h"
#include "s_texfetch.h" #include "s_texfetch.h"
@@ -1177,6 +1178,13 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
NULL, NULL,
NULL NULL
}, },
{
MESA_FORMAT_ETC1_RGB8,
NULL,
_mesa_fetch_texel_2d_f_etc1_rgb8,
NULL,
NULL
},
{ {
MESA_FORMAT_SIGNED_A8, MESA_FORMAT_SIGNED_A8,
fetch_texel_1d_signed_a8, fetch_texel_1d_signed_a8,