From 77246243237943020c32554b0831a10659fc5ce3 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Thu, 22 May 2003 06:32:23 +0000 Subject: [PATCH] Make RageBitmapTexture:m_ID private (so it can't be modified) --- stepmania/src/RageBitmapTexture.cpp | 82 ++++++++----------- stepmania/src/RageDisplay.h | 12 +++ stepmania/src/RageTexture.h | 6 +- .../arch/MovieTexture/MovieTexture_DShow.cpp | 12 +-- 4 files changed, 57 insertions(+), 55 deletions(-) diff --git a/stepmania/src/RageBitmapTexture.cpp b/stepmania/src/RageBitmapTexture.cpp index bd5e84e1d3..bae7f4a794 100644 --- a/stepmania/src/RageBitmapTexture.cpp +++ b/stepmania/src/RageBitmapTexture.cpp @@ -78,6 +78,8 @@ void RageBitmapTexture::Reload() */ void RageBitmapTexture::Create() { + RageTextureID actualID = GetID(); + /* Create (and return) a surface ready to be loaded to OpenGL */ /* Load the image into an SDL surface. */ SDL_Surface *img = IMG_Load(GetFilePath()); @@ -87,7 +89,7 @@ void RageBitmapTexture::Create() if(img == NULL) 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 * 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. */ int traits = FindSurfaceTraits(img); if(traits & TRAIT_NO_TRANSPARENCY) - m_ID.iAlphaBits = 0; + actualID.iAlphaBits = 0; else if(traits & TRAIT_BOOL_TRANSPARENCY) - m_ID.iAlphaBits = 1; + actualID.iAlphaBits = 1; if(traits & TRAIT_WHITE_ONLY) - m_ID.iTransparencyOnly = 8; + actualID.iTransparencyOnly = 8; } // look in the file name for a format hints CString HintString = GetFilePath(); HintString.MakeLower(); - if( HintString.Find("4alphaonly") != -1 ) m_ID.iTransparencyOnly = 4; - else if( HintString.Find("8alphaonly") != -1 ) m_ID.iTransparencyOnly = 8; - if( HintString.Find("dither") != -1 ) m_ID.bDither = true; + if( HintString.Find("4alphaonly") != -1 ) actualID.iTransparencyOnly = 4; + else if( HintString.Find("8alphaonly") != -1 ) actualID.iTransparencyOnly = 8; + if( HintString.Find("dither") != -1 ) actualID.bDither = true; - if( m_ID.iTransparencyOnly ) - m_ID.iColorDepth = 32; /* Treat the image as 32-bit, so we don't lose any alpha precision. */ + if( actualID.iTransparencyOnly ) + 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. */ - m_ID.iMaxSize = min( m_ID.iMaxSize, DISPLAY->GetMaxTextureSize() ); + actualID.iMaxSize = min( actualID.iMaxSize, DISPLAY->GetMaxTextureSize() ); /* Save information about the source. */ m_iSourceWidth = img->w; 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 */ - m_iImageWidth = min( m_iSourceWidth, m_ID.iMaxSize ); - m_iImageHeight = min( m_iSourceHeight, m_ID.iMaxSize ); + m_iImageWidth = min( m_iSourceWidth, actualID.iMaxSize ); + m_iImageHeight = min( m_iSourceHeight, actualID.iMaxSize ); /* Texture dimensions need to be a power of two; jump to the next. */ m_iTextureWidth = power_of_two(m_iImageWidth); m_iTextureHeight = power_of_two(m_iImageHeight); - ASSERT( m_iTextureWidth <= m_ID.iMaxSize ); - ASSERT( m_iTextureHeight <= m_ID.iMaxSize ); + ASSERT( m_iTextureWidth <= actualID.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, * 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 PixelFormat pixfmt; - SDL_SaveBMP( img, "testing.bmp" ); - /* Figure out which texture format to use. */ // if the source is palleted, load palleted no matter what the prefs if(img->format->BitsPerPixel == 8 && DISPLAY->SupportsTextureFormat(FMT_PAL)) @@ -180,7 +177,7 @@ void RageBitmapTexture::Create() else { // not paletted - switch( m_ID.iColorDepth ) + switch( actualID.iColorDepth ) { case 16: { @@ -196,7 +193,7 @@ void RageBitmapTexture::Create() src_alpha_bits = max( 1, src_alpha_bits ); /* 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 ) { case 0: @@ -213,7 +210,7 @@ void RageBitmapTexture::Create() pixfmt = FMT_RGBA8; break; 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. @@ -221,7 +218,7 @@ void RageBitmapTexture::Create() * 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! * fix this later. -Chris */ -// if(m_ID.iTransparencyOnly > 0) +// if(actualID.iTransparencyOnly > 0) // { // imagePixfmt = 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. * 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. */ { /* 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 * 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. */ FixHiddenAlpha(img); - SDL_SaveBMP( img, "testing.bmp" ); - /* Convert the data to the destination format and dimensions * required by OpenGL if it's not in it already. */ 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[2], PIXEL_FORMAT_DESC[pixfmt].masks[3]); - SDL_SaveBMP( img, "testing.bmp" ); - m_uTexHandle = DISPLAY->CreateTexture( pixfmt, img ); SDL_FreeSurface( img ); CreateFrameRects(); -/* + /* See if the apparent "size" is being overridden. */ + GetResolutionFromFileName(actualID.filename, m_iSourceWidth, m_iSourceHeight); + + CString props = " "; - switch( pixfmt ) - { - case FMT_RGBA4: props += "FMT_RGBA4 "; break; - case FMT_RGBA8: props += "FMT_RGBA8 "; break; - case FMT_RGB5A1: props += "FMT_RGB5A1 "; break; - case FMT_ALPHA8: props += "FMT_ALPHA8 "; break; - 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 += PixelFormatToString( pixfmt ); + if(actualID.iAlphaBits == 0) props += "opaque "; + if(actualID.iAlphaBits == 1) props += "matte "; + if(actualID.iTransparencyOnly) props += "mask "; + if(actualID.bStretch) props += "stretch "; + if(actualID.bDither) props += "dither "; props.erase(props.size()-1); 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, m_iImageWidth, m_iImageHeight); -*/ } void RageBitmapTexture::Destroy() diff --git a/stepmania/src/RageDisplay.h b/stepmania/src/RageDisplay.h index b6fef5a3c2..8967fd1720 100644 --- a/stepmania/src/RageDisplay.h +++ b/stepmania/src/RageDisplay.h @@ -46,10 +46,22 @@ enum PixelFormat { FMT_PAL, 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 { int bpp; unsigned int masks[4]; }; +/* This is info is different for OGL and D3D. */ extern const PixelFormatDesc PIXEL_FORMAT_DESC[NUM_PIX_FORMATS]; class RageDisplay diff --git a/stepmania/src/RageTexture.h b/stepmania/src/RageTexture.h index 3e611ef5c1..f9f9185e68 100644 --- a/stepmania/src/RageTexture.h +++ b/stepmania/src/RageTexture.h @@ -93,11 +93,15 @@ public: static void GetFrameDimensionsFromFileName( CString sPath, int* puFramesWide, int* puFramesHigh ); static int GetFrameCountFromFileName( CString sPath ); -protected: + const RageTextureID& GetID() { return m_ID; } + +private: /* We might change settings when loading (due to hints, hardware * limitations, etc). The data actually loaded is here: */ RageTextureID m_ID; +protected: + 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_iImageWidth, m_iImageHeight; // dimensions of the image in the texture diff --git a/stepmania/src/arch/MovieTexture/MovieTexture_DShow.cpp b/stepmania/src/arch/MovieTexture/MovieTexture_DShow.cpp index 6c8c1cd8cb..3b167f02a9 100644 --- a/stepmania/src/arch/MovieTexture/MovieTexture_DShow.cpp +++ b/stepmania/src/arch/MovieTexture/MovieTexture_DShow.cpp @@ -194,9 +194,11 @@ void PrintCodecError(HRESULT hr, CString s) void MovieTexture_DShow::Create() { + RageTextureID actualID = GetID(); + HRESULT hr; - m_ID.iAlphaBits = 0; + actualID.iAlphaBits = 0; if( FAILED( hr=CoInitialize(NULL) ) ) RageException::Throw( hr_ssprintf(hr, "Could not CoInitialize") ); @@ -217,7 +219,7 @@ void MovieTexture_DShow::Create() // Add the source filter CComPtr pFSrc; // Source Filter 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( FAILED( hr = m_pGB->AddSourceFilter( wFileName, L"SOURCE", &pFSrc ) ) ) @@ -246,7 +248,7 @@ void MovieTexture_DShow::Create() pCTR->SetRenderTarget(this); /* 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 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(); /* image size cannot exceed max size */ - m_iImageWidth = min( m_iSourceWidth, m_ID.iMaxSize ); - m_iImageHeight = min( m_iSourceHeight, m_ID.iMaxSize ); + m_iImageWidth = min( m_iSourceWidth, actualID.iMaxSize ); + m_iImageHeight = min( m_iSourceHeight, actualID.iMaxSize ); /* Texture dimensions need to be a power of two; jump to the next. */ m_iTextureWidth = power_of_two(m_iImageWidth);