@@ -88,6 +88,9 @@ class PenSkin extends Skin {
8888 /** @type {HTMLCanvasElement } */
8989 this . _canvas = document . createElement ( 'canvas' ) ;
9090
91+ /** @type {Array<number> } */
92+ this . _canvasSize = twgl . v3 . create ( ) ;
93+
9194 /** @type {WebGLTexture } */
9295 this . _texture = null ;
9396
@@ -165,7 +168,7 @@ class PenSkin extends Skin {
165168 * @return {Array<number> } the "native" size, in texels, of this skin. [width, height]
166169 */
167170 get size ( ) {
168- return [ this . _canvas . width , this . _canvas . height ] ;
171+ return this . _canvasSize ;
169172 }
170173
171174 /**
@@ -188,13 +191,13 @@ class PenSkin extends Skin {
188191 clear ( ) {
189192 const gl = this . _renderer . gl ;
190193 twgl . bindFramebufferInfo ( gl , this . _framebuffer ) ;
191-
194+
192195 /* Reset framebuffer to transparent black */
193196 gl . clearColor ( 0 , 0 , 0 , 0 ) ;
194197 gl . clear ( gl . COLOR_BUFFER_BIT ) ;
195198
196199 const ctx = this . _canvas . getContext ( '2d' ) ;
197- ctx . clearRect ( 0 , 0 , this . _canvas . width , this . _canvas . height ) ;
200+ ctx . clearRect ( 0 , 0 , this . _canvasSize [ 0 ] , this . _canvasSize [ 1 ] ) ;
198201
199202 this . _silhouetteDirty = true ;
200203 }
@@ -451,7 +454,7 @@ class PenSkin extends Skin {
451454 * @param {number } x - centered at x
452455 * @param {number } y - centered at y
453456 */
454- _drawRectangle ( currentShader , texture , bounds , x = - this . _canvas . width / 2 , y = this . _canvas . height / 2 ) {
457+ _drawRectangle ( currentShader , texture , bounds , x = - this . _canvasSize [ 0 ] / 2 , y = this . _canvasSize [ 1 ] / 2 ) {
455458 const gl = this . _renderer . gl ;
456459
457460 const projection = twgl . m4 . ortho (
@@ -514,7 +517,7 @@ class PenSkin extends Skin {
514517 * @param {number } x - texture centered at x
515518 * @param {number } y - texture centered at y
516519 */
517- _drawToBuffer ( texture = this . _texture , x = - this . _canvas . width / 2 , y = this . _canvas . height / 2 ) {
520+ _drawToBuffer ( texture = this . _texture , x = - this . _canvasSize [ 0 ] / 2 , y = this . _canvasSize [ 1 ] / 2 ) {
518521 if ( texture !== this . _texture && this . _canvasDirty ) {
519522 this . _drawToBuffer ( ) ;
520523 }
@@ -528,7 +531,7 @@ class PenSkin extends Skin {
528531 gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , gl . RGBA , gl . UNSIGNED_BYTE , this . _canvas ) ;
529532
530533 const ctx = this . _canvas . getContext ( '2d' ) ;
531- ctx . clearRect ( 0 , 0 , this . _canvas . width , this . _canvas . height ) ;
534+ ctx . clearRect ( 0 , 0 , this . _canvasSize [ 0 ] , this . _canvasSize [ 1 ] ) ;
532535
533536 this . _canvasDirty = false ;
534537 }
@@ -564,8 +567,8 @@ class PenSkin extends Skin {
564567 this . _bounds = new Rectangle ( ) ;
565568 this . _bounds . initFromBounds ( width / 2 , width / - 2 , height / 2 , height / - 2 ) ;
566569
567- this . _canvas . width = width ;
568- this . _canvas . height = height ;
570+ this . _canvas . width = this . _canvasSize [ 0 ] = width ;
571+ this . _canvas . height = this . _canvasSize [ 1 ] = height ;
569572 this . _rotationCenter [ 0 ] = width / 2 ;
570573 this . _rotationCenter [ 1 ] = height / 2 ;
571574
@@ -651,8 +654,8 @@ class PenSkin extends Skin {
651654 this . _renderer . enterDrawRegion ( this . _toBufferDrawRegionId ) ;
652655
653656 // Sample the framebuffer's pixels into the silhouette instance
654- const skinPixels = new Uint8Array ( Math . floor ( this . _canvas . width * this . _canvas . height * 4 ) ) ;
655- gl . readPixels ( 0 , 0 , this . _canvas . width , this . _canvas . height , gl . RGBA , gl . UNSIGNED_BYTE , skinPixels ) ;
657+ const skinPixels = new Uint8Array ( Math . floor ( this . _canvasSize [ 0 ] * this . _canvasSize [ 1 ] * 4 ) ) ;
658+ gl . readPixels ( 0 , 0 , this . _canvasSize [ 0 ] , this . _canvasSize [ 1 ] , gl . RGBA , gl . UNSIGNED_BYTE , skinPixels ) ;
656659
657660 const skinCanvas = this . _canvas ;
658661 skinCanvas . width = bounds . width ;
0 commit comments