Commit 689e1962 authored by D-AIRY's avatar D-AIRY

Pool for textures

parent 13ece842
......@@ -115,8 +115,9 @@ bool XMETHODCALLTYPE CMaterialSystem::loadTexture(const char *szName, IXTexture
LibReport(REPORT_MSG_LEVEL_WARNING, "Texture '%s' has no mipmaps!\n", szFileName);
}
CTexture *pTex = new CTexture(this, pRes);
//CTexture *pTex = new CTexture(this, pRes);
CTexture *pTex = m_poolTextures.Alloc(this, pRes);
m_mpTextures[sName] = pTex;
pTex->setName(m_mpTextures.TmpNode->Key.c_str());
......@@ -203,6 +204,8 @@ void CMaterialSystem::onTextureRelease(CTexture *pTexture)
assert(pTexture);
m_mpTextures[pTexture->getName()] = NULL;
m_poolTextures.Delete(pTexture);
}
void CMaterialSystem::queueTextureUpload(CTexture *pTexture)
......@@ -263,8 +266,6 @@ CTexture::CTexture(CMaterialSystem *pMaterialSystem, IXResourceTexture *m_pResou
CTexture::~CTexture()
{
m_pMaterialSystem->onTextureRelease(this);
mem_release(m_pResource);
for(UINT i = 0; i < m_uFrameCount; ++i)
......@@ -274,6 +275,15 @@ CTexture::~CTexture()
mem_delete_a(m_ppGXTexture);
}
void XMETHODCALLTYPE CTexture::Release()
{
--m_uRefCount;
if(!m_uRefCount)
{
m_pMaterialSystem->onTextureRelease(this);
}
}
void XMETHODCALLTYPE CTexture::getAPITexture(IGXBaseTexture **ppTexture, UINT uFrame)
{
assert(uFrame < m_uFrameCount);
......
......@@ -13,6 +13,7 @@ class CTexture: public IXTexture
public:
CTexture(CMaterialSystem *pMaterialSystem, IXResourceTexture *m_pResource);
~CTexture();
void XMETHODCALLTYPE Release() override;
void XMETHODCALLTYPE getAPITexture(IGXBaseTexture **ppTexture, UINT uFrame = 0) override;
bool XMETHODCALLTYPE isReady() const override;
......@@ -96,6 +97,7 @@ protected:
} m_objectData;
IGXConstantBuffer *m_pObjectConstantBuffer = NULL;
MemAlloc<CTexture> m_poolTextures;
Array<IXTextureProxy*> m_aTextureProxies;
AssotiativeArray<String, CTexture*> m_mpTextures;
CConcurrentQueue<CTexture*> m_queueTextureToLoad;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment