Readded texture stretch, texture dither, and 16 bit textures.
This commit is contained in:
@@ -156,8 +156,11 @@ found_effect:
|
|||||||
case EFFECT_STRETCH_WATER:
|
case EFFECT_STRETCH_WATER:
|
||||||
case EFFECT_STRETCH_BUBBLE:
|
case EFFECT_STRETCH_BUBBLE:
|
||||||
case EFFECT_STRETCH_TWIST:
|
case EFFECT_STRETCH_TWIST:
|
||||||
|
{
|
||||||
m_iNumSprites = 1;
|
m_iNumSprites = 1;
|
||||||
m_Sprites[0].Load( sPath, false, 4, 4, false, true );
|
RageTexturePrefs prefs;
|
||||||
|
prefs.bStretch = true;
|
||||||
|
m_Sprites[0].Load( sPath, prefs );
|
||||||
m_Sprites[0].StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) );
|
m_Sprites[0].StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) );
|
||||||
m_Sprites[0].SetCustomTextureRect( RectF(0,0,1,1) );
|
m_Sprites[0].SetCustomTextureRect( RectF(0,0,1,1) );
|
||||||
|
|
||||||
@@ -175,6 +178,7 @@ found_effect:
|
|||||||
default:
|
default:
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case EFFECT_STRETCH_SPIN:
|
case EFFECT_STRETCH_SPIN:
|
||||||
m_iNumSprites = 1;
|
m_iNumSprites = 1;
|
||||||
|
|||||||
@@ -174,7 +174,11 @@ void Background::LoadFromSong( Song* pSong )
|
|||||||
// loader would have no way of knowing that the image, seeming to use the
|
// loader would have no way of knowing that the image, seeming to use the
|
||||||
// alpha layer, actually doesn't since it's the back-most image. Hmm.)
|
// alpha layer, actually doesn't since it's the back-most image. Hmm.)
|
||||||
Sprite sprDummy;
|
Sprite sprDummy;
|
||||||
sprDummy.Load( sSongBackgroundPath, true, 4, 0, true, false );
|
RageTexturePrefs prefs;
|
||||||
|
prefs.bForceReload = true;
|
||||||
|
prefs.iMipMaps = 1;
|
||||||
|
prefs.bDither = true;
|
||||||
|
sprDummy.Load( sSongBackgroundPath, prefs );
|
||||||
|
|
||||||
{
|
{
|
||||||
BGAnimation *pTempBGA = new BGAnimation;
|
BGAnimation *pTempBGA = new BGAnimation;
|
||||||
|
|||||||
@@ -25,10 +25,10 @@ Banner::Banner()
|
|||||||
Banner::Load( THEME->GetPathTo("Graphics","fallback banner") );
|
Banner::Load( THEME->GetPathTo("Graphics","fallback banner") );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Banner::Load( CString sFilePath, bool bForceReload, int iMipMaps, int iAlphaBits, bool bDither, bool bStretch )
|
bool Banner::Load( CString sFilePath, RageTexturePrefs prefs )
|
||||||
{
|
{
|
||||||
// note that the defaults are changes for faster loading
|
// note that the defaults are changes for faster loading
|
||||||
return CroppedSprite::Load( sFilePath, bForceReload, iMipMaps, iAlphaBits, bDither, bStretch );
|
return CroppedSprite::Load( sFilePath, prefs );
|
||||||
};
|
};
|
||||||
|
|
||||||
void Banner::Update( float fDeltaTime )
|
void Banner::Update( float fDeltaTime )
|
||||||
@@ -98,7 +98,9 @@ bool Banner::LoadFromCourse( Course* pCourse ) // NULL means no course
|
|||||||
|
|
||||||
bool Banner::LoadRoulette()
|
bool Banner::LoadRoulette()
|
||||||
{
|
{
|
||||||
Banner::Load( THEME->GetPathTo("Graphics","select music roulette banner"), false, 0, 0, false, false );
|
RageTexturePrefs prefs;
|
||||||
|
prefs.iMipMaps = 0;
|
||||||
|
Banner::Load( THEME->GetPathTo("Graphics","select music roulette banner"), prefs );
|
||||||
m_bScrolling = true;
|
m_bScrolling = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ class Banner : public CroppedSprite
|
|||||||
public:
|
public:
|
||||||
Banner();
|
Banner();
|
||||||
|
|
||||||
virtual bool Load( CString sFilePath, bool bForceReload = false, int iMipMaps = 0, int iAlphaBits = 0, bool bDither = false, bool bStretch = false );
|
virtual bool Load( CString sFilePath, RageTexturePrefs prefs );
|
||||||
|
virtual bool Load( CString sFilePath ) { return Load( sFilePath, RageTexturePrefs() ); }
|
||||||
|
|
||||||
virtual void Update( float fDeltaTime );
|
virtual void Update( float fDeltaTime );
|
||||||
|
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ CroppedSprite::CroppedSprite()
|
|||||||
m_fCropWidth = m_fCropHeight = 100;
|
m_fCropWidth = m_fCropHeight = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CroppedSprite::Load( CString sFilePath, bool bForceReload, int iMipMaps, int iAlphaBits, bool bDither, bool bStretch )
|
bool CroppedSprite::Load( CString sFilePath, RageTexturePrefs prefs )
|
||||||
{
|
{
|
||||||
Sprite::Load( sFilePath, bForceReload, iMipMaps, iAlphaBits, bDither, bStretch );
|
Sprite::Load( sFilePath, prefs );
|
||||||
CropToSize( m_fCropWidth, m_fCropHeight );
|
CropToSize( m_fCropWidth, m_fCropHeight );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Sprite.h"
|
#include "Sprite.h"
|
||||||
#include "Song.h"
|
|
||||||
|
|
||||||
|
|
||||||
class CroppedSprite : public Sprite
|
class CroppedSprite : public Sprite
|
||||||
@@ -21,7 +20,7 @@ public:
|
|||||||
CroppedSprite();
|
CroppedSprite();
|
||||||
virtual ~CroppedSprite() { }
|
virtual ~CroppedSprite() { }
|
||||||
|
|
||||||
bool Load( CString sFilePath, bool bForceReload = false, int iMipMaps = 4, int iAlphaBits = 4, bool bDither = false, bool bStretch = false );
|
bool Load( CString sFilePath, RageTexturePrefs prefs );
|
||||||
void SetCroppedSize( float fWidth, float fHeight );
|
void SetCroppedSize( float fWidth, float fHeight );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -10,21 +10,23 @@
|
|||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "RageUtil.h"
|
|
||||||
|
|
||||||
#include "GrooveRadar.h"
|
#include "GrooveRadar.h"
|
||||||
|
#include "RageUtil.h"
|
||||||
#include "PrefsManager.h"
|
#include "PrefsManager.h"
|
||||||
#include "RageBitmapTexture.h"
|
#include "RageBitmapTexture.h"
|
||||||
#include "GameConstantsAndTypes.h"
|
#include "GameConstantsAndTypes.h"
|
||||||
#include "ThemeManager.h"
|
#include "ThemeManager.h"
|
||||||
#include "Notes.h"
|
#include "Notes.h"
|
||||||
|
#include "RageDisplay.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
#define LABEL_OFFSET_X( i ) THEME->GetMetricF("GrooveRadar",ssprintf("Label%dOffsetX",i+1))
|
#define LABEL_OFFSET_X( i ) THEME->GetMetricF("GrooveRadar",ssprintf("Label%dOffsetX",i+1))
|
||||||
#define LABEL_OFFSET_Y( i ) THEME->GetMetricF("GrooveRadar",ssprintf("Label%dOffsetY",i+1))
|
#define LABEL_OFFSET_Y( i ) THEME->GetMetricF("GrooveRadar",ssprintf("Label%dOffsetY",i+1))
|
||||||
|
|
||||||
|
|
||||||
float RADAR_VALUE_ROTATION( int iValueIndex ) { return D3DX_PI/2 + D3DX_PI*2 / 5.0f * iValueIndex; }
|
float RADAR_VALUE_ROTATION( int iValueIndex ) { return PI/2 + PI*2 / 5.0f * iValueIndex; }
|
||||||
|
|
||||||
const float RADAR_EDGE_WIDTH = 3;
|
const float RADAR_EDGE_WIDTH = 3;
|
||||||
|
|
||||||
@@ -203,7 +205,7 @@ void GrooveRadar::GrooveRadarValueMap::DrawPrimitives()
|
|||||||
void GrooveRadar::GrooveRadarValueMap::TweenOnScreen()
|
void GrooveRadar::GrooveRadarValueMap::TweenOnScreen()
|
||||||
{
|
{
|
||||||
SetZoom( 0.5f );
|
SetZoom( 0.5f );
|
||||||
SetRotation( D3DX_PI*4 );
|
SetRotation( PI*4 );
|
||||||
BeginTweening( 0.6f );
|
BeginTweening( 0.6f );
|
||||||
SetTweenZoom( 1 );
|
SetTweenZoom( 1 );
|
||||||
SetTweenRotationZ( 0 );
|
SetTweenRotationZ( 0 );
|
||||||
@@ -212,6 +214,6 @@ void GrooveRadar::GrooveRadarValueMap::TweenOnScreen()
|
|||||||
void GrooveRadar::GrooveRadarValueMap::TweenOffScreen()
|
void GrooveRadar::GrooveRadarValueMap::TweenOffScreen()
|
||||||
{
|
{
|
||||||
BeginTweening( 0.6f );
|
BeginTweening( 0.6f );
|
||||||
SetTweenRotationZ( D3DX_PI*4 );
|
SetTweenRotationZ( PI*4 );
|
||||||
SetTweenZoom( 0 );
|
SetTweenZoom( 0 );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
Desc: Holder for a static texture with metadata. Can load just about any image format.
|
Desc: Holder for a static texture with metadata. Can load just about any image format.
|
||||||
|
|
||||||
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
||||||
Chris Danford
|
|
||||||
Glenn Maynard
|
Glenn Maynard
|
||||||
|
Chris Danford
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
#include "RageUtil.h"
|
#include "RageUtil.h"
|
||||||
#include "RageLog.h"
|
#include "RageLog.h"
|
||||||
#include "RageException.h"
|
#include "RageException.h"
|
||||||
#include "RageTextureManager.h"
|
#include "RageDisplay.h"
|
||||||
|
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
#include "SDL_image.h"
|
#include "SDL_image.h"
|
||||||
@@ -25,16 +25,59 @@
|
|||||||
#include "SDL_dither.h"
|
#include "SDL_dither.h"
|
||||||
#include "SDL_opengl.h"
|
#include "SDL_opengl.h"
|
||||||
|
|
||||||
|
#include "RageTimer.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Definitions for various texture formats. We'll probably want RGBA
|
||||||
|
* in OpenGL, not ARGB ... All of these are in local (little) endian;
|
||||||
|
* this may or may not need adjustment for OpenGL. */
|
||||||
|
const static unsigned int PixFmtMasks[][5] =
|
||||||
|
{
|
||||||
|
/* Err. D3D's texture formats are little-endian, so the order of
|
||||||
|
* colors (bytewise) is BGRA; D3DFMT_A8R8G8B8 is really BGRA (bytewise).
|
||||||
|
* D3DFMT_A4R4G4B4 is 0xGBAR; flip the bytes and it's sane (0xARGB).
|
||||||
|
*/
|
||||||
|
{ 0x00FF0000, /* B8G8R8A8 */
|
||||||
|
0x0000FF00,
|
||||||
|
0x000000FF,
|
||||||
|
0xFF000000, 32 },
|
||||||
|
{ 0x0F00, /* B4G4R4A4 */
|
||||||
|
0x00F0,
|
||||||
|
0x000F,
|
||||||
|
0xF000, 16 },
|
||||||
|
{ 0x7C00, /* B5G5R5A1 */
|
||||||
|
0x03E0,
|
||||||
|
0x001F,
|
||||||
|
0x8000, 16 },
|
||||||
|
// { 0xF800, /* B5G6R5 */ /* this format doesn't seem to be supported in OGL 1.0 */
|
||||||
|
// 0x07E0,
|
||||||
|
// 0x001F,
|
||||||
|
// 0x0000, 16 }
|
||||||
|
};
|
||||||
|
|
||||||
|
int PixFmtMaskNo(GLenum fmt)
|
||||||
|
{
|
||||||
|
switch(fmt) {
|
||||||
|
case GL_RGBA8: return 0;
|
||||||
|
case GL_RGBA4: return 1;
|
||||||
|
case GL_RGB5_A1: return 2;
|
||||||
|
// case D3DFMT_R5G6B5: return 3;
|
||||||
|
default: ASSERT(0); return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// RageBitmapTexture constructor
|
// RageBitmapTexture constructor
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
RageBitmapTexture::RageBitmapTexture( const CString &sFilePath ) : RageTexture( sFilePath )
|
RageBitmapTexture::RageBitmapTexture( CString sFilePath, RageTexturePrefs prefs ) :
|
||||||
|
RageTexture( sFilePath, prefs )
|
||||||
{
|
{
|
||||||
// LOG->Trace( "RageBitmapTexture::RageBitmapTexture()" );
|
// LOG->Trace( "RageBitmapTexture::RageBitmapTexture()" );
|
||||||
|
|
||||||
m_uGLTextureID = 0;
|
m_uGLTextureID = 0;
|
||||||
Load( sFilePath );
|
|
||||||
|
Create(); // sFilePath and prefs are saved by RageTexture()
|
||||||
}
|
}
|
||||||
|
|
||||||
RageBitmapTexture::~RageBitmapTexture()
|
RageBitmapTexture::~RageBitmapTexture()
|
||||||
@@ -43,35 +86,164 @@ RageBitmapTexture::~RageBitmapTexture()
|
|||||||
glDeleteTextures(1, &m_uGLTextureID);
|
glDeleteTextures(1, &m_uGLTextureID);
|
||||||
}
|
}
|
||||||
|
|
||||||
int power_of_two(int input)
|
void RageBitmapTexture::Reload( RageTexturePrefs prefs )
|
||||||
|
{
|
||||||
|
DISPLAY->SetTexture(0);
|
||||||
|
|
||||||
|
if(m_uGLTextureID)
|
||||||
|
{
|
||||||
|
glDeleteTextures(1, &m_uGLTextureID);
|
||||||
|
m_uGLTextureID = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Create();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int power_of_two(int input)
|
||||||
{
|
{
|
||||||
int value = 1;
|
int value = 1;
|
||||||
|
|
||||||
while ( value < input ) value <<= 1;
|
while ( value < input ) value <<= 1;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageBitmapTexture::Load( const CString &sFilePath )
|
/*
|
||||||
|
* Each dwMaxSize, dwTextureColorDepth and iAlphaBits are maximums; we may
|
||||||
|
* use less. iAlphaBits must be 0, 1 or 4.
|
||||||
|
*
|
||||||
|
* XXX: change iAlphaBits == 4 to iAlphaBits == 8 to indicate "as much alpha
|
||||||
|
* as needed", since that's what it really is; still only use 4 in 16-bit textures.
|
||||||
|
*
|
||||||
|
* Dither forces dithering when loading 16-bit textures.
|
||||||
|
* Stretch forces the loaded image to fill the texture completely.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void RageBitmapTexture::Create()
|
||||||
{
|
{
|
||||||
m_sFilePath = sFilePath; // save file path
|
// look in the file name for a format hints
|
||||||
|
m_sFilePath.MakeLower();
|
||||||
|
|
||||||
int iMaxSize = DISPLAY->GetMaxTextureSize();
|
if( m_sFilePath.Find("no alpha") != -1 ) m_prefs.iAlphaBits = 0;
|
||||||
|
else if( m_sFilePath.Find("1 alpha") != -1 ) m_prefs.iAlphaBits = 1;
|
||||||
SDL_Surface *img;
|
else if( m_sFilePath.Find("1alpha") != -1 ) m_prefs.iAlphaBits = 1;
|
||||||
|
else if( m_sFilePath.Find("0alpha") != -1 ) m_prefs.iAlphaBits = 0;
|
||||||
|
if( m_sFilePath.Find("dither") != -1 ) m_prefs.bDither = true;
|
||||||
|
|
||||||
/* Load the image into an SDL surface. */
|
/* Load the image into an SDL surface. */
|
||||||
img = IMG_Load(sFilePath);
|
SDL_Surface *img = IMG_Load(m_sFilePath);
|
||||||
if(!img)
|
|
||||||
throw RageException("Could not load graphic '%s'", sFilePath.GetString());
|
|
||||||
|
|
||||||
/* Save information about the source. Unless something else changes this
|
/* Figure out which texture format to use. */
|
||||||
* later, the image inside the texture is the same size as the source. */
|
GLenum fmtTexture;
|
||||||
m_iImageWidth = m_iSourceWidth = img->w;
|
|
||||||
m_iImageHeight = m_iSourceHeight = img->h;
|
if( m_prefs.iTextureColorDepth == 16 )
|
||||||
|
{
|
||||||
|
/* Bits of alpha in the source: */
|
||||||
|
int src_alpha_bits = 8 - img->format->Aloss;
|
||||||
|
|
||||||
|
/* No real alpha in paletted input. */
|
||||||
|
if( img->format->BytesPerPixel == 1 )
|
||||||
|
src_alpha_bits = 0;
|
||||||
|
|
||||||
|
/* Colorkeyed input effectively has at least one bit of alpha: */
|
||||||
|
if( img->flags & SDL_SRCCOLORKEY )
|
||||||
|
src_alpha_bits = max( 1, src_alpha_bits );
|
||||||
|
|
||||||
|
/* Don't use more than we were hinted to. */
|
||||||
|
src_alpha_bits = min( m_prefs.iAlphaBits, src_alpha_bits );
|
||||||
|
|
||||||
|
/* XXX Scan the image, and see if it actually uses its alpha channel/color key
|
||||||
|
* (if any). Reduce to 1 or 0 bits of alpha if possible. */
|
||||||
|
|
||||||
|
switch( src_alpha_bits ) {
|
||||||
|
case 0:
|
||||||
|
case 1:
|
||||||
|
fmtTexture = GL_RGB5_A1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fmtTexture = GL_RGBA4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if( m_prefs.iTextureColorDepth == 32 )
|
||||||
|
fmtTexture = GL_RGBA8;
|
||||||
|
else
|
||||||
|
throw RageException( "Invalid color depth: %d bits", m_prefs.iTextureColorDepth );
|
||||||
|
|
||||||
|
/* Cap the max texture size to the hardware max. */
|
||||||
|
m_prefs.iMaxSize = min( m_prefs.iMaxSize, DISPLAY->GetMaxTextureSize() );
|
||||||
|
|
||||||
|
/* Save information about the source. */
|
||||||
|
m_iSourceWidth = img->w;
|
||||||
|
m_iSourceHeight = img->h;
|
||||||
|
|
||||||
|
/* image size cannot exceed max size */
|
||||||
|
m_iImageWidth = min( m_iSourceWidth, m_prefs.iMaxSize );
|
||||||
|
m_iImageHeight = min( m_iSourceHeight, m_prefs.iMaxSize );
|
||||||
|
|
||||||
/* Texture dimensions need to be a power of two; jump to the next. */
|
/* Texture dimensions need to be a power of two; jump to the next. */
|
||||||
m_iTextureWidth = power_of_two(img->w);
|
m_iTextureWidth = power_of_two(m_iImageWidth);
|
||||||
m_iTextureHeight = power_of_two(img->h);
|
m_iTextureHeight = power_of_two(m_iImageHeight);
|
||||||
|
|
||||||
|
ASSERT( m_iTextureWidth <= m_prefs.iMaxSize );
|
||||||
|
ASSERT( m_iTextureHeight <= m_prefs.iMaxSize );
|
||||||
|
|
||||||
|
|
||||||
|
/* If the source is larger than the texture, we have to scale it down; that's
|
||||||
|
* "stretching", I guess. */
|
||||||
|
if(m_iSourceWidth != m_iImageWidth || m_iSourceHeight > m_iImageHeight)
|
||||||
|
m_prefs.bStretch = true;
|
||||||
|
|
||||||
|
int target = PixFmtMaskNo(fmtTexture);
|
||||||
|
|
||||||
|
/* Dither only when the target is 16bpp, not when it's 32bpp. */
|
||||||
|
if( PixFmtMasks[target][4] /* XXX magic 4 */ == 4)
|
||||||
|
m_prefs.bDither = false;
|
||||||
|
|
||||||
|
if( m_prefs.bStretch )
|
||||||
|
{
|
||||||
|
/* resize currently only does RGBA8888 */
|
||||||
|
int mask = 0;
|
||||||
|
ConvertSDLSurface(img, img->w, img->h, PixFmtMasks[mask][4],
|
||||||
|
PixFmtMasks[mask][0], PixFmtMasks[mask][1], PixFmtMasks[mask][2], PixFmtMasks[mask][3]);
|
||||||
|
|
||||||
|
SDL_Surface *dst = zoomSurface(img, m_iImageWidth, m_iImageHeight );
|
||||||
|
SDL_FreeSurface(img);
|
||||||
|
img = dst;
|
||||||
|
|
||||||
|
// Commented out to see how things look without iterative filtering. -Chris
|
||||||
|
// while (m_iImageWidth != m_iTextureWidth || m_iImageHeight != m_iTextureHeight) {
|
||||||
|
// float xscale = float(m_iTextureWidth)/m_iImageWidth;
|
||||||
|
// float yscale = float(m_iTextureHeight)/m_iImageHeight;
|
||||||
|
//
|
||||||
|
// /* Our filter is a simple linear filter, so it can't scale to
|
||||||
|
// * less than .5 very well. If we need to go lower than .5, do
|
||||||
|
// * it iteratively. */
|
||||||
|
// xscale = max(xscale, .5f);
|
||||||
|
// yscale = max(yscale, .5f);
|
||||||
|
//
|
||||||
|
// SDL_Surface *dst = zoomSurface(img, xscale, yscale);
|
||||||
|
//
|
||||||
|
// SDL_FreeSurface(img);
|
||||||
|
// img = dst;
|
||||||
|
//
|
||||||
|
// /* The new image size is the full texture size. */
|
||||||
|
// m_iImageWidth = int(m_iImageWidth * xscale + .0001);
|
||||||
|
// m_iImageHeight = int(m_iImageHeight * yscale + .0001);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
if( m_prefs.bDither )
|
||||||
|
{
|
||||||
|
/* Dither down to the destination format. */
|
||||||
|
SDL_Surface *dst = SDL_CreateRGBSurfaceSane(SDL_SWSURFACE, img->w, img->h, PixFmtMasks[target][4],
|
||||||
|
PixFmtMasks[target][0], PixFmtMasks[target][1], PixFmtMasks[target][2], PixFmtMasks[target][3]);
|
||||||
|
|
||||||
|
SM_SDL_OrderedDither(img, dst);
|
||||||
|
SDL_FreeSurface(img);
|
||||||
|
img = dst;
|
||||||
|
}
|
||||||
|
|
||||||
/* Convert the data to the destination format. Hmm. We could just
|
/* Convert the data to the destination format. Hmm. We could just
|
||||||
* convert the format, leaving the resolution alone (simplifying
|
* convert the format, leaving the resolution alone (simplifying
|
||||||
@@ -91,23 +263,17 @@ void RageBitmapTexture::Load( const CString &sFilePath )
|
|||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, img->pitch / img->format->BytesPerPixel);
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, img->pitch / img->format->BytesPerPixel);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, img->w, img->h, 0, GL_RGBA,
|
glTexImage2D(GL_TEXTURE_2D, 0, fmtTexture, img->w, img->h, 0, GL_RGBA,
|
||||||
GL_UNSIGNED_BYTE, img->pixels);
|
GL_UNSIGNED_BYTE, img->pixels);
|
||||||
glFlush();
|
glFlush();
|
||||||
|
|
||||||
SDL_FreeSurface(img);
|
SDL_FreeSurface(img);
|
||||||
|
|
||||||
CreateFrameRects();
|
CreateFrameRects();
|
||||||
|
|
||||||
|
// LOG->Trace( "RageBitmapTexture: Loaded '%s' (%ux%u) from disk. bStretch = %d, source %d,%d; image %d,%d.",
|
||||||
|
// m_sFilePath.GetString(), GetTextureWidth(), GetTextureHeight(),
|
||||||
|
// bStretch, m_iSourceWidth, m_iSourceHeight,
|
||||||
|
// m_iImageWidth, m_iImageHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageBitmapTexture::Reload()
|
|
||||||
{
|
|
||||||
DISPLAY->SetTexture(0);
|
|
||||||
|
|
||||||
if(m_uGLTextureID) {
|
|
||||||
glDeleteTextures(1, &m_uGLTextureID);
|
|
||||||
m_uGLTextureID = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Load( m_sFilePath );
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#pragma once
|
#ifndef RAGEBITMAPTEXTURE_H
|
||||||
|
#define RAGEBITMAPTEXTURE_H
|
||||||
|
|
||||||
/*
|
/*
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
Class: RageBitmapTexture
|
Class: RageBitmapTexture
|
||||||
@@ -10,29 +12,24 @@
|
|||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "RageDisplay.h"
|
|
||||||
#include "RageTexture.h"
|
#include "RageTexture.h"
|
||||||
#include <d3dx8.h>
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// RageBitmapTexture Class Declarations
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
class RageBitmapTexture : public RageTexture
|
class RageBitmapTexture : public RageTexture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RageBitmapTexture( const CString &sFilePath );
|
RageBitmapTexture( CString sFilePath, RageTexturePrefs prefs );
|
||||||
virtual ~RageBitmapTexture();
|
virtual ~RageBitmapTexture();
|
||||||
/* only called by RageTextureManager::InvalidateTextures */
|
/* only called by RageTextureManager::InvalidateTextures */
|
||||||
virtual void Invalidate() { m_uGLTextureID = 0; }
|
virtual void Invalidate() { m_uGLTextureID = 0; }
|
||||||
|
virtual void Reload( RageTexturePrefs prefs );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Load( const CString &sFilePath );
|
void Create(); // called by constructor and Reload
|
||||||
virtual void Reload();
|
|
||||||
|
|
||||||
virtual unsigned int GetGLTextureID() { return m_uGLTextureID; }
|
virtual unsigned int GetGLTextureID() { return m_uGLTextureID; }
|
||||||
|
|
||||||
unsigned int m_uGLTextureID;
|
unsigned int m_uGLTextureID;
|
||||||
CString m_sFilePath;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -22,11 +22,12 @@
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// RageTexture constructor
|
// RageTexture constructor
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
RageTexture::RageTexture( const CString &sFilePath )
|
RageTexture::RageTexture( CString sFilePath, RageTexturePrefs prefs )
|
||||||
{
|
{
|
||||||
// LOG->Trace( "RageTexture::RageTexture()" );
|
// LOG->Trace( "RageTexture::RageTexture()" );
|
||||||
|
|
||||||
m_sFilePath = sFilePath;
|
m_sFilePath = sFilePath;
|
||||||
|
m_prefs = prefs;
|
||||||
m_iRefCount = 1;
|
m_iRefCount = 1;
|
||||||
|
|
||||||
m_iSourceWidth = m_iSourceHeight = 0;
|
m_iSourceWidth = m_iSourceHeight = 0;
|
||||||
|
|||||||
@@ -17,16 +17,39 @@
|
|||||||
const int MAX_TEXTURE_FRAMES = 256;
|
const int MAX_TEXTURE_FRAMES = 256;
|
||||||
|
|
||||||
|
|
||||||
|
struct RageTexturePrefs
|
||||||
|
{
|
||||||
|
bool bForceReload;
|
||||||
|
int iMaxSize;
|
||||||
|
int iTextureColorDepth;
|
||||||
|
int iMipMaps;
|
||||||
|
int iAlphaBits;
|
||||||
|
bool bDither;
|
||||||
|
bool bStretch;
|
||||||
|
|
||||||
|
RageTexturePrefs()
|
||||||
|
{
|
||||||
|
bForceReload = false;
|
||||||
|
iMaxSize = 2048;
|
||||||
|
iTextureColorDepth = 16;
|
||||||
|
iMipMaps = 4;
|
||||||
|
iAlphaBits = 4;
|
||||||
|
bDither = false;
|
||||||
|
bStretch = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// RageTexture Class Declarations
|
// RageTexture Class Declarations
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
class RageTexture
|
class RageTexture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RageTexture( const CString &sFilePath );
|
RageTexture( CString sFilePath, RageTexturePrefs prefs );
|
||||||
virtual ~RageTexture() = 0;
|
virtual ~RageTexture() = 0;
|
||||||
|
virtual void Reload( RageTexturePrefs prefs ) = 0;
|
||||||
virtual void Reload() = 0;
|
virtual void Invalidate() { } /* only called by RageTextureManager::InvalidateTextures */
|
||||||
|
virtual unsigned int GetGLTextureID() = 0; // accessed by RageDisplay
|
||||||
|
|
||||||
// movie texture/animated texture stuff
|
// movie texture/animated texture stuff
|
||||||
virtual void Play() {}
|
virtual void Play() {}
|
||||||
@@ -61,9 +84,6 @@ public:
|
|||||||
int m_iRefCount;
|
int m_iRefCount;
|
||||||
int m_iTimeOfLastUnload;
|
int m_iTimeOfLastUnload;
|
||||||
|
|
||||||
/* only called by RageTextureManager::InvalidateTextures */
|
|
||||||
virtual void Invalidate() { }
|
|
||||||
virtual unsigned int GetGLTextureID() = 0; // accessed by RageDisplay
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@@ -71,6 +91,7 @@ protected:
|
|||||||
virtual void GetFrameDimensionsFromFileName( CString sPath, int* puFramesWide, int* puFramesHigh ) const;
|
virtual void GetFrameDimensionsFromFileName( CString sPath, int* puFramesWide, int* puFramesHigh ) const;
|
||||||
|
|
||||||
CString m_sFilePath;
|
CString m_sFilePath;
|
||||||
|
RageTexturePrefs m_prefs;
|
||||||
|
|
||||||
int m_iSourceWidth, m_iSourceHeight; // dimensions of the original image loaded from disk
|
int m_iSourceWidth, m_iSourceHeight; // dimensions of the original image loaded from disk
|
||||||
int m_iTextureWidth, m_iTextureHeight; // dimensions of the texture in memory
|
int m_iTextureWidth, m_iTextureHeight; // dimensions of the texture in memory
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ RageTexture* RageTextureManager::LoadTexture( CString sTexturePath )
|
|||||||
// if( sExt == "avi" || sExt == "mpg" || sExt == "mpeg" )
|
// if( sExt == "avi" || sExt == "mpg" || sExt == "mpeg" )
|
||||||
// pTexture = new RageMovieTexture( sTexturePath );
|
// pTexture = new RageMovieTexture( sTexturePath );
|
||||||
// else
|
// else
|
||||||
pTexture = new RageBitmapTexture( sTexturePath );
|
pTexture = new RageBitmapTexture( sTexturePath, RageTexturePrefs() );
|
||||||
|
|
||||||
LOG->Trace( "RageTextureManager: Finished loading '%s'.", sTexturePath.GetString() );
|
LOG->Trace( "RageTextureManager: Finished loading '%s'.", sTexturePath.GetString() );
|
||||||
|
|
||||||
@@ -179,7 +179,7 @@ void RageTextureManager::ReloadAll()
|
|||||||
{
|
{
|
||||||
RageTexture* pTexture = i->second;
|
RageTexture* pTexture = i->second;
|
||||||
|
|
||||||
pTexture->Reload(); // this is not entirely correct. Hints are lost! XXX
|
pTexture->Reload( RageTexturePrefs() ); // this is not entirely correct. Hints are lost! XXX
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -141,35 +141,15 @@ void zoomSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst)
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Sanity check zoom factors
|
|
||||||
*/
|
|
||||||
if (zoomx < VALUE_LIMIT) zoomx = VALUE_LIMIT;
|
|
||||||
if (zoomy < VALUE_LIMIT) zoomy = VALUE_LIMIT;
|
|
||||||
|
|
||||||
/* Calculate target size */
|
SDL_Surface *zoomSurface(SDL_Surface * src, int dstwidth, int dstheight)
|
||||||
*dstwidth = (int) ((double) width * zoomx);
|
|
||||||
*dstheight = (int) ((double) height * zoomy);
|
|
||||||
if (*dstwidth < 1) *dstwidth = 1;
|
|
||||||
if (*dstheight < 1) *dstheight = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy)
|
|
||||||
{
|
{
|
||||||
SDL_Surface *rz_dst;
|
SDL_Surface *rz_dst;
|
||||||
int dstwidth, dstheight;
|
|
||||||
|
|
||||||
/*
|
/* Sanity check */
|
||||||
* Sanity check
|
|
||||||
*/
|
|
||||||
if (src == NULL)
|
if (src == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
/* Get size if target */
|
|
||||||
zoomSurfaceSize(src->w, src->h, zoomx, zoomy, &dstwidth, &dstheight);
|
|
||||||
|
|
||||||
/* Alloc space to completely contain the zoomed surface */
|
/* Alloc space to completely contain the zoomed surface */
|
||||||
/* Target surface is 32bit with source RGBA/ABGR ordering */
|
/* Target surface is 32bit with source RGBA/ABGR ordering */
|
||||||
rz_dst =
|
rz_dst =
|
||||||
|
|||||||
@@ -22,9 +22,7 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy);
|
SDL_Surface *zoomSurface(SDL_Surface * src, int dstwidth, int dstheight);
|
||||||
|
|
||||||
/* Returns the size of the target surface for a zoomSurface() call */
|
|
||||||
void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -43,13 +43,6 @@ Sprite::~Sprite()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Sprite::LoadFromTexture( CString sTexturePath, bool bForceReload, int iMipMaps, int iAlphaBits, bool bDither, bool bStretch )
|
|
||||||
{
|
|
||||||
LOG->Trace( ssprintf("Sprite::LoadFromTexture(%s)", sTexturePath.GetString()) );
|
|
||||||
|
|
||||||
//Init();
|
|
||||||
return LoadTexture( sTexturePath, bForceReload, iMipMaps, iAlphaBits, bDither, bStretch );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sprite file has the format:
|
// Sprite file has the format:
|
||||||
//
|
//
|
||||||
@@ -59,7 +52,7 @@ bool Sprite::LoadFromTexture( CString sTexturePath, bool bForceReload, int iMipM
|
|||||||
// Delay0000=1.0
|
// Delay0000=1.0
|
||||||
// Frame0001=3
|
// Frame0001=3
|
||||||
// Delay0000=2.0
|
// Delay0000=2.0
|
||||||
bool Sprite::LoadFromSpriteFile( CString sSpritePath, bool bForceReload, int iMipMaps, int iAlphaBits, bool bDither, bool bStretch )
|
bool Sprite::LoadFromSpriteFile( CString sSpritePath, RageTexturePrefs prefs )
|
||||||
{
|
{
|
||||||
LOG->Trace( ssprintf("Sprite::LoadFromSpriteFile(%s)", sSpritePath.GetString()) );
|
LOG->Trace( ssprintf("Sprite::LoadFromSpriteFile(%s)", sSpritePath.GetString()) );
|
||||||
|
|
||||||
@@ -93,15 +86,12 @@ bool Sprite::LoadFromSpriteFile( CString sSpritePath, bool bForceReload, int iMi
|
|||||||
throw RageException( "The sprite file '%s' points to a texture '%s' which doesn't exist.", m_sSpritePath.GetString(), sTexturePath.GetString() );
|
throw RageException( "The sprite file '%s' points to a texture '%s' which doesn't exist.", m_sSpritePath.GetString(), sTexturePath.GetString() );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Load the texture
|
// Load the texture
|
||||||
if( !LoadTexture( sTexturePath ) )
|
LoadFromTexture( sTexturePath, prefs );
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
|
|
||||||
// Read in frames and delays from the sprite file,
|
// Read in frames and delays from the sprite file,
|
||||||
// overwriting the states that LoadFromTexture created.
|
// overwriting the states that LoadFromTexture created.
|
||||||
for( UINT i=0; i<MAX_SPRITE_STATES; i++ )
|
for( int i=0; i<MAX_SPRITE_STATES; i++ )
|
||||||
{
|
{
|
||||||
CString sFrameKey = ssprintf( "Frame%04d", i );
|
CString sFrameKey = ssprintf( "Frame%04d", i );
|
||||||
CString sDelayKey = ssprintf( "Delay%04d", i );
|
CString sDelayKey = ssprintf( "Delay%04d", i );
|
||||||
@@ -141,7 +131,7 @@ void Sprite::UnloadTexture()
|
|||||||
m_sTexturePath = "";
|
m_sTexturePath = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sprite::LoadTexture( CString sTexturePath, bool bForceReload, int iMipMaps, int iAlphaBits, bool bDither, bool bStretch )
|
bool Sprite::LoadFromTexture( CString sTexturePath, RageTexturePrefs prefs )
|
||||||
{
|
{
|
||||||
UnloadTexture();
|
UnloadTexture();
|
||||||
|
|
||||||
|
|||||||
@@ -27,13 +27,14 @@ public:
|
|||||||
Sprite();
|
Sprite();
|
||||||
virtual ~Sprite();
|
virtual ~Sprite();
|
||||||
|
|
||||||
virtual bool Load( CString sFilePath, bool bForceReload = false, int iMipMaps = 4, int iAlphaBits = 4, bool bDither = false, bool bStretch = false )
|
virtual bool Load( CString sFilePath ) { return Load( sFilePath, RageTexturePrefs() ); }
|
||||||
|
virtual bool Load( CString sFilePath, RageTexturePrefs prefs )
|
||||||
{
|
{
|
||||||
ASSERT( sFilePath != "" );
|
ASSERT( sFilePath != "" );
|
||||||
if( sFilePath.Right(7) == ".sprite" )
|
if( sFilePath.Right(7) == ".sprite" )
|
||||||
return LoadFromSpriteFile( sFilePath, bForceReload, iMipMaps, iAlphaBits, bDither, bStretch );
|
return LoadFromSpriteFile( sFilePath, prefs );
|
||||||
else
|
else
|
||||||
return LoadFromTexture( sFilePath, bForceReload, iMipMaps, iAlphaBits, bDither, bStretch );
|
return LoadFromTexture( sFilePath, prefs );
|
||||||
};
|
};
|
||||||
void UnloadTexture();
|
void UnloadTexture();
|
||||||
RageTexture* GetTexture() { return m_pTexture; };
|
RageTexture* GetTexture() { return m_pTexture; };
|
||||||
@@ -58,12 +59,8 @@ public:
|
|||||||
void StopUsingCustomCoords();
|
void StopUsingCustomCoords();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual bool LoadFromTexture( CString sTexturePath, RageTexturePrefs prefs );
|
||||||
virtual bool LoadFromTexture( CString sTexturePath, bool bForceReload = false, int iMipMaps = 4, int iAlphaBits = 4, bool bDither = false, bool bStretch = false );
|
virtual bool LoadFromSpriteFile( CString sSpritePath, RageTexturePrefs prefs );
|
||||||
virtual bool LoadFromSpriteFile( CString sSpritePath, bool bForceReload = false, int iMipMaps = 4, int iAlphaBits = 4, bool bDither = false, bool bStretch = false );
|
|
||||||
|
|
||||||
virtual bool LoadTexture( CString sTexture, bool bForceReload = false, int iMipMaps = 4, int iAlphaBits = 4, bool bDither = false, bool bStretch = false );
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CString m_sSpritePath;
|
CString m_sSpritePath;
|
||||||
|
|||||||
Reference in New Issue
Block a user