Skip to content

Commit 99eae50

Browse files
authored
RenderContexts: Introduce getForClear(). (#30256)
1 parent 3abfd88 commit 99eae50

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

src/renderers/common/RenderContexts.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import ChainMap from './ChainMap.js';
22
import RenderContext from './RenderContext.js';
3+
import { Scene } from '../../scenes/Scene.js';
4+
import { Camera } from '../../cameras/Camera.js';
35

46
const _chainKeys = [];
7+
const _defaultScene = /*@__PURE__*/ new Scene();
8+
const _defaultCamera = /*@__PURE__*/ new Camera();
59

610
/**
711
* This module manages the render contexts of the renderer.
@@ -28,22 +32,15 @@ class RenderContexts {
2832
/**
2933
* Returns a render context for the given scene, camera and render target.
3034
*
31-
* @param {Scene?} [scene=null] - The scene. The parameter can become `null` e.g. when the renderer clears a render target.
32-
* @param {Camera?} [camera=null] - The camera that is used to render the scene. The parameter can become `null` e.g. when the renderer clears a render target.
35+
* @param {Scene} scene - The scene.
36+
* @param {Camera} camera - The camera that is used to render the scene.
3337
* @param {RenderTarget?} [renderTarget=null] - The active render target.
3438
* @return {RenderContext} The render context.
3539
*/
36-
get( scene = null, camera = null, renderTarget = null ) {
37-
38-
if ( scene !== null ) _chainKeys.push( scene );
39-
if ( camera !== null ) _chainKeys.push( camera );
40-
41-
if ( _chainKeys.length === 0 ) {
42-
43-
_chainKeys.push( { id: 'default' } );
44-
45-
}
40+
get( scene, camera, renderTarget = null ) {
4641

42+
_chainKeys[ 0 ] = scene;
43+
_chainKeys[ 1 ] = camera;
4744

4845
let attachmentState;
4946

@@ -60,7 +57,7 @@ class RenderContexts {
6057

6158
}
6259

63-
const chainMap = this.getChainMap( attachmentState );
60+
const chainMap = this._getChainMap( attachmentState );
6461

6562
let renderState = chainMap.get( _chainKeys );
6663

@@ -80,13 +77,26 @@ class RenderContexts {
8077

8178
}
8279

80+
/**
81+
* Returns a render context intended for clear operations.
82+
*
83+
* @param {RenderTarget?} [renderTarget=null] - The active render target.
84+
* @return {RenderContext} The render context.
85+
*/
86+
getForClear( renderTarget = null ) {
87+
88+
return this.get( _defaultScene, _defaultCamera, renderTarget );
89+
90+
}
91+
8392
/**
8493
* Returns a chain map for the given attachment state.
8594
*
95+
* @private
8696
* @param {String} attachmentState - The attachment state.
8797
* @return {ChainMap} The chain map.
8898
*/
89-
getChainMap( attachmentState ) {
99+
_getChainMap( attachmentState ) {
90100

91101
return this.chainMaps[ attachmentState ] || ( this.chainMaps[ attachmentState ] = new ChainMap() );
92102

src/renderers/common/Renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,7 @@ class Renderer {
18441844

18451845
const renderTargetData = this._textures.get( renderTarget );
18461846

1847-
renderContext = this._renderContexts.get( null, null, renderTarget );
1847+
renderContext = this._renderContexts.getForClear( renderTarget );
18481848
renderContext.textures = renderTargetData.textures;
18491849
renderContext.depthTexture = renderTargetData.depthTexture;
18501850
renderContext.width = renderTargetData.width;

0 commit comments

Comments
 (0)