summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2009-11-23 12:39:17 -0800
committerIan Romanick <ian.d.romanick@intel.com>2009-11-23 12:39:17 -0800
commit6cfb88428e1a8770901108ea279442b2687a91d7 (patch)
treed85a81c490d2d624e24066e36805fb7aa237607e
parentd3507ec738f71f6b012ab06d6249b66c57904ab8 (diff)
ARB_texture_rg: Refactor _mesa_texstore_rg88 and _mesa_texstore_al88texture_rg-2
Create a new function _mesa_texstore_unorm88 that implements both _mesa_texstore_rg88 and _mesa_texstore_al88.
-rw-r--r--src/mesa/main/texstore.c169
1 files changed, 44 insertions, 125 deletions
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index 5ff1810e20..5f892c4256 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -316,6 +316,8 @@ make_temp_float_image(GLcontext *ctx, GLuint dims,
ASSERT(logicalBaseFormat == GL_RGBA ||
logicalBaseFormat == GL_RGB ||
+ logicalBaseFormat == GL_RG ||
+ logicalBaseFormat == GL_RED ||
logicalBaseFormat == GL_LUMINANCE_ALPHA ||
logicalBaseFormat == GL_LUMINANCE ||
logicalBaseFormat == GL_ALPHA ||
@@ -325,6 +327,8 @@ make_temp_float_image(GLcontext *ctx, GLuint dims,
ASSERT(textureBaseFormat == GL_RGBA ||
textureBaseFormat == GL_RGB ||
+ textureBaseFormat == GL_RG ||
+ textureBaseFormat == GL_RED ||
textureBaseFormat == GL_LUMINANCE_ALPHA ||
textureBaseFormat == GL_LUMINANCE ||
textureBaseFormat == GL_ALPHA ||
@@ -2047,124 +2051,23 @@ _mesa_texstore_argb1555(TEXSTORE_PARAMS)
static GLboolean
-_mesa_texstore_rg88(TEXSTORE_PARAMS)
+_mesa_texstore_unorm88(TEXSTORE_PARAMS)
{
const GLboolean littleEndian = _mesa_little_endian();
const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
- ASSERT(dstFormat == MESA_FORMAT_RG88 ||
+ ASSERT(dstFormat == MESA_FORMAT_AL88 ||
+ dstFormat == MESA_FORMAT_AL88_REV ||
+ dstFormat == MESA_FORMAT_RG88 ||
dstFormat == MESA_FORMAT_RG88_REV);
- ASSERT(texelBytes == 2);
-
- if (!ctx->_ImageTransferState &&
- !srcPacking->SwapBytes &&
- dstFormat == MESA_FORMAT_RG88 &&
- baseInternalFormat == GL_RG &&
- srcFormat == GL_RG &&
- srcType == GL_UNSIGNED_BYTE &&
- littleEndian) {
- /* simple memcpy path */
- memcpy_texture(ctx, dims,
- dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride,
- dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcFormat, srcType,
- srcAddr, srcPacking);
- }
- else if (!ctx->_ImageTransferState &&
- littleEndian &&
- srcType == GL_UNSIGNED_BYTE &&
- can_swizzle(baseInternalFormat) &&
- can_swizzle(srcFormat)) {
- GLubyte dstmap[4];
-
- /* dstmap - how to swizzle from RGBA to dst format:
- */
- if ((littleEndian && dstFormat == MESA_FORMAT_RG88) ||
- (!littleEndian && dstFormat == MESA_FORMAT_RG88_REV)) {
- dstmap[0] = 0;
- dstmap[1] = 1;
- }
- else {
- dstmap[0] = 1;
- dstmap[1] = 0;
- }
- dstmap[2] = ZERO; /* ? */
- dstmap[3] = ONE; /* ? */
-
- _mesa_swizzle_ubyte_image(ctx, dims,
- srcFormat,
- srcType,
- baseInternalFormat,
- dstmap, 2,
- dstAddr, dstXoffset, dstYoffset, dstZoffset,
- dstRowStride, dstImageOffsets,
- srcWidth, srcHeight, srcDepth, srcAddr,
- srcPacking);
- }
- else {
- /* 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;
- _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
- for (img = 0; img < srcDepth; img++) {
- GLubyte *dstRow = (GLubyte *) dstAddr
- + dstImageOffsets[dstZoffset + img] * texelBytes
- + dstYoffset * dstRowStride
- + dstXoffset * texelBytes;
- for (row = 0; row < srcHeight; row++) {
- GLushort *dstUS = (GLushort *) dstRow;
- if (dstFormat == MESA_FORMAT_RG88) {
- for (col = 0; col < srcWidth; col++) {
- /* src[0] is luminance, src[1] is alpha */
- dstUS[col] = PACK_COLOR_88( CHAN_TO_UBYTE(src[1]),
- CHAN_TO_UBYTE(src[0]) );
- src += 2;
- }
- }
- else {
- for (col = 0; col < srcWidth; col++) {
- /* src[0] is luminance, src[1] is alpha */
- dstUS[col] = PACK_COLOR_88_REV( CHAN_TO_UBYTE(src[1]),
- CHAN_TO_UBYTE(src[0]) );
- src += 2;
- }
- }
- dstRow += dstRowStride;
- }
- }
- _mesa_free((void *) tempImage);
- }
- return GL_TRUE;
-}
-
-
-static GLboolean
-_mesa_texstore_al88(TEXSTORE_PARAMS)
-{
- const GLboolean littleEndian = _mesa_little_endian();
- const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
- const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
-
- ASSERT(dstFormat == MESA_FORMAT_AL88 ||
- dstFormat == MESA_FORMAT_AL88_REV);
ASSERT(texelBytes == 2);
if (!ctx->_ImageTransferState &&
!srcPacking->SwapBytes &&
- dstFormat == MESA_FORMAT_AL88 &&
- baseInternalFormat == GL_LUMINANCE_ALPHA &&
- srcFormat == GL_LUMINANCE_ALPHA &&
+ baseInternalFormat == srcFormat &&
+ (dstFormat == MESA_FORMAT_AL88 || dstFormat == MESA_FORMAT_RG88) &&
srcType == GL_UNSIGNED_BYTE &&
littleEndian) {
/* simple memcpy path */
@@ -2185,15 +2088,30 @@ _mesa_texstore_al88(TEXSTORE_PARAMS)
/* dstmap - how to swizzle from RGBA to dst format:
*/
- if ((littleEndian && dstFormat == MESA_FORMAT_AL88) ||
- (!littleEndian && dstFormat == MESA_FORMAT_AL88_REV)) {
- dstmap[0] = 0;
- dstmap[1] = 3;
+ if ((dstFormat == MESA_FORMAT_AL88) ||
+ (dstFormat == MESA_FORMAT_AL88_REV)) {
+ if ((littleEndian && dstFormat == MESA_FORMAT_AL88) ||
+ (!littleEndian && dstFormat == MESA_FORMAT_AL88_REV)) {
+ dstmap[0] = 0;
+ dstmap[1] = 3;
+ }
+ else {
+ dstmap[0] = 3;
+ dstmap[1] = 0;
+ }
}
else {
- dstmap[0] = 3;
- dstmap[1] = 0;
+ if ((littleEndian && dstFormat == MESA_FORMAT_RG88) ||
+ (!littleEndian && dstFormat == MESA_FORMAT_RG88_REV)) {
+ dstmap[0] = 0;
+ dstmap[1] = 1;
+ }
+ else {
+ dstmap[0] = 1;
+ dstmap[1] = 0;
+ }
}
+
dstmap[2] = ZERO; /* ? */
dstmap[3] = ONE; /* ? */
@@ -2227,7 +2145,8 @@ _mesa_texstore_al88(TEXSTORE_PARAMS)
+ dstXoffset * texelBytes;
for (row = 0; row < srcHeight; row++) {
GLushort *dstUS = (GLushort *) dstRow;
- if (dstFormat == MESA_FORMAT_AL88) {
+ if ((dstFormat == MESA_FORMAT_AL88) ||
+ (dstFormat == MESA_FORMAT_RG88)) {
for (col = 0; col < srcWidth; col++) {
/* src[0] is luminance, src[1] is alpha */
dstUS[col] = PACK_COLOR_88( CHAN_TO_UBYTE(src[1]),
@@ -3201,13 +3120,13 @@ _mesa_texstore_sla8(TEXSTORE_PARAMS)
/* reuse normal luminance/alpha texstore code */
newDstFormat = MESA_FORMAT_AL88;
- k = _mesa_texstore_al88(ctx, dims, baseInternalFormat,
- newDstFormat, dstAddr,
- dstXoffset, dstYoffset, dstZoffset,
- dstRowStride, dstImageOffsets,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType,
- srcAddr, srcPacking);
+ k = _mesa_texstore_unorm88(ctx, dims, baseInternalFormat,
+ newDstFormat, dstAddr,
+ dstXoffset, dstYoffset, dstZoffset,
+ dstRowStride, dstImageOffsets,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType,
+ srcAddr, srcPacking);
return k;
}
@@ -3251,11 +3170,11 @@ 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_RG88, _mesa_texstore_rg88 },
- { MESA_FORMAT_RG88_REV, _mesa_texstore_rg88 },
+ { MESA_FORMAT_RG88, _mesa_texstore_unorm88 },
+ { MESA_FORMAT_RG88_REV, _mesa_texstore_unorm88 },
{ MESA_FORMAT_R8, _mesa_texstore_a8 },
- { MESA_FORMAT_AL88, _mesa_texstore_al88 },
- { MESA_FORMAT_AL88_REV, _mesa_texstore_al88 },
+ { MESA_FORMAT_AL88, _mesa_texstore_unorm88 },
+ { MESA_FORMAT_AL88_REV, _mesa_texstore_unorm88 },
{ MESA_FORMAT_AL1616, _mesa_texstore_al1616 },
{ MESA_FORMAT_AL1616_REV, _mesa_texstore_al1616 },
{ MESA_FORMAT_RGB332, _mesa_texstore_rgb332 },