rapid-render 1.0.10 → 1.0.11
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/README.md +1 -3
- package/dist/draw.d.ts +4 -0
- package/dist/matrix-engine.d.ts +2 -2
- package/dist/particle.d.ts +1 -1
- package/dist/rapid-render.js +295 -289
- package/dist/rapid-render.umd.cjs +11 -11
- package/dist/region/particleRegion.d.ts +1 -1
- package/dist/render.d.ts +1 -1
- package/package.json +1 -1
package/dist/rapid-render.js
CHANGED
|
@@ -172,7 +172,7 @@ class _ {
|
|
|
172
172
|
this.usedElemNum = 0;
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
|
-
class
|
|
175
|
+
class it extends _ {
|
|
176
176
|
/** The actual WebGLBuffer object maintained by this instance. */
|
|
177
177
|
buffer;
|
|
178
178
|
/** The related WebGL rendering context. */
|
|
@@ -480,7 +480,7 @@ class x {
|
|
|
480
480
|
static TRANSPARENT = new x(0, 0, 0, 0);
|
|
481
481
|
}
|
|
482
482
|
const E = 6;
|
|
483
|
-
class
|
|
483
|
+
class Ut {
|
|
484
484
|
/** Total number of matrices currently allocated in the store. */
|
|
485
485
|
matrixCount = 0;
|
|
486
486
|
/** The dynamic buffer used to hold matrix data. */
|
|
@@ -596,8 +596,8 @@ class wt {
|
|
|
596
596
|
* @param bIdx - The index of matrix B.
|
|
597
597
|
*/
|
|
598
598
|
multiplyOut(t, e, r) {
|
|
599
|
-
const i = t * E, s = e * E, a = r * E, o = this.data, h = o[s], c = o[s + 1], u = o[s + 2], l = o[s + 3], d = o[s + 4], f = o[s + 5], m = o[a],
|
|
600
|
-
o[i] = h * m + u *
|
|
599
|
+
const i = t * E, s = e * E, a = r * E, o = this.data, h = o[s], c = o[s + 1], u = o[s + 2], l = o[s + 3], d = o[s + 4], f = o[s + 5], m = o[a], v = o[a + 1], y = o[a + 2], T = o[a + 3], M = o[a + 4], A = o[a + 5];
|
|
600
|
+
o[i] = h * m + u * v, o[i + 1] = c * m + l * v, o[i + 2] = h * y + u * T, o[i + 3] = c * y + l * T, o[i + 4] = h * M + u * A + d, o[i + 5] = c * M + l * A + f;
|
|
601
601
|
}
|
|
602
602
|
/**
|
|
603
603
|
* Inverts the matrix at the given index. If the matrix is not invertible, it defaults to the identity matrix.
|
|
@@ -721,17 +721,17 @@ class wt {
|
|
|
721
721
|
i[r] = e[0], i[r + 1] = e[1], i[r + 2] = e[2], i[r + 3] = e[3], i[r + 4] = e[4], i[r + 5] = e[5];
|
|
722
722
|
}
|
|
723
723
|
multiplyAffineInPlace(t, e, r, i, s, a, o) {
|
|
724
|
-
const h = t * 6, c = this.data, u = c[h], l = c[h + 1], d = c[h + 2], f = c[h + 3], m = c[h + 4],
|
|
725
|
-
c[h] = u * e + d * r, c[h + 1] = l * e + f * r, c[h + 2] = u * i + d * s, c[h + 3] = l * i + f * s, c[h + 4] = u * a + d * o + m, c[h + 5] = l * a + f * o +
|
|
724
|
+
const h = t * 6, c = this.data, u = c[h], l = c[h + 1], d = c[h + 2], f = c[h + 3], m = c[h + 4], v = c[h + 5];
|
|
725
|
+
c[h] = u * e + d * r, c[h + 1] = l * e + f * r, c[h + 2] = u * i + d * s, c[h + 3] = l * i + f * s, c[h + 4] = u * a + d * o + m, c[h + 5] = l * a + f * o + v;
|
|
726
726
|
}
|
|
727
727
|
multiplyAffine(t, e, r, i, s, a, o, h) {
|
|
728
|
-
const c = t * 6, u = e * 6, l = this.data, d = l[c], f = l[c + 1], m = l[c + 2],
|
|
729
|
-
l[u] = d * r + m * i, l[u + 1] = f * r +
|
|
728
|
+
const c = t * 6, u = e * 6, l = this.data, d = l[c], f = l[c + 1], m = l[c + 2], v = l[c + 3], y = l[c + 4], T = l[c + 5];
|
|
729
|
+
l[u] = d * r + m * i, l[u + 1] = f * r + v * i, l[u + 2] = d * s + m * a, l[u + 3] = f * s + v * a, l[u + 4] = d * o + m * h + y, l[u + 5] = f * o + v * h + T;
|
|
730
730
|
}
|
|
731
731
|
}
|
|
732
|
-
class
|
|
732
|
+
class Ct {
|
|
733
733
|
/** The underlying store for matrices. */
|
|
734
|
-
matrix = new
|
|
734
|
+
matrix = new Ut();
|
|
735
735
|
/** The current step or depth in the transformation hierarchy. */
|
|
736
736
|
step = 0;
|
|
737
737
|
/** Internal stack maintaining structural information. */
|
|
@@ -740,7 +740,7 @@ class At {
|
|
|
740
740
|
stepWorldM = new _(b.Uint32);
|
|
741
741
|
/** Records actions (push/pop) taken during the traversal. */
|
|
742
742
|
stepAction = new _(b.Uint32);
|
|
743
|
-
/** Records the parent world matrix for each step (used by
|
|
743
|
+
/** Records the parent world matrix for each step (used by updateMatrixSubtree). */
|
|
744
744
|
stepParentM = new _(b.Uint32);
|
|
745
745
|
/** Buffer used during hierarchy traversal updates. */
|
|
746
746
|
parentStack = new _(b.Uint32);
|
|
@@ -776,7 +776,7 @@ class At {
|
|
|
776
776
|
* Evaluates and updates matrices from the given step. Used primarily for deferred transformation.
|
|
777
777
|
* @param step - The initial step to update matrices from.
|
|
778
778
|
*/
|
|
779
|
-
|
|
779
|
+
updateMatrixSubtree(t) {
|
|
780
780
|
const e = typeof t == "number" ? t : t.step;
|
|
781
781
|
let r = 0, i = e;
|
|
782
782
|
for (; i < this.step; ) {
|
|
@@ -919,41 +919,41 @@ class At {
|
|
|
919
919
|
t.offset && (l += t.offset.x, d += t.offset.y);
|
|
920
920
|
const f = t.origin;
|
|
921
921
|
f !== void 0 && (typeof f == "number" ? (l -= f * e, d -= f * r) : (l -= f.x * e, d -= f.y * r));
|
|
922
|
-
const m = u ? Math.cos(u) : 1,
|
|
922
|
+
const m = u ? Math.cos(u) : 1, v = u ? Math.sin(u) : 0, y = m * o, T = v * o, M = -v * h, A = m * h, P = s + y * l + M * d, C = a + T * l + A * d;
|
|
923
923
|
if (i !== -1) {
|
|
924
924
|
this.matrix.multiplyAffine(
|
|
925
925
|
this.curWorldM,
|
|
926
926
|
i,
|
|
927
|
-
v,
|
|
928
927
|
y,
|
|
929
|
-
|
|
928
|
+
T,
|
|
929
|
+
M,
|
|
930
930
|
A,
|
|
931
931
|
P,
|
|
932
|
-
|
|
932
|
+
C
|
|
933
933
|
);
|
|
934
934
|
return;
|
|
935
935
|
}
|
|
936
936
|
this.matrix.multiplyAffineInPlace(
|
|
937
937
|
this.curLocalM,
|
|
938
|
-
v,
|
|
939
938
|
y,
|
|
940
|
-
|
|
939
|
+
T,
|
|
940
|
+
M,
|
|
941
941
|
A,
|
|
942
942
|
P,
|
|
943
|
-
|
|
943
|
+
C
|
|
944
944
|
), this.matrix.multiplyAffineInPlace(
|
|
945
945
|
this.curWorldM,
|
|
946
|
-
v,
|
|
947
946
|
y,
|
|
948
|
-
|
|
947
|
+
T,
|
|
948
|
+
M,
|
|
949
949
|
A,
|
|
950
950
|
P,
|
|
951
|
-
|
|
951
|
+
C
|
|
952
952
|
);
|
|
953
953
|
}
|
|
954
954
|
}
|
|
955
|
-
var
|
|
956
|
-
class
|
|
955
|
+
var Q = /* @__PURE__ */ ((n) => (n[n.REPEAT = 0] = "REPEAT", n[n.CLAMP = 1] = "CLAMP", n[n.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", n))(Q || {});
|
|
956
|
+
class _t {
|
|
957
957
|
render;
|
|
958
958
|
cache = /* @__PURE__ */ new Map();
|
|
959
959
|
constructor(t) {
|
|
@@ -968,10 +968,10 @@ class St {
|
|
|
968
968
|
async load(t, e) {
|
|
969
969
|
let r = this.cache.get(t);
|
|
970
970
|
if (r)
|
|
971
|
-
return new
|
|
971
|
+
return new O(r);
|
|
972
972
|
try {
|
|
973
973
|
const i = await this._fetchImage(t);
|
|
974
|
-
return r =
|
|
974
|
+
return r = z.fromSource(this.render, i, e), r.uid = t, this.cache.set(t, r), new O(r);
|
|
975
975
|
} catch (i) {
|
|
976
976
|
throw console.error(`[TextureManager] Failed to load: ${t}`, i), i;
|
|
977
977
|
}
|
|
@@ -984,9 +984,9 @@ class St {
|
|
|
984
984
|
*/
|
|
985
985
|
create(t, e) {
|
|
986
986
|
if (e?.key && this.cache.has(e.key))
|
|
987
|
-
return new
|
|
988
|
-
const r =
|
|
989
|
-
return e?.key && (r.uid = e.key, this.cache.set(e.key, r)), new
|
|
987
|
+
return new O(this.cache.get(e.key));
|
|
988
|
+
const r = z.fromSource(this.render, t, e);
|
|
989
|
+
return e?.key && (r.uid = e.key, this.cache.set(e.key, r)), new O(r);
|
|
990
990
|
}
|
|
991
991
|
/**
|
|
992
992
|
* Creates a generic Render Texture (FrameBuffer).
|
|
@@ -996,7 +996,7 @@ class St {
|
|
|
996
996
|
* @returns The newly created RenderTexture.
|
|
997
997
|
*/
|
|
998
998
|
createRenderTexture(t) {
|
|
999
|
-
return new
|
|
999
|
+
return new Pt(this.render, t);
|
|
1000
1000
|
}
|
|
1001
1001
|
/**
|
|
1002
1002
|
* Creates a TextTexture for rendering text.
|
|
@@ -1004,7 +1004,7 @@ class St {
|
|
|
1004
1004
|
* @returns The newly created TextTexture.
|
|
1005
1005
|
*/
|
|
1006
1006
|
createTextTexture(t) {
|
|
1007
|
-
return new
|
|
1007
|
+
return new Lt(this.render, t);
|
|
1008
1008
|
}
|
|
1009
1009
|
/**
|
|
1010
1010
|
* Destroys a texture and potentially removes its BaseTexture from the cache.
|
|
@@ -1015,7 +1015,7 @@ class St {
|
|
|
1015
1015
|
*/
|
|
1016
1016
|
destroy(t, e = !1) {
|
|
1017
1017
|
let r, i;
|
|
1018
|
-
typeof t == "string" ? (i = t, r = this.cache.get(i)) : t instanceof
|
|
1018
|
+
typeof t == "string" ? (i = t, r = this.cache.get(i)) : t instanceof O ? (r = t.base, i = r?.uid, t.destroy()) : (r = t, i = r.uid), r && (r.refCount <= 0 || e) && (r.destroy(this.render.gl), i && this.cache.delete(i));
|
|
1019
1019
|
}
|
|
1020
1020
|
/**
|
|
1021
1021
|
* Destroys all cached textures and clears the cache, ignoring reference counts.
|
|
@@ -1032,7 +1032,7 @@ class St {
|
|
|
1032
1032
|
});
|
|
1033
1033
|
}
|
|
1034
1034
|
}
|
|
1035
|
-
class
|
|
1035
|
+
class z {
|
|
1036
1036
|
glTexture = null;
|
|
1037
1037
|
width;
|
|
1038
1038
|
height;
|
|
@@ -1049,8 +1049,8 @@ class X {
|
|
|
1049
1049
|
* @returns The created BaseTexture.
|
|
1050
1050
|
*/
|
|
1051
1051
|
static fromSource(t, e, r = {}) {
|
|
1052
|
-
const i =
|
|
1053
|
-
return new
|
|
1052
|
+
const i = et(t, e, r);
|
|
1053
|
+
return new z(i, e.width, e.height);
|
|
1054
1054
|
}
|
|
1055
1055
|
/**
|
|
1056
1056
|
* Updates the content of the existing texture (e.g. for Video or dynamic Canvas).
|
|
@@ -1059,19 +1059,19 @@ class X {
|
|
|
1059
1059
|
* @param source - The new image source.
|
|
1060
1060
|
*/
|
|
1061
1061
|
updateSource(t, e, r = {}) {
|
|
1062
|
-
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), r.textureFilter !== void 0 &&
|
|
1062
|
+
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), r.textureFilter !== void 0 && nt(t, r.textureFilter), r.wrap !== void 0 && st(t, r.wrap), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, 1), t.pixelStorei(t.UNPACK_ALIGNMENT, 1), r.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, r.premultipliedAlpha), this.width === e.width && this.height === e.height ? t.texSubImage2D(t.TEXTURE_2D, 0, 0, 0, t.RGBA, t.UNSIGNED_BYTE, e) : (t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, t.RGBA, t.UNSIGNED_BYTE, e), this.width = e.width, this.height = e.height), r.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1));
|
|
1063
1063
|
}
|
|
1064
1064
|
/**
|
|
1065
1065
|
* Dynamically updates the texture filtering mode.
|
|
1066
1066
|
*/
|
|
1067
1067
|
setFilterMode(t, e) {
|
|
1068
|
-
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture),
|
|
1068
|
+
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), nt(t, e), t.bindTexture(t.TEXTURE_2D, null));
|
|
1069
1069
|
}
|
|
1070
1070
|
/**
|
|
1071
1071
|
* Dynamically updates the texture wrap mode.
|
|
1072
1072
|
*/
|
|
1073
1073
|
setWrapMode(t, e) {
|
|
1074
|
-
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture),
|
|
1074
|
+
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), st(t, e), t.bindTexture(t.TEXTURE_2D, null));
|
|
1075
1075
|
}
|
|
1076
1076
|
/**
|
|
1077
1077
|
* Destroys the WebGL texture resource.
|
|
@@ -1081,7 +1081,7 @@ class X {
|
|
|
1081
1081
|
this.glTexture && (t.deleteTexture(this.glTexture), this.glTexture = null);
|
|
1082
1082
|
}
|
|
1083
1083
|
}
|
|
1084
|
-
class
|
|
1084
|
+
class O {
|
|
1085
1085
|
base;
|
|
1086
1086
|
uvX = 0;
|
|
1087
1087
|
uvY = 0;
|
|
@@ -1138,7 +1138,7 @@ class W {
|
|
|
1138
1138
|
* @returns A new Texture pointing to the sub-region.
|
|
1139
1139
|
*/
|
|
1140
1140
|
getSubTexture(t, e, r, i) {
|
|
1141
|
-
if (!this.base) return new
|
|
1141
|
+
if (!this.base) return new O();
|
|
1142
1142
|
const s = this.clone(), a = this._px, o = this._py;
|
|
1143
1143
|
return s.setRegion(a + t, o + e, r, i), s;
|
|
1144
1144
|
}
|
|
@@ -1147,7 +1147,7 @@ class W {
|
|
|
1147
1147
|
* @returns A new Texture instance.
|
|
1148
1148
|
*/
|
|
1149
1149
|
clone(t) {
|
|
1150
|
-
const e = t ?? new
|
|
1150
|
+
const e = t ?? new O(this.base);
|
|
1151
1151
|
return t && this.base && t.setBase(this.base), e.scale = this.scale, e.uvX = this.uvX, e.uvY = this.uvY, e.uvW = this.uvW, e.uvH = this.uvH, e.rawWidth = this.rawWidth, e.rawHeight = this.rawHeight, e.offsetX = this.offsetX, e.offsetY = this.offsetY, e.flipY = this.flipY, e.isRotated = this.isRotated, e.isAtlas = this.isAtlas, e._px = this._px, e._py = this._py, e._pw = this._pw, e._ph = this._ph, e;
|
|
1152
1152
|
}
|
|
1153
1153
|
/**
|
|
@@ -1164,8 +1164,8 @@ class W {
|
|
|
1164
1164
|
if (!this.base) return [];
|
|
1165
1165
|
const a = [], o = this.rawWidth, h = this.rawHeight, c = Math.max(0, s), u = t + c, l = e + c, d = r ?? Math.floor((o + c) / u), f = i ?? Math.floor((h + c) / l);
|
|
1166
1166
|
for (let m = 0; m < f; m++)
|
|
1167
|
-
for (let
|
|
1168
|
-
a.push(this.getSubTexture(
|
|
1167
|
+
for (let v = 0; v < d; v++)
|
|
1168
|
+
a.push(this.getSubTexture(v * u, m * l, t, e));
|
|
1169
1169
|
return a;
|
|
1170
1170
|
}
|
|
1171
1171
|
/**
|
|
@@ -1174,8 +1174,8 @@ class W {
|
|
|
1174
1174
|
* @param options - Optional antialias and wrap mode settings.
|
|
1175
1175
|
*/
|
|
1176
1176
|
static fromImageSource(t, e, r = {}) {
|
|
1177
|
-
const i =
|
|
1178
|
-
return new
|
|
1177
|
+
const i = et(t, e, r);
|
|
1178
|
+
return new O(new z(i, e.width, e.height));
|
|
1179
1179
|
}
|
|
1180
1180
|
/**
|
|
1181
1181
|
* Marks this Texture as destroyed, decrementing the BaseTexture reference count.
|
|
@@ -1184,7 +1184,7 @@ class W {
|
|
|
1184
1184
|
this.base && (this.base.refCount--, this.base = void 0), this.glTexture = null;
|
|
1185
1185
|
}
|
|
1186
1186
|
}
|
|
1187
|
-
class
|
|
1187
|
+
class Pt extends O {
|
|
1188
1188
|
framebuffer;
|
|
1189
1189
|
renderbuffer;
|
|
1190
1190
|
gl;
|
|
@@ -1195,8 +1195,8 @@ class bt extends W {
|
|
|
1195
1195
|
_allocH = 0;
|
|
1196
1196
|
constructor(t, e) {
|
|
1197
1197
|
super(), this.gl = t.gl, this.clearColor = e.clearColor ?? x.Black;
|
|
1198
|
-
const r = Math.max(Math.round(e.width), 1), i = Math.max(Math.round(e.height), 1), a =
|
|
1199
|
-
if (this.setBase(new
|
|
1198
|
+
const r = Math.max(Math.round(e.width), 1), i = Math.max(Math.round(e.height), 1), a = et(t, { width: r, height: i }, { ...e, onlySize: !0 });
|
|
1199
|
+
if (this.setBase(new z(a, r, i)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
|
|
1200
1200
|
throw new Error("Failed to create Framebuffer or Renderbuffer");
|
|
1201
1201
|
this.resize(r, i, !0);
|
|
1202
1202
|
}
|
|
@@ -1274,7 +1274,7 @@ class bt extends W {
|
|
|
1274
1274
|
super.destroy(), this.framebuffer && this.gl.deleteFramebuffer(this.framebuffer), this.renderbuffer && this.gl.deleteRenderbuffer(this.renderbuffer), this.base?.destroy(this.gl);
|
|
1275
1275
|
}
|
|
1276
1276
|
}
|
|
1277
|
-
const
|
|
1277
|
+
const Nt = {
|
|
1278
1278
|
fontFamily: "Arial",
|
|
1279
1279
|
fontSize: 24,
|
|
1280
1280
|
fontWeight: "normal",
|
|
@@ -1283,7 +1283,7 @@ const Ut = {
|
|
|
1283
1283
|
align: "left",
|
|
1284
1284
|
lineHeight: 1
|
|
1285
1285
|
};
|
|
1286
|
-
class
|
|
1286
|
+
class Lt extends O {
|
|
1287
1287
|
canvas;
|
|
1288
1288
|
ctx;
|
|
1289
1289
|
render;
|
|
@@ -1292,12 +1292,12 @@ class Ct extends W {
|
|
|
1292
1292
|
options;
|
|
1293
1293
|
flipY = !0;
|
|
1294
1294
|
constructor(t, e) {
|
|
1295
|
-
super(), this.render = t, this._style = { ...
|
|
1295
|
+
super(), this.render = t, this._style = { ...Nt, ...e }, this._text = e?.text ?? "", this.options = { premultipliedAlpha: t.premultipliedAlpha, ...e }, this.scale = 1 / t.dpr, this.canvas = document.createElement("canvas");
|
|
1296
1296
|
const r = this.canvas.getContext("2d", { willReadFrequently: !0 });
|
|
1297
1297
|
if (!r) throw new Error("Failed to get 2d context for TextTexture");
|
|
1298
1298
|
this.ctx = r, this.canvas.width = 1, this.canvas.height = 1;
|
|
1299
|
-
const i =
|
|
1300
|
-
this.setBase(new
|
|
1299
|
+
const i = et(t, this.canvas, this.options);
|
|
1300
|
+
this.setBase(new z(i, 1, 1)), this.update();
|
|
1301
1301
|
}
|
|
1302
1302
|
get text() {
|
|
1303
1303
|
return this._text;
|
|
@@ -1337,27 +1337,27 @@ class Ct extends W {
|
|
|
1337
1337
|
`);
|
|
1338
1338
|
let u = 0, l = 0;
|
|
1339
1339
|
const d = t.measureText(c[0] || "M"), f = (d.fontBoundingBoxAscent || r) + (d.fontBoundingBoxDescent || r * 0.2);
|
|
1340
|
-
for (const
|
|
1341
|
-
const N = t.measureText(
|
|
1340
|
+
for (const W of c) {
|
|
1341
|
+
const N = t.measureText(W);
|
|
1342
1342
|
N.width > u && (u = N.width), l += f * a;
|
|
1343
1343
|
}
|
|
1344
1344
|
l -= f * (a - 1);
|
|
1345
|
-
const m = this._style.strokeThickness || 0,
|
|
1346
|
-
(this.canvas.width !==
|
|
1347
|
-
const A = this.updateOffset(
|
|
1348
|
-
|
|
1349
|
-
let
|
|
1350
|
-
for (const
|
|
1351
|
-
|
|
1352
|
-
this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0,
|
|
1345
|
+
const m = this._style.strokeThickness || 0, v = Math.ceil(u + m * 2) || 1, y = Math.ceil(l + m * 2) || 1, T = Math.ceil(v * h), M = Math.ceil(y * h);
|
|
1346
|
+
(this.canvas.width !== T || this.canvas.height !== M) && (this.canvas.width = T, this.canvas.height = M), t.setTransform(h, 0, 0, h, 0, 0), t.clearRect(0, 0, v, y), t.font = o, t.textBaseline = "top", t.textAlign = this._style.align;
|
|
1347
|
+
const A = this.updateOffset(v, m), P = e.strokeThickness, C = P > 0;
|
|
1348
|
+
C && (t.lineWidth = P, t.strokeStyle = e.stroke, t.lineJoin = "round"), e.fill && (t.fillStyle = e.fill);
|
|
1349
|
+
let F = m;
|
|
1350
|
+
for (const W of c)
|
|
1351
|
+
C && t.strokeText(W, A, F), e.fill && t.fillText(W, A, F), F += f * a;
|
|
1352
|
+
this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0, T, M);
|
|
1353
1353
|
}
|
|
1354
1354
|
}
|
|
1355
|
-
const
|
|
1355
|
+
const It = (n, t = !1, e = !0) => {
|
|
1356
1356
|
const r = n.getContext("webgl2", { stencil: !0, antialias: t, premultipliedAlpha: e });
|
|
1357
1357
|
if (!r)
|
|
1358
1358
|
throw new Error("WebGL2 is not supported in this browser.");
|
|
1359
1359
|
return r;
|
|
1360
|
-
},
|
|
1360
|
+
}, dt = (n, t, e) => {
|
|
1361
1361
|
const r = n.createShader(e);
|
|
1362
1362
|
if (!r)
|
|
1363
1363
|
throw new Error("Unable to create webgl shader");
|
|
@@ -1366,8 +1366,8 @@ const _t = (n, t = !1, e = !0) => {
|
|
|
1366
1366
|
throw console.error("Shader compilation failed:", s), new Error("Unable to compile shader: " + s + t);
|
|
1367
1367
|
}
|
|
1368
1368
|
return r;
|
|
1369
|
-
},
|
|
1370
|
-
var r = n.createProgram(), i =
|
|
1369
|
+
}, Ot = (n, t, e) => {
|
|
1370
|
+
var r = n.createProgram(), i = dt(n, t, 35633), s = dt(n, e, 35632);
|
|
1371
1371
|
if (!r)
|
|
1372
1372
|
throw new Error("Unable to create program shader");
|
|
1373
1373
|
if (n.attachShader(r, i), n.attachShader(r, s), n.linkProgram(r), !n.getProgramParameter(r, n.LINK_STATUS)) {
|
|
@@ -1376,26 +1376,26 @@ const _t = (n, t = !1, e = !0) => {
|
|
|
1376
1376
|
}
|
|
1377
1377
|
return r;
|
|
1378
1378
|
};
|
|
1379
|
-
function
|
|
1379
|
+
function st(n, t) {
|
|
1380
1380
|
const e = {
|
|
1381
|
-
[
|
|
1382
|
-
[
|
|
1383
|
-
[
|
|
1381
|
+
[Q.CLAMP]: n.CLAMP_TO_EDGE,
|
|
1382
|
+
[Q.REPEAT]: n.REPEAT,
|
|
1383
|
+
[Q.MIRRORED_REPEAT]: n.MIRRORED_REPEAT
|
|
1384
1384
|
}[t] || n.CLAMP_TO_EDGE;
|
|
1385
1385
|
n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_S, e), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_T, e);
|
|
1386
1386
|
}
|
|
1387
|
-
function
|
|
1387
|
+
function nt(n, t) {
|
|
1388
1388
|
const e = {
|
|
1389
|
-
[
|
|
1390
|
-
[
|
|
1389
|
+
[ht.LINEAR]: n.LINEAR,
|
|
1390
|
+
[ht.NEAREST]: n.NEAREST
|
|
1391
1391
|
}[t] ?? n.NEAREST;
|
|
1392
1392
|
n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MIN_FILTER, e), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MAG_FILTER, e);
|
|
1393
1393
|
}
|
|
1394
|
-
function
|
|
1394
|
+
function et(n, t, e) {
|
|
1395
1395
|
const r = n.gl, i = r.createTexture();
|
|
1396
1396
|
if (!i)
|
|
1397
1397
|
throw new Error("Unable to create WebGL texture");
|
|
1398
|
-
if (r.bindTexture(r.TEXTURE_2D, i), r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL, 0), r.pixelStorei(r.UNPACK_ALIGNMENT, 1),
|
|
1398
|
+
if (r.bindTexture(r.TEXTURE_2D, i), r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL, 0), r.pixelStorei(r.UNPACK_ALIGNMENT, 1), st(r, e.wrap ?? Q.CLAMP), nt(r, e.textureFilter ?? n.textureFilter), e.onlySize) {
|
|
1399
1399
|
const s = t;
|
|
1400
1400
|
r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, s.width, s.height, 0, r.RGBA, r.UNSIGNED_BYTE, null);
|
|
1401
1401
|
} else {
|
|
@@ -1413,15 +1413,15 @@ function V(n, t) {
|
|
|
1413
1413
|
}
|
|
1414
1414
|
return n;
|
|
1415
1415
|
}
|
|
1416
|
-
const
|
|
1417
|
-
function
|
|
1416
|
+
const Ft = 5126, at = 5121;
|
|
1417
|
+
function Wt(n, t, e) {
|
|
1418
1418
|
n.vertexAttribDivisor(t, e);
|
|
1419
1419
|
}
|
|
1420
|
-
function
|
|
1420
|
+
function Mt(n, t, e, r, i) {
|
|
1421
1421
|
n.drawArraysInstanced(t, e, r, i);
|
|
1422
1422
|
}
|
|
1423
|
-
let
|
|
1424
|
-
class
|
|
1423
|
+
let Bt = 0;
|
|
1424
|
+
class wt {
|
|
1425
1425
|
program;
|
|
1426
1426
|
attributeLoc = {};
|
|
1427
1427
|
uniformLoc = {};
|
|
@@ -1433,11 +1433,11 @@ class Tt {
|
|
|
1433
1433
|
/** Whether the uniform is an array (e.g. sampler2D uTextures[8]) */
|
|
1434
1434
|
uniformIsArray = {};
|
|
1435
1435
|
gl;
|
|
1436
|
-
shaderId =
|
|
1436
|
+
shaderId = Bt++;
|
|
1437
1437
|
// for debug
|
|
1438
1438
|
vao;
|
|
1439
1439
|
constructor(t, e, r, i) {
|
|
1440
|
-
this.gl = t, this.program =
|
|
1440
|
+
this.gl = t, this.program = Ot(t, e, r), this.parseShader(e), this.parseShader(r), this.vao = t.createVertexArray(), i && this.setAttributes(i);
|
|
1441
1441
|
}
|
|
1442
1442
|
/** Switch GPU to use this shader program */
|
|
1443
1443
|
use() {
|
|
@@ -1463,7 +1463,7 @@ class Tt {
|
|
|
1463
1463
|
const r = this.uniformLoc[t];
|
|
1464
1464
|
if (r === void 0) return;
|
|
1465
1465
|
const i = this.uniformType[t], s = this.uniformIsArray[t];
|
|
1466
|
-
|
|
1466
|
+
Dt(this.gl, r, i, e, s);
|
|
1467
1467
|
}
|
|
1468
1468
|
/**
|
|
1469
1469
|
* Batch-set uniforms via a plain value map.
|
|
@@ -1490,11 +1490,11 @@ class Tt {
|
|
|
1490
1490
|
r.vertexAttribPointer(
|
|
1491
1491
|
e,
|
|
1492
1492
|
t.size,
|
|
1493
|
-
t.type ??
|
|
1493
|
+
t.type ?? Ft,
|
|
1494
1494
|
t.normalized ?? !1,
|
|
1495
1495
|
t.stride,
|
|
1496
1496
|
t.offset ?? 0
|
|
1497
|
-
), r.enableVertexAttribArray(e),
|
|
1497
|
+
), r.enableVertexAttribArray(e), Wt(r, e, t.divisor ?? 0);
|
|
1498
1498
|
}
|
|
1499
1499
|
/** Bind all vertex attribute pointers at once */
|
|
1500
1500
|
setAttributes(t) {
|
|
@@ -1522,7 +1522,7 @@ class Tt {
|
|
|
1522
1522
|
}
|
|
1523
1523
|
}
|
|
1524
1524
|
}
|
|
1525
|
-
function
|
|
1525
|
+
function Dt(n, t, e, r, i = !1) {
|
|
1526
1526
|
switch (e) {
|
|
1527
1527
|
// scalars
|
|
1528
1528
|
case "float":
|
|
@@ -1558,10 +1558,10 @@ function Ot(n, t, e, r, i = !1) {
|
|
|
1558
1558
|
return n.uniformMatrix4fv(t, !1, r);
|
|
1559
1559
|
// fallback: guess by value shape
|
|
1560
1560
|
default:
|
|
1561
|
-
return
|
|
1561
|
+
return kt(n, t, r);
|
|
1562
1562
|
}
|
|
1563
1563
|
}
|
|
1564
|
-
function
|
|
1564
|
+
function kt(n, t, e) {
|
|
1565
1565
|
if (typeof e == "number")
|
|
1566
1566
|
return n.uniform1f(t, e);
|
|
1567
1567
|
const r = e;
|
|
@@ -1580,7 +1580,7 @@ function Ft(n, t, e) {
|
|
|
1580
1580
|
return n.uniform1fv(t, r);
|
|
1581
1581
|
}
|
|
1582
1582
|
}
|
|
1583
|
-
class
|
|
1583
|
+
class ft {
|
|
1584
1584
|
/** Custom vertex shader code */
|
|
1585
1585
|
vs;
|
|
1586
1586
|
/** Custom fragment shader code */
|
|
@@ -1655,7 +1655,7 @@ class ct {
|
|
|
1655
1655
|
this.glshader.forEach((t) => t.destroy());
|
|
1656
1656
|
}
|
|
1657
1657
|
}
|
|
1658
|
-
class
|
|
1658
|
+
class At {
|
|
1659
1659
|
constructor(t) {
|
|
1660
1660
|
this.rapid = t, this.gl = t.gl, this.maxTextureUnits = t.maxTextureUnits, this.matrixStore = t.matrix;
|
|
1661
1661
|
}
|
|
@@ -1698,7 +1698,7 @@ class Et {
|
|
|
1698
1698
|
return i == -1 ? (this.freeTextureUnitNum === 0 && this.flush(), this.usedTextures.push(t), this.usedTexturePadding.push(e), this.usedTexturePadding.push(r), this.usedTextures.length - 1) : i;
|
|
1699
1699
|
}
|
|
1700
1700
|
createShader(t, e) {
|
|
1701
|
-
return new
|
|
1701
|
+
return new wt(this.gl, t, e);
|
|
1702
1702
|
}
|
|
1703
1703
|
createCustomShader(t) {
|
|
1704
1704
|
return t.getGLShader(this, this.KEY, this.vs, this.fs);
|
|
@@ -1706,7 +1706,7 @@ class Et {
|
|
|
1706
1706
|
getCustomShader(t) {
|
|
1707
1707
|
if (!t)
|
|
1708
1708
|
return this.defaultShader;
|
|
1709
|
-
if (t instanceof
|
|
1709
|
+
if (t instanceof ft) {
|
|
1710
1710
|
const e = this.createCustomShader(t);
|
|
1711
1711
|
return e ?? this.defaultShader;
|
|
1712
1712
|
}
|
|
@@ -1721,7 +1721,7 @@ class Et {
|
|
|
1721
1721
|
return this.isDefaultShader && !t ? !0 : this.getCustomShader(t) == this.currentShader;
|
|
1722
1722
|
}
|
|
1723
1723
|
enter(t) {
|
|
1724
|
-
this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof
|
|
1724
|
+
this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof ft ? (this.customShader = t, this.customShaderUsedTextureNum = t.usedTextureUnitNum) : (this.customShader = null, this.customShaderUsedTextureNum = 0), this.isDefaultShader = this.currentShader == this.defaultShader, this.currentShader.use(), this.currentShader.setUniform("u_projection", this.rapid.projection);
|
|
1725
1725
|
}
|
|
1726
1726
|
exit() {
|
|
1727
1727
|
this.hasPendingContent() && this.flush(), this.gl.bindVertexArray(null);
|
|
@@ -1758,7 +1758,7 @@ class Et {
|
|
|
1758
1758
|
return !1;
|
|
1759
1759
|
}
|
|
1760
1760
|
}
|
|
1761
|
-
const
|
|
1761
|
+
const tt = `#version 300 es\r
|
|
1762
1762
|
precision highp float;\r
|
|
1763
1763
|
\r
|
|
1764
1764
|
// per-vertex\r
|
|
@@ -1806,7 +1806,7 @@ void main(void) {\r
|
|
|
1806
1806
|
\r
|
|
1807
1807
|
gl_Position = u_projection * position;\r
|
|
1808
1808
|
}\r
|
|
1809
|
-
`,
|
|
1809
|
+
`, mt = `#version 300 es\r
|
|
1810
1810
|
precision mediump float;\r
|
|
1811
1811
|
\r
|
|
1812
1812
|
uniform sampler2D uTextures[%TEXTURE_NUM%];\r
|
|
@@ -1855,8 +1855,8 @@ void main(void) {\r
|
|
|
1855
1855
|
\r
|
|
1856
1856
|
// CUSTOM_CODE_CALL\r
|
|
1857
1857
|
}\r
|
|
1858
|
-
`,
|
|
1859
|
-
class
|
|
1858
|
+
`, $ = 48, Gt = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
|
|
1859
|
+
class ot extends At {
|
|
1860
1860
|
instanceBuffer;
|
|
1861
1861
|
quadBuffer;
|
|
1862
1862
|
instanceCount = 0;
|
|
@@ -1868,28 +1868,28 @@ class at extends Et {
|
|
|
1868
1868
|
}
|
|
1869
1869
|
createBuffer() {
|
|
1870
1870
|
const t = this.gl;
|
|
1871
|
-
this.quadBuffer = new
|
|
1872
|
-
for (const e of
|
|
1873
|
-
this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new
|
|
1871
|
+
this.quadBuffer = new it(t, b.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
|
|
1872
|
+
for (const e of Gt) this.quadBuffer.pushFloat32(e);
|
|
1873
|
+
this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new it(t, b.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
|
|
1874
1874
|
}
|
|
1875
1875
|
createDefaultShader() {
|
|
1876
|
-
const t = this.rapid, e = V(
|
|
1876
|
+
const t = this.rapid, e = V(mt, t.maxTextureUnits), r = V(tt, t.maxTextureUnits);
|
|
1877
1877
|
return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
|
|
1878
1878
|
}
|
|
1879
1879
|
createShader(t, e) {
|
|
1880
1880
|
const r = super.createShader(t, e);
|
|
1881
1881
|
return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
|
|
1882
|
-
{ name: "aMatrixRow0", size: 3, stride:
|
|
1883
|
-
{ name: "aMatrixRow1", size: 3, stride:
|
|
1884
|
-
{ name: "aUVRect", size: 4, stride:
|
|
1885
|
-
{ name: "aColor", size: 4, type:
|
|
1886
|
-
{ name: "aTextureId", size: 1, type:
|
|
1882
|
+
{ name: "aMatrixRow0", size: 3, stride: $, offset: 0, divisor: 1 },
|
|
1883
|
+
{ name: "aMatrixRow1", size: 3, stride: $, offset: 12, divisor: 1 },
|
|
1884
|
+
{ name: "aUVRect", size: 4, stride: $, offset: 24, divisor: 1 },
|
|
1885
|
+
{ name: "aColor", size: 4, type: at, normalized: !0, stride: $, offset: 40, divisor: 1 },
|
|
1886
|
+
{ name: "aTextureId", size: 1, type: at, stride: $, offset: 44, divisor: 1 }
|
|
1887
1887
|
]), this.quadBuffer.bindBuffer(), r.setAttributes([
|
|
1888
1888
|
{ name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
|
|
1889
1889
|
]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
|
|
1890
1890
|
}
|
|
1891
1891
|
createCustomShader(t) {
|
|
1892
|
-
const e = V(
|
|
1892
|
+
const e = V(mt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = V(tt, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
|
|
1893
1893
|
return t.getGLShader(this, this.KEY, r, e);
|
|
1894
1894
|
}
|
|
1895
1895
|
/**
|
|
@@ -1926,23 +1926,23 @@ class at extends Et {
|
|
|
1926
1926
|
d
|
|
1927
1927
|
);
|
|
1928
1928
|
}
|
|
1929
|
-
drawSpriteAffine(t, e, r, i, s, a, o, h = 0, c = 0, u = 1, l = 1, d = 4294967295, f = 0, m = 0,
|
|
1930
|
-
const
|
|
1929
|
+
drawSpriteAffine(t, e, r, i, s, a, o, h = 0, c = 0, u = 1, l = 1, d = 4294967295, f = 0, m = 0, v = !1, y = !1, T = !1) {
|
|
1930
|
+
const M = t.base, A = t.rawWidth, P = t.rawHeight, C = t.offsetX, F = t.offsetY, W = this.useTexture(
|
|
1931
1931
|
t.glTexture,
|
|
1932
|
-
f /
|
|
1933
|
-
m /
|
|
1934
|
-
), N = this.instanceBuffer,
|
|
1932
|
+
f / M.width,
|
|
1933
|
+
m / M.height
|
|
1934
|
+
), N = this.instanceBuffer, w = N.usedElemNum;
|
|
1935
1935
|
N.resize(12);
|
|
1936
|
-
const
|
|
1937
|
-
|
|
1938
|
-
const
|
|
1939
|
-
|
|
1936
|
+
const U = N.float32, X = N.uint32, k = T ? P : A, G = T ? A : P, I = k + 2 * f, B = G + 2 * m, H = C - f, R = F - m, g = this.localSpriteMatrix;
|
|
1937
|
+
T ? (g[0] = 0, g[1] = y ? B : -B, g[2] = v ? -I : I, g[3] = 0, g[4] = H + (v ? I : 0), g[5] = R + (y ? 0 : B)) : (g[0] = v ? -I : I, g[1] = 0, g[2] = 0, g[3] = y ? -B : B, g[4] = H + (v ? I : 0), g[5] = R + (y ? B : 0));
|
|
1938
|
+
const S = this.worldSpriteMatrix;
|
|
1939
|
+
S[0] = e * g[0] + i * g[1], S[1] = r * g[0] + s * g[1], S[2] = e * g[2] + i * g[3], S[3] = r * g[2] + s * g[3], S[4] = a + e * g[4] + i * g[5], S[5] = o + r * g[4] + s * g[5], U[w + 6] = h, U[w + 7] = c, U[w + 8] = u, U[w + 9] = l, X[w + 10] = d, X[w + 11] = W, this.rapid.roundPixels && (S[4] = Math.round(S[4]), S[5] = Math.round(S[5])), U[w] = S[0], U[w + 1] = S[2], U[w + 2] = S[4], U[w + 3] = S[1], U[w + 4] = S[3], U[w + 5] = S[5], N.usedElemNum += 12, N.makeDirty(), this.instanceCount++;
|
|
1940
1940
|
}
|
|
1941
1941
|
render() {
|
|
1942
1942
|
if (this.instanceCount === 0) return;
|
|
1943
1943
|
this.prepareRender();
|
|
1944
1944
|
const t = this.gl, e = this.currentShader;
|
|
1945
|
-
this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(),
|
|
1945
|
+
this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), Mt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
|
|
1946
1946
|
}
|
|
1947
1947
|
resetRender() {
|
|
1948
1948
|
super.resetRender(), this.instanceBuffer.clear(), this.instanceCount = 0;
|
|
@@ -1951,7 +1951,7 @@ class at extends Et {
|
|
|
1951
1951
|
return this.instanceCount > 0;
|
|
1952
1952
|
}
|
|
1953
1953
|
}
|
|
1954
|
-
const
|
|
1954
|
+
const Ht = `#version 300 es\r
|
|
1955
1955
|
precision highp float;\r
|
|
1956
1956
|
\r
|
|
1957
1957
|
in vec2 aPosition;\r
|
|
@@ -1982,7 +1982,7 @@ void main(void) {\r
|
|
|
1982
1982
|
// CUSTOM_CODE_CALL\r
|
|
1983
1983
|
gl_Position = u_projection * position;\r
|
|
1984
1984
|
}\r
|
|
1985
|
-
`,
|
|
1985
|
+
`, Vt = `#version 300 es\r
|
|
1986
1986
|
precision mediump float;\r
|
|
1987
1987
|
\r
|
|
1988
1988
|
in vec4 vColor;\r
|
|
@@ -2028,7 +2028,7 @@ void main(void) {\r
|
|
|
2028
2028
|
fragColor = sampleTexture(vRegion) * vColor;\r
|
|
2029
2029
|
// CUSTOM_CODE_CALL\r
|
|
2030
2030
|
}\r
|
|
2031
|
-
`,
|
|
2031
|
+
`, Yt = `#version 300 es\r
|
|
2032
2032
|
precision highp float;\r
|
|
2033
2033
|
\r
|
|
2034
2034
|
in vec2 aPosition;\r
|
|
@@ -2051,7 +2051,7 @@ void main(void) {\r
|
|
|
2051
2051
|
);\r
|
|
2052
2052
|
gl_Position = u_projection * position;\r
|
|
2053
2053
|
}\r
|
|
2054
|
-
`,
|
|
2054
|
+
`, zt = `#version 300 es\r
|
|
2055
2055
|
precision mediump float;\r
|
|
2056
2056
|
\r
|
|
2057
2057
|
in vec2 vRegion;\r
|
|
@@ -2071,8 +2071,8 @@ void main(void) {\r
|
|
|
2071
2071
|
discard;\r
|
|
2072
2072
|
}\r
|
|
2073
2073
|
}\r
|
|
2074
|
-
`,
|
|
2075
|
-
class
|
|
2074
|
+
`, K = 20;
|
|
2075
|
+
class Xt extends At {
|
|
2076
2076
|
vertexBuffer;
|
|
2077
2077
|
vertexCount = 0;
|
|
2078
2078
|
matrixIndex = -1;
|
|
@@ -2085,24 +2085,24 @@ class Ht extends Et {
|
|
|
2085
2085
|
}
|
|
2086
2086
|
createBuffer() {
|
|
2087
2087
|
const t = this.gl;
|
|
2088
|
-
this.vertexBuffer = new
|
|
2088
|
+
this.vertexBuffer = new it(t, b.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(Yt, zt);
|
|
2089
2089
|
}
|
|
2090
2090
|
createDefaultShader() {
|
|
2091
|
-
return this.vs =
|
|
2091
|
+
return this.vs = Ht, this.fs = Vt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
|
|
2092
2092
|
}
|
|
2093
2093
|
createMaskShader(t, e) {
|
|
2094
|
-
const r = this.gl, i = new
|
|
2094
|
+
const r = this.gl, i = new wt(r, t, e);
|
|
2095
2095
|
return i.use(), i.bindVAO(), this.vertexBuffer.bindBuffer(), i.setAttributes([
|
|
2096
|
-
{ name: "aPosition", size: 2, type: r.FLOAT, stride:
|
|
2097
|
-
{ name: "aUV", size: 2, type: r.FLOAT, stride:
|
|
2096
|
+
{ name: "aPosition", size: 2, type: r.FLOAT, stride: K - 4, offset: 0, divisor: 0 },
|
|
2097
|
+
{ name: "aUV", size: 2, type: r.FLOAT, stride: K - 4, offset: 8, divisor: 0 }
|
|
2098
2098
|
]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
|
|
2099
2099
|
}
|
|
2100
2100
|
createShader(t, e) {
|
|
2101
2101
|
const r = this.gl, i = super.createShader(t, e);
|
|
2102
2102
|
return i.use(), i.bindVAO(), this.vertexBuffer.bindBuffer(), i.setAttributes([
|
|
2103
|
-
{ name: "aPosition", size: 2, type: r.FLOAT, stride:
|
|
2104
|
-
{ name: "aColor", size: 4, type: r.UNSIGNED_BYTE, normalized: !0, stride:
|
|
2105
|
-
{ name: "aUV", size: 2, type: r.FLOAT, stride:
|
|
2103
|
+
{ name: "aPosition", size: 2, type: r.FLOAT, stride: K, offset: 0, divisor: 0 },
|
|
2104
|
+
{ name: "aColor", size: 4, type: r.UNSIGNED_BYTE, normalized: !0, stride: K, offset: 8, divisor: 0 },
|
|
2105
|
+
{ name: "aUV", size: 2, type: r.FLOAT, stride: K, offset: 12, divisor: 0 }
|
|
2106
2106
|
]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
|
|
2107
2107
|
}
|
|
2108
2108
|
/**
|
|
@@ -2271,7 +2271,7 @@ class p {
|
|
|
2271
2271
|
return new p(Math.cos(t), Math.sin(t));
|
|
2272
2272
|
}
|
|
2273
2273
|
}
|
|
2274
|
-
const
|
|
2274
|
+
const jt = (n, t) => {
|
|
2275
2275
|
const [e, r, i, s, a, o] = t, h = new Float32Array([
|
|
2276
2276
|
e,
|
|
2277
2277
|
i,
|
|
@@ -2290,8 +2290,8 @@ const Vt = (n, t) => {
|
|
|
2290
2290
|
0,
|
|
2291
2291
|
1
|
|
2292
2292
|
]);
|
|
2293
|
-
return
|
|
2294
|
-
},
|
|
2293
|
+
return $t(h, n);
|
|
2294
|
+
}, $t = (n, t) => {
|
|
2295
2295
|
const e = new Float32Array(16);
|
|
2296
2296
|
for (let r = 0; r < 4; r++)
|
|
2297
2297
|
for (let i = 0; i < 4; i++) {
|
|
@@ -2302,15 +2302,15 @@ const Vt = (n, t) => {
|
|
|
2302
2302
|
}
|
|
2303
2303
|
return e;
|
|
2304
2304
|
};
|
|
2305
|
-
var
|
|
2306
|
-
const
|
|
2305
|
+
var Kt = /* @__PURE__ */ ((n) => (n[n.STRETCH = 0] = "STRETCH", n[n.REPEAT = 1] = "REPEAT", n))(Kt || {});
|
|
2306
|
+
const rt = 10, xt = (n, t, e, r, i, s) => {
|
|
2307
2307
|
const a = [], o = [], h = r ? Math.atan2(t.y, t.x) : Math.atan2(-t.y, -t.x), c = Math.PI, u = new p(t.y, -t.x);
|
|
2308
|
-
for (let l = 0; l <
|
|
2309
|
-
const d = l /
|
|
2310
|
-
a.push(n), o.push(new p(i, 0.5)), a.push(n.add(
|
|
2308
|
+
for (let l = 0; l < rt; l++) {
|
|
2309
|
+
const d = l / rt, f = (l + 1) / rt, m = h + d * c, v = h + f * c, y = new p(Math.cos(m) * e, Math.sin(m) * e), T = new p(Math.cos(v) * e, Math.sin(v) * e);
|
|
2310
|
+
a.push(n), o.push(new p(i, 0.5)), a.push(n.add(y)), o.push(new p(i + y.dot(u) * s, 0.5 - 0.5 * y.dot(t) / e)), a.push(n.add(T)), o.push(new p(i + T.dot(u) * s, 0.5 - 0.5 * T.dot(t) / e));
|
|
2311
2311
|
}
|
|
2312
2312
|
return { vertices: a, uv: o };
|
|
2313
|
-
},
|
|
2313
|
+
}, qt = (n, t = !1) => {
|
|
2314
2314
|
const e = [];
|
|
2315
2315
|
if (n.length < 2 || t && n.length < 3) return { normals: e, length: 0 };
|
|
2316
2316
|
const r = 4, i = 1e-3, s = n.length;
|
|
@@ -2330,8 +2330,8 @@ const tt = 10, lt = (n, t, e, r, i, s) => {
|
|
|
2330
2330
|
{
|
|
2331
2331
|
let m = d.add(l).normalize();
|
|
2332
2332
|
l.cross(d) < 0 && (m = m.multiply(-1));
|
|
2333
|
-
let
|
|
2334
|
-
return { normal: m, miters: Math.min(
|
|
2333
|
+
let v = 1 / Math.sqrt((1 - f) / 2);
|
|
2334
|
+
return { normal: m, miters: Math.min(v, r) };
|
|
2335
2335
|
}
|
|
2336
2336
|
};
|
|
2337
2337
|
if (t)
|
|
@@ -2350,27 +2350,27 @@ const tt = 10, lt = (n, t, e, r, i, s) => {
|
|
|
2350
2350
|
} else
|
|
2351
2351
|
e.push(o(n[h - 1], n[h], n[h + 1]));
|
|
2352
2352
|
return { normals: e, length: a };
|
|
2353
|
-
},
|
|
2353
|
+
}, Qt = (n) => {
|
|
2354
2354
|
const t = n.points;
|
|
2355
2355
|
if (t.length < 2) return { vertices: [], uv: [] };
|
|
2356
|
-
const { normals: e, length: r } =
|
|
2356
|
+
const { normals: e, length: r } = qt(t, n.closed), i = (n.width || 1) / 2, s = [], a = [], o = n.roundCap || !1, h = n.textureMode || 0;
|
|
2357
2357
|
let c = 0;
|
|
2358
2358
|
const u = n.texture?.rawWidth || 1, l = n.closed ? t.length : t.length - 1;
|
|
2359
2359
|
for (let d = 0; d < l; d++) {
|
|
2360
|
-
const f = t[d], m = e[d].normal,
|
|
2361
|
-
let
|
|
2362
|
-
h === 0 ? (
|
|
2363
|
-
const
|
|
2364
|
-
s.push(P), a.push(
|
|
2360
|
+
const f = t[d], m = e[d].normal, v = e[d].miters, y = (d + 1) % t.length, T = t[y], M = e[y].normal, A = e[y].miters, P = f.add(m.multiply(v * i)), C = f.subtract(m.multiply(v * i)), F = T.add(M.multiply(A * i)), W = T.subtract(M.multiply(A * i)), N = f.distanceTo(T);
|
|
2361
|
+
let w = 0, U = 0;
|
|
2362
|
+
h === 0 ? (w = c / r, U = (c + N) / r) : (w = c / u, U = w + N / u);
|
|
2363
|
+
const X = new p(w, 0), k = new p(w, 1), G = new p(U, 0), I = new p(U, 1);
|
|
2364
|
+
s.push(P), a.push(X), s.push(C), a.push(k), s.push(F), a.push(G), s.push(F), a.push(G), s.push(W), a.push(I), s.push(C), a.push(k), c += N;
|
|
2365
2365
|
}
|
|
2366
2366
|
if (o && !n.closed) {
|
|
2367
|
-
const d = t[0], f = e[0].normal, m = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u,
|
|
2368
|
-
s.push(...
|
|
2369
|
-
const
|
|
2367
|
+
const d = t[0], f = e[0].normal, m = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u, v = xt(d, f, i, !0, 0, m);
|
|
2368
|
+
s.push(...v.vertices), a.push(...v.uv);
|
|
2369
|
+
const y = t[t.length - 1], T = e[t.length - 1].normal, M = h === 0 ? 1 : c / u, A = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u, P = xt(y, T, i, !1, M, A);
|
|
2370
2370
|
s.push(...P.vertices), a.push(...P.uv);
|
|
2371
2371
|
}
|
|
2372
2372
|
return { vertices: s, uv: a };
|
|
2373
|
-
},
|
|
2373
|
+
}, Z = (n, t, e, r) => {
|
|
2374
2374
|
if (t.customMatrix !== void 0)
|
|
2375
2375
|
return t.customMatrix;
|
|
2376
2376
|
if (t.modifyStack) {
|
|
@@ -2389,8 +2389,8 @@ const tt = 10, lt = (n, t, e, r, i, s) => {
|
|
|
2389
2389
|
i
|
|
2390
2390
|
), i;
|
|
2391
2391
|
}
|
|
2392
|
-
},
|
|
2393
|
-
const e =
|
|
2392
|
+
}, Zt = (n, t) => t ? n ? t.premultipliedUint32 : t.uint32 : 4294967295, Jt = 2, te = (n, t) => {
|
|
2393
|
+
const e = Z(n, t, t.texture.rawWidth, t.texture.rawHeight), r = t.texture;
|
|
2394
2394
|
if (!r?.base || n.inCreateMask)
|
|
2395
2395
|
return;
|
|
2396
2396
|
const i = r.isAtlas ? n.atlasSpriteRegion : n.spriteRegion;
|
|
@@ -2398,7 +2398,7 @@ const tt = 10, lt = (n, t, e, r, i, s) => {
|
|
|
2398
2398
|
let s = r.uvX, a = r.uvY, o = r.uvW, h = r.uvH;
|
|
2399
2399
|
const c = !!t.flipX, u = !!t.flipY != !!r.flipY;
|
|
2400
2400
|
let l = t.padding ?? i.currentShader.padding;
|
|
2401
|
-
r.isAtlas && (l +=
|
|
2401
|
+
r.isAtlas && (l += Jt);
|
|
2402
2402
|
const d = s <= o ? l : -l, f = a <= h ? l : -l;
|
|
2403
2403
|
i.drawSprite(
|
|
2404
2404
|
r,
|
|
@@ -2414,7 +2414,7 @@ const tt = 10, lt = (n, t, e, r, i, s) => {
|
|
|
2414
2414
|
u,
|
|
2415
2415
|
r.isRotated
|
|
2416
2416
|
);
|
|
2417
|
-
},
|
|
2417
|
+
}, ee = (n, t) => {
|
|
2418
2418
|
const e = n.particleRegion;
|
|
2419
2419
|
n.enterRegion(e, t.shader);
|
|
2420
2420
|
const r = t.texture, i = t.count ?? t.x.length, s = t.color;
|
|
@@ -2427,10 +2427,10 @@ const tt = 10, lt = (n, t, e, r, i, s) => {
|
|
|
2427
2427
|
i,
|
|
2428
2428
|
t.scaleX,
|
|
2429
2429
|
t.scaleY,
|
|
2430
|
-
r.uvX,
|
|
2431
|
-
r.uvY,
|
|
2432
|
-
r.uvW,
|
|
2433
|
-
r.uvH,
|
|
2430
|
+
t.u0 ?? r.uvX,
|
|
2431
|
+
t.v0 ?? r.uvY,
|
|
2432
|
+
t.u1 ?? r.uvW,
|
|
2433
|
+
t.v1 ?? r.uvH,
|
|
2434
2434
|
t.flipX,
|
|
2435
2435
|
t.flipY,
|
|
2436
2436
|
r.isRotated,
|
|
@@ -2440,9 +2440,9 @@ const tt = 10, lt = (n, t, e, r, i, s) => {
|
|
|
2440
2440
|
t.reverseOrder,
|
|
2441
2441
|
t.customMatrix
|
|
2442
2442
|
);
|
|
2443
|
-
},
|
|
2443
|
+
}, St = (n, t) => {
|
|
2444
2444
|
if (t.points.length === 0) return;
|
|
2445
|
-
const e =
|
|
2445
|
+
const e = Z(n, t, 0, 0);
|
|
2446
2446
|
n.startGraphic(
|
|
2447
2447
|
t.drawMode ?? n.gl.TRIANGLES,
|
|
2448
2448
|
t.texture,
|
|
@@ -2460,18 +2460,18 @@ const tt = 10, lt = (n, t, e, r, i, s) => {
|
|
|
2460
2460
|
);
|
|
2461
2461
|
}
|
|
2462
2462
|
n.endGraphic();
|
|
2463
|
-
},
|
|
2463
|
+
}, re = (n, t) => {
|
|
2464
2464
|
if (n.inCreateMask)
|
|
2465
2465
|
return;
|
|
2466
|
-
const { vertices: e, uv: r } =
|
|
2467
|
-
|
|
2466
|
+
const { vertices: e, uv: r } = Qt(t);
|
|
2467
|
+
St(n, {
|
|
2468
2468
|
...t,
|
|
2469
2469
|
points: e,
|
|
2470
2470
|
uv: r,
|
|
2471
2471
|
drawMode: n.gl.TRIANGLES
|
|
2472
2472
|
});
|
|
2473
|
-
},
|
|
2474
|
-
const e =
|
|
2473
|
+
}, ie = (n, t) => {
|
|
2474
|
+
const e = Z(
|
|
2475
2475
|
n,
|
|
2476
2476
|
t,
|
|
2477
2477
|
t.texture.rawWidth,
|
|
@@ -2482,16 +2482,16 @@ const tt = 10, lt = (n, t, e, r, i, s) => {
|
|
|
2482
2482
|
t.texture,
|
|
2483
2483
|
e ?? t.customMatrix
|
|
2484
2484
|
), n.addRectVertex(t.texture.rawWidth, t.texture.rawHeight), n.endGraphic();
|
|
2485
|
-
},
|
|
2486
|
-
const e =
|
|
2485
|
+
}, se = (n, t) => {
|
|
2486
|
+
const e = Z(n, t, t.width, t.height);
|
|
2487
2487
|
n.startGraphic(
|
|
2488
2488
|
n.gl.TRIANGLE_FAN,
|
|
2489
2489
|
t.texture,
|
|
2490
2490
|
t.shader,
|
|
2491
2491
|
e ?? t.customMatrix
|
|
2492
2492
|
), n.addRectVertex(t.width, t.height, t.color), n.endGraphic();
|
|
2493
|
-
},
|
|
2494
|
-
const e = t.segments ?? 32, r =
|
|
2493
|
+
}, ne = (n, t) => {
|
|
2494
|
+
const e = t.segments ?? 32, r = Z(n, t, 0, 0);
|
|
2495
2495
|
n.startGraphic(
|
|
2496
2496
|
n.gl.TRIANGLE_FAN,
|
|
2497
2497
|
void 0,
|
|
@@ -2500,7 +2500,7 @@ const tt = 10, lt = (n, t, e, r, i, s) => {
|
|
|
2500
2500
|
);
|
|
2501
2501
|
const i = n.getColorUint32(t.color);
|
|
2502
2502
|
n.addGraphicVertex(0, 0, 0.5, 0.5, i), n.addCircleVertex(t.radius, t.color, e), n.addGraphicVertex(t.radius, 0, 1, 0.5, i), n.endGraphic();
|
|
2503
|
-
},
|
|
2503
|
+
}, pt = `#version 300 es\r
|
|
2504
2504
|
precision mediump float;\r
|
|
2505
2505
|
\r
|
|
2506
2506
|
uniform sampler2D uTextures[%TEXTURE_NUM%];\r
|
|
@@ -2550,21 +2550,21 @@ void main(void) {\r
|
|
|
2550
2550
|
// CUSTOM_CODE_CALL\r
|
|
2551
2551
|
}\r
|
|
2552
2552
|
`;
|
|
2553
|
-
class
|
|
2553
|
+
class ae extends ot {
|
|
2554
2554
|
KEY = "AtlasSprite";
|
|
2555
2555
|
constructor(t) {
|
|
2556
2556
|
super(t);
|
|
2557
2557
|
}
|
|
2558
2558
|
createCustomShader(t) {
|
|
2559
|
-
const e = V(
|
|
2559
|
+
const e = V(pt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = V(tt, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
|
|
2560
2560
|
return t.getGLShader(this, this.KEY, r, e);
|
|
2561
2561
|
}
|
|
2562
2562
|
createDefaultShader() {
|
|
2563
|
-
const t = this.rapid, e = V(
|
|
2563
|
+
const t = this.rapid, e = V(pt, t.maxTextureUnits), r = V(tt, t.maxTextureUnits);
|
|
2564
2564
|
return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
|
|
2565
2565
|
}
|
|
2566
2566
|
}
|
|
2567
|
-
const
|
|
2567
|
+
const gt = `#version 300 es\r
|
|
2568
2568
|
precision highp float;\r
|
|
2569
2569
|
\r
|
|
2570
2570
|
// per-vertex\r
|
|
@@ -2605,7 +2605,7 @@ void main(void) {\r
|
|
|
2605
2605
|
\r
|
|
2606
2606
|
gl_Position = u_projection * vec4(v, 0.0, 1.0);\r
|
|
2607
2607
|
}\r
|
|
2608
|
-
`,
|
|
2608
|
+
`, vt = `#version 300 es\r
|
|
2609
2609
|
precision mediump float;\r
|
|
2610
2610
|
\r
|
|
2611
2611
|
uniform sampler2D uTexture;\r
|
|
@@ -2621,8 +2621,8 @@ void main(void) {\r
|
|
|
2621
2621
|
\r
|
|
2622
2622
|
// CUSTOM_CODE_CALL\r
|
|
2623
2623
|
}\r
|
|
2624
|
-
`,
|
|
2625
|
-
class
|
|
2624
|
+
`, Y = 48, yt = Y / 4;
|
|
2625
|
+
class he extends ot {
|
|
2626
2626
|
KEY = "ParticleSprite";
|
|
2627
2627
|
texture;
|
|
2628
2628
|
customMatrix;
|
|
@@ -2630,10 +2630,10 @@ class ie extends at {
|
|
|
2630
2630
|
super(t);
|
|
2631
2631
|
}
|
|
2632
2632
|
createCustomShader(t) {
|
|
2633
|
-
return t.getGLShader(this, this.KEY,
|
|
2633
|
+
return t.getGLShader(this, this.KEY, gt, vt);
|
|
2634
2634
|
}
|
|
2635
2635
|
createDefaultShader() {
|
|
2636
|
-
const t =
|
|
2636
|
+
const t = vt, e = gt;
|
|
2637
2637
|
return this.vs = e, this.fs = t, this.defaultShader = this.createShader(e, t), this.defaultShader;
|
|
2638
2638
|
}
|
|
2639
2639
|
enter(t) {
|
|
@@ -2642,44 +2642,50 @@ class ie extends at {
|
|
|
2642
2642
|
createShader(t, e) {
|
|
2643
2643
|
const r = super.createShader(t, e);
|
|
2644
2644
|
return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
|
|
2645
|
-
{ name: "aPosition", size: 2, stride:
|
|
2646
|
-
{ name: "aScale", size: 2, stride:
|
|
2647
|
-
{ name: "aRotation", size: 1, stride:
|
|
2648
|
-
{ name: "aUVRect", size: 4, stride:
|
|
2649
|
-
{ name: "aColor", size: 4, type:
|
|
2650
|
-
{ name: "aOrigin", size: 2, stride:
|
|
2645
|
+
{ name: "aPosition", size: 2, stride: Y, offset: 0, divisor: 1 },
|
|
2646
|
+
{ name: "aScale", size: 2, stride: Y, offset: 8, divisor: 1 },
|
|
2647
|
+
{ name: "aRotation", size: 1, stride: Y, offset: 16, divisor: 1 },
|
|
2648
|
+
{ name: "aUVRect", size: 4, stride: Y, offset: 20, divisor: 1 },
|
|
2649
|
+
{ name: "aColor", size: 4, type: at, normalized: !0, stride: Y, offset: 36, divisor: 1 },
|
|
2650
|
+
{ name: "aOrigin", size: 2, stride: Y, offset: 40, divisor: 1 }
|
|
2651
2651
|
]), this.quadBuffer.bindBuffer(), r.setAttributes([
|
|
2652
2652
|
{ name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
|
|
2653
2653
|
]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
|
|
2654
2654
|
}
|
|
2655
|
-
drawParticles(t, e, r, i = 0, s = 4294967295, a, o = 1, h = 1, c = 0, u = 0, l = 1, d = 1, f = !1, m = !1,
|
|
2655
|
+
drawParticles(t, e, r, i = 0, s = 4294967295, a, o = 1, h = 1, c = 0, u = 0, l = 1, d = 1, f = !1, m = !1, v = !1, y = 0.5, T = 0.5, M, A = !1, P) {
|
|
2656
2656
|
if (!t.glTexture || a <= 0) return;
|
|
2657
|
-
let
|
|
2658
|
-
const
|
|
2657
|
+
let C = 0;
|
|
2658
|
+
const F = typeof o == "number", W = typeof h == "number", N = typeof i == "number", w = typeof s == "number", U = typeof c == "number", X = !w && typeof s[0] == "number";
|
|
2659
2659
|
let k = t.rawWidth * (f ? -1 : 1);
|
|
2660
|
-
|
|
2660
|
+
F && (k *= o);
|
|
2661
2661
|
let G = t.rawHeight * (m ? -1 : 1);
|
|
2662
|
-
|
|
2663
|
-
let
|
|
2664
|
-
for (N && (
|
|
2662
|
+
W && (G *= h), U && (G *= d - u, k *= l - c);
|
|
2663
|
+
let I = v ? Math.PI / 2 : 0;
|
|
2664
|
+
for (N && (I += i); C < a; ) {
|
|
2665
2665
|
this.texture && t !== this.texture && this.flush(), this.texture || (this.texture = t, this.useTexture(t.glTexture, 0, 0));
|
|
2666
|
-
const
|
|
2667
|
-
let
|
|
2668
|
-
|
|
2669
|
-
const
|
|
2670
|
-
for (let
|
|
2671
|
-
const
|
|
2672
|
-
if (
|
|
2673
|
-
|
|
2674
|
-
else
|
|
2675
|
-
|
|
2666
|
+
const B = a - C, H = this.instanceBuffer;
|
|
2667
|
+
let R = H.usedElemNum;
|
|
2668
|
+
H.resize(B * yt);
|
|
2669
|
+
const g = H.float32, S = H.uint32;
|
|
2670
|
+
for (let J = 0; J < B; J++) {
|
|
2671
|
+
const D = A ? a - 1 - C - J : C + J;
|
|
2672
|
+
if (g[R] = e[D], g[R + 1] = r[D], g[R + 2] = F ? k : k * o[D], g[R + 3] = W ? G : G * h[D], g[R + 4] = N ? I : i[D] + I, U)
|
|
2673
|
+
g[R + 5] = c, g[R + 6] = u, g[R + 7] = l, g[R + 8] = d;
|
|
2674
|
+
else {
|
|
2675
|
+
const j = c[D], ct = u[D], ut = l[D], lt = d[D];
|
|
2676
|
+
g[R + 5] = j, g[R + 6] = ct, g[R + 7] = ut, g[R + 8] = lt, g[R + 2] *= lt - ct, g[R + 3] *= ut - j;
|
|
2677
|
+
}
|
|
2678
|
+
if (w)
|
|
2679
|
+
S[R + 9] = 4294967295;
|
|
2680
|
+
else if (X)
|
|
2681
|
+
S[R + 9] = s[D];
|
|
2676
2682
|
else {
|
|
2677
|
-
const
|
|
2678
|
-
|
|
2683
|
+
const j = s[D];
|
|
2684
|
+
S[R + 9] = M ? j.premultipliedUint32 : j.uint32;
|
|
2679
2685
|
}
|
|
2680
|
-
|
|
2686
|
+
g[R + 10] = y, g[R + 11] = T, R += yt;
|
|
2681
2687
|
}
|
|
2682
|
-
|
|
2688
|
+
H.usedElemNum = R, H.makeDirty(), this.instanceCount += B, C += B;
|
|
2683
2689
|
}
|
|
2684
2690
|
this.customMatrix = P, this.flush();
|
|
2685
2691
|
}
|
|
@@ -2690,12 +2696,12 @@ class ie extends at {
|
|
|
2690
2696
|
this.texture && (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.texture.glTexture));
|
|
2691
2697
|
const e = this.currentShader;
|
|
2692
2698
|
this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO();
|
|
2693
|
-
const r = this.rapid.matrixStack, s = this.rapid.matrix.getMatrix(this.customMatrix ?? r.curWorldM), a =
|
|
2694
|
-
this.currentShader.setUniform("u_projection", a),
|
|
2699
|
+
const r = this.rapid.matrixStack, s = this.rapid.matrix.getMatrix(this.customMatrix ?? r.curWorldM), a = jt(this.rapid.projection, s);
|
|
2700
|
+
this.currentShader.setUniform("u_projection", a), Mt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++, this.texture = void 0, this.customMatrix = void 0;
|
|
2695
2701
|
}
|
|
2696
2702
|
}
|
|
2697
|
-
var
|
|
2698
|
-
class
|
|
2703
|
+
var oe = /* @__PURE__ */ ((n) => (n[n.EQUAL = 0] = "EQUAL", n[n.NOT_EQUAL = 1] = "NOT_EQUAL", n))(oe || {}), ce = /* @__PURE__ */ ((n) => (n[n.NORMAL = 0] = "NORMAL", n[n.ADD = 1] = "ADD", n[n.MULTIPLY = 2] = "MULTIPLY", n[n.SCREEN = 3] = "SCREEN", n[n.ERASE = 4] = "ERASE", n))(ce || {}), ht = /* @__PURE__ */ ((n) => (n[n.LINEAR = 0] = "LINEAR", n[n.NEAREST = 1] = "NEAREST", n))(ht || {}), ue = /* @__PURE__ */ ((n) => (n[n.CanvasItem = 0] = "CanvasItem", n[n.Viewport = 1] = "Viewport", n))(ue || {});
|
|
2704
|
+
class fe {
|
|
2699
2705
|
/** The active WebGL context. */
|
|
2700
2706
|
gl;
|
|
2701
2707
|
/** The target HTMLCanvasElement. */
|
|
@@ -2721,7 +2727,7 @@ class ce {
|
|
|
2721
2727
|
/** Maximum number of texture units supported by the device. */
|
|
2722
2728
|
maxTextureUnits = 0;
|
|
2723
2729
|
/** Matrix stack for hierarchical transformations. */
|
|
2724
|
-
matrixStack = new
|
|
2730
|
+
matrixStack = new Ct(this);
|
|
2725
2731
|
/** Direct access to the underlying matrix store. */
|
|
2726
2732
|
matrix;
|
|
2727
2733
|
/** Region dedicated to fast sprite rendering. */
|
|
@@ -2746,7 +2752,7 @@ class ce {
|
|
|
2746
2752
|
scaleMode;
|
|
2747
2753
|
/** Internal ping-pong RenderTextures for multi-filter chains. */
|
|
2748
2754
|
_filterRT = [null, null];
|
|
2749
|
-
_filterInput = new
|
|
2755
|
+
_filterInput = new O();
|
|
2750
2756
|
get height() {
|
|
2751
2757
|
return this.logicHeight;
|
|
2752
2758
|
}
|
|
@@ -2759,10 +2765,10 @@ class ce {
|
|
|
2759
2765
|
*/
|
|
2760
2766
|
constructor(t) {
|
|
2761
2767
|
this.canvas = t.canvas, this.dpr = window.devicePixelRatio || 1, this.antialias = t.antialias ?? !1, this.textureFilter = t.textureFilter ?? 1, this.premultipliedAlpha = t.premultipliedAlpha ?? !0, this.roundPixels = t.roundPixels ?? !1, this.scaleMode = t.scaleMode ?? 0;
|
|
2762
|
-
const e =
|
|
2763
|
-
this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new
|
|
2768
|
+
const e = It(this.canvas, this.antialias, this.premultipliedAlpha);
|
|
2769
|
+
this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new ot(this), this.graphicRegion = new Xt(this), this.atlasSpriteRegion = new ae(this), this.particleRegion = new he(this);
|
|
2764
2770
|
const r = this.canvas.clientWidth || this.canvas.width, i = this.canvas.clientHeight || this.canvas.height;
|
|
2765
|
-
this.physicsWidth = t.physicsWidth || Math.round(r * this.dpr), this.physicsHeight = t.physicsHeight || Math.round(i * this.dpr), this.logicWidth = t.logicWidth || t.width || this.physicsWidth / this.dpr, this.logicHeight = t.logicHeight || t.height || this.physicsHeight / this.dpr, this.resize(this.logicWidth, this.logicHeight, this.physicsWidth, this.physicsHeight), this.texture = new
|
|
2771
|
+
this.physicsWidth = t.physicsWidth || Math.round(r * this.dpr), this.physicsHeight = t.physicsHeight || Math.round(i * this.dpr), this.logicWidth = t.logicWidth || t.width || this.physicsWidth / this.dpr, this.logicHeight = t.logicHeight || t.height || this.physicsHeight / this.dpr, this.resize(this.logicWidth, this.logicHeight, this.physicsWidth, this.physicsHeight), this.texture = new _t(this), t.backgroundColor && (this.backgroundColor = t.backgroundColor), e.enable(e.BLEND), this.premultipliedAlpha ? e.blendFunc(e.ONE, e.ONE_MINUS_SRC_ALPHA) : e.blendFunc(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA), e.enable(e.STENCIL_TEST), e.stencilFunc(e.ALWAYS, 1, 255), e.stencilOp(e.KEEP, e.KEEP, e.KEEP);
|
|
2766
2772
|
}
|
|
2767
2773
|
setTextureFilter(t) {
|
|
2768
2774
|
this.textureFilter = t;
|
|
@@ -2771,7 +2777,7 @@ class ce {
|
|
|
2771
2777
|
this.antialias = t;
|
|
2772
2778
|
}
|
|
2773
2779
|
getColorUint32(t) {
|
|
2774
|
-
return
|
|
2780
|
+
return Zt(this.premultipliedAlpha, t);
|
|
2775
2781
|
}
|
|
2776
2782
|
/**
|
|
2777
2783
|
* Enters a specific rendering region, flushing the previous one if necessary.
|
|
@@ -2782,22 +2788,22 @@ class ce {
|
|
|
2782
2788
|
this.currentRegion === t && this.currentRegion.isSameShader(e) || (this.flush(), this.currentRegion = t, t.enter(e));
|
|
2783
2789
|
}
|
|
2784
2790
|
drawParticles(t) {
|
|
2785
|
-
|
|
2791
|
+
ee(this, t);
|
|
2786
2792
|
}
|
|
2787
2793
|
drawSprite(t) {
|
|
2788
|
-
|
|
2794
|
+
te(this, t);
|
|
2789
2795
|
}
|
|
2790
2796
|
drawLine(t) {
|
|
2791
|
-
|
|
2797
|
+
re(this, t);
|
|
2792
2798
|
}
|
|
2793
2799
|
drawGraphic(t) {
|
|
2794
|
-
|
|
2800
|
+
St(this, t);
|
|
2795
2801
|
}
|
|
2796
2802
|
drawRect(t) {
|
|
2797
|
-
|
|
2803
|
+
se(this, t);
|
|
2798
2804
|
}
|
|
2799
2805
|
drawCircle(t) {
|
|
2800
|
-
|
|
2806
|
+
ne(this, t);
|
|
2801
2807
|
}
|
|
2802
2808
|
/**
|
|
2803
2809
|
* Starts rendering arbitrary graphics geometries.
|
|
@@ -2821,7 +2827,7 @@ class ce {
|
|
|
2821
2827
|
* @param texture The texture to be used as a mask.
|
|
2822
2828
|
*/
|
|
2823
2829
|
drawMaskImage(t) {
|
|
2824
|
-
|
|
2830
|
+
ie(this, t);
|
|
2825
2831
|
}
|
|
2826
2832
|
/**
|
|
2827
2833
|
* Pushes vertices for a rectangle geometry. Should be enclosed by startGraphic and endGraphic.
|
|
@@ -3177,7 +3183,7 @@ class ce {
|
|
|
3177
3183
|
endScissor() {
|
|
3178
3184
|
this.flush(), this.gl.disable(this.gl.SCISSOR_TEST);
|
|
3179
3185
|
}
|
|
3180
|
-
|
|
3186
|
+
applyCamera(t) {
|
|
3181
3187
|
this.matrixStack.applyTransform(t);
|
|
3182
3188
|
const e = this.matrixStack.curWorldM;
|
|
3183
3189
|
this.matrix.invert(e);
|
|
@@ -3217,10 +3223,10 @@ class ce {
|
|
|
3217
3223
|
return this.matrix.toCSSMatrix(t ?? this.matrixStack.curWorldM, e, r);
|
|
3218
3224
|
}
|
|
3219
3225
|
}
|
|
3220
|
-
function
|
|
3226
|
+
function le(n) {
|
|
3221
3227
|
return !(n === null || typeof n != "object" || Array.isArray(n) || n instanceof p || n instanceof x);
|
|
3222
3228
|
}
|
|
3223
|
-
class
|
|
3229
|
+
class L {
|
|
3224
3230
|
/** Random float in [min, max). */
|
|
3225
3231
|
static float(t, e) {
|
|
3226
3232
|
return Math.random() * (e - t) + t;
|
|
@@ -3235,20 +3241,20 @@ class F {
|
|
|
3235
3241
|
}
|
|
3236
3242
|
/** Random Vec2 with components in the supplied per-axis ranges. */
|
|
3237
3243
|
static vector(t, e, r, i) {
|
|
3238
|
-
return new p(
|
|
3244
|
+
return new p(L.float(t, e), L.float(r, i));
|
|
3239
3245
|
}
|
|
3240
3246
|
/** Random Color with each component interpolated between minColor and maxColor. */
|
|
3241
3247
|
static randomColor(t, e) {
|
|
3242
3248
|
return new x(
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3249
|
+
L.float(t.r, e.r),
|
|
3250
|
+
L.float(t.g, e.g),
|
|
3251
|
+
L.float(t.b, e.b),
|
|
3252
|
+
L.float(t.a, e.a)
|
|
3247
3253
|
);
|
|
3248
3254
|
}
|
|
3249
3255
|
/** Pick a random element from an array with uniform probability. */
|
|
3250
3256
|
static pick(t) {
|
|
3251
|
-
return t[
|
|
3257
|
+
return t[L.int(0, t.length - 1)];
|
|
3252
3258
|
}
|
|
3253
3259
|
/**
|
|
3254
3260
|
* Pick a random element using weighted probability.
|
|
@@ -3274,18 +3280,18 @@ class F {
|
|
|
3274
3280
|
if (Array.isArray(t)) {
|
|
3275
3281
|
const [r, i] = t;
|
|
3276
3282
|
if (typeof r == "number")
|
|
3277
|
-
return
|
|
3283
|
+
return L.float(r, i);
|
|
3278
3284
|
if (r instanceof p)
|
|
3279
|
-
return
|
|
3285
|
+
return L.vector(r.x, i.x, r.y, i.y);
|
|
3280
3286
|
if (r instanceof x)
|
|
3281
|
-
return
|
|
3287
|
+
return L.randomColor(r, i);
|
|
3282
3288
|
}
|
|
3283
3289
|
return typeof t == "number" ? t : t.clone();
|
|
3284
3290
|
}
|
|
3285
3291
|
}
|
|
3286
|
-
var
|
|
3287
|
-
const
|
|
3288
|
-
class
|
|
3292
|
+
var de = /* @__PURE__ */ ((n) => (n.POINT = "point", n.CIRCLE = "circle", n.RECT = "rect", n))(de || {});
|
|
3293
|
+
const Tt = 10, Et = 0, Rt = !0;
|
|
3294
|
+
class q {
|
|
3289
3295
|
components;
|
|
3290
3296
|
constructor(t = 1) {
|
|
3291
3297
|
if (!Number.isInteger(t) || t <= 0)
|
|
@@ -3326,13 +3332,13 @@ class K {
|
|
|
3326
3332
|
}
|
|
3327
3333
|
}
|
|
3328
3334
|
resolveComponent(t, e, r) {
|
|
3329
|
-
return t === void 0 ? r : Array.isArray(t) ?
|
|
3335
|
+
return t === void 0 ? r : Array.isArray(t) ? L.float(
|
|
3330
3336
|
this.getComponent(t[0], e),
|
|
3331
3337
|
this.getComponent(t[1], e)
|
|
3332
3338
|
) : this.getComponent(t, e);
|
|
3333
3339
|
}
|
|
3334
3340
|
create(t, e, r = 1) {
|
|
3335
|
-
const i =
|
|
3341
|
+
const i = le(t) ? t : void 0, s = i === void 0 ? t : void 0, a = r > 0 ? r : 1;
|
|
3336
3342
|
let o = 0;
|
|
3337
3343
|
for (let h = 0; h < this.components.length; h++) {
|
|
3338
3344
|
const { value: c, delta: u, damping: l } = this.components[h], d = this.getComponent(e, h), f = s === void 0 ? this.resolveComponent(i?.start, h, d) : this.getComponent(s, h), m = i?.end === void 0 ? f : this.resolveComponent(i.end, h, d);
|
|
@@ -3341,15 +3347,15 @@ class K {
|
|
|
3341
3347
|
return o;
|
|
3342
3348
|
}
|
|
3343
3349
|
}
|
|
3344
|
-
class
|
|
3350
|
+
class bt {
|
|
3345
3351
|
options;
|
|
3346
3352
|
emitting = !1;
|
|
3347
3353
|
emitTimer = 0;
|
|
3348
|
-
emitRate =
|
|
3349
|
-
emitTime =
|
|
3354
|
+
emitRate = Tt;
|
|
3355
|
+
emitTime = Et;
|
|
3350
3356
|
emitTimeCounter = 0;
|
|
3351
3357
|
/** Whether spawned particles are positioned in local emitter space (default: true). */
|
|
3352
|
-
localSpace =
|
|
3358
|
+
localSpace = Rt;
|
|
3353
3359
|
rapid;
|
|
3354
3360
|
x = new _(b.Float32);
|
|
3355
3361
|
y = new _(b.Float32);
|
|
@@ -3358,11 +3364,11 @@ class Mt {
|
|
|
3358
3364
|
rotation = new _(b.Float32);
|
|
3359
3365
|
color = new _(b.Uint32);
|
|
3360
3366
|
animations = {
|
|
3361
|
-
speed: new
|
|
3362
|
-
rotation: new
|
|
3363
|
-
scale: new
|
|
3364
|
-
color: new
|
|
3365
|
-
velocity: new
|
|
3367
|
+
speed: new q(),
|
|
3368
|
+
rotation: new q(),
|
|
3369
|
+
scale: new q(),
|
|
3370
|
+
color: new q(4),
|
|
3371
|
+
velocity: new q(2)
|
|
3366
3372
|
};
|
|
3367
3373
|
count = 0;
|
|
3368
3374
|
/**
|
|
@@ -3371,7 +3377,7 @@ class Mt {
|
|
|
3371
3377
|
* @param options - Emitter configuration options
|
|
3372
3378
|
*/
|
|
3373
3379
|
constructor(t, e) {
|
|
3374
|
-
this.rapid = t, this.options = e, this.emitRate = e.emitRate ??
|
|
3380
|
+
this.rapid = t, this.options = e, this.emitRate = e.emitRate ?? Tt, this.emitTime = e.emitTime ?? Et, this.localSpace = e.localSpace ?? Rt;
|
|
3375
3381
|
}
|
|
3376
3382
|
getAllArrayBuffer() {
|
|
3377
3383
|
return [
|
|
@@ -3393,7 +3399,7 @@ class Mt {
|
|
|
3393
3399
|
* Particle state is NOT copied.
|
|
3394
3400
|
*/
|
|
3395
3401
|
clone() {
|
|
3396
|
-
return new
|
|
3402
|
+
return new bt(this.rapid, { ...this.options });
|
|
3397
3403
|
}
|
|
3398
3404
|
/** Sets particles-per-second emission rate (continuous mode). */
|
|
3399
3405
|
setEmitRate(t) {
|
|
@@ -3427,7 +3433,7 @@ class Mt {
|
|
|
3427
3433
|
this.createParticle();
|
|
3428
3434
|
}
|
|
3429
3435
|
createParticle() {
|
|
3430
|
-
const t =
|
|
3436
|
+
const t = L.scalarOrRange(this.options.life, 1);
|
|
3431
3437
|
let e = 0, r = 0;
|
|
3432
3438
|
switch (this.options.emitShape) {
|
|
3433
3439
|
case "circle": {
|
|
@@ -3525,40 +3531,40 @@ class Mt {
|
|
|
3525
3531
|
}
|
|
3526
3532
|
export {
|
|
3527
3533
|
b as ArrayType,
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3534
|
+
z as BaseTexture,
|
|
3535
|
+
ce as BlendMode,
|
|
3536
|
+
ue as CanvasScaleMode,
|
|
3531
3537
|
x as Color,
|
|
3532
|
-
|
|
3538
|
+
ft as CustomGlShader,
|
|
3533
3539
|
_ as DynamicArrayBuffer,
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3540
|
+
wt as GLShader,
|
|
3541
|
+
Xt as GraphicRegion,
|
|
3542
|
+
Kt as LineTextureMode,
|
|
3543
|
+
oe as MaskType,
|
|
3544
|
+
Ct as MatrixStack,
|
|
3545
|
+
Ut as MatrixStore,
|
|
3546
|
+
bt as ParticleEmitter,
|
|
3547
|
+
de as ParticleShape,
|
|
3548
|
+
Gt as QUAD_VERTICES,
|
|
3549
|
+
fe as Rapid,
|
|
3550
|
+
At as Region,
|
|
3551
|
+
Pt as RenderTexture,
|
|
3552
|
+
ot as SpriteRegion,
|
|
3553
|
+
Lt as TextTexture,
|
|
3554
|
+
O as Texture,
|
|
3555
|
+
ht as TextureFilterMode,
|
|
3556
|
+
_t as TextureManager,
|
|
3557
|
+
Q as TextureWrapMode,
|
|
3552
3558
|
p as Vec2,
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3559
|
+
it as WebglBufferArray,
|
|
3560
|
+
jt as composeProjectionWithAffine,
|
|
3561
|
+
ne as drawCircle,
|
|
3562
|
+
St as drawGraphic,
|
|
3563
|
+
re as drawLine,
|
|
3564
|
+
ie as drawMaskImage,
|
|
3565
|
+
ee as drawParticles,
|
|
3566
|
+
se as drawRect,
|
|
3567
|
+
te as drawSprite,
|
|
3568
|
+
Zt as getColorUint32,
|
|
3569
|
+
$t as multiplyMat4
|
|
3564
3570
|
};
|