Clean up endianness mess.
This commit is contained in:
@@ -100,37 +100,37 @@ static PixelFormatDesc PIXEL_FORMAT_DESC[NUM_PIX_FORMATS] = {
|
|||||||
{
|
{
|
||||||
/* B8G8R8A8 */
|
/* B8G8R8A8 */
|
||||||
32,
|
32,
|
||||||
{ 0x000000FF,
|
{ 0xFF000000,
|
||||||
0x0000FF00,
|
|
||||||
0x00FF0000,
|
0x00FF0000,
|
||||||
0xFF000000 }
|
0x0000FF00,
|
||||||
|
0x000000FF }
|
||||||
}, {
|
}, {
|
||||||
/* B4G4R4A4 */
|
/* R4G4B4A4 */
|
||||||
16,
|
16,
|
||||||
{ 0xF000,
|
{ 0xF000,
|
||||||
0x0F00,
|
0x0F00,
|
||||||
0x00F0,
|
0x00F0,
|
||||||
0x000F },
|
0x000F },
|
||||||
}, {
|
}, {
|
||||||
/* B5G5R5A1 */
|
/* R5G5B5A1 */
|
||||||
16,
|
16,
|
||||||
{ 0xF800,
|
{ 0xF800,
|
||||||
0x07C0,
|
0x07C0,
|
||||||
0x003E,
|
0x003E,
|
||||||
0x0001 },
|
0x0001 },
|
||||||
}, {
|
}, {
|
||||||
/* B5G5R5 */
|
/* R5G5B5 */
|
||||||
16,
|
16,
|
||||||
{ 0xF800,
|
{ 0xF800,
|
||||||
0x07C0,
|
0x07C0,
|
||||||
0x003E,
|
0x003E,
|
||||||
0x0000 },
|
0x0000 },
|
||||||
}, {
|
}, {
|
||||||
/* B8G8R8 */
|
/* R8G8B8 */
|
||||||
24,
|
24,
|
||||||
{ 0x0000FF,
|
{ 0xFF0000,
|
||||||
0x00FF00,
|
0x00FF00,
|
||||||
0xFF0000,
|
0x0000FF,
|
||||||
0x000000 }
|
0x000000 }
|
||||||
}, {
|
}, {
|
||||||
/* Paletted */
|
/* Paletted */
|
||||||
@@ -180,10 +180,11 @@ struct GLPixFmtInfo_t {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Uint32 mySDL_Swap24(Uint32 x);
|
||||||
|
|
||||||
static void FixBigEndian()
|
static void FixLilEndian()
|
||||||
{
|
{
|
||||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||||
static bool Initialized = false;
|
static bool Initialized = false;
|
||||||
if( Initialized )
|
if( Initialized )
|
||||||
return;
|
return;
|
||||||
@@ -193,8 +194,9 @@ static void FixBigEndian()
|
|||||||
{
|
{
|
||||||
PixelFormatDesc &pf = PIXEL_FORMAT_DESC[i];
|
PixelFormatDesc &pf = PIXEL_FORMAT_DESC[i];
|
||||||
|
|
||||||
/* Byte formats aren't affected by endianness. */
|
/* OpenGL and SDL handle byte formats differently; we need
|
||||||
if( GL_PIXFMT_INFO[i].type == GL_UNSIGNED_BYTE )
|
* to flip non-paletted masks to make them line up. */
|
||||||
|
if( GL_PIXFMT_INFO[i].type != GL_UNSIGNED_BYTE || pf.bpp == 8 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for( int mask = 0; mask < 4; ++mask)
|
for( int mask = 0; mask < 4; ++mask)
|
||||||
@@ -202,8 +204,9 @@ static void FixBigEndian()
|
|||||||
int m = pf.masks[mask];
|
int m = pf.masks[mask];
|
||||||
switch( pf.bpp )
|
switch( pf.bpp )
|
||||||
{
|
{
|
||||||
case 16: m = SDL_Swap16(m); break;
|
case 24: m = mySDL_Swap24(m); break;
|
||||||
case 32: m = SDL_Swap32(m); break;
|
case 32: m = SDL_Swap32(m); break;
|
||||||
|
default: ASSERT(0);
|
||||||
}
|
}
|
||||||
pf.masks[mask] = m;
|
pf.masks[mask] = m;
|
||||||
}
|
}
|
||||||
@@ -237,7 +240,7 @@ RageDisplay_OGL::RageDisplay_OGL( VideoModeParams p, bool bAllowUnacceleratedRen
|
|||||||
LOG->Trace( "RageDisplay_OGL::RageDisplay_OGL()" );
|
LOG->Trace( "RageDisplay_OGL::RageDisplay_OGL()" );
|
||||||
LOG->MapLog("renderer", "Current renderer: OpenGL");
|
LOG->MapLog("renderer", "Current renderer: OpenGL");
|
||||||
|
|
||||||
FixBigEndian();
|
FixLilEndian();
|
||||||
|
|
||||||
wind = MakeLowLevelWindow();
|
wind = MakeLowLevelWindow();
|
||||||
|
|
||||||
@@ -1040,7 +1043,6 @@ void RageDisplay_OGL::UpdateTexture(
|
|||||||
glImageFormat, glImageType, img->pixels);
|
glImageFormat, glImageType, img->pixels);
|
||||||
|
|
||||||
/* Must unset PixelStore when we're done! */
|
/* Must unset PixelStore when we're done! */
|
||||||
glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
|
|
||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||||
glFlush();
|
glFlush();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,12 +32,6 @@ Uint32 mySDL_Swap24(Uint32 x)
|
|||||||
return SDL_Swap32(x) >> 8; // xx223344 -> 443322xx -> 00443322
|
return SDL_Swap32(x) >> 8; // xx223344 -> 443322xx -> 00443322
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
|
||||||
#define mySDL_SwapLE24(x) mySDL_Swap24(x)
|
|
||||||
#else
|
|
||||||
#define mySDL_SwapLE24(x) (x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* These conditionals in the inner loop are slow. Templates? */
|
/* These conditionals in the inner loop are slow. Templates? */
|
||||||
inline Uint32 decodepixel(const Uint8 *p, int bpp)
|
inline Uint32 decodepixel(const Uint8 *p, int bpp)
|
||||||
{
|
{
|
||||||
@@ -257,36 +251,13 @@ void ConvertSDLSurface(SDL_Surface *&image,
|
|||||||
image = ret_image;
|
image = ret_image;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* With d3d, textures are stored little endian (local endian for x86).
|
|
||||||
*
|
|
||||||
* I'm not sure if we should store textures in big endian, little endian
|
|
||||||
* or local endian with OpenGL. It doesn't really impact anything except
|
|
||||||
* the actual code that loads the texture itself, and OpenGL does have
|
|
||||||
* byte order toggles, so maybe we can get rid of this. */
|
|
||||||
SDL_Surface *SDL_CreateRGBSurfaceSane
|
SDL_Surface *SDL_CreateRGBSurfaceSane
|
||||||
(Uint32 flags, int width, int height, int depth,
|
(Uint32 flags, int width, int height, int depth,
|
||||||
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
|
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
|
||||||
{
|
{
|
||||||
/* This is untested on big-endian machines. */
|
|
||||||
if(depth == 16) {
|
|
||||||
Rmask = SDL_SwapLE16((Uint16)Rmask);
|
|
||||||
Gmask = SDL_SwapLE16((Uint16)Gmask);
|
|
||||||
Bmask = SDL_SwapLE16((Uint16)Bmask);
|
|
||||||
Amask = SDL_SwapLE16((Uint16)Amask);
|
|
||||||
} else if(depth == 24) { // completely untested
|
|
||||||
Rmask = mySDL_SwapLE24(Rmask);
|
|
||||||
Gmask = mySDL_SwapLE24(Gmask);
|
|
||||||
Bmask = mySDL_SwapLE24(Bmask);
|
|
||||||
Amask = mySDL_SwapLE24(Amask);
|
|
||||||
} else if(depth == 32) {
|
|
||||||
Rmask = SDL_SwapLE32(Rmask);
|
|
||||||
Gmask = SDL_SwapLE32(Gmask);
|
|
||||||
Bmask = SDL_SwapLE32(Bmask);
|
|
||||||
Amask = SDL_SwapLE32(Amask);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Surface *ret = SDL_CreateRGBSurface(flags, width, height, depth,
|
SDL_Surface *ret = SDL_CreateRGBSurface(flags, width, height, depth,
|
||||||
Rmask, Gmask, Bmask, Amask);
|
Rmask, Gmask, Bmask, Amask);
|
||||||
|
|
||||||
if(ret == NULL)
|
if(ret == NULL)
|
||||||
RageException::Throw("SDL_CreateRGBSurface(%i, %i, %i, %i, %8x, %8x, %8x, %8x) failed: %s",
|
RageException::Throw("SDL_CreateRGBSurface(%i, %i, %i, %i, %8x, %8x, %8x, %8x) failed: %s",
|
||||||
flags, width, height, depth, Rmask, Gmask, Bmask, Amask, SDL_GetError());
|
flags, width, height, depth, Rmask, Gmask, Bmask, Amask, SDL_GetError());
|
||||||
|
|||||||
Reference in New Issue
Block a user