Jelajahi Sumber

Merge pull request #21254 from Mugen87/dev2

WebGLRenderLists: Use stack approach.
Mr.doob 4 tahun lalu
induk
melakukan
1da7835b26

+ 17 - 15
src/renderers/WebGLRenderer.js

@@ -68,8 +68,9 @@ function WebGLRenderer( parameters ) {
 	let currentRenderState = null;
 	let currentRenderState = null;
 
 
 	// render() can be called from within a callback triggered by another render.
 	// 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 = [];
 	const renderStateStack = [];
 
 
 	// public properties
 	// public properties
@@ -1023,9 +1024,11 @@ function WebGLRenderer( parameters ) {
 		_localClippingEnabled = this.localClippingEnabled;
 		_localClippingEnabled = this.localClippingEnabled;
 		_clippingEnabled = clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
 		_clippingEnabled = clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
 
 
-		currentRenderList = renderLists.get( scene, camera );
+		currentRenderList = renderLists.get( scene, renderListStack.length );
 		currentRenderList.init();
 		currentRenderList.init();
 
 
+		renderListStack.push( currentRenderList );
+
 		projectObject( scene, camera, 0, _this.sortObjects );
 		projectObject( scene, camera, 0, _this.sortObjects );
 
 
 		currentRenderList.finish();
 		currentRenderList.finish();
@@ -1100,6 +1103,7 @@ function WebGLRenderer( parameters ) {
 		// _gl.finish();
 		// _gl.finish();
 
 
 		renderStateStack.pop();
 		renderStateStack.pop();
+
 		if ( renderStateStack.length > 0 ) {
 		if ( renderStateStack.length > 0 ) {
 
 
 			currentRenderState = renderStateStack[ renderStateStack.length - 1 ];
 			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 () {
 	this.getRenderTarget = function () {
 
 
 		return _currentRenderTarget;
 		return _currentRenderTarget;

+ 0 - 2
src/renderers/webgl/WebGLCubeMaps.js

@@ -40,7 +40,6 @@ function WebGLCubeMaps( renderer ) {
 
 
 					if ( image && image.height > 0 ) {
 					if ( image && image.height > 0 ) {
 
 
-						const currentRenderList = renderer.getRenderList();
 						const currentRenderTarget = renderer.getRenderTarget();
 						const currentRenderTarget = renderer.getRenderTarget();
 
 
 						const renderTarget = new WebGLCubeRenderTarget( image.height / 2 );
 						const renderTarget = new WebGLCubeRenderTarget( image.height / 2 );
@@ -48,7 +47,6 @@ function WebGLCubeMaps( renderer ) {
 						cubemaps.set( texture, renderTarget );
 						cubemaps.set( texture, renderTarget );
 
 
 						renderer.setRenderTarget( currentRenderTarget );
 						renderer.setRenderTarget( currentRenderTarget );
-						renderer.setRenderList( currentRenderList );
 
 
 						texture.addEventListener( 'dispose', onTextureDispose );
 						texture.addEventListener( 'dispose', onTextureDispose );
 
 

+ 10 - 8
src/renderers/webgl/WebGLRenderLists.js

@@ -174,24 +174,26 @@ function WebGLRenderLists( properties ) {
 
 
 	let lists = new WeakMap();
 	let lists = new WeakMap();
 
 
-	function get( scene, camera ) {
+	function get( scene, renderCallDepth ) {
 
 
-		const cameras = lists.get( scene );
 		let list;
 		let list;
 
 
-		if ( cameras === undefined ) {
+		if ( lists.has( scene ) === false ) {
 
 
 			list = new WebGLRenderList( properties );
 			list = new WebGLRenderList( properties );
-			lists.set( scene, new WeakMap() );
-			lists.get( scene ).set( camera, list );
+			lists.set( scene, [] );
+			lists.get( scene ).push( list );
 
 
 		} else {
 		} else {
 
 
-			list = cameras.get( camera );
-			if ( list === undefined ) {
+			if ( renderCallDepth >= lists.get( scene ).length ) {
 
 
 				list = new WebGLRenderList( properties );
 				list = new WebGLRenderList( properties );
-				cameras.set( camera, list );
+				lists.get( scene ).push( list );
+
+			} else {
+
+				list = lists.get( scene )[ renderCallDepth ];
 
 
 			}
 			}
 
 

+ 8 - 13
test/unit/src/renderers/webgl/WebGLRenderLists.tests.js

@@ -2,7 +2,6 @@
 
 
 import { WebGLRenderLists, WebGLRenderList } from '../../../../../src/renderers/webgl/WebGLRenderLists';
 import { WebGLRenderLists, WebGLRenderList } from '../../../../../src/renderers/webgl/WebGLRenderLists';
 import { WebGLProperties } from '../../../../../src/renderers/webgl/WebGLProperties';
 import { WebGLProperties } from '../../../../../src/renderers/webgl/WebGLProperties';
-import { Camera } from '../../../../../src/cameras/Camera';
 import { Scene } from '../../../../../src/scenes/Scene';
 import { Scene } from '../../../../../src/scenes/Scene';
 
 
 export default QUnit.module( 'Renderers', () => {
 export default QUnit.module( 'Renderers', () => {
@@ -19,18 +18,14 @@ export default QUnit.module( 'Renderers', () => {
 				var renderLists = new WebGLRenderLists( properties );
 				var renderLists = new WebGLRenderLists( properties );
 				var sceneA = new Scene();
 				var sceneA = new Scene();
 				var sceneB = 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." );
+
 
 
 			} );
 			} );