Просмотр исходного кода

WebGPURenderer: Fix clear alpha in WebGLBackend (#30329)

* WebGPURenderer: Fix clear alpha in WebGLBackend

* improved jsdoc

* add comment

* simplify

* remove white space

* revert
Renaud Rohlinger 1 год назад
Родитель
Сommit
a13e4b053a

+ 3 - 0
src/renderers/common/Renderer.js

@@ -1855,6 +1855,9 @@ class Renderer {
 
 
 		}
 		}
 
 
+		// #30329
+		renderContext.clearColorValue = this._clearColor;
+
 		this.backend.clear( color, depth, stencil, renderContext );
 		this.backend.clear( color, depth, stencil, renderContext );
 
 
 		if ( renderTarget !== null && this._renderTarget === null ) {
 		if ( renderTarget !== null && this._renderTarget === null ) {

+ 8 - 16
src/renderers/webgl-fallback/WebGLBackend.js

@@ -410,7 +410,7 @@ class WebGLBackend extends Backend {
 	 */
 	 */
 	beginRender( renderContext ) {
 	beginRender( renderContext ) {
 
 
-		const { gl } = this;
+		const { state, gl } = this;
 		const renderContextData = this.get( renderContext );
 		const renderContextData = this.get( renderContext );
 
 
 		//
 		//
@@ -433,7 +433,7 @@ class WebGLBackend extends Backend {
 
 
 		} else {
 		} else {
 
 
-			gl.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight );
+			state.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight );
 
 
 		}
 		}
 
 
@@ -441,7 +441,7 @@ class WebGLBackend extends Backend {
 
 
 			const { x, y, width, height } = renderContext.scissorValue;
 			const { x, y, width, height } = renderContext.scissorValue;
 
 
-			gl.scissor( x, renderContext.height - height - y, width, height );
+			state.scissor( x, renderContext.height - height - y, width, height );
 
 
 		}
 		}
 
 
@@ -565,7 +565,7 @@ class WebGLBackend extends Backend {
 
 
 			} else {
 			} else {
 
 
-				gl.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight );
+				state.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight );
 
 
 			}
 			}
 
 
@@ -663,10 +663,10 @@ class WebGLBackend extends Backend {
 	 */
 	 */
 	updateViewport( renderContext ) {
 	updateViewport( renderContext ) {
 
 
-		const gl = this.gl;
+		const { state } = this;
 		const { x, y, width, height } = renderContext.viewportValue;
 		const { x, y, width, height } = renderContext.viewportValue;
 
 
-		gl.viewport( x, renderContext.height - height - y, width, height );
+		state.viewport( x, renderContext.height - height - y, width, height );
 
 
 	}
 	}
 
 
@@ -677,17 +677,9 @@ class WebGLBackend extends Backend {
 	 */
 	 */
 	setScissorTest( boolean ) {
 	setScissorTest( boolean ) {
 
 
-		const gl = this.gl;
-
-		if ( boolean ) {
+		const state = this.state;
 
 
-			gl.enable( gl.SCISSOR_TEST );
-
-		} else {
-
-			gl.disable( gl.SCISSOR_TEST );
-
-		}
+		state.setScissorTest( boolean );
 
 
 	}
 	}
 
 

+ 78 - 0
src/renderers/webgl-fallback/utils/WebGLState.js

@@ -6,6 +6,7 @@ import {
 	OneMinusSrcColorFactor, OneMinusSrcAlphaFactor, OneMinusDstColorFactor, OneMinusDstAlphaFactor,
 	OneMinusSrcColorFactor, OneMinusSrcAlphaFactor, OneMinusDstColorFactor, OneMinusDstAlphaFactor,
 	NeverDepth, AlwaysDepth, LessDepth, LessEqualDepth, EqualDepth, GreaterEqualDepth, GreaterDepth, NotEqualDepth
 	NeverDepth, AlwaysDepth, LessDepth, LessEqualDepth, EqualDepth, GreaterEqualDepth, GreaterDepth, NotEqualDepth
 } from '../../../constants.js';
 } from '../../../constants.js';
+import { Vector4 } from '../../../math/Vector4.js';
 
 
 let initialized = false, equationToGL, factorToGL;
 let initialized = false, equationToGL, factorToGL;
 
 
@@ -121,6 +122,14 @@ class WebGLState {
 			[ OneMinusDstAlphaFactor ]: gl.ONE_MINUS_DST_ALPHA
 			[ OneMinusDstAlphaFactor ]: gl.ONE_MINUS_DST_ALPHA
 		};
 		};
 
 
+		const scissorParam = gl.getParameter( gl.SCISSOR_BOX );
+		const viewportParam = gl.getParameter( gl.VIEWPORT );
+
+		this.currentScissor = new Vector4().fromArray( scissorParam );
+		this.currentViewport = new Vector4().fromArray( viewportParam );
+		this._tempScissor = new Vector4();
+		this._tempViewport = new Vector4();
+
 	}
 	}
 
 
 	/**
 	/**
@@ -543,6 +552,75 @@ class WebGLState {
 
 
 	}
 	}
 
 
+	/**
+	 * Specifies the viewport.
+	 *
+	 * @param {Number} x - The x-coordinate of the lower left corner of the viewport.
+	 * @param {Number} y - The y-coordinate of the lower left corner of the viewport.
+	 * @param {Number} width - The width of the viewport.
+	 * @param {Number} height - The height of the viewport.
+	 *
+	 */
+	scissor( x, y, width, height ) {
+
+		const scissor = this._tempScissor.set( x, y, width, height );
+
+		if ( this.currentScissor.equals( scissor ) === false ) {
+
+			const { gl } = this;
+
+			gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
+			this.currentScissor.copy( scissor );
+
+		}
+
+	}
+
+	/**
+	 * Specifies the viewport.
+	 *
+	 * @param {Number} x - The x-coordinate of the lower left corner of the viewport.
+	 * @param {Number} y - The y-coordinate of the lower left corner of the viewport.
+	 * @param {Number} width - The width of the viewport.
+	 * @param {Number} height - The height of the viewport.
+	 *
+	 */
+	viewport( x, y, width, height ) {
+
+		const viewport = this._tempScissor.set( x, y, width, height );
+
+		if ( this.currentViewport.equals( viewport ) === false ) {
+
+			const { gl } = this;
+
+			gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
+			this.currentViewport.copy( viewport );
+
+		}
+
+	}
+
+	/**
+	 * Defines the scissor test.
+	 *
+	 * @param {Boolean} boolean - Whether the scissor test should be enabled or not.
+	 */
+	setScissorTest( boolean ) {
+
+		const gl = this.gl;
+
+		if ( boolean ) {
+
+			gl.enable( gl.SCISSOR_TEST );
+
+		} else {
+
+			gl.disable( gl.SCISSOR_TEST );
+
+		}
+
+	}
+
 	/**
 	/**
 	 * Specifies whether the stencil test is enabled or not.
 	 * Specifies whether the stencil test is enabled or not.
 	 *
 	 *

粤ICP备19079148号