@@ -68,6 +68,12 @@ class PenSkin extends Skin {
68
68
exit : ( ) => this . _exitDrawLineOnBuffer ( )
69
69
} ;
70
70
71
+ /** @type {object } */
72
+ this . _usePenBufferDrawRegionId = {
73
+ enter : ( ) => this . _enterUsePenBuffer ( ) ,
74
+ exit : ( ) => this . _exitUsePenBuffer ( )
75
+ } ;
76
+
71
77
/** @type {twgl.BufferInfo } */
72
78
this . _lineBufferInfo = twgl . createBufferInfoFromArrays ( this . _renderer . gl , {
73
79
a_position : {
@@ -130,10 +136,10 @@ class PenSkin extends Skin {
130
136
* Clear the pen layer.
131
137
*/
132
138
clear ( ) {
133
- const gl = this . _renderer . gl ;
134
- twgl . bindFramebufferInfo ( gl , this . _framebuffer ) ;
139
+ this . _renderer . enterDrawRegion ( this . _usePenBufferDrawRegionId ) ;
135
140
136
141
/* Reset framebuffer to transparent black */
142
+ const gl = this . _renderer . gl ;
137
143
gl . clearColor ( 0 , 0 , 0 , 0 ) ;
138
144
gl . clear ( gl . COLOR_BUFFER_BIT ) ;
139
145
@@ -204,6 +210,20 @@ class PenSkin extends Skin {
204
210
twgl . bindFramebufferInfo ( gl , null ) ;
205
211
}
206
212
213
+ /**
214
+ * Prepare to do things with this PenSkin's framebuffer
215
+ */
216
+ _enterUsePenBuffer ( ) {
217
+ twgl . bindFramebufferInfo ( this . _renderer . gl , this . _framebuffer ) ;
218
+ }
219
+
220
+ /**
221
+ * Return to a base state
222
+ */
223
+ _exitUsePenBuffer ( ) {
224
+ twgl . bindFramebufferInfo ( this . _renderer . gl , null ) ;
225
+ }
226
+
207
227
/**
208
228
* Draw a line on the framebuffer.
209
229
* Note that the point coordinates are in the following coordinate space:
@@ -311,9 +331,9 @@ class PenSkin extends Skin {
311
331
*/
312
332
updateSilhouette ( ) {
313
333
if ( this . _silhouetteDirty ) {
334
+ this . _renderer . enterDrawRegion ( this . _usePenBufferDrawRegionId ) ;
314
335
// Sample the framebuffer's pixels into the silhouette instance
315
336
const gl = this . _renderer . gl ;
316
- twgl . bindFramebufferInfo ( gl , this . _framebuffer ) ;
317
337
gl . readPixels (
318
338
0 , 0 ,
319
339
this . _size [ 0 ] , this . _size [ 1 ] ,
0 commit comments