Skip to content

Commit 1da7835

Browse files
authored
Merge pull request #21254 from Mugen87/dev2
WebGLRenderLists: Use stack approach.
2 parents 9d8ed27 + 4c18162 commit 1da7835

File tree

4 files changed

+35
-38
lines changed

4 files changed

+35
-38
lines changed

src/renderers/WebGLRenderer.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ function WebGLRenderer( parameters ) {
6868
let currentRenderState = null;
6969

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

73+
const renderListStack = [];
7374
const renderStateStack = [];
7475

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

1026-
currentRenderList = renderLists.get( scene, camera );
1027+
currentRenderList = renderLists.get( scene, renderListStack.length );
10271028
currentRenderList.init();
10281029

1030+
renderListStack.push( currentRenderList );
1031+
10291032
projectObject( scene, camera, 0, _this.sortObjects );
10301033

10311034
currentRenderList.finish();
@@ -1100,6 +1103,7 @@ function WebGLRenderer( parameters ) {
11001103
// _gl.finish();
11011104

11021105
renderStateStack.pop();
1106+
11031107
if ( renderStateStack.length > 0 ) {
11041108

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

11111115
}
11121116

1113-
currentRenderList = null;
1117+
renderListStack.pop();
1118+
1119+
if ( renderListStack.length > 0 ) {
1120+
1121+
currentRenderList = renderListStack[ renderListStack.length - 1 ];
1122+
1123+
} else {
1124+
1125+
currentRenderList = null;
1126+
1127+
}
11141128

11151129
};
11161130

@@ -1750,18 +1764,6 @@ function WebGLRenderer( parameters ) {
17501764

17511765
};
17521766

1753-
this.getRenderList = function () {
1754-
1755-
return currentRenderList;
1756-
1757-
};
1758-
1759-
this.setRenderList = function ( renderList ) {
1760-
1761-
currentRenderList = renderList;
1762-
1763-
};
1764-
17651767
this.getRenderTarget = function () {
17661768

17671769
return _currentRenderTarget;

src/renderers/webgl/WebGLCubeMaps.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,13 @@ function WebGLCubeMaps( renderer ) {
4040

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

43-
const currentRenderList = renderer.getRenderList();
4443
const currentRenderTarget = renderer.getRenderTarget();
4544

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

5049
renderer.setRenderTarget( currentRenderTarget );
51-
renderer.setRenderList( currentRenderList );
5250

5351
texture.addEventListener( 'dispose', onTextureDispose );
5452

src/renderers/webgl/WebGLRenderLists.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,24 +174,26 @@ function WebGLRenderLists( properties ) {
174174

175175
let lists = new WeakMap();
176176

177-
function get( scene, camera ) {
177+
function get( scene, renderCallDepth ) {
178178

179-
const cameras = lists.get( scene );
180179
let list;
181180

182-
if ( cameras === undefined ) {
181+
if ( lists.has( scene ) === false ) {
183182

184183
list = new WebGLRenderList( properties );
185-
lists.set( scene, new WeakMap() );
186-
lists.get( scene ).set( camera, list );
184+
lists.set( scene, [] );
185+
lists.get( scene ).push( list );
187186

188187
} else {
189188

190-
list = cameras.get( camera );
191-
if ( list === undefined ) {
189+
if ( renderCallDepth >= lists.get( scene ).length ) {
192190

193191
list = new WebGLRenderList( properties );
194-
cameras.set( camera, list );
192+
lists.get( scene ).push( list );
193+
194+
} else {
195+
196+
list = lists.get( scene )[ renderCallDepth ];
195197

196198
}
197199

test/unit/src/renderers/webgl/WebGLRenderLists.tests.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { WebGLRenderLists, WebGLRenderList } from '../../../../../src/renderers/webgl/WebGLRenderLists';
44
import { WebGLProperties } from '../../../../../src/renderers/webgl/WebGLProperties';
5-
import { Camera } from '../../../../../src/cameras/Camera';
65
import { Scene } from '../../../../../src/scenes/Scene';
76

87
export default QUnit.module( 'Renderers', () => {
@@ -19,18 +18,14 @@ export default QUnit.module( 'Renderers', () => {
1918
var renderLists = new WebGLRenderLists( properties );
2019
var sceneA = new Scene();
2120
var sceneB = new Scene();
22-
var cameraA = new Camera();
23-
var cameraB = new Camera();
24-
25-
var listAA = renderLists.get( sceneA, cameraA );
26-
var listAB = renderLists.get( sceneA, cameraB );
27-
var listBA = renderLists.get( sceneB, cameraA );
28-
29-
assert.propEqual( listAA, new WebGLRenderList( properties ), "listAA is type of WebGLRenderList." );
30-
assert.propEqual( listAB, new WebGLRenderList( properties ), "listAB is type of WebGLRenderList." );
31-
assert.ok( listAA !== listAB, "Render lists for camera A and B with same scene are different." );
32-
assert.ok( listAA !== listBA, "Render lists for scene A and B with same camera are different." );
33-
assert.ok( listAA === renderLists.get( sceneA, cameraA ), "The same list is returned when called with the same scene, camera." );
21+
22+
var listA = renderLists.get( sceneA );
23+
var listB = renderLists.get( sceneB );
24+
25+
assert.propEqual( listA, new WebGLRenderList( properties ), "listA is type of WebGLRenderList." );
26+
assert.propEqual( listB, new WebGLRenderList( properties ), "listB is type of WebGLRenderList." );
27+
assert.ok( listA !== listB, "Render lists are different." );
28+
3429

3530
} );
3631

0 commit comments

Comments
 (0)