Files
Leviathan/Client/Game/engine/Renderer/KUITextureManager.h
T
2026-06-01 12:46:52 +02:00

232 lines
4.8 KiB
C++

#pragma once
#include <toolkit/khash.h>
#include "KResourceManager.h"
#include <geometry/X2DRectAllocator.h>
#include "KResource.h"
class K3DTexture;
class KResSpriteAnimation;
class K3DRenderDeviceDX;
namespace
{
/// 텍스쳐 메모리
struct _INNER
{
_INNER()
{
pAlloc = NULL;
}
~_INNER()
{
SAFE_DELETE( pAlloc );
}
void Reset( const X2D::Rect<int> & rc )
{
if( pAlloc ) pAlloc->Remove( rc );
}
X2D::RectAllocator< int >* pAlloc; ///< Rect Allocator
K3DTextureSPtr spTexture;
};
struct _TEX_SRC_INFO
{
_TEX_SRC_INFO()
{
nWidth = 0;
nHeight = 0;
nBitDepth = 0;
pSrcTexel = NULL;
}
int nWidth; ///< 가로 크기
int nHeight; ///< 세로 크기
int nBitDepth;
BYTE* pSrcTexel;
};
struct _LOADED_INFO
{
_LOADED_INFO()
{
pAniName = NULL;
nWidth = 2;
nHeight = 2;
nCount = 0;
spTexArray = NULL;
pInner = NULL;
bUseColorkey = false;
ColorKey = KColor(0,0,0,0);
}
~_LOADED_INFO()
{
TextureClear();
TgaTextureClear();
}
void TextureClear()
{
nCount = 0;
SAFE_DELETE_ARRAY( spTexArray );
}
void TgaTextureClear()
{
for( unsigned int i(0); vSrcList.size()>i; i++ )
{
delete [] vSrcList[i].pSrcTexel;
}
vSrcList.clear();
}
const char * pAniName;///< AniName
int nWidth; ///< 전체 가로 크기
int nHeight; ///< 전체 세로 크기
//Copy 후 삭제 될 것
int nCount; ///< 조작 텍스쳐 갯수
K3DTextureSPtr* spTexArray; ///< 조각 텍스쳐's
std::vector< _TEX_SRC_INFO > vSrcList;
bool bUseColorkey;
KColor ColorKey; ///< 칼라키
//삭제시 필요 정보
_INNER * pInner; ///< Allocator
X2D::Point<int> point; ///< 텍스쳐 상의 위치
};
/// SprAni 와 Delete Info
struct _SPRITE_PACK
{
_SPRITE_PACK()
{
pSprInfo = NULL;
}
~_SPRITE_PACK()
{
SAFE_DELETE ( pSprInfo );
}
_LOADED_INFO* pSprInfo; ///< 삭제시 참조 데이타
KResSpriteAnimationSPtr spResSprAni; ///< 로드된 스프라이트 애니
};
/// Allocator 에 Loaded 된 리소스
struct _LOADED_SPRITE_SET
{
_LOADED_SPRITE_SET()
{
strSprName = "NotLoaded";
}
~_LOADED_SPRITE_SET()
{
_SPRITE_PACK *pPack = NULL;
bool bRet;
bRet = hashSprAni.get_first_value( pPack );
while ( bRet )
{
SAFE_DELETE(pPack);
bRet = hashSprAni.get_next_value( pPack );
}
hashSprAni.clear();
}
std::string strSprName;
KHash<_SPRITE_PACK *, hashPr_string_nocase> hashSprAni;
};
}
class KUITextureManager : public KSingletoneResourceManager<KUITextureManager>
{
public:
KUITextureManager();
virtual ~KUITextureManager();
void DeviceLost();
KResSpriteAnimation * GetSprAni( const char * szSprSetName, const char * szAniName );
int DelSprAni( const char * szSprSetName, const char * szAniName );
static void SetRenderDevice( class K3DRenderDeviceDX * pDevice );
static void SetTextureSize( unsigned int nSize ) { m_TextureSize = nSize; }
static void Clear();
static int GetHWType() { return m_nHW_Support; }
virtual void DiscardAll();
void OutputTexture();
enum
{
HW_SUPPORT = 0,
NOT_HW_SUPPORT, ///< 하드 웨어 지원 안됨
NOTPOW_SUPPORT, ///< 텍스쳐 2거듭 제곱 지원 안됨
};
protected:
_SPRITE_PACK * add_Texture( const char * szSprSetName, const char * szAniName );
/// SPRITE_SET 추가
_LOADED_SPRITE_SET * add_SprSet( const char * szSprSetName );
/// ResSprAni 추가
KResSpriteAnimation * add_SprAni( _LOADED_SPRITE_SET * pAddSprSet, const char * szSprSetName, const char * szAniName );
bool _add( _INNER * pInner, _SPRITE_PACK * pSprPack );
void _del( _LOADED_INFO * pUpdate );
static unsigned int m_TextureSize; ///< 가로 세로 동일
std::vector< _INNER* > m_vManageList; ///< 내부 메모리 Pool
//AniName 으로 접근 할 수 있는 데이타
KHash<_LOADED_SPRITE_SET *, hashPr_string_nocase > m_setByName; ///< 외부에서 사용하는 실제 텍스쳐
static K3DRenderDeviceDX* m_pDevice;
static int m_nHW_Support; ///< 하드웨어 지원
private:
};
// { [sonador]
#ifdef _KUI_INVALIDATION
class KUICachedTextureManager : public KSingletoneResourceManager< KUICachedTextureManager >
{
public:
enum
{
HW_SUPPORT = 0,
NOT_HW_SUPPORT, ///< 하드 웨어 지원 안됨
NOTPOW_SUPPORT, ///< 텍스쳐 2거듭 제곱 지원 안됨
};
KUICachedTextureManager();
virtual ~KUICachedTextureManager();
static void SetRenderDevice( class K3DRenderDeviceDX* renderDevice );
static bool SupportNonPow2();
K3DTexture* GetTexture( int width, int height );
K3DRenderTarget* GetRenderTarget( int width, int height, UINT level, DWORD depthUsage );
protected:
static class K3DRenderDeviceDX* m_pRenderDevice;
static int m_nHW_Support;
};
#endif
// }