diff --git a/desmume/src/OGLRender.cpp b/desmume/src/OGLRender.cpp index b16b386bf..95135ff38 100644 --- a/desmume/src/OGLRender.cpp +++ b/desmume/src/OGLRender.cpp @@ -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; diff --git a/desmume/src/rasterize.cpp b/desmume/src/rasterize.cpp index 2ec747747..b8bdbe2f8 100644 --- a/desmume/src/rasterize.cpp +++ b/desmume/src/rasterize.cpp @@ -1179,6 +1179,8 @@ void SoftRasterizerTexture::Load() ColorspaceConvertBuffer8888To6665<false, false>(this->_renderData, this->_renderData, this->_renderWidth * this->_renderHeight); } + + this->_isLoadNeeded = false; } u32* SoftRasterizerTexture::GetUnpackData() diff --git a/desmume/src/render3D.cpp b/desmume/src/render3D.cpp index 18a1ae376..da3c56ac4 100644 --- a/desmume/src/render3D.cpp +++ b/desmume/src/render3D.cpp @@ -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(); } } diff --git a/desmume/src/texcache.cpp b/desmume/src/texcache.cpp index ed45a9f70..cf73dcec4 100644 --- a/desmume/src/texcache.cpp +++ b/desmume/src/texcache.cpp @@ -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 diff --git a/desmume/src/texcache.h b/desmume/src/texcache.h index 9af1baf7f..32cd82982 100644 --- a/desmume/src/texcache.h +++ b/desmume/src/texcache.h @@ -74,6 +74,7 @@ public: void Invalidate(); void Evict(); void Reset(); + void ForceReloadAllTextures(); TextureStore* GetTexture(u32 texAttributes, u32 palAttributes);