namespace NT { /**
     * Holds reference information for a given Texture.
     */ class TextureReferenceNode { /** The referenced Texture. */ public texture : Texture ; /** The number of times the Texture is referenced. Default is 1 because this is only created when a Texture is needed. */ public referenceCount : number = 1 ; param texture public constructor ( texture ) { this . texture = texture ; } } /**
     * Manages Textures in the engine. This is responsible for managing Texture references, and automatically
     * destroying unreferenced Texture.
     */ export class TextureManager { private static _textures : { [ name ] : TextureReferenceNode ; } = { } ; /** Private to enforce singleton pattern. */ private constructor ( ) { } param textureName public static getTexture ( textureName ) { if ( TextureManager . _textures [ textureName ] === undefined ) { let texture = new Texture ( textureName ) ; TextureManager . _textures [ textureName ] = new TextureReferenceNode ( texture ) ; } else { TextureManager . _textures [ textureName ] . referenceCount ++ ; } return TextureManager . _textures [ textureName ] . texture ; } param textureName public static releaseTexture ( textureName ) { if ( TextureManager . _textures [ textureName ] === undefined ) { console . warn ( `A texture named ${ textureName } does not exist and therefore cannot be released.` ) ; } else { TextureManager . _textures [ textureName ] . referenceCount -- ; if ( TextureManager . _textures [ textureName ] . referenceCount < 1 ) { TextureManager . _textures [ textureName ] . texture . destroy ( ) ; TextureManager . _textures [ textureName ] = undefined ; delete TextureManager . _textures [ textureName ] ; } } } } }