import { inject , injectable } from 'inversify' ; import { IFramebuffer } from '../..' ; import { IDENTIFIER } from '../../identifier' ; import { gl } from '../renderer/gl' ; import { IRendererService } from '../renderer/IRendererService' ; import { ResourceEntry } from './ResourceEntry' ; @ injectable ( ) export class ResourcePool { @ inject ( IDENTIFIER . RenderEngine ) private readonly engine : IRendererService ; private resourcePool : Record < string , IFramebuffer > = { } ; param resource public getOrCreateResource ( resource ) { if ( ! this . resourcePool [ resource . name ] ) { const { width , height , usage } = resource . descriptor ; this . resourcePool [ resource . name ] = this . engine . createFramebuffer ( { color : this . engine . createTexture2D ( { width , height , wrapS : gl . CLAMP_TO_EDGE , wrapT : gl . CLAMP_TO_EDGE , usage , } ) , } ) ; } return this . resourcePool [ resource . name ] ; } public clean ( ) { this . resourcePool = { } ; } }