Skip to content

WebGPURenderer: Fix clear alpha in WebGLBackend #30329

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

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
78 changes: 78 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,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.
*
Expand Down
Loading