mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-07 03:13:49 +00:00
Code refactor: simplify texture fetching shader parts.
This commit is contained in:
parent
dfada113d3
commit
509ee7ed10
|
@ -24,6 +24,14 @@ public:
|
|||
return (m_mode & 2) != 0;
|
||||
}
|
||||
|
||||
bool useYUVCoversion() const {
|
||||
return (m_mode & 3) != 3;
|
||||
}
|
||||
|
||||
bool useTextureFiltering() const {
|
||||
return (m_mode & 3) != 0;
|
||||
}
|
||||
|
||||
private:
|
||||
u32 m_mode;
|
||||
};
|
||||
|
@ -901,14 +909,23 @@ public:
|
|||
class ShaderFragmentHeaderReadMSTex : public ShaderPart
|
||||
{
|
||||
public:
|
||||
ShaderFragmentHeaderReadMSTex(const opengl::GLInfo & _glinfo)
|
||||
ShaderFragmentHeaderReadMSTex(const opengl::GLInfo & _glinfo) : m_glinfo(_glinfo)
|
||||
{
|
||||
if (!_glinfo.isGLES2 && config.video.multisampling > 0) {
|
||||
m_part =
|
||||
}
|
||||
|
||||
void write(std::stringstream & shader) const override
|
||||
{
|
||||
if (!m_glinfo.isGLES2 &&
|
||||
config.video.multisampling > 0 &&
|
||||
(g_cycleType == G_CYC_COPY || g_textureConvert.useTextureFiltering()))
|
||||
{
|
||||
shader <<
|
||||
"lowp vec4 readTexMS(in lowp sampler2DMS mstex, in mediump vec2 texCoord, in lowp int fbMonochrome, in lowp int fbFixedAlpha);\n";
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const opengl::GLInfo& m_glinfo;
|
||||
};
|
||||
|
||||
class ShaderFragmentHeaderDither : public ShaderPart
|
||||
|
@ -945,34 +962,23 @@ public:
|
|||
class ShaderFragmentHeaderReadTex : public ShaderPart
|
||||
{
|
||||
public:
|
||||
ShaderFragmentHeaderReadTex (const opengl::GLInfo & _glinfo)
|
||||
ShaderFragmentHeaderReadTex(const opengl::GLInfo & _glinfo) : m_glinfo(_glinfo)
|
||||
{
|
||||
if (!_glinfo.isGLES2) {
|
||||
m_part =
|
||||
"uniform lowp ivec2 uTextureFormat; \n"
|
||||
"uniform lowp ivec2 uTextureConvert; \n"
|
||||
"uniform mediump ivec4 uConvertParams; \n"
|
||||
"uniform lowp int uTextureFilterMode; \n"
|
||||
"#define YUVCONVERT_TEX(name, tex, texCoord, convert, format, prev) \\\n"
|
||||
" { \\\n"
|
||||
" if (convert != 0) name = prev; \\\n"
|
||||
" else name = texture(tex, texCoord); \\\n"
|
||||
" mediump ivec4 icolor = ivec4(name*255.0); \\\n"
|
||||
" if (format == 1) \\\n"
|
||||
" icolor.rg -= 128; \\\n"
|
||||
" mediump ivec4 iconvert; \\\n"
|
||||
" iconvert.r = icolor.b + (uConvertParams[0]*icolor.g + 128)/256; \\\n"
|
||||
" iconvert.g = icolor.b + (uConvertParams[1]*icolor.r + uConvertParams[2]*icolor.g + 128)/256; \\\n"
|
||||
" iconvert.b = icolor.b + (uConvertParams[3]*icolor.r + 128)/256; \\\n"
|
||||
" iconvert.a = icolor.b; \\\n"
|
||||
" name = vec4(iconvert)/255.0; \\\n"
|
||||
" } \n"
|
||||
;
|
||||
}
|
||||
|
||||
void write(std::stringstream & shader) const override
|
||||
{
|
||||
std::string shaderPart;
|
||||
|
||||
if (!m_glinfo.isGLES2) {
|
||||
|
||||
if (g_textureConvert.useTextureFiltering()) {
|
||||
shaderPart += "uniform lowp int uTextureFilterMode; \n";
|
||||
if (config.texture.bilinearMode == BILINEAR_3POINT) {
|
||||
// 3 point texture filtering.
|
||||
// Original author: ArthurCarvalho
|
||||
// GLSL implementation: twinaphex, mupen64plus-libretro project.
|
||||
m_part +=
|
||||
shaderPart +=
|
||||
"#define TEX_OFFSET(off, tex, texCoord) texture(tex, texCoord - (off)/texSize) \n"
|
||||
"#define TEX_FILTER(name, tex, texCoord) \\\n"
|
||||
" { \\\n"
|
||||
|
@ -986,7 +992,7 @@ public:
|
|||
" } \n"
|
||||
;
|
||||
} else {
|
||||
m_part +=
|
||||
shaderPart +=
|
||||
"#define TEX_OFFSET(off, tex, texCoord) texture(tex, texCoord - (off)/texSize) \n"
|
||||
"#define TEX_FILTER(name, tex, texCoord) \\\n"
|
||||
"{ \\\n"
|
||||
|
@ -1008,7 +1014,7 @@ public:
|
|||
"} \n"
|
||||
;
|
||||
}
|
||||
m_part +=
|
||||
shaderPart +=
|
||||
"#define READ_TEX(name, tex, texCoord, fbMonochrome, fbFixedAlpha) \\\n"
|
||||
" { \\\n"
|
||||
" if (fbMonochrome == 3) { \\\n"
|
||||
|
@ -1028,17 +1034,59 @@ public:
|
|||
" if (fbFixedAlpha == 1) name.a = 0.825; \\\n"
|
||||
" } \n"
|
||||
;
|
||||
} else {
|
||||
m_part =
|
||||
}
|
||||
|
||||
if (g_textureConvert.useYUVCoversion()) {
|
||||
shaderPart +=
|
||||
"uniform lowp ivec2 uTextureFormat; \n"
|
||||
"uniform lowp ivec2 uTextureConvert; \n"
|
||||
"uniform lowp int uTextureConvert; \n"
|
||||
"uniform mediump ivec4 uConvertParams; \n"
|
||||
"#define YUVCONVERT(name, format) \\\n"
|
||||
" mediump ivec4 icolor = ivec4(name*255.0); \\\n"
|
||||
" if (format == 1) \\\n"
|
||||
" icolor.rg -= 128; \\\n"
|
||||
" mediump ivec4 iconvert; \\\n"
|
||||
" iconvert.r = icolor.b + (uConvertParams[0]*icolor.g + 128)/256; \\\n"
|
||||
" iconvert.g = icolor.b + (uConvertParams[1]*icolor.r + uConvertParams[2]*icolor.g + 128)/256; \\\n"
|
||||
" iconvert.b = icolor.b + (uConvertParams[3]*icolor.r + 128)/256; \\\n"
|
||||
" iconvert.a = icolor.b; \\\n"
|
||||
" name = vec4(iconvert)/255.0; \n"
|
||||
"#define YUVCONVERT_TEX0(name, tex, texCoord, format) \\\n"
|
||||
" { \\\n"
|
||||
" name = texture(tex, texCoord); \\\n"
|
||||
" YUVCONVERT(name, format) \\\n"
|
||||
" } \n"
|
||||
"#define YUVCONVERT_TEX1(name, tex, texCoord, format, prev) \\\n"
|
||||
" { \\\n"
|
||||
" if (uTextureConvert != 0) name = prev; \\\n"
|
||||
" else name = texture(tex, texCoord); \\\n"
|
||||
" YUVCONVERT(name, format) \\\n"
|
||||
" } \n"
|
||||
;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (g_textureConvert.useTextureFiltering()) {
|
||||
shaderPart +=
|
||||
"uniform lowp int uTextureFilterMode; \n"
|
||||
"lowp vec4 readTex(in sampler2D tex, in mediump vec2 texCoord, in lowp int fbMonochrome, in lowp int fbFixedAlpha); \n"
|
||||
;
|
||||
}
|
||||
if (g_textureConvert.useYUVCoversion()) {
|
||||
shaderPart +=
|
||||
"uniform lowp ivec2 uTextureFormat; \n"
|
||||
"uniform lowp int uTextureConvert; \n"
|
||||
"uniform mediump ivec4 uConvertParams; \n"
|
||||
"lowp vec4 YUV_Convert(in sampler2D tex, in mediump vec2 texCoord, in lowp int convert, in lowp int format, in lowp vec4 prev); \n"
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
shader << shaderPart;
|
||||
}
|
||||
|
||||
private:
|
||||
const opengl::GLInfo& m_glinfo;
|
||||
};
|
||||
|
||||
class ShaderFragmentHeaderReadTexCopyMode : public ShaderPart
|
||||
|
@ -1185,34 +1233,33 @@ public:
|
|||
std::string shaderPart;
|
||||
|
||||
if (m_glinfo.isGLES2) {
|
||||
|
||||
shaderPart = " nCurrentTile = 0; \n";
|
||||
if (g_textureConvert.getBilerp0()) {
|
||||
shaderPart += " lowp vec4 readtex0 = readTex(uTex0, vTexCoord0, uFbMonochrome[0], uFbFixedAlpha[0]); \n";
|
||||
} else {
|
||||
shaderPart += " lowp vec4 tmpTex = vec4(0.0); \n"
|
||||
" lowp vec4 readtex0 = YUV_Convert(uTex0, vTexCoord0, uTextureConvert[0], uTextureFormat[0], tmpTex); \n";
|
||||
" lowp vec4 readtex0 = YUV_Convert(uTex0, vTexCoord0, 0, uTextureFormat[0], tmpTex); \n";
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (!g_textureConvert.getBilerp0()) {
|
||||
shaderPart = " lowp vec4 readtex0; \n"
|
||||
" YUVCONVERT_TEX0(readtex0, uTex0, vTexCoord0, uTextureFormat[0]) \n";
|
||||
} else {
|
||||
if (config.video.multisampling > 0) {
|
||||
shaderPart =
|
||||
" lowp vec4 readtex0; \n"
|
||||
" if (uMSTexEnabled[0] == 0) { \n";
|
||||
" if (uMSTexEnabled[0] == 0) { \n"
|
||||
" READ_TEX(readtex0, uTex0, vTexCoord0, uFbMonochrome[0], uFbFixedAlpha[0]) \n"
|
||||
" } else readtex0 = readTexMS(uMSTex0, vTexCoord0, uFbMonochrome[0], uFbFixedAlpha[0]); \n";
|
||||
} else {
|
||||
shaderPart = " lowp vec4 readtex0; \n"
|
||||
" READ_TEX(readtex0, uTex0, vTexCoord0, uFbMonochrome[0], uFbFixedAlpha[0]) \n";
|
||||
}
|
||||
}
|
||||
|
||||
if (g_textureConvert.getBilerp0()) {
|
||||
shaderPart += " READ_TEX(readtex0, uTex0, vTexCoord0, uFbMonochrome[0], uFbFixedAlpha[0]) \n";
|
||||
} else {
|
||||
shaderPart += " YUVCONVERT_TEX(readtex0, uTex0, vTexCoord0, uTextureConvert[0], uTextureFormat[0], readtex0) \n";
|
||||
}
|
||||
shaderPart += " } else readtex0 = readTexMS(uMSTex0, vTexCoord0, uFbMonochrome[0], uFbFixedAlpha[0]); \n";
|
||||
} else {
|
||||
shaderPart = " lowp vec4 readtex0; \n";
|
||||
if (g_textureConvert.getBilerp0()) {
|
||||
shaderPart += " READ_TEX(readtex0, uTex0, vTexCoord0, uFbMonochrome[0], uFbFixedAlpha[0]) \n";
|
||||
} else {
|
||||
shaderPart += " YUVCONVERT_TEX(readtex0, uTex0, vTexCoord0, uTextureConvert[0], uTextureFormat[0], readtex0) \n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shader << shaderPart;
|
||||
|
@ -1234,35 +1281,34 @@ public:
|
|||
std::string shaderPart;
|
||||
|
||||
if (m_glinfo.isGLES2) {
|
||||
|
||||
shaderPart = " nCurrentTile = 1; \n";
|
||||
|
||||
if (g_textureConvert.getBilerp1()) {
|
||||
shaderPart += " lowp vec4 readtex1 = readTex(uTex1, vTexCoord1, uFbMonochrome[1], uFbFixedAlpha[1]); \n";
|
||||
} else {
|
||||
shaderPart += " lowp vec4 readtex1 = YUV_Convert(uTex1, vTexCoord1, uTextureConvert[1], uTextureFormat[1], readtex0); \n";
|
||||
shaderPart += " lowp vec4 readtex1 = YUV_Convert(uTex1, vTexCoord1, uTextureConvert, uTextureFormat[1], readtex0); \n";
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (!g_textureConvert.getBilerp1()) {
|
||||
shaderPart =
|
||||
" lowp vec4 readtex1; \n"
|
||||
" YUVCONVERT_TEX1(readtex1, uTex1, vTexCoord1, uTextureFormat[1], readtex0) \n";
|
||||
} else {
|
||||
if (config.video.multisampling > 0) {
|
||||
shaderPart =
|
||||
" lowp vec4 readtex1; \n"
|
||||
" if (uMSTexEnabled[1] == 0) { \n";
|
||||
|
||||
if (g_textureConvert.getBilerp1()) {
|
||||
shaderPart += " READ_TEX(readtex1, uTex1, vTexCoord1, uFbMonochrome[1], uFbFixedAlpha[1]) \n";
|
||||
" if (uMSTexEnabled[1] == 0) { \n"
|
||||
" READ_TEX(readtex1, uTex1, vTexCoord1, uFbMonochrome[1], uFbFixedAlpha[1]) \n"
|
||||
" } else readtex1 = readTexMS(uMSTex1, vTexCoord1, uFbMonochrome[1], uFbFixedAlpha[1]); \n";
|
||||
} else {
|
||||
shaderPart += " YUVCONVERT_TEX(readtex1, uTex1, vTexCoord1, uTextureConvert[1], uTextureFormat[1], readtex0) \n";
|
||||
}
|
||||
|
||||
shaderPart += " } else readtex1 = readTexMS(uMSTex1, vTexCoord1, uFbMonochrome[1], uFbFixedAlpha[1]);\n";
|
||||
} else {
|
||||
shaderPart = " lowp vec4 readtex1; \n";
|
||||
|
||||
if (g_textureConvert.getBilerp1()) {
|
||||
shaderPart += " READ_TEX(readtex1, uTex1, vTexCoord1, uFbMonochrome[1], uFbFixedAlpha[1]) \n";
|
||||
} else {
|
||||
shaderPart += " YUVCONVERT_TEX(readtex1, uTex1, vTexCoord1, uTextureConvert[1], uTextureFormat[1], readtex0)\n";
|
||||
shaderPart = " lowp vec4 readtex1; \n"
|
||||
" READ_TEX(readtex1, uTex1, vTexCoord1, uFbMonochrome[1], uFbFixedAlpha[1]) \n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
shader << shaderPart;
|
||||
|
@ -1621,10 +1667,17 @@ public:
|
|||
class ShaderReadtex : public ShaderPart
|
||||
{
|
||||
public:
|
||||
ShaderReadtex(const opengl::GLInfo & _glinfo)
|
||||
ShaderReadtex(const opengl::GLInfo & _glinfo) : m_glinfo(_glinfo)
|
||||
{
|
||||
if (_glinfo.isGLES2) {
|
||||
m_part =
|
||||
}
|
||||
|
||||
void write(std::stringstream & shader) const override
|
||||
{
|
||||
std::string shaderPart;
|
||||
|
||||
if (m_glinfo.isGLES2) {
|
||||
if (g_textureConvert.useYUVCoversion())
|
||||
shaderPart +=
|
||||
"lowp vec4 YUV_Convert(in sampler2D tex, in mediump vec2 texCoord, in lowp int convert, in lowp int format, in lowp vec4 prev) \n"
|
||||
"{ \n"
|
||||
" lowp vec4 texColor; \n"
|
||||
|
@ -1641,8 +1694,9 @@ public:
|
|||
" return vec4(iconvert)/255.0; \n"
|
||||
" } \n"
|
||||
;
|
||||
if (g_textureConvert.useTextureFiltering()) {
|
||||
if (config.texture.bilinearMode == BILINEAR_3POINT) {
|
||||
m_part +=
|
||||
shaderPart +=
|
||||
"uniform mediump vec2 uTextureSize[2]; \n"
|
||||
// 3 point texture filtering.
|
||||
// Original author: ArthurCarvalho
|
||||
|
@ -1664,7 +1718,7 @@ public:
|
|||
"} \n"
|
||||
;
|
||||
} else {
|
||||
m_part +=
|
||||
shaderPart +=
|
||||
// bilinear filtering.
|
||||
"uniform mediump vec2 uTextureSize[2]; \n"
|
||||
"#define TEX_OFFSET(off) texture2D(tex, texCoord - (off)/texSize) \n"
|
||||
|
@ -1692,7 +1746,7 @@ public:
|
|||
"} \n"
|
||||
;
|
||||
}
|
||||
m_part +=
|
||||
shaderPart +=
|
||||
"lowp vec4 readTex(in sampler2D tex, in mediump vec2 texCoord, in lowp int fbMonochrome, in lowp int fbFixedAlpha) \n"
|
||||
"{ \n"
|
||||
" lowp vec4 texColor; \n"
|
||||
|
@ -1705,9 +1759,10 @@ public:
|
|||
" return texColor; \n"
|
||||
"} \n"
|
||||
;
|
||||
}
|
||||
} else {
|
||||
if (config.video.multisampling > 0) {
|
||||
m_part =
|
||||
if (config.video.multisampling > 0 && g_textureConvert.useTextureFiltering()) {
|
||||
shaderPart =
|
||||
"uniform lowp int uMSAASamples; \n"
|
||||
"lowp vec4 sampleMS(in lowp sampler2DMS mstex, in mediump ivec2 ipos) \n"
|
||||
"{ \n"
|
||||
|
@ -1740,7 +1795,12 @@ public:
|
|||
;
|
||||
}
|
||||
}
|
||||
|
||||
shader << shaderPart;
|
||||
}
|
||||
|
||||
private:
|
||||
const opengl::GLInfo& m_glinfo;
|
||||
};
|
||||
|
||||
class ShaderReadtexCopyMode : public ShaderPart
|
||||
|
|
|
@ -467,7 +467,7 @@ public:
|
|||
textureFilter |= 2;
|
||||
uTextureFilterMode.set(textureFilter, _force);
|
||||
uTextureFormat.set(gSP.textureTile[0]->format, gSP.textureTile[1]->format, _force);
|
||||
uTextureConvert.set(0, gDP.otherMode.convert_one, _force);
|
||||
uTextureConvert.set(gDP.otherMode.convert_one, _force);
|
||||
if (gDP.otherMode.bi_lerp0 == 0 || gDP.otherMode.bi_lerp1 == 0)
|
||||
uConvertParams.set(gDP.convert.k0, gDP.convert.k1, gDP.convert.k2, gDP.convert.k3, _force);
|
||||
}
|
||||
|
@ -475,7 +475,7 @@ public:
|
|||
private:
|
||||
iUniform uTextureFilterMode;
|
||||
iv2Uniform uTextureFormat;
|
||||
iv2Uniform uTextureConvert;
|
||||
iUniform uTextureConvert;
|
||||
i4Uniform uConvertParams;
|
||||
};
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace glsl {
|
|||
bool _saveCombinerKeys(const graphics::Combiners & _combiners) const;
|
||||
bool _loadFromCombinerKeys(graphics::Combiners & _combiners);
|
||||
|
||||
const u32 m_formatVersion = 0x18U;
|
||||
const u32 m_formatVersion = 0x19U;
|
||||
const u32 m_keysFormatVersion = 0x04;
|
||||
const opengl::GLInfo & m_glinfo;
|
||||
opengl::CachedUseProgram * m_useProgram;
|
||||
|
|
Loading…
Reference in New Issue
Block a user