Skip to content

Commit

Permalink
RenderContexts: Introduce getForClear(). (#30256)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 authored Jan 3, 2025
1 parent 3abfd88 commit 99eae50
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
38 changes: 24 additions & 14 deletions src/renderers/common/RenderContexts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import ChainMap from './ChainMap.js';
import RenderContext from './RenderContext.js';
import { Scene } from '../../scenes/Scene.js';
import { Camera } from '../../cameras/Camera.js';

const _chainKeys = [];
const _defaultScene = /*@__PURE__*/ new Scene();
const _defaultCamera = /*@__PURE__*/ new Camera();

/**
* This module manages the render contexts of the renderer.
Expand All @@ -28,22 +32,15 @@ class RenderContexts {
/**
* Returns a render context for the given scene, camera and render target.
*
* @param {Scene?} [scene=null] - The scene. The parameter can become `null` e.g. when the renderer clears a render target.
* @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.
* @param {Scene} scene - The scene.
* @param {Camera} camera - The camera that is used to render the scene.
* @param {RenderTarget?} [renderTarget=null] - The active render target.
* @return {RenderContext} The render context.
*/
get( scene = null, camera = null, renderTarget = null ) {

if ( scene !== null ) _chainKeys.push( scene );
if ( camera !== null ) _chainKeys.push( camera );

if ( _chainKeys.length === 0 ) {

_chainKeys.push( { id: 'default' } );

}
get( scene, camera, renderTarget = null ) {

_chainKeys[ 0 ] = scene;
_chainKeys[ 1 ] = camera;

let attachmentState;

Expand All @@ -60,7 +57,7 @@ class RenderContexts {

}

const chainMap = this.getChainMap( attachmentState );
const chainMap = this._getChainMap( attachmentState );

let renderState = chainMap.get( _chainKeys );

Expand All @@ -80,13 +77,26 @@ class RenderContexts {

}

/**
* Returns a render context intended for clear operations.
*
* @param {RenderTarget?} [renderTarget=null] - The active render target.
* @return {RenderContext} The render context.
*/
getForClear( renderTarget = null ) {

return this.get( _defaultScene, _defaultCamera, renderTarget );

}

/**
* Returns a chain map for the given attachment state.
*
* @private
* @param {String} attachmentState - The attachment state.
* @return {ChainMap} The chain map.
*/
getChainMap( attachmentState ) {
_getChainMap( attachmentState ) {

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

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,7 @@ class Renderer {

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

renderContext = this._renderContexts.get( null, null, renderTarget );
renderContext = this._renderContexts.getForClear( renderTarget );
renderContext.textures = renderTargetData.textures;
renderContext.depthTexture = renderTargetData.depthTexture;
renderContext.width = renderTargetData.width;
Expand Down

0 comments on commit 99eae50

Please sign in to comment.