- implemented a proper texture composition cache.

This will mostly ensure that each patch used for composition is only loaded once and automatically unloaded once no longer needed.
So far only for paletted rendering, but the same logic can be used for true color as well.
This commit is contained in:
Christoph Oelckers 2018-12-10 01:17:39 +01:00
commit 2e7bcf9e41
32 changed files with 367 additions and 60 deletions

View file

@ -373,7 +373,14 @@ void OpenGLFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation)
FHardwareTexture::UnbindAll();
}
FModelRenderer *OpenGLFrameBuffer::CreateModelRenderer(int mli)
bool OpenGLFrameBuffer::CheckPrecacheMaterial(FMaterial *mat)
{
if (!mat->tex->GetImage()) return true;
auto base = static_cast<FHardwareTexture*>(mat->GetLayer(0));
return base->Exists(0);
}
FModelRenderer *OpenGLFrameBuffer::CreateModelRenderer(int mli)
{
return new FGLModelRenderer(nullptr, gl_RenderState, mli);
}

View file

@ -36,6 +36,7 @@ public:
void SetTextureFilterMode() override;
IHardwareTexture *CreateHardwareTexture(FTexture *tex) override;
void PrecacheMaterial(FMaterial *mat, int translation) override;
bool CheckPrecacheMaterial(FMaterial *mat) override;
FModelRenderer *CreateModelRenderer(int mli) override;
void TextureFilterChanged() override;
void BeginFrame() override;

View file

@ -467,4 +467,29 @@ bool FHardwareTexture::BindOrCreate(FTexture *tex, int texunit, int clampmode, i
return true;
}
//===========================================================================
//
// Binds a texture to the renderer
//
//===========================================================================
bool FHardwareTexture::Exists(int translation)
{
int usebright = false;
if (translation <= 0)
{
translation = -translation;
}
else
{
auto remap = TranslationToTable(translation);
translation = remap == nullptr ? 0 : remap->GetUniqueIndex();
}
TranslatedTexture *pTex = GetTexID(translation);
return (pTex->glTexID != 0);
}
}

View file

@ -81,6 +81,7 @@ public:
unsigned int Bind(int texunit, int translation, bool needmipmap);
bool BindOrCreate(FTexture *tex, int texunit, int clampmode, int translation, int flags);
bool Exists(int translation);
void AllocateBuffer(int w, int h, int texelsize);
uint8_t *MapBuffer();