Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FBO depth mask state: track depth mask state in FBO as it's state… #20573

Open
wants to merge 2 commits into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cocos/renderer/CCFrameBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ FrameBuffer::FrameBuffer()
, _rt(nullptr)
, _rtDepthStencil(nullptr)
, _isDefault(false)
, _restoreDepthMask(false)
#if CC_ENABLE_CACHE_TEXTURE_DATA
, _dirtyFBOListener(nullptr)
#endif
Expand Down Expand Up @@ -470,12 +471,30 @@ void FrameBuffer::applyFBO()
{
CCLOG("FrameBuffer Status Error %d", (int)glCheckFramebufferStatus(GL_FRAMEBUFFER));
}

if (_rtDepthStencil->getBuffer())
{
GLboolean depthWitable = GL_FALSE;
glGetBooleanv(GL_DEPTH_WRITEMASK, &depthWitable);
if (depthWitable == GL_FALSE)
{
glDepthMask(GL_TRUE);
_restoreDepthMask = true;
}
}

CHECK_GL_ERROR_DEBUG();
}

void FrameBuffer::restoreFBO()
{
glBindFramebuffer(GL_FRAMEBUFFER, _previousFBO);
if (_restoreDepthMask)
{
glDepthMask(GL_FALSE);
_restoreDepthMask = false;
}

}

void FrameBuffer::attachDepthStencilTarget(RenderTargetDepthStencil* rt)
Expand Down
1 change: 1 addition & 0 deletions cocos/renderer/CCFrameBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class CC_DLL FrameBuffer : public Ref
RenderTargetBase* _rt;
RenderTargetDepthStencil* _rtDepthStencil;
bool _isDefault;
bool _restoreDepthMask;
public:
static FrameBuffer* getOrCreateDefaultFBO(GLView* glView);
static void applyDefaultFBO();
Expand Down