mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-02 09:03:37 +00:00
Cleanup FB Texture caching code
This commit is contained in:
parent
667b3d28ee
commit
cb90bb95ed
|
@ -79,7 +79,6 @@ void ColorBufferToRDRAM::_initFBTexture(void)
|
|||
m_pTexture->realWidth = m_lastBufferWidth;
|
||||
m_pTexture->realHeight = VI_GetMaxBufferHeight(m_lastBufferWidth);
|
||||
m_pTexture->textureBytes = m_pTexture->realWidth * m_pTexture->realHeight * fbTexFormat.colorFormatBytes;
|
||||
textureCache().addFrameBufferTextureSize(m_pTexture->textureBytes);
|
||||
|
||||
{
|
||||
Context::InitTextureParams params;
|
||||
|
|
|
@ -61,7 +61,6 @@ void DepthBufferToRDRAM::init()
|
|||
m_pColorTexture->realWidth = DEPTH_TEX_WIDTH;
|
||||
m_pColorTexture->realHeight = DEPTH_TEX_HEIGHT;
|
||||
m_pColorTexture->textureBytes = m_pColorTexture->realWidth * m_pColorTexture->realHeight;
|
||||
textureCache().addFrameBufferTextureSize(m_pColorTexture->textureBytes);
|
||||
|
||||
m_pDepthTexture = textureCache().addFrameBufferTexture(false);
|
||||
m_pDepthTexture->format = G_IM_FMT_I;
|
||||
|
@ -76,7 +75,6 @@ void DepthBufferToRDRAM::init()
|
|||
m_pDepthTexture->realWidth = DEPTH_TEX_WIDTH;
|
||||
m_pDepthTexture->realHeight = DEPTH_TEX_HEIGHT;
|
||||
m_pDepthTexture->textureBytes = m_pDepthTexture->realWidth * m_pDepthTexture->realHeight * sizeof(float);
|
||||
textureCache().addFrameBufferTextureSize(m_pDepthTexture->textureBytes);
|
||||
|
||||
const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats();
|
||||
Context::InitTextureParams initParams;
|
||||
|
|
|
@ -43,7 +43,6 @@ void RDRAMtoColorBuffer::init()
|
|||
m_pTexture->realWidth = 640;
|
||||
m_pTexture->realHeight = 580;
|
||||
m_pTexture->textureBytes = m_pTexture->realWidth * m_pTexture->realHeight * fbTexFormats.colorFormatBytes;
|
||||
textureCache().addFrameBufferTextureSize(m_pTexture->textureBytes);
|
||||
|
||||
Context::InitTextureParams initParams;
|
||||
initParams.handle = m_pTexture->name;
|
||||
|
|
|
@ -59,7 +59,6 @@ void DepthBuffer::_initDepthImageTexture(FrameBuffer * _pBuffer, CachedTexture&
|
|||
_cachedTexture.realWidth = _cachedTexture.width;
|
||||
_cachedTexture.realHeight = _cachedTexture.height;
|
||||
_cachedTexture.textureBytes = _cachedTexture.realWidth * _cachedTexture.realHeight * fbTexFormat.depthImageFormatBytes;
|
||||
textureCache().addFrameBufferTextureSize(_cachedTexture.textureBytes);
|
||||
|
||||
{
|
||||
Context::InitTextureParams params;
|
||||
|
@ -133,7 +132,6 @@ void DepthBuffer::_initDepthBufferTexture(FrameBuffer * _pBuffer, CachedTexture
|
|||
_pTexture->realWidth = _pTexture->width;
|
||||
_pTexture->realHeight = _pTexture->height;
|
||||
_pTexture->textureBytes = _pTexture->realWidth * _pTexture->realHeight * fbTexFormat.depthFormatBytes;
|
||||
textureCache().addFrameBufferTextureSize(_pTexture->textureBytes);
|
||||
|
||||
Context::InitTextureParams initParams;
|
||||
initParams.handle = _pTexture->name;
|
||||
|
|
|
@ -95,7 +95,6 @@ void FrameBuffer::_initTexture(u16 _width, u16 _height, u16 _format, u16 _size,
|
|||
_pTexture->textureBytes *= fbTexFormats.colorFormatBytes;
|
||||
else
|
||||
_pTexture->textureBytes *= fbTexFormats.monochromeFormatBytes;
|
||||
textureCache().addFrameBufferTextureSize(_pTexture->textureBytes);
|
||||
}
|
||||
|
||||
void FrameBuffer::_setAndAttachTexture(ObjectHandle _fbo, CachedTexture *_pTexture, u32 _t, bool _multisampling)
|
||||
|
|
|
@ -125,7 +125,6 @@ void NoiseTexture::init()
|
|||
m_pTexture[i]->realWidth = NOISE_TEX_WIDTH;
|
||||
m_pTexture[i]->realHeight = NOISE_TEX_HEIGHT;
|
||||
m_pTexture[i]->textureBytes = m_pTexture[i]->realWidth * m_pTexture[i]->realHeight;
|
||||
textureCache().addFrameBufferTextureSize(m_pTexture[i]->textureBytes);
|
||||
|
||||
const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats();
|
||||
{
|
||||
|
|
|
@ -37,7 +37,6 @@ void PaletteTexture::init()
|
|||
m_pTexture->realWidth = 256;
|
||||
m_pTexture->realHeight = 1;
|
||||
m_pTexture->textureBytes = m_pTexture->realWidth * m_pTexture->realHeight * fbTexFormats.lutFormatBytes;
|
||||
textureCache().addFrameBufferTextureSize(m_pTexture->textureBytes);
|
||||
|
||||
Context::InitTextureParams initParams;
|
||||
initParams.handle = m_pTexture->name;
|
||||
|
|
|
@ -36,7 +36,6 @@ void PostProcessor::_createResultBuffer(const FrameBuffer * _pMainBuffer)
|
|||
pTexture->realWidth = pMainTexture->realWidth;
|
||||
pTexture->realHeight = pMainTexture->realHeight;
|
||||
pTexture->textureBytes = pTexture->realWidth * pTexture->realHeight * 4;
|
||||
textureCache().addFrameBufferTextureSize(pTexture->textureBytes);
|
||||
|
||||
Context::InitTextureParams initParams;
|
||||
initParams.handle = pTexture->name;
|
||||
|
|
|
@ -46,7 +46,6 @@ void TexrectDrawer::init()
|
|||
m_pTexture->realWidth = 640;
|
||||
m_pTexture->realHeight = 580;
|
||||
m_pTexture->textureBytes = m_pTexture->realWidth * m_pTexture->realHeight * fbTexFormats.colorFormatBytes;
|
||||
textureCache().addFrameBufferTextureSize(m_pTexture->textureBytes);
|
||||
m_stepX = 2.0f / 640.0f;
|
||||
m_stepY = 2.0f / 580.0f;
|
||||
|
||||
|
|
|
@ -106,7 +106,6 @@ struct Atlas {
|
|||
m_pTexture->realWidth = w;
|
||||
m_pTexture->realHeight = h;
|
||||
m_pTexture->textureBytes = m_pTexture->realWidth * m_pTexture->realHeight * fbTexFormats.noiseFormatBytes;
|
||||
textureCache().addFrameBufferTextureSize(m_pTexture->textureBytes);
|
||||
|
||||
Context::InitTextureParams initParams;
|
||||
initParams.handle = m_pTexture->name;
|
||||
|
|
|
@ -494,7 +494,6 @@ void TextureCache::init()
|
|||
params.data = dummyTexture;
|
||||
gfxContext.init2DTexture(params);
|
||||
|
||||
m_cachedBytes = m_pDummy->textureBytes;
|
||||
activateDummy( 0 );
|
||||
activateDummy(1);
|
||||
current[0] = current[1] = nullptr;
|
||||
|
@ -535,15 +534,12 @@ void TextureCache::destroy()
|
|||
for (FBTextures::const_iterator cur = m_fbTextures.cbegin(); cur != m_fbTextures.cend(); ++cur)
|
||||
gfxContext.deleteTexture(cur->second.name);
|
||||
m_fbTextures.clear();
|
||||
|
||||
m_cachedBytes = 0;
|
||||
}
|
||||
|
||||
void TextureCache::_checkCacheSize()
|
||||
{
|
||||
if (m_textures.size() >= m_maxCacheSize) {
|
||||
CachedTexture& clsTex = m_textures.back();
|
||||
m_cachedBytes -= clsTex.textureBytes;
|
||||
gfxContext.deleteTexture(clsTex.name);
|
||||
m_lruTextureLocations.erase(clsTex.crc);
|
||||
m_textures.pop_back();
|
||||
|
@ -566,20 +562,18 @@ void TextureCache::removeFrameBufferTexture(CachedTexture * _pTexture)
|
|||
{
|
||||
if (_pTexture == nullptr)
|
||||
return;
|
||||
FBTextures::const_iterator iter = m_fbTextures.find(_pTexture->name);
|
||||
FBTextures::const_iterator iter = m_fbTextures.find(u32(_pTexture->name));
|
||||
assert(iter != m_fbTextures.cend());
|
||||
m_cachedBytes -= iter->second.textureBytes;
|
||||
gfxContext.deleteTexture(ObjectHandle(iter->second.name));
|
||||
m_fbTextures.erase(iter);
|
||||
}
|
||||
|
||||
CachedTexture * TextureCache::addFrameBufferTexture(bool _multisample)
|
||||
{
|
||||
_checkCacheSize();
|
||||
ObjectHandle texName(gfxContext.createTexture(_multisample ?
|
||||
textureTarget::TEXTURE_2D_MULTISAMPLE : textureTarget::TEXTURE_2D));
|
||||
m_fbTextures.emplace(texName, texName);
|
||||
return &m_fbTextures.at(texName);
|
||||
m_fbTextures.emplace(u32(texName), texName);
|
||||
return &m_fbTextures.at(u32(texName));
|
||||
}
|
||||
|
||||
struct TileSizes
|
||||
|
@ -1443,7 +1437,6 @@ void TextureCache::_updateBackground()
|
|||
_loadBackground(pCurrent);
|
||||
activateTexture(0, pCurrent);
|
||||
|
||||
m_cachedBytes += pCurrent->textureBytes;
|
||||
current[0] = pCurrent;
|
||||
}
|
||||
|
||||
|
@ -1452,7 +1445,6 @@ void TextureCache::_clear()
|
|||
current[0] = current[1] = nullptr;
|
||||
|
||||
for (auto cur = m_textures.cbegin(); cur != m_textures.cend(); ++cur) {
|
||||
m_cachedBytes -= cur->textureBytes;
|
||||
gfxContext.deleteTexture(cur->name);
|
||||
}
|
||||
m_textures.clear();
|
||||
|
@ -1551,7 +1543,6 @@ void TextureCache::update(u32 _t)
|
|||
return;
|
||||
}
|
||||
|
||||
m_cachedBytes -= currentTex.textureBytes;
|
||||
gfxContext.deleteTexture(currentTex.name);
|
||||
m_lruTextureLocations.erase(locations_iter);
|
||||
m_textures.erase(iter);
|
||||
|
@ -1601,7 +1592,6 @@ void TextureCache::update(u32 _t)
|
|||
_load(_t, pCurrent);
|
||||
activateTexture( _t, pCurrent );
|
||||
|
||||
m_cachedBytes += pCurrent->textureBytes;
|
||||
current[_t] = pCurrent;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,6 @@ struct TextureCache
|
|||
void init();
|
||||
void destroy();
|
||||
CachedTexture * addFrameBufferTexture(bool _multisample);
|
||||
void addFrameBufferTextureSize(u32 _size) {m_cachedBytes += _size;}
|
||||
void removeFrameBufferTexture(CachedTexture * _pTexture);
|
||||
void activateTexture(u32 _t, CachedTexture *_pTexture);
|
||||
void activateDummy(u32 _t);
|
||||
|
@ -69,7 +68,6 @@ private:
|
|||
, m_pMSDummy(nullptr)
|
||||
, m_hits(0)
|
||||
, m_misses(0)
|
||||
, m_cachedBytes(0)
|
||||
, m_curUnpackAlignment(4)
|
||||
, m_toggleDumpTex(false)
|
||||
{
|
||||
|
@ -93,14 +91,13 @@ private:
|
|||
|
||||
typedef std::list<CachedTexture> Textures;
|
||||
typedef std::unordered_map<u32, Textures::iterator> Texture_Locations;
|
||||
typedef std::map<graphics::ObjectHandle, CachedTexture> FBTextures;
|
||||
typedef std::unordered_map<u32, CachedTexture> FBTextures;
|
||||
Textures m_textures;
|
||||
Texture_Locations m_lruTextureLocations;
|
||||
FBTextures m_fbTextures;
|
||||
CachedTexture * m_pDummy;
|
||||
CachedTexture * m_pMSDummy;
|
||||
u32 m_hits, m_misses;
|
||||
u32 m_cachedBytes;
|
||||
s32 m_curUnpackAlignment;
|
||||
bool m_toggleDumpTex;
|
||||
const size_t m_maxCacheSize = 8000;
|
||||
|
|
|
@ -38,7 +38,6 @@ void ZlutTexture::init()
|
|||
m_pTexture->realWidth = 512;
|
||||
m_pTexture->realHeight = 512;
|
||||
m_pTexture->textureBytes = m_pTexture->realWidth * m_pTexture->realHeight * fbTexFormats.lutFormatBytes;
|
||||
textureCache().addFrameBufferTextureSize(m_pTexture->textureBytes);
|
||||
|
||||
Context::InitTextureParams initParams;
|
||||
initParams.handle = m_pTexture->name;
|
||||
|
|
Loading…
Reference in New Issue
Block a user