Skip to content

Commit

Permalink
WebGLBackground: Split adding to render list and clearing of buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
mrxz committed Apr 7, 2024
1 parent 2b07742 commit 1375474
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
21 changes: 12 additions & 9 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,13 @@ class WebGLRenderer {

}

const renderBackground = xr.enabled === false || xr.isPresenting === false || xr.hasDepthSensing() === false;
if ( renderBackground ) {

background.addToRenderList( currentRenderList, scene );

}

//

this.info.render.frame ++;
Expand All @@ -1166,15 +1173,6 @@ class WebGLRenderer {

if ( this.info.autoReset === true ) this.info.reset();


//

if ( xr.enabled === false || xr.isPresenting === false || xr.hasDepthSensing() === false ) {

background.render( currentRenderList, scene );

}

// render scene

currentRenderState.setupLights( _this._useLegacyLights );
Expand All @@ -1191,6 +1189,8 @@ class WebGLRenderer {

}

if ( renderBackground ) background.render( scene );

for ( let i = 0, l = cameras.length; i < l; i ++ ) {

const camera2 = cameras[ i ];
Expand All @@ -1202,6 +1202,9 @@ class WebGLRenderer {
} else {

renderTransmissionPass( currentRenderList.opaque, currentRenderList.transmissive, scene, camera );

if ( renderBackground ) background.render( scene );

renderScene( currentRenderList, scene, camera );

}
Expand Down
21 changes: 18 additions & 3 deletions src/renderers/webgl/WebGLBackground.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,
let currentBackgroundVersion = 0;
let currentTonemapping = null;

function render( renderList, scene ) {
function getBackground( scene ) {

let forceClear = false;
let background = scene.isScene === true ? scene.background : null;

if ( background && background.isTexture ) {
Expand All @@ -38,6 +37,15 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,

}

return background;

}

function render( scene ) {

let forceClear = false;
const background = getBackground( scene );

if ( background === null ) {

setClear( clearColor, clearAlpha );
Expand Down Expand Up @@ -67,6 +75,12 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,

}

}

function addToRenderList( renderList, scene ) {

const background = getBackground( scene );

if ( background && ( background.isCubeTexture || background.mapping === CubeUVReflectionMapping ) ) {

if ( boxMesh === undefined ) {
Expand Down Expand Up @@ -247,7 +261,8 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,
setClear( clearColor, clearAlpha );

},
render: render
render: render,
addToRenderList: addToRenderList

};

Expand Down

0 comments on commit 1375474

Please sign in to comment.