From 01d81ffa720bc95372224e9d92a149bdd85f04cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 28 Mar 2018 11:23:41 +0200 Subject: [PATCH] OpenGL: Fix texture wrapping of render targets. --- GPU/GLES/TextureCacheGLES.cpp | 8 ++++---- UI/GameSettingsScreen.cpp | 2 ++ Windows/GPU/WindowsGLContext.cpp | 3 ++- ext/native/math/math_util.h | 4 ++++ ext/native/thin3d/GLQueueRunner.cpp | 3 ++- ext/native/thin3d/thin3d_gl.cpp | 5 +---- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 2627cd426..e1b45f40c 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -169,16 +169,16 @@ void TextureCacheGLES::SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferH minFilt &= 1; // framebuffers can't mipmap. - float aniso = 0.0f; - render_->SetTextureSampler(0, sClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, tClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, MagFiltGL[magFilt], MinFiltGL[minFilt], aniso); - // Often the framebuffer will not match the texture size. We'll wrap/clamp in the shader in that case. // This happens whether we have OES_texture_npot or not. int w = gstate.getTextureWidth(0); int h = gstate.getTextureHeight(0); if (w != bufferWidth || h != bufferHeight) { - return; + sClamp = true; + tClamp = true; } + float aniso = 0.0f; + render_->SetTextureSampler(0, sClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, tClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, MagFiltGL[magFilt], MinFiltGL[minFilt], aniso); } static void ConvertColors(void *dstBuf, const void *srcBuf, GLuint dstFmt, int numPixels) { diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 8d803f913..21e294185 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -112,6 +112,8 @@ static std::string PostShaderTranslateName(const char *value) { const ShaderInfo *info = GetPostShaderInfo(value); if (info) { return ps->T(value, info ? info->name.c_str() : value); + } else { + return value; } } diff --git a/Windows/GPU/WindowsGLContext.cpp b/Windows/GPU/WindowsGLContext.cpp index 8feae4430..bed1349cf 100644 --- a/Windows/GPU/WindowsGLContext.cpp +++ b/Windows/GPU/WindowsGLContext.cpp @@ -149,7 +149,8 @@ void DebugCallbackARB(GLenum source, GLenum type, GLuint id, GLenum severity, case GL_DEBUG_TYPE_OTHER_ARB: default: - INFO_LOG(G3D, "GL: %s", finalMessage); + // These are just performance warnings. + VERBOSE_LOG(G3D, "GL: %s", finalMessage); break; } } diff --git a/ext/native/math/math_util.h b/ext/native/math/math_util.h index b06fed514..23ee8969a 100644 --- a/ext/native/math/math_util.h +++ b/ext/native/math/math_util.h @@ -28,6 +28,10 @@ inline float Float16ToFloat(float16 ix) { return x; } +inline bool isPowerOf2(int n) { + return n == 1 || (n & (n - 1)) == 0; +} + inline uint32_t RoundUpToPowerOf2(uint32_t v) { v--; v |= v >> 1; diff --git a/ext/native/thin3d/GLQueueRunner.cpp b/ext/native/thin3d/GLQueueRunner.cpp index f183dbe8c..1bfb3a426 100644 --- a/ext/native/thin3d/GLQueueRunner.cpp +++ b/ext/native/thin3d/GLQueueRunner.cpp @@ -8,6 +8,7 @@ #include "gfx/gl_debug_log.h" #include "gfx_es2/gpu_features.h" #include "math/dataconv.h" +#include "math/math_util.h" #define TEXCACHE_NAME_CACHE_SIZE 16 @@ -326,7 +327,7 @@ void GLQueueRunner::InitCreateFramebuffer(const GLRInitStep &step) { fbo->color_texture.wrapT = GL_CLAMP_TO_EDGE; fbo->color_texture.magFilter = GL_LINEAR; fbo->color_texture.minFilter = GL_LINEAR; - fbo->color_texture.canWrap = false; + fbo->color_texture.canWrap = isPowerOf2(fbo->width) && isPowerOf2(fbo->height); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, fbo->color_texture.wrapS); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, fbo->color_texture.wrapT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, fbo->color_texture.magFilter); diff --git a/ext/native/thin3d/thin3d_gl.cpp b/ext/native/thin3d/thin3d_gl.cpp index 5ef1af487..84e28a2dc 100644 --- a/ext/native/thin3d/thin3d_gl.cpp +++ b/ext/native/thin3d/thin3d_gl.cpp @@ -7,6 +7,7 @@ #include "base/logging.h" #include "math/dataconv.h" +#include "math/math_util.h" #include "math/lin/matrix4x4.h" #include "thin3d/thin3d.h" #include "thin3d/DataFormatGL.h" @@ -573,10 +574,6 @@ GLuint TypeToTarget(TextureType type) { } } -inline bool isPowerOf2(int n) { - return n == 1 || (n & (n - 1)) == 0; -} - class OpenGLTexture : public Texture { public: OpenGLTexture(GLRenderManager *render, const TextureDesc &desc);