import { ALPHA_MODES } from '@pixi/constants' ; import { BaseTexture , GLTexture , Resource , Renderer } from '@pixi/core' ; import type { Rectangle } from '@pixi/math' ; import type { Texture } from '@pixi/core' ; /**
 * Types of image sources supported by  AtlasResource .
 *
 *  public export type AtlasResourceSource = HTMLImageElement | HTMLCanvasElement | ImageBitmap | ImageData | ArrayBufferView ; public export type AtlasResourceItem = { /**
     * The location of the atlas item in the base-texture's space.
     */ frame : Rectangle ; /**
     * The source of the texture data.
     */ source : AtlasResourceSource ; /**
     * This flags when the resource is to be re-uploaded.
     */ dirtyId : number ; /**
     * This flags when the resource is uploaded and update-to-date with the dirty ID.
     */ updateId : number ; /**
     * The texture holding this item.
     */ texture : Texture ; } ; /**
 * An {@code AtlasResource} is used by  AtlasAllocator to manage texture sources
 *
 *  public export class AtlasResource extends Resource { /**
     * The list of managed resources in the atlas.
     */ public managedItems : AtlasResourceItem [ ] ; param width param height constructor ( width , height ) { super ( width , height ) ; this . managedItems = [ ] ; } param renderer param baseTexture param glTexture upload ( renderer , baseTexture , glTexture ) { const gl = renderer . gl ; const width = baseTexture . realWidth ; const height = baseTexture . realHeight ; gl . pixelStorei ( gl . UNPACK_PREMULTIPLY_ALPHA_WEBGL , baseTexture . alphaMode === ALPHA_MODES . UNPACK ) ; if ( glTexture . width !== width || glTexture . height !== height ) { glTexture . width = width ; glTexture . height = height ; gl . texImage2D ( baseTexture . target , 0 , baseTexture . format , width , height , 0 , baseTexture . format , baseTexture . type , undefined ) ; } const items = this . managedItems ; for ( let i = 0 , j = items . length ; i < j ; i ++ ) { this . uploadItem ( renderer , baseTexture . target , baseTexture . format , baseTexture . type , items [ i ] ) ; } return true ; } param renderer param target param format param type param item protected uploadItem ( renderer , target , format , type , item ) { if ( item . updateId === item . dirtyId ) { return ; } const gl = renderer . gl ; const source = item . source ; const frame = item . frame ; gl . texSubImage2D ( target , 0 , frame . x , frame . y , frame . width , frame . height , format , type , source as any ) ; item . updateId = item . dirtyId ; } }