Make RageBitmapTexture:m_ID private (so it can't be modified)
This commit is contained in:
@@ -78,6 +78,8 @@ void RageBitmapTexture::Reload()
|
|||||||
*/
|
*/
|
||||||
void RageBitmapTexture::Create()
|
void RageBitmapTexture::Create()
|
||||||
{
|
{
|
||||||
|
RageTextureID actualID = GetID();
|
||||||
|
|
||||||
/* Create (and return) a surface ready to be loaded to OpenGL */
|
/* Create (and return) a surface ready to be loaded to OpenGL */
|
||||||
/* Load the image into an SDL surface. */
|
/* Load the image into an SDL surface. */
|
||||||
SDL_Surface *img = IMG_Load(GetFilePath());
|
SDL_Surface *img = IMG_Load(GetFilePath());
|
||||||
@@ -87,7 +89,7 @@ void RageBitmapTexture::Create()
|
|||||||
if(img == NULL)
|
if(img == NULL)
|
||||||
RageException::Throw( "RageBitmapTexture: Couldn't load %s: %s", GetFilePath().c_str(), SDL_GetError() );
|
RageException::Throw( "RageBitmapTexture: Couldn't load %s: %s", GetFilePath().c_str(), SDL_GetError() );
|
||||||
|
|
||||||
if(m_ID.bHotPinkColorKey)
|
if(actualID.bHotPinkColorKey)
|
||||||
{
|
{
|
||||||
/* Annoying: SDL will do a nearest-match on paletted images if
|
/* Annoying: SDL will do a nearest-match on paletted images if
|
||||||
* they don't have the color we ask for, so images without HOT PINK
|
* they don't have the color we ask for, so images without HOT PINK
|
||||||
@@ -112,46 +114,43 @@ void RageBitmapTexture::Create()
|
|||||||
* TRAIT_NO_TRANSPARENCY if the color key is never used. */
|
* TRAIT_NO_TRANSPARENCY if the color key is never used. */
|
||||||
int traits = FindSurfaceTraits(img);
|
int traits = FindSurfaceTraits(img);
|
||||||
if(traits & TRAIT_NO_TRANSPARENCY)
|
if(traits & TRAIT_NO_TRANSPARENCY)
|
||||||
m_ID.iAlphaBits = 0;
|
actualID.iAlphaBits = 0;
|
||||||
else if(traits & TRAIT_BOOL_TRANSPARENCY)
|
else if(traits & TRAIT_BOOL_TRANSPARENCY)
|
||||||
m_ID.iAlphaBits = 1;
|
actualID.iAlphaBits = 1;
|
||||||
if(traits & TRAIT_WHITE_ONLY)
|
if(traits & TRAIT_WHITE_ONLY)
|
||||||
m_ID.iTransparencyOnly = 8;
|
actualID.iTransparencyOnly = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
// look in the file name for a format hints
|
// look in the file name for a format hints
|
||||||
CString HintString = GetFilePath();
|
CString HintString = GetFilePath();
|
||||||
HintString.MakeLower();
|
HintString.MakeLower();
|
||||||
|
|
||||||
if( HintString.Find("4alphaonly") != -1 ) m_ID.iTransparencyOnly = 4;
|
if( HintString.Find("4alphaonly") != -1 ) actualID.iTransparencyOnly = 4;
|
||||||
else if( HintString.Find("8alphaonly") != -1 ) m_ID.iTransparencyOnly = 8;
|
else if( HintString.Find("8alphaonly") != -1 ) actualID.iTransparencyOnly = 8;
|
||||||
if( HintString.Find("dither") != -1 ) m_ID.bDither = true;
|
if( HintString.Find("dither") != -1 ) actualID.bDither = true;
|
||||||
|
|
||||||
if( m_ID.iTransparencyOnly )
|
if( actualID.iTransparencyOnly )
|
||||||
m_ID.iColorDepth = 32; /* Treat the image as 32-bit, so we don't lose any alpha precision. */
|
actualID.iColorDepth = 32; /* Treat the image as 32-bit, so we don't lose any alpha precision. */
|
||||||
|
|
||||||
/* Cap the max texture size to the hardware max. */
|
/* Cap the max texture size to the hardware max. */
|
||||||
m_ID.iMaxSize = min( m_ID.iMaxSize, DISPLAY->GetMaxTextureSize() );
|
actualID.iMaxSize = min( actualID.iMaxSize, DISPLAY->GetMaxTextureSize() );
|
||||||
|
|
||||||
/* Save information about the source. */
|
/* Save information about the source. */
|
||||||
m_iSourceWidth = img->w;
|
m_iSourceWidth = img->w;
|
||||||
m_iSourceHeight = img->h;
|
m_iSourceHeight = img->h;
|
||||||
|
|
||||||
/* See if the apparent "size" is being overridden. */
|
|
||||||
GetResolutionFromFileName(m_ID.filename, m_iSourceWidth, m_iSourceHeight);
|
|
||||||
|
|
||||||
/* image size cannot exceed max size */
|
/* image size cannot exceed max size */
|
||||||
m_iImageWidth = min( m_iSourceWidth, m_ID.iMaxSize );
|
m_iImageWidth = min( m_iSourceWidth, actualID.iMaxSize );
|
||||||
m_iImageHeight = min( m_iSourceHeight, m_ID.iMaxSize );
|
m_iImageHeight = min( m_iSourceHeight, actualID.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(m_iImageWidth);
|
m_iTextureWidth = power_of_two(m_iImageWidth);
|
||||||
m_iTextureHeight = power_of_two(m_iImageHeight);
|
m_iTextureHeight = power_of_two(m_iImageHeight);
|
||||||
|
|
||||||
ASSERT( m_iTextureWidth <= m_ID.iMaxSize );
|
ASSERT( m_iTextureWidth <= actualID.iMaxSize );
|
||||||
ASSERT( m_iTextureHeight <= m_ID.iMaxSize );
|
ASSERT( m_iTextureHeight <= actualID.iMaxSize );
|
||||||
|
|
||||||
if(m_ID.bStretch)
|
if(actualID.bStretch)
|
||||||
{
|
{
|
||||||
/* The hints asked for the image to be stretched to the texture size,
|
/* The hints asked for the image to be stretched to the texture size,
|
||||||
* probably for tiling. */
|
* probably for tiling. */
|
||||||
@@ -169,8 +168,6 @@ void RageBitmapTexture::Create()
|
|||||||
// Format of the image that we will pass to OpenGL and that we want OpenGL to use
|
// Format of the image that we will pass to OpenGL and that we want OpenGL to use
|
||||||
PixelFormat pixfmt;
|
PixelFormat pixfmt;
|
||||||
|
|
||||||
SDL_SaveBMP( img, "testing.bmp" );
|
|
||||||
|
|
||||||
/* Figure out which texture format to use. */
|
/* Figure out which texture format to use. */
|
||||||
// if the source is palleted, load palleted no matter what the prefs
|
// if the source is palleted, load palleted no matter what the prefs
|
||||||
if(img->format->BitsPerPixel == 8 && DISPLAY->SupportsTextureFormat(FMT_PAL))
|
if(img->format->BitsPerPixel == 8 && DISPLAY->SupportsTextureFormat(FMT_PAL))
|
||||||
@@ -180,7 +177,7 @@ void RageBitmapTexture::Create()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// not paletted
|
// not paletted
|
||||||
switch( m_ID.iColorDepth )
|
switch( actualID.iColorDepth )
|
||||||
{
|
{
|
||||||
case 16:
|
case 16:
|
||||||
{
|
{
|
||||||
@@ -196,7 +193,7 @@ void RageBitmapTexture::Create()
|
|||||||
src_alpha_bits = max( 1, src_alpha_bits );
|
src_alpha_bits = max( 1, src_alpha_bits );
|
||||||
|
|
||||||
/* Don't use more than we were hinted to. */
|
/* Don't use more than we were hinted to. */
|
||||||
src_alpha_bits = min( m_ID.iAlphaBits, src_alpha_bits );
|
src_alpha_bits = min( actualID.iAlphaBits, src_alpha_bits );
|
||||||
|
|
||||||
switch( src_alpha_bits ) {
|
switch( src_alpha_bits ) {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -213,7 +210,7 @@ void RageBitmapTexture::Create()
|
|||||||
pixfmt = FMT_RGBA8;
|
pixfmt = FMT_RGBA8;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
RageException::Throw( "Invalid color depth: %d bits", m_ID.iColorDepth );
|
RageException::Throw( "Invalid color depth: %d bits", actualID.iColorDepth );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Override the internalformat with an alpha format if it was requested.
|
/* Override the internalformat with an alpha format if it was requested.
|
||||||
@@ -221,7 +218,7 @@ void RageBitmapTexture::Create()
|
|||||||
* images are as small or smaller (and the load will fail). */
|
* images are as small or smaller (and the load will fail). */
|
||||||
/* SDL surfaces don't allow for 8 bpp surfaces that aren't paletted. Arg!
|
/* SDL surfaces don't allow for 8 bpp surfaces that aren't paletted. Arg!
|
||||||
* fix this later. -Chris */
|
* fix this later. -Chris */
|
||||||
// if(m_ID.iTransparencyOnly > 0)
|
// if(actualID.iTransparencyOnly > 0)
|
||||||
// {
|
// {
|
||||||
// imagePixfmt = FMT_ALPHA8;
|
// imagePixfmt = FMT_ALPHA8;
|
||||||
// texturePixfmt = FMT_ALPHA8;
|
// texturePixfmt = FMT_ALPHA8;
|
||||||
@@ -229,7 +226,7 @@ void RageBitmapTexture::Create()
|
|||||||
|
|
||||||
/* It's either not a paletted image, or we can't handle paletted textures.
|
/* It's either not a paletted image, or we can't handle paletted textures.
|
||||||
* Convert to the desired RGBA format, dithering if appropriate. */
|
* Convert to the desired RGBA format, dithering if appropriate. */
|
||||||
if( m_ID.bDither &&
|
if( actualID.bDither &&
|
||||||
(pixfmt==FMT_RGBA4 || pixfmt==FMT_RGB5A1) ) /* Don't dither if format is 32bpp; there's no point. */
|
(pixfmt==FMT_RGBA4 || pixfmt==FMT_RGB5A1) ) /* Don't dither if format is 32bpp; there's no point. */
|
||||||
{
|
{
|
||||||
/* Dither down to the destination format. */
|
/* Dither down to the destination format. */
|
||||||
@@ -243,52 +240,39 @@ void RageBitmapTexture::Create()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_SaveBMP( img, "testing.bmp" );
|
|
||||||
|
|
||||||
/* This needs to be done *after* the final resize, since that resize
|
/* This needs to be done *after* the final resize, since that resize
|
||||||
* may introduce new alpha bits that need to be set. It needs to be
|
* may introduce new alpha bits that need to be set. It needs to be
|
||||||
* done *before* we set up the palette, since it might change it. */
|
* done *before* we set up the palette, since it might change it. */
|
||||||
FixHiddenAlpha(img);
|
FixHiddenAlpha(img);
|
||||||
|
|
||||||
SDL_SaveBMP( img, "testing.bmp" );
|
|
||||||
|
|
||||||
/* Convert the data to the destination format and dimensions
|
/* Convert the data to the destination format and dimensions
|
||||||
* required by OpenGL if it's not in it already. */
|
* required by OpenGL if it's not in it already. */
|
||||||
ConvertSDLSurface(img, m_iTextureWidth, m_iTextureHeight, PIXEL_FORMAT_DESC[pixfmt].bpp,
|
ConvertSDLSurface(img, m_iTextureWidth, m_iTextureHeight, PIXEL_FORMAT_DESC[pixfmt].bpp,
|
||||||
PIXEL_FORMAT_DESC[pixfmt].masks[0], PIXEL_FORMAT_DESC[pixfmt].masks[1],
|
PIXEL_FORMAT_DESC[pixfmt].masks[0], PIXEL_FORMAT_DESC[pixfmt].masks[1],
|
||||||
PIXEL_FORMAT_DESC[pixfmt].masks[2], PIXEL_FORMAT_DESC[pixfmt].masks[3]);
|
PIXEL_FORMAT_DESC[pixfmt].masks[2], PIXEL_FORMAT_DESC[pixfmt].masks[3]);
|
||||||
|
|
||||||
SDL_SaveBMP( img, "testing.bmp" );
|
|
||||||
|
|
||||||
m_uTexHandle = DISPLAY->CreateTexture( pixfmt, img );
|
m_uTexHandle = DISPLAY->CreateTexture( pixfmt, img );
|
||||||
|
|
||||||
SDL_FreeSurface( img );
|
SDL_FreeSurface( img );
|
||||||
|
|
||||||
CreateFrameRects();
|
CreateFrameRects();
|
||||||
|
|
||||||
/*
|
/* See if the apparent "size" is being overridden. */
|
||||||
|
GetResolutionFromFileName(actualID.filename, m_iSourceWidth, m_iSourceHeight);
|
||||||
|
|
||||||
|
|
||||||
CString props = " ";
|
CString props = " ";
|
||||||
switch( pixfmt )
|
props += PixelFormatToString( pixfmt );
|
||||||
{
|
if(actualID.iAlphaBits == 0) props += "opaque ";
|
||||||
case FMT_RGBA4: props += "FMT_RGBA4 "; break;
|
if(actualID.iAlphaBits == 1) props += "matte ";
|
||||||
case FMT_RGBA8: props += "FMT_RGBA8 "; break;
|
if(actualID.iTransparencyOnly) props += "mask ";
|
||||||
case FMT_RGB5A1: props += "FMT_RGB5A1 "; break;
|
if(actualID.bStretch) props += "stretch ";
|
||||||
case FMT_ALPHA8: props += "FMT_ALPHA8 "; break;
|
if(actualID.bDither) props += "dither ";
|
||||||
case FMT_PAL: props += "FMT_PAL "; break;
|
|
||||||
default: ASSERT(0); break;
|
|
||||||
}
|
|
||||||
if(m_ID.iAlphaBits == 0) props += "opaque ";
|
|
||||||
if(m_ID.iAlphaBits == 1) props += "matte ";
|
|
||||||
if(m_ID.iTransparencyOnly) props += "mask ";
|
|
||||||
if(m_ID.bStretch) props += "stretch ";
|
|
||||||
if(m_ID.bDither) props += "dither ";
|
|
||||||
if(IsPackedPixelFormat(pixfmt)) props += "paletted ";
|
|
||||||
props.erase(props.size()-1);
|
props.erase(props.size()-1);
|
||||||
LOG->Trace( "RageBitmapTexture: Loaded '%s' (%ux%u); %s, source %d,%d; image %d,%d.",
|
LOG->Trace( "RageBitmapTexture: Loaded '%s' (%ux%u); %s, source %d,%d; image %d,%d.",
|
||||||
m_ID.filename.c_str(), GetTextureWidth(), GetTextureHeight(),
|
actualID.filename.c_str(), GetTextureWidth(), GetTextureHeight(),
|
||||||
props.c_str(), m_iSourceWidth, m_iSourceHeight,
|
props.c_str(), m_iSourceWidth, m_iSourceHeight,
|
||||||
m_iImageWidth, m_iImageHeight);
|
m_iImageWidth, m_iImageHeight);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageBitmapTexture::Destroy()
|
void RageBitmapTexture::Destroy()
|
||||||
|
|||||||
@@ -46,10 +46,22 @@ enum PixelFormat {
|
|||||||
FMT_PAL,
|
FMT_PAL,
|
||||||
NUM_PIX_FORMATS
|
NUM_PIX_FORMATS
|
||||||
};
|
};
|
||||||
|
inline CString PixelFormatToString( PixelFormat pixfmt )
|
||||||
|
{
|
||||||
|
const CString s[NUM_PIX_FORMATS] = {
|
||||||
|
"FMT_RGBA8",
|
||||||
|
"FMT_RGBA4",
|
||||||
|
"FMT_RGB5A1",
|
||||||
|
"FMT_RGB5",
|
||||||
|
"FMT_RGB8",
|
||||||
|
"FMT_PAL" };
|
||||||
|
return s[pixfmt];
|
||||||
|
};
|
||||||
struct PixelFormatDesc {
|
struct PixelFormatDesc {
|
||||||
int bpp;
|
int bpp;
|
||||||
unsigned int masks[4];
|
unsigned int masks[4];
|
||||||
};
|
};
|
||||||
|
/* This is info is different for OGL and D3D. */
|
||||||
extern const PixelFormatDesc PIXEL_FORMAT_DESC[NUM_PIX_FORMATS];
|
extern const PixelFormatDesc PIXEL_FORMAT_DESC[NUM_PIX_FORMATS];
|
||||||
|
|
||||||
class RageDisplay
|
class RageDisplay
|
||||||
|
|||||||
@@ -93,11 +93,15 @@ public:
|
|||||||
static void GetFrameDimensionsFromFileName( CString sPath, int* puFramesWide, int* puFramesHigh );
|
static void GetFrameDimensionsFromFileName( CString sPath, int* puFramesWide, int* puFramesHigh );
|
||||||
static int GetFrameCountFromFileName( CString sPath );
|
static int GetFrameCountFromFileName( CString sPath );
|
||||||
|
|
||||||
protected:
|
const RageTextureID& GetID() { return m_ID; }
|
||||||
|
|
||||||
|
private:
|
||||||
/* We might change settings when loading (due to hints, hardware
|
/* We might change settings when loading (due to hints, hardware
|
||||||
* limitations, etc). The data actually loaded is here: */
|
* limitations, etc). The data actually loaded is here: */
|
||||||
RageTextureID m_ID;
|
RageTextureID m_ID;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
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
|
||||||
int m_iImageWidth, m_iImageHeight; // dimensions of the image in the texture
|
int m_iImageWidth, m_iImageHeight; // dimensions of the image in the texture
|
||||||
|
|||||||
@@ -194,9 +194,11 @@ void PrintCodecError(HRESULT hr, CString s)
|
|||||||
|
|
||||||
void MovieTexture_DShow::Create()
|
void MovieTexture_DShow::Create()
|
||||||
{
|
{
|
||||||
|
RageTextureID actualID = GetID();
|
||||||
|
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
m_ID.iAlphaBits = 0;
|
actualID.iAlphaBits = 0;
|
||||||
|
|
||||||
if( FAILED( hr=CoInitialize(NULL) ) )
|
if( FAILED( hr=CoInitialize(NULL) ) )
|
||||||
RageException::Throw( hr_ssprintf(hr, "Could not CoInitialize") );
|
RageException::Throw( hr_ssprintf(hr, "Could not CoInitialize") );
|
||||||
@@ -217,7 +219,7 @@ void MovieTexture_DShow::Create()
|
|||||||
// Add the source filter
|
// Add the source filter
|
||||||
CComPtr<IBaseFilter> pFSrc; // Source Filter
|
CComPtr<IBaseFilter> pFSrc; // Source Filter
|
||||||
WCHAR wFileName[MAX_PATH];
|
WCHAR wFileName[MAX_PATH];
|
||||||
MultiByteToWideChar(CP_ACP, 0, m_ID.filename.c_str(), -1, wFileName, MAX_PATH);
|
MultiByteToWideChar(CP_ACP, 0, actualID.filename.c_str(), -1, wFileName, MAX_PATH);
|
||||||
|
|
||||||
// if this fails, it's probably because the user doesn't have DivX installed
|
// if this fails, it's probably because the user doesn't have DivX installed
|
||||||
if( FAILED( hr = m_pGB->AddSourceFilter( wFileName, L"SOURCE", &pFSrc ) ) )
|
if( FAILED( hr = m_pGB->AddSourceFilter( wFileName, L"SOURCE", &pFSrc ) ) )
|
||||||
@@ -246,7 +248,7 @@ void MovieTexture_DShow::Create()
|
|||||||
pCTR->SetRenderTarget(this);
|
pCTR->SetRenderTarget(this);
|
||||||
|
|
||||||
/* Cap the max texture size to the hardware max. */
|
/* Cap the max texture size to the hardware max. */
|
||||||
m_ID.iMaxSize = min( m_ID.iMaxSize, DISPLAY->GetMaxTextureSize() );
|
actualID.iMaxSize = min( actualID.iMaxSize, DISPLAY->GetMaxTextureSize() );
|
||||||
|
|
||||||
// The graph is built, now get the set the output video width and height.
|
// The graph is built, now get the set the output video width and height.
|
||||||
// The source and image width will always be the same since we can't scale the video
|
// The source and image width will always be the same since we can't scale the video
|
||||||
@@ -254,8 +256,8 @@ void MovieTexture_DShow::Create()
|
|||||||
m_iSourceHeight = pCTR->GetVidHeight();
|
m_iSourceHeight = pCTR->GetVidHeight();
|
||||||
|
|
||||||
/* image size cannot exceed max size */
|
/* image size cannot exceed max size */
|
||||||
m_iImageWidth = min( m_iSourceWidth, m_ID.iMaxSize );
|
m_iImageWidth = min( m_iSourceWidth, actualID.iMaxSize );
|
||||||
m_iImageHeight = min( m_iSourceHeight, m_ID.iMaxSize );
|
m_iImageHeight = min( m_iSourceHeight, actualID.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(m_iImageWidth);
|
m_iTextureWidth = power_of_two(m_iImageWidth);
|
||||||
|
|||||||
Reference in New Issue
Block a user