@vectojs/core 1.23.0 → 1.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-UPULSLKA.mjs → chunk-I4WQY7CJ.mjs} +178 -94
- package/dist/{chunk-LHONR3GO.js → chunk-KHGHP2J3.js} +178 -94
- package/dist/{chunk-FRMLD4PP.mjs → chunk-MVFPN4Y5.mjs} +114 -1
- package/dist/{chunk-AGP4VLF4.js → chunk-Z3HFY75R.js} +131 -18
- package/dist/index.d.ts +1 -0
- package/dist/index.js +481 -268
- package/dist/index.mjs +234 -21
- package/dist/performance/UserTiming.d.ts +44 -0
- package/dist/renderer.js +2 -2
- package/dist/renderer.mjs +1 -1
- package/dist/text/MSDFTextEntity.d.ts +24 -0
- package/dist/text/SVGEntity.d.ts +24 -0
- package/dist/text.js +2 -2
- package/dist/text.mjs +1 -1
- package/dist/tree/Scene.d.ts +49 -1
- package/package.json +7 -6
|
@@ -922,10 +922,11 @@ var FLOATS_PER_POINT = 7;
|
|
|
922
922
|
var POINT_STRIDE = FLOATS_PER_POINT * 4;
|
|
923
923
|
var VERTS_PER_QUAD = 4;
|
|
924
924
|
var INDICES_PER_QUAD = 6;
|
|
925
|
-
var
|
|
926
|
-
var
|
|
927
|
-
var
|
|
928
|
-
var
|
|
925
|
+
var PACKED_QUAD_VERT_STRIDE = 16;
|
|
926
|
+
var PACKED_RECT_VERT_STRIDE = 12;
|
|
927
|
+
var PACKED_UV_OFFSET = 8;
|
|
928
|
+
var PACKED_TINT_OFFSET = 12;
|
|
929
|
+
var PACKED_RECT_TINT_OFFSET = 8;
|
|
929
930
|
function buildQuadIndices(quads) {
|
|
930
931
|
const out = new Uint32Array(quads * INDICES_PER_QUAD);
|
|
931
932
|
for (let i = 0; i < quads; i++) {
|
|
@@ -940,6 +941,35 @@ function buildQuadIndices(quads) {
|
|
|
940
941
|
}
|
|
941
942
|
return out;
|
|
942
943
|
}
|
|
944
|
+
function encodeUnorm(v, max) {
|
|
945
|
+
return v <= 0 ? 0 : v >= 1 ? max : v * max + 0.5 | 0;
|
|
946
|
+
}
|
|
947
|
+
var LITTLE_ENDIAN = new Uint8Array(new Uint32Array([1]).buffer)[0] === 1;
|
|
948
|
+
function packTint(r, g, b, a) {
|
|
949
|
+
const ri = encodeUnorm(r, 255);
|
|
950
|
+
const gi = encodeUnorm(g, 255);
|
|
951
|
+
const bi = encodeUnorm(b, 255);
|
|
952
|
+
const ai = encodeUnorm(a, 255);
|
|
953
|
+
return LITTLE_ENDIAN ? ai << 24 | bi << 16 | gi << 8 | ri : ri << 24 | gi << 16 | bi << 8 | ai;
|
|
954
|
+
}
|
|
955
|
+
function createPackedBuffer(byteLength) {
|
|
956
|
+
const bytes = new ArrayBuffer(byteLength);
|
|
957
|
+
return {
|
|
958
|
+
bytes,
|
|
959
|
+
f32: new Float32Array(bytes),
|
|
960
|
+
u16: new Uint16Array(bytes),
|
|
961
|
+
u32: new Uint32Array(bytes),
|
|
962
|
+
u8: new Uint8Array(bytes)
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
function growPacked(buf, neededBytes) {
|
|
966
|
+
if (neededBytes <= buf.bytes.byteLength) return buf;
|
|
967
|
+
let cap = buf.bytes.byteLength;
|
|
968
|
+
while (cap < neededBytes) cap *= 2;
|
|
969
|
+
const grown = createPackedBuffer(cap);
|
|
970
|
+
grown.u8.set(buf.u8);
|
|
971
|
+
return grown;
|
|
972
|
+
}
|
|
943
973
|
var POINT_VERT = `#version 300 es
|
|
944
974
|
in vec2 a_pos;
|
|
945
975
|
in float a_radius;
|
|
@@ -1067,7 +1097,7 @@ function link(gl, vsSrc, fsSrc) {
|
|
|
1067
1097
|
}
|
|
1068
1098
|
return program;
|
|
1069
1099
|
}
|
|
1070
|
-
function writeQuad(out,
|
|
1100
|
+
function writeQuad(out, byteOffset, x, y, width, height, u0, v0, u1, v1, r, g, b, al, rotation) {
|
|
1071
1101
|
let x1;
|
|
1072
1102
|
let y1;
|
|
1073
1103
|
let x2;
|
|
@@ -1095,40 +1125,39 @@ function writeQuad(out, o, x, y, width, height, u0, v0, u1, v1, r, g, b, al, rot
|
|
|
1095
1125
|
x3 = x - hs;
|
|
1096
1126
|
y3 = y + hc;
|
|
1097
1127
|
}
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
out[o + 31] = al;
|
|
1128
|
+
const iu0 = encodeUnorm(u0, 65535);
|
|
1129
|
+
const iv0 = encodeUnorm(v0, 65535);
|
|
1130
|
+
const iu1 = encodeUnorm(u1, 65535);
|
|
1131
|
+
const iv1 = encodeUnorm(v1, 65535);
|
|
1132
|
+
const tint = packTint(r, g, b, al);
|
|
1133
|
+
const f32 = out.f32;
|
|
1134
|
+
const u16 = out.u16;
|
|
1135
|
+
const u32 = out.u32;
|
|
1136
|
+
const fi = byteOffset >> 2;
|
|
1137
|
+
const si = byteOffset + PACKED_UV_OFFSET >> 1;
|
|
1138
|
+
const ti = byteOffset + PACKED_TINT_OFFSET >> 2;
|
|
1139
|
+
f32[fi] = x;
|
|
1140
|
+
f32[fi + 1] = y;
|
|
1141
|
+
u16[si] = iu0;
|
|
1142
|
+
u16[si + 1] = iv0;
|
|
1143
|
+
u32[ti] = tint;
|
|
1144
|
+
f32[fi + 4] = x1;
|
|
1145
|
+
f32[fi + 5] = y1;
|
|
1146
|
+
u16[si + 8] = iu1;
|
|
1147
|
+
u16[si + 9] = iv0;
|
|
1148
|
+
u32[ti + 4] = tint;
|
|
1149
|
+
f32[fi + 8] = x2;
|
|
1150
|
+
f32[fi + 9] = y2;
|
|
1151
|
+
u16[si + 16] = iu1;
|
|
1152
|
+
u16[si + 17] = iv1;
|
|
1153
|
+
u32[ti + 8] = tint;
|
|
1154
|
+
f32[fi + 12] = x3;
|
|
1155
|
+
f32[fi + 13] = y3;
|
|
1156
|
+
u16[si + 24] = iu0;
|
|
1157
|
+
u16[si + 25] = iv1;
|
|
1158
|
+
u32[ti + 12] = tint;
|
|
1130
1159
|
}
|
|
1131
|
-
function writeRectQuad(out,
|
|
1160
|
+
function writeRectQuad(out, byteOffset, x, y, width, height, r, g, b, al, rotation) {
|
|
1132
1161
|
let x1;
|
|
1133
1162
|
let y1;
|
|
1134
1163
|
let x2;
|
|
@@ -1156,30 +1185,22 @@ function writeRectQuad(out, o, x, y, width, height, r, g, b, al, rotation) {
|
|
|
1156
1185
|
x3 = x - hs;
|
|
1157
1186
|
y3 = y + hc;
|
|
1158
1187
|
}
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
out[o + 16] = b;
|
|
1176
|
-
out[o + 17] = al;
|
|
1177
|
-
out[o + 18] = x3;
|
|
1178
|
-
out[o + 19] = y3;
|
|
1179
|
-
out[o + 20] = r;
|
|
1180
|
-
out[o + 21] = g;
|
|
1181
|
-
out[o + 22] = b;
|
|
1182
|
-
out[o + 23] = al;
|
|
1188
|
+
const tint = packTint(r, g, b, al);
|
|
1189
|
+
const f32 = out.f32;
|
|
1190
|
+
const u32 = out.u32;
|
|
1191
|
+
const fi = byteOffset >> 2;
|
|
1192
|
+
f32[fi] = x;
|
|
1193
|
+
f32[fi + 1] = y;
|
|
1194
|
+
u32[fi + 2] = tint;
|
|
1195
|
+
f32[fi + 3] = x1;
|
|
1196
|
+
f32[fi + 4] = y1;
|
|
1197
|
+
u32[fi + 5] = tint;
|
|
1198
|
+
f32[fi + 6] = x2;
|
|
1199
|
+
f32[fi + 7] = y2;
|
|
1200
|
+
u32[fi + 8] = tint;
|
|
1201
|
+
f32[fi + 9] = x3;
|
|
1202
|
+
f32[fi + 10] = y3;
|
|
1203
|
+
u32[fi + 11] = tint;
|
|
1183
1204
|
}
|
|
1184
1205
|
function grow(data, needed) {
|
|
1185
1206
|
if (needed <= data.length) return data;
|
|
@@ -1189,6 +1210,16 @@ function grow(data, needed) {
|
|
|
1189
1210
|
grown.set(data);
|
|
1190
1211
|
return grown;
|
|
1191
1212
|
}
|
|
1213
|
+
function isSourceReady(source) {
|
|
1214
|
+
const candidate = source;
|
|
1215
|
+
if (typeof candidate.complete === "boolean") {
|
|
1216
|
+
if (!candidate.complete) return false;
|
|
1217
|
+
if (typeof candidate.naturalWidth === "number" && candidate.naturalWidth === 0) return false;
|
|
1218
|
+
return true;
|
|
1219
|
+
}
|
|
1220
|
+
if (typeof candidate.readyState === "number") return candidate.readyState >= 2;
|
|
1221
|
+
return true;
|
|
1222
|
+
}
|
|
1192
1223
|
function createWebGLPointRenderer(canvas) {
|
|
1193
1224
|
const gl = canvas.getContext("webgl2", {
|
|
1194
1225
|
premultipliedAlpha: false
|
|
@@ -1226,9 +1257,16 @@ function createWebGLPointRenderer(canvas) {
|
|
|
1226
1257
|
gl.bindVertexArray(rectVAO);
|
|
1227
1258
|
gl.bindBuffer(gl.ARRAY_BUFFER, rectBuffer);
|
|
1228
1259
|
gl.enableVertexAttribArray(rAPos);
|
|
1229
|
-
gl.vertexAttribPointer(rAPos, 2, gl.FLOAT, false,
|
|
1260
|
+
gl.vertexAttribPointer(rAPos, 2, gl.FLOAT, false, PACKED_RECT_VERT_STRIDE, 0);
|
|
1230
1261
|
gl.enableVertexAttribArray(rAColor);
|
|
1231
|
-
gl.vertexAttribPointer(
|
|
1262
|
+
gl.vertexAttribPointer(
|
|
1263
|
+
rAColor,
|
|
1264
|
+
4,
|
|
1265
|
+
gl.UNSIGNED_BYTE,
|
|
1266
|
+
true,
|
|
1267
|
+
PACKED_RECT_VERT_STRIDE,
|
|
1268
|
+
PACKED_RECT_TINT_OFFSET
|
|
1269
|
+
);
|
|
1232
1270
|
const sAPos = gl.getAttribLocation(spriteProgram, "a_pos");
|
|
1233
1271
|
const sAUv = gl.getAttribLocation(spriteProgram, "a_uv");
|
|
1234
1272
|
const sATint = gl.getAttribLocation(spriteProgram, "a_tint");
|
|
@@ -1239,11 +1277,25 @@ function createWebGLPointRenderer(canvas) {
|
|
|
1239
1277
|
gl.bindVertexArray(spriteVAO);
|
|
1240
1278
|
gl.bindBuffer(gl.ARRAY_BUFFER, spriteBuffer);
|
|
1241
1279
|
gl.enableVertexAttribArray(sAPos);
|
|
1242
|
-
gl.vertexAttribPointer(sAPos, 2, gl.FLOAT, false,
|
|
1280
|
+
gl.vertexAttribPointer(sAPos, 2, gl.FLOAT, false, PACKED_QUAD_VERT_STRIDE, 0);
|
|
1243
1281
|
gl.enableVertexAttribArray(sAUv);
|
|
1244
|
-
gl.vertexAttribPointer(
|
|
1282
|
+
gl.vertexAttribPointer(
|
|
1283
|
+
sAUv,
|
|
1284
|
+
2,
|
|
1285
|
+
gl.UNSIGNED_SHORT,
|
|
1286
|
+
true,
|
|
1287
|
+
PACKED_QUAD_VERT_STRIDE,
|
|
1288
|
+
PACKED_UV_OFFSET
|
|
1289
|
+
);
|
|
1245
1290
|
gl.enableVertexAttribArray(sATint);
|
|
1246
|
-
gl.vertexAttribPointer(
|
|
1291
|
+
gl.vertexAttribPointer(
|
|
1292
|
+
sATint,
|
|
1293
|
+
4,
|
|
1294
|
+
gl.UNSIGNED_BYTE,
|
|
1295
|
+
true,
|
|
1296
|
+
PACKED_QUAD_VERT_STRIDE,
|
|
1297
|
+
PACKED_TINT_OFFSET
|
|
1298
|
+
);
|
|
1247
1299
|
const gAPos = gl.getAttribLocation(msdfProgram, "a_pos");
|
|
1248
1300
|
const gAUv = gl.getAttribLocation(msdfProgram, "a_uv");
|
|
1249
1301
|
const gATint = gl.getAttribLocation(msdfProgram, "a_tint");
|
|
@@ -1255,11 +1307,25 @@ function createWebGLPointRenderer(canvas) {
|
|
|
1255
1307
|
gl.bindVertexArray(glyphVAO);
|
|
1256
1308
|
gl.bindBuffer(gl.ARRAY_BUFFER, glyphBuffer);
|
|
1257
1309
|
gl.enableVertexAttribArray(gAPos);
|
|
1258
|
-
gl.vertexAttribPointer(gAPos, 2, gl.FLOAT, false,
|
|
1310
|
+
gl.vertexAttribPointer(gAPos, 2, gl.FLOAT, false, PACKED_QUAD_VERT_STRIDE, 0);
|
|
1259
1311
|
gl.enableVertexAttribArray(gAUv);
|
|
1260
|
-
gl.vertexAttribPointer(
|
|
1312
|
+
gl.vertexAttribPointer(
|
|
1313
|
+
gAUv,
|
|
1314
|
+
2,
|
|
1315
|
+
gl.UNSIGNED_SHORT,
|
|
1316
|
+
true,
|
|
1317
|
+
PACKED_QUAD_VERT_STRIDE,
|
|
1318
|
+
PACKED_UV_OFFSET
|
|
1319
|
+
);
|
|
1261
1320
|
gl.enableVertexAttribArray(gATint);
|
|
1262
|
-
gl.vertexAttribPointer(
|
|
1321
|
+
gl.vertexAttribPointer(
|
|
1322
|
+
gATint,
|
|
1323
|
+
4,
|
|
1324
|
+
gl.UNSIGNED_BYTE,
|
|
1325
|
+
true,
|
|
1326
|
+
PACKED_QUAD_VERT_STRIDE,
|
|
1327
|
+
PACKED_TINT_OFFSET
|
|
1328
|
+
);
|
|
1263
1329
|
const cAPos = gl.getAttribLocation(circleQuadProgram, "a_pos");
|
|
1264
1330
|
const cAUv = gl.getAttribLocation(circleQuadProgram, "a_uv");
|
|
1265
1331
|
const cATint = gl.getAttribLocation(circleQuadProgram, "a_tint");
|
|
@@ -1269,11 +1335,25 @@ function createWebGLPointRenderer(canvas) {
|
|
|
1269
1335
|
gl.bindVertexArray(circleQuadVAO);
|
|
1270
1336
|
gl.bindBuffer(gl.ARRAY_BUFFER, circleQuadBuffer);
|
|
1271
1337
|
gl.enableVertexAttribArray(cAPos);
|
|
1272
|
-
gl.vertexAttribPointer(cAPos, 2, gl.FLOAT, false,
|
|
1338
|
+
gl.vertexAttribPointer(cAPos, 2, gl.FLOAT, false, PACKED_QUAD_VERT_STRIDE, 0);
|
|
1273
1339
|
gl.enableVertexAttribArray(cAUv);
|
|
1274
|
-
gl.vertexAttribPointer(
|
|
1340
|
+
gl.vertexAttribPointer(
|
|
1341
|
+
cAUv,
|
|
1342
|
+
2,
|
|
1343
|
+
gl.UNSIGNED_SHORT,
|
|
1344
|
+
true,
|
|
1345
|
+
PACKED_QUAD_VERT_STRIDE,
|
|
1346
|
+
PACKED_UV_OFFSET
|
|
1347
|
+
);
|
|
1275
1348
|
gl.enableVertexAttribArray(cATint);
|
|
1276
|
-
gl.vertexAttribPointer(
|
|
1349
|
+
gl.vertexAttribPointer(
|
|
1350
|
+
cATint,
|
|
1351
|
+
4,
|
|
1352
|
+
gl.UNSIGNED_BYTE,
|
|
1353
|
+
true,
|
|
1354
|
+
PACKED_QUAD_VERT_STRIDE,
|
|
1355
|
+
PACKED_TINT_OFFSET
|
|
1356
|
+
);
|
|
1277
1357
|
gl.bindVertexArray(null);
|
|
1278
1358
|
const quadIndexBuffer = gl.createBuffer();
|
|
1279
1359
|
let quadIndexCapacity = 0;
|
|
@@ -1283,7 +1363,6 @@ function createWebGLPointRenderer(canvas) {
|
|
|
1283
1363
|
while (cap < quads) cap *= 2;
|
|
1284
1364
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, quadIndexBuffer);
|
|
1285
1365
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, buildQuadIndices(cap), gl.STATIC_DRAW);
|
|
1286
|
-
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
1287
1366
|
quadIndexCapacity = cap;
|
|
1288
1367
|
};
|
|
1289
1368
|
for (const vao of [rectVAO, spriteVAO, glyphVAO, circleQuadVAO]) {
|
|
@@ -1298,11 +1377,11 @@ function createWebGLPointRenderer(canvas) {
|
|
|
1298
1377
|
let distanceRange = 4;
|
|
1299
1378
|
let pointData = new Float32Array(FLOATS_PER_POINT * 1024);
|
|
1300
1379
|
let pointCount = 0;
|
|
1301
|
-
let rectData =
|
|
1380
|
+
let rectData = createPackedBuffer(PACKED_RECT_VERT_STRIDE * VERTS_PER_QUAD * 256);
|
|
1302
1381
|
let rectCount = 0;
|
|
1303
|
-
let spriteData =
|
|
1382
|
+
let spriteData = createPackedBuffer(PACKED_QUAD_VERT_STRIDE * VERTS_PER_QUAD * 256);
|
|
1304
1383
|
let spriteCount = 0;
|
|
1305
|
-
let glyphData =
|
|
1384
|
+
let glyphData = createPackedBuffer(PACKED_QUAD_VERT_STRIDE * VERTS_PER_QUAD * 1024);
|
|
1306
1385
|
let glyphCount = 0;
|
|
1307
1386
|
let frameDrawCalls = 0;
|
|
1308
1387
|
let lastFrameDrawCalls = 0;
|
|
@@ -1310,7 +1389,7 @@ function createWebGLPointRenderer(canvas) {
|
|
|
1310
1389
|
let atlasSwitches = 0;
|
|
1311
1390
|
let circleQuadFallbacks = 0;
|
|
1312
1391
|
let circlePoints = 0;
|
|
1313
|
-
let circleQuadData =
|
|
1392
|
+
let circleQuadData = createPackedBuffer(PACKED_QUAD_VERT_STRIDE * VERTS_PER_QUAD * 64);
|
|
1314
1393
|
let circleQuadCount = 0;
|
|
1315
1394
|
let logicalW = 0;
|
|
1316
1395
|
let logicalH = 0;
|
|
@@ -1320,11 +1399,11 @@ function createWebGLPointRenderer(canvas) {
|
|
|
1320
1399
|
const maxPointSize = pointSizeRange ? pointSizeRange[1] : Infinity;
|
|
1321
1400
|
const drawGlyphs = () => {
|
|
1322
1401
|
if (glyphCount === 0 || !msdfTexture) return;
|
|
1323
|
-
const
|
|
1402
|
+
const bytes = glyphCount * VERTS_PER_QUAD * PACKED_QUAD_VERT_STRIDE;
|
|
1324
1403
|
gl.useProgram(msdfProgram);
|
|
1325
1404
|
gl.bindVertexArray(glyphVAO);
|
|
1326
1405
|
gl.bindBuffer(gl.ARRAY_BUFFER, glyphBuffer);
|
|
1327
|
-
gl.bufferData(gl.ARRAY_BUFFER, glyphData.subarray(0,
|
|
1406
|
+
gl.bufferData(gl.ARRAY_BUFFER, glyphData.u8.subarray(0, bytes), gl.DYNAMIC_DRAW);
|
|
1328
1407
|
gl.activeTexture(gl.TEXTURE0);
|
|
1329
1408
|
gl.bindTexture(gl.TEXTURE_2D, msdfTexture);
|
|
1330
1409
|
gl.uniform1i(gUTex, 0);
|
|
@@ -1376,6 +1455,7 @@ function createWebGLPointRenderer(canvas) {
|
|
|
1376
1455
|
},
|
|
1377
1456
|
setTexture(source) {
|
|
1378
1457
|
if (source === textureSource && texture) return;
|
|
1458
|
+
if (!isSourceReady(source)) return;
|
|
1379
1459
|
if (!texture) {
|
|
1380
1460
|
texture = gl.createTexture();
|
|
1381
1461
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
@@ -1391,8 +1471,8 @@ function createWebGLPointRenderer(canvas) {
|
|
|
1391
1471
|
},
|
|
1392
1472
|
addSprite(x, y, width, height, u0, v0, u1, v1, color = "#ffffff", alpha = 1, rotation = 0) {
|
|
1393
1473
|
if (!texture) return;
|
|
1394
|
-
const stride =
|
|
1395
|
-
spriteData =
|
|
1474
|
+
const stride = PACKED_QUAD_VERT_STRIDE * VERTS_PER_QUAD;
|
|
1475
|
+
spriteData = growPacked(spriteData, (spriteCount + 1) * stride);
|
|
1396
1476
|
const rgba = parseColorToRGBA(color);
|
|
1397
1477
|
writeQuad(
|
|
1398
1478
|
spriteData,
|
|
@@ -1418,6 +1498,10 @@ function createWebGLPointRenderer(canvas) {
|
|
|
1418
1498
|
distanceRange = range;
|
|
1419
1499
|
return;
|
|
1420
1500
|
}
|
|
1501
|
+
if (!isSourceReady(source)) {
|
|
1502
|
+
distanceRange = range;
|
|
1503
|
+
return;
|
|
1504
|
+
}
|
|
1421
1505
|
atlasSwitches++;
|
|
1422
1506
|
drawGlyphs();
|
|
1423
1507
|
distanceRange = range;
|
|
@@ -1436,8 +1520,8 @@ function createWebGLPointRenderer(canvas) {
|
|
|
1436
1520
|
},
|
|
1437
1521
|
addGlyph(x, y, width, height, u0, v0, u1, v1, color = "#ffffff", alpha = 1, rotation = 0) {
|
|
1438
1522
|
if (!msdfTexture) return;
|
|
1439
|
-
const stride =
|
|
1440
|
-
glyphData =
|
|
1523
|
+
const stride = PACKED_QUAD_VERT_STRIDE * VERTS_PER_QUAD;
|
|
1524
|
+
glyphData = growPacked(glyphData, (glyphCount + 1) * stride);
|
|
1441
1525
|
const rgba = parseColorToRGBA(color);
|
|
1442
1526
|
writeQuad(
|
|
1443
1527
|
glyphData,
|
|
@@ -1462,8 +1546,8 @@ function createWebGLPointRenderer(canvas) {
|
|
|
1462
1546
|
const needsQuad = logicalW > 0 && (x < radius || y < radius || x > logicalW - radius || y > logicalH - radius) || radius * 2 * dpr > maxPointSize;
|
|
1463
1547
|
if (needsQuad) {
|
|
1464
1548
|
circleQuadFallbacks++;
|
|
1465
|
-
const stride =
|
|
1466
|
-
circleQuadData =
|
|
1549
|
+
const stride = PACKED_QUAD_VERT_STRIDE * VERTS_PER_QUAD;
|
|
1550
|
+
circleQuadData = growPacked(circleQuadData, (circleQuadCount + 1) * stride);
|
|
1467
1551
|
const rgba = parseColorToRGBA(color);
|
|
1468
1552
|
const d = radius * 2;
|
|
1469
1553
|
writeQuad(
|
|
@@ -1500,8 +1584,8 @@ function createWebGLPointRenderer(canvas) {
|
|
|
1500
1584
|
pointCount++;
|
|
1501
1585
|
},
|
|
1502
1586
|
addRect(x, y, width, height, color, alpha = 1, rotation = 0) {
|
|
1503
|
-
const stride =
|
|
1504
|
-
rectData =
|
|
1587
|
+
const stride = PACKED_RECT_VERT_STRIDE * VERTS_PER_QUAD;
|
|
1588
|
+
rectData = growPacked(rectData, (rectCount + 1) * stride);
|
|
1505
1589
|
const rgba = parseColorToRGBA(color);
|
|
1506
1590
|
writeRectQuad(
|
|
1507
1591
|
rectData,
|
|
@@ -1520,11 +1604,11 @@ function createWebGLPointRenderer(canvas) {
|
|
|
1520
1604
|
},
|
|
1521
1605
|
flush() {
|
|
1522
1606
|
if (rectCount > 0) {
|
|
1523
|
-
const
|
|
1607
|
+
const bytes = rectCount * VERTS_PER_QUAD * PACKED_RECT_VERT_STRIDE;
|
|
1524
1608
|
gl.useProgram(rectProgram);
|
|
1525
1609
|
gl.bindVertexArray(rectVAO);
|
|
1526
1610
|
gl.bindBuffer(gl.ARRAY_BUFFER, rectBuffer);
|
|
1527
|
-
gl.bufferData(gl.ARRAY_BUFFER, rectData.subarray(0,
|
|
1611
|
+
gl.bufferData(gl.ARRAY_BUFFER, rectData.u8.subarray(0, bytes), gl.DYNAMIC_DRAW);
|
|
1528
1612
|
gl.uniform2f(rURes, logicalW, logicalH);
|
|
1529
1613
|
ensureQuadIndices(rectCount);
|
|
1530
1614
|
gl.drawElements(gl.TRIANGLES, rectCount * INDICES_PER_QUAD, gl.UNSIGNED_INT, 0);
|
|
@@ -1545,22 +1629,22 @@ function createWebGLPointRenderer(canvas) {
|
|
|
1545
1629
|
frameDrawCalls++;
|
|
1546
1630
|
}
|
|
1547
1631
|
if (circleQuadCount > 0) {
|
|
1548
|
-
const
|
|
1632
|
+
const bytes = circleQuadCount * VERTS_PER_QUAD * PACKED_QUAD_VERT_STRIDE;
|
|
1549
1633
|
gl.useProgram(circleQuadProgram);
|
|
1550
1634
|
gl.bindVertexArray(circleQuadVAO);
|
|
1551
1635
|
gl.bindBuffer(gl.ARRAY_BUFFER, circleQuadBuffer);
|
|
1552
|
-
gl.bufferData(gl.ARRAY_BUFFER, circleQuadData.subarray(0,
|
|
1636
|
+
gl.bufferData(gl.ARRAY_BUFFER, circleQuadData.u8.subarray(0, bytes), gl.DYNAMIC_DRAW);
|
|
1553
1637
|
gl.uniform2f(cURes, logicalW, logicalH);
|
|
1554
1638
|
ensureQuadIndices(circleQuadCount);
|
|
1555
1639
|
gl.drawElements(gl.TRIANGLES, circleQuadCount * INDICES_PER_QUAD, gl.UNSIGNED_INT, 0);
|
|
1556
1640
|
frameDrawCalls++;
|
|
1557
1641
|
}
|
|
1558
1642
|
if (spriteCount > 0 && texture) {
|
|
1559
|
-
const
|
|
1643
|
+
const bytes = spriteCount * VERTS_PER_QUAD * PACKED_QUAD_VERT_STRIDE;
|
|
1560
1644
|
gl.useProgram(spriteProgram);
|
|
1561
1645
|
gl.bindVertexArray(spriteVAO);
|
|
1562
1646
|
gl.bindBuffer(gl.ARRAY_BUFFER, spriteBuffer);
|
|
1563
|
-
gl.bufferData(gl.ARRAY_BUFFER, spriteData.subarray(0,
|
|
1647
|
+
gl.bufferData(gl.ARRAY_BUFFER, spriteData.u8.subarray(0, bytes), gl.DYNAMIC_DRAW);
|
|
1564
1648
|
gl.activeTexture(gl.TEXTURE0);
|
|
1565
1649
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
1566
1650
|
gl.uniform1i(sUTex, 0);
|