Files
itgmania212121/stepmania/src/RageTexture.cpp
T

198 lines
5.5 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
/*
-----------------------------------------------------------------------------
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-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()
{
/* Maximum size of the texture, per dimension. */
2002-12-30 03:35:58 +00:00
iMaxSize = 2048;
/* Number of mipmaps. (unimplemented) */
2002-12-30 03:35:58 +00:00
iMipMaps = 4;
/* 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-10-08 02:19:59 +00:00
/* If this is greater than -1, then the image will be loaded as a luma/alpha
* map, eg. I4A4. At most 8 bits per pixel will be used This only actually happens
* when paletted textures are supported.
*
* If the sum of alpha and grayscale bits is <= 4, and the system supports 4-bit
* palettes, then the image will be loaded with 4bpp.
*
* This may be set to 0, resulting in an alpha map with all pixels white. */
iGrayscaleBits = -1;
/* If true and color precision is being lost, dither. (slow) */
2002-12-30 03:35:58 +00:00
bDither = false;
/* If true, resize the image to fill the internal texture. (slow) */
2002-12-30 03:35:58 +00:00
bStretch = false;
/* 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-10-08 02:52:12 +00:00
/* These hints will be used in addition to any in the filename. */
AdditionalTextureHints = "";
2002-12-30 03:35:58 +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-05-05 03:03:53 +00:00
#define COMP(a) if(a<rhs.a) return true; if(a>rhs.a) return false;
COMP(filename);
COMP(iMaxSize);
COMP(iMipMaps);
COMP(iAlphaBits);
2003-10-08 02:19:59 +00:00
COMP(iGrayscaleBits);
2003-05-05 03:03:53 +00:00
COMP(iColorDepth);
COMP(bDither);
COMP(bStretch);
COMP(bHotPinkColorKey);
2003-10-08 02:52:12 +00:00
COMP(AdditionalTextureHints);
2003-05-05 03:03:53 +00:00
#undef COMP
2003-02-12 22:32:04 +00:00
return false;
2003-01-09 02:55:16 +00:00
}
bool RageTextureID::operator==(const RageTextureID &rhs) const
{
2003-06-05 19:29:27 +00:00
#define EQUAL(a) (a==rhs.a)
return
2003-06-05 19:29:27 +00:00
EQUAL(filename) &&
EQUAL(iMaxSize) &&
EQUAL(iMipMaps) &&
EQUAL(iAlphaBits) &&
2003-10-08 02:19:59 +00:00
EQUAL(iGrayscaleBits) &&
2003-06-05 19:29:27 +00:00
EQUAL(iColorDepth) &&
EQUAL(bDither) &&
EQUAL(bStretch) &&
2003-10-08 02:52:12 +00:00
EQUAL(bHotPinkColorKey) &&
EQUAL(AdditionalTextureHints);
}
2003-01-09 02:55:16 +00:00
RageTexture::RageTexture( RageTextureID name ):
m_ID(name)
2001-11-03 10:52:42 +00:00
{
// LOG->Trace( "RageTexture::RageTexture()" );
2001-11-03 10:52:42 +00:00
m_iRefCount = 1;
2003-06-10 19:24:00 +00:00
m_Policy = TEX_DEFAULT;
m_bWasUsed = false;
2001-11-03 10:52:42 +00:00
2003-05-22 05:28:37 +00:00
// SetActualID();
m_iSourceWidth = m_iSourceHeight = 0;
m_iTextureWidth = m_iTextureHeight = 0;
m_iImageWidth = m_iImageHeight = 0;
m_iFramesWide = m_iFramesHigh = 0;
2001-11-03 10:52:42 +00:00
}
/* Set the initial ActualID; this is what the actual texture will start
* from. */
2003-05-22 05:28:37 +00:00
//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()
{
}
void RageTexture::CreateFrameRects()
2001-11-03 10:52:42 +00:00
{
2003-06-05 19:29:27 +00:00
GetFrameDimensionsFromFileName( GetID().filename, &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
for( int j=0; j<m_iFramesHigh; j++ ) // traverse along Y
2001-11-03 10:52:42 +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
(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
//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
}
}
}
void RageTexture::GetFrameDimensionsFromFileName( CString sPath, int* piFramesWide, int* piFramesHigh )
2001-11-03 10:52:42 +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
/* XXX: allow dims to be in parens */
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
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
*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
}
2003-01-06 11:14:43 +00:00
int RageTexture::GetFrameCountFromFileName( CString sPath )
{
int wide, high;
GetFrameDimensionsFromFileName(sPath, &wide, &high );
return wide*high;
}
const RectF *RageTexture::GetTextureCoordRect( int frameNo ) const
{
return &m_TextureCoordRects[frameNo];
}