1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-04 10:03:36 +00:00

Do not use hybrid filer for GLES 2.0 due to poor performance.

Shader and code simplifications.
This commit is contained in:
Sergey Lipskiy 2019-11-30 15:42:28 +07:00
parent 25b270492e
commit d52d402d76

View File

@ -358,19 +358,8 @@ namespace glsl {
std::string const& getHybridTextureFilter()
{
static std::string strFilter =
"#if __VERSION__ < 130 \n"
"uniform ivec2 uTextureSize; \n"
"#endif \n"
"uniform sampler2D uTex0; \n"
" \n"
"ivec2 getTextureSize() \n"
"{ \n"
"#if __VERSION__ < 130 \n"
" return uTextureSize; \n"
"#else \n"
" return textureSize(uTex0, 0); \n"
"#endif \n"
"} \n"
"mediump vec2 norm2denorm(in mediump vec2 uv, in ivec2 texture_size) \n"
"{ \n"
" return uv * vec2(texture_size) - 0.5; \n"
@ -395,7 +384,7 @@ namespace glsl {
"} \n"
"mediump vec4 hybridFilter(in mediump vec2 uv) \n"
"{ \n"
" ivec2 texSize = getTextureSize(); \n"
" ivec2 texSize = textureSize(uTex0, 0); \n"
" mediump vec2 denorm_uv = norm2denorm(uv,texSize); \n"
" ivec2 idx_low = denorm2idx(denorm_uv); \n"
" mediump vec2 ratio = denorm_uv - vec2(idx_low); \n"
@ -459,15 +448,27 @@ namespace glsl {
public:
TexrectCopy(const opengl::GLInfo & _glinfo)
{
m_part = getHybridTextureFilter();
m_part +=
"IN mediump vec2 vTexCoord0; \n"
"OUT lowp vec4 fragColor; \n"
" \n"
"void main() \n"
"{ \n"
" fragColor = hybridFilter(vTexCoord0); \n"
;
if (_glinfo.isGLES2) {
m_part =
"IN mediump vec2 vTexCoord0; \n"
"uniform sampler2D uTex0; \n"
"OUT lowp vec4 fragColor; \n"
" \n"
"void main() \n"
"{ \n"
" fragColor = texture2D(uTex0, vTexCoord0); \n"
;
} else {
m_part = getHybridTextureFilter();
m_part +=
"IN mediump vec2 vTexCoord0; \n"
"OUT lowp vec4 fragColor; \n"
" \n"
"void main() \n"
"{ \n"
" fragColor = hybridFilter(vTexCoord0); \n"
;
}
}
};
@ -478,17 +479,31 @@ namespace glsl {
public:
TexrectColorAndDepthCopy(const opengl::GLInfo & _glinfo)
{
m_part = getHybridTextureFilter();
m_part +=
"IN mediump vec2 vTexCoord0; \n"
"uniform sampler2D uTex1; \n"
"OUT lowp vec4 fragColor; \n"
" \n"
"void main() \n"
"{ \n"
" fragColor = hybridFilter(vTexCoord0); \n"
" gl_FragDepth = texture2D(uTex1, vTexCoord0).r; \n"
;
if (_glinfo.isGLES2) {
m_part =
"IN mediump vec2 vTexCoord0; \n"
"uniform sampler2D uTex0; \n"
"uniform sampler2D uTex1; \n"
"OUT lowp vec4 fragColor; \n"
" \n"
"void main() \n"
"{ \n"
" fragColor = texture2D(uTex0, vTexCoord0); \n"
" gl_FragDepth = texture2D(uTex1, vTexCoord0).r; \n"
;
} else {
m_part = getHybridTextureFilter();
m_part +=
"IN mediump vec2 vTexCoord0; \n"
"uniform sampler2D uTex1; \n"
"OUT lowp vec4 fragColor; \n"
" \n"
"void main() \n"
"{ \n"
" fragColor = hybridFilter(vTexCoord0); \n"
" gl_FragDepth = texture2D(uTex1, vTexCoord0).r; \n"
;
}
}
};
@ -781,23 +796,8 @@ namespace glsl {
m_useProgram->useProgram(m_program);
const int texLoc = glGetUniformLocation(GLuint(m_program), "uTex0");
glUniform1i(texLoc, 0);
m_textureSizeLoc = glGetUniformLocation(GLuint(m_program), "uTextureSize");
m_useProgram->useProgram(graphics::ObjectHandle::null);
}
void activate() override
{
TexrectCopyShaderBase::activate();
if (m_textureSizeLoc < 0)
return;
GLint texWidth, texHeight;
glGetTexLevelParameteriv(0, 0, GL_TEXTURE_WIDTH, &texWidth);
glGetTexLevelParameteriv(0, 0, GL_TEXTURE_HEIGHT, &texHeight);
glUniform2i(m_textureSizeLoc, texWidth, texHeight);
}
private:
GLint m_textureSizeLoc;
};
/*---------------TexrectColorAndDepthCopyShader-------------*/
@ -819,23 +819,8 @@ namespace glsl {
glUniform1i(texLoc0, 0);
const int texLoc1 = glGetUniformLocation(GLuint(m_program), "uTex1");
glUniform1i(texLoc1, 1);
m_textureSizeLoc = glGetUniformLocation(GLuint(m_program), "uTextureSize");
m_useProgram->useProgram(graphics::ObjectHandle::null);
}
void activate() override
{
TexrectColorAndDepthCopyShaderBase::activate();
if (m_textureSizeLoc < 0)
return;
GLint texWidth, texHeight;
glGetTexLevelParameteriv(0, 0, GL_TEXTURE_WIDTH, &texWidth);
glGetTexLevelParameteriv(0, 0, GL_TEXTURE_HEIGHT, &texHeight);
glUniform2i(m_textureSizeLoc, texWidth, texHeight);
}
private:
GLint m_textureSizeLoc;
};
/*---------------PostProcessorShader-------------*/