Skip to content

Commit 76cf67e

Browse files
committed
Merge branch 'faster-pen' into webgl2-only
2 parents 92cfe2d + 368cd4d commit 76cf67e

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

src/PenSkin.js

+9-15
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
// WebGL2 has native instanced rendering
101105
this.instancedRendering = true;
@@ -107,7 +111,7 @@ class PenSkin extends Skin {
107111
const instancedArraysExtension = gl.getExtension('ANGLE_instanced_arrays');
108112
if (instancedArraysExtension) {
109113
this.instancedRendering = true;
110-
this.glDrawArraysInstanced = instancedArraysExtension.drawElementsInstancedANGLE.bind(
114+
this.glDrawArraysInstanced = instancedArraysExtension.drawArraysInstancedANGLE.bind(
111115
instancedArraysExtension
112116
);
113117
this.glVertexAttribDivisor = instancedArraysExtension.vertexAttribDivisorANGLE.bind(
@@ -125,14 +129,8 @@ class PenSkin extends Skin {
125129
1, 0,
126130
0, 0,
127131
1, 1,
128-
1, 1,
129-
0, 0,
130132
0, 1
131133
]), gl.STATIC_DRAW);
132-
133-
this.attribute_data = new Float32Array(PEN_ATTRIBUTE_BUFFER_SIZE);
134-
gl.bindBuffer(gl.ARRAY_BUFFER, this.attribute_glbuffer);
135-
gl.bufferData(gl.ARRAY_BUFFER, this.attribute_data.length * 4, gl.STREAM_DRAW);
136134
} else {
137135
const positionBuffer = new Float32Array(PEN_ATTRIBUTE_BUFFER_SIZE / PEN_ATTRIBUTE_STRIDE * 2);
138136
for (let i = 0; i < positionBuffer.length; i += 12) {
@@ -151,10 +149,6 @@ class PenSkin extends Skin {
151149
}
152150
gl.bindBuffer(gl.ARRAY_BUFFER, this.a_position_glbuffer);
153151
gl.bufferData(gl.ARRAY_BUFFER, positionBuffer, gl.STATIC_DRAW);
154-
155-
this.attribute_data = new Float32Array(PEN_ATTRIBUTE_BUFFER_SIZE);
156-
gl.bindBuffer(gl.ARRAY_BUFFER, this.attribute_glbuffer);
157-
gl.bufferData(gl.ARRAY_BUFFER, this.attribute_data.length * 4, gl.STREAM_DRAW);
158152
}
159153

160154
this.onNativeSizeChanged = this.onNativeSizeChanged.bind(this);
@@ -444,8 +438,8 @@ class PenSkin extends Skin {
444438
this.glVertexAttribDivisor(this.a_penPoints_loc, 1);
445439

446440
this.glDrawArraysInstanced(
447-
gl.TRIANGLES,
448-
0, 6,
441+
gl.TRIANGLE_STRIP,
442+
0, 4,
449443
this.attribute_index / PEN_ATTRIBUTE_STRIDE
450444
);
451445

0 commit comments

Comments
 (0)