diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 5c50a0c11b923f..fd734e88e1fe24 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -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 @@ -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(); @@ -1100,6 +1103,7 @@ function WebGLRenderer( parameters ) { // _gl.finish(); renderStateStack.pop(); + if ( renderStateStack.length > 0 ) { currentRenderState = renderStateStack[ renderStateStack.length - 1 ]; @@ -1110,7 +1114,17 @@ function WebGLRenderer( parameters ) { } - currentRenderList = null; + renderListStack.pop(); + + if ( renderListStack.length > 0 ) { + + currentRenderList = renderListStack[ renderListStack.length - 1 ]; + + } else { + + currentRenderList = null; + + } }; @@ -1750,18 +1764,6 @@ function WebGLRenderer( parameters ) { }; - this.getRenderList = function () { - - return currentRenderList; - - }; - - this.setRenderList = function ( renderList ) { - - currentRenderList = renderList; - - }; - this.getRenderTarget = function () { return _currentRenderTarget; diff --git a/src/renderers/webgl/WebGLCubeMaps.js b/src/renderers/webgl/WebGLCubeMaps.js index e23f85ba01cb56..ae764eb65bec3f 100644 --- a/src/renderers/webgl/WebGLCubeMaps.js +++ b/src/renderers/webgl/WebGLCubeMaps.js @@ -40,7 +40,6 @@ function WebGLCubeMaps( renderer ) { if ( image && image.height > 0 ) { - const currentRenderList = renderer.getRenderList(); const currentRenderTarget = renderer.getRenderTarget(); const renderTarget = new WebGLCubeRenderTarget( image.height / 2 ); @@ -48,7 +47,6 @@ function WebGLCubeMaps( renderer ) { cubemaps.set( texture, renderTarget ); renderer.setRenderTarget( currentRenderTarget ); - renderer.setRenderList( currentRenderList ); texture.addEventListener( 'dispose', onTextureDispose ); diff --git a/src/renderers/webgl/WebGLRenderLists.js b/src/renderers/webgl/WebGLRenderLists.js index b2a49c7c7a82ea..3da709b952795a 100644 --- a/src/renderers/webgl/WebGLRenderLists.js +++ b/src/renderers/webgl/WebGLRenderLists.js @@ -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 ); } 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 ]; } diff --git a/test/unit/src/renderers/webgl/WebGLRenderLists.tests.js b/test/unit/src/renderers/webgl/WebGLRenderLists.tests.js index d81b36447d9e28..f277d44b4ab1a3 100644 --- a/test/unit/src/renderers/webgl/WebGLRenderLists.tests.js +++ b/test/unit/src/renderers/webgl/WebGLRenderLists.tests.js @@ -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', () => { @@ -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." ); + } );