melonJS
    Preparing search index...

    Class Texture2dAbstract

    Abstract base for a 2D texture asset — an object that owns a texture source and can be used anywhere the engine expects an image: Sprite#image, Sprite#normalMap, an ImageLayer, or bound as a sampler uniform in a custom shader (see ShaderEffect#setTexture).

    A Texture2d is recognized via instanceof and resolved to its backing source through Texture2d#getTexture — so passing the asset object directly ({ image: myTexture }) works the same as passing a raw HTMLCanvasElement. Raw DOM image/canvas sources and the loader's decoded CompressedImage data are accepted too, but are not part of this class hierarchy.

    Most assets are CPU-backed and resolve to a drawable canvas/image — those are the ones assignable to Sprite#image / Sprite#normalMap / an ImageLayer (which upload the drawable through the texture cache). Subclasses may also be GPU-resident, resolving to an opaque renderer backing that never leaves the GPU (e.g. the capture returned by renderer.toFrameTexture()). A GPU-resident texture is not a drawable source: use it as a custom-shader sampler via ShaderEffect#setTexture (which binds its live GL handle), NOT as Sprite#image. The contract admits both (a future WebGPU backend follows the same shape with a GPUTexture).

    Concrete implementations:

    • TextureAtlas — packed multi-region sprite sheet (CPU-backed)

    Hierarchy (View Summary)

    Index
    • Release any GPU/CPU resources held by this texture. The texture must not be used after calling destroy.

      Broadcasts event.TEXTURE2D_DESTROYED with the backing source so GPU-side caches keyed by source image (e.g. the lit batcher's normal-map textures) release what they hold for it. Subclasses that own additional resources override this and call super.destroy() FIRST — the source must still be resolvable when the event fires.

      Returns void