1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

Move TextureFilterHandler class to separate files.

This commit is contained in:
Sergey Lipskiy 2016-06-10 17:58:47 +06:00
parent 86fbea9edc
commit 2fbee3661f
11 changed files with 194 additions and 168 deletions

View File

@ -265,6 +265,7 @@
<ClCompile Include="..\..\src\RSP.cpp" />
<ClCompile Include="..\..\src\ShaderUtils.cpp" />
<ClCompile Include="..\..\src\TextDrawer.cpp" />
<ClCompile Include="..\..\src\TextureFilterHandler.cpp" />
<ClCompile Include="..\..\src\Textures.cpp" />
<ClCompile Include="..\..\src\Turbo3D.cpp" />
<ClCompile Include="..\..\src\VI.cpp" />
@ -345,6 +346,7 @@
<ClInclude Include="..\..\src\RSP.h" />
<ClInclude Include="..\..\src\ShaderUtils.h" />
<ClInclude Include="..\..\src\TextDrawer.h" />
<ClInclude Include="..\..\src\TextureFilterHandler.h" />
<ClInclude Include="..\..\src\Textures.h" />
<ClInclude Include="..\..\src\Turbo3D.h" />
<ClInclude Include="..\..\src\Types.h" />

View File

@ -215,6 +215,9 @@
<ClCompile Include="..\..\src\BufferCopy\ColorBufferToRDRAM_GL.cpp">
<Filter>Source Files\BufferCopy</Filter>
</ClCompile>
<ClCompile Include="..\..\src\TextureFilterHandler.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\3DMath.h">
@ -388,5 +391,8 @@
<ClInclude Include="..\..\src\BufferCopy\WriteToRDRAM.h">
<Filter>Header Files\BufferCopy</Filter>
</ClInclude>
<ClInclude Include="..\..\src\TextureFilterHandler.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -43,6 +43,7 @@ set(GLideN64_SOURCES
ShaderUtils.cpp
Textures.cpp
TextDrawer.cpp
TextureFilterHandler.cpp
PostProcessor.cpp
VI.cpp
BufferCopy/ColorBufferToRDRAM.cpp

View File

@ -1,6 +1,5 @@
#include <algorithm>
#include <assert.h>
#include <stdio.h>
#include <math.h>
#include <time.h> /* 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;

View File

@ -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();

View File

@ -13,6 +13,7 @@
#include "GBI.h"
#include "PluginAPI.h"
#include "Config.h"
#include "TextureFilterHandler.h"
using namespace std;

View File

@ -0,0 +1,144 @@
#include <stdarg.h>
#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;

View File

@ -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

View File

@ -16,6 +16,7 @@
#include "Config.h"
#include "Keys.h"
#include "GLideNHQ/Ext_TxFilter.h"
#include "TextureFilterHandler.h"
using namespace std;

View File

@ -1,22 +1,23 @@
#ifdef OS_WINDOWS
# include <windows.h>
#else
# include "../winlnxdefs.h"
# include <winlnxdefs.h>
#endif // OS_WINDOWS
#include <assert.h>
#include "../PluginAPI.h"
#include <PluginAPI.h>
#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 <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 <TextureFilterHandler.h>
#include <Log.h>
PluginAPI & PluginAPI::get()
{

View File

@ -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"