Render 3D: Whenever the texture deposterization or upscaling settings are changed, simply reload the existing textures instead of completely destroying and recreating them from scratch.

This commit is contained in:
rogerman 2016-12-02 22:08:21 -08:00
parent ac69f1e229
commit c5678a6ba4
5 changed files with 28 additions and 12 deletions

View File

@ -735,6 +735,8 @@ void OpenGLTexture::Load(bool isNewTexture)
default:
break;
}
this->_isLoadNeeded = false;
}
GLuint OpenGLTexture::GetID() const
@ -1311,8 +1313,6 @@ OpenGLTexture* OpenGLRenderer::GetLoadedTextureFromPolygon(const POLY &thePoly,
{
theTexture = new OpenGLTexture(thePoly.texParam, thePoly.texPalette);
theTexture->SetUnpackBuffer(this->_workingTextureUnpackBuffer);
theTexture->SetDeposterizeBuffer(this->_workingTextureUnpackBuffer, this->_textureDeposterizeDstSurface.workingSurface[0]);
theTexture->SetUpscalingBuffer(this->_textureUpscaleBuffer);
texCache.Add(theTexture);
}
@ -1324,9 +1324,15 @@ OpenGLTexture* OpenGLRenderer::GetLoadedTextureFromPolygon(const POLY &thePoly,
if (theTexture->IsLoadNeeded() && isTextureEnabled)
{
const size_t previousScalingFactor = theTexture->GetScalingFactor();
theTexture->SetDeposterizeBuffer(this->_workingTextureUnpackBuffer, this->_textureDeposterizeDstSurface.workingSurface[0]);
theTexture->SetUpscalingBuffer(this->_textureUpscaleBuffer);
theTexture->SetUseDeposterize(this->_textureDeposterize);
theTexture->SetScalingFactor(this->_textureScalingFactor);
theTexture->Load(isNewTexture);
theTexture->Load(isNewTexture || (previousScalingFactor != this->_textureScalingFactor));
}
return theTexture;

View File

@ -1179,6 +1179,8 @@ void SoftRasterizerTexture::Load()
ColorspaceConvertBuffer8888To6665<false, false>(this->_renderData, this->_renderData, this->_renderWidth * this->_renderHeight);
}
this->_isLoadNeeded = false;
}
u32* SoftRasterizerTexture::GetUnpackData()

View File

@ -408,7 +408,7 @@ void Render3D::SetTextureProcessingProperties(size_t scalingFactor, bool willDep
{
const bool isScaleValid = ( (scalingFactor == 2) || (scalingFactor == 4) );
const size_t newScalingFactor = (isScaleValid) ? scalingFactor : 1;
bool needTexCacheReset = false;
bool needTextureReload = false;
if ( willDeposterize && !this->_textureDeposterize)
{
@ -422,7 +422,7 @@ void Render3D::SetTextureProcessingProperties(size_t scalingFactor, bool willDep
memset(this->_textureDeposterizeDstSurface.Surface, 0, bufferSize);
this->_textureDeposterize = true;
needTexCacheReset = true;
needTextureReload = true;
}
else if (!willDeposterize && this->_textureDeposterize)
{
@ -431,7 +431,7 @@ void Render3D::SetTextureProcessingProperties(size_t scalingFactor, bool willDep
this->_textureDeposterizeDstSurface.workingSurface[0] = NULL;
this->_textureDeposterize = false;
needTexCacheReset = true;
needTextureReload = true;
}
if (newScalingFactor != this->_textureScalingFactor)
@ -442,14 +442,14 @@ void Render3D::SetTextureProcessingProperties(size_t scalingFactor, bool willDep
this->_textureUpscaleBuffer = newTextureBuffer;
free_aligned(oldTextureBuffer);
needTexCacheReset = true;
needTextureReload = true;
}
this->_textureSmooth = willSmooth;
if (needTexCacheReset)
if (needTextureReload)
{
texCache.Reset();
texCache.ForceReloadAllTextures();
}
}

View File

@ -315,6 +315,14 @@ void TextureCache::Reset()
memset(this->_paletteDump, 0, sizeof(this->_paletteDump));
}
void TextureCache::ForceReloadAllTextures()
{
for (TextureCacheMap::iterator it(this->_texCacheMap.begin()); it != this->_texCacheMap.end(); ++it)
{
it->second->SetLoadNeeded();
}
}
TextureStore* TextureCache::GetTexture(u32 texAttributes, u32 palAttributes)
{
TextureStore *theTexture = NULL;
@ -602,7 +610,7 @@ size_t TextureStore::GetUnpackSizeUsingFormat(const TextureStoreUnpackFormat tex
template <TextureStoreUnpackFormat TEXCACHEFORMAT>
void TextureStore::Unpack(u32 *unpackBuffer)
{
{
// Whenever a 1-bit alpha or no-alpha texture is unpacked (this means any texture
// format that is not A3I5 or A5I3), set all transparent pixels to 0 so that 3D
// renderers can assume that the transparent color is 0 during texture sampling.
@ -651,13 +659,12 @@ void TextureStore::Unpack(u32 *unpackBuffer)
#ifdef DO_DEBUG_DUMP_TEXTURE
this->DebugDump();
#endif
this->_isLoadNeeded = false;
}
void TextureStore::Load(void *targetBuffer)
{
this->Unpack<TexFormat_32bpp>((u32 *)targetBuffer);
this->_isLoadNeeded = false;
}
bool TextureStore::IsSuspectedInvalid() const

View File

@ -74,6 +74,7 @@ public:
void Invalidate();
void Evict();
void Reset();
void ForceReloadAllTextures();
TextureStore* GetTexture(u32 texAttributes, u32 palAttributes);