@@ -109,6 +109,12 @@ class PenSkin extends Skin {
109
109
/** @type {boolean } */
110
110
this . _silhouetteDirty = false ;
111
111
112
+ /** @type {Uint8Array } */
113
+ this . _silhouettePixels = null ;
114
+
115
+ /** @type {ImageData } */
116
+ this . _silhouetteImageData = null ;
117
+
112
118
/** @type {object } */
113
119
this . _lineOnBufferDrawRegionId = {
114
120
enter : ( ) => this . _enterDrawLineOnBuffer ( ) ,
@@ -597,6 +603,9 @@ class PenSkin extends Skin {
597
603
gl . clearColor ( 0 , 0 , 0 , 0 ) ;
598
604
gl . clear ( gl . COLOR_BUFFER_BIT ) ;
599
605
606
+ this . _silhouettePixels = new Uint8Array ( Math . floor ( width * height * 4 ) ) ;
607
+ this . _silhouetteImageData = this . _canvas . getContext ( '2d' ) . createImageData ( width , height ) ;
608
+
600
609
this . _silhouetteDirty = true ;
601
610
}
602
611
@@ -634,24 +643,17 @@ class PenSkin extends Skin {
634
643
// Render export texture to another framebuffer
635
644
const gl = this . _renderer . gl ;
636
645
637
- const bounds = this . _bounds ;
638
-
639
646
this . _renderer . enterDrawRegion ( this . _toBufferDrawRegionId ) ;
640
647
641
648
// Sample the framebuffer's pixels into the silhouette instance
642
- const skinPixels = new Uint8Array ( Math . floor ( this . _canvas . width * this . _canvas . height * 4 ) ) ;
643
- gl . readPixels ( 0 , 0 , this . _canvas . width , this . _canvas . height , gl . RGBA , gl . UNSIGNED_BYTE , skinPixels ) ;
644
-
645
- const skinCanvas = this . _canvas ;
646
- skinCanvas . width = bounds . width ;
647
- skinCanvas . height = bounds . height ;
648
-
649
- const skinContext = skinCanvas . getContext ( '2d' ) ;
650
- const skinImageData = skinContext . createImageData ( bounds . width , bounds . height ) ;
651
- skinImageData . data . set ( skinPixels ) ;
652
- skinContext . putImageData ( skinImageData , 0 , 0 ) ;
653
-
654
- this . _silhouette . update ( this . _canvas , true /* isPremultiplied */ ) ;
649
+ gl . readPixels (
650
+ 0 , 0 ,
651
+ this . _canvas . width , this . _canvas . height ,
652
+ gl . RGBA , gl . UNSIGNED_BYTE , this . _silhouettePixels
653
+ ) ;
654
+
655
+ this . _silhouetteImageData . data . set ( this . _silhouettePixels ) ;
656
+ this . _silhouette . update ( this . _silhouetteImageData , true /* isPremultiplied */ ) ;
655
657
656
658
this . _silhouetteDirty = false ;
657
659
}
0 commit comments