diff options
Diffstat (limited to 'mesalib/src/mesa/main/image.c')
-rw-r--r-- | mesalib/src/mesa/main/image.c | 512 |
1 files changed, 381 insertions, 131 deletions
diff --git a/mesalib/src/mesa/main/image.c b/mesalib/src/mesa/main/image.c index dc8d97728..86aa6d0d7 100644 --- a/mesalib/src/mesa/main/image.c +++ b/mesalib/src/mesa/main/image.c @@ -32,7 +32,6 @@ #include "glheader.h" #include "colormac.h" -#include "context.h" #include "enums.h" #include "image.h" #include "imports.h" @@ -274,17 +273,25 @@ _mesa_components_in_format( GLenum format ) case GL_STENCIL_INDEX: case GL_DEPTH_COMPONENT: case GL_RED: + case GL_RED_INTEGER_EXT: case GL_GREEN: + case GL_GREEN_INTEGER_EXT: case GL_BLUE: + case GL_BLUE_INTEGER_EXT: case GL_ALPHA: + case GL_ALPHA_INTEGER_EXT: case GL_LUMINANCE: + case GL_LUMINANCE_INTEGER_EXT: case GL_INTENSITY: return 1; case GL_LUMINANCE_ALPHA: + case GL_LUMINANCE_ALPHA_INTEGER_EXT: return 2; case GL_RGB: + case GL_RGB_INTEGER_EXT: return 3; case GL_RGBA: + case GL_RGBA_INTEGER_EXT: return 4; case GL_BGR: return 3; @@ -523,6 +530,28 @@ _mesa_is_legal_format_and_type( GLcontext *ctx, GLenum format, GLenum type ) default: return GL_FALSE; } + case GL_RED_INTEGER_EXT: + case GL_GREEN_INTEGER_EXT: + case GL_BLUE_INTEGER_EXT: + case GL_ALPHA_INTEGER_EXT: + case GL_RGB_INTEGER_EXT: + case GL_RGBA_INTEGER_EXT: + case GL_BGR_INTEGER_EXT: + case GL_BGRA_INTEGER_EXT: + case GL_LUMINANCE_INTEGER_EXT: + case GL_LUMINANCE_ALPHA_INTEGER_EXT: + switch (type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_INT: + case GL_UNSIGNED_INT: + return ctx->Extensions.EXT_texture_integer; + default: + return GL_FALSE; + } + default: ; /* fall-through */ } @@ -734,6 +763,32 @@ _mesa_is_depthstencil_format(GLenum format) } } + +/** + * Test if the given image format is a depth or stencil format. + */ +GLboolean +_mesa_is_depth_or_stencil_format(GLenum format) +{ + switch (format) { + case GL_DEPTH_COMPONENT: + case GL_DEPTH_COMPONENT16: + case GL_DEPTH_COMPONENT24: + case GL_DEPTH_COMPONENT32: + case GL_STENCIL_INDEX: + case GL_STENCIL_INDEX1_EXT: + case GL_STENCIL_INDEX4_EXT: + case GL_STENCIL_INDEX8_EXT: + case GL_STENCIL_INDEX16_EXT: + case GL_DEPTH_STENCIL_EXT: + case GL_DEPTH24_STENCIL8_EXT: + return GL_TRUE; + default: + return GL_FALSE; + } +} + + /** * Test if the given image format is a dudv format. */ @@ -751,6 +806,64 @@ _mesa_is_dudv_format(GLenum format) /** + * Test if the given format is an integer (non-normalized) format. + */ +GLboolean +_mesa_is_integer_format(GLenum format) +{ + switch (format) { + case GL_RED_INTEGER_EXT: + case GL_GREEN_INTEGER_EXT: + case GL_BLUE_INTEGER_EXT: + case GL_ALPHA_INTEGER_EXT: + case GL_RGB_INTEGER_EXT: + case GL_RGBA_INTEGER_EXT: + case GL_BGR_INTEGER_EXT: + case GL_BGRA_INTEGER_EXT: + case GL_LUMINANCE_INTEGER_EXT: + case GL_LUMINANCE_ALPHA_INTEGER_EXT: + return GL_TRUE; + default: + return GL_FALSE; + } +} + + +/** + * Test if an image format is a supported compressed format. + * \param format the internal format token provided by the user. + * \return GL_TRUE if compressed, GL_FALSE if uncompressed + */ +GLboolean +_mesa_is_compressed_format(GLcontext *ctx, GLenum format) +{ + switch (format) { + case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + return ctx->Extensions.EXT_texture_compression_s3tc; + case GL_RGB_S3TC: + case GL_RGB4_S3TC: + case GL_RGBA_S3TC: + case GL_RGBA4_S3TC: + return ctx->Extensions.S3_s3tc; + case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: + return ctx->Extensions.EXT_texture_sRGB + && ctx->Extensions.EXT_texture_compression_s3tc; + case GL_COMPRESSED_RGB_FXT1_3DFX: + case GL_COMPRESSED_RGBA_FXT1_3DFX: + return ctx->Extensions.TDFX_texture_compression_FXT1; + default: + return GL_FALSE; + } +} + + +/** * Return the address of a specific pixel in an image (1D, 2D or 3D). * * Pixel unpacking/packing parameters are observed according to \p packing. @@ -3215,6 +3328,8 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], GLint redIndex, greenIndex, blueIndex, alphaIndex; GLint stride; GLint rComp, bComp, gComp, aComp; + GLboolean intFormat; + GLfloat rs = 1.0f, gs = 1.0f, bs = 1.0f, as = 1.0f; /* scale factors */ ASSERT(srcFormat == GL_RED || srcFormat == GL_GREEN || @@ -3229,7 +3344,17 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], srcFormat == GL_BGRA || srcFormat == GL_ABGR_EXT || srcFormat == GL_DU8DV8_ATI || - srcFormat == GL_DUDV_ATI); + srcFormat == GL_DUDV_ATI || + srcFormat == GL_RED_INTEGER_EXT || + srcFormat == GL_GREEN_INTEGER_EXT || + srcFormat == GL_BLUE_INTEGER_EXT || + srcFormat == GL_ALPHA_INTEGER_EXT || + srcFormat == GL_RGB_INTEGER_EXT || + srcFormat == GL_RGBA_INTEGER_EXT || + srcFormat == GL_BGR_INTEGER_EXT || + srcFormat == GL_BGRA_INTEGER_EXT || + srcFormat == GL_LUMINANCE_INTEGER_EXT || + srcFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT); ASSERT(srcType == GL_UNSIGNED_BYTE || srcType == GL_BYTE || @@ -3256,31 +3381,37 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], switch (srcFormat) { case GL_RED: + case GL_RED_INTEGER_EXT: redIndex = 0; greenIndex = blueIndex = alphaIndex = -1; stride = 1; break; case GL_GREEN: + case GL_GREEN_INTEGER_EXT: greenIndex = 0; redIndex = blueIndex = alphaIndex = -1; stride = 1; break; case GL_BLUE: + case GL_BLUE_INTEGER_EXT: blueIndex = 0; redIndex = greenIndex = alphaIndex = -1; stride = 1; break; case GL_ALPHA: + case GL_ALPHA_INTEGER_EXT: redIndex = greenIndex = blueIndex = -1; alphaIndex = 0; stride = 1; break; case GL_LUMINANCE: + case GL_LUMINANCE_INTEGER_EXT: redIndex = greenIndex = blueIndex = 0; alphaIndex = -1; stride = 1; break; case GL_LUMINANCE_ALPHA: + case GL_LUMINANCE_ALPHA_INTEGER_EXT: redIndex = greenIndex = blueIndex = 0; alphaIndex = 1; stride = 2; @@ -3290,6 +3421,7 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], stride = 1; break; case GL_RGB: + case GL_RGB_INTEGER: redIndex = 0; greenIndex = 1; blueIndex = 2; @@ -3312,6 +3444,7 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], stride = 3; break; case GL_RGBA: + case GL_RGBA_INTEGER: redIndex = 0; greenIndex = 1; blueIndex = 2; @@ -3358,12 +3491,20 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], return; } + intFormat = _mesa_is_integer_format(srcFormat); -#define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \ +#define PROCESS(INDEX, CHANNEL, DEFAULT, DEFAULT_INT, TYPE, CONVERSION) \ if ((INDEX) < 0) { \ GLuint i; \ - for (i = 0; i < n; i++) { \ - rgba[i][CHANNEL] = DEFAULT; \ + if (intFormat) { \ + for (i = 0; i < n; i++) { \ + rgba[i][CHANNEL] = DEFAULT_INT; \ + } \ + } \ + else { \ + for (i = 0; i < n; i++) { \ + rgba[i][CHANNEL] = DEFAULT; \ + } \ } \ } \ else if (swapBytes) { \ @@ -3377,77 +3518,93 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], else if (sizeof(TYPE) == 4) { \ SWAP4BYTE(value); \ } \ - rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \ + if (intFormat) \ + rgba[i][CHANNEL] = (GLfloat) value; \ + else \ + rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \ s += stride; \ } \ } \ else { \ const TYPE *s = (const TYPE *) src; \ GLuint i; \ - for (i = 0; i < n; i++) { \ - rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \ - s += stride; \ + if (intFormat) { \ + for (i = 0; i < n; i++) { \ + rgba[i][CHANNEL] = (GLfloat) s[INDEX]; \ + s += stride; \ + } \ + } \ + else { \ + for (i = 0; i < n; i++) { \ + rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \ + s += stride; \ + } \ } \ } switch (srcType) { case GL_UNSIGNED_BYTE: - PROCESS(redIndex, RCOMP, 0.0F, GLubyte, UBYTE_TO_FLOAT); - PROCESS(greenIndex, GCOMP, 0.0F, GLubyte, UBYTE_TO_FLOAT); - PROCESS(blueIndex, BCOMP, 0.0F, GLubyte, UBYTE_TO_FLOAT); - PROCESS(alphaIndex, ACOMP, 1.0F, GLubyte, UBYTE_TO_FLOAT); + PROCESS(redIndex, RCOMP, 0.0F, 0, GLubyte, UBYTE_TO_FLOAT); + PROCESS(greenIndex, GCOMP, 0.0F, 0, GLubyte, UBYTE_TO_FLOAT); + PROCESS(blueIndex, BCOMP, 0.0F, 0, GLubyte, UBYTE_TO_FLOAT); + PROCESS(alphaIndex, ACOMP, 1.0F, 255, GLubyte, UBYTE_TO_FLOAT); break; case GL_BYTE: - PROCESS(redIndex, RCOMP, 0.0F, GLbyte, BYTE_TO_FLOAT); - PROCESS(greenIndex, GCOMP, 0.0F, GLbyte, BYTE_TO_FLOAT); - PROCESS(blueIndex, BCOMP, 0.0F, GLbyte, BYTE_TO_FLOAT); - PROCESS(alphaIndex, ACOMP, 1.0F, GLbyte, BYTE_TO_FLOAT); + PROCESS(redIndex, RCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOAT); + PROCESS(greenIndex, GCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOAT); + PROCESS(blueIndex, BCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOAT); + PROCESS(alphaIndex, ACOMP, 1.0F, 127, GLbyte, BYTE_TO_FLOAT); break; case GL_UNSIGNED_SHORT: - PROCESS(redIndex, RCOMP, 0.0F, GLushort, USHORT_TO_FLOAT); - PROCESS(greenIndex, GCOMP, 0.0F, GLushort, USHORT_TO_FLOAT); - PROCESS(blueIndex, BCOMP, 0.0F, GLushort, USHORT_TO_FLOAT); - PROCESS(alphaIndex, ACOMP, 1.0F, GLushort, USHORT_TO_FLOAT); + PROCESS(redIndex, RCOMP, 0.0F, 0, GLushort, USHORT_TO_FLOAT); + PROCESS(greenIndex, GCOMP, 0.0F, 0, GLushort, USHORT_TO_FLOAT); + PROCESS(blueIndex, BCOMP, 0.0F, 0, GLushort, USHORT_TO_FLOAT); + PROCESS(alphaIndex, ACOMP, 1.0F, 0xffff, GLushort, USHORT_TO_FLOAT); break; case GL_SHORT: - PROCESS(redIndex, RCOMP, 0.0F, GLshort, SHORT_TO_FLOAT); - PROCESS(greenIndex, GCOMP, 0.0F, GLshort, SHORT_TO_FLOAT); - PROCESS(blueIndex, BCOMP, 0.0F, GLshort, SHORT_TO_FLOAT); - PROCESS(alphaIndex, ACOMP, 1.0F, GLshort, SHORT_TO_FLOAT); + PROCESS(redIndex, RCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOAT); + PROCESS(greenIndex, GCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOAT); + PROCESS(blueIndex, BCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOAT); + PROCESS(alphaIndex, ACOMP, 1.0F, 32767, GLshort, SHORT_TO_FLOAT); break; case GL_UNSIGNED_INT: - PROCESS(redIndex, RCOMP, 0.0F, GLuint, UINT_TO_FLOAT); - PROCESS(greenIndex, GCOMP, 0.0F, GLuint, UINT_TO_FLOAT); - PROCESS(blueIndex, BCOMP, 0.0F, GLuint, UINT_TO_FLOAT); - PROCESS(alphaIndex, ACOMP, 1.0F, GLuint, UINT_TO_FLOAT); + PROCESS(redIndex, RCOMP, 0.0F, 0, GLuint, UINT_TO_FLOAT); + PROCESS(greenIndex, GCOMP, 0.0F, 0, GLuint, UINT_TO_FLOAT); + PROCESS(blueIndex, BCOMP, 0.0F, 0, GLuint, UINT_TO_FLOAT); + PROCESS(alphaIndex, ACOMP, 1.0F, 0xffffffff, GLuint, UINT_TO_FLOAT); break; case GL_INT: - PROCESS(redIndex, RCOMP, 0.0F, GLint, INT_TO_FLOAT); - PROCESS(greenIndex, GCOMP, 0.0F, GLint, INT_TO_FLOAT); - PROCESS(blueIndex, BCOMP, 0.0F, GLint, INT_TO_FLOAT); - PROCESS(alphaIndex, ACOMP, 1.0F, GLint, INT_TO_FLOAT); + PROCESS(redIndex, RCOMP, 0.0F, 0, GLint, INT_TO_FLOAT); + PROCESS(greenIndex, GCOMP, 0.0F, 0, GLint, INT_TO_FLOAT); + PROCESS(blueIndex, BCOMP, 0.0F, 0, GLint, INT_TO_FLOAT); + PROCESS(alphaIndex, ACOMP, 1.0F, 2147483647, GLint, INT_TO_FLOAT); break; case GL_FLOAT: - PROCESS(redIndex, RCOMP, 0.0F, GLfloat, (GLfloat)); - PROCESS(greenIndex, GCOMP, 0.0F, GLfloat, (GLfloat)); - PROCESS(blueIndex, BCOMP, 0.0F, GLfloat, (GLfloat)); - PROCESS(alphaIndex, ACOMP, 1.0F, GLfloat, (GLfloat)); + PROCESS(redIndex, RCOMP, 0.0F, 0.0F, GLfloat, (GLfloat)); + PROCESS(greenIndex, GCOMP, 0.0F, 0.0F, GLfloat, (GLfloat)); + PROCESS(blueIndex, BCOMP, 0.0F, 0.0F, GLfloat, (GLfloat)); + PROCESS(alphaIndex, ACOMP, 1.0F, 1.0F, GLfloat, (GLfloat)); break; case GL_HALF_FLOAT_ARB: - PROCESS(redIndex, RCOMP, 0.0F, GLhalfARB, _mesa_half_to_float); - PROCESS(greenIndex, GCOMP, 0.0F, GLhalfARB, _mesa_half_to_float); - PROCESS(blueIndex, BCOMP, 0.0F, GLhalfARB, _mesa_half_to_float); - PROCESS(alphaIndex, ACOMP, 1.0F, GLhalfARB, _mesa_half_to_float); + PROCESS(redIndex, RCOMP, 0.0F, 0.0F, GLhalfARB, _mesa_half_to_float); + PROCESS(greenIndex, GCOMP, 0.0F, 0.0F, GLhalfARB, _mesa_half_to_float); + PROCESS(blueIndex, BCOMP, 0.0F, 0.0F, GLhalfARB, _mesa_half_to_float); + PROCESS(alphaIndex, ACOMP, 1.0F, 1.0F, GLhalfARB, _mesa_half_to_float); break; case GL_UNSIGNED_BYTE_3_3_2: { const GLubyte *ubsrc = (const GLubyte *) src; GLuint i; + if (!intFormat) { + rs = 1.0F / 7.0F; + gs = 1.0F / 7.0F; + bs = 1.0F / 3.0F; + } for (i = 0; i < n; i ++) { GLubyte p = ubsrc[i]; - rgba[i][rComp] = ((p >> 5) ) * (1.0F / 7.0F); - rgba[i][gComp] = ((p >> 2) & 0x7) * (1.0F / 7.0F); - rgba[i][bComp] = ((p ) & 0x3) * (1.0F / 3.0F); + rgba[i][rComp] = ((p >> 5) ) * rs; + rgba[i][gComp] = ((p >> 2) & 0x7) * gs; + rgba[i][bComp] = ((p ) & 0x3) * bs; rgba[i][aComp] = 1.0F; } } @@ -3456,25 +3613,35 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], { const GLubyte *ubsrc = (const GLubyte *) src; GLuint i; + if (!intFormat) { + rs = 1.0F / 7.0F; + gs = 1.0F / 7.0F; + bs = 1.0F / 3.0F; + } for (i = 0; i < n; i ++) { GLubyte p = ubsrc[i]; - rgba[i][rComp] = ((p ) & 0x7) * (1.0F / 7.0F); - rgba[i][gComp] = ((p >> 3) & 0x7) * (1.0F / 7.0F); - rgba[i][bComp] = ((p >> 6) ) * (1.0F / 3.0F); + rgba[i][rComp] = ((p ) & 0x7) * rs; + rgba[i][gComp] = ((p >> 3) & 0x7) * gs; + rgba[i][bComp] = ((p >> 6) ) * bs; rgba[i][aComp] = 1.0F; } } break; case GL_UNSIGNED_SHORT_5_6_5: + if (!intFormat) { + rs = 1.0F / 31.0F; + gs = 1.0F / 63.0F; + bs = 1.0F / 31.0F; + } if (swapBytes) { const GLushort *ussrc = (const GLushort *) src; GLuint i; for (i = 0; i < n; i ++) { GLushort p = ussrc[i]; SWAP2BYTE(p); - rgba[i][rComp] = ((p >> 11) ) * (1.0F / 31.0F); - rgba[i][gComp] = ((p >> 5) & 0x3f) * (1.0F / 63.0F); - rgba[i][bComp] = ((p ) & 0x1f) * (1.0F / 31.0F); + rgba[i][rComp] = ((p >> 11) ) * rs; + rgba[i][gComp] = ((p >> 5) & 0x3f) * gs; + rgba[i][bComp] = ((p ) & 0x1f) * bs; rgba[i][aComp] = 1.0F; } } @@ -3483,23 +3650,28 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], GLuint i; for (i = 0; i < n; i ++) { GLushort p = ussrc[i]; - rgba[i][rComp] = ((p >> 11) ) * (1.0F / 31.0F); - rgba[i][gComp] = ((p >> 5) & 0x3f) * (1.0F / 63.0F); - rgba[i][bComp] = ((p ) & 0x1f) * (1.0F / 31.0F); + rgba[i][rComp] = ((p >> 11) ) * rs; + rgba[i][gComp] = ((p >> 5) & 0x3f) * gs; + rgba[i][bComp] = ((p ) & 0x1f) * bs; rgba[i][aComp] = 1.0F; } } break; case GL_UNSIGNED_SHORT_5_6_5_REV: + if (!intFormat) { + rs = 1.0F / 31.0F; + gs = 1.0F / 63.0F; + bs = 1.0F / 31.0F; + } if (swapBytes) { const GLushort *ussrc = (const GLushort *) src; GLuint i; for (i = 0; i < n; i ++) { GLushort p = ussrc[i]; SWAP2BYTE(p); - rgba[i][rComp] = ((p ) & 0x1f) * (1.0F / 31.0F); - rgba[i][gComp] = ((p >> 5) & 0x3f) * (1.0F / 63.0F); - rgba[i][bComp] = ((p >> 11) ) * (1.0F / 31.0F); + rgba[i][rComp] = ((p ) & 0x1f) * rs; + rgba[i][gComp] = ((p >> 5) & 0x3f) * gs; + rgba[i][bComp] = ((p >> 11) ) * bs; rgba[i][aComp] = 1.0F; } } @@ -3508,24 +3680,27 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], GLuint i; for (i = 0; i < n; i ++) { GLushort p = ussrc[i]; - rgba[i][rComp] = ((p ) & 0x1f) * (1.0F / 31.0F); - rgba[i][gComp] = ((p >> 5) & 0x3f) * (1.0F / 63.0F); - rgba[i][bComp] = ((p >> 11) ) * (1.0F / 31.0F); + rgba[i][rComp] = ((p ) & 0x1f) * rs; + rgba[i][gComp] = ((p >> 5) & 0x3f) * gs; + rgba[i][bComp] = ((p >> 11) ) * bs; rgba[i][aComp] = 1.0F; } } break; case GL_UNSIGNED_SHORT_4_4_4_4: + if (!intFormat) { + rs = gs = bs = as = 1.0F / 15.0F; + } if (swapBytes) { const GLushort *ussrc = (const GLushort *) src; GLuint i; for (i = 0; i < n; i ++) { GLushort p = ussrc[i]; SWAP2BYTE(p); - rgba[i][rComp] = ((p >> 12) ) * (1.0F / 15.0F); - rgba[i][gComp] = ((p >> 8) & 0xf) * (1.0F / 15.0F); - rgba[i][bComp] = ((p >> 4) & 0xf) * (1.0F / 15.0F); - rgba[i][aComp] = ((p ) & 0xf) * (1.0F / 15.0F); + rgba[i][rComp] = ((p >> 12) ) * rs; + rgba[i][gComp] = ((p >> 8) & 0xf) * gs; + rgba[i][bComp] = ((p >> 4) & 0xf) * bs; + rgba[i][aComp] = ((p ) & 0xf) * as; } } else { @@ -3533,24 +3708,27 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], GLuint i; for (i = 0; i < n; i ++) { GLushort p = ussrc[i]; - rgba[i][rComp] = ((p >> 12) ) * (1.0F / 15.0F); - rgba[i][gComp] = ((p >> 8) & 0xf) * (1.0F / 15.0F); - rgba[i][bComp] = ((p >> 4) & 0xf) * (1.0F / 15.0F); - rgba[i][aComp] = ((p ) & 0xf) * (1.0F / 15.0F); + rgba[i][rComp] = ((p >> 12) ) * rs; + rgba[i][gComp] = ((p >> 8) & 0xf) * gs; + rgba[i][bComp] = ((p >> 4) & 0xf) * bs; + rgba[i][aComp] = ((p ) & 0xf) * as; } } break; case GL_UNSIGNED_SHORT_4_4_4_4_REV: + if (!intFormat) { + rs = gs = bs = as = 1.0F / 15.0F; + } if (swapBytes) { const GLushort *ussrc = (const GLushort *) src; GLuint i; for (i = 0; i < n; i ++) { GLushort p = ussrc[i]; SWAP2BYTE(p); - rgba[i][rComp] = ((p ) & 0xf) * (1.0F / 15.0F); - rgba[i][gComp] = ((p >> 4) & 0xf) * (1.0F / 15.0F); - rgba[i][bComp] = ((p >> 8) & 0xf) * (1.0F / 15.0F); - rgba[i][aComp] = ((p >> 12) ) * (1.0F / 15.0F); + rgba[i][rComp] = ((p ) & 0xf) * rs; + rgba[i][gComp] = ((p >> 4) & 0xf) * gs; + rgba[i][bComp] = ((p >> 8) & 0xf) * bs; + rgba[i][aComp] = ((p >> 12) ) * as; } } else { @@ -3558,24 +3736,27 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], GLuint i; for (i = 0; i < n; i ++) { GLushort p = ussrc[i]; - rgba[i][rComp] = ((p ) & 0xf) * (1.0F / 15.0F); - rgba[i][gComp] = ((p >> 4) & 0xf) * (1.0F / 15.0F); - rgba[i][bComp] = ((p >> 8) & 0xf) * (1.0F / 15.0F); - rgba[i][aComp] = ((p >> 12) ) * (1.0F / 15.0F); + rgba[i][rComp] = ((p ) & 0xf) * rs; + rgba[i][gComp] = ((p >> 4) & 0xf) * gs; + rgba[i][bComp] = ((p >> 8) & 0xf) * bs; + rgba[i][aComp] = ((p >> 12) ) * as; } } break; case GL_UNSIGNED_SHORT_5_5_5_1: + if (!intFormat) { + rs = gs = bs = 1.0F / 31.0F; + } if (swapBytes) { const GLushort *ussrc = (const GLushort *) src; GLuint i; for (i = 0; i < n; i ++) { GLushort p = ussrc[i]; SWAP2BYTE(p); - rgba[i][rComp] = ((p >> 11) ) * (1.0F / 31.0F); - rgba[i][gComp] = ((p >> 6) & 0x1f) * (1.0F / 31.0F); - rgba[i][bComp] = ((p >> 1) & 0x1f) * (1.0F / 31.0F); - rgba[i][aComp] = ((p ) & 0x1) * (1.0F / 1.0F); + rgba[i][rComp] = ((p >> 11) ) * rs; + rgba[i][gComp] = ((p >> 6) & 0x1f) * gs; + rgba[i][bComp] = ((p >> 1) & 0x1f) * bs; + rgba[i][aComp] = ((p ) & 0x1) * as; } } else { @@ -3583,24 +3764,27 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], GLuint i; for (i = 0; i < n; i ++) { GLushort p = ussrc[i]; - rgba[i][rComp] = ((p >> 11) ) * (1.0F / 31.0F); - rgba[i][gComp] = ((p >> 6) & 0x1f) * (1.0F / 31.0F); - rgba[i][bComp] = ((p >> 1) & 0x1f) * (1.0F / 31.0F); - rgba[i][aComp] = ((p ) & 0x1) * (1.0F / 1.0F); + rgba[i][rComp] = ((p >> 11) ) * rs; + rgba[i][gComp] = ((p >> 6) & 0x1f) * gs; + rgba[i][bComp] = ((p >> 1) & 0x1f) * bs; + rgba[i][aComp] = ((p ) & 0x1) * as; } } break; case GL_UNSIGNED_SHORT_1_5_5_5_REV: + if (!intFormat) { + rs = gs = bs = 1.0F / 31.0F; + } if (swapBytes) { const GLushort *ussrc = (const GLushort *) src; GLuint i; for (i = 0; i < n; i ++) { GLushort p = ussrc[i]; SWAP2BYTE(p); - rgba[i][rComp] = ((p ) & 0x1f) * (1.0F / 31.0F); - rgba[i][gComp] = ((p >> 5) & 0x1f) * (1.0F / 31.0F); - rgba[i][bComp] = ((p >> 10) & 0x1f) * (1.0F / 31.0F); - rgba[i][aComp] = ((p >> 15) ) * (1.0F / 1.0F); + rgba[i][rComp] = ((p ) & 0x1f) * rs; + rgba[i][gComp] = ((p >> 5) & 0x1f) * gs; + rgba[i][bComp] = ((p >> 10) & 0x1f) * bs; + rgba[i][aComp] = ((p >> 15) ) * as; } } else { @@ -3608,10 +3792,10 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], GLuint i; for (i = 0; i < n; i ++) { GLushort p = ussrc[i]; - rgba[i][rComp] = ((p ) & 0x1f) * (1.0F / 31.0F); - rgba[i][gComp] = ((p >> 5) & 0x1f) * (1.0F / 31.0F); - rgba[i][bComp] = ((p >> 10) & 0x1f) * (1.0F / 31.0F); - rgba[i][aComp] = ((p >> 15) ) * (1.0F / 1.0F); + rgba[i][rComp] = ((p ) & 0x1f) * rs; + rgba[i][gComp] = ((p >> 5) & 0x1f) * gs; + rgba[i][bComp] = ((p >> 10) & 0x1f) * bs; + rgba[i][aComp] = ((p >> 15) ) * as; } } break; @@ -3619,23 +3803,45 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], if (swapBytes) { const GLuint *uisrc = (const GLuint *) src; GLuint i; - for (i = 0; i < n; i ++) { - GLuint p = uisrc[i]; - rgba[i][rComp] = UBYTE_TO_FLOAT((p ) & 0xff); - rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff); - rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff); - rgba[i][aComp] = UBYTE_TO_FLOAT((p >> 24) ); + if (intFormat) { + for (i = 0; i < n; i ++) { + GLuint p = uisrc[i]; + rgba[i][rComp] = (GLfloat) ((p ) & 0xff); + rgba[i][gComp] = (GLfloat) ((p >> 8) & 0xff); + rgba[i][bComp] = (GLfloat) ((p >> 16) & 0xff); + rgba[i][aComp] = (GLfloat) ((p >> 24) ); + } + } + else { + for (i = 0; i < n; i ++) { + GLuint p = uisrc[i]; + rgba[i][rComp] = UBYTE_TO_FLOAT((p ) & 0xff); + rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff); + rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff); + rgba[i][aComp] = UBYTE_TO_FLOAT((p >> 24) ); + } } } else { const GLuint *uisrc = (const GLuint *) src; GLuint i; - for (i = 0; i < n; i ++) { - GLuint p = uisrc[i]; - rgba[i][rComp] = UBYTE_TO_FLOAT((p >> 24) ); - rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff); - rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff); - rgba[i][aComp] = UBYTE_TO_FLOAT((p ) & 0xff); + if (intFormat) { + for (i = 0; i < n; i ++) { + GLuint p = uisrc[i]; + rgba[i][rComp] = (GLfloat) ((p >> 24) ); + rgba[i][gComp] = (GLfloat) ((p >> 16) & 0xff); + rgba[i][bComp] = (GLfloat) ((p >> 8) & 0xff); + rgba[i][aComp] = (GLfloat) ((p ) & 0xff); + } + } + else { + for (i = 0; i < n; i ++) { + GLuint p = uisrc[i]; + rgba[i][rComp] = UBYTE_TO_FLOAT((p >> 24) ); + rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff); + rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff); + rgba[i][aComp] = UBYTE_TO_FLOAT((p ) & 0xff); + } } } break; @@ -3643,37 +3849,65 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], if (swapBytes) { const GLuint *uisrc = (const GLuint *) src; GLuint i; - for (i = 0; i < n; i ++) { - GLuint p = uisrc[i]; - rgba[i][rComp] = UBYTE_TO_FLOAT((p >> 24) ); - rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff); - rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff); - rgba[i][aComp] = UBYTE_TO_FLOAT((p ) & 0xff); + if (intFormat) { + for (i = 0; i < n; i ++) { + GLuint p = uisrc[i]; + rgba[i][rComp] = (GLfloat) ((p >> 24) ); + rgba[i][gComp] = (GLfloat) ((p >> 16) & 0xff); + rgba[i][bComp] = (GLfloat) ((p >> 8) & 0xff); + rgba[i][aComp] = (GLfloat) ((p ) & 0xff); + } + } + else { + for (i = 0; i < n; i ++) { + GLuint p = uisrc[i]; + rgba[i][rComp] = UBYTE_TO_FLOAT((p >> 24) ); + rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff); + rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff); + rgba[i][aComp] = UBYTE_TO_FLOAT((p ) & 0xff); + } } } else { const GLuint *uisrc = (const GLuint *) src; GLuint i; - for (i = 0; i < n; i ++) { - GLuint p = uisrc[i]; - rgba[i][rComp] = UBYTE_TO_FLOAT((p ) & 0xff); - rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff); - rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff); - rgba[i][aComp] = UBYTE_TO_FLOAT((p >> 24) ); + if (intFormat) { + for (i = 0; i < n; i ++) { + GLuint p = uisrc[i]; + rgba[i][rComp] = (GLfloat) ((p ) & 0xff); + rgba[i][gComp] = (GLfloat) ((p >> 8) & 0xff); + rgba[i][bComp] = (GLfloat) ((p >> 16) & 0xff); + rgba[i][aComp] = (GLfloat) ((p >> 24) ); + } + } + else { + for (i = 0; i < n; i ++) { + GLuint p = uisrc[i]; + rgba[i][rComp] = UBYTE_TO_FLOAT((p ) & 0xff); + rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff); + rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff); + rgba[i][aComp] = UBYTE_TO_FLOAT((p >> 24) ); + } } } break; case GL_UNSIGNED_INT_10_10_10_2: + if (!intFormat) { + rs = 1.0F / 1023.0F; + gs = 1.0F / 1023.0F; + bs = 1.0F / 1023.0F; + as = 1.0F / 3.0F; + } if (swapBytes) { const GLuint *uisrc = (const GLuint *) src; GLuint i; for (i = 0; i < n; i ++) { GLuint p = uisrc[i]; SWAP4BYTE(p); - rgba[i][rComp] = ((p >> 22) ) * (1.0F / 1023.0F); - rgba[i][gComp] = ((p >> 12) & 0x3ff) * (1.0F / 1023.0F); - rgba[i][bComp] = ((p >> 2) & 0x3ff) * (1.0F / 1023.0F); - rgba[i][aComp] = ((p ) & 0x3 ) * (1.0F / 3.0F); + rgba[i][rComp] = ((p >> 22) ) * rs; + rgba[i][gComp] = ((p >> 12) & 0x3ff) * gs; + rgba[i][bComp] = ((p >> 2) & 0x3ff) * bs; + rgba[i][aComp] = ((p ) & 0x3 ) * as; } } else { @@ -3681,24 +3915,30 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], GLuint i; for (i = 0; i < n; i ++) { GLuint p = uisrc[i]; - rgba[i][rComp] = ((p >> 22) ) * (1.0F / 1023.0F); - rgba[i][gComp] = ((p >> 12) & 0x3ff) * (1.0F / 1023.0F); - rgba[i][bComp] = ((p >> 2) & 0x3ff) * (1.0F / 1023.0F); - rgba[i][aComp] = ((p ) & 0x3 ) * (1.0F / 3.0F); + rgba[i][rComp] = ((p >> 22) ) * rs; + rgba[i][gComp] = ((p >> 12) & 0x3ff) * gs; + rgba[i][bComp] = ((p >> 2) & 0x3ff) * bs; + rgba[i][aComp] = ((p ) & 0x3 ) * as; } } break; case GL_UNSIGNED_INT_2_10_10_10_REV: + if (!intFormat) { + rs = 1.0F / 1023.0F; + gs = 1.0F / 1023.0F; + bs = 1.0F / 1023.0F; + as = 1.0F / 3.0F; + } if (swapBytes) { const GLuint *uisrc = (const GLuint *) src; GLuint i; for (i = 0; i < n; i ++) { GLuint p = uisrc[i]; SWAP4BYTE(p); - rgba[i][rComp] = ((p ) & 0x3ff) * (1.0F / 1023.0F); - rgba[i][gComp] = ((p >> 10) & 0x3ff) * (1.0F / 1023.0F); - rgba[i][bComp] = ((p >> 20) & 0x3ff) * (1.0F / 1023.0F); - rgba[i][aComp] = ((p >> 30) ) * (1.0F / 3.0F); + rgba[i][rComp] = ((p ) & 0x3ff) * rs; + rgba[i][gComp] = ((p >> 10) & 0x3ff) * gs; + rgba[i][bComp] = ((p >> 20) & 0x3ff) * bs; + rgba[i][aComp] = ((p >> 30) ) * as; } } else { @@ -3706,10 +3946,10 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], GLuint i; for (i = 0; i < n; i ++) { GLuint p = uisrc[i]; - rgba[i][rComp] = ((p ) & 0x3ff) * (1.0F / 1023.0F); - rgba[i][gComp] = ((p >> 10) & 0x3ff) * (1.0F / 1023.0F); - rgba[i][bComp] = ((p >> 20) & 0x3ff) * (1.0F / 1023.0F); - rgba[i][aComp] = ((p >> 30) ) * (1.0F / 3.0F); + rgba[i][rComp] = ((p ) & 0x3ff) * rs; + rgba[i][gComp] = ((p >> 10) & 0x3ff) * gs; + rgba[i][bComp] = ((p >> 20) & 0x3ff) * bs; + rgba[i][aComp] = ((p >> 30) ) * as; } } break; @@ -4101,6 +4341,16 @@ _mesa_unpack_color_span_float( GLcontext *ctx, srcFormat == GL_RGBA || srcFormat == GL_BGRA || srcFormat == GL_ABGR_EXT || + srcFormat == GL_RED_INTEGER_EXT || + srcFormat == GL_GREEN_INTEGER_EXT || + srcFormat == GL_BLUE_INTEGER_EXT || + srcFormat == GL_ALPHA_INTEGER_EXT || + srcFormat == GL_RGB_INTEGER_EXT || + srcFormat == GL_RGBA_INTEGER_EXT || + srcFormat == GL_BGR_INTEGER_EXT || + srcFormat == GL_BGRA_INTEGER_EXT || + srcFormat == GL_LUMINANCE_INTEGER_EXT || + srcFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT || srcFormat == GL_COLOR_INDEX); ASSERT(srcType == GL_BITMAP || |