Skip to content

Commit 19e8c3b

Browse files
committed
WebGLBackend: Fix clear().
1 parent 57e59a9 commit 19e8c3b

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/renderers/common/Renderer.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,17 @@ class Renderer {
19171917
renderContext.depth = renderTarget.depthBuffer;
19181918
renderContext.stencil = renderTarget.stencilBuffer;
19191919
// #30329
1920-
renderContext.clearColorValue = this._clearColor;
1920+
renderContext.clearColorValue = this.backend.getClearColor();
1921+
1922+
// premultiply alpha
1923+
1924+
if ( this.backend.isWebGLBackend === true || this.alpha === true ) {
1925+
1926+
renderContext.clearColorValue.r *= renderContext.clearColorValue.a;
1927+
renderContext.clearColorValue.g *= renderContext.clearColorValue.a;
1928+
renderContext.clearColorValue.b *= renderContext.clearColorValue.a;
1929+
1930+
}
19211931

19221932
}
19231933

src/renderers/webgl-fallback/WebGLBackend.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ class WebGLBackend extends Backend {
717717
*/
718718
clear( color, depth, stencil, descriptor = null, setFrameBuffer = true ) {
719719

720-
const { gl } = this;
720+
const { gl, renderer } = this;
721721

722722
if ( descriptor === null ) {
723723

@@ -764,6 +764,9 @@ class WebGLBackend extends Backend {
764764

765765
}
766766

767+
const clearDepth = renderer.getClearDepth();
768+
const clearStecil = renderer.getClearStencil();
769+
767770
if ( depth ) this.state.setDepthMask( true );
768771

769772
if ( descriptor.textures === null ) {
@@ -787,15 +790,15 @@ class WebGLBackend extends Backend {
787790

788791
if ( depth && stencil ) {
789792

790-
gl.clearBufferfi( gl.DEPTH_STENCIL, 0, 1, 0 );
793+
gl.clearBufferfi( gl.DEPTH_STENCIL, 0, clearDepth, clearStecil );
791794

792795
} else if ( depth ) {
793796

794-
gl.clearBufferfv( gl.DEPTH, 0, [ 1.0 ] );
797+
gl.clearBufferfv( gl.DEPTH, 0, [ clearDepth ] );
795798

796799
} else if ( stencil ) {
797800

798-
gl.clearBufferiv( gl.STENCIL, 0, [ 0 ] );
801+
gl.clearBufferiv( gl.STENCIL, 0, [ clearStecil ] );
799802

800803
}
801804

0 commit comments

Comments
 (0)