mirror of
https://github.com/dhewm/dhewm3.git
synced 2024-11-23 12:53:09 +00:00
Fix and cleanup endianess defines
Use various defines set by the compiler to determine the endianess of the target arch.
This commit is contained in:
parent
04832863e8
commit
5ee2e5b564
2 changed files with 38 additions and 12 deletions
|
@ -152,12 +152,12 @@ dword PackColor( const idVec4 &color ) {
|
|||
dz = ColorFloatToByte( color.z );
|
||||
dw = ColorFloatToByte( color.w );
|
||||
|
||||
#if defined(_WIN32) || defined(__linux__) || (defined(MACOS_X) && defined(__i386__))
|
||||
#if defined(ID_LITTLE_ENDIAN)
|
||||
return ( dx << 0 ) | ( dy << 8 ) | ( dz << 16 ) | ( dw << 24 );
|
||||
#elif (defined(MACOS_X) && defined(__ppc__))
|
||||
#elif defined(ID_BIG_ENDIAN)
|
||||
return ( dx << 24 ) | ( dy << 16 ) | ( dz << 8 ) | ( dw << 0 );
|
||||
#else
|
||||
#error OS define is required!
|
||||
#error unknown endianness!
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -167,18 +167,18 @@ UnpackColor
|
|||
================
|
||||
*/
|
||||
void UnpackColor( const dword color, idVec4 &unpackedColor ) {
|
||||
#if defined(_WIN32) || defined(__linux__) || (defined(MACOS_X) && defined(__i386__))
|
||||
#if defined(ID_LITTLE_ENDIAN)
|
||||
unpackedColor.Set( ( ( color >> 0 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||
( ( color >> 8 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||
( ( color >> 16 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||
( ( color >> 24 ) & 255 ) * ( 1.0f / 255.0f ) );
|
||||
#elif (defined(MACOS_X) && defined(__ppc__))
|
||||
#elif defined(ID_BIG_ENDIAN)
|
||||
unpackedColor.Set( ( ( color >> 24 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||
( ( color >> 16 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||
( ( color >> 8 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||
( ( color >> 0 ) & 255 ) * ( 1.0f / 255.0f ) );
|
||||
#else
|
||||
#error OS define is required!
|
||||
#error unknown endianness!
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -194,12 +194,12 @@ dword PackColor( const idVec3 &color ) {
|
|||
dy = ColorFloatToByte( color.y );
|
||||
dz = ColorFloatToByte( color.z );
|
||||
|
||||
#if defined(_WIN32) || defined(__linux__) || (defined(MACOS_X) && defined(__i386__))
|
||||
#if defined(ID_LITTLE_ENDIAN)
|
||||
return ( dx << 0 ) | ( dy << 8 ) | ( dz << 16 );
|
||||
#elif (defined(MACOS_X) && defined(__ppc__))
|
||||
#elif defined(ID_BIG_ENDIAN)
|
||||
return ( dy << 16 ) | ( dz << 8 ) | ( dx << 0 );
|
||||
#else
|
||||
#error OS define is required!
|
||||
#error unknown endianness!
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -209,16 +209,16 @@ UnpackColor
|
|||
================
|
||||
*/
|
||||
void UnpackColor( const dword color, idVec3 &unpackedColor ) {
|
||||
#if defined(_WIN32) || defined(__linux__) || (defined(MACOS_X) && defined(__i386__))
|
||||
#if defined(ID_LITTLE_ENDIAN)
|
||||
unpackedColor.Set( ( ( color >> 0 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||
( ( color >> 8 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||
( ( color >> 16 ) & 255 ) * ( 1.0f / 255.0f ) );
|
||||
#elif (defined(MACOS_X) && defined(__ppc__))
|
||||
#elif defined(ID_BIG_ENDIAN)
|
||||
unpackedColor.Set( ( ( color >> 16 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||
( ( color >> 8 ) & 255 ) * ( 1.0f / 255.0f ),
|
||||
( ( color >> 0 ) & 255 ) * ( 1.0f / 255.0f ) );
|
||||
#else
|
||||
#error OS define is required!
|
||||
#error unknown endianness!
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -61,8 +61,13 @@ If you have questions concerning this license or the applicable additional terms
|
|||
|
||||
#define THREAD_RETURN_TYPE dword
|
||||
|
||||
#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
|
||||
#define ID_LITTLE_ENDIAN 1
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Mac OSX
|
||||
#if defined(MACOS_X) || defined(__APPLE__)
|
||||
|
||||
|
@ -159,6 +164,27 @@ If you have questions concerning this license or the applicable additional terms
|
|||
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(ID_LITTLE_ENDIAN) && !defined(ID_BIG_ENDIAN)
|
||||
#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__)
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
#define ID_LITTLE_ENDIAN
|
||||
#endif
|
||||
#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__)
|
||||
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
#define ID_BIG_ENDIAN
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(ID_LITTLE_ENDIAN) && !defined(ID_BIG_ENDIAN)
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
#define ID_LITTLE_ENDIAN 1
|
||||
#elif defined(__ppc__)
|
||||
#define ID_BIG_ENDIAN 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define id_attribute(x) __attribute__(x)
|
||||
#else
|
||||
|
|
Loading…
Reference in a new issue