diff --git a/src/OpenGL.cpp b/src/OpenGL.cpp index 31810086..af2984dd 100644 --- a/src/OpenGL.cpp +++ b/src/OpenGL.cpp @@ -1349,6 +1349,8 @@ void OGLRender::_destroyData() m_renderState = rsNone; if (config.bloomFilter.enable != 0) PostProcessor::get().destroy(); + if (TFH.optionsChanged()) + TFH.shutdown(); TextDrawer::get().destroy(); Combiner_Destroy(); FrameBuffer_Destroy(); @@ -1444,57 +1446,66 @@ void displayLoadProgress(const wchar_t *format, ...) glBindFramebuffer(GL_DRAW_FRAMEBUFFER, pBuffer->m_FBO); } +u32 TextureFilterHandler::_getConfigOptions() const +{ + u32 options = textureFilters[config.textureFilter.txFilterMode] | textureEnhancements[config.textureFilter.txEnhancementMode]; + if (config.textureFilter.txHiresEnable) + options |= RICE_HIRESTEXTURES; + if (config.textureFilter.txForce16bpp) + options |= FORCE16BPP_TEX | FORCE16BPP_HIRESTEX; + if (config.textureFilter.txCacheCompression) + options |= GZ_TEXCACHE | GZ_HIRESTEXCACHE; + if (config.textureFilter.txSaveCache) + options |= (DUMP_TEXCACHE | DUMP_HIRESTEXCACHE); + if (config.textureFilter.txHiresFullAlphaChannel) + options |= LET_TEXARTISTS_FLY; + if (config.textureFilter.txDump) + options |= DUMP_TEX; + return options; +} + void TextureFilterHandler::init() { - if (!isInited()) { - m_inited = config.textureFilter.txFilterMode | config.textureFilter.txEnhancementMode | config.textureFilter.txHiresEnable; - if (m_inited != 0) { - u32 options = textureFilters[config.textureFilter.txFilterMode] | textureEnhancements[config.textureFilter.txEnhancementMode]; - if (config.textureFilter.txHiresEnable) - options |= RICE_HIRESTEXTURES; - if (config.textureFilter.txForce16bpp) - options |= FORCE16BPP_TEX | FORCE16BPP_HIRESTEX; - if (config.textureFilter.txCacheCompression) - options |= GZ_TEXCACHE | GZ_HIRESTEXCACHE; - if (config.textureFilter.txSaveCache) - options |= (DUMP_TEXCACHE | DUMP_HIRESTEXCACHE); - if (config.textureFilter.txHiresFullAlphaChannel) - options |= LET_TEXARTISTS_FLY; - if (config.textureFilter.txDump) - options |= DUMP_TEX; + if (isInited()) + return; - GLint maxTextureSize; - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); - wchar_t wRomName[32]; - ::mbstowcs(wRomName, RSP.romname, 32); - wchar_t txPath[PLUGIN_PATH_SIZE+16]; - wchar_t * pTexPackPath = config.textureFilter.txPath; - if (::wcslen(config.textureFilter.txPath) == 0) { - api().GetUserDataPath(txPath); - gln_wcscat(txPath, wst("/hires_texture")); - pTexPackPath = txPath; - } - wchar_t txCachePath[PLUGIN_PATH_SIZE]; - api().GetUserCachePath(txCachePath); + m_inited = config.textureFilter.txFilterMode | config.textureFilter.txEnhancementMode | config.textureFilter.txHiresEnable; + if (m_inited == 0) + return; - m_inited = txfilter_init(maxTextureSize, // max texture width supported by hardware - maxTextureSize, // max texture height supported by hardware - 32, // max texture bpp supported by hardware - options, - config.textureFilter.txCacheSize, // cache texture to system memory - txCachePath, // path to store cache files - pTexPackPath, // path to texture packs folder - wRomName, // name of ROM. must be no longer than 256 characters - displayLoadProgress); - } + m_options = _getConfigOptions(); + + GLint maxTextureSize; + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); + wchar_t wRomName[32]; + ::mbstowcs(wRomName, RSP.romname, 32); + wchar_t txPath[PLUGIN_PATH_SIZE + 16]; + wchar_t * pTexPackPath = config.textureFilter.txPath; + if (::wcslen(config.textureFilter.txPath) == 0) { + api().GetUserDataPath(txPath); + gln_wcscat(txPath, wst("/hires_texture")); + pTexPackPath = txPath; } + wchar_t txCachePath[PLUGIN_PATH_SIZE]; + api().GetUserCachePath(txCachePath); + + m_inited = txfilter_init(maxTextureSize, // max texture width supported by hardware + maxTextureSize, // max texture height supported by hardware + 32, // max texture bpp supported by hardware + m_options, + config.textureFilter.txCacheSize, // cache texture to system memory + txCachePath, // path to store cache files + pTexPackPath, // path to texture packs folder + wRomName, // name of ROM. must be no longer than 256 characters + displayLoadProgress); + } void TextureFilterHandler::shutdown() { if (isInited()) { txfilter_shutdown(); - m_inited = 0; + m_inited = m_options = 0; } } diff --git a/src/OpenGL.h b/src/OpenGL.h index fd03022f..a41e210b 100644 --- a/src/OpenGL.h +++ b/src/OpenGL.h @@ -264,14 +264,17 @@ OGLVideo & video() class TextureFilterHandler { public: - TextureFilterHandler() : m_inited(0) {} + TextureFilterHandler() : m_inited(0), m_options(0) {} // It's not safe to call shutdown() in destructor, because texture filter has its own static objects, which can be destroyed first. - ~TextureFilterHandler() { m_inited = 0; } + ~TextureFilterHandler() { m_inited = m_options = 0; } void init(); void shutdown(); bool isInited() const { return m_inited != 0; } + bool optionsChanged() const { return _getConfigOptions() != m_options; } private: + u32 _getConfigOptions() const; u32 m_inited; + u32 m_options; }; extern TextureFilterHandler TFH; diff --git a/src/common/CommonAPIImpl_common.cpp b/src/common/CommonAPIImpl_common.cpp index 20728f61..836d2b92 100644 --- a/src/common/CommonAPIImpl_common.cpp +++ b/src/common/CommonAPIImpl_common.cpp @@ -31,7 +31,6 @@ void RSP_ThreadProc(std::mutex * _pRspThreadMtx, std::mutex * _pPluginThreadMtx, GBI.init(); Config_LoadConfig(); video().start(); - TFH.init(); assert(!isGLError()); while (true) {