[Mesa-dev] [PATCH] mesa: adjust usage of swapBytes/littleEndian in format_matches_format_and_type
Marek Olšák
maraeo at gmail.com
Thu Jan 31 09:03:19 PST 2013
On Thu, Jan 31, 2013 at 5:39 PM, Michel Dänzer <michel at daenzer.net> wrote:
> I'm afraid these are not quite correct yet. I'm not 100% sure after
> looking at the red book and the GL 3.x spec — this is head spinning
> material, isn't it? :\ — but I think swapBytes only applies to the basic
> type, in these cases GL_BYTE, so it's irrelevant. However, because the
> Mesa formats are defined as 16 bit packed values in host byte order,
> these cases can only match directly on little endian hosts, i.e. if
> (type == GL_BYTE && littleEndian).
I don't really know. This is the first time I have to worry about endiannes.
I discarded the modifications where we are unsure. The updated patch is here:
- swapBytes has no effect on 8-bit single-component formats
- GL_SHORT is in host byte order, so checking for littleEndian is unnecessary,
I decided to make the change for single-component formats only
Based on suggestions from Michel Dänzer.
---
src/mesa/main/formats.c | 42 +++++++++++++++++-------------------------
1 file changed, 17 insertions(+), 25 deletions(-)
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 4598d65..68ce984 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -3006,19 +3006,16 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
case MESA_FORMAT_A8:
return format == GL_ALPHA && type == GL_UNSIGNED_BYTE;
case MESA_FORMAT_A16:
- return format == GL_ALPHA && type == GL_UNSIGNED_SHORT &&
- littleEndian && !swapBytes;
+ return format == GL_ALPHA && type == GL_UNSIGNED_SHORT && !swapBytes;
case MESA_FORMAT_L8:
case MESA_FORMAT_SL8:
return format == GL_LUMINANCE && type == GL_UNSIGNED_BYTE;
case MESA_FORMAT_L16:
- return format == GL_LUMINANCE && type == GL_UNSIGNED_SHORT &&
- littleEndian && !swapBytes;
+ return format == GL_LUMINANCE && type == GL_UNSIGNED_SHORT && !swapBytes;
case MESA_FORMAT_I8:
return format == GL_INTENSITY && type == GL_UNSIGNED_BYTE;
case MESA_FORMAT_I16:
- return format == GL_INTENSITY && type == GL_UNSIGNED_SHORT &&
- littleEndian && !swapBytes;
+ return format == GL_INTENSITY && type == GL_UNSIGNED_SHORT && !swapBytes;
case MESA_FORMAT_YCBCR:
return format == GL_YCBCR_MESA &&
@@ -3037,7 +3034,7 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
return GL_FALSE;
case MESA_FORMAT_R16:
- return format == GL_RED && type == GL_UNSIGNED_SHORT && littleEndian &&
+ return format == GL_RED && type == GL_UNSIGNED_SHORT &&
!swapBytes;
case MESA_FORMAT_GR1616:
return format == GL_RG && type == GL_UNSIGNED_SHORT && littleEndian &&
@@ -3125,8 +3122,7 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
return format == GL_RG && type == GL_HALF_FLOAT && !swapBytes;
case MESA_FORMAT_ALPHA_UINT8:
- return format == GL_ALPHA_INTEGER && type == GL_UNSIGNED_BYTE &&
- !swapBytes;
+ return format == GL_ALPHA_INTEGER && type == GL_UNSIGNED_BYTE;
case MESA_FORMAT_ALPHA_UINT16:
return format == GL_ALPHA_INTEGER && type == GL_UNSIGNED_SHORT &&
!swapBytes;
@@ -3134,7 +3130,7 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
return format == GL_ALPHA_INTEGER && type == GL_UNSIGNED_INT &&
!swapBytes;
case MESA_FORMAT_ALPHA_INT8:
- return format == GL_ALPHA_INTEGER && type == GL_BYTE && !swapBytes;
+ return format == GL_ALPHA_INTEGER && type == GL_BYTE;
case MESA_FORMAT_ALPHA_INT16:
return format == GL_ALPHA_INTEGER && type == GL_SHORT && !swapBytes;
case MESA_FORMAT_ALPHA_INT32:
@@ -3150,8 +3146,7 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
return GL_FALSE;
case MESA_FORMAT_LUMINANCE_UINT8:
- return format == GL_LUMINANCE_INTEGER_EXT && type == GL_UNSIGNED_BYTE &&
- !swapBytes;
+ return format == GL_LUMINANCE_INTEGER_EXT && type == GL_UNSIGNED_BYTE;
case MESA_FORMAT_LUMINANCE_UINT16:
return format == GL_LUMINANCE_INTEGER_EXT && type == GL_UNSIGNED_SHORT &&
!swapBytes;
@@ -3159,8 +3154,7 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
return format == GL_LUMINANCE_INTEGER_EXT && type == GL_UNSIGNED_INT &&
!swapBytes;
case MESA_FORMAT_LUMINANCE_INT8:
- return format == GL_LUMINANCE_INTEGER_EXT && type == GL_BYTE &&
- !swapBytes;
+ return format == GL_LUMINANCE_INTEGER_EXT && type == GL_BYTE;
case MESA_FORMAT_LUMINANCE_INT16:
return format == GL_LUMINANCE_INTEGER_EXT && type == GL_SHORT &&
!swapBytes;
@@ -3187,7 +3181,7 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
!swapBytes;
case MESA_FORMAT_R_INT8:
- return format == GL_RED_INTEGER && type == GL_BYTE && !swapBytes;
+ return format == GL_RED_INTEGER && type == GL_BYTE;
case MESA_FORMAT_RG_INT8:
return format == GL_RG_INTEGER && type == GL_BYTE && !swapBytes;
case MESA_FORMAT_RGB_INT8:
@@ -3212,7 +3206,7 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
return format == GL_RGBA_INTEGER && type == GL_INT && !swapBytes;
case MESA_FORMAT_R_UINT8:
- return format == GL_RED_INTEGER && type == GL_UNSIGNED_BYTE && !swapBytes;
+ return format == GL_RED_INTEGER && type == GL_UNSIGNED_BYTE;
case MESA_FORMAT_RG_UINT8:
return format == GL_RG_INTEGER && type == GL_UNSIGNED_BYTE && !swapBytes;
case MESA_FORMAT_RGB_UINT8:
@@ -3245,7 +3239,7 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
type == GL_BYTE && littleEndian && !swapBytes;
case MESA_FORMAT_SIGNED_R8:
- return format == GL_RED && type == GL_BYTE && !swapBytes;
+ return format == GL_RED && type == GL_BYTE;
case MESA_FORMAT_SIGNED_RG88_REV:
return format == GL_RG && type == GL_BYTE && littleEndian &&
!swapBytes;
@@ -3271,7 +3265,7 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
return GL_FALSE;
case MESA_FORMAT_SIGNED_R16:
- return format == GL_RED && type == GL_SHORT && littleEndian &&
+ return format == GL_RED && type == GL_SHORT &&
!swapBytes;
case MESA_FORMAT_SIGNED_GR1616:
return format == GL_RG && type == GL_SHORT && littleEndian && !swapBytes;
@@ -3309,20 +3303,18 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
return GL_FALSE;
case MESA_FORMAT_SIGNED_A8:
- return format == GL_ALPHA && type == GL_BYTE && !swapBytes;
+ return format == GL_ALPHA && type == GL_BYTE;
case MESA_FORMAT_SIGNED_L8:
- return format == GL_LUMINANCE && type == GL_BYTE && !swapBytes;
+ return format == GL_LUMINANCE && type == GL_BYTE;
case MESA_FORMAT_SIGNED_AL88:
return format == GL_LUMINANCE_ALPHA && type == GL_BYTE &&
littleEndian && !swapBytes;
case MESA_FORMAT_SIGNED_I8:
- return format == GL_INTENSITY && type == GL_BYTE && !swapBytes;
+ return format == GL_INTENSITY && type == GL_BYTE;
case MESA_FORMAT_SIGNED_A16:
- return format == GL_ALPHA && type == GL_SHORT && littleEndian &&
- !swapBytes;
+ return format == GL_ALPHA && type == GL_SHORT && !swapBytes;
case MESA_FORMAT_SIGNED_L16:
- return format == GL_LUMINANCE && type == GL_SHORT && littleEndian &&
- !swapBytes;
+ return format == GL_LUMINANCE && type == GL_SHORT && !swapBytes;
case MESA_FORMAT_SIGNED_AL1616:
return format == GL_LUMINANCE_ALPHA && type == GL_SHORT &&
littleEndian && !swapBytes;
--
1.7.10.4
More information about the mesa-dev
mailing list