diff --git a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp index 53d2f85552..27a88bf68a 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp @@ -297,11 +297,17 @@ GLuint FramebufferManager::ResolveAndGetDepthTarget(const EFBRectangle &source_r return GetEFBDepthTexture(source_rect); } +XFBSource::~XFBSource() +{ + glDeleteRenderbuffers(1, &renderbuf); +} + + void XFBSource::Draw(const MathUtil::Rectangle &sourcerc, const MathUtil::Rectangle &drawrc, int width, int height) const { // Texture map xfbSource->texture onto the main buffer - glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, texture, 0); + glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuf); glBlitFramebuffer(sourcerc.left, sourcerc.bottom, sourcerc.right, sourcerc.top, drawrc.left, drawrc.bottom, drawrc.right, drawrc.top, GL_COLOR_BUFFER_BIT, GL_LINEAR); @@ -311,7 +317,7 @@ void XFBSource::Draw(const MathUtil::Rectangle &sourcerc, void XFBSource::DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight) { - TextureConverter::DecodeToTexture(xfbAddr, fbWidth, fbHeight, texture); + TextureConverter::DecodeToTexture(xfbAddr, fbWidth, fbHeight, renderbuf); } void XFBSource::CopyEFB(float Gamma) @@ -321,7 +327,7 @@ void XFBSource::CopyEFB(float Gamma) glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferManager::GetXFBFramebuffer()); // Bind texture. - glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, texture, 0); + glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuf); GL_REPORT_FBO_ERROR(); glBlitFramebuffer( @@ -330,26 +336,21 @@ void XFBSource::CopyEFB(float Gamma) GL_COLOR_BUFFER_BIT, GL_NEAREST ); - // Unbind texture. - glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, 0, 0); - // Return to EFB. - glBindFramebuffer(GL_FRAMEBUFFER, FramebufferManager::GetEFBFramebuffer()); + FramebufferManager::SetFramebuffer(0); } XFBSourceBase* FramebufferManager::CreateXFBSource(unsigned int target_width, unsigned int target_height) { - GLuint texture; + GLuint renderbuf; - glGenTextures(1, &texture); + glGenRenderbuffers(1, &renderbuf); + + glBindRenderbuffer(GL_RENDERBUFFER, renderbuf); + glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, target_width, target_height); - glBindTexture(GL_TEXTURE_RECTANGLE, texture); - glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, target_width, target_height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); - - glBindTexture(GL_TEXTURE_RECTANGLE, 0); - - return new XFBSource(texture); + return new XFBSource(renderbuf); } void FramebufferManager::GetTargetSize(unsigned int *width, unsigned int *height, const EFBRectangle& sourceRc) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.h b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.h index ffe3399705..2a7b20defd 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.h @@ -57,15 +57,15 @@ namespace OGL { struct XFBSource : public XFBSourceBase { - XFBSource(GLuint tex) : texture(tex) {} - ~XFBSource() { glDeleteTextures(1, &texture); } + XFBSource(GLuint rbuf) : renderbuf(rbuf) {} + ~XFBSource(); void CopyEFB(float Gamma); void DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight); void Draw(const MathUtil::Rectangle &sourcerc, const MathUtil::Rectangle &drawrc, int width, int height) const; - const GLuint texture; + const GLuint renderbuf; }; class FramebufferManager : public FramebufferManagerBase diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp index 7e619a3855..5f98fe9377 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp @@ -395,7 +395,7 @@ void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* des // Should be scale free. -void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTexture) +void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destRenderbuf) { u8* srcAddr = Memory::GetPointer(xfbAddr); if (!srcAddr) @@ -411,9 +411,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); - glBindTexture(GL_TEXTURE_2D, 0); - glBindTexture(GL_TEXTURE_RECTANGLE_ARB, destTexture); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, destTexture, 0); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, destRenderbuf); GL_REPORT_FBO_ERROR(); @@ -471,7 +469,6 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur // reset state glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, 0, 0); TextureCache::DisableStage(0); VertexShaderManager::SetViewportChanged(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.h b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.h index 4113778603..b226e20180 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.h @@ -35,7 +35,7 @@ void Shutdown(); void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* destAddr, int dstWidth, int dstHeight); -void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTexture); +void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destRenderbuf); // returns size of the encoded data (in bytes) int EncodeToRamFromTexture(u32 address, GLuint source_texture, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source);