Skip to content

Commit 205a8c9

Browse files
committed
Use draw region for accessing pen framebuffer
1 parent 8ac7ed2 commit 205a8c9

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/PenSkin.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ class PenSkin extends Skin {
6868
exit: () => this._exitDrawLineOnBuffer()
6969
};
7070

71+
/** @type {object} */
72+
this._usePenBufferDrawRegionId = {
73+
enter: () => this._enterUsePenBuffer(),
74+
exit: () => this._exitUsePenBuffer()
75+
};
76+
7177
/** @type {twgl.BufferInfo} */
7278
this._lineBufferInfo = twgl.createBufferInfoFromArrays(this._renderer.gl, {
7379
a_position: {
@@ -130,10 +136,10 @@ class PenSkin extends Skin {
130136
* Clear the pen layer.
131137
*/
132138
clear () {
133-
const gl = this._renderer.gl;
134-
twgl.bindFramebufferInfo(gl, this._framebuffer);
139+
this._renderer.enterDrawRegion(this._usePenBufferDrawRegionId);
135140

136141
/* Reset framebuffer to transparent black */
142+
const gl = this._renderer.gl;
137143
gl.clearColor(0, 0, 0, 0);
138144
gl.clear(gl.COLOR_BUFFER_BIT);
139145

@@ -204,6 +210,20 @@ class PenSkin extends Skin {
204210
twgl.bindFramebufferInfo(gl, null);
205211
}
206212

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+
207227
/**
208228
* Draw a line on the framebuffer.
209229
* Note that the point coordinates are in the following coordinate space:
@@ -311,9 +331,9 @@ class PenSkin extends Skin {
311331
*/
312332
updateSilhouette () {
313333
if (this._silhouetteDirty) {
334+
this._renderer.enterDrawRegion(this._usePenBufferDrawRegionId);
314335
// Sample the framebuffer's pixels into the silhouette instance
315336
const gl = this._renderer.gl;
316-
twgl.bindFramebufferInfo(gl, this._framebuffer);
317337
gl.readPixels(
318338
0, 0,
319339
this._size[0], this._size[1],

0 commit comments

Comments
 (0)