From bae9d511f343c7bd5eb66d1d1d18d32b47e738e3 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Tue, 21 Dec 2010 23:46:32 +0100 Subject: 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. --- src/mesa/main/colormac.h | 3 +++ src/mesa/main/formats.c | 10 ++++++++++ src/mesa/main/formats.h | 1 + src/mesa/main/texfetch.c | 7 +++++++ src/mesa/main/texfetch_tmp.h | 24 ++++++++++++++++++++++ src/mesa/main/texformat.c | 4 +++- src/mesa/main/texstore.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 95 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/mesa/main/colormac.h b/src/mesa/main/colormac.h index f00faa5bee..065f9f937a 100644 --- a/src/mesa/main/colormac.h +++ b/src/mesa/main/colormac.h @@ -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)) diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c index 0975407214..90296f434c 100644 --- a/src/mesa/main/formats.c +++ b/src/mesa/main/formats.c @@ -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: diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h index c147376ea2..db63fde3f2 100644 --- a/src/mesa/main/formats.h +++ b/src/mesa/main/formats.h @@ -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 */ diff --git a/src/mesa/main/texfetch.c b/src/mesa/main/texfetch.c index dff5963117..5c7e728c13 100644 --- a/src/mesa/main/texfetch.c +++ b/src/mesa/main/texfetch.c @@ -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, diff --git a/src/mesa/main/texfetch_tmp.h b/src/mesa/main/texfetch_tmp.h index c985de9290..b6ffdd09f9 100644 --- a/src/mesa/main/texfetch_tmp.h +++ b/src/mesa/main/texfetch_tmp.h @@ -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 */ diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c index 9d30a7e30c..fb738fc635 100644 --- a/src/mesa/main/texformat.c +++ b/src/mesa/main/texformat.c @@ -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; diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c index b14ffe84b6..f9ab946902 100644 --- a/src/mesa/main/texstore.c +++ b/src/mesa/main/texstore.c @@ -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 }, -- cgit v1.2.3