diff --git a/stepmania/src/RageBitmapTexture.cpp b/stepmania/src/RageBitmapTexture.cpp index d26fa58a81..bf5f5ac575 100644 --- a/stepmania/src/RageBitmapTexture.cpp +++ b/stepmania/src/RageBitmapTexture.cpp @@ -91,9 +91,25 @@ void RageBitmapTexture::Create() } - - // load texture and get image info + ///////////////////// + // Figure out whether the texture can fit into texture memory unscaled + ///////////////////// + bool bScaleImageToTextureSize; + D3DXIMAGE_INFO ddii; + if( FAILED( hr = D3DXGetImageInfoFromFile( + m_sFilePath, + &ddii ) ) ) + { + RageErrorHr( ssprintf("D3DXGetImageInfoFromFile() failed for file '%s'.", m_sFilePath), hr ); + } + + D3DCAPS8 caps; + m_pd3dDevice->GetDeviceCaps( &caps ); + + bScaleImageToTextureSize = ddii.Width > caps.MaxTextureWidth + || ddii.Height > caps.MaxTextureHeight; + if( FAILED( hr = D3DXCreateTextureFromFileEx( m_pd3dDevice, // device @@ -103,8 +119,8 @@ void RageBitmapTexture::Create() 0, // usage (is a render target?) fmtTexture, // our preferred texture format D3DPOOL_MANAGED, // which memory pool - D3DX_FILTER_BOX, // filter - D3DX_FILTER_BOX, // mip filter + bScaleImageToTextureSize ? D3DX_FILTER_BOX : D3DX_FILTER_NONE, // filter + D3DX_DEFAULT, // mip filter 0, // no color key &ddii, // struct to fill with source image info NULL, // no palette @@ -113,15 +129,13 @@ void RageBitmapTexture::Create() RageErrorHr( ssprintf("D3DXCreateTextureFromFileEx() failed for file '%s'.", m_sFilePath), hr ); } - // save the source image's width and height + + ///////////////////// + // Save information about the texture + ///////////////////// m_uSourceWidth = ddii.Width; m_uSourceHeight= ddii.Height; - - //RageLog( "info.Width = %d, info.Height = %d, devCaps.MaxTextureWidth = %d, devCaps.MaxTextureHeight = %d", - // info.Width, info.Height, devCaps.MaxTextureWidth, devCaps.MaxTextureHeight ); - - D3DSURFACE_DESC ddsd; if ( FAILED( hr = m_pd3dTexture->GetLevelDesc( 0, &ddsd ) ) ) RageErrorHr( "Could not get level Description of D3DX texture!", hr ); @@ -130,5 +144,16 @@ void RageBitmapTexture::Create() m_uTextureWidth = ddsd.Width; m_uTextureHeight = ddsd.Height; m_TextureFormat = ddsd.Format; + + if( bScaleImageToTextureSize ) + { + m_uImageWidth = m_uTextureWidth; + m_uImageHeight = m_uTextureHeight; + } + else + { + m_uImageWidth = m_uSourceWidth; + m_uImageHeight = m_uSourceHeight; + } } diff --git a/stepmania/src/RageTexture.cpp b/stepmania/src/RageTexture.cpp index bf0132b95e..f313794d6f 100644 --- a/stepmania/src/RageTexture.cpp +++ b/stepmania/src/RageTexture.cpp @@ -20,15 +20,7 @@ //----------------------------------------------------------------------------- // RageTexture constructor //----------------------------------------------------------------------------- -RageTexture::RageTexture( LPRageScreen pScreen, CString sFilePath ) : - m_uSourceWidth( 0 ), - m_uSourceHeight( 0 ), - m_uTextureWidth( 0 ), - m_uTextureHeight( 0 ), - m_uFramesWide( 1 ), - m_uFramesHigh( 1 ), - m_uSourceFrameWidth( 0 ), - m_uSourceFrameHeight( 0 ) +RageTexture::RageTexture( LPRageScreen pScreen, CString sFilePath ) { // RageLog( "RageTexture::RageTexture()" ); @@ -41,7 +33,10 @@ RageTexture::RageTexture( LPRageScreen pScreen, CString sFilePath ) : // m_pd3dTexture = NULL; m_iRefCount = 1; - + m_uSourceWidth = m_uSourceHeight = 0; + m_uTextureWidth = m_uTextureHeight = 0; + m_uImageWidth = m_uImageHeight = 0; + m_uFramesWide = m_uFramesHigh = 1; } RageTexture::~RageTexture() @@ -61,10 +56,10 @@ void RageTexture::CreateFrameRects() { for( UINT i=0; i