From 3897e1959e0b983728d10df5bb78d288529c2daf Mon Sep 17 00:00:00 2001 From: degasus Date: Mon, 8 Apr 2013 14:36:58 +0200 Subject: [PATCH] ogl: one framebuffer per efb2tex texture suggestion from nvidia/valve. let's see if it helps --- .../Plugin_VideoOGL/Src/TextureCache.cpp | 34 ++++++++----------- .../Plugin_VideoOGL/Src/TextureCache.h | 1 + 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp index b0bc682f29..05c5a9c232 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp @@ -74,8 +74,6 @@ struct VBOCache { }; static std::map s_VBO; -static u32 s_TempFramebuffer = 0; - bool SaveTexture(const char* filename, u32 textarget, u32 tex, int virtual_width, int virtual_height, unsigned int level) { int width = std::max(virtual_width >> level, 1); @@ -107,12 +105,20 @@ TextureCache::TCacheEntry::~TCacheEntry() glDeleteTextures(1, &texture); texture = 0; } + + if (framebuffer) + { + glDeleteFramebuffers(1, &framebuffer); + framebuffer = 0; + } } TextureCache::TCacheEntry::TCacheEntry() { glGenTextures(1, &texture); GL_REPORT_ERRORD(); + + framebuffer = 0; } void TextureCache::TCacheEntry::Bind(unsigned int stage) @@ -268,9 +274,13 @@ TextureCache::TCacheEntryBase* TextureCache::CreateRenderTargetTexture( entry->m_tex_levels = 1; glTexImage2D(GL_TEXTURE_2D, 0, gl_iformat, scaled_tex_w, scaled_tex_h, 0, gl_format, gl_type, NULL); - glBindTexture(GL_TEXTURE_2D, 0); + glGenFramebuffers(1, &entry->framebuffer); + FramebufferManager::SetFramebuffer(entry->framebuffer); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, entry->texture, 0); + GL_REPORT_FBO_ERROR(); + SetStage(); GL_REPORT_ERRORD(); @@ -290,17 +300,12 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo FramebufferManager::ResolveAndGetDepthTarget(srcRect) : FramebufferManager::ResolveAndGetRenderTarget(srcRect); - GL_REPORT_ERRORD(); + GL_REPORT_ERRORD(); if (type != TCET_EC_DYNAMIC || g_ActiveConfig.bCopyEFBToTexture) { - if (s_TempFramebuffer == 0) - glGenFramebuffers(1, (GLuint*)&s_TempFramebuffer); + FramebufferManager::SetFramebuffer(framebuffer); - FramebufferManager::SetFramebuffer(s_TempFramebuffer); - // Bind texture to temporary framebuffer - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); - GL_REPORT_FBO_ERROR(); GL_REPORT_ERRORD(); glActiveTexture(GL_TEXTURE0+9); @@ -371,9 +376,6 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); GL_REPORT_ERRORD(); - - // Unbind texture from temporary framebuffer - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); } if (false == g_ActiveConfig.bCopyEFBToTexture) @@ -477,12 +479,6 @@ TextureCache::~TextureCache() glDeleteVertexArrays(1, &it->second.vao); } s_VBO.clear(); - - if (s_TempFramebuffer) - { - glDeleteFramebuffers(1, (GLuint*)&s_TempFramebuffer); - s_TempFramebuffer = 0; - } } void TextureCache::DisableStage(unsigned int stage) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.h b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.h index a41c86e0b3..e08c0b827a 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.h @@ -41,6 +41,7 @@ private: struct TCacheEntry : TCacheEntryBase { GLuint texture; + GLuint framebuffer; PC_TexFormat pcfmt;