X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Ftexcompress_rgtc.c;h=5773459d79fe7886d182f6f134bac6fac8bf364a;hb=f7fa946d1da96178e63e42dd8d8739d3e0f66e1d;hp=26dca2d760b5dbbb08566c719158fd1194606721;hpb=cf143c1f4d7c3636ddd5c767518b1b00ff46b16c;p=mesa.git diff --git a/src/mesa/main/texcompress_rgtc.c b/src/mesa/main/texcompress_rgtc.c index 26dca2d760b..5773459d79f 100644 --- a/src/mesa/main/texcompress_rgtc.c +++ b/src/mesa/main/texcompress_rgtc.c @@ -43,12 +43,14 @@ #include "texcompress.h" #include "texcompress_rgtc.h" #include "texstore.h" +#include "swrast/s_context.h" + #define RGTC_DEBUG 0 -static void unsigned_encode_rgtc_chan(GLubyte *blkaddr, GLubyte srccolors[4][4], +static void unsigned_encode_rgtc_ubyte(GLubyte *blkaddr, GLubyte srccolors[4][4], GLint numxpixels, GLint numypixels); -static void signed_encode_rgtc_chan(GLbyte *blkaddr, GLbyte srccolors[4][4], +static void signed_encode_rgtc_ubyte(GLbyte *blkaddr, GLbyte srccolors[4][4], GLint numxpixels, GLint numypixels); static void unsigned_fetch_texel_rgtc(unsigned srcRowStride, const GLubyte *pixdata, @@ -57,15 +59,15 @@ static void unsigned_fetch_texel_rgtc(unsigned srcRowStride, const GLubyte *pixd static void signed_fetch_texel_rgtc(unsigned srcRowStride, const GLbyte *pixdata, unsigned i, unsigned j, GLbyte *value, unsigned comps); -static void extractsrc_u( GLubyte srcpixels[4][4], const GLchan *srcaddr, +static void extractsrc_u( GLubyte srcpixels[4][4], const GLubyte *srcaddr, GLint srcRowStride, GLint numxpixels, GLint numypixels, GLint comps) { GLubyte i, j; - const GLchan *curaddr; + const GLubyte *curaddr; for (j = 0; j < numypixels; j++) { curaddr = srcaddr + j * srcRowStride * comps; for (i = 0; i < numxpixels; i++) { - srcpixels[j][i] = *curaddr / (CHAN_MAX / 255); + srcpixels[j][i] = *curaddr; curaddr += comps; } } @@ -90,23 +92,17 @@ GLboolean _mesa_texstore_red_rgtc1(TEXSTORE_PARAMS) { GLubyte *dst; - const GLint texWidth = dstRowStride * 4 / 8; /* a bit of a hack */ - const GLchan *tempImage = NULL; + const GLubyte *tempImage = NULL; int i, j; int numxpixels, numypixels; - const GLchan *srcaddr; + const GLubyte *srcaddr; GLubyte srcpixels[4][4]; GLubyte *blkaddr; GLint dstRowDiff; - ASSERT(dstFormat == MESA_FORMAT_RED_RGTC1); - ASSERT(dstXoffset % 4 == 0); - ASSERT(dstYoffset % 4 == 0); - ASSERT(dstZoffset % 4 == 0); - (void) dstZoffset; - (void) dstImageOffsets; - + ASSERT(dstFormat == MESA_FORMAT_RED_RGTC1 || + dstFormat == MESA_FORMAT_L_LATC1); - tempImage = _mesa_make_temp_chan_image(ctx, dims, + tempImage = _mesa_make_temp_ubyte_image(ctx, dims, baseInternalFormat, _mesa_get_format_base_format(dstFormat), srcWidth, srcHeight, srcDepth, @@ -115,12 +111,10 @@ _mesa_texstore_red_rgtc1(TEXSTORE_PARAMS) if (!tempImage) return GL_FALSE; /* out of memory */ - dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0, - dstFormat, - texWidth, (GLubyte *) dstAddr); + dst = dstSlices[0]; blkaddr = dst; - dstRowDiff = dstRowStride >= (srcWidth * 4) ? dstRowStride - (((srcWidth + 3) & ~3) * 4) : 0; + dstRowDiff = dstRowStride >= (srcWidth * 2) ? dstRowStride - (((srcWidth + 3) & ~3) * 2) : 0; for (j = 0; j < srcHeight; j+=4) { if (srcHeight > j + 3) numypixels = 4; else numypixels = srcHeight - j; @@ -129,14 +123,14 @@ _mesa_texstore_red_rgtc1(TEXSTORE_PARAMS) if (srcWidth > i + 3) numxpixels = 4; else numxpixels = srcWidth - i; extractsrc_u(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 1); - unsigned_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels); + unsigned_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels); srcaddr += numxpixels; blkaddr += 8; } blkaddr += dstRowDiff; } - if (tempImage) - free((void *) tempImage); + + free((void *) tempImage); return GL_TRUE; } @@ -145,7 +139,6 @@ GLboolean _mesa_texstore_signed_red_rgtc1(TEXSTORE_PARAMS) { GLbyte *dst; - const GLint texWidth = dstRowStride * 4 / 8; /* a bit of a hack */ const GLfloat *tempImage = NULL; int i, j; int numxpixels, numypixels; @@ -153,12 +146,8 @@ _mesa_texstore_signed_red_rgtc1(TEXSTORE_PARAMS) GLbyte srcpixels[4][4]; GLbyte *blkaddr; GLint dstRowDiff; - ASSERT(dstFormat == MESA_FORMAT_SIGNED_RED_RGTC1); - ASSERT(dstXoffset % 4 == 0); - ASSERT(dstYoffset % 4 == 0); - ASSERT(dstZoffset % 4 == 0); - (void) dstZoffset; - (void) dstImageOffsets; + ASSERT(dstFormat == MESA_FORMAT_SIGNED_RED_RGTC1 || + dstFormat == MESA_FORMAT_SIGNED_L_LATC1); tempImage = _mesa_make_temp_float_image(ctx, dims, baseInternalFormat, @@ -169,12 +158,10 @@ _mesa_texstore_signed_red_rgtc1(TEXSTORE_PARAMS) if (!tempImage) return GL_FALSE; /* out of memory */ - dst = (GLbyte *)_mesa_compressed_image_address(dstXoffset, dstYoffset, 0, - dstFormat, - texWidth, (GLubyte *) dstAddr); + dst = (GLbyte *) dstSlices[0]; blkaddr = dst; - dstRowDiff = dstRowStride >= (srcWidth * 4) ? dstRowStride - (((srcWidth + 3) & ~3) * 4) : 0; + dstRowDiff = dstRowStride >= (srcWidth * 2) ? dstRowStride - (((srcWidth + 3) & ~3) * 2) : 0; for (j = 0; j < srcHeight; j+=4) { if (srcHeight > j + 3) numypixels = 4; else numypixels = srcHeight - j; @@ -183,14 +170,14 @@ _mesa_texstore_signed_red_rgtc1(TEXSTORE_PARAMS) if (srcWidth > i + 3) numxpixels = 4; else numxpixels = srcWidth - i; extractsrc_s(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 1); - signed_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels); + signed_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels); srcaddr += numxpixels; blkaddr += 8; } blkaddr += dstRowDiff; } - if (tempImage) - free((void *) tempImage); + + free((void *) tempImage); return GL_TRUE; } @@ -199,23 +186,18 @@ GLboolean _mesa_texstore_rg_rgtc2(TEXSTORE_PARAMS) { GLubyte *dst; - const GLint texWidth = dstRowStride * 4 / 16; /* a bit of a hack */ - const GLchan *tempImage = NULL; + const GLubyte *tempImage = NULL; int i, j; int numxpixels, numypixels; - const GLchan *srcaddr; + const GLubyte *srcaddr; GLubyte srcpixels[4][4]; GLubyte *blkaddr; GLint dstRowDiff; - ASSERT(dstFormat == MESA_FORMAT_RG_RGTC2); - ASSERT(dstXoffset % 4 == 0); - ASSERT(dstYoffset % 4 == 0); - ASSERT(dstZoffset % 4 == 0); - (void) dstZoffset; - (void) dstImageOffsets; + ASSERT(dstFormat == MESA_FORMAT_RG_RGTC2 || + dstFormat == MESA_FORMAT_LA_LATC2); - tempImage = _mesa_make_temp_chan_image(ctx, dims, + tempImage = _mesa_make_temp_ubyte_image(ctx, dims, baseInternalFormat, _mesa_get_format_base_format(dstFormat), srcWidth, srcHeight, srcDepth, @@ -224,12 +206,10 @@ _mesa_texstore_rg_rgtc2(TEXSTORE_PARAMS) if (!tempImage) return GL_FALSE; /* out of memory */ - dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0, - dstFormat, - texWidth, (GLubyte *) dstAddr); + dst = dstSlices[0]; blkaddr = dst; - dstRowDiff = dstRowStride >= (srcWidth * 8) ? dstRowStride - (((srcWidth + 7) & ~7) * 8) : 0; + dstRowDiff = dstRowStride >= (srcWidth * 4) ? dstRowStride - (((srcWidth + 3) & ~3) * 4) : 0; for (j = 0; j < srcHeight; j+=4) { if (srcHeight > j + 3) numypixels = 4; else numypixels = srcHeight - j; @@ -238,11 +218,11 @@ _mesa_texstore_rg_rgtc2(TEXSTORE_PARAMS) if (srcWidth > i + 3) numxpixels = 4; else numxpixels = srcWidth - i; extractsrc_u(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 2); - unsigned_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels); + unsigned_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels); blkaddr += 8; - extractsrc_u(srcpixels, (GLchan *)srcaddr + 1, srcWidth, numxpixels, numypixels, 2); - unsigned_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels); + extractsrc_u(srcpixels, (GLubyte *)srcaddr + 1, srcWidth, numxpixels, numypixels, 2); + unsigned_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels); blkaddr += 8; @@ -250,8 +230,8 @@ _mesa_texstore_rg_rgtc2(TEXSTORE_PARAMS) } blkaddr += dstRowDiff; } - if (tempImage) - free((void *) tempImage); + + free((void *) tempImage); return GL_TRUE; } @@ -260,7 +240,6 @@ GLboolean _mesa_texstore_signed_rg_rgtc2(TEXSTORE_PARAMS) { GLbyte *dst; - const GLint texWidth = dstRowStride * 4 / 16; /* a bit of a hack */ const GLfloat *tempImage = NULL; int i, j; int numxpixels, numypixels; @@ -269,12 +248,8 @@ _mesa_texstore_signed_rg_rgtc2(TEXSTORE_PARAMS) GLbyte *blkaddr; GLint dstRowDiff; - ASSERT(dstFormat == MESA_FORMAT_SIGNED_RG_RGTC2); - ASSERT(dstXoffset % 4 == 0); - ASSERT(dstYoffset % 4 == 0); - ASSERT(dstZoffset % 4 == 0); - (void) dstZoffset; - (void) dstImageOffsets; + ASSERT(dstFormat == MESA_FORMAT_SIGNED_RG_RGTC2 || + dstFormat == MESA_FORMAT_SIGNED_LA_LATC2); tempImage = _mesa_make_temp_float_image(ctx, dims, baseInternalFormat, @@ -285,12 +260,10 @@ _mesa_texstore_signed_rg_rgtc2(TEXSTORE_PARAMS) if (!tempImage) return GL_FALSE; /* out of memory */ - dst = (GLbyte *)_mesa_compressed_image_address(dstXoffset, dstYoffset, 0, - dstFormat, - texWidth, (GLubyte *) dstAddr); + dst = (GLbyte *) dstSlices[0]; blkaddr = dst; - dstRowDiff = dstRowStride >= (srcWidth * 8) ? dstRowStride - (((srcWidth + 7) & ~7) * 8) : 0; + dstRowDiff = dstRowStride >= (srcWidth * 4) ? dstRowStride - (((srcWidth + 3) & ~3) * 4) : 0; for (j = 0; j < srcHeight; j += 4) { if (srcHeight > j + 3) numypixels = 4; else numypixels = srcHeight - j; @@ -300,11 +273,11 @@ _mesa_texstore_signed_rg_rgtc2(TEXSTORE_PARAMS) else numxpixels = srcWidth - i; extractsrc_s(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 2); - signed_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels); + signed_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels); blkaddr += 8; extractsrc_s(srcpixels, srcaddr + 1, srcWidth, numxpixels, numypixels, 2); - signed_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels); + signed_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels); blkaddr += 8; srcaddr += numxpixels * 2; @@ -312,19 +285,21 @@ _mesa_texstore_signed_rg_rgtc2(TEXSTORE_PARAMS) } blkaddr += dstRowDiff; } - if (tempImage) - free((void *) tempImage); + + free((void *) tempImage); return GL_TRUE; } void -_mesa_fetch_texel_2d_f_red_rgtc1(const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel) +_mesa_fetch_texel_red_rgtc1(const struct swrast_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel) { GLubyte red; - unsigned_fetch_texel_rgtc(texImage->RowStride, (GLubyte *)(texImage->Data), - i, j, &red, 1); + GLint sliceOffset = k ? texImage->ImageOffsets[k] / 2 : 0; + unsigned_fetch_texel_rgtc(texImage->RowStride, + texImage->Map + sliceOffset, + i, j, &red, 1); texel[RCOMP] = UBYTE_TO_FLOAT(red); texel[GCOMP] = 0.0; texel[BCOMP] = 0.0; @@ -332,12 +307,14 @@ _mesa_fetch_texel_2d_f_red_rgtc1(const struct gl_texture_image *texImage, } void -_mesa_fetch_texel_2d_f_signed_red_rgtc1(const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel) +_mesa_fetch_texel_signed_red_rgtc1(const struct swrast_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel) { GLbyte red; - signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data), - i, j, &red, 1); + GLint sliceOffset = k ? texImage->ImageOffsets[k] / 2 : 0; + signed_fetch_texel_rgtc(texImage->RowStride, + (GLbyte *)(texImage->Map) + sliceOffset, + i, j, &red, 1); texel[RCOMP] = BYTE_TO_FLOAT_TEX(red); texel[GCOMP] = 0.0; texel[BCOMP] = 0.0; @@ -345,14 +322,17 @@ _mesa_fetch_texel_2d_f_signed_red_rgtc1(const struct gl_texture_image *texImage, } void -_mesa_fetch_texel_2d_f_rg_rgtc2(const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel) +_mesa_fetch_texel_rg_rgtc2(const struct swrast_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel) { GLubyte red, green; - unsigned_fetch_texel_rgtc(texImage->RowStride, (GLubyte *)(texImage->Data), - i, j, &red, 2); - unsigned_fetch_texel_rgtc(texImage->RowStride, (GLubyte *)(texImage->Data) + 8, - i, j, &green, 2); + GLint sliceOffset = k ? texImage->ImageOffsets[k] : 0; + unsigned_fetch_texel_rgtc(texImage->RowStride, + texImage->Map + sliceOffset, + i, j, &red, 2); + unsigned_fetch_texel_rgtc(texImage->RowStride, + texImage->Map + sliceOffset + 8, + i, j, &green, 2); texel[RCOMP] = UBYTE_TO_FLOAT(red); texel[GCOMP] = UBYTE_TO_FLOAT(green); texel[BCOMP] = 0.0; @@ -360,20 +340,89 @@ _mesa_fetch_texel_2d_f_rg_rgtc2(const struct gl_texture_image *texImage, } void -_mesa_fetch_texel_2d_f_signed_rg_rgtc2(const struct gl_texture_image *texImage, - GLint i, GLint j, GLint k, GLfloat *texel) +_mesa_fetch_texel_signed_rg_rgtc2(const struct swrast_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel) { GLbyte red, green; - signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data), - i, j, &red, 2); - signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data) + 8, - i, j, &green, 2); + GLint sliceOffset = k ? texImage->ImageOffsets[k] : 0; + signed_fetch_texel_rgtc(texImage->RowStride, + (GLbyte *)(texImage->Map) + sliceOffset, + i, j, &red, 2); + signed_fetch_texel_rgtc(texImage->RowStride, + (GLbyte *)(texImage->Map) + sliceOffset + 8, + i, j, &green, 2); texel[RCOMP] = BYTE_TO_FLOAT_TEX(red); texel[GCOMP] = BYTE_TO_FLOAT_TEX(green); texel[BCOMP] = 0.0; texel[ACOMP] = 1.0; } +void +_mesa_fetch_texel_l_latc1(const struct swrast_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel) +{ + GLubyte red; + GLint sliceOffset = k ? texImage->ImageOffsets[k] / 2 : 0; + unsigned_fetch_texel_rgtc(texImage->RowStride, + texImage->Map + sliceOffset, + i, j, &red, 1); + texel[RCOMP] = + texel[GCOMP] = + texel[BCOMP] = UBYTE_TO_FLOAT(red); + texel[ACOMP] = 1.0; +} + +void +_mesa_fetch_texel_signed_l_latc1(const struct swrast_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel) +{ + GLbyte red; + GLint sliceOffset = k ? texImage->ImageOffsets[k] / 2 : 0; + signed_fetch_texel_rgtc(texImage->RowStride, + (GLbyte *)(texImage->Map) + sliceOffset, + i, j, &red, 1); + texel[RCOMP] = + texel[GCOMP] = + texel[BCOMP] = BYTE_TO_FLOAT_TEX(red); + texel[ACOMP] = 1.0; +} + +void +_mesa_fetch_texel_la_latc2(const struct swrast_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel) +{ + GLubyte red, green; + GLint sliceOffset = k ? texImage->ImageOffsets[k] : 0; + unsigned_fetch_texel_rgtc(texImage->RowStride, + texImage->Map + sliceOffset, + i, j, &red, 2); + unsigned_fetch_texel_rgtc(texImage->RowStride, + texImage->Map + sliceOffset + 8, + i, j, &green, 2); + texel[RCOMP] = + texel[GCOMP] = + texel[BCOMP] = UBYTE_TO_FLOAT(red); + texel[ACOMP] = UBYTE_TO_FLOAT(green); +} + +void +_mesa_fetch_texel_signed_la_latc2(const struct swrast_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel) +{ + GLbyte red, green; + GLint sliceOffset = k ? texImage->ImageOffsets[k] : 0; + signed_fetch_texel_rgtc(texImage->RowStride, + (GLbyte *)(texImage->Map) + sliceOffset, + i, j, &red, 2); + signed_fetch_texel_rgtc(texImage->RowStride, + (GLbyte *)(texImage->Map) + sliceOffset + 8, + i, j, &green, 2); + texel[RCOMP] = + texel[GCOMP] = + texel[BCOMP] = BYTE_TO_FLOAT_TEX(red); + texel[ACOMP] = BYTE_TO_FLOAT_TEX(green); +} + #define TAG(x) unsigned_##x #define TYPE GLubyte