general minor cosmetics

This commit is contained in:
Glenn Maynard
2005-11-13 18:22:52 +00:00
parent 7580e3d9bf
commit fec044a796
+105 -100
View File
@@ -85,7 +85,7 @@ const GLenum RageSpriteVertexFormat = GL_T2F_C4F_N3F_V3F;
/* If we support texture matrix scaling, a handle to the vertex program: */ /* If we support texture matrix scaling, a handle to the vertex program: */
static GLhandleARB g_bTextureMatrixShader = 0; static GLhandleARB g_bTextureMatrixShader = 0;
LowLevelWindow *wind; static LowLevelWindow *g_pWind;
static void InvalidateAllGeometry(); static void InvalidateAllGeometry();
@@ -232,10 +232,10 @@ struct GLPixFmtInfo_t {
static void FixLittleEndian() static void FixLittleEndian()
{ {
#if defined(ENDIAN_LITTLE) #if defined(ENDIAN_LITTLE)
static bool Initialized = false; static bool bInitialized = false;
if( Initialized ) if( bInitialized )
return; return;
Initialized = true; bInitialized = true;
for( int i = 0; i < NUM_PixelFormat; ++i ) for( int i = 0; i < NUM_PixelFormat; ++i )
{ {
@@ -326,7 +326,7 @@ RageDisplay_OGL::RageDisplay_OGL()
FixLittleEndian(); FixLittleEndian();
InitStringMap(); InitStringMap();
wind = NULL; g_pWind = NULL;
g_bTextureMatrixShader = 0; g_bTextureMatrixShader = 0;
} }
@@ -424,7 +424,7 @@ void InitScalingScript()
CString RageDisplay_OGL::Init( VideoModeParams p, bool bAllowUnacceleratedRenderer ) CString RageDisplay_OGL::Init( VideoModeParams p, bool bAllowUnacceleratedRenderer )
{ {
wind = MakeLowLevelWindow(); g_pWind = MakeLowLevelWindow();
bool bIgnore = false; bool bIgnore = false;
CString sError = SetVideoMode( p, bIgnore ); CString sError = SetVideoMode( p, bIgnore );
@@ -498,29 +498,29 @@ bool RageDisplay_OGL::IsSoftwareRenderer()
RageDisplay_OGL::~RageDisplay_OGL() RageDisplay_OGL::~RageDisplay_OGL()
{ {
delete wind; delete g_pWind;
} }
static void CheckPalettedTextures() static void CheckPalettedTextures()
{ {
CString error; CString sError;
do do
{ {
if( !GLExt.HasExtension("GL_EXT_paletted_texture") ) if( !GLExt.HasExtension("GL_EXT_paletted_texture") )
{ {
error = "GL_EXT_paletted_texture missing"; sError = "GL_EXT_paletted_texture missing";
break; break;
} }
if( GLExt.glColorTableEXT == NULL ) if( GLExt.glColorTableEXT == NULL )
{ {
error = "glColorTableEXT missing"; sError = "glColorTableEXT missing";
break; break;
} }
if( GLExt.glGetColorTableParameterivEXT == NULL ) if( GLExt.glGetColorTableParameterivEXT == NULL )
{ {
error = "glGetColorTableParameterivEXT missing"; sError = "glGetColorTableParameterivEXT missing";
break; break;
} }
@@ -529,14 +529,14 @@ static void CheckPalettedTextures()
GLenum glImageFormat = g_GLPixFmtInfo[PixelFormat_PAL].format; GLenum glImageFormat = g_GLPixFmtInfo[PixelFormat_PAL].format;
GLenum glImageType = g_GLPixFmtInfo[PixelFormat_PAL].type; GLenum glImageType = g_GLPixFmtInfo[PixelFormat_PAL].type;
int bits = 8; int iBits = 8;
FlushGLErrors(); FlushGLErrors();
#define GL_CHECK_ERROR(f) \ #define GL_CHECK_ERROR(f) \
{ \ { \
GLenum glError = glGetError(); \ GLenum glError = glGetError(); \
if( glError != GL_NO_ERROR ) { \ if( glError != GL_NO_ERROR ) { \
error = ssprintf(f " failed (%s)", GLToString(glError).c_str() ); \ sError = ssprintf(f " failed (%s)", GLToString(glError).c_str() ); \
break; \ break; \
} \ } \
} }
@@ -547,14 +547,13 @@ static void CheckPalettedTextures()
glImageFormat, glImageType, NULL ); glImageFormat, glImageType, NULL );
GL_CHECK_ERROR( "glTexImage2D" ); GL_CHECK_ERROR( "glTexImage2D" );
GLuint ifmt = 0; GLuint iFormat = 0;
glGetTexLevelParameteriv( GL_PROXY_TEXTURE_2D, 0, GLenum(GL_TEXTURE_INTERNAL_FORMAT), (GLint *)&ifmt ); glGetTexLevelParameteriv( GL_PROXY_TEXTURE_2D, 0, GLenum(GL_TEXTURE_INTERNAL_FORMAT), (GLint *) &iFormat );
GL_CHECK_ERROR( "glGetTexLevelParameteriv(GL_TEXTURE_INTERNAL_FORMAT)" ); GL_CHECK_ERROR( "glGetTexLevelParameteriv(GL_TEXTURE_INTERNAL_FORMAT)" );
if( ifmt != glTexFormat ) if( iFormat != glTexFormat )
{ {
error = ssprintf( "Expected format %s, got %s instead", sError = ssprintf( "Expected format %s, got %s instead",
GLToString(glTexFormat).c_str(), GLToString(glTexFormat).c_str(), GLToString(iFormat).c_str() );
GLToString(ifmt).c_str() );
break; break;
} }
@@ -563,43 +562,43 @@ static void CheckPalettedTextures()
GLExt.glColorTableEXT(GL_PROXY_TEXTURE_2D, GL_RGBA8, 256, GL_RGBA, GL_UNSIGNED_BYTE, palette); GLExt.glColorTableEXT(GL_PROXY_TEXTURE_2D, GL_RGBA8, 256, GL_RGBA, GL_UNSIGNED_BYTE, palette);
GL_CHECK_ERROR( "glColorTableEXT" ); GL_CHECK_ERROR( "glColorTableEXT" );
GLint size = 0; GLint iSize = 0;
glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GLenum(GL_TEXTURE_INDEX_SIZE_EXT), &size); glGetTexLevelParameteriv( GL_PROXY_TEXTURE_2D, 0, GLenum(GL_TEXTURE_INDEX_SIZE_EXT), &iSize );
GL_CHECK_ERROR( "glGetTexLevelParameteriv(GL_TEXTURE_INDEX_SIZE_EXT)" ); GL_CHECK_ERROR( "glGetTexLevelParameteriv(GL_TEXTURE_INDEX_SIZE_EXT)" );
if( bits > size || size > 8 ) if( iBits > iSize || iSize > 8 )
{ {
error = ssprintf("Expected %i-bit palette, got a %i-bit one instead", bits, int(size)); sError = ssprintf( "Expected %i-bit palette, got a %i-bit one instead", iBits, int(iSize) );
break; break;
} }
GLint RealWidth = 0; GLint iRealWidth = 0;
GLExt.glGetColorTableParameterivEXT(GL_PROXY_TEXTURE_2D, GL_COLOR_TABLE_WIDTH, &RealWidth); GLExt.glGetColorTableParameterivEXT( GL_PROXY_TEXTURE_2D, GL_COLOR_TABLE_WIDTH, &iRealWidth );
GL_CHECK_ERROR( "glGetColorTableParameterivEXT(GL_COLOR_TABLE_WIDTH)" ); GL_CHECK_ERROR( "glGetColorTableParameterivEXT(GL_COLOR_TABLE_WIDTH)" );
if( RealWidth != 1 << bits ) if( iRealWidth != 1 << iBits )
{ {
error = ssprintf("GL_COLOR_TABLE_WIDTH returned %i instead of %i", int(RealWidth), 1 << bits ); sError = ssprintf( "GL_COLOR_TABLE_WIDTH returned %i instead of %i", int(iRealWidth), 1 << iBits );
break; break;
} }
GLint RealFormat = 0; GLint iRealFormat = 0;
GLExt.glGetColorTableParameterivEXT(GL_PROXY_TEXTURE_2D, GL_COLOR_TABLE_FORMAT, &RealFormat); GLExt.glGetColorTableParameterivEXT( GL_PROXY_TEXTURE_2D, GL_COLOR_TABLE_FORMAT, &iRealFormat );
GL_CHECK_ERROR( "glGetColorTableParameterivEXT(GL_COLOR_TABLE_FORMAT)" ); GL_CHECK_ERROR( "glGetColorTableParameterivEXT(GL_COLOR_TABLE_FORMAT)" );
if( RealFormat != GL_RGBA8 ) if( iRealFormat != GL_RGBA8 )
{ {
error = ssprintf("GL_COLOR_TABLE_FORMAT returned %s instead of GL_RGBA8", GLToString(RealFormat).c_str() ); sError = ssprintf( "GL_COLOR_TABLE_FORMAT returned %s instead of GL_RGBA8", GLToString(iRealFormat).c_str() );
break; break;
} }
} while(0); } while(0);
#undef GL_CHECK_ERROR #undef GL_CHECK_ERROR
if( error == "" ) if( sError == "" )
return; return;
/* If 8-bit palettes don't work, disable them entirely--don't trust 4-bit /* If 8-bit palettes don't work, disable them entirely--don't trust 4-bit
* palettes if it can't even get 8-bit ones right. */ * palettes if it can't even get 8-bit ones right. */
GLExt.glColorTableEXT = NULL; GLExt.glColorTableEXT = NULL;
GLExt.glGetColorTableParameterivEXT = NULL; GLExt.glGetColorTableParameterivEXT = NULL;
LOG->Info("Paletted textures disabled: %s.", error.c_str()); LOG->Info( "Paletted textures disabled: %s.", sError.c_str() );
} }
static void CheckReversePackedPixels() static void CheckReversePackedPixels()
@@ -613,7 +612,9 @@ static void CheckReversePackedPixels()
const GLenum glError = glGetError(); const GLenum glError = glGetError();
if( glError == GL_NO_ERROR ) if( glError == GL_NO_ERROR )
{
g_bReversePackedPixelsWorks = true; g_bReversePackedPixelsWorks = true;
}
else else
{ {
g_bReversePackedPixelsWorks = false; g_bReversePackedPixelsWorks = false;
@@ -630,7 +631,7 @@ void SetupExtensions()
const float fGLUVersion = strtof( (const char *) gluGetString(GLU_VERSION), NULL ); const float fGLUVersion = strtof( (const char *) gluGetString(GLU_VERSION), NULL );
g_gluVersion = int(roundf(fGLUVersion * 10)); g_gluVersion = int(roundf(fGLUVersion * 10));
GLExt.Load( wind ); GLExt.Load( g_pWind );
g_iMaxTextureUnits = 1; g_iMaxTextureUnits = 1;
if( GLExt.glActiveTextureARB != NULL ) if( GLExt.glActiveTextureARB != NULL )
@@ -651,9 +652,11 @@ void SetupExtensions()
g_bColorIndexTableWorks = false; g_bColorIndexTableWorks = false;
} }
else else
{
g_bColorIndexTableWorks = true; g_bColorIndexTableWorks = true;
} }
} }
}
void RageDisplay_OGL::ResolutionChanged() void RageDisplay_OGL::ResolutionChanged()
{ {
@@ -671,7 +674,7 @@ CString RageDisplay_OGL::TryVideoMode( VideoModeParams p, bool &bNewDeviceOut )
{ {
// LOG->Trace( "RageDisplay_OGL::SetVideoMode( %d, %d, %d, %d, %d, %d )", windowed, width, height, bpp, rate, vsync ); // LOG->Trace( "RageDisplay_OGL::SetVideoMode( %d, %d, %d, %d, %d, %d )", windowed, width, height, bpp, rate, vsync );
CString err; CString err;
err = wind->TryVideoMode( p, bNewDeviceOut ); err = g_pWind->TryVideoMode( p, bNewDeviceOut );
if( err != "" ) if( err != "" )
return err; // failed to set video mode return err; // failed to set video mode
@@ -706,10 +709,10 @@ void RageDisplay_OGL::SetViewport(int shift_left, int shift_down)
{ {
/* left and down are on a 0..SCREEN_WIDTH, 0..SCREEN_HEIGHT scale. /* left and down are on a 0..SCREEN_WIDTH, 0..SCREEN_HEIGHT scale.
* Scale them to the actual viewport range. */ * Scale them to the actual viewport range. */
shift_left = int( shift_left * float(wind->GetActualVideoModeParams().width) / SCREEN_WIDTH ); shift_left = int( shift_left * float(g_pWind->GetActualVideoModeParams().width) / SCREEN_WIDTH );
shift_down = int( shift_down * float(wind->GetActualVideoModeParams().height) / SCREEN_HEIGHT ); shift_down = int( shift_down * float(g_pWind->GetActualVideoModeParams().height) / SCREEN_HEIGHT );
glViewport(shift_left, -shift_down, wind->GetActualVideoModeParams().width, wind->GetActualVideoModeParams().height); glViewport( shift_left, -shift_down, g_pWind->GetActualVideoModeParams().width, g_pWind->GetActualVideoModeParams().height );
} }
int RageDisplay_OGL::GetMaxTextureSize() const int RageDisplay_OGL::GetMaxTextureSize() const
@@ -734,9 +737,9 @@ void RageDisplay_OGL::EndFrame()
// Gog-knows-what. // Gog-knows-what.
glFlush(); glFlush();
wind->SwapBuffers(); g_pWind->SwapBuffers();
wind->Update(); g_pWind->Update();
if( PREFSMAN->m_bDisableScreenSaver ) if( PREFSMAN->m_bDisableScreenSaver )
{ {
@@ -777,8 +780,8 @@ void RageDisplay_OGL::EndFrame()
RageSurface* RageDisplay_OGL::CreateScreenshot() RageSurface* RageDisplay_OGL::CreateScreenshot()
{ {
int width = wind->GetActualVideoModeParams().width; int width = g_pWind->GetActualVideoModeParams().width;
int height = wind->GetActualVideoModeParams().height; int height = g_pWind->GetActualVideoModeParams().height;
const PixelFormatDesc &desc = PIXEL_FORMAT_DESC[PixelFormat_RGBA8]; const PixelFormatDesc &desc = PIXEL_FORMAT_DESC[PixelFormat_RGBA8];
RageSurface *image = CreateSurface( width, height, desc.bpp, RageSurface *image = CreateSurface( width, height, desc.bpp,
@@ -789,7 +792,7 @@ RageSurface* RageDisplay_OGL::CreateScreenshot()
glReadBuffer( GL_FRONT ); glReadBuffer( GL_FRONT );
AssertNoGLError(); AssertNoGLError();
glReadPixels(0, 0, wind->GetActualVideoModeParams().width, wind->GetActualVideoModeParams().height, GL_RGBA, glReadPixels( 0, 0, g_pWind->GetActualVideoModeParams().width, g_pWind->GetActualVideoModeParams().height, GL_RGBA,
GL_UNSIGNED_BYTE, image->pixels ); GL_UNSIGNED_BYTE, image->pixels );
AssertNoGLError(); AssertNoGLError();
@@ -800,7 +803,7 @@ RageSurface* RageDisplay_OGL::CreateScreenshot()
VideoModeParams RageDisplay_OGL::GetActualVideoModeParams() const VideoModeParams RageDisplay_OGL::GetActualVideoModeParams() const
{ {
return wind->GetActualVideoModeParams(); return g_pWind->GetActualVideoModeParams();
} }
static void SetupVertices( const RageSpriteVertex v[], int iNumVerts ) static void SetupVertices( const RageSpriteVertex v[], int iNumVerts )
@@ -1333,14 +1336,14 @@ void RageDisplay_OGL::DrawCompiledGeometryInternal( const RageCompiledGeometry *
p->Draw( iMeshIndex ); p->Draw( iMeshIndex );
} }
void RageDisplay_OGL::DrawLineStripInternal( const RageSpriteVertex v[], int iNumVerts, float LineWidth ) void RageDisplay_OGL::DrawLineStripInternal( const RageSpriteVertex v[], int iNumVerts, float fLineWidth )
{ {
TurnOffHardwareVBO(); TurnOffHardwareVBO();
if( !GetActualVideoModeParams().bSmoothLines ) if( !GetActualVideoModeParams().bSmoothLines )
{ {
/* Fall back on the generic polygon-based line strip. */ /* Fall back on the generic polygon-based line strip. */
RageDisplay::DrawLineStripInternal(v, iNumVerts, LineWidth ); RageDisplay::DrawLineStripInternal(v, iNumVerts, fLineWidth );
return; return;
} }
@@ -1354,20 +1357,20 @@ void RageDisplay_OGL::DrawLineStripInternal( const RageSpriteVertex v[], int iNu
/* Our line width is wrt the regular internal SCREEN_WIDTHxSCREEN_HEIGHT screen, /* Our line width is wrt the regular internal SCREEN_WIDTHxSCREEN_HEIGHT screen,
* but these width functions actually want raster sizes (that is, actual pixels). * but these width functions actually want raster sizes (that is, actual pixels).
* Scale the line width and point size by the average ratio of the scale. */ * Scale the line width and point size by the average ratio of the scale. */
float WidthVal = float(wind->GetActualVideoModeParams().width) / SCREEN_WIDTH; float fWidthVal = float(g_pWind->GetActualVideoModeParams().width) / SCREEN_WIDTH;
float HeightVal = float(wind->GetActualVideoModeParams().height) / SCREEN_HEIGHT; float fHeightVal = float(g_pWind->GetActualVideoModeParams().height) / SCREEN_HEIGHT;
LineWidth *= (WidthVal + HeightVal) / 2; fLineWidth *= (fWidthVal + fHeightVal) / 2;
/* Clamp the width to the hardware max for both lines and points (whichever /* Clamp the width to the hardware max for both lines and points (whichever
* is more restrictive). */ * is more restrictive). */
LineWidth = clamp(LineWidth, g_line_range[0], g_line_range[1]); fLineWidth = clamp( fLineWidth, g_line_range[0], g_line_range[1] );
LineWidth = clamp(LineWidth, g_point_range[0], g_point_range[1]); fLineWidth = clamp( fLineWidth, g_point_range[0], g_point_range[1] );
/* Hmm. The granularity of lines and points might be different; for example, /* Hmm. The granularity of lines and points might be different; for example,
* if lines are .5 and points are .25, we might want to snap the width to the * if lines are .5 and points are .25, we might want to snap the width to the
* nearest .5, so the hardware doesn't snap them to different sizes. Does it * nearest .5, so the hardware doesn't snap them to different sizes. Does it
* matter? */ * matter? */
glLineWidth(LineWidth); glLineWidth( fLineWidth );
/* Draw the line loop: */ /* Draw the line loop: */
SetupVertices( v, iNumVerts ); SetupVertices( v, iNumVerts );
@@ -1378,7 +1381,7 @@ void RageDisplay_OGL::DrawLineStripInternal( const RageSpriteVertex v[], int iNu
/* Round off the corners. This isn't perfect; the point is sometimes a little /* Round off the corners. This isn't perfect; the point is sometimes a little
* larger than the line, causing a small bump on the edge. Not sure how to fix * larger than the line, causing a small bump on the edge. Not sure how to fix
* that. */ * that. */
glPointSize(LineWidth); glPointSize( fLineWidth );
/* Hack: if the points will all be the same, we don't want to draw /* Hack: if the points will all be the same, we don't want to draw
* any points at all, since there's nothing to connect. That'll happen * any points at all, since there's nothing to connect. That'll happen
@@ -1453,6 +1456,7 @@ void RageDisplay_OGL::SetTexture( TextureUnit tu, RageTexture* pTexture )
glDisable( GL_TEXTURE_2D ); glDisable( GL_TEXTURE_2D );
} }
} }
void RageDisplay_OGL::SetTextureModeModulate() void RageDisplay_OGL::SetTextureModeModulate()
{ {
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
@@ -1610,6 +1614,7 @@ void RageDisplay_OGL::SetLightOff( int index )
{ {
glDisable( GL_LIGHT0+index ); glDisable( GL_LIGHT0+index );
} }
void RageDisplay_OGL::SetLightDirectional( void RageDisplay_OGL::SetLightDirectional(
int index, int index,
const RageColor &ambient, const RageColor &ambient,
@@ -1669,7 +1674,7 @@ void RageDisplay_OGL::DeleteTexture( unsigned uTexHandle )
} }
PixelFormat RageDisplay_OGL::GetImgPixelFormat( RageSurface* &img, bool &FreeImg, int width, int height, bool bPalettedTexture ) PixelFormat RageDisplay_OGL::GetImgPixelFormat( RageSurface* &img, bool &bFreeImg, int width, int height, bool bPalettedTexture )
{ {
PixelFormat pixfmt = FindPixelFormat( img->format->BitsPerPixel, img->format->Rmask, img->format->Gmask, img->format->Bmask, img->format->Amask ); PixelFormat pixfmt = FindPixelFormat( img->format->BitsPerPixel, img->format->Rmask, img->format->Gmask, img->format->Bmask, img->format->Amask );
@@ -1697,11 +1702,11 @@ PixelFormat RageDisplay_OGL::GetImgPixelFormat( RageSurface* &img, bool &FreeImg
pfd->bpp, pfd->masks[0], pfd->masks[1], pfd->masks[2], pfd->masks[3] ); pfd->bpp, pfd->masks[0], pfd->masks[1], pfd->masks[2], pfd->masks[3] );
RageSurfaceUtils::Blit( img, imgconv, width, height ); RageSurfaceUtils::Blit( img, imgconv, width, height );
img = imgconv; img = imgconv;
FreeImg = true; bFreeImg = true;
} }
else else
{ {
FreeImg = false; bFreeImg = false;
} }
return pixfmt; return pixfmt;
@@ -1739,16 +1744,16 @@ void SetPixelMapForSurface( int glImageFormat, int glTexFormat, const RageSurfac
unsigned RageDisplay_OGL::CreateTexture( unsigned RageDisplay_OGL::CreateTexture(
PixelFormat pixfmt, PixelFormat pixfmt,
RageSurface* img, RageSurface* pImg,
bool bGenerateMipMaps ) bool bGenerateMipMaps )
{ {
ASSERT( pixfmt < NUM_PixelFormat ); ASSERT( pixfmt < NUM_PixelFormat );
ASSERT( img->w == power_of_two(img->w) && img->h == power_of_two(img->h) ); ASSERT( pImg->w == power_of_two(pImg->w) && pImg->h == power_of_two(pImg->h) );
/* Find the pixel format of the image we've been given. */ /* Find the pixel format of the image we've been given. */
bool FreeImg; bool bFreeImg;
PixelFormat imgpixfmt = GetImgPixelFormat( img, FreeImg, img->w, img->h, pixfmt == PixelFormat_PAL ); PixelFormat imgpixfmt = GetImgPixelFormat( pImg, bFreeImg, pImg->w, pImg->h, pixfmt == PixelFormat_PAL );
ASSERT( imgpixfmt != PixelFormat_INVALID ); ASSERT( imgpixfmt != PixelFormat_INVALID );
GLenum glTexFormat = g_GLPixFmtInfo[pixfmt].internalfmt; GLenum glTexFormat = g_GLPixFmtInfo[pixfmt].internalfmt;
@@ -1757,7 +1762,7 @@ unsigned RageDisplay_OGL::CreateTexture(
/* If the image is paletted, but we're not sending it to a paletted image, /* If the image is paletted, but we're not sending it to a paletted image,
* set up glPixelMap. */ * set up glPixelMap. */
SetPixelMapForSurface( glImageFormat, glTexFormat, img->format->palette ); SetPixelMapForSurface( glImageFormat, glTexFormat, pImg->format->palette );
// HACK: OpenGL 1.2 types aren't available in GLU 1.3. Don't call GLU for mip // HACK: OpenGL 1.2 types aren't available in GLU 1.3. Don't call GLU for mip
// mapping if we're using an OGL 1.2 type and don't have >= GLU 1.3. // mapping if we're using an OGL 1.2 type and don't have >= GLU 1.3.
@@ -1787,31 +1792,31 @@ unsigned RageDisplay_OGL::CreateTexture(
glBindTexture( GL_TEXTURE_2D, uTexHandle ); glBindTexture( GL_TEXTURE_2D, uTexHandle );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
GLint minFilter; GLint iMinFilter;
if( bGenerateMipMaps ) if( bGenerateMipMaps )
{ {
if( wind->GetActualVideoModeParams().bTrilinearFiltering ) if( g_pWind->GetActualVideoModeParams().bTrilinearFiltering )
minFilter = GL_LINEAR_MIPMAP_LINEAR; iMinFilter = GL_LINEAR_MIPMAP_LINEAR;
else else
minFilter = GL_LINEAR_MIPMAP_NEAREST; iMinFilter = GL_LINEAR_MIPMAP_NEAREST;
} }
else else
{ {
minFilter = GL_LINEAR; iMinFilter = GL_LINEAR;
} }
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iMinFilter );
if( wind->GetActualVideoModeParams().bAnisotropicFiltering && if( g_pWind->GetActualVideoModeParams().bAnisotropicFiltering &&
GLExt.HasExtension("GL_EXT_texture_filter_anisotropic") ) GLExt.HasExtension("GL_EXT_texture_filter_anisotropic") )
{ {
GLfloat largest_supported_anisotropy; GLfloat fLargestSupportedAnisotropy;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &largest_supported_anisotropy); glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &fLargestSupportedAnisotropy );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, largest_supported_anisotropy); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, fLargestSupportedAnisotropy );
} }
SetTextureWrapping( false ); SetTextureWrapping( false );
glPixelStorei(GL_UNPACK_ROW_LENGTH, img->pitch / img->format->BytesPerPixel); glPixelStorei( GL_UNPACK_ROW_LENGTH, pImg->pitch / pImg->format->BytesPerPixel );
if( pixfmt == PixelFormat_PAL ) if( pixfmt == PixelFormat_PAL )
@@ -1821,20 +1826,20 @@ unsigned RageDisplay_OGL::CreateTexture(
memset( palette, 0, sizeof(palette) ); memset( palette, 0, sizeof(palette) );
int p = 0; int p = 0;
/* Copy the palette to the format OpenGL expects. */ /* Copy the palette to the format OpenGL expects. */
for(int i = 0; i < img->format->palette->ncolors; ++i) for( int i = 0; i < pImg->format->palette->ncolors; ++i )
{ {
palette[p++] = img->format->palette->colors[i].r; palette[p++] = pImg->format->palette->colors[i].r;
palette[p++] = img->format->palette->colors[i].g; palette[p++] = pImg->format->palette->colors[i].g;
palette[p++] = img->format->palette->colors[i].b; palette[p++] = pImg->format->palette->colors[i].b;
palette[p++] = img->format->palette->colors[i].a; palette[p++] = pImg->format->palette->colors[i].a;
} }
/* Set the palette. */ /* Set the palette. */
GLExt.glColorTableEXT( GL_TEXTURE_2D, GL_RGBA8, 256, GL_RGBA, GL_UNSIGNED_BYTE, palette ); GLExt.glColorTableEXT( GL_TEXTURE_2D, GL_RGBA8, 256, GL_RGBA, GL_UNSIGNED_BYTE, palette );
GLint RealFormat = 0; GLint iRealFormat = 0;
GLExt.glGetColorTableParameterivEXT(GL_TEXTURE_2D, GL_COLOR_TABLE_FORMAT, &RealFormat); GLExt.glGetColorTableParameterivEXT( GL_TEXTURE_2D, GL_COLOR_TABLE_FORMAT, &iRealFormat );
ASSERT( RealFormat == GL_RGBA8); /* This is a case I don't expect to happen. */ ASSERT( iRealFormat == GL_RGBA8 );
} }
@@ -1844,7 +1849,7 @@ unsigned RageDisplay_OGL::CreateTexture(
s << (bGenerateMipMaps? "gluBuild2DMipmaps":"glTexImage2D"); s << (bGenerateMipMaps? "gluBuild2DMipmaps":"glTexImage2D");
s << "(format " << GLToString(glTexFormat) << s << "(format " << GLToString(glTexFormat) <<
", " << img->w << "x" << img->h << ", " << pImg->w << "x" << pImg->h <<
", format " << GLToString(glImageFormat) << ", format " << GLToString(glImageFormat) <<
", type " << GLToString(glImageType) << ", type " << GLToString(glImageType) <<
", pixfmt " << pixfmt << ", pixfmt " << pixfmt <<
@@ -1859,16 +1864,16 @@ unsigned RageDisplay_OGL::CreateTexture(
{ {
GLenum error = gluBuild2DMipmaps( GLenum error = gluBuild2DMipmaps(
GL_TEXTURE_2D, glTexFormat, GL_TEXTURE_2D, glTexFormat,
img->w, img->h, pImg->w, pImg->h,
glImageFormat, glImageType, img->pixels ); glImageFormat, glImageType, pImg->pixels );
ASSERT_M( error == 0, (char *) gluErrorString(error) ); ASSERT_M( error == 0, (char *) gluErrorString(error) );
} }
else else
{ {
glTexImage2D( glTexImage2D(
GL_TEXTURE_2D, 0, glTexFormat, GL_TEXTURE_2D, 0, glTexFormat,
img->w, img->h, 0, pImg->w, pImg->h, 0,
glImageFormat, glImageType, img->pixels); glImageFormat, glImageType, pImg->pixels);
GLenum error = glGetError(); GLenum error = glGetError();
ASSERT_M( error == GL_NO_ERROR, GLToString(error) ); ASSERT_M( error == GL_NO_ERROR, GLToString(error) );
@@ -1878,17 +1883,17 @@ unsigned RageDisplay_OGL::CreateTexture(
/* Sanity check: */ /* Sanity check: */
if( pixfmt == PixelFormat_PAL ) if( pixfmt == PixelFormat_PAL )
{ {
GLint size = 0; GLint iSize = 0;
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GLenum(GL_TEXTURE_INDEX_SIZE_EXT), &size); glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GLenum(GL_TEXTURE_INDEX_SIZE_EXT), &iSize );
if(size != 8) if( iSize != 8 )
RageException::Throw( "Thought paletted textures worked, but they don't." ); RageException::Throw( "Thought paletted textures worked, but they don't." );
} }
glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 ); glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
glFlush(); glFlush();
if( FreeImg ) if( bFreeImg )
delete img; delete pImg;
return uTexHandle; return uTexHandle;
} }
@@ -1896,31 +1901,31 @@ unsigned RageDisplay_OGL::CreateTexture(
* This is only used for movies anyway, which are never paletted. */ * This is only used for movies anyway, which are never paletted. */
void RageDisplay_OGL::UpdateTexture( void RageDisplay_OGL::UpdateTexture(
unsigned uTexHandle, unsigned uTexHandle,
RageSurface* img, RageSurface* pImg,
int xoffset, int yoffset, int width, int height ) int iXOffset, int iYOffset, int iWidth, int iHeight )
{ {
glBindTexture( GL_TEXTURE_2D, uTexHandle ); glBindTexture( GL_TEXTURE_2D, uTexHandle );
bool FreeImg; bool bFreeImg;
PixelFormat pixfmt = GetImgPixelFormat( img, FreeImg, width, height, false ); PixelFormat pixfmt = GetImgPixelFormat( pImg, bFreeImg, iWidth, iHeight, false );
glPixelStorei(GL_UNPACK_ROW_LENGTH, img->pitch / img->format->BytesPerPixel); glPixelStorei( GL_UNPACK_ROW_LENGTH, pImg->pitch / pImg->format->BytesPerPixel );
// GLenum glTexFormat = g_GLPixFmtInfo[pixfmt].internalfmt; // GLenum glTexFormat = g_GLPixFmtInfo[pixfmt].internalfmt;
GLenum glImageFormat = g_GLPixFmtInfo[pixfmt].format; GLenum glImageFormat = g_GLPixFmtInfo[pixfmt].format;
GLenum glImageType = g_GLPixFmtInfo[pixfmt].type; GLenum glImageType = g_GLPixFmtInfo[pixfmt].type;
glTexSubImage2D( GL_TEXTURE_2D, 0, glTexSubImage2D( GL_TEXTURE_2D, 0,
xoffset, yoffset, iXOffset, iYOffset,
width, height, iWidth, iHeight,
glImageFormat, glImageType, img->pixels); glImageFormat, glImageType, pImg->pixels );
/* Must unset PixelStore when we're done! */ /* Must unset PixelStore when we're done! */
glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 ); glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
glFlush(); glFlush();
if( FreeImg ) if( bFreeImg )
delete img; delete pImg;
} }
void RageDisplay_OGL::SetPolygonMode( PolygonMode pm ) void RageDisplay_OGL::SetPolygonMode( PolygonMode pm )