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;