You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.1 KiB
64 lines
1.1 KiB
import ChainMap from './ChainMap.js';
|
|
import RenderContext from './RenderContext.js';
|
|
|
|
class RenderContexts {
|
|
|
|
constructor() {
|
|
|
|
this.chainMaps = {};
|
|
|
|
}
|
|
|
|
get( scene, camera, renderTarget = null ) {
|
|
|
|
const chainKey = [ scene, camera ];
|
|
|
|
let attachmentState;
|
|
|
|
if ( renderTarget === null ) {
|
|
|
|
attachmentState = 'default';
|
|
|
|
} else {
|
|
|
|
const format = renderTarget.texture.format;
|
|
const count = renderTarget.count;
|
|
|
|
attachmentState = `${ count }:${ format }:${ renderTarget.samples }:${ renderTarget.depthBuffer }:${ renderTarget.stencilBuffer }`;
|
|
|
|
}
|
|
|
|
const chainMap = this.getChainMap( attachmentState );
|
|
|
|
let renderState = chainMap.get( chainKey );
|
|
|
|
if ( renderState === undefined ) {
|
|
|
|
renderState = new RenderContext();
|
|
|
|
chainMap.set( chainKey, renderState );
|
|
|
|
}
|
|
|
|
if ( renderTarget !== null ) renderState.sampleCount = renderTarget.samples === 0 ? 1 : renderTarget.samples;
|
|
|
|
return renderState;
|
|
|
|
}
|
|
|
|
getChainMap( attachmentState ) {
|
|
|
|
return this.chainMaps[ attachmentState ] || ( this.chainMaps[ attachmentState ] = new ChainMap() );
|
|
|
|
}
|
|
|
|
dispose() {
|
|
|
|
this.chainMaps = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export default RenderContexts;
|