make Quad less special. Create a "default" texture object for the
"no texture" properties. This way, loaded sprites always have a texture loaded.
This commit is contained in:
@@ -1,12 +1,15 @@
|
|||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "Quad.h"
|
#include "Quad.h"
|
||||||
#include "ActorUtil.h"
|
#include "ActorUtil.h"
|
||||||
|
#include "RageTextureManager.h"
|
||||||
|
|
||||||
REGISTER_ACTOR_CLASS( Quad )
|
REGISTER_ACTOR_CLASS( Quad )
|
||||||
|
|
||||||
|
|
||||||
void Quad::LoadFromNode( const XNode* pNode )
|
void Quad::LoadFromNode( const XNode* pNode )
|
||||||
{
|
{
|
||||||
|
Load( TEXTUREMAN->GetDefaultTextureID() );
|
||||||
|
|
||||||
// HACK: Bypass Sprite's texture loading. Sprite should really derive from Quad.
|
// HACK: Bypass Sprite's texture loading. Sprite should really derive from Quad.
|
||||||
Actor::LoadFromNode( pNode );
|
Actor::LoadFromNode( pNode );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,6 @@
|
|||||||
class Quad : public Sprite
|
class Quad : public Sprite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Quad()
|
|
||||||
{
|
|
||||||
SetDrawIfTextureNull( true );
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadFromNode( const XNode* pNode );
|
void LoadFromNode( const XNode* pNode );
|
||||||
virtual Quad *Copy() const;
|
virtual Quad *Copy() const;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -194,6 +194,9 @@ public:
|
|||||||
RageSurface* img, // must be in pixfmt
|
RageSurface* img, // must be in pixfmt
|
||||||
bool bGenerateMipMaps
|
bool bGenerateMipMaps
|
||||||
) = 0;
|
) = 0;
|
||||||
|
/* Return a texture handle to the default texture, an opaque, all-white,
|
||||||
|
* immutable texture. Deleting or updating this texture has no effect. */
|
||||||
|
virtual unsigned CreateTextureDefault() = 0;
|
||||||
virtual void UpdateTexture(
|
virtual void UpdateTexture(
|
||||||
unsigned iTexHandle,
|
unsigned iTexHandle,
|
||||||
RageSurface* img,
|
RageSurface* img,
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public:
|
|||||||
PixelFormat pixfmt,
|
PixelFormat pixfmt,
|
||||||
RageSurface* img,
|
RageSurface* img,
|
||||||
bool bGenerateMipMaps ) { return 1; }
|
bool bGenerateMipMaps ) { return 1; }
|
||||||
|
unsigned CreateTextureDefault() { return 0; }
|
||||||
void UpdateTexture(
|
void UpdateTexture(
|
||||||
unsigned iTexHandle,
|
unsigned iTexHandle,
|
||||||
RageSurface* img,
|
RageSurface* img,
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ public:
|
|||||||
PixelFormat pixfmt,
|
PixelFormat pixfmt,
|
||||||
RageSurface* img,
|
RageSurface* img,
|
||||||
bool bGenerateMipMaps );
|
bool bGenerateMipMaps );
|
||||||
|
unsigned CreateTextureDefault() { return 0; }
|
||||||
void UpdateTexture(
|
void UpdateTexture(
|
||||||
unsigned iTexHandle,
|
unsigned iTexHandle,
|
||||||
RageSurface* img,
|
RageSurface* img,
|
||||||
|
|||||||
@@ -89,6 +89,30 @@ void RageTextureManager::RegisterTexture( RageTextureID ID, RageTexture *pTextur
|
|||||||
m_mapPathToTexture[ID] = pTexture;
|
m_mapPathToTexture[ID] = pTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const RString g_sDefaultTextureName = "__blank__";
|
||||||
|
RageTextureID RageTextureManager::GetDefaultTextureID()
|
||||||
|
{
|
||||||
|
return RageTextureID( g_sDefaultTextureName );
|
||||||
|
}
|
||||||
|
|
||||||
|
class RageTexture_Default: public RageTexture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RageTexture_Default():
|
||||||
|
RageTexture( RageTextureID() )
|
||||||
|
{
|
||||||
|
m_uTexHandle = DISPLAY->CreateTextureDefault();
|
||||||
|
m_iSourceWidth = m_iSourceHeight = 1;
|
||||||
|
m_iTextureWidth = m_iTextureHeight = 1;
|
||||||
|
m_iImageWidth = m_iImageHeight = 1;
|
||||||
|
CreateFrameRects();
|
||||||
|
}
|
||||||
|
unsigned GetTexHandle() const { return m_uTexHandle; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned m_uTexHandle;
|
||||||
|
};
|
||||||
|
|
||||||
// Load and unload textures from disk.
|
// Load and unload textures from disk.
|
||||||
RageTexture* RageTextureManager::LoadTextureInternal( RageTextureID ID )
|
RageTexture* RageTextureManager::LoadTextureInternal( RageTextureID ID )
|
||||||
{
|
{
|
||||||
@@ -112,7 +136,9 @@ RageTexture* RageTextureManager::LoadTextureInternal( RageTextureID ID )
|
|||||||
sExt.MakeLower();
|
sExt.MakeLower();
|
||||||
|
|
||||||
RageTexture* pTexture;
|
RageTexture* pTexture;
|
||||||
if( sExt == "avi" || sExt == "mpg" || sExt == "mpeg" )
|
if( ID.filename == g_sDefaultTextureName )
|
||||||
|
pTexture = new RageTexture_Default;
|
||||||
|
else if( sExt == "avi" || sExt == "mpg" || sExt == "mpeg" )
|
||||||
pTexture = RageMovieTexture::Create( ID );
|
pTexture = RageMovieTexture::Create( ID );
|
||||||
else
|
else
|
||||||
pTexture = new RageBitmapTexture( ID );
|
pTexture = new RageBitmapTexture( ID );
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ public:
|
|||||||
void EnableOddDimensionWarning() { m_iNoWarnAboutOddDimensions--; }
|
void EnableOddDimensionWarning() { m_iNoWarnAboutOddDimensions--; }
|
||||||
bool GetOddDimensionWarning() const { return m_iNoWarnAboutOddDimensions == 0; }
|
bool GetOddDimensionWarning() const { return m_iNoWarnAboutOddDimensions == 0; }
|
||||||
|
|
||||||
|
RageTextureID GetDefaultTextureID();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DeleteTexture( RageTexture *t );
|
void DeleteTexture( RageTexture *t );
|
||||||
enum GCType { screen_changed, delayed_delete };
|
enum GCType { screen_changed, delayed_delete };
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ REGISTER_ACTOR_CLASS( Sprite )
|
|||||||
Sprite::Sprite()
|
Sprite::Sprite()
|
||||||
{
|
{
|
||||||
m_pTexture = NULL;
|
m_pTexture = NULL;
|
||||||
m_bDrawIfTextureNull = false;
|
|
||||||
m_iCurState = 0;
|
m_iCurState = 0;
|
||||||
m_fSecsIntoState = 0.0f;
|
m_fSecsIntoState = 0.0f;
|
||||||
m_bUsingCustomTexCoords = false;
|
m_bUsingCustomTexCoords = false;
|
||||||
@@ -43,7 +42,6 @@ Sprite::Sprite( const Sprite &cpy ):
|
|||||||
Actor( cpy )
|
Actor( cpy )
|
||||||
{
|
{
|
||||||
#define CPY(a) a = cpy.a
|
#define CPY(a) a = cpy.a
|
||||||
CPY( m_bDrawIfTextureNull );
|
|
||||||
CPY( m_States );
|
CPY( m_States );
|
||||||
CPY( m_iCurState );
|
CPY( m_iCurState );
|
||||||
CPY( m_fSecsIntoState );
|
CPY( m_fSecsIntoState );
|
||||||
@@ -557,7 +555,7 @@ void Sprite::DrawTexture( const TweenState *state )
|
|||||||
|
|
||||||
bool Sprite::EarlyAbortDraw() const
|
bool Sprite::EarlyAbortDraw() const
|
||||||
{
|
{
|
||||||
return m_pTexture == NULL && !m_bDrawIfTextureNull;
|
return m_pTexture == NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite::DrawPrimitives()
|
void Sprite::DrawPrimitives()
|
||||||
|
|||||||
@@ -67,16 +67,14 @@ public:
|
|||||||
virtual void PushSelf( lua_State *L );
|
virtual void PushSelf( lua_State *L );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void SetDrawIfTextureNull( bool b ) { m_bDrawIfTextureNull = b; }
|
void LoadFromTexture( RageTextureID ID );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void LoadFromTexture( RageTextureID ID );
|
|
||||||
void LoadStatesFromTexture();
|
void LoadStatesFromTexture();
|
||||||
|
|
||||||
void DrawTexture( const TweenState *state );
|
void DrawTexture( const TweenState *state );
|
||||||
|
|
||||||
RageTexture* m_pTexture;
|
RageTexture* m_pTexture;
|
||||||
bool m_bDrawIfTextureNull;
|
|
||||||
|
|
||||||
struct State
|
struct State
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user