2003-02-16 04:01:45 +00:00
|
|
|
#include "global.h"
|
2001-11-04 19:34:28 +00:00
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
File: RageTexture.h
|
|
|
|
|
|
|
|
|
|
Desc: Abstract class for a texture with metadata.
|
|
|
|
|
|
2002-05-19 01:59:48 +00:00
|
|
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
2001-11-04 19:34:28 +00:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
#include "RageTexture.h"
|
|
|
|
|
#include "RageUtil.h"
|
2002-12-30 03:35:58 +00:00
|
|
|
#include "RageTextureManager.h"
|
2002-05-27 18:36:01 +00:00
|
|
|
#include <string.h>
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-12-30 03:35:58 +00:00
|
|
|
void RageTextureID::Init()
|
|
|
|
|
{
|
2003-03-24 22:38:34 +00:00
|
|
|
/* Maximum size of the texture, per dimension. */
|
2002-12-30 03:35:58 +00:00
|
|
|
iMaxSize = 2048;
|
2003-03-24 22:38:34 +00:00
|
|
|
|
|
|
|
|
/* Number of mipmaps. (unimplemented) */
|
2002-12-30 03:35:58 +00:00
|
|
|
iMipMaps = 4;
|
2003-03-24 22:38:34 +00:00
|
|
|
|
|
|
|
|
/* Maximum number of bits for alpha. In 16-bit modes, lowering
|
|
|
|
|
* this gives more bits for color values. (0, 1 or 4) */
|
2002-12-30 03:35:58 +00:00
|
|
|
iAlphaBits = 4;
|
2003-03-24 22:38:34 +00:00
|
|
|
|
|
|
|
|
/* If true and color precision is being lost, dither. (slow) */
|
2002-12-30 03:35:58 +00:00
|
|
|
bDither = false;
|
2003-03-24 22:38:34 +00:00
|
|
|
/* If true, resize the image to fill the internal texture. (slow) */
|
2002-12-30 03:35:58 +00:00
|
|
|
bStretch = false;
|
2003-03-24 22:38:34 +00:00
|
|
|
|
|
|
|
|
/* Preferred color depth of the image. (This is overridden for
|
|
|
|
|
* paletted images and transparencies.) */
|
|
|
|
|
iColorDepth = -1; /* default */
|
|
|
|
|
|
|
|
|
|
/* If true, enable HOT PINK color keying. (deprecated but needed for
|
|
|
|
|
* banners) */
|
2003-01-22 04:15:43 +00:00
|
|
|
bHotPinkColorKey = false;
|
2003-03-24 22:38:34 +00:00
|
|
|
|
|
|
|
|
/* This indicates that the image is a transparency. This allows for
|
|
|
|
|
* high-resolution, memory-compact transparent layers. The diffuse
|
|
|
|
|
* color will be used with no texture color. (0, 4, 8) */
|
|
|
|
|
iTransparencyOnly = 0;
|
2002-12-30 03:35:58 +00:00
|
|
|
}
|
2002-11-11 04:53:31 +00:00
|
|
|
|
2003-02-12 22:32:04 +00:00
|
|
|
bool RageTextureID::operator<(const RageTextureID &rhs) const
|
2003-01-09 02:55:16 +00:00
|
|
|
{
|
2003-02-12 22:32:04 +00:00
|
|
|
if(filename < rhs.filename) return true;
|
|
|
|
|
if(filename > rhs.filename) return false;
|
|
|
|
|
if(iMaxSize < rhs.iMaxSize) return true;
|
|
|
|
|
if(iMaxSize > rhs.iMaxSize) return false;
|
|
|
|
|
if(iMipMaps < rhs.iMipMaps) return true;
|
|
|
|
|
if(iMipMaps > rhs.iMipMaps) return false;
|
|
|
|
|
if(iAlphaBits < rhs.iAlphaBits) return true;
|
|
|
|
|
if(iAlphaBits > rhs.iAlphaBits) return false;
|
|
|
|
|
if(iColorDepth < rhs.iColorDepth) return true;
|
|
|
|
|
if(iColorDepth > rhs.iColorDepth) return false;
|
|
|
|
|
if(bDither < rhs.bDither) return true;
|
|
|
|
|
if(bDither > rhs.bDither) return false;
|
|
|
|
|
if(bStretch < rhs.bStretch) return true;
|
|
|
|
|
if(bStretch > rhs.bStretch) return false;
|
|
|
|
|
if(bHotPinkColorKey < rhs.bHotPinkColorKey) return true;
|
|
|
|
|
if(bHotPinkColorKey > rhs.bHotPinkColorKey) return false;
|
|
|
|
|
return false;
|
2003-01-09 02:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-10 00:16:49 +00:00
|
|
|
bool RageTextureID::operator==(const RageTextureID &rhs) const
|
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
filename == rhs.filename &&
|
|
|
|
|
iMaxSize == rhs.iMaxSize &&
|
|
|
|
|
iMipMaps == rhs.iMipMaps &&
|
|
|
|
|
iAlphaBits == rhs.iAlphaBits &&
|
|
|
|
|
iColorDepth == rhs.iColorDepth &&
|
|
|
|
|
bDither == rhs.bDither &&
|
|
|
|
|
bStretch == rhs.bStretch &&
|
|
|
|
|
bHotPinkColorKey == rhs.bHotPinkColorKey;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-09 02:55:16 +00:00
|
|
|
|
2003-01-26 00:56:13 +00:00
|
|
|
RageTexture::RageTexture( RageTextureID name ):
|
|
|
|
|
m_ID(name)
|
2001-11-03 10:52:42 +00:00
|
|
|
{
|
2002-07-31 19:40:40 +00:00
|
|
|
// LOG->Trace( "RageTexture::RageTexture()" );
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
m_iRefCount = 1;
|
|
|
|
|
|
2003-01-26 00:56:13 +00:00
|
|
|
SetActualID();
|
2002-03-30 20:00:13 +00:00
|
|
|
m_iSourceWidth = m_iSourceHeight = 0;
|
|
|
|
|
m_iTextureWidth = m_iTextureHeight = 0;
|
|
|
|
|
m_iImageWidth = m_iImageHeight = 0;
|
2002-11-11 04:53:31 +00:00
|
|
|
m_iFramesWide = m_iFramesHigh = 0;
|
2001-11-03 10:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
2003-01-26 00:56:13 +00:00
|
|
|
|
|
|
|
|
/* Set the initial ActualID; this is what the actual texture will start
|
|
|
|
|
* from. */
|
|
|
|
|
void RageTexture::SetActualID()
|
|
|
|
|
{
|
|
|
|
|
m_ActualID = m_ID;
|
|
|
|
|
|
|
|
|
|
/* Texture color depth preference can be overridden. */
|
|
|
|
|
if(m_ID.iColorDepth == -1)
|
|
|
|
|
m_ActualID.iColorDepth = TEXTUREMAN->GetTextureColorDepth();
|
|
|
|
|
|
|
|
|
|
/* The max texture size can never be higher than the preference,
|
|
|
|
|
* since it might be set to something to fix driver problems. */
|
|
|
|
|
m_ActualID.iMaxSize = min(m_ActualID.iMaxSize, TEXTUREMAN->GetMaxTextureResolution());
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-03 10:52:42 +00:00
|
|
|
RageTexture::~RageTexture()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-25 23:22:20 +00:00
|
|
|
void RageTexture::CreateFrameRects()
|
2001-11-03 10:52:42 +00:00
|
|
|
{
|
2002-12-30 02:43:52 +00:00
|
|
|
GetFrameDimensionsFromFileName( GetFilePath(), &m_iFramesWide, &m_iFramesHigh );
|
2001-11-25 04:31:44 +00:00
|
|
|
|
2001-11-03 10:52:42 +00:00
|
|
|
///////////////////////////////////
|
|
|
|
|
// Fill in the m_FrameRects with the bounds of each frame in the animation.
|
|
|
|
|
///////////////////////////////////
|
2002-10-24 20:15:24 +00:00
|
|
|
m_TextureCoordRects.clear();
|
2002-05-28 20:01:22 +00:00
|
|
|
|
2002-03-30 20:00:13 +00:00
|
|
|
for( int j=0; j<m_iFramesHigh; j++ ) // traverse along Y
|
2001-11-03 10:52:42 +00:00
|
|
|
{
|
2002-03-30 20:00:13 +00:00
|
|
|
for( int i=0; i<m_iFramesWide; i++ ) // traverse along X (important that this is the inner loop)
|
2001-11-03 10:52:42 +00:00
|
|
|
{
|
2002-10-31 06:00:30 +00:00
|
|
|
RectF frect( (i+0)/(float)m_iFramesWide*m_iImageWidth /(float)m_iTextureWidth, // these will all be between 0.0 and 1.0
|
2002-03-30 20:00:13 +00:00
|
|
|
(j+0)/(float)m_iFramesHigh*m_iImageHeight/(float)m_iTextureHeight,
|
|
|
|
|
(i+1)/(float)m_iFramesWide*m_iImageWidth /(float)m_iTextureWidth,
|
|
|
|
|
(j+1)/(float)m_iFramesHigh*m_iImageHeight/(float)m_iTextureHeight );
|
2002-10-31 04:23:39 +00:00
|
|
|
m_TextureCoordRects.push_back( frect ); // the index of this array element will be (i + j*m_iFramesWide)
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-07-31 19:40:40 +00:00
|
|
|
//LOG->Trace( "Adding frect%d %f %f %f %f", (i + j*m_iFramesWide), frect.left, frect.top, frect.right, frect.bottom );
|
2001-11-03 10:52:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-05 01:44:24 +00:00
|
|
|
void RageTexture::GetFrameDimensionsFromFileName( CString sPath, int* piFramesWide, int* piFramesHigh )
|
2001-11-03 10:52:42 +00:00
|
|
|
{
|
2002-03-30 20:00:13 +00:00
|
|
|
*piFramesWide = *piFramesHigh = 1; // set default values in case we don't find the dimension in the file name
|
2001-12-28 10:15:59 +00:00
|
|
|
|
|
|
|
|
sPath.MakeLower();
|
|
|
|
|
|
|
|
|
|
CString sDir, sFName, sExt;
|
|
|
|
|
splitrelpath( sPath, sDir, sFName, sExt);
|
|
|
|
|
|
2002-01-28 21:24:17 +00:00
|
|
|
CStringArray arrayBits;
|
|
|
|
|
split( sFName, " ", arrayBits, false );
|
2001-12-28 10:15:59 +00:00
|
|
|
|
2003-01-05 01:44:24 +00:00
|
|
|
/* XXX: allow dims to be in parens */
|
2002-10-31 03:16:02 +00:00
|
|
|
for( unsigned i=0; i<arrayBits.size(); i++ )
|
2002-01-28 21:24:17 +00:00
|
|
|
{
|
|
|
|
|
CString &sBit = arrayBits[ i ];
|
|
|
|
|
|
|
|
|
|
// Test to see if it looks like "%ux%u" (e.g. 16x8)
|
2001-12-28 10:15:59 +00:00
|
|
|
|
2002-01-28 21:24:17 +00:00
|
|
|
CStringArray arrayDimensionsBits;
|
|
|
|
|
split( sBit, "x", arrayDimensionsBits, false );
|
2001-12-28 10:15:59 +00:00
|
|
|
|
2002-10-31 03:16:02 +00:00
|
|
|
if( arrayDimensionsBits.size() != 2 )
|
2002-01-28 21:24:17 +00:00
|
|
|
continue;
|
|
|
|
|
else if( !IsAnInt(arrayDimensionsBits[0]) || !IsAnInt(arrayDimensionsBits[1]) )
|
|
|
|
|
continue;
|
2001-12-28 10:15:59 +00:00
|
|
|
|
2002-03-30 20:00:13 +00:00
|
|
|
*piFramesWide = atoi(arrayDimensionsBits[0]);
|
|
|
|
|
*piFramesHigh = atoi(arrayDimensionsBits[1]);
|
2001-12-28 10:15:59 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-27 08:23:27 +00:00
|
|
|
}
|
2002-11-11 04:53:31 +00:00
|
|
|
|
2003-01-06 11:14:43 +00:00
|
|
|
int RageTexture::GetFrameCountFromFileName( CString sPath )
|
|
|
|
|
{
|
|
|
|
|
int wide, high;
|
|
|
|
|
GetFrameDimensionsFromFileName(sPath, &wide, &high );
|
|
|
|
|
return wide*high;
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
const RectF *RageTexture::GetTextureCoordRect( int frameNo ) const
|
|
|
|
|
{
|
|
|
|
|
return &m_TextureCoordRects[frameNo];
|
|
|
|
|
}
|
|
|
|
|
|