828 lines
21 KiB
C++
828 lines
21 KiB
C++
|
|
#include "stdafx.h"
|
|
#include "KResource.h"
|
|
#include "KResourceDX.h"
|
|
#include <kfile/KFileManager.h>
|
|
|
|
#include "KDeviceManager.h"
|
|
#include "KResourceManager.h"
|
|
#include "KUITextureManager.h"
|
|
|
|
//#include "Util.h"
|
|
|
|
#include <kfile/XOREn.h>
|
|
|
|
#include "KTGA_IO.h"
|
|
|
|
#include "Slog.h"
|
|
//#include "SDebug_Util.h"
|
|
|
|
unsigned int KUITextureManager::m_TextureSize = 1024;
|
|
|
|
KUITextureManager *KSingletoneResourceManager<KUITextureManager>::s_pStaticManager = new KUITextureManager;
|
|
K3DRenderDeviceDX* KUITextureManager::m_pDevice = NULL;
|
|
int KUITextureManager::m_nHW_Support = HW_SUPPORT;
|
|
|
|
void KUITextureManager::SetRenderDevice( class K3DRenderDeviceDX * pDevice )
|
|
{
|
|
m_pDevice = pDevice;
|
|
|
|
K3DTexture * pNewTex = KDeviceManager::GetDeviceManager()->GetRenderDevice()->CreateTexture( 2, 2, KUSAGE_DYNAMIC, K3DFMT_A8R8G8B8, D3DPOOL_DEFAULT );
|
|
if( pNewTex )
|
|
{
|
|
if( !pNewTex->IsValid() )
|
|
m_nHW_Support = NOT_HW_SUPPORT;
|
|
|
|
//Intel Chip 계열에서 지원 안 되는 넘들이 있음.
|
|
pNewTex->AddRef();
|
|
SAFE_RELEASE( pNewTex );
|
|
}
|
|
else
|
|
{
|
|
m_nHW_Support = NOT_HW_SUPPORT;
|
|
}
|
|
|
|
if( m_pDevice )
|
|
{
|
|
if ( ((m_pDevice->GetCaps().TextureCaps & D3DPTEXTURECAPS_POW2) != 0) &&
|
|
((m_pDevice->GetCaps().TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL) == 0) )
|
|
{
|
|
m_nHW_Support = NOTPOW_SUPPORT;
|
|
}
|
|
}
|
|
}
|
|
|
|
void KUITextureManager::Clear()
|
|
{
|
|
|
|
}
|
|
|
|
KUITextureManager::KUITextureManager()
|
|
{
|
|
|
|
}
|
|
|
|
KUITextureManager::~KUITextureManager()
|
|
{
|
|
DiscardAll();
|
|
}
|
|
|
|
void KUITextureManager::DiscardAll()
|
|
{
|
|
_LOADED_SPRITE_SET *pSet = NULL;
|
|
bool bRet;
|
|
|
|
bRet = m_setByName.get_first_value( pSet );
|
|
while ( bRet )
|
|
{
|
|
SAFE_DELETE(pSet);
|
|
bRet = m_setByName.get_next_value( pSet );
|
|
}
|
|
m_setByName.clear();
|
|
|
|
for( unsigned int i(0); m_vManageList.size()>i; i++ )
|
|
{
|
|
delete m_vManageList[i];
|
|
}
|
|
m_vManageList.erase( m_vManageList.begin(), m_vManageList.end() );
|
|
}
|
|
|
|
void SetCopyWithColorKey( char * pSrc, const int nSrcStride, char * pDst, const int nDstStride, const int nWidth, const int nHeight, const KColor color_key )
|
|
{
|
|
KColor* pDstColor;
|
|
KColor* pSrcColor;
|
|
int nCmpVal[3];
|
|
for(int y = 0; y < nHeight; y++ )
|
|
{
|
|
pDstColor = ( KColor* )pDst;
|
|
pSrcColor = ( KColor* )pSrc;
|
|
|
|
for( int x = 0; x < nWidth; x++ )
|
|
{
|
|
if( pSrcColor[x].r == color_key.r &&
|
|
pSrcColor[x].g == color_key.g &&
|
|
pSrcColor[x].b == color_key.b )
|
|
{
|
|
pDstColor[x].r = pSrcColor[x].r;
|
|
pDstColor[x].g = pSrcColor[x].g;
|
|
pDstColor[x].b = pSrcColor[x].b;
|
|
pDstColor[x].a = 0;
|
|
}
|
|
else
|
|
{
|
|
nCmpVal[0] = (pSrcColor[x].r - color_key.r)*(pSrcColor[x].r - color_key.r);
|
|
nCmpVal[1] = (pSrcColor[x].g - color_key.g)*(pSrcColor[x].g - color_key.g);
|
|
nCmpVal[2] = (pSrcColor[x].b - color_key.b)*(pSrcColor[x].b - color_key.b);
|
|
|
|
//오차 +-100
|
|
if( nCmpVal[0] <= 10000 &&
|
|
nCmpVal[1] <= 10000 &&
|
|
nCmpVal[2] <= 10000 )
|
|
{
|
|
pDstColor[x].r = pSrcColor[x].r;
|
|
pDstColor[x].g = pSrcColor[x].g;
|
|
pDstColor[x].b = pSrcColor[x].b;
|
|
pDstColor[x].a = 0;
|
|
}
|
|
else
|
|
{
|
|
pDstColor[x] = pSrcColor[x];
|
|
}
|
|
}
|
|
}
|
|
|
|
pDst += nDstStride;
|
|
pSrc += nSrcStride;
|
|
}
|
|
|
|
}
|
|
|
|
void SetCopy( char * pSrc, const int nSrcStride, char * pDst, const int nDstStride, const int nWidth, const int nHeight )
|
|
{
|
|
KColor* pDstColor;
|
|
KColor* pSrcColor;
|
|
for(int y = 0; y < nHeight; y++ )
|
|
{
|
|
pDstColor = ( KColor* )pDst;
|
|
pSrcColor = ( KColor* )pSrc;
|
|
|
|
for( int x = 0; x < nWidth; x++ )
|
|
{
|
|
pDstColor[x] = pSrcColor[x];
|
|
}
|
|
|
|
pDst += nDstStride;
|
|
pSrc += nSrcStride;
|
|
}
|
|
|
|
// assert( _CrtCheckMemory() && "Memory Error!!!" );
|
|
}
|
|
|
|
bool KUITextureManager::_add( _INNER * pInner, _SPRITE_PACK * pSprPack )
|
|
{
|
|
X2D::Point<int> pt;
|
|
_LOADED_INFO * pUpdate = pSprPack->pSprInfo;
|
|
KResSpriteAnimation * pSprAni = pSprPack->spResSprAni;
|
|
|
|
if( pInner->pAlloc->Alloc( pUpdate->nWidth, pUpdate->nHeight, &pt ) )
|
|
{
|
|
//삭제 정보
|
|
//텍스쳐 상의 위치
|
|
pUpdate->pInner = pInner;
|
|
pUpdate->point = pt;
|
|
|
|
//텍스쳐 복사
|
|
RECT rect;
|
|
rect.left = 0;
|
|
rect.top = 0;
|
|
|
|
POINT point;
|
|
point.x = pt.x;
|
|
point.y = pt.y;
|
|
|
|
assert( pSprAni->GetKeyCount() == pUpdate->nCount && "Invalid Res Count!!!" );
|
|
|
|
// 2011. 6. 7 - marine
|
|
// 가로 사이즈가 256이상인 버튼은 surface를 y방향으로 증가시킨다...
|
|
bool bIsWidthOver = false;
|
|
if((pUpdate->spTexArray[0]->GetWidth() * pUpdate->nCount) > (int)m_TextureSize)
|
|
bIsWidthOver = true;
|
|
|
|
int nAddPoint = 0;
|
|
for( int n(0); pUpdate->nCount>n; n++ )
|
|
{
|
|
//옆으로 이동 하면서 복사
|
|
if(bIsWidthOver)
|
|
point.y += nAddPoint;
|
|
else
|
|
point.x += nAddPoint;
|
|
|
|
if( m_nHW_Support == HW_SUPPORT )
|
|
{
|
|
rect.right = pUpdate->spTexArray[n]->GetWidth();
|
|
rect.bottom = pUpdate->spTexArray[n]->GetHeight();
|
|
|
|
if( pUpdate->bUseColorkey )
|
|
{
|
|
//소프트웨어 락
|
|
char* pDstBuf = NULL;
|
|
char* pSrcBuf = NULL;
|
|
int nSrcStride, nDstStride;
|
|
pUpdate->spTexArray[n]->LockRect( NULL, (void**)&pSrcBuf, nSrcStride );
|
|
if( pSrcBuf == NULL )
|
|
{
|
|
assert( 0 && "Texture Src Lock Failed!!!" );
|
|
return false;
|
|
}
|
|
|
|
KRect krect = KRect(point.x, point.y, point.x+rect.right, point.y+rect.bottom);
|
|
|
|
pInner->spTexture->LockRect( &krect, (void**)&pDstBuf, nDstStride );
|
|
if( pDstBuf == NULL )
|
|
{
|
|
assert( 0 && "Texture Pool Lock Failed!!!" );
|
|
return false;
|
|
}
|
|
|
|
SetCopyWithColorKey( pSrcBuf, nSrcStride, pDstBuf, nDstStride, rect.right, rect.bottom, pUpdate->ColorKey );
|
|
|
|
pUpdate->spTexArray[n]->Unlock();
|
|
pInner->spTexture->Unlock();
|
|
}
|
|
else
|
|
{
|
|
if( m_pDevice->UpdateSurface( pUpdate->spTexArray[n], &rect, pInner->spTexture, &point ) != D3D_OK )
|
|
{
|
|
assert( 0 && "Texture Update Surface Failed!!!" );
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
else if( m_nHW_Support == NOT_HW_SUPPORT )
|
|
{
|
|
rect.right = pUpdate->spTexArray[n]->GetWidth();
|
|
rect.bottom = pUpdate->spTexArray[n]->GetHeight();
|
|
|
|
//소프트웨어 락
|
|
char* pDstBuf = NULL;
|
|
char* pSrcBuf = NULL;
|
|
int nSrcStride, nDstStride;
|
|
pUpdate->spTexArray[n]->LockRect( NULL, (void**)&pSrcBuf, nSrcStride );
|
|
if( pSrcBuf == NULL )
|
|
{
|
|
assert( 0 && "Texture Src Lock Failed!!!" );
|
|
return false;
|
|
}
|
|
|
|
KRect krect = KRect(point.x, point.y, point.x+rect.right, point.y+rect.bottom);
|
|
|
|
pInner->spTexture->LockRect( &krect, (void**)&pDstBuf, nDstStride );
|
|
if( pDstBuf == NULL )
|
|
{
|
|
assert( 0 && "Texture Pool Lock Failed!!!" );
|
|
return false;
|
|
}
|
|
|
|
if( pUpdate->bUseColorkey )
|
|
SetCopyWithColorKey( pSrcBuf, nSrcStride, pDstBuf, nDstStride, rect.right, rect.bottom, pUpdate->ColorKey );
|
|
else
|
|
SetCopy( pSrcBuf, nSrcStride, pDstBuf, nDstStride, rect.right, rect.bottom );
|
|
|
|
|
|
pUpdate->spTexArray[n]->Unlock();
|
|
pInner->spTexture->Unlock();
|
|
//------------------------------------
|
|
}
|
|
else if( m_nHW_Support == NOTPOW_SUPPORT )
|
|
{
|
|
rect.right = pUpdate->vSrcList[n].nWidth;
|
|
rect.bottom = pUpdate->vSrcList[n].nHeight;
|
|
|
|
//소프트웨어 락
|
|
char* pDstBuf = NULL;
|
|
char* pSrcBuf = NULL;
|
|
|
|
int nDepth = (pUpdate->vSrcList[n].nBitDepth/8);
|
|
|
|
int nSrcStride, nDstStride;
|
|
nSrcStride = pUpdate->vSrcList[n].nWidth * nDepth;
|
|
pSrcBuf = (char*)pUpdate->vSrcList[n].pSrcTexel;
|
|
|
|
KRect krect = KRect(point.x, point.y, point.x+rect.right, point.y+rect.bottom);
|
|
|
|
pInner->spTexture->LockRect( &krect, (void**)&pDstBuf, nDstStride );
|
|
if( pDstBuf == NULL )
|
|
{
|
|
assert( 0 && "Texture Pool Lock Failed!!!" );
|
|
return false;
|
|
}
|
|
|
|
if( nDepth == 4 ) //32Bit 지원
|
|
{
|
|
if( pUpdate->bUseColorkey )
|
|
SetCopyWithColorKey( pSrcBuf, nSrcStride, pDstBuf, nDstStride, rect.right, rect.bottom, pUpdate->ColorKey );
|
|
else
|
|
SetCopy( pSrcBuf, nSrcStride, pDstBuf, nDstStride, rect.right, rect.bottom );
|
|
}
|
|
|
|
pInner->spTexture->Unlock();
|
|
//------------------------------------
|
|
}
|
|
|
|
//위의 텍스쳐와 아래 Sprite 는 같은 것임.
|
|
//UV 계산
|
|
KResSpriteAnimation::Key key = pSprAni->GetKey(n);
|
|
KRect uv_rect;
|
|
uv_rect.left = point.x;
|
|
uv_rect.top = point.y;
|
|
uv_rect.right = point.x + rect.right;
|
|
uv_rect.bottom = point.y + rect.bottom;
|
|
key.spSprite->SetTexture( pInner->spTexture, &uv_rect );
|
|
|
|
if( m_nHW_Support == NOTPOW_SUPPORT )
|
|
{ //TGA 뒤집어 있음, Y 반전
|
|
key.spSprite->SetMirror( false, true );
|
|
}
|
|
|
|
if(bIsWidthOver)
|
|
nAddPoint = rect.bottom;
|
|
else
|
|
nAddPoint = rect.right;
|
|
}
|
|
|
|
pSprAni->SetLoad( true );
|
|
|
|
//정보 설정
|
|
pUpdate->TextureClear(); //Loaded 된 조각을 모두 사용 했으므로 모두 삭제 한다.
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
//static int nCnt = 0;
|
|
_SPRITE_PACK * KUITextureManager::add_Texture( const char * szSprSetName, const char * szAniName )
|
|
{
|
|
bool bIsAdd = false;
|
|
|
|
SPRITE_SET * pSet = KSpriteManager::GetManager()->GetSpriteSet( szSprSetName );
|
|
if( !pSet )
|
|
{
|
|
assert(0 && "Sprite Set Not Found!!!" );
|
|
return NULL;
|
|
}
|
|
|
|
KResSpriteAnimation * pSprAni = pSet->GetSpriteResAni( szAniName );
|
|
if( !pSprAni )
|
|
{
|
|
std::string strAniName( szAniName );
|
|
|
|
if( strAniName.find( '/' ) == std::string::npos )
|
|
SDEBUGLOG( "[텍스쳐메니져] 스프라이트(SPR) 파일에서 AniName을 찾을 수 없습니다. - [ %s ]", szAniName );
|
|
|
|
/// 2010.11.12 디버그가 힘들어 때문에 주석 처리함 - prodongi
|
|
//assert(0 && "Sprite Ani Not Found!!!" );
|
|
return NULL;
|
|
}
|
|
|
|
const std::vector<std::string> & vFrameList = pSprAni->GetFrame();
|
|
|
|
if( vFrameList.empty() )
|
|
{
|
|
assert( 0 && "Frame Is Empty!!!" );
|
|
return NULL;
|
|
}
|
|
|
|
K3DTextureSPtr* spTexArray = new K3DTextureSPtr[vFrameList.size()];
|
|
NX3LoadPack loadpack;
|
|
loadpack.Init();
|
|
|
|
//Frame all Loading
|
|
RECT total_rect;
|
|
total_rect.left = 0;
|
|
total_rect.top = 0;
|
|
total_rect.right = 0;
|
|
total_rect.bottom = 0;
|
|
|
|
std::vector< _TEX_SRC_INFO > vSrcList;
|
|
|
|
for( unsigned int i(0); vFrameList.size()>i; i++ )
|
|
{
|
|
// _oprint( "UI Texture Load : %s\n", vFrameList[i].c_str() );
|
|
KStream *stream = KFileManager::Instance().CreateStreamFromResource( vFrameList[i].c_str() );
|
|
if( stream == NULL )
|
|
{
|
|
_oprint( "Texture Resource Not Found : %s\n", vFrameList[i].c_str() );
|
|
// assert( 0 && "Texture Resource Not Found!!!" );
|
|
SAFE_DELETE_ARRAY( spTexArray );
|
|
return false;
|
|
}
|
|
|
|
if( pSprAni->IsEncrypt() )
|
|
{
|
|
KMemoryStream* pEncStream = new KMemoryStream( stream->GetMappedPtr(0), stream->GetLength() ); //새로 생성
|
|
KFileManager::Instance().DeleteStream( stream ); //삭제
|
|
stream = pEncStream;
|
|
|
|
char *pSrc = (char*)stream->GetMappedPtr( KStream::MAPPED_WRITE );
|
|
if ( pSrc )
|
|
for( size_t idx = 0; idx < stream->GetLength(); idx++ ) pSrc[idx] ^= XOREn::GetEncodeKeyChar( idx );
|
|
}
|
|
|
|
if( m_nHW_Support == HW_SUPPORT || m_nHW_Support == NOT_HW_SUPPORT )
|
|
{
|
|
//기존 DX 방법------------------------------------------------------------
|
|
K3DTextureDX * pSrcTex = new K3DTextureDX( m_pDevice );
|
|
if( m_nHW_Support == HW_SUPPORT )
|
|
{
|
|
pSrcTex->Initialize( *stream, 0, D3DPOOL_SYSTEMMEM, K3DFMT_A8R8G8B8 );
|
|
|
|
// 로드한 이미지를 파일로 저장하고 싶은 경우 이것을 바꿔주세요.
|
|
bool bOutputTexture(false);
|
|
|
|
if( bOutputTexture )
|
|
pSrcTex->SaveToFile( std::string( vFrameList[i].c_str() ) );
|
|
}
|
|
else if( m_nHW_Support == NOT_HW_SUPPORT )
|
|
pSrcTex->Initialize( *stream, 0, D3DPOOL_MANAGED, K3DFMT_A8R8G8B8 );
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
if(pSrcTex->GetWidth() > (int)(m_TextureSize/4) ) /// 2011.01.19 형변환 추가 - prodongi
|
|
{
|
|
if( total_rect.right < pSrcTex->GetWidth() )
|
|
total_rect.right = pSrcTex->GetWidth(); //세로 증가
|
|
|
|
total_rect.bottom += pSrcTex->GetHeight();
|
|
}
|
|
else
|
|
{
|
|
total_rect.right += pSrcTex->GetWidth(); //가로 증가
|
|
|
|
if( total_rect.bottom < pSrcTex->GetHeight() )
|
|
total_rect.bottom = pSrcTex->GetHeight();
|
|
}
|
|
|
|
spTexArray[i] = pSrcTex;
|
|
}
|
|
else if( m_nHW_Support == NOTPOW_SUPPORT )
|
|
{
|
|
_TEX_SRC_INFO _src_info;
|
|
//TGA 직접 로딩 방법------------------------------------------------------
|
|
if( TGAReadImage( stream, &_src_info.nWidth, &_src_info.nHeight, &_src_info.nBitDepth, &_src_info.pSrcTexel ) )
|
|
{
|
|
vSrcList.push_back( _src_info );
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
total_rect.right += _src_info.nWidth; //가로 증가
|
|
total_rect.bottom = _src_info.nHeight;
|
|
}
|
|
|
|
KFileManager::Instance().DeleteStream( stream );
|
|
}
|
|
|
|
assert( total_rect.right <= (int)m_TextureSize && "텍스쳐 사이즈를 넘어가는 컨트롤!!!" );
|
|
assert( total_rect.bottom <= (int)m_TextureSize && "텍스쳐 사이즈를 넘어가는 컨트롤!!!" );
|
|
|
|
_SPRITE_PACK * pSprPack = new _SPRITE_PACK;
|
|
if( NULL == pSprPack )
|
|
assert( NULL );
|
|
|
|
//KResSprAni
|
|
pSprPack->spResSprAni = pSprAni;
|
|
|
|
//Loaded Info
|
|
pSprPack->pSprInfo = new _LOADED_INFO;
|
|
pSprPack->pSprInfo->pAniName = pSprAni->GetName();
|
|
pSprPack->pSprInfo->nWidth = total_rect.right;
|
|
pSprPack->pSprInfo->nHeight = total_rect.bottom;
|
|
|
|
pSprPack->pSprInfo->bUseColorkey = pSprAni->IsUseColorKey();
|
|
pSprPack->pSprInfo->ColorKey = pSprAni->GetColorKey();
|
|
|
|
if( m_nHW_Support == HW_SUPPORT || m_nHW_Support == NOT_HW_SUPPORT )
|
|
{
|
|
pSprPack->pSprInfo->nCount = (int)vFrameList.size();
|
|
pSprPack->pSprInfo->spTexArray = spTexArray;
|
|
}
|
|
else if( m_nHW_Support == NOTPOW_SUPPORT )
|
|
{
|
|
pSprPack->pSprInfo->spTexArray = NULL;
|
|
|
|
SAFE_DELETE_ARRAY( spTexArray );
|
|
|
|
pSprPack->pSprInfo->nCount = (int)vSrcList.size();
|
|
|
|
for( unsigned int i(0); vSrcList.size()>i; i++ )
|
|
{
|
|
_TEX_SRC_INFO _src_info;
|
|
|
|
_src_info.nWidth = vSrcList[i].nWidth ;
|
|
_src_info.nHeight = vSrcList[i].nHeight ;
|
|
_src_info.nBitDepth = vSrcList[i].nBitDepth;
|
|
_src_info.pSrcTexel = vSrcList[i].pSrcTexel;
|
|
|
|
pSprPack->pSprInfo->vSrcList.push_back( _src_info );
|
|
}
|
|
}
|
|
|
|
//기존 텍스쳐에 추가 시도
|
|
for( unsigned int i(0); m_vManageList.size()>i; i++ )
|
|
{
|
|
_INNER * pInner = m_vManageList[i];
|
|
|
|
if( _add( pInner, pSprPack) )
|
|
{
|
|
bIsAdd = true;
|
|
return pSprPack;
|
|
}
|
|
}
|
|
|
|
//새 텍스쳐에 추가
|
|
if( !bIsAdd )
|
|
{
|
|
//기존 것들은 꽉 찼다.
|
|
_INNER * pInner = new _INNER;
|
|
pInner->pAlloc = new X2D::RectAllocator<int>( m_TextureSize, m_TextureSize ) ;
|
|
|
|
K3DTexture * pNewTex = NULL;
|
|
// _oprint( "UI Texture pool : %08X\n", pNewTex );
|
|
|
|
if( m_nHW_Support == HW_SUPPORT )
|
|
{
|
|
pNewTex = KDeviceManager::GetDeviceManager()->GetRenderDevice()->CreateTexture( m_TextureSize, m_TextureSize, KUSAGE_DYNAMIC, K3DFMT_A8R8G8B8, D3DPOOL_DEFAULT );
|
|
}
|
|
else
|
|
{
|
|
//Intel Chip 계열에서 지원 안 되는 넘들이 있음.
|
|
pNewTex = KDeviceManager::GetDeviceManager()->GetRenderDevice()->CreateTexture( m_TextureSize, m_TextureSize, K3DFMT_A8R8G8B8, D3DPOOL_MANAGED );
|
|
}
|
|
|
|
if( pNewTex )
|
|
{
|
|
|
|
#ifdef _FIIL_TEXTURE_
|
|
//Fill Texture
|
|
char* pBuf = NULL;
|
|
int nStride;
|
|
pNewTex->LockRect( NULL, (void**)&pBuf, nStride );
|
|
if( pBuf == NULL )
|
|
{
|
|
assert( 0 && "Texture Pool Lock Failed!!!" );
|
|
return NULL;
|
|
}
|
|
|
|
KColor* pColor;
|
|
for(UINT y = 0; y < m_TextureSize; y++ )
|
|
{
|
|
pColor = ( KColor* )pBuf;
|
|
for( UINT x = 0; x < m_TextureSize; x++ )
|
|
{
|
|
KColor col;
|
|
col.r = 0; col.g = 0; col.b = 0; col.a = 0;
|
|
pColor[x] = col;
|
|
}
|
|
pBuf += nStride;
|
|
}
|
|
pNewTex->Unlock();
|
|
//------------------------------------
|
|
#endif
|
|
|
|
// assert( _CrtCheckMemory() && "Memory Error 1 !!!" );
|
|
|
|
pInner->spTexture = pNewTex;
|
|
|
|
if( _add(pInner, pSprPack) )
|
|
{
|
|
bIsAdd = true;
|
|
m_vManageList.push_back( pInner );
|
|
return pSprPack;
|
|
}
|
|
else
|
|
{
|
|
SAFE_DELETE ( pSprPack );
|
|
SAFE_DELETE ( pInner );
|
|
|
|
assert(0 && "Alloc Failed!!!" );
|
|
return NULL;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
SAFE_DELETE ( pSprPack );
|
|
SAFE_DELETE ( pInner );
|
|
|
|
assert(0 && "Create Texture Failed!!!" );
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
SAFE_DELETE ( pSprPack );
|
|
|
|
assert(0 && "Unknow Failed!!!" );
|
|
return NULL;
|
|
}
|
|
|
|
void KUITextureManager::_del( _LOADED_INFO * pUpdate )
|
|
{
|
|
//영역 삭제
|
|
pUpdate->pInner->pAlloc->Remove( pUpdate->point );
|
|
|
|
pUpdate->pInner->pAlloc = NULL;
|
|
pUpdate->point = X2D::Point<int>(0,0);
|
|
|
|
pUpdate->pInner->spTexture = NULL;
|
|
}
|
|
|
|
int KUITextureManager::DelSprAni( const char * szSprSetName, const char * szAniName )
|
|
{
|
|
//Allocator에서 관리 되고 있는가?
|
|
_LOADED_SPRITE_SET * pLoadedSprSet = NULL;
|
|
if( m_setByName.lookup( szSprSetName, pLoadedSprSet ) == false )
|
|
return S_FALSE;
|
|
|
|
if( pLoadedSprSet )
|
|
{
|
|
_SPRITE_PACK * pSprPack = NULL;
|
|
if( pLoadedSprSet->hashSprAni.lookup( szAniName, pSprPack ) == false )
|
|
return FALSE;
|
|
|
|
if( pSprPack && pSprPack->spResSprAni != NULL)
|
|
{
|
|
KResSpriteAnimation * pSprAni = pSprPack->spResSprAni;
|
|
|
|
for( int n(0); pSprAni->GetKeyCount()>n; n++ )
|
|
{
|
|
KResSpriteAnimation::Key key = pSprAni->GetKey(n);
|
|
key.spSprite->SetTexture( NULL, NULL );
|
|
}
|
|
}
|
|
|
|
SAFE_DELETE( pSprPack );
|
|
|
|
//삭제
|
|
pLoadedSprSet->hashSprAni.erase( szAniName );
|
|
}
|
|
|
|
//Frame 전체 크기 삭제
|
|
|
|
return S_OK;
|
|
}
|
|
|
|
_LOADED_SPRITE_SET * KUITextureManager::add_SprSet( const char * szSprSetName ) //SPRITE_SET 추가
|
|
{
|
|
_LOADED_SPRITE_SET * pAddSprSet = new _LOADED_SPRITE_SET;
|
|
pAddSprSet->strSprName = szSprSetName;
|
|
|
|
if( m_setByName.add( szSprSetName, pAddSprSet ) )
|
|
return pAddSprSet;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
KResSpriteAnimation * KUITextureManager::add_SprAni( _LOADED_SPRITE_SET * pAddSprSet, const char * szSprSetName, const char * szAniName ) //ResSprAni 추가
|
|
{
|
|
//추가
|
|
_SPRITE_PACK * pSprPack = add_Texture( szSprSetName, szAniName );
|
|
if( pSprPack )
|
|
{
|
|
pAddSprSet->hashSprAni.add( szAniName, pSprPack );
|
|
|
|
return pSprPack->spResSprAni;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
void KUITextureManager::OutputTexture()
|
|
{
|
|
for( unsigned int i(0); m_vManageList.size()>i; i++ )
|
|
{
|
|
std::string strFname;
|
|
strFname = CStringUtil::StringFormat( "c:\\ui_pool%02d.tga", i );
|
|
K3DTexture* pTexture = m_vManageList[i]->spTexture;
|
|
K3DTextureDX* pTextureDX = static_cast<K3DTextureDX*>(pTexture);
|
|
D3DXSaveTextureToFile( strFname.c_str(), D3DXIFF_TGA, pTextureDX->GetD3DTexture(), NULL);
|
|
}
|
|
}
|
|
|
|
KResSpriteAnimation * KUITextureManager::GetSprAni( const char * szSprName, const char * szAniName )
|
|
{
|
|
if( strlen(szAniName) <= 0 ) //static 중에서 캡션만 있는 넘들은 AniName 이 없음.
|
|
return NULL;
|
|
|
|
_LOADED_SPRITE_SET * pLoadedSprSet = NULL;
|
|
|
|
if( m_setByName.lookup( szSprName, pLoadedSprSet ) == true )
|
|
{
|
|
_SPRITE_PACK * pSpritePack = NULL;
|
|
if( pLoadedSprSet->hashSprAni.lookup( szAniName, pSpritePack ) == true )
|
|
{
|
|
return pSpritePack->spResSprAni; //이미 로딩 되어 있는 것
|
|
}
|
|
else
|
|
{ //Res 추가 작업
|
|
KResSpriteAnimation * pSprAni01 = add_SprAni( pLoadedSprSet, szSprName, szAniName );
|
|
return pSprAni01;
|
|
}
|
|
}
|
|
|
|
//Spr Set 추가 작업 일어 난다.
|
|
_LOADED_SPRITE_SET * pNewSprSet = add_SprSet( szSprName );
|
|
if( pNewSprSet )
|
|
{ //Res 추가 작업
|
|
KResSpriteAnimation * pSprAni02 = add_SprAni( pNewSprSet, szSprName, szAniName );
|
|
return pSprAni02;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
struct _RELOAD_SPR
|
|
{
|
|
std::string strSprName;
|
|
std::vector< std::string > listAniName;
|
|
};
|
|
|
|
void KUITextureManager::DeviceLost()
|
|
{ //디바이스 로스트 처리
|
|
std::vector< _RELOAD_SPR > reloadlist;
|
|
|
|
bool bRet = false;
|
|
_LOADED_SPRITE_SET *pSet = NULL;
|
|
bRet = m_setByName.get_first_value( pSet );
|
|
while ( bRet )
|
|
{
|
|
bool bPack = false;
|
|
_SPRITE_PACK * pSprPack = NULL;
|
|
bPack = pSet->hashSprAni.get_first_value( pSprPack );
|
|
|
|
_RELOAD_SPR _reload_spr;
|
|
_reload_spr.strSprName = pSet->strSprName.c_str();
|
|
|
|
while ( bPack )
|
|
{
|
|
_reload_spr.listAniName.push_back( pSprPack->spResSprAni->GetName() );
|
|
|
|
bPack = pSet->hashSprAni.get_next_value( pSprPack );
|
|
}
|
|
reloadlist.push_back( _reload_spr );
|
|
|
|
bRet = m_setByName.get_next_value( pSet );
|
|
}
|
|
|
|
DiscardAll();
|
|
|
|
|
|
//복구
|
|
for( unsigned int i(0); reloadlist.size()>i; i++ )
|
|
{
|
|
for( unsigned int j(0); reloadlist[i].listAniName.size()>j; j++ )
|
|
{
|
|
|
|
GetSprAni( reloadlist[i].strSprName.c_str(), reloadlist[i].listAniName[j].c_str() );
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
// { [sonador]
|
|
#ifdef _KUI_INVALIDATION
|
|
|
|
KUICachedTextureManager*
|
|
KSingletoneResourceManager< KUICachedTextureManager >::s_pStaticManager = new KUICachedTextureManager;
|
|
K3DRenderDeviceDX* KUICachedTextureManager::m_pRenderDevice = NULL;
|
|
int KUICachedTextureManager::m_nHW_Support = HW_SUPPORT;
|
|
|
|
KUICachedTextureManager::KUICachedTextureManager()
|
|
{
|
|
}
|
|
|
|
KUICachedTextureManager::~KUICachedTextureManager()
|
|
{
|
|
}
|
|
|
|
void KUICachedTextureManager::SetRenderDevice( class K3DRenderDeviceDX* renderDevice )
|
|
{
|
|
m_pRenderDevice = renderDevice;
|
|
|
|
K3DTexture * pNewTex = KDeviceManager::GetDeviceManager()->GetRenderDevice()->CreateTexture( 2, 2, KUSAGE_DYNAMIC, K3DFMT_A8R8G8B8, D3DPOOL_DEFAULT );
|
|
if( pNewTex )
|
|
{
|
|
if( !pNewTex->IsValid() )
|
|
m_nHW_Support = NOT_HW_SUPPORT;
|
|
|
|
//Intel Chip 계열에서 지원 안 되는 넘들이 있음.
|
|
pNewTex->AddRef();
|
|
SAFE_RELEASE( pNewTex );
|
|
}
|
|
else
|
|
{
|
|
m_nHW_Support = NOT_HW_SUPPORT;
|
|
}
|
|
|
|
if( m_pRenderDevice )
|
|
{
|
|
if( ( ( m_pRenderDevice->GetCaps().TextureCaps & D3DPTEXTURECAPS_POW2) != 0 ) &&
|
|
( ( m_pRenderDevice->GetCaps().TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL) == 0 ) )
|
|
{
|
|
m_nHW_Support = NOTPOW_SUPPORT;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool KUICachedTextureManager::SupportNonPow2() { return NOTPOW_SUPPORT != m_nHW_Support; }
|
|
|
|
K3DTexture* KUICachedTextureManager::GetTexture( int width, int height )
|
|
{
|
|
return m_pRenderDevice->CreateTexture( width, height, 0, K3DFORMAT::K3DFMT_A8R8G8B8 );
|
|
}
|
|
|
|
K3DRenderTarget* KUICachedTextureManager::GetRenderTarget( int width, int height, UINT level, DWORD depthUsage )
|
|
{
|
|
return m_pRenderDevice->CreateRenderTarget(
|
|
width, height, level, K3DFORMAT::K3DFMT_A8R8G8B8, depthUsage );
|
|
}
|
|
#endif
|
|
// }
|