-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
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 6 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 |
---|---|---|
|
@@ -1594,6 +1594,15 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, | |
const renderTargetProperties = properties.get( renderTarget ); | ||
const isCube = ( renderTarget.isWebGLCubeRenderTarget === true ); | ||
|
||
// check if the depth texture is already bound to the frame buffer and that it's been initialized | ||
if ( renderTargetProperties.__boundDepthTexture === renderTarget.depthTexture && properties.has( renderTarget.depthTexture ) ) { | ||
|
||
return; | ||
|
||
} | ||
|
||
renderTargetProperties.__boundDepthTexture = renderTarget.depthTexture; | ||
|
||
if ( renderTarget.depthTexture && ! renderTargetProperties.__autoAllocateDepthBuffer ) { | ||
|
||
if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' ); | ||
|
@@ -1609,16 +1618,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 +1798,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.
Can we move this check in
setRenderTarget()
and do it before checking the dimensions of the depth texture? The dimensions check should be only relevant when exchanging depth textures and not in the default case.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 realized this is a bit more complicated when I was thinking through it again. Hopefully the current change makes sense. We need account for the case the where a depth texture is used and already bound on a render target, then disposed - meaning the depth texture is implicitly unbound so we need to make sure the three.js state reflects this. I tested and pushed the current change to the depth peeling demo page.