Skip to content

Commit

Permalink
WebGPURenderer: Fix clear alpha in WebGLBackend
Browse files Browse the repository at this point in the history
  • Loading branch information
RenaudRohlinger committed Jan 15, 2025
1 parent accd150 commit dc3b68e
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1855,6 +1855,8 @@ class Renderer {

}

renderContext.clearColorValue = this._clearColor;

this.backend.clear( color, depth, stencil, renderContext );

if ( renderTarget !== null && this._renderTarget === null ) {
Expand Down
24 changes: 8 additions & 16 deletions src/renderers/webgl-fallback/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ class WebGLBackend extends Backend {
*/
beginRender( renderContext ) {

const { gl } = this;
const { state, gl } = this;
const renderContextData = this.get( renderContext );

//
Expand All @@ -433,15 +433,15 @@ class WebGLBackend extends Backend {

} else {

gl.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight );
state.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight );

}

if ( renderContext.scissor ) {

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 );

}

Expand Down Expand Up @@ -565,7 +565,7 @@ class WebGLBackend extends Backend {

} else {

gl.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight );
state.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight );

}

Expand Down Expand Up @@ -663,10 +663,10 @@ class WebGLBackend extends Backend {
*/
updateViewport( renderContext ) {

const gl = this.gl;
const { state } = this;
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 );

}

Expand All @@ -677,17 +677,9 @@ class WebGLBackend extends Backend {
*/
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 );

}

Expand Down
69 changes: 69 additions & 0 deletions src/renderers/webgl-fallback/utils/WebGLState.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
OneMinusSrcColorFactor, OneMinusSrcAlphaFactor, OneMinusDstColorFactor, OneMinusDstAlphaFactor,
NeverDepth, AlwaysDepth, LessDepth, LessEqualDepth, EqualDepth, GreaterEqualDepth, GreaterDepth, NotEqualDepth
} from '../../../constants.js';
import { Vector4 } from '../../../math/Vector4.js';

let initialized = false, equationToGL, factorToGL;

Expand Down Expand Up @@ -121,6 +122,14 @@ class WebGLState {
[ 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();

}

/**
Expand Down Expand Up @@ -543,6 +552,66 @@ class WebGLState {

}

scissor( x, y, z, w ) {

const scissor = this._tempScissor.set( x, y, z, w );

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.
*
Expand Down

0 comments on commit dc3b68e

Please sign in to comment.