Skip to content

Commit fab4309

Browse files
committed
Merge branch 'faster-pen' into webgl1-angle
2 parents 86cfaec + 368cd4d commit fab4309

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/PenSkin.js

+8-14
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,16 @@ class PenSkin extends Skin {
9090
this.a_position_glbuffer = gl.createBuffer();
9191
this.a_position_loc = gl.getAttribLocation(this._lineShader.program, 'a_position');
9292

93-
this.attribute_glbuffer = gl.createBuffer();
94-
this.attribute_index = 0;
9593
this.a_lineColor_loc = gl.getAttribLocation(this._lineShader.program, 'a_lineColor');
9694
this.a_lineThicknessAndLength_loc = gl.getAttribLocation(this._lineShader.program, 'a_lineThicknessAndLength');
9795
this.a_penPoints_loc = gl.getAttribLocation(this._lineShader.program, 'a_penPoints');
9896

97+
this.attribute_glbuffer = gl.createBuffer();
98+
this.attribute_index = 0;
99+
this.attribute_data = new Float32Array(PEN_ATTRIBUTE_BUFFER_SIZE);
100+
gl.bindBuffer(gl.ARRAY_BUFFER, this.attribute_glbuffer);
101+
gl.bufferData(gl.ARRAY_BUFFER, this.attribute_data.length * 4, gl.STREAM_DRAW);
102+
99103
if (gl.drawArraysInstanced) {
100104
throw new Error('bad');
101105
// WebGL2 has native instanced rendering
@@ -126,14 +130,8 @@ class PenSkin extends Skin {
126130
1, 0,
127131
0, 0,
128132
1, 1,
129-
1, 1,
130-
0, 0,
131133
0, 1
132134
]), gl.STATIC_DRAW);
133-
134-
this.attribute_data = new Float32Array(PEN_ATTRIBUTE_BUFFER_SIZE);
135-
gl.bindBuffer(gl.ARRAY_BUFFER, this.attribute_glbuffer);
136-
gl.bufferData(gl.ARRAY_BUFFER, this.attribute_data.length * 4, gl.STREAM_DRAW);
137135
} else {
138136
const positionBuffer = new Float32Array(PEN_ATTRIBUTE_BUFFER_SIZE / PEN_ATTRIBUTE_STRIDE * 2);
139137
for (let i = 0; i < positionBuffer.length; i += 12) {
@@ -152,10 +150,6 @@ class PenSkin extends Skin {
152150
}
153151
gl.bindBuffer(gl.ARRAY_BUFFER, this.a_position_glbuffer);
154152
gl.bufferData(gl.ARRAY_BUFFER, positionBuffer, gl.STATIC_DRAW);
155-
156-
this.attribute_data = new Float32Array(PEN_ATTRIBUTE_BUFFER_SIZE);
157-
gl.bindBuffer(gl.ARRAY_BUFFER, this.attribute_glbuffer);
158-
gl.bufferData(gl.ARRAY_BUFFER, this.attribute_data.length * 4, gl.STREAM_DRAW);
159153
}
160154

161155
this.onNativeSizeChanged = this.onNativeSizeChanged.bind(this);
@@ -445,8 +439,8 @@ class PenSkin extends Skin {
445439
this.glVertexAttribDivisor(this.a_penPoints_loc, 1);
446440

447441
this.glDrawArraysInstanced(
448-
gl.TRIANGLES,
449-
0, 6,
442+
gl.TRIANGLE_STRIP,
443+
0, 4,
450444
this.attribute_index / PEN_ATTRIBUTE_STRIDE
451445
);
452446

0 commit comments

Comments
 (0)