mesa: implement new texture format AL44

Radeon GPUs can do this. R600 can even do render-to-texture.
Packing and extracting aren't implemented, but we shouldn't hit them (I think).
Tested with swrast, softpipe, and r300g.
This commit is contained in:
Marek Olšák
2010-12-21 23:46:32 +01:00
parent 621e5254ef
commit bae9d511f3
7 changed files with 95 additions and 1 deletions
+3
View File
@@ -208,6 +208,9 @@ do { \
#define PACK_COLOR_4444_REV( R, G, B, A ) \
((((B) & 0xf0) << 8) | (((A) & 0xf0) << 4) | ((R) & 0xf0) | ((G) >> 4))
#define PACK_COLOR_44( L, A ) \
(((L) & 0xf0) | (((A) & 0xf0) >> 4))
#define PACK_COLOR_88( L, A ) \
(((L) << 8) | (A))
+10
View File
@@ -221,6 +221,15 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
1, 1, 2 /* BlockWidth/Height,Bytes */
},
{
MESA_FORMAT_AL44, /* Name */
"MESA_FORMAT_AL44", /* StrName */
GL_LUMINANCE_ALPHA, /* BaseFormat */
GL_UNSIGNED_NORMALIZED, /* DataType */
0, 0, 0, 4, /* Red/Green/Blue/AlphaBits */
4, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
1, 1, 1 /* BlockWidth/Height,Bytes */
},
{
MESA_FORMAT_AL88, /* Name */
"MESA_FORMAT_AL88", /* StrName */
@@ -1270,6 +1279,7 @@ _mesa_format_to_type_and_comps(gl_format format,
*comps = 4;
return;
case MESA_FORMAT_AL44: /* XXX this isn't plain GL_UNSIGNED_BYTE */
case MESA_FORMAT_AL88:
case MESA_FORMAT_AL88_REV:
case MESA_FORMAT_RG88:
+1
View File
@@ -65,6 +65,7 @@ typedef enum
MESA_FORMAT_RGBA5551, /* RRRR RGGG GGBB BBBA */
MESA_FORMAT_ARGB1555, /* ARRR RRGG GGGB BBBB */
MESA_FORMAT_ARGB1555_REV, /* GGGB BBBB ARRR RRGG */
MESA_FORMAT_AL44, /* AAAA LLLL */
MESA_FORMAT_AL88, /* AAAA AAAA LLLL LLLL */
MESA_FORMAT_AL88_REV, /* LLLL LLLL AAAA AAAA */
MESA_FORMAT_AL1616, /* AAAA AAAA AAAA AAAA LLLL LLLL LLLL LLLL */
+7
View File
@@ -236,6 +236,13 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
fetch_texel_3d_f_argb1555_rev,
store_texel_argb1555_rev
},
{
MESA_FORMAT_AL44,
fetch_texel_1d_f_al44,
fetch_texel_2d_f_al44,
fetch_texel_3d_f_al44,
store_texel_al44
},
{
MESA_FORMAT_AL88,
fetch_texel_1d_f_al88,
+24
View File
@@ -883,6 +883,30 @@ static void store_texel_rg88_rev(struct gl_texture_image *texImage,
#endif
/* MESA_FORMAT_AL44 **********************************************************/
/* Fetch texel from 1D, 2D or 3D al44 texture, return 4 GLchans */
static void FETCH(f_al44)( const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLfloat *texel )
{
const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
texel[RCOMP] =
texel[GCOMP] =
texel[BCOMP] = UBYTE_TO_FLOAT( (s & 0x0f) << 4 );
texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xf0 );
}
#if DIM == 3
static void store_texel_al44(struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, const void *texel)
{
const GLubyte *rgba = (const GLubyte *) texel;
GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
*dst = PACK_COLOR_44(rgba[ACOMP], rgba[RCOMP]);
}
#endif
/* MESA_FORMAT_AL88 **********************************************************/
/* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
+3 -1
View File
@@ -117,9 +117,11 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
return MESA_FORMAT_L8;
/* Luminance/Alpha formats */
case GL_LUMINANCE4_ALPHA4:
return MESA_FORMAT_AL44;
case 2:
case GL_LUMINANCE_ALPHA:
case GL_LUMINANCE4_ALPHA4:
case GL_LUMINANCE6_ALPHA2:
case GL_LUMINANCE8_ALPHA8:
return MESA_FORMAT_AL88;
+47
View File
@@ -2112,6 +2112,52 @@ _mesa_texstore_argb2101010(TEXSTORE_PARAMS)
}
/**
* Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
*/
static GLboolean
_mesa_texstore_unorm44(TEXSTORE_PARAMS)
{
const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
ASSERT(dstFormat == MESA_FORMAT_AL44);
ASSERT(texelBytes == 1);
{
/* general path */
const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
baseInternalFormat,
baseFormat,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
srcPacking);
const GLchan *src = tempImage;
GLint img, row, col;
if (!tempImage)
return GL_FALSE;
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = (GLubyte *) dstAddr
+ dstImageOffsets[dstZoffset + img] * texelBytes
+ dstYoffset * dstRowStride
+ dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
GLubyte *dstUS = (GLubyte *) dstRow;
for (col = 0; col < srcWidth; col++) {
/* src[0] is luminance, src[1] is alpha */
dstUS[col] = PACK_COLOR_44( CHAN_TO_UBYTE(src[1]),
CHAN_TO_UBYTE(src[0]) );
src += 2;
}
dstRow += dstRowStride;
}
}
free((void *) tempImage);
}
return GL_TRUE;
}
/**
* Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
*/
@@ -3995,6 +4041,7 @@ texstore_funcs[MESA_FORMAT_COUNT] =
{ MESA_FORMAT_RGBA5551, _mesa_texstore_rgba5551 },
{ MESA_FORMAT_ARGB1555, _mesa_texstore_argb1555 },
{ MESA_FORMAT_ARGB1555_REV, _mesa_texstore_argb1555 },
{ MESA_FORMAT_AL44, _mesa_texstore_unorm44 },
{ MESA_FORMAT_AL88, _mesa_texstore_unorm88 },
{ MESA_FORMAT_AL88_REV, _mesa_texstore_unorm88 },
{ MESA_FORMAT_AL1616, _mesa_texstore_unorm1616 },