Skip to content

Commit a13e4b0

Browse files
WebGPURenderer: Fix clear alpha in WebGLBackend (#30329)
* WebGPURenderer: Fix clear alpha in WebGLBackend * improved jsdoc * add comment * simplify * remove white space * revert
1 parent d9ca4dc commit a13e4b0

File tree

3 files changed

+89
-16
lines changed

3 files changed

+89
-16
lines changed

src/renderers/common/Renderer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,6 +1855,9 @@ class Renderer {
18551855

18561856
}
18571857

1858+
// #30329
1859+
renderContext.clearColorValue = this._clearColor;
1860+
18581861
this.backend.clear( color, depth, stencil, renderContext );
18591862

18601863
if ( renderTarget !== null && this._renderTarget === null ) {

src/renderers/webgl-fallback/WebGLBackend.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ class WebGLBackend extends Backend {
410410
*/
411411
beginRender( renderContext ) {
412412

413-
const { gl } = this;
413+
const { state, gl } = this;
414414
const renderContextData = this.get( renderContext );
415415

416416
//
@@ -433,15 +433,15 @@ class WebGLBackend extends Backend {
433433

434434
} else {
435435

436-
gl.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight );
436+
state.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight );
437437

438438
}
439439

440440
if ( renderContext.scissor ) {
441441

442442
const { x, y, width, height } = renderContext.scissorValue;
443443

444-
gl.scissor( x, renderContext.height - height - y, width, height );
444+
state.scissor( x, renderContext.height - height - y, width, height );
445445

446446
}
447447

@@ -565,7 +565,7 @@ class WebGLBackend extends Backend {
565565

566566
} else {
567567

568-
gl.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight );
568+
state.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight );
569569

570570
}
571571

@@ -663,10 +663,10 @@ class WebGLBackend extends Backend {
663663
*/
664664
updateViewport( renderContext ) {
665665

666-
const gl = this.gl;
666+
const { state } = this;
667667
const { x, y, width, height } = renderContext.viewportValue;
668668

669-
gl.viewport( x, renderContext.height - height - y, width, height );
669+
state.viewport( x, renderContext.height - height - y, width, height );
670670

671671
}
672672

@@ -677,17 +677,9 @@ class WebGLBackend extends Backend {
677677
*/
678678
setScissorTest( boolean ) {
679679

680-
const gl = this.gl;
681-
682-
if ( boolean ) {
680+
const state = this.state;
683681

684-
gl.enable( gl.SCISSOR_TEST );
685-
686-
} else {
687-
688-
gl.disable( gl.SCISSOR_TEST );
689-
690-
}
682+
state.setScissorTest( boolean );
691683

692684
}
693685

src/renderers/webgl-fallback/utils/WebGLState.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
OneMinusSrcColorFactor, OneMinusSrcAlphaFactor, OneMinusDstColorFactor, OneMinusDstAlphaFactor,
77
NeverDepth, AlwaysDepth, LessDepth, LessEqualDepth, EqualDepth, GreaterEqualDepth, GreaterDepth, NotEqualDepth
88
} from '../../../constants.js';
9+
import { Vector4 } from '../../../math/Vector4.js';
910

1011
let initialized = false, equationToGL, factorToGL;
1112

@@ -121,6 +122,14 @@ class WebGLState {
121122
[ OneMinusDstAlphaFactor ]: gl.ONE_MINUS_DST_ALPHA
122123
};
123124

125+
const scissorParam = gl.getParameter( gl.SCISSOR_BOX );
126+
const viewportParam = gl.getParameter( gl.VIEWPORT );
127+
128+
this.currentScissor = new Vector4().fromArray( scissorParam );
129+
this.currentViewport = new Vector4().fromArray( viewportParam );
130+
this._tempScissor = new Vector4();
131+
this._tempViewport = new Vector4();
132+
124133
}
125134

126135
/**
@@ -543,6 +552,75 @@ class WebGLState {
543552

544553
}
545554

555+
/**
556+
* Specifies the viewport.
557+
*
558+
* @param {Number} x - The x-coordinate of the lower left corner of the viewport.
559+
* @param {Number} y - The y-coordinate of the lower left corner of the viewport.
560+
* @param {Number} width - The width of the viewport.
561+
* @param {Number} height - The height of the viewport.
562+
*
563+
*/
564+
scissor( x, y, width, height ) {
565+
566+
const scissor = this._tempScissor.set( x, y, width, height );
567+
568+
if ( this.currentScissor.equals( scissor ) === false ) {
569+
570+
const { gl } = this;
571+
572+
gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
573+
this.currentScissor.copy( scissor );
574+
575+
}
576+
577+
}
578+
579+
/**
580+
* Specifies the viewport.
581+
*
582+
* @param {Number} x - The x-coordinate of the lower left corner of the viewport.
583+
* @param {Number} y - The y-coordinate of the lower left corner of the viewport.
584+
* @param {Number} width - The width of the viewport.
585+
* @param {Number} height - The height of the viewport.
586+
*
587+
*/
588+
viewport( x, y, width, height ) {
589+
590+
const viewport = this._tempScissor.set( x, y, width, height );
591+
592+
if ( this.currentViewport.equals( viewport ) === false ) {
593+
594+
const { gl } = this;
595+
596+
gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
597+
this.currentViewport.copy( viewport );
598+
599+
}
600+
601+
}
602+
603+
/**
604+
* Defines the scissor test.
605+
*
606+
* @param {Boolean} boolean - Whether the scissor test should be enabled or not.
607+
*/
608+
setScissorTest( boolean ) {
609+
610+
const gl = this.gl;
611+
612+
if ( boolean ) {
613+
614+
gl.enable( gl.SCISSOR_TEST );
615+
616+
} else {
617+
618+
gl.disable( gl.SCISSOR_TEST );
619+
620+
}
621+
622+
}
623+
546624
/**
547625
* Specifies whether the stencil test is enabled or not.
548626
*

0 commit comments

Comments
 (0)