From 3541d06339bbbbcc56c97f78ca6c6f7ce6844aed Mon Sep 17 00:00:00 2001 From: coulsonwang Date: Tue, 24 Dec 2019 09:55:43 +0800 Subject: [PATCH] set gl framebuffer read and write back again (#20403) * set gl framebuffer read and write back again * update review --- .../backend/opengl/CommandBufferGL.cpp | 18 ++++++++++++++++++ .../renderer/backend/opengl/CommandBufferGL.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/cocos/renderer/backend/opengl/CommandBufferGL.cpp b/cocos/renderer/backend/opengl/CommandBufferGL.cpp index 721a653272..e7ecfe05f9 100644 --- a/cocos/renderer/backend/opengl/CommandBufferGL.cpp +++ b/cocos/renderer/backend/opengl/CommandBufferGL.cpp @@ -198,6 +198,23 @@ void CommandBufferGL::applyRenderPassDescriptor(const RenderPassDescriptor& desc if (useGeneratedFBO) _generatedFBOBindColor = true; + +#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX + if (_framebufferReadWriteDisabled) + { + if (useGeneratedFBO) //user-defined framebuffer + { + glDrawBuffer(GL_COLOR_ATTACHMENT0); + glReadBuffer(GL_COLOR_ATTACHMENT0); + } + else //default framebuffer + { + glDrawBuffer(GL_BACK); + glReadBuffer(GL_BACK); + } + _framebufferReadWriteDisabled = false; + } +#endif } else { @@ -219,6 +236,7 @@ void CommandBufferGL::applyRenderPassDescriptor(const RenderPassDescriptor& desc #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); + _framebufferReadWriteDisabled = true; #endif } CHECK_GL_ERROR_DEBUG(); diff --git a/cocos/renderer/backend/opengl/CommandBufferGL.h b/cocos/renderer/backend/opengl/CommandBufferGL.h index eb7dff7e70..2153d80de4 100644 --- a/cocos/renderer/backend/opengl/CommandBufferGL.h +++ b/cocos/renderer/backend/opengl/CommandBufferGL.h @@ -190,6 +190,9 @@ private: bool _generatedFBOBindColor = false; bool _generatedFBOBindDepth = false; bool _generatedFBOBindStencil = false; +#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX + bool _framebufferReadWriteDisabled = false; +#endif GLint _defaultFBO = 0; // The value gets from glGetIntegerv, so need to use GLint GLuint _currentFBO = 0;