From 42bb48bd460d0ee1e11691b4de9aeab9510a43fa Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Thu, 4 Dec 2014 14:59:16 +0100 Subject: [PATCH] FramebufferManager: Bind only the first framebuffer layer when the EFB only has one layer. --- .../VideoBackends/OGL/FramebufferManager.cpp | 27 ++++++++++++++----- .../VideoBackends/OGL/FramebufferManager.h | 1 + Source/Core/VideoBackends/OGL/Render.cpp | 9 ------- .../Core/VideoBackends/OGL/TextureCache.cpp | 2 +- .../VideoBackends/OGL/TextureConverter.cpp | 2 +- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/Source/Core/VideoBackends/OGL/FramebufferManager.cpp b/Source/Core/VideoBackends/OGL/FramebufferManager.cpp index 4ea9262625..c458b79dc6 100644 --- a/Source/Core/VideoBackends/OGL/FramebufferManager.cpp +++ b/Source/Core/VideoBackends/OGL/FramebufferManager.cpp @@ -135,8 +135,8 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms // Bind resolved textures to resolved framebuffer. glGenFramebuffers(1, &m_resolvedFramebuffer); glBindFramebuffer(GL_FRAMEBUFFER, m_resolvedFramebuffer); - glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_resolvedColorTexture, 0); - glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_resolvedDepthTexture, 0); + FramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, resolvedType, m_resolvedColorTexture, 0); + FramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, resolvedType, m_resolvedDepthTexture, 0); } // Create XFB framebuffer; targets will be created elsewhere. @@ -145,8 +145,8 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms // Bind target textures to EFB framebuffer. glGenFramebuffers(1, &m_efbFramebuffer); glBindFramebuffer(GL_FRAMEBUFFER, m_efbFramebuffer); - glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_efbColor, 0); - glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_efbDepth, 0); + FramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_textureType, m_efbColor, 0); + FramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_textureType, m_efbDepth, 0); // EFB framebuffer is currently bound, make sure to clear its alpha value to 1.f glViewport(0, 0, m_targetWidth, m_targetHeight); @@ -343,6 +343,21 @@ void FramebufferManager::SetFramebuffer(GLuint fb) glBindFramebuffer(GL_FRAMEBUFFER, fb != 0 ? fb : GetEFBFramebuffer()); } +void FramebufferManager::FramebufferTexture(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) +{ + if (textarget == GL_TEXTURE_2D_ARRAY || textarget == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) + { + if (m_EFBLayers > 1) + glFramebufferTexture(target, attachment, texture, level); + else + glFramebufferTextureLayer(target, attachment, texture, level, 0); + } + else + { + glFramebufferTexture2D(target, attachment, textarget, texture, level); + } +} + // Apply AA if enabled GLuint FramebufferManager::ResolveAndGetRenderTarget(const EFBRectangle &source_rect) { @@ -367,7 +382,7 @@ void FramebufferManager::ReinterpretPixelData(unsigned int convtype) src_texture = m_efbColor; m_efbColor = m_efbColorSwap; m_efbColorSwap = src_texture; - glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_efbColor, 0); + FramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_textureType, m_efbColor, 0); glViewport(0,0, m_targetWidth, m_targetHeight); glActiveTexture(GL_TEXTURE0 + 9); @@ -399,7 +414,7 @@ void XFBSource::CopyEFB(float Gamma) glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferManager::GetXFBFramebuffer()); // Bind texture. - glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture, 0); + FramebufferManager::FramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_ARRAY, texture, 0); glBlitFramebuffer( 0, 0, texWidth, texHeight, diff --git a/Source/Core/VideoBackends/OGL/FramebufferManager.h b/Source/Core/VideoBackends/OGL/FramebufferManager.h index ed129c5a6e..8d42523bcc 100644 --- a/Source/Core/VideoBackends/OGL/FramebufferManager.h +++ b/Source/Core/VideoBackends/OGL/FramebufferManager.h @@ -75,6 +75,7 @@ public: static GLuint GetResolvedFramebuffer() { return m_resolvedFramebuffer; } static void SetFramebuffer(GLuint fb); + static void FramebufferTexture(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); // If in MSAA mode, this will perform a resolve of the specified rectangle, and return the resolve target as a texture ID. // Thus, this call may be expensive. Don't repeat it unnecessarily. diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 186c663a89..f33c59899c 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -207,10 +207,6 @@ static void GLAPIENTRY ClearDepthf(GLfloat depthval) { glClearDepth(depthval); } -static void GLAPIENTRY FramebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level) -{ - glFramebufferTextureLayer(target, attachment, texture, level, 0); -} static void InitDriverInfo() { @@ -474,11 +470,6 @@ Renderer::Renderer() glClearDepthf = ClearDepthf; } - if (GLExtensions::Version() < 320 || GLInterface->GetMode() != GLInterfaceMode::MODE_OPENGL) - { - glFramebufferTexture = FramebufferTexture; - } - g_Config.backend_info.bSupportsDualSourceBlend = GLExtensions::Supports("GL_ARB_blend_func_extended"); g_Config.backend_info.bSupportsPrimitiveRestart = !DriverDetails::HasBug(DriverDetails::BUG_PRIMITIVERESTART) && ((GLExtensions::Version() >= 310) || GLExtensions::Supports("GL_NV_primitive_restart")); diff --git a/Source/Core/VideoBackends/OGL/TextureCache.cpp b/Source/Core/VideoBackends/OGL/TextureCache.cpp index 66f633c6e3..49bfc98a55 100644 --- a/Source/Core/VideoBackends/OGL/TextureCache.cpp +++ b/Source/Core/VideoBackends/OGL/TextureCache.cpp @@ -226,7 +226,7 @@ TextureCache::TCacheEntryBase* TextureCache::CreateRenderTargetTexture( glGenFramebuffers(1, &entry->framebuffer); FramebufferManager::SetFramebuffer(entry->framebuffer); - glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, entry->texture, 0); + FramebufferManager::FramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_ARRAY, entry->texture, 0); SetStage(); diff --git a/Source/Core/VideoBackends/OGL/TextureConverter.cpp b/Source/Core/VideoBackends/OGL/TextureConverter.cpp index ece33797a6..8753b58e8a 100644 --- a/Source/Core/VideoBackends/OGL/TextureConverter.cpp +++ b/Source/Core/VideoBackends/OGL/TextureConverter.cpp @@ -365,7 +365,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur // switch to texture converter frame buffer // attach destTexture as color destination FramebufferManager::SetFramebuffer(s_texConvFrameBuffer[1]); - glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, destTexture, 0); + FramebufferManager::FramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_ARRAY, destTexture, 0); // activate source texture // set srcAddr as data for source texture