2001-11-03 10:52:42 +00:00
|
|
|
#include "stdafx.h"
|
2001-11-04 19:34:28 +00:00
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
File: RageBitmapTexture.h
|
|
|
|
|
|
|
|
|
|
Desc: Holder for a static texture with metadata. Can load just about any image format.
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2001 Chris Danford. All rights reserved.
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// In-line Links
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
//#pragma comment(lib, "winmm.lib")
|
|
|
|
|
#pragma comment(lib, "dxerr8.lib")
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Includes
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
#include "RageBitmapTexture.h"
|
|
|
|
|
#include "dxerr8.h"
|
|
|
|
|
#include "DXUtil.h"
|
|
|
|
|
#include "RageUtil.h"
|
2002-01-20 23:29:03 +00:00
|
|
|
#include "GameInfo.h"
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
//#include <stdio.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// RageBitmapTexture constructor
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
RageBitmapTexture::RageBitmapTexture( LPRageScreen pScreen, CString sFilePath ) :
|
|
|
|
|
RageTexture( pScreen, sFilePath )
|
|
|
|
|
{
|
|
|
|
|
// RageLog( "RageBitmapTexture::RageBitmapTexture()" );
|
|
|
|
|
|
2001-12-19 01:50:57 +00:00
|
|
|
m_pd3dTexture = NULL;
|
|
|
|
|
|
2001-11-03 10:52:42 +00:00
|
|
|
Create();
|
|
|
|
|
|
|
|
|
|
CreateFrameRects();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RageBitmapTexture::~RageBitmapTexture()
|
|
|
|
|
{
|
|
|
|
|
SAFE_RELEASE(m_pd3dTexture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// GetTexture
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
LPDIRECT3DTEXTURE8 RageBitmapTexture::GetD3DTexture()
|
|
|
|
|
{
|
|
|
|
|
return m_pd3dTexture;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-25 23:22:20 +00:00
|
|
|
void RageBitmapTexture::Create()
|
2001-11-03 10:52:42 +00:00
|
|
|
{
|
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
2002-01-28 21:24:17 +00:00
|
|
|
///////////////////////
|
|
|
|
|
// Figure out which texture format to use
|
|
|
|
|
///////////////////////
|
2002-01-20 23:29:03 +00:00
|
|
|
D3DFORMAT fmtTexture;
|
2002-01-28 21:24:17 +00:00
|
|
|
|
|
|
|
|
// look in the file name for a hint
|
|
|
|
|
m_sFilePath.MakeLower();
|
|
|
|
|
if( -1 != m_sFilePath.Find("(no alpha)") )
|
2002-01-20 23:29:03 +00:00
|
|
|
{
|
2002-01-28 21:24:17 +00:00
|
|
|
fmtTexture = D3DFMT_R5G6B5;
|
|
|
|
|
}
|
|
|
|
|
else if( -1 != m_sFilePath.Find("(1 alpha)") )
|
|
|
|
|
{
|
|
|
|
|
fmtTexture = D3DFMT_A1R5G5B5;
|
2002-01-20 23:29:03 +00:00
|
|
|
}
|
2002-01-28 21:24:17 +00:00
|
|
|
else // no hint, assume full alpha
|
2002-01-24 08:01:24 +00:00
|
|
|
{
|
2002-01-28 21:24:17 +00:00
|
|
|
fmtTexture = D3DFMT_A4R4G4B4;
|
2002-01-24 08:01:24 +00:00
|
|
|
}
|
2002-01-28 21:24:17 +00:00
|
|
|
|
|
|
|
|
// if the user has requested high color textures, use the higher color
|
|
|
|
|
if( GAMEINFO != NULL
|
|
|
|
|
&& GAMEINFO->m_GameOptions.m_iDisplayColor == 32
|
|
|
|
|
&& GAMEINFO->m_GameOptions.m_iTextureColor == 32 )
|
2002-01-20 23:29:03 +00:00
|
|
|
{
|
2002-01-28 21:24:17 +00:00
|
|
|
fmtTexture = D3DFMT_A8R8G8B8;
|
2002-01-20 23:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
2002-01-28 21:24:17 +00:00
|
|
|
|
2002-01-29 08:19:03 +00:00
|
|
|
/////////////////////
|
|
|
|
|
// Figure out whether the texture can fit into texture memory unscaled
|
|
|
|
|
/////////////////////
|
|
|
|
|
bool bScaleImageToTextureSize;
|
|
|
|
|
|
2001-11-03 10:52:42 +00:00
|
|
|
D3DXIMAGE_INFO ddii;
|
2002-01-29 08:19:03 +00:00
|
|
|
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;
|
|
|
|
|
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-01-20 09:40:21 +00:00
|
|
|
if( FAILED( hr = D3DXCreateTextureFromFileEx(
|
|
|
|
|
m_pd3dDevice, // device
|
|
|
|
|
m_sFilePath, // soure file
|
|
|
|
|
D3DX_DEFAULT, D3DX_DEFAULT, // width, height
|
2002-01-28 21:24:17 +00:00
|
|
|
4, // mip map levels
|
2002-01-20 09:40:21 +00:00
|
|
|
0, // usage (is a render target?)
|
2002-01-28 21:24:17 +00:00
|
|
|
fmtTexture, // our preferred texture format
|
2002-01-20 09:40:21 +00:00
|
|
|
D3DPOOL_MANAGED, // which memory pool
|
2002-01-29 08:19:03 +00:00
|
|
|
bScaleImageToTextureSize ? D3DX_FILTER_BOX : D3DX_FILTER_NONE, // filter
|
|
|
|
|
D3DX_DEFAULT, // mip filter
|
2002-01-20 09:40:21 +00:00
|
|
|
0, // no color key
|
|
|
|
|
&ddii, // struct to fill with source image info
|
|
|
|
|
NULL, // no palette
|
|
|
|
|
&m_pd3dTexture ) ) )
|
|
|
|
|
{
|
2001-11-03 10:52:42 +00:00
|
|
|
RageErrorHr( ssprintf("D3DXCreateTextureFromFileEx() failed for file '%s'.", m_sFilePath), hr );
|
2002-01-20 09:40:21 +00:00
|
|
|
}
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-01-29 08:19:03 +00:00
|
|
|
|
|
|
|
|
/////////////////////
|
|
|
|
|
// Save information about the texture
|
|
|
|
|
/////////////////////
|
2001-11-25 04:31:44 +00:00
|
|
|
m_uSourceWidth = ddii.Width;
|
|
|
|
|
m_uSourceHeight= ddii.Height;
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
D3DSURFACE_DESC ddsd;
|
|
|
|
|
if ( FAILED( hr = m_pd3dTexture->GetLevelDesc( 0, &ddsd ) ) )
|
|
|
|
|
RageErrorHr( "Could not get level Description of D3DX texture!", hr );
|
|
|
|
|
|
2001-11-25 04:31:44 +00:00
|
|
|
// save information about the texture
|
|
|
|
|
m_uTextureWidth = ddsd.Width;
|
|
|
|
|
m_uTextureHeight = ddsd.Height;
|
|
|
|
|
m_TextureFormat = ddsd.Format;
|
2002-01-29 08:19:03 +00:00
|
|
|
|
|
|
|
|
if( bScaleImageToTextureSize )
|
|
|
|
|
{
|
|
|
|
|
m_uImageWidth = m_uTextureWidth;
|
|
|
|
|
m_uImageHeight = m_uTextureHeight;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_uImageWidth = m_uSourceWidth;
|
|
|
|
|
m_uImageHeight = m_uSourceHeight;
|
|
|
|
|
}
|
2001-11-03 10:52:42 +00:00
|
|
|
}
|
|
|
|
|
|