From b7eebb5df5b3ab1fd95dbea2eda5561cd1aac673 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 11 Jun 2003 01:19:02 +0000 Subject: [PATCH] Add some code to try to fix texture masks on big endian machines. --- stepmania/src/RageDisplay_OGL.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/stepmania/src/RageDisplay_OGL.cpp b/stepmania/src/RageDisplay_OGL.cpp index 9a4302d3e1..6657b03acc 100644 --- a/stepmania/src/RageDisplay_OGL.cpp +++ b/stepmania/src/RageDisplay_OGL.cpp @@ -57,6 +57,7 @@ namespace GLExt { #include "GameConstantsAndTypes.h" #include "StepMania.h" #include "RageUtil.h" +#include "SDL_endian.h" #include "arch/arch.h" #include "arch/LowLevelWindow/LowLevelWindow.h" @@ -95,7 +96,7 @@ const GLenum RageVertexFormat = GL_T2F_C4F_N3F_V3F; LowLevelWindow *wind; -static const PixelFormatDesc PIXEL_FORMAT_DESC[NUM_PIX_FORMATS] = { +static PixelFormatDesc PIXEL_FORMAT_DESC[NUM_PIX_FORMATS] = { { /* B8G8R8A8 */ 32, @@ -180,6 +181,28 @@ struct GLPixFmtInfo_t { }; +static void FixBigEndian() +{ +#if SDL_BYTEORDER != SDL_LIL_ENDIAN + static bool Initialized = false; + if( Initialized ) + return; + Initialized = true; + + for( int i = 0; i < NUM_PIX_FORMATS; ++i ) + { + PixelFormatDesc &pf = PIXEL_FORMAT_DESC[i]; + + /* Byte formats aren't affected by endianness. */ + if( GL_PIXFMT_INFO[i].type == GL_UNSIGNED_BYTE ) + continue; + + for( int mask = 0; mask < 4; ++mask) + pf.masks[mask] = SDL_Swap32( pf.masks[mask] ); + } +#endif +} + void GetGLExtensions(set &ext) { @@ -197,6 +220,8 @@ RageDisplay_OGL::RageDisplay_OGL( VideoModeParams p ) LOG->Trace( "RageDisplay_OGL::RageDisplay_OGL()" ); LOG->MapLog("renderer", "Current renderer: OpenGL"); + FixBigEndian(); + wind = MakeLowLevelWindow(); SetVideoMode( p );