Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
32 changes: 17 additions & 15 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ function WebGLRenderer( parameters ) {
let currentRenderState = null;

// render() can be called from within a callback triggered by another render.
// We track this so that the nested render call gets its state isolated from the parent render call.
// We track this so that the nested render call gets its list and state isolated from the parent render call.

const renderListStack = [];
const renderStateStack = [];

// public properties
Expand Down Expand Up @@ -1023,9 +1024,11 @@ function WebGLRenderer( parameters ) {
_localClippingEnabled = this.localClippingEnabled;
_clippingEnabled = clipping.init( this.clippingPlanes, _localClippingEnabled, camera );

currentRenderList = renderLists.get( scene, camera );
currentRenderList = renderLists.get( scene, renderListStack.length );
currentRenderList.init();

renderListStack.push( currentRenderList );

projectObject( scene, camera, 0, _this.sortObjects );

currentRenderList.finish();
Expand Down Expand Up @@ -1100,6 +1103,7 @@ function WebGLRenderer( parameters ) {
// _gl.finish();

renderStateStack.pop();

if ( renderStateStack.length > 0 ) {

currentRenderState = renderStateStack[ renderStateStack.length - 1 ];
Expand All @@ -1110,7 +1114,17 @@ function WebGLRenderer( parameters ) {

}

currentRenderList = null;
renderListStack.pop();

if ( renderListStack.length > 0 ) {

currentRenderList = renderListStack[ renderListStack.length - 1 ];

} else {

currentRenderList = null;

}

};

Expand Down Expand Up @@ -1750,18 +1764,6 @@ function WebGLRenderer( parameters ) {

};

this.getRenderList = function () {

return currentRenderList;

};

this.setRenderList = function ( renderList ) {

currentRenderList = renderList;

};

this.getRenderTarget = function () {

return _currentRenderTarget;
Expand Down
2 changes: 0 additions & 2 deletions src/renderers/webgl/WebGLCubeMaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@ function WebGLCubeMaps( renderer ) {

if ( image && image.height > 0 ) {

const currentRenderList = renderer.getRenderList();
const currentRenderTarget = renderer.getRenderTarget();

const renderTarget = new WebGLCubeRenderTarget( image.height / 2 );
renderTarget.fromEquirectangularTexture( renderer, texture );
cubemaps.set( texture, renderTarget );

renderer.setRenderTarget( currentRenderTarget );
renderer.setRenderList( currentRenderList );

texture.addEventListener( 'dispose', onTextureDispose );

Expand Down
18 changes: 10 additions & 8 deletions src/renderers/webgl/WebGLRenderLists.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,26 @@ function WebGLRenderLists( properties ) {

let lists = new WeakMap();

function get( scene, camera ) {
function get( scene, renderCallDepth ) {

const cameras = lists.get( scene );
let list;

if ( cameras === undefined ) {
if ( lists.has( scene ) === false ) {

list = new WebGLRenderList( properties );
lists.set( scene, new WeakMap() );
lists.get( scene ).set( camera, list );
lists.set( scene, [] );
lists.get( scene ).push( list );
Comment on lines +184 to +185
Copy link
Owner

@mrdoob mrdoob Feb 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these two lines can be simplified to this?

lists.set( scene, [ list ] );

Copy link
Owner

@mrdoob mrdoob Feb 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change it on my end.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same change can be applied in WebGLRenderStates, too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, you were faster than my comment 😅 af07e8a


} else {

list = cameras.get( camera );
if ( list === undefined ) {
if ( renderCallDepth >= lists.get( scene ).length ) {

list = new WebGLRenderList( properties );
cameras.set( camera, list );
lists.get( scene ).push( list );

} else {

list = lists.get( scene )[ renderCallDepth ];

}

Expand Down
21 changes: 8 additions & 13 deletions test/unit/src/renderers/webgl/WebGLRenderLists.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { WebGLRenderLists, WebGLRenderList } from '../../../../../src/renderers/webgl/WebGLRenderLists';
import { WebGLProperties } from '../../../../../src/renderers/webgl/WebGLProperties';
import { Camera } from '../../../../../src/cameras/Camera';
import { Scene } from '../../../../../src/scenes/Scene';

export default QUnit.module( 'Renderers', () => {
Expand All @@ -19,18 +18,14 @@ export default QUnit.module( 'Renderers', () => {
var renderLists = new WebGLRenderLists( properties );
var sceneA = new Scene();
var sceneB = new Scene();
var cameraA = new Camera();
var cameraB = new Camera();

var listAA = renderLists.get( sceneA, cameraA );
var listAB = renderLists.get( sceneA, cameraB );
var listBA = renderLists.get( sceneB, cameraA );

assert.propEqual( listAA, new WebGLRenderList( properties ), "listAA is type of WebGLRenderList." );
assert.propEqual( listAB, new WebGLRenderList( properties ), "listAB is type of WebGLRenderList." );
assert.ok( listAA !== listAB, "Render lists for camera A and B with same scene are different." );
assert.ok( listAA !== listBA, "Render lists for scene A and B with same camera are different." );
assert.ok( listAA === renderLists.get( sceneA, cameraA ), "The same list is returned when called with the same scene, camera." );

var listA = renderLists.get( sceneA );
var listB = renderLists.get( sceneB );

assert.propEqual( listA, new WebGLRenderList( properties ), "listA is type of WebGLRenderList." );
assert.propEqual( listB, new WebGLRenderList( properties ), "listB is type of WebGLRenderList." );
assert.ok( listA !== listB, "Render lists are different." );


} );

Expand Down