export class ImageCanvas { canvas : HTMLCanvasElement ; context : CanvasRenderingContext2D ; constructor ( width = 1024 , height = 1024 ) { this . canvas = document . createElement ( "canvas" ) ; this . canvas . width = width ; this . canvas . height = height ; this . context = this . canvas . getContext ( "2d" ) ; } copyFromCanvas ( src , resize = false ) { if ( resize ) { if ( this . canvas . width != src . width ) this . canvas . width = src . width ; if ( this . canvas . height != src . height ) this . canvas . height = src . height ; } this . context . clearRect ( 0 , 0 , this . canvas . width , this . canvas . height ) ; this . context . drawImage ( src , 0 , 0 , this . canvas . width , this . canvas . height ) ; } copyFromImageCanvas ( imageCanvas ) { this . context . clearRect ( 0 , 0 , this . canvas . width , this . canvas . height ) ; this . context . drawImage ( imageCanvas . canvas , 0 , 0 , this . canvas . width , this . canvas . height ) ; } resize ( width , height ) { this . canvas . width = width ; this . canvas . height = height ; } width ( ) { return this . canvas . width ; } height ( ) { return this . canvas . height ; } toImage ( ) { const img = < HTMLImageElement > ( document . createElement ( "image" ) ) ; img . src = this . canvas . toDataURL ( "image/png" ) ; return img ; } createTexture ( gl ) { const texture = gl . createTexture ( ) ; gl . bindTexture ( gl . TEXTURE_2D , texture ) ; gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_S , gl . REPEAT ) ; gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_T , gl . REPEAT ) ; gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , gl . LINEAR ) ; gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MAG_FILTER , gl . LINEAR ) ; gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , gl . RGBA , gl . UNSIGNED_BYTE , this . canvas ) ; return texture ; } }