From 2fbee3661f5a7e75cad5e4b66ec02b2999e4f166 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Fri, 10 Jun 2016 17:58:47 +0600 Subject: [PATCH] Move TextureFilterHandler class to separate files. --- projects/msvc12/GLideN64.vcxproj | 2 + projects/msvc12/GLideN64.vcxproj.filters | 6 + src/CMakeLists.txt | 1 + src/OpenGL.cpp | 139 +--------------------- src/OpenGL.h | 18 --- src/RSP.cpp | 1 + src/TextureFilterHandler.cpp | 144 +++++++++++++++++++++++ src/TextureFilterHandler.h | 24 ++++ src/Textures.cpp | 1 + src/common/CommonAPIImpl_common.cpp | 25 ++-- src/gDP.cpp | 1 + 11 files changed, 194 insertions(+), 168 deletions(-) create mode 100644 src/TextureFilterHandler.cpp create mode 100644 src/TextureFilterHandler.h diff --git a/projects/msvc12/GLideN64.vcxproj b/projects/msvc12/GLideN64.vcxproj index fca7e8db..3132f4c7 100644 --- a/projects/msvc12/GLideN64.vcxproj +++ b/projects/msvc12/GLideN64.vcxproj @@ -265,6 +265,7 @@ + @@ -345,6 +346,7 @@ + diff --git a/projects/msvc12/GLideN64.vcxproj.filters b/projects/msvc12/GLideN64.vcxproj.filters index 2ae8cb31..aef356ad 100644 --- a/projects/msvc12/GLideN64.vcxproj.filters +++ b/projects/msvc12/GLideN64.vcxproj.filters @@ -215,6 +215,9 @@ Source Files\BufferCopy + + Source Files + @@ -388,5 +391,8 @@ Header Files\BufferCopy + + Header Files + \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6896b2bb..3ddaf69c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,6 +43,7 @@ set(GLideN64_SOURCES ShaderUtils.cpp Textures.cpp TextDrawer.cpp + TextureFilterHandler.cpp PostProcessor.cpp VI.cpp BufferCopy/ColorBufferToRDRAM.cpp diff --git a/src/OpenGL.cpp b/src/OpenGL.cpp index c95ef350..a290ff6b 100644 --- a/src/OpenGL.cpp +++ b/src/OpenGL.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include /* time_t, struct tm, difftime, time, mktime */ @@ -18,15 +17,13 @@ #include "FrameBuffer.h" #include "DepthBuffer.h" #include "FrameBufferInfo.h" -#include "GLideNHQ/Ext_TxFilter.h" #include "VI.h" #include "Config.h" -#include "wst.h" #include "Log.h" #include "TextDrawer.h" -#include "PluginAPI.h" #include "PostProcessor.h" #include "ShaderUtils.h" +#include "TextureFilterHandler.h" using namespace std; @@ -1927,137 +1924,3 @@ void OGLRender::_setSpecialTexrect() const else texturedRectSpecial = nullptr; } - -static -u32 textureFilters[] = { - NO_FILTER, //"None" - SMOOTH_FILTER_1, //"Smooth filtering 1" - SMOOTH_FILTER_2, //"Smooth filtering 2" - SMOOTH_FILTER_3, //"Smooth filtering 3" - SMOOTH_FILTER_4, //"Smooth filtering 4" - SHARP_FILTER_1, //"Sharp filtering 1" - SHARP_FILTER_2, //"Sharp filtering 2" -}; - -static -u32 textureEnhancements[] = { - NO_ENHANCEMENT, //"None" - NO_ENHANCEMENT, //"Store" - X2_ENHANCEMENT, //"X2" - X2SAI_ENHANCEMENT, //"X2SAI" - HQ2X_ENHANCEMENT, //"HQ2X" - HQ2XS_ENHANCEMENT, //"HQ2XS" - LQ2X_ENHANCEMENT, //"LQ2X" - LQ2XS_ENHANCEMENT, //"LQ2XS" - HQ4X_ENHANCEMENT, //"HQ4X" - BRZ2X_ENHANCEMENT, //"2XBRZ" - BRZ3X_ENHANCEMENT, //"3XBRZ" - BRZ4X_ENHANCEMENT, //"4XBRZ" - BRZ5X_ENHANCEMENT, //"5XBRZ" - BRZ6X_ENHANCEMENT //"6XBRZ" -}; - -void displayLoadProgress(const wchar_t *format, ...) -{ - va_list args; - wchar_t wbuf[INFO_BUF]; - char buf[INFO_BUF]; - - // process input -#ifdef ANDROID - const u32 bufSize = 2048; - char cbuf[bufSize]; - char fmt[bufSize]; - wcstombs(fmt, format, bufSize); - va_start(args, format); - vsprintf(cbuf, fmt, args); - va_end(args); - mbstowcs(wbuf, cbuf, INFO_BUF); -#else - va_start(args, format); - vswprintf(wbuf, INFO_BUF, format, args); - va_end(args); -#endif - - // XXX: convert to multibyte - wcstombs(buf, wbuf, INFO_BUF); - - FrameBuffer* pBuffer = frameBufferList().getCurrent(); - if (pBuffer != nullptr) - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); - - OGLRender & render = video().getRender(); - render.clearColorBuffer(nullptr); - render.drawText(buf, -0.9f, 0); - video().swapBuffers(); - - if (pBuffer != nullptr) - 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; - if (config.textureFilter.txDeposterize) - options |= DEPOSTERIZE; - return options; -} - -void TextureFilterHandler::init() -{ - if (isInited()) - return; - - m_inited = config.textureFilter.txFilterMode | config.textureFilter.txEnhancementMode | config.textureFilter.txHiresEnable; - if (m_inited == 0) - return; - - 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 = m_options = 0; - } -} - -TextureFilterHandler TFH; diff --git a/src/OpenGL.h b/src/OpenGL.h index d35f9a9f..6f2000a4 100644 --- a/src/OpenGL.h +++ b/src/OpenGL.h @@ -352,24 +352,6 @@ OGLVideo & video() return OGLVideo::get(); } -class TextureFilterHandler -{ -public: - 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 = 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; - void initGLFunctions(); bool checkFBO(); bool isGLError(); diff --git a/src/RSP.cpp b/src/RSP.cpp index 14eff29a..44eab689 100644 --- a/src/RSP.cpp +++ b/src/RSP.cpp @@ -13,6 +13,7 @@ #include "GBI.h" #include "PluginAPI.h" #include "Config.h" +#include "TextureFilterHandler.h" using namespace std; diff --git a/src/TextureFilterHandler.cpp b/src/TextureFilterHandler.cpp new file mode 100644 index 00000000..7cb45d2d --- /dev/null +++ b/src/TextureFilterHandler.cpp @@ -0,0 +1,144 @@ +#include +#include "GLideNHQ/Ext_TxFilter.h" + +#include "wst.h" +#include "RSP.h" +#include "OpenGL.h" +#include "Config.h" +#include "PluginAPI.h" +#include "FrameBuffer.h" +#include "TextureFilterHandler.h" + +static +u32 textureFilters[] = { + NO_FILTER, //"None" + SMOOTH_FILTER_1, //"Smooth filtering 1" + SMOOTH_FILTER_2, //"Smooth filtering 2" + SMOOTH_FILTER_3, //"Smooth filtering 3" + SMOOTH_FILTER_4, //"Smooth filtering 4" + SHARP_FILTER_1, //"Sharp filtering 1" + SHARP_FILTER_2, //"Sharp filtering 2" +}; + +static +u32 textureEnhancements[] = { + NO_ENHANCEMENT, //"None" + NO_ENHANCEMENT, //"Store" + X2_ENHANCEMENT, //"X2" + X2SAI_ENHANCEMENT, //"X2SAI" + HQ2X_ENHANCEMENT, //"HQ2X" + HQ2XS_ENHANCEMENT, //"HQ2XS" + LQ2X_ENHANCEMENT, //"LQ2X" + LQ2XS_ENHANCEMENT, //"LQ2XS" + HQ4X_ENHANCEMENT, //"HQ4X" + BRZ2X_ENHANCEMENT, //"2XBRZ" + BRZ3X_ENHANCEMENT, //"3XBRZ" + BRZ4X_ENHANCEMENT, //"4XBRZ" + BRZ5X_ENHANCEMENT, //"5XBRZ" + BRZ6X_ENHANCEMENT //"6XBRZ" +}; + +void displayLoadProgress(const wchar_t *format, ...) +{ + va_list args; + wchar_t wbuf[INFO_BUF]; + char buf[INFO_BUF]; + + // process input +#ifdef ANDROID + const u32 bufSize = 2048; + char cbuf[bufSize]; + char fmt[bufSize]; + wcstombs(fmt, format, bufSize); + va_start(args, format); + vsprintf(cbuf, fmt, args); + va_end(args); + mbstowcs(wbuf, cbuf, INFO_BUF); +#else + va_start(args, format); + vswprintf(wbuf, INFO_BUF, format, args); + va_end(args); +#endif + + // XXX: convert to multibyte + wcstombs(buf, wbuf, INFO_BUF); + + FrameBuffer* pBuffer = frameBufferList().getCurrent(); + if (pBuffer != nullptr) + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + + OGLRender & render = video().getRender(); + render.clearColorBuffer(nullptr); + render.drawText(buf, -0.9f, 0); + video().swapBuffers(); + + if (pBuffer != nullptr) + 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; + if (config.textureFilter.txDeposterize) + options |= DEPOSTERIZE; + return options; +} + +void TextureFilterHandler::init() +{ + if (isInited()) + return; + + m_inited = config.textureFilter.txFilterMode | config.textureFilter.txEnhancementMode | config.textureFilter.txHiresEnable; + if (m_inited == 0) + return; + + 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 = m_options = 0; + } +} + +TextureFilterHandler TFH; diff --git a/src/TextureFilterHandler.h b/src/TextureFilterHandler.h new file mode 100644 index 00000000..2940a6db --- /dev/null +++ b/src/TextureFilterHandler.h @@ -0,0 +1,24 @@ +#ifndef TEXTUREFILTERHANDLER_H +#define TEXTUREFILTERHANDLER_H + +#include "Types.h" + +class TextureFilterHandler +{ +public: + 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 = 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; + +#endif // TEXTUREFILTERHANDLER_H diff --git a/src/Textures.cpp b/src/Textures.cpp index c701c232..b579e309 100644 --- a/src/Textures.cpp +++ b/src/Textures.cpp @@ -16,6 +16,7 @@ #include "Config.h" #include "Keys.h" #include "GLideNHQ/Ext_TxFilter.h" +#include "TextureFilterHandler.h" using namespace std; diff --git a/src/common/CommonAPIImpl_common.cpp b/src/common/CommonAPIImpl_common.cpp index abb71c6a..1f8b216c 100644 --- a/src/common/CommonAPIImpl_common.cpp +++ b/src/common/CommonAPIImpl_common.cpp @@ -1,22 +1,23 @@ #ifdef OS_WINDOWS # include #else -# include "../winlnxdefs.h" +# include #endif // OS_WINDOWS #include -#include "../PluginAPI.h" +#include -#include "../N64.h" -#include "../GLideN64.h" -#include "../OpenGL.h" -#include "../RSP.h" -#include "../RDP.h" -#include "../VI.h" -#include "../Config.h" -#include "../Debug.h" -#include "../FrameBufferInfo.h" -#include "../Log.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include PluginAPI & PluginAPI::get() { diff --git a/src/gDP.cpp b/src/gDP.cpp index 97adfc1b..6bf1ec47 100644 --- a/src/gDP.cpp +++ b/src/gDP.cpp @@ -16,6 +16,7 @@ #include "FrameBuffer.h" #include "DepthBuffer.h" #include "FrameBufferInfo.h" +#include "TextureFilterHandler.h" #include "VI.h" #include "Config.h" #include "Combiner.h"