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

WebGPURenderer: Use common clearing code and fix depth state for WebGLBackend #27065

Merged
merged 2 commits into from Oct 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 37 additions & 32 deletions examples/jsm/renderers/webgl/WebGLBackend.js
Expand Up @@ -63,34 +63,7 @@

this._setFramebuffer( renderContext );

let clear = 0;

if ( renderContext.clearColor ) clear |= gl.COLOR_BUFFER_BIT;
if ( renderContext.clearDepth ) clear |= gl.DEPTH_BUFFER_BIT;
if ( renderContext.clearStencil ) clear |= gl.STENCIL_BUFFER_BIT;

const clearColor = renderContext.clearColorValue;

if ( clear !== 0 ) {

if ( renderContext.textures === null ) {

gl.clearColor( clearColor.r, clearColor.g, clearColor.b, clearColor.a );
gl.clear( clear );

} else {

for ( let i = 0; i < renderContext.textures.length; i ++ ) {

gl.clearBufferfv( gl.COLOR, i, [ clearColor.r, clearColor.g, clearColor.b, clearColor.a ] );

}

gl.clearBufferfi( gl.DEPTH_STENCIL, 0, 1, 1 );

}

}
this.clear( renderContext, renderContext.clearColor, renderContext.clearDepth, renderContext.clearStencil );

//

Expand Down Expand Up @@ -254,12 +227,44 @@
if ( depth ) clear |= gl.DEPTH_BUFFER_BIT;
if ( stencil ) clear |= gl.STENCIL_BUFFER_BIT;

const clearColor = renderContext.clearColorValue;
if ( clear !== 0 ) {

const clearColor = renderContext.clearColorValue;

if ( clear === 0 ) return;
if ( depth ) this.state.setDepthMask( true );

gl.clearColor( clearColor.x, clearColor.y, clearColor.z, clearColor.a );
gl.clear( clear );
if ( renderContext.textures === null ) {

gl.clearColor( clearColor.r, clearColor.g, clearColor.b, clearColor.a );
gl.clear( clear );

} else {

if ( color ) {

for ( let i = 0; i < renderContext.textures.length; i ++ ) {

gl.clearBufferfv( gl.COLOR, i, [ clearColor.r, clearColor.g, clearColor.b, clearColor.a ] );

}
}

if ( depth && stencil ) {

gl.clearBufferfi( gl.DEPTH_STENCIL, 0, 1, 0 );

} else if ( depth ) {

gl.clearBufferfv( gl.DEPTH, 0, [ 1.0 ] )
Fixed Show fixed Hide fixed

} else if ( stencil ) {

gl.clearBufferiv( gl.STENCIL, 0, [ 0 ] );
}

}

}

}

Expand Down