-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
WebGLRenderer: Add support for changing the assigned render target depth texture #28584
Changes from 5 commits
7b420b1
bf626e4
9daaabe
ecc85ea
e3aabfd
929f112
3175f66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1609,16 +1609,42 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, | |
for ( let i = 0; i < 6; i ++ ) { | ||
|
||
state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] ); | ||
renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer(); | ||
setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget, false ); | ||
|
||
if ( renderTargetProperties.__webglDepthbuffer[ i ] === undefined ) { | ||
|
||
renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer(); | ||
setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget, false ); | ||
|
||
} else { | ||
|
||
// attach buffer if it's been created already | ||
const glAttachmentType = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT; | ||
const renderbuffer = renderTargetProperties.__webglDepthbuffer[ i ]; | ||
_gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer ); | ||
_gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, glAttachmentType, _gl.RENDERBUFFER, renderbuffer ); | ||
|
||
} | ||
|
||
} | ||
|
||
} else { | ||
|
||
state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer ); | ||
renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer(); | ||
setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget, false ); | ||
|
||
if ( renderTargetProperties.__webglDepthbuffer === undefined ) { | ||
|
||
renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer(); | ||
setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget, false ); | ||
|
||
} else { | ||
|
||
// attach buffer if it's been created already | ||
const glAttachmentType = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT; | ||
const renderbuffer = renderTargetProperties.__webglDepthbuffer; | ||
_gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer ); | ||
_gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, glAttachmentType, _gl.RENDERBUFFER, renderbuffer ); | ||
|
||
} | ||
|
||
} | ||
|
||
|
@@ -1763,7 +1789,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, | |
|
||
_gl.bindRenderbuffer( _gl.RENDERBUFFER, null ); | ||
|
||
if ( renderTarget.depthBuffer ) { | ||
if ( renderTarget.depthBuffer && renderTargetProperties.__webglDepthRenderbuffer === undefined ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this bit.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just removed this. I added it when checking whether the depth buffer needed to be initialized in other functions but you're right it's not needed here. |
||
|
||
renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer(); | ||
setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested the PR with webgl_rtt and it does not look right (or at least optimal) to me that this code path is taken in normal
setRenderTarget()
calls. The additional bindings executed insetupDepthRenderbuffer()
are a waste for all scenarios with a static depth buffer.Isn't it possible to make the depth texture exchange more explicit? E.g. use a flag that is set to true when depth texture reference is changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call - I just added a check in
setupDepthRenderbuffer
to avoid rebinding the depth buffer if it has already been bound. Let me know what you think.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @Mugen87 - just wanted to check on this again. The PR has now been changed so that the depth buffer is only updated and rebound if it has changed.