summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2014-08-22 20:32:27 -0700
committerIago Toral Quiroga <[email protected]>2015-01-12 11:20:27 +0100
commit96fe6191cb8c61ca5ae7c49f54db83f3b44ed126 (patch)
tree2fb827970e9532c18d18be63c5b7a60602612f96
parent3e4669a8f3f61dab54faf1ae8512569bca1e54da (diff)
mesa: Fix A1R5G5B5 packing/unpacking
As with B5G6R5, these have been left broken with comments saying they are. Signed-off-by: Jason Ekstrand <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
-rw-r--r--src/mesa/main/format_pack.c8
-rw-r--r--src/mesa/main/format_unpack.c11
-rw-r--r--src/mesa/main/formats.c3
-rw-r--r--src/mesa/swrast/s_texfetch_tmp.h8
4 files changed, 11 insertions, 19 deletions
diff --git a/src/mesa/main/format_pack.c b/src/mesa/main/format_pack.c
index 20d2b1a4821..3d191c186f2 100644
--- a/src/mesa/main/format_pack.c
+++ b/src/mesa/main/format_pack.c
@@ -584,17 +584,11 @@ pack_float_B5G5R5A1_UNORM(const GLfloat src[4], void *dst)
pack_ubyte_B5G5R5A1_UNORM(v, dst);
}
-
-/* MESA_FORMAT_A1R5G5B5_UNORM
- * Warning: these functions do not match the current Mesa definition
- * of MESA_FORMAT_A1R5G5B5_UNORM.
- */
-
static void
pack_ubyte_A1R5G5B5_UNORM(const GLubyte src[4], void *dst)
{
GLushort *d = ((GLushort *) dst), tmp;
- tmp = PACK_COLOR_1555(src[ACOMP], src[RCOMP], src[GCOMP], src[BCOMP]);
+ tmp = PACK_COLOR_5551(src[BCOMP], src[GCOMP], src[RCOMP], src[ACOMP]);
*d = (tmp >> 8) | (tmp << 8);
}
diff --git a/src/mesa/main/format_unpack.c b/src/mesa/main/format_unpack.c
index 69c76d354c7..dfc5024dd48 100644
--- a/src/mesa/main/format_unpack.c
+++ b/src/mesa/main/format_unpack.c
@@ -2830,17 +2830,14 @@ unpack_ubyte_B5G5R5A1_UNORM(const void *src, GLubyte dst[][4], GLuint n)
static void
unpack_ubyte_A1R5G5B5_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
- /* Warning: this function does not match the current Mesa definition
- * of MESA_FORMAT_A1R5G5B5_UNORM.
- */
const GLushort *s = ((const GLushort *) src);
GLuint i;
for (i = 0; i < n; i++) {
GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
- dst[i][RCOMP] = EXPAND_5_8((tmp >> 10) & 0x1f);
- dst[i][GCOMP] = EXPAND_5_8((tmp >> 5) & 0x1f);
- dst[i][BCOMP] = EXPAND_5_8((tmp >> 0) & 0x1f);
- dst[i][ACOMP] = EXPAND_1_8((tmp >> 15) & 0x01);
+ dst[i][RCOMP] = EXPAND_5_8((tmp >> 1) & 0x1f);
+ dst[i][GCOMP] = EXPAND_5_8((tmp >> 6) & 0x1f);
+ dst[i][BCOMP] = EXPAND_5_8((tmp >> 11) & 0x1f);
+ dst[i][ACOMP] = EXPAND_1_8((tmp ) & 0x01);
}
}
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 1315d368c27..676ac2781ae 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -1487,7 +1487,8 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
!swapBytes;
case MESA_FORMAT_A1R5G5B5_UNORM:
- return GL_FALSE;
+ return format == GL_BGRA && type == GL_UNSIGNED_SHORT_5_5_5_1 &&
+ !swapBytes;
case MESA_FORMAT_L4A4_UNORM:
return GL_FALSE;
diff --git a/src/mesa/swrast/s_texfetch_tmp.h b/src/mesa/swrast/s_texfetch_tmp.h
index 23db48d969e..e3a3cfe361a 100644
--- a/src/mesa/swrast/s_texfetch_tmp.h
+++ b/src/mesa/swrast/s_texfetch_tmp.h
@@ -482,10 +482,10 @@ FETCH(A1R5G5B5_UNORM)(const struct swrast_texture_image *texImage,
{
const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
- texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
- texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
- texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
- texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
+ texel[RCOMP] = ((s >> 1) & 0x1f) * (1.0F / 31.0F);
+ texel[GCOMP] = ((s >> 6) & 0x1f) * (1.0F / 31.0F);
+ texel[BCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
+ texel[ACOMP] = ((s ) & 0x01) * 1.0F;
}