@holtjs/stage 0.5.2 → 0.6.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/CHANGELOG.md +16 -0
- package/dist/{game-DWELKTnB.d.ts → game-Blm49zGH.d.ts} +175 -11
- package/dist/{game-B8UlnEB_.js → game-Ds-cn2YI.js} +464 -281
- package/dist/headless.d.ts +1 -1
- package/dist/headless.js +2 -2
- package/dist/index.d.ts +17 -2
- package/dist/index.js +5 -4
- package/dist/joystick.d.ts +1 -1
- package/dist/joystick.js +1 -1
- package/dist/kernel.d.ts +1 -1
- package/dist/kernel.js +4 -0
- package/dist/lighting.d.ts +1 -1
- package/dist/lighting.js +4 -9
- package/dist/projection.d.ts +1 -1
- package/dist/{renderer-webgpu-Djk7FayG.js → renderer-webgpu-DJVQHR70.js} +889 -68
- package/dist/renderer-webgpu.d.ts +1 -1
- package/dist/renderer-webgpu.js +1 -1
- package/dist/rig2d.d.ts +1 -1
- package/dist/rig2d.js +1 -1
- package/dist/tilemap.d.ts +1 -1
- package/dist/tilemap.js +1 -1
- package/dist/trace.d.ts +1 -1
- package/dist/trace.js +1 -1
- package/dist/{types-DRFB0Klc.js → types-CXsCvp1p.js} +5 -1
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/skills/stage/SKILL.md +17 -7
- package/skills/stage/references/subpaths.md +5 -5
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { _ as rgbToCss, a as EventEmitter,
|
|
2
|
-
import { _ as
|
|
1
|
+
import { _ as rgbToCss, a as EventEmitter, c as Scale, h as packColorAbgr, l as Scenes, m as createMatrix2D, o as FilterMode, p as WHITE_RGB, r as BlendModes, u as TintModes } from "./types-CXsCvp1p.js";
|
|
2
|
+
import { _ as TextObject, a as Container, d as InstancedBatchObject, f as MsdfIconObject, g as ShapeBatchObject, h as RectangleObject, i as BlitterObject, l as Graphics, m as PanelObject, o as CustomPassObject, p as NineSliceObject, r as Renderer2D, s as DisplayList, t as RendererWebGpu, u as ImageObject, v as TileSpriteObject, y as Camera } from "./renderer-webgpu-DJVQHR70.js";
|
|
3
3
|
import { TweenManager } from "./tween.js";
|
|
4
4
|
import { StageKernel } from "./kernel.js";
|
|
5
5
|
// src/texture.ts
|
|
6
|
-
var TextureSource = class {
|
|
6
|
+
var TextureSource = class TextureSource {
|
|
7
|
+
static nextId = 1;
|
|
8
|
+
id = TextureSource.nextId++;
|
|
9
|
+
version = 0;
|
|
7
10
|
texture;
|
|
8
11
|
image;
|
|
9
12
|
width;
|
|
@@ -47,6 +50,7 @@ var TextureSource = class {
|
|
|
47
50
|
update() {
|
|
48
51
|
this.width = sourceWidth(this.image);
|
|
49
52
|
this.height = sourceHeight(this.image);
|
|
53
|
+
this.version++;
|
|
50
54
|
this.dirty = true;
|
|
51
55
|
if (this.host?.gl && !this.host.contextLost && this.width > 0 && this.height > 0) this.host.uploadTextureSource(this);
|
|
52
56
|
}
|
|
@@ -280,264 +284,7 @@ var TextureManager = class {
|
|
|
280
284
|
this.host = null;
|
|
281
285
|
}
|
|
282
286
|
};
|
|
283
|
-
|
|
284
|
-
var Camera = class {
|
|
285
|
-
x = 0;
|
|
286
|
-
y = 0;
|
|
287
|
-
width;
|
|
288
|
-
height;
|
|
289
|
-
scrollX = 0;
|
|
290
|
-
scrollY = 0;
|
|
291
|
-
zoom = 1;
|
|
292
|
-
alpha = 1;
|
|
293
|
-
originX = .5;
|
|
294
|
-
originY = .5;
|
|
295
|
-
roundPixels = false;
|
|
296
|
-
useBounds = false;
|
|
297
|
-
boundsX = 0;
|
|
298
|
-
boundsY = 0;
|
|
299
|
-
boundsWidth = 0;
|
|
300
|
-
boundsHeight = 0;
|
|
301
|
-
backgroundColor;
|
|
302
|
-
transparent;
|
|
303
|
-
worldView = {
|
|
304
|
-
x: 0,
|
|
305
|
-
y: 0,
|
|
306
|
-
width: 0,
|
|
307
|
-
height: 0,
|
|
308
|
-
right: 0,
|
|
309
|
-
bottom: 0
|
|
310
|
-
};
|
|
311
|
-
matrixCombined = createMatrix2D();
|
|
312
|
-
followTarget = null;
|
|
313
|
-
followLerpX = 1;
|
|
314
|
-
followLerpY = 1;
|
|
315
|
-
followOffsetX = 0;
|
|
316
|
-
followOffsetY = 0;
|
|
317
|
-
deadzoneW = 0;
|
|
318
|
-
deadzoneH = 0;
|
|
319
|
-
constructor(width, height, transparent = false, backgroundColor) {
|
|
320
|
-
this.width = Math.max(1, width);
|
|
321
|
-
this.height = Math.max(1, height);
|
|
322
|
-
this.transparent = transparent;
|
|
323
|
-
this.backgroundColor = backgroundColor !== void 0 ? parseColor(backgroundColor, transparent ? 0 : 1) : {
|
|
324
|
-
r: 0,
|
|
325
|
-
g: 0,
|
|
326
|
-
b: 0,
|
|
327
|
-
a: transparent ? 0 : 1
|
|
328
|
-
};
|
|
329
|
-
this.syncMetrics();
|
|
330
|
-
}
|
|
331
|
-
get displayWidth() {
|
|
332
|
-
return this.width / (this.zoom || 1);
|
|
333
|
-
}
|
|
334
|
-
get displayHeight() {
|
|
335
|
-
return this.height / (this.zoom || 1);
|
|
336
|
-
}
|
|
337
|
-
setBackgroundColor(color) {
|
|
338
|
-
this.backgroundColor = parseColor(color, 1);
|
|
339
|
-
this.transparent = this.backgroundColor.a <= 0;
|
|
340
|
-
return this;
|
|
341
|
-
}
|
|
342
|
-
setRoundPixels(v) {
|
|
343
|
-
this.roundPixels = !!v;
|
|
344
|
-
return this;
|
|
345
|
-
}
|
|
346
|
-
setOrigin(x = .5, y = x) {
|
|
347
|
-
this.originX = x;
|
|
348
|
-
this.originY = y;
|
|
349
|
-
this.syncMetrics();
|
|
350
|
-
return this;
|
|
351
|
-
}
|
|
352
|
-
setZoom(z) {
|
|
353
|
-
this.zoom = z > 0 ? z : 1;
|
|
354
|
-
if (this.useBounds) {
|
|
355
|
-
this.scrollX = this.clampX(this.scrollX);
|
|
356
|
-
this.scrollY = this.clampY(this.scrollY);
|
|
357
|
-
}
|
|
358
|
-
this.syncMetrics();
|
|
359
|
-
return this;
|
|
360
|
-
}
|
|
361
|
-
setScroll(x, y) {
|
|
362
|
-
this.scrollX = this.useBounds ? this.clampX(x) : x;
|
|
363
|
-
this.scrollY = this.useBounds ? this.clampY(y) : y;
|
|
364
|
-
this.syncMetrics();
|
|
365
|
-
return this;
|
|
366
|
-
}
|
|
367
|
-
setViewport(x, y, width, height) {
|
|
368
|
-
this.x = x;
|
|
369
|
-
this.y = y;
|
|
370
|
-
this.width = Math.max(1, width);
|
|
371
|
-
this.height = Math.max(1, height);
|
|
372
|
-
if (this.useBounds) {
|
|
373
|
-
this.scrollX = this.clampX(this.scrollX);
|
|
374
|
-
this.scrollY = this.clampY(this.scrollY);
|
|
375
|
-
}
|
|
376
|
-
this.syncMetrics();
|
|
377
|
-
return this;
|
|
378
|
-
}
|
|
379
|
-
setSize(width, height) {
|
|
380
|
-
this.width = Math.max(1, width);
|
|
381
|
-
this.height = Math.max(1, height);
|
|
382
|
-
if (this.useBounds) {
|
|
383
|
-
this.scrollX = this.clampX(this.scrollX);
|
|
384
|
-
this.scrollY = this.clampY(this.scrollY);
|
|
385
|
-
}
|
|
386
|
-
this.syncMetrics();
|
|
387
|
-
return this;
|
|
388
|
-
}
|
|
389
|
-
setAlpha(a) {
|
|
390
|
-
this.alpha = Math.max(0, Math.min(1, a));
|
|
391
|
-
return this;
|
|
392
|
-
}
|
|
393
|
-
setBounds(x, y, width, height) {
|
|
394
|
-
this.useBounds = true;
|
|
395
|
-
this.boundsX = x;
|
|
396
|
-
this.boundsY = y;
|
|
397
|
-
this.boundsWidth = width;
|
|
398
|
-
this.boundsHeight = height;
|
|
399
|
-
this.scrollX = this.clampX(this.scrollX);
|
|
400
|
-
this.scrollY = this.clampY(this.scrollY);
|
|
401
|
-
this.syncMetrics();
|
|
402
|
-
return this;
|
|
403
|
-
}
|
|
404
|
-
clampX(sx) {
|
|
405
|
-
if (!this.useBounds) return sx;
|
|
406
|
-
const ox = this.width * this.originX;
|
|
407
|
-
const dw = this.displayWidth;
|
|
408
|
-
if (dw >= this.boundsWidth) return this.boundsX + this.boundsWidth * .5 - ox;
|
|
409
|
-
const minSx = this.boundsX - ox + ox / this.zoom;
|
|
410
|
-
const maxSx = this.boundsX + this.boundsWidth - dw - ox + ox / this.zoom;
|
|
411
|
-
return sx < minSx ? minSx : sx > maxSx ? maxSx : sx;
|
|
412
|
-
}
|
|
413
|
-
clampY(sy) {
|
|
414
|
-
if (!this.useBounds) return sy;
|
|
415
|
-
const oy = this.height * this.originY;
|
|
416
|
-
const dh = this.displayHeight;
|
|
417
|
-
if (dh >= this.boundsHeight) return this.boundsY + this.boundsHeight * .5 - oy;
|
|
418
|
-
const minSy = this.boundsY - oy + oy / this.zoom;
|
|
419
|
-
const maxSy = this.boundsY + this.boundsHeight - dh - oy + oy / this.zoom;
|
|
420
|
-
return sy < minSy ? minSy : sy > maxSy ? maxSy : sy;
|
|
421
|
-
}
|
|
422
|
-
centerOn(x, y) {
|
|
423
|
-
const ox = this.width * this.originX;
|
|
424
|
-
const oy = this.height * this.originY;
|
|
425
|
-
return this.setScroll(x - ox, y - oy);
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* One-line HiDPI camera + backing-buffer configurator: maps logical `(0, 0)..(viewportW, viewportH)`
|
|
429
|
-
* 1:1 onto crisp physical `viewportW * dpr` pixels without copy-pasting origin/scroll math.
|
|
430
|
-
* Returns the clamped `dpr` applied.
|
|
431
|
-
*/
|
|
432
|
-
configureHiDpi(scale, viewportWidth, viewportHeight, dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1, maxDpr = 2) {
|
|
433
|
-
const safeDpr = Math.min(Math.max(1, maxDpr), Math.max(1, Number.isFinite(dpr) ? dpr : 1));
|
|
434
|
-
const vw = Math.max(1, Math.round(viewportWidth));
|
|
435
|
-
const vh = Math.max(1, Math.round(viewportHeight));
|
|
436
|
-
scale.zoom = 1 / safeDpr;
|
|
437
|
-
scale.resize(Math.round(vw * safeDpr), Math.round(vh * safeDpr));
|
|
438
|
-
if (scale.canvas?.style) {
|
|
439
|
-
scale.canvas.style.width = `${vw}px`;
|
|
440
|
-
scale.canvas.style.height = `${vh}px`;
|
|
441
|
-
}
|
|
442
|
-
const ox = this.width * this.originX;
|
|
443
|
-
const oy = this.height * this.originY;
|
|
444
|
-
this.setZoom(safeDpr);
|
|
445
|
-
this.setScroll(ox / safeDpr - ox, oy / safeDpr - oy);
|
|
446
|
-
return safeDpr;
|
|
447
|
-
}
|
|
448
|
-
/** Convert canvas/backing-buffer coordinates `(screenX, screenY)` into world coordinates. */
|
|
449
|
-
screenToWorld(screenX, screenY, out = {
|
|
450
|
-
x: 0,
|
|
451
|
-
y: 0
|
|
452
|
-
}) {
|
|
453
|
-
const m = this.matrixCombined;
|
|
454
|
-
out.x = (screenX - m.tx) / (m.a || 1);
|
|
455
|
-
out.y = (screenY - m.ty) / (m.d || 1);
|
|
456
|
-
return out;
|
|
457
|
-
}
|
|
458
|
-
/** Convert world coordinates `(worldX, worldY)` into canvas/backing-buffer coordinates. */
|
|
459
|
-
worldToScreen(worldX, worldY, out = {
|
|
460
|
-
x: 0,
|
|
461
|
-
y: 0
|
|
462
|
-
}) {
|
|
463
|
-
const m = this.matrixCombined;
|
|
464
|
-
out.x = worldX * m.a + m.tx;
|
|
465
|
-
out.y = worldY * m.d + m.ty;
|
|
466
|
-
return out;
|
|
467
|
-
}
|
|
468
|
-
/** Lock or smoothly follow any `{ x, y }` actor/point (frame-rate independent lerp + optional deadzone). */
|
|
469
|
-
startFollow(target, options = {}) {
|
|
470
|
-
this.followTarget = target;
|
|
471
|
-
this.followLerpX = Math.max(.001, Math.min(1, options.lerpX ?? 1));
|
|
472
|
-
this.followLerpY = Math.max(.001, Math.min(1, options.lerpY ?? this.followLerpX));
|
|
473
|
-
this.followOffsetX = options.offsetX ?? 0;
|
|
474
|
-
this.followOffsetY = options.offsetY ?? 0;
|
|
475
|
-
this.deadzoneW = Math.max(0, options.deadzoneWidth ?? 0);
|
|
476
|
-
this.deadzoneH = Math.max(0, options.deadzoneHeight ?? 0);
|
|
477
|
-
return this;
|
|
478
|
-
}
|
|
479
|
-
stopFollow() {
|
|
480
|
-
this.followTarget = null;
|
|
481
|
-
return this;
|
|
482
|
-
}
|
|
483
|
-
/** Internal per-step follow update invoked automatically by `Game.step()` before rendering. */
|
|
484
|
-
stepFollow(deltaMs) {
|
|
485
|
-
const target = this.followTarget;
|
|
486
|
-
if (!target) return;
|
|
487
|
-
const tx = target.x + this.followOffsetX;
|
|
488
|
-
const ty = target.y + this.followOffsetY;
|
|
489
|
-
const curCx = this.worldView.x + this.worldView.width * .5;
|
|
490
|
-
const curCy = this.worldView.y + this.worldView.height * .5;
|
|
491
|
-
let wantCx = curCx;
|
|
492
|
-
let wantCy = curCy;
|
|
493
|
-
const halfDzW = this.deadzoneW * .5;
|
|
494
|
-
const halfDzH = this.deadzoneH * .5;
|
|
495
|
-
if (tx < curCx - halfDzW) wantCx = tx + halfDzW;
|
|
496
|
-
else if (tx > curCx + halfDzW) wantCx = tx - halfDzW;
|
|
497
|
-
if (ty < curCy - halfDzH) wantCy = ty + halfDzH;
|
|
498
|
-
else if (ty > curCy + halfDzH) wantCy = ty - halfDzH;
|
|
499
|
-
const frames = Math.max(.1, deltaMs / (1e3 / 60));
|
|
500
|
-
const ax = this.followLerpX >= 1 ? 1 : 1 - Math.pow(1 - this.followLerpX, frames);
|
|
501
|
-
const ay = this.followLerpY >= 1 ? 1 : 1 - Math.pow(1 - this.followLerpY, frames);
|
|
502
|
-
const nextCx = curCx + (wantCx - curCx) * ax;
|
|
503
|
-
const nextCy = curCy + (wantCy - curCy) * ay;
|
|
504
|
-
const ox = this.width * this.originX;
|
|
505
|
-
const oy = this.height * this.originY;
|
|
506
|
-
const z = this.zoom || 1;
|
|
507
|
-
const nextSx = nextCx - this.worldView.width * .5 - ox + ox / z;
|
|
508
|
-
const nextSy = nextCy - this.worldView.height * .5 - oy + oy / z;
|
|
509
|
-
this.setScroll(nextSx, nextSy);
|
|
510
|
-
}
|
|
511
|
-
/** Recompute `worldView` and world->canvas `matrixCombined`. */
|
|
512
|
-
syncMetrics() {
|
|
513
|
-
const z = this.zoom || 1;
|
|
514
|
-
const ox = this.width * this.originX;
|
|
515
|
-
const oy = this.height * this.originY;
|
|
516
|
-
const sx = this.roundPixels ? Math.round(this.scrollX) : this.scrollX;
|
|
517
|
-
const sy = this.roundPixels ? Math.round(this.scrollY) : this.scrollY;
|
|
518
|
-
const dw = this.width / z;
|
|
519
|
-
const dh = this.height / z;
|
|
520
|
-
const vx = sx + ox - ox / z;
|
|
521
|
-
const vy = sy + oy - oy / z;
|
|
522
|
-
this.worldView.x = vx;
|
|
523
|
-
this.worldView.y = vy;
|
|
524
|
-
this.worldView.width = dw;
|
|
525
|
-
this.worldView.height = dh;
|
|
526
|
-
this.worldView.right = vx + dw;
|
|
527
|
-
this.worldView.bottom = vy + dh;
|
|
528
|
-
const m = this.matrixCombined;
|
|
529
|
-
m.a = z;
|
|
530
|
-
m.b = 0;
|
|
531
|
-
m.c = 0;
|
|
532
|
-
m.d = z;
|
|
533
|
-
m.tx = (-sx - ox) * z + ox + this.x;
|
|
534
|
-
m.ty = (-sy - oy) * z + oy + this.y;
|
|
535
|
-
m.scaleX = z;
|
|
536
|
-
m.scaleY = z;
|
|
537
|
-
}
|
|
538
|
-
};
|
|
539
|
-
// src/sdf-panel.ts
|
|
540
|
-
const MAX_PANELS = 1024;
|
|
287
|
+
const MAX_PANELS = 4096;
|
|
541
288
|
const MAX_VERTS$3 = MAX_PANELS * 4;
|
|
542
289
|
const VERT_FLOATS$3 = 18;
|
|
543
290
|
const VERT_STRIDE$3 = 72;
|
|
@@ -838,6 +585,100 @@ var SdfPanelBatcher = class {
|
|
|
838
585
|
u32[off + 17] = glintAbgr;
|
|
839
586
|
this.panelCount++;
|
|
840
587
|
}
|
|
588
|
+
/**
|
|
589
|
+
* Fast-path SDF quad emitter for symmetric-radius shapes (`Graphics` circles/rounded-rects & `ShapeBatchObject`)
|
|
590
|
+
* with `pxScale` precomputed once per node/matrix. Caller ensures `pending < MAX_SDF_BATCH_QUADS` before calling.
|
|
591
|
+
*/
|
|
592
|
+
pushSimple(m, pxScale, rx, ry, w, h, radius, fillAbgr, borderAbgr, borderWidth, pixelStep = 0) {
|
|
593
|
+
const maxR = Math.min(w, h) * .5;
|
|
594
|
+
const rad = radius <= 0 ? 0 : radius >= maxR ? maxR : radius;
|
|
595
|
+
const bw = borderWidth <= 0 ? 0 : borderWidth >= maxR ? maxR : borderWidth;
|
|
596
|
+
const step = pixelStep > 0 ? pixelStep : 0;
|
|
597
|
+
const pad = step > 0 ? 0 : 1 / pxScale;
|
|
598
|
+
const lx0 = rx - pad, ly0 = ry - pad;
|
|
599
|
+
const lx1 = rx + w + pad, ly1 = ry + h + pad;
|
|
600
|
+
const u0 = -pad, v0 = -pad, u1 = w + pad, v1 = h + pad;
|
|
601
|
+
const a = m.a, b = m.b, c = m.c, d = m.d, tx = m.tx, ty = m.ty;
|
|
602
|
+
const f32 = this.vertF32;
|
|
603
|
+
const u32 = this.vertU32;
|
|
604
|
+
let off = this.panelCount * 4 * VERT_FLOATS$3;
|
|
605
|
+
f32[off] = a * lx0 + c * ly0 + tx;
|
|
606
|
+
f32[off + 1] = b * lx0 + d * ly0 + ty;
|
|
607
|
+
f32[off + 2] = u0;
|
|
608
|
+
f32[off + 3] = v0;
|
|
609
|
+
f32[off + 4] = w;
|
|
610
|
+
f32[off + 5] = h;
|
|
611
|
+
f32[off + 6] = 0;
|
|
612
|
+
f32[off + 7] = rad;
|
|
613
|
+
f32[off + 8] = rad;
|
|
614
|
+
f32[off + 9] = rad;
|
|
615
|
+
f32[off + 10] = rad;
|
|
616
|
+
f32[off + 11] = bw;
|
|
617
|
+
f32[off + 12] = step;
|
|
618
|
+
f32[off + 13] = pxScale;
|
|
619
|
+
f32[off + 14] = 0;
|
|
620
|
+
u32[off + 15] = fillAbgr;
|
|
621
|
+
u32[off + 16] = borderAbgr;
|
|
622
|
+
u32[off + 17] = 0;
|
|
623
|
+
off += VERT_FLOATS$3;
|
|
624
|
+
f32[off] = a * lx1 + c * ly0 + tx;
|
|
625
|
+
f32[off + 1] = b * lx1 + d * ly0 + ty;
|
|
626
|
+
f32[off + 2] = u1;
|
|
627
|
+
f32[off + 3] = v0;
|
|
628
|
+
f32[off + 4] = w;
|
|
629
|
+
f32[off + 5] = h;
|
|
630
|
+
f32[off + 6] = 0;
|
|
631
|
+
f32[off + 7] = rad;
|
|
632
|
+
f32[off + 8] = rad;
|
|
633
|
+
f32[off + 9] = rad;
|
|
634
|
+
f32[off + 10] = rad;
|
|
635
|
+
f32[off + 11] = bw;
|
|
636
|
+
f32[off + 12] = step;
|
|
637
|
+
f32[off + 13] = pxScale;
|
|
638
|
+
f32[off + 14] = 0;
|
|
639
|
+
u32[off + 15] = fillAbgr;
|
|
640
|
+
u32[off + 16] = borderAbgr;
|
|
641
|
+
u32[off + 17] = 0;
|
|
642
|
+
off += VERT_FLOATS$3;
|
|
643
|
+
f32[off] = a * lx1 + c * ly1 + tx;
|
|
644
|
+
f32[off + 1] = b * lx1 + d * ly1 + ty;
|
|
645
|
+
f32[off + 2] = u1;
|
|
646
|
+
f32[off + 3] = v1;
|
|
647
|
+
f32[off + 4] = w;
|
|
648
|
+
f32[off + 5] = h;
|
|
649
|
+
f32[off + 6] = 0;
|
|
650
|
+
f32[off + 7] = rad;
|
|
651
|
+
f32[off + 8] = rad;
|
|
652
|
+
f32[off + 9] = rad;
|
|
653
|
+
f32[off + 10] = rad;
|
|
654
|
+
f32[off + 11] = bw;
|
|
655
|
+
f32[off + 12] = step;
|
|
656
|
+
f32[off + 13] = pxScale;
|
|
657
|
+
f32[off + 14] = 0;
|
|
658
|
+
u32[off + 15] = fillAbgr;
|
|
659
|
+
u32[off + 16] = borderAbgr;
|
|
660
|
+
u32[off + 17] = 0;
|
|
661
|
+
off += VERT_FLOATS$3;
|
|
662
|
+
f32[off] = a * lx0 + c * ly1 + tx;
|
|
663
|
+
f32[off + 1] = b * lx0 + d * ly1 + ty;
|
|
664
|
+
f32[off + 2] = u0;
|
|
665
|
+
f32[off + 3] = v1;
|
|
666
|
+
f32[off + 4] = w;
|
|
667
|
+
f32[off + 5] = h;
|
|
668
|
+
f32[off + 6] = 0;
|
|
669
|
+
f32[off + 7] = rad;
|
|
670
|
+
f32[off + 8] = rad;
|
|
671
|
+
f32[off + 9] = rad;
|
|
672
|
+
f32[off + 10] = rad;
|
|
673
|
+
f32[off + 11] = bw;
|
|
674
|
+
f32[off + 12] = step;
|
|
675
|
+
f32[off + 13] = pxScale;
|
|
676
|
+
f32[off + 14] = 0;
|
|
677
|
+
u32[off + 15] = fillAbgr;
|
|
678
|
+
u32[off + 16] = borderAbgr;
|
|
679
|
+
u32[off + 17] = 0;
|
|
680
|
+
this.panelCount++;
|
|
681
|
+
}
|
|
841
682
|
flush(resW, resH) {
|
|
842
683
|
const count = this.panelCount;
|
|
843
684
|
if (count === 0 || !this.program || !this.vbo || !this.quadIbo) return false;
|
|
@@ -1791,6 +1632,19 @@ function buildLineSeg(x0, y0, x1, y1, halfW, rgb, alpha) {
|
|
|
1791
1632
|
const ny = dx / len * halfW;
|
|
1792
1633
|
buildQuadPts(x0 + nx, y0 + ny, x1 + nx, y1 + ny, x1 - nx, y1 - ny, x0 - nx, y0 - ny, rgb, alpha);
|
|
1793
1634
|
}
|
|
1635
|
+
const UNIT_COS = [];
|
|
1636
|
+
const UNIT_SIN = [];
|
|
1637
|
+
for (let segs = 6; segs <= 64; segs++) {
|
|
1638
|
+
const cs = new Float32Array(segs);
|
|
1639
|
+
const sn = new Float32Array(segs);
|
|
1640
|
+
const step = Math.PI * 2 / segs;
|
|
1641
|
+
for (let i = 0; i < segs; i++) {
|
|
1642
|
+
cs[i] = Math.cos(i * step);
|
|
1643
|
+
sn[i] = Math.sin(i * step);
|
|
1644
|
+
}
|
|
1645
|
+
UNIT_COS[segs] = cs;
|
|
1646
|
+
UNIT_SIN[segs] = sn;
|
|
1647
|
+
}
|
|
1794
1648
|
function buildEllipseFill(cx, cy, rx, ry, scale, rgb, alpha) {
|
|
1795
1649
|
if (rx <= 0 || ry <= 0) return;
|
|
1796
1650
|
buildHasScaleCurves = true;
|
|
@@ -1807,13 +1661,11 @@ function buildEllipseFill(cx, cy, rx, ry, scale, rgb, alpha) {
|
|
|
1807
1661
|
buildRgb[baseV] = rgb;
|
|
1808
1662
|
buildAlphas[baseV] = alpha;
|
|
1809
1663
|
buildAbgr1[baseV] = abgr;
|
|
1810
|
-
const
|
|
1664
|
+
const csLut = UNIT_COS[segs];
|
|
1665
|
+
const snLut = UNIT_SIN[segs];
|
|
1811
1666
|
for (let i = 0; i < segs; i++) {
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
const py = cy + Math.sin(ang) * ry;
|
|
1815
|
-
buildXy[xyI++] = px;
|
|
1816
|
-
buildXy[xyI++] = py;
|
|
1667
|
+
buildXy[xyI++] = cx + csLut[i] * rx;
|
|
1668
|
+
buildXy[xyI++] = cy + snLut[i] * ry;
|
|
1817
1669
|
buildRgb[baseV + 1 + i] = rgb;
|
|
1818
1670
|
buildAlphas[baseV + 1 + i] = alpha;
|
|
1819
1671
|
buildAbgr1[baseV + 1 + i] = abgr;
|
|
@@ -1841,10 +1693,10 @@ function buildEllipseStroke(cx, cy, rx, ry, lw, scale, rgb, alpha) {
|
|
|
1841
1693
|
const baseV = buildV;
|
|
1842
1694
|
const abgr = packColorAbgr(rgb, alpha);
|
|
1843
1695
|
let xyI = baseV * 2;
|
|
1844
|
-
const
|
|
1696
|
+
const csLut = UNIT_COS[segs];
|
|
1697
|
+
const snLut = UNIT_SIN[segs];
|
|
1845
1698
|
for (let i = 0; i < segs; i++) {
|
|
1846
|
-
const
|
|
1847
|
-
const cs = Math.cos(ang), sn = Math.sin(ang);
|
|
1699
|
+
const cs = csLut[i], sn = snLut[i];
|
|
1848
1700
|
const vi = baseV + i * 2;
|
|
1849
1701
|
buildXy[xyI++] = cx + cs * orx;
|
|
1850
1702
|
buildXy[xyI++] = cy + sn * ory;
|
|
@@ -2785,11 +2637,7 @@ var RendererGl = class extends EventEmitter {
|
|
|
2785
2637
|
const sdf = this.sdfBatcher;
|
|
2786
2638
|
if (!sdf || sdf.pending === 0 || this.contextLost) return;
|
|
2787
2639
|
const count = sdf.pending;
|
|
2788
|
-
if (!this.batchStateBound)
|
|
2789
|
-
const gl = this.gl;
|
|
2790
|
-
if (this.curBlend === BlendModes.ADD) gl.blendFunc(gl.ONE, gl.ONE);
|
|
2791
|
-
else gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
|
2792
|
-
}
|
|
2640
|
+
if (!this.batchStateBound) applyGlBlendMode(this.gl, this.curBlend);
|
|
2793
2641
|
if (sdf.flush(this.width, this.height)) {
|
|
2794
2642
|
this.curDrawCalls++;
|
|
2795
2643
|
this.curFlushes++;
|
|
@@ -3292,6 +3140,10 @@ var RendererGl = class extends EventEmitter {
|
|
|
3292
3140
|
}
|
|
3293
3141
|
renderGraphics(g, m, alpha) {
|
|
3294
3142
|
if (g.opLen === 0) return;
|
|
3143
|
+
if (g._hasSdfShapes && !g._hasNonSdfOps && this.sdfBatcher) {
|
|
3144
|
+
this.renderGraphicsSdf(g, m, alpha);
|
|
3145
|
+
return;
|
|
3146
|
+
}
|
|
3295
3147
|
let cache = g._glCache;
|
|
3296
3148
|
let scaleBucket = 2;
|
|
3297
3149
|
if (!cache || cache.version !== g.version || cache.hasScaleCurves) {
|
|
@@ -3433,8 +3285,253 @@ var RendererGl = class extends EventEmitter {
|
|
|
3433
3285
|
if (this.pixelAaBatcher?.pending) this.flushPixelAa();
|
|
3434
3286
|
if (this.indexCount > 0) this.flush();
|
|
3435
3287
|
this.setBlend(panel.blendMode);
|
|
3288
|
+
if (this.sdfBatcher && this.sdfBatcher.pending >= 4096) this.flushSdf();
|
|
3436
3289
|
this.sdfBatcher?.push(m, ox, oy, w, h, panel.radiusTL, panel.radiusTR, panel.radiusBR, panel.radiusBL, panel.fillColor, fillAlpha, panel.borderColor, borderAlpha, borderW, panel.pixelStep, panel.openSide, panel.topGlintColor, panel.topGlintAlpha, panel.topGlintHeight, this.width, this.height);
|
|
3437
3290
|
}
|
|
3291
|
+
renderGraphicsSdf(g, m, alpha) {
|
|
3292
|
+
const sdf = this.sdfBatcher;
|
|
3293
|
+
if (!sdf) return;
|
|
3294
|
+
if (this.activeCustomHandler) this.flushCustomHandler();
|
|
3295
|
+
if (this.msdfBatcher?.pending) this.flushMsdf();
|
|
3296
|
+
if (this.pixelAaBatcher?.pending) this.flushPixelAa();
|
|
3297
|
+
if (this.indexCount > 0) this.flush();
|
|
3298
|
+
this.setBlend(g.blendMode);
|
|
3299
|
+
const sx = Math.hypot(m.a, m.b);
|
|
3300
|
+
const sy = Math.hypot(m.c, m.d);
|
|
3301
|
+
const pxScale = Math.max(.001, Math.min(sx, sy));
|
|
3302
|
+
gfxStateStack.length = 0;
|
|
3303
|
+
let fillRgb = WHITE_RGB, fillA = 1;
|
|
3304
|
+
let lineW = 1, lineRgb = WHITE_RGB, lineA = 1;
|
|
3305
|
+
let cachedFillRgb = -1, cachedFillA = -1, fillAbgr = 0;
|
|
3306
|
+
let cachedLineRgb = -1, cachedLineA = -1, lineAbgr = 0;
|
|
3307
|
+
const getFillAbgr = () => {
|
|
3308
|
+
const eff = fillA * alpha;
|
|
3309
|
+
if (fillRgb !== cachedFillRgb || eff !== cachedFillA) {
|
|
3310
|
+
cachedFillRgb = fillRgb;
|
|
3311
|
+
cachedFillA = eff;
|
|
3312
|
+
fillAbgr = packColorAbgr(fillRgb, eff);
|
|
3313
|
+
}
|
|
3314
|
+
return fillAbgr;
|
|
3315
|
+
};
|
|
3316
|
+
const getLineAbgr = () => {
|
|
3317
|
+
const eff = lineA * alpha;
|
|
3318
|
+
if (lineRgb !== cachedLineRgb || eff !== cachedLineA) {
|
|
3319
|
+
cachedLineRgb = lineRgb;
|
|
3320
|
+
cachedLineA = eff;
|
|
3321
|
+
lineAbgr = packColorAbgr(lineRgb, eff);
|
|
3322
|
+
}
|
|
3323
|
+
return lineAbgr;
|
|
3324
|
+
};
|
|
3325
|
+
const ops = g.ops;
|
|
3326
|
+
const nums = g.nums;
|
|
3327
|
+
let ni = 0;
|
|
3328
|
+
for (let oi = 0; oi < g.opLen; oi++) switch (ops[oi]) {
|
|
3329
|
+
case 22:
|
|
3330
|
+
gfxStateStack.push(fillRgb, fillA, lineW, lineRgb, lineA);
|
|
3331
|
+
break;
|
|
3332
|
+
case 23:
|
|
3333
|
+
if (gfxStateStack.length >= 5) {
|
|
3334
|
+
lineA = gfxStateStack.pop();
|
|
3335
|
+
lineRgb = gfxStateStack.pop();
|
|
3336
|
+
lineW = gfxStateStack.pop();
|
|
3337
|
+
fillA = gfxStateStack.pop();
|
|
3338
|
+
fillRgb = gfxStateStack.pop();
|
|
3339
|
+
}
|
|
3340
|
+
break;
|
|
3341
|
+
case 1:
|
|
3342
|
+
fillRgb = nums[ni++];
|
|
3343
|
+
fillA = nums[ni++];
|
|
3344
|
+
break;
|
|
3345
|
+
case 2:
|
|
3346
|
+
lineW = nums[ni++];
|
|
3347
|
+
lineRgb = nums[ni++];
|
|
3348
|
+
lineA = nums[ni++];
|
|
3349
|
+
break;
|
|
3350
|
+
case 3: {
|
|
3351
|
+
const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++];
|
|
3352
|
+
if (fillA * alpha > 0 && w !== 0 && h !== 0) {
|
|
3353
|
+
const rx = w < 0 ? x + w : x, ry = h < 0 ? y + h : y;
|
|
3354
|
+
const rw = Math.abs(w), rh = Math.abs(h);
|
|
3355
|
+
if (!this.isOffscreen(m, rx, ry, rx + rw, ry + rh)) {
|
|
3356
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3357
|
+
sdf.pushSimple(m, pxScale, rx, ry, rw, rh, 0, getFillAbgr(), 0, 0);
|
|
3358
|
+
} else this.curCulled++;
|
|
3359
|
+
}
|
|
3360
|
+
break;
|
|
3361
|
+
}
|
|
3362
|
+
case 4: {
|
|
3363
|
+
const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++];
|
|
3364
|
+
if (lineA * alpha > 0 && lineW > 0 && w !== 0 && h !== 0) {
|
|
3365
|
+
const hw = lineW * .5;
|
|
3366
|
+
const rx = (w < 0 ? x + w : x) - hw, ry = (h < 0 ? y + h : y) - hw;
|
|
3367
|
+
const rw = Math.abs(w) + lineW, rh = Math.abs(h) + lineW;
|
|
3368
|
+
if (!this.isOffscreen(m, rx, ry, rx + rw, ry + rh)) {
|
|
3369
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3370
|
+
sdf.pushSimple(m, pxScale, rx, ry, rw, rh, 0, 0, getLineAbgr(), lineW);
|
|
3371
|
+
} else this.curCulled++;
|
|
3372
|
+
}
|
|
3373
|
+
break;
|
|
3374
|
+
}
|
|
3375
|
+
case 5: {
|
|
3376
|
+
const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++], r = nums[ni++];
|
|
3377
|
+
if (fillA * alpha > 0 && w > 0 && h > 0) {
|
|
3378
|
+
if (!this.isOffscreen(m, x, y, x + w, y + h)) {
|
|
3379
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3380
|
+
sdf.pushSimple(m, pxScale, x, y, w, h, r, getFillAbgr(), 0, 0);
|
|
3381
|
+
} else this.curCulled++;
|
|
3382
|
+
}
|
|
3383
|
+
break;
|
|
3384
|
+
}
|
|
3385
|
+
case 6: {
|
|
3386
|
+
const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++], r = nums[ni++];
|
|
3387
|
+
if (lineA * alpha > 0 && lineW > 0 && w > 0 && h > 0) {
|
|
3388
|
+
const hw = lineW * .5;
|
|
3389
|
+
const rx = x - hw, ry = y - hw, rw = w + lineW, rh = h + lineW;
|
|
3390
|
+
if (!this.isOffscreen(m, rx, ry, rx + rw, ry + rh)) {
|
|
3391
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3392
|
+
sdf.pushSimple(m, pxScale, rx, ry, rw, rh, Math.max(0, r) + hw, 0, getLineAbgr(), lineW);
|
|
3393
|
+
} else this.curCulled++;
|
|
3394
|
+
}
|
|
3395
|
+
break;
|
|
3396
|
+
}
|
|
3397
|
+
case 7: {
|
|
3398
|
+
const cx = nums[ni++], cy = nums[ni++], r = nums[ni++];
|
|
3399
|
+
if (fillA * alpha > 0 && r > 0) {
|
|
3400
|
+
const d = r * 2, rx = cx - r, ry = cy - r;
|
|
3401
|
+
if (!this.isOffscreen(m, rx, ry, rx + d, ry + d)) {
|
|
3402
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3403
|
+
sdf.pushSimple(m, pxScale, rx, ry, d, d, r, getFillAbgr(), 0, 0);
|
|
3404
|
+
} else this.curCulled++;
|
|
3405
|
+
}
|
|
3406
|
+
break;
|
|
3407
|
+
}
|
|
3408
|
+
case 8: {
|
|
3409
|
+
const cx = nums[ni++], cy = nums[ni++], r = nums[ni++];
|
|
3410
|
+
if (lineA * alpha > 0 && lineW > 0 && r > 0) {
|
|
3411
|
+
const ro = r + lineW * .5, d = ro * 2, rx = cx - ro, ry = cy - ro;
|
|
3412
|
+
if (!this.isOffscreen(m, rx, ry, rx + d, ry + d)) {
|
|
3413
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3414
|
+
sdf.pushSimple(m, pxScale, rx, ry, d, d, ro, 0, getLineAbgr(), lineW);
|
|
3415
|
+
} else this.curCulled++;
|
|
3416
|
+
}
|
|
3417
|
+
break;
|
|
3418
|
+
}
|
|
3419
|
+
case 9: {
|
|
3420
|
+
const cx = nums[ni++], cy = nums[ni++], w = nums[ni++], h = nums[ni++];
|
|
3421
|
+
if (fillA * alpha > 0 && w > 0 && h > 0) {
|
|
3422
|
+
const rx = cx - w * .5, ry = cy - h * .5;
|
|
3423
|
+
if (!this.isOffscreen(m, rx, ry, rx + w, ry + h)) {
|
|
3424
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3425
|
+
sdf.pushSimple(m, pxScale, rx, ry, w, h, w * .5, getFillAbgr(), 0, 0);
|
|
3426
|
+
} else this.curCulled++;
|
|
3427
|
+
}
|
|
3428
|
+
break;
|
|
3429
|
+
}
|
|
3430
|
+
case 10: {
|
|
3431
|
+
const cx = nums[ni++], cy = nums[ni++], w = nums[ni++], h = nums[ni++];
|
|
3432
|
+
if (lineA * alpha > 0 && lineW > 0 && w > 0 && h > 0) {
|
|
3433
|
+
const rw = w + lineW, rh = h + lineW, rx = cx - rw * .5, ry = cy - rh * .5;
|
|
3434
|
+
if (!this.isOffscreen(m, rx, ry, rx + rw, ry + rh)) {
|
|
3435
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3436
|
+
sdf.pushSimple(m, pxScale, rx, ry, rw, rh, rw * .5, 0, getLineAbgr(), lineW);
|
|
3437
|
+
} else this.curCulled++;
|
|
3438
|
+
}
|
|
3439
|
+
break;
|
|
3440
|
+
}
|
|
3441
|
+
}
|
|
3442
|
+
}
|
|
3443
|
+
renderShapeBatch(batch, m, alpha) {
|
|
3444
|
+
const sdf = this.sdfBatcher;
|
|
3445
|
+
const cols = batch.columns;
|
|
3446
|
+
if (!sdf || !cols || cols.count <= 0) return;
|
|
3447
|
+
const n = Math.min(cols.count, batch.maxCount, cols.x.length, cols.y.length);
|
|
3448
|
+
if (n <= 0) return;
|
|
3449
|
+
if (this.activeCustomHandler) this.flushCustomHandler();
|
|
3450
|
+
if (this.msdfBatcher?.pending) this.flushMsdf();
|
|
3451
|
+
if (this.pixelAaBatcher?.pending) this.flushPixelAa();
|
|
3452
|
+
if (this.indexCount > 0) this.flush();
|
|
3453
|
+
this.setBlend(batch.blendMode);
|
|
3454
|
+
const sx = Math.hypot(m.a, m.b);
|
|
3455
|
+
const sy = Math.hypot(m.c, m.d);
|
|
3456
|
+
const basePxScale = Math.max(.001, Math.min(sx, sy));
|
|
3457
|
+
const oxRatio = batch.originX;
|
|
3458
|
+
const oyRatio = batch.originY;
|
|
3459
|
+
const step = batch.pixelStep;
|
|
3460
|
+
const wCol = typeof cols.width === "object" && cols.width ? cols.width : null;
|
|
3461
|
+
const wDef = typeof cols.width === "number" ? cols.width : batch.defaultWidth;
|
|
3462
|
+
const hCol = typeof cols.height === "object" && cols.height ? cols.height : null;
|
|
3463
|
+
const hDef = typeof cols.height === "number" ? cols.height : typeof cols.width === "number" ? cols.width : batch.defaultHeight;
|
|
3464
|
+
const rCol = typeof cols.radius === "object" && cols.radius ? cols.radius : null;
|
|
3465
|
+
const rDef = typeof cols.radius === "number" ? cols.radius : batch.defaultRadius;
|
|
3466
|
+
const fcCol = typeof cols.fillColor === "object" && cols.fillColor ? cols.fillColor : null;
|
|
3467
|
+
const fcDef = typeof cols.fillColor === "number" ? cols.fillColor : batch.defaultFillColor;
|
|
3468
|
+
const faCol = typeof cols.fillAlpha === "object" && cols.fillAlpha ? cols.fillAlpha : null;
|
|
3469
|
+
const faDef = typeof cols.fillAlpha === "number" ? cols.fillAlpha : batch.defaultFillAlpha;
|
|
3470
|
+
const bcCol = typeof cols.borderColor === "object" && cols.borderColor ? cols.borderColor : null;
|
|
3471
|
+
const bcDef = typeof cols.borderColor === "number" ? cols.borderColor : batch.defaultBorderColor;
|
|
3472
|
+
const baCol = typeof cols.borderAlpha === "object" && cols.borderAlpha ? cols.borderAlpha : null;
|
|
3473
|
+
const baDef = typeof cols.borderAlpha === "number" ? cols.borderAlpha : batch.defaultBorderAlpha;
|
|
3474
|
+
const bwCol = typeof cols.borderWidth === "object" && cols.borderWidth ? cols.borderWidth : null;
|
|
3475
|
+
const bwDef = typeof cols.borderWidth === "number" ? cols.borderWidth : batch.defaultBorderWidth;
|
|
3476
|
+
const rotCol = cols.rotation ?? null;
|
|
3477
|
+
const ordCol = cols.order ?? null;
|
|
3478
|
+
let lastFc = -1, lastFa = -1, fillAbgr = 0;
|
|
3479
|
+
let lastBc = -1, lastBa = -1, borderAbgr = 0;
|
|
3480
|
+
const rotMat = this.sfMat;
|
|
3481
|
+
for (let i = 0; i < n; i++) {
|
|
3482
|
+
const s = ordCol ? ordCol[i] : i;
|
|
3483
|
+
const w = wCol ? wCol[s] : wDef;
|
|
3484
|
+
const h = hCol ? hCol[s] : wCol ? w : hDef;
|
|
3485
|
+
if (w <= 0 || h <= 0) continue;
|
|
3486
|
+
const fa = (faCol ? faCol[s] : faDef) * alpha;
|
|
3487
|
+
const bw = bwCol ? bwCol[s] : bwDef;
|
|
3488
|
+
const ba = bw > 0 ? (baCol ? baCol[s] : baDef) * alpha : 0;
|
|
3489
|
+
if (fa <= 0 && ba <= 0) continue;
|
|
3490
|
+
const fc = fcCol ? fcCol[s] : fcDef;
|
|
3491
|
+
if (fc !== lastFc || fa !== lastFa) {
|
|
3492
|
+
lastFc = fc;
|
|
3493
|
+
lastFa = fa;
|
|
3494
|
+
fillAbgr = packColorAbgr(fc, fa);
|
|
3495
|
+
}
|
|
3496
|
+
if (bw > 0) {
|
|
3497
|
+
const bc = bcCol ? bcCol[s] : bcDef;
|
|
3498
|
+
if (bc !== lastBc || ba !== lastBa) {
|
|
3499
|
+
lastBc = bc;
|
|
3500
|
+
lastBa = ba;
|
|
3501
|
+
borderAbgr = packColorAbgr(bc, ba);
|
|
3502
|
+
}
|
|
3503
|
+
} else borderAbgr = 0;
|
|
3504
|
+
const rad = rCol ? rCol[s] : rDef;
|
|
3505
|
+
const px = cols.x[s];
|
|
3506
|
+
const py = cols.y[s];
|
|
3507
|
+
const rot = rotCol ? rotCol[s] : 0;
|
|
3508
|
+
if (rot === 0) {
|
|
3509
|
+
const rx = px - w * oxRatio;
|
|
3510
|
+
const ry = py - h * oyRatio;
|
|
3511
|
+
if (this.isOffscreen(m, rx, ry, rx + w, ry + h)) {
|
|
3512
|
+
this.curCulled++;
|
|
3513
|
+
continue;
|
|
3514
|
+
}
|
|
3515
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3516
|
+
sdf.pushSimple(m, basePxScale, rx, ry, w, h, rad, fillAbgr, borderAbgr, bw, step);
|
|
3517
|
+
} else {
|
|
3518
|
+
const cs = Math.cos(rot), sn = Math.sin(rot);
|
|
3519
|
+
rotMat.a = m.a * cs + m.c * sn;
|
|
3520
|
+
rotMat.b = m.b * cs + m.d * sn;
|
|
3521
|
+
rotMat.c = m.a * -sn + m.c * cs;
|
|
3522
|
+
rotMat.d = m.b * -sn + m.d * cs;
|
|
3523
|
+
rotMat.tx = m.a * px + m.c * py + m.tx;
|
|
3524
|
+
rotMat.ty = m.b * px + m.d * py + m.ty;
|
|
3525
|
+
const rx = -w * oxRatio, ry = -h * oyRatio;
|
|
3526
|
+
if (this.isOffscreen(rotMat, rx, ry, rx + w, ry + h)) {
|
|
3527
|
+
this.curCulled++;
|
|
3528
|
+
continue;
|
|
3529
|
+
}
|
|
3530
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3531
|
+
sdf.pushSimple(rotMat, basePxScale, rx, ry, w, h, rad, fillAbgr, borderAbgr, bw, step);
|
|
3532
|
+
}
|
|
3533
|
+
}
|
|
3534
|
+
}
|
|
3438
3535
|
renderMsdfIcon(icon, m, alpha) {
|
|
3439
3536
|
const w = icon.width;
|
|
3440
3537
|
const h = icon.height;
|
|
@@ -3679,7 +3776,25 @@ var RendererGl = class extends EventEmitter {
|
|
|
3679
3776
|
width: w,
|
|
3680
3777
|
height: h,
|
|
3681
3778
|
texture: tex,
|
|
3779
|
+
camera: new Camera(w, h, true),
|
|
3682
3780
|
_fbo: fbo,
|
|
3781
|
+
readPixels: (out) => {
|
|
3782
|
+
const byteLen = w * h * 4;
|
|
3783
|
+
const dst = out && out.length >= byteLen ? out : new Uint8Array(byteLen);
|
|
3784
|
+
if (this.contextLost) return dst;
|
|
3785
|
+
this.flushAll();
|
|
3786
|
+
const raw = new Uint8Array(byteLen);
|
|
3787
|
+
const prev = this.activeFbo;
|
|
3788
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
|
|
3789
|
+
gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, raw);
|
|
3790
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, prev);
|
|
3791
|
+
const rowStride = w * 4;
|
|
3792
|
+
for (let y = 0; y < h; y++) {
|
|
3793
|
+
const srcOff = (h - 1 - y) * rowStride;
|
|
3794
|
+
dst.set(raw.subarray(srcOff, srcOff + rowStride), y * rowStride);
|
|
3795
|
+
}
|
|
3796
|
+
return dst;
|
|
3797
|
+
},
|
|
3683
3798
|
destroy: () => {
|
|
3684
3799
|
try {
|
|
3685
3800
|
if (!this.contextLost) {
|
|
@@ -3692,8 +3807,8 @@ var RendererGl = class extends EventEmitter {
|
|
|
3692
3807
|
}
|
|
3693
3808
|
};
|
|
3694
3809
|
}
|
|
3695
|
-
/** Render a `DisplayList` (or custom pass callback) into an offscreen `StageRenderTarget` FBO. */
|
|
3696
|
-
renderToTarget(target, content, camera) {
|
|
3810
|
+
/** Render a `DisplayList` (or custom pass callback) into an offscreen `StageRenderTarget` FBO (`camera` defaults to `target.camera`). */
|
|
3811
|
+
renderToTarget(target, content, camera = target.camera) {
|
|
3697
3812
|
if (this.contextLost) return;
|
|
3698
3813
|
this.flushAll();
|
|
3699
3814
|
const gl = this.gl;
|
|
@@ -3826,6 +3941,9 @@ var RendererGl = class extends EventEmitter {
|
|
|
3826
3941
|
case "InstancedBatch":
|
|
3827
3942
|
this.renderInstancedBatch(obj, m, effAlpha);
|
|
3828
3943
|
break;
|
|
3944
|
+
case "ShapeBatch":
|
|
3945
|
+
this.renderShapeBatch(obj, m, effAlpha);
|
|
3946
|
+
break;
|
|
3829
3947
|
case "Container": {
|
|
3830
3948
|
const cont = obj;
|
|
3831
3949
|
const mask = cont.clipMask;
|
|
@@ -4831,6 +4949,10 @@ var GameObjectFactory = class {
|
|
|
4831
4949
|
instancedBatch(key, maxCount = 1024, frame) {
|
|
4832
4950
|
return this.register(new InstancedBatchObject(this.scene, key, maxCount, frame));
|
|
4833
4951
|
}
|
|
4952
|
+
/** Create a zero-texture GPU analytical SDF shape batch (`circles`, `rings`, `pills`, `rounded rects`). */
|
|
4953
|
+
shapeBatch(maxCount = 1024, defaults) {
|
|
4954
|
+
return this.register(new ShapeBatchObject(this.scene, maxCount, defaults));
|
|
4955
|
+
}
|
|
4834
4956
|
container(x = 0, y = 0, children) {
|
|
4835
4957
|
return this.register(new Container(this.scene, x, y, children));
|
|
4836
4958
|
}
|
|
@@ -4843,15 +4965,21 @@ var ScaleManager = class extends EventEmitter {
|
|
|
4843
4965
|
renderer;
|
|
4844
4966
|
width;
|
|
4845
4967
|
height;
|
|
4968
|
+
logicalWidth;
|
|
4969
|
+
logicalHeight;
|
|
4846
4970
|
zoom;
|
|
4971
|
+
mode;
|
|
4847
4972
|
displayScale;
|
|
4848
|
-
constructor(canvas, renderer, width, height, zoom = 1) {
|
|
4973
|
+
constructor(canvas, renderer, width, height, zoom = 1, mode = Scale.NONE) {
|
|
4849
4974
|
super();
|
|
4850
4975
|
this.canvas = canvas;
|
|
4851
4976
|
this.renderer = renderer;
|
|
4852
4977
|
this.width = Math.max(1, Math.round(width));
|
|
4853
4978
|
this.height = Math.max(1, Math.round(height));
|
|
4979
|
+
this.logicalWidth = this.width;
|
|
4980
|
+
this.logicalHeight = this.height;
|
|
4854
4981
|
this.zoom = zoom > 0 ? zoom : 1;
|
|
4982
|
+
this.mode = mode;
|
|
4855
4983
|
this.displayScale = {
|
|
4856
4984
|
x: 1 / this.zoom,
|
|
4857
4985
|
y: 1 / this.zoom
|
|
@@ -4877,7 +5005,41 @@ var ScaleManager = class extends EventEmitter {
|
|
|
4877
5005
|
});
|
|
4878
5006
|
return this;
|
|
4879
5007
|
}
|
|
5008
|
+
/**
|
|
5009
|
+
* Proportionally fit `canvas.style.width/height` inside `availWidth × availHeight` (or `canvas.parentElement` / `window`)
|
|
5010
|
+
* preserving `logicalWidth : logicalHeight` aspect ratio (zero CSS matrix distortion; `InputPlugin` & `clientToWorld` stay exact).
|
|
5011
|
+
*/
|
|
5012
|
+
fitToContainer(availWidth, availHeight) {
|
|
5013
|
+
const parent = this.canvas?.parentElement;
|
|
5014
|
+
const win = this.canvas?.ownerDocument?.defaultView;
|
|
5015
|
+
const aw = Math.max(1, availWidth ?? parent?.clientWidth ?? win?.innerWidth ?? this.logicalWidth);
|
|
5016
|
+
const ah = Math.max(1, availHeight ?? parent?.clientHeight ?? win?.innerHeight ?? this.logicalHeight);
|
|
5017
|
+
const lw = Math.max(1, this.logicalWidth);
|
|
5018
|
+
const lh = Math.max(1, this.logicalHeight);
|
|
5019
|
+
const scale = Math.min(aw / lw, ah / lh);
|
|
5020
|
+
const cssWidth = Math.max(1, Math.round(lw * scale));
|
|
5021
|
+
const cssHeight = Math.max(1, Math.round(lh * scale));
|
|
5022
|
+
const offsetX = Math.floor((aw - cssWidth) * .5);
|
|
5023
|
+
const offsetY = Math.floor((ah - cssHeight) * .5);
|
|
5024
|
+
if (this.canvas?.style) {
|
|
5025
|
+
this.canvas.style.width = `${cssWidth}px`;
|
|
5026
|
+
this.canvas.style.height = `${cssHeight}px`;
|
|
5027
|
+
}
|
|
5028
|
+
this.displayScale.x = this.width / cssWidth;
|
|
5029
|
+
this.displayScale.y = this.height / cssHeight;
|
|
5030
|
+
return {
|
|
5031
|
+
scale,
|
|
5032
|
+
cssWidth,
|
|
5033
|
+
cssHeight,
|
|
5034
|
+
offsetX,
|
|
5035
|
+
offsetY
|
|
5036
|
+
};
|
|
5037
|
+
}
|
|
4880
5038
|
refresh() {
|
|
5039
|
+
if (this.mode === Scale.FIT) {
|
|
5040
|
+
this.fitToContainer();
|
|
5041
|
+
return this;
|
|
5042
|
+
}
|
|
4881
5043
|
this.displayScale.x = 1 / (this.zoom || 1);
|
|
4882
5044
|
this.displayScale.y = 1 / (this.zoom || 1);
|
|
4883
5045
|
return this;
|
|
@@ -5147,6 +5309,7 @@ var Game = class {
|
|
|
5147
5309
|
destroyed = false;
|
|
5148
5310
|
ownedCanvas = false;
|
|
5149
5311
|
inStep = false;
|
|
5312
|
+
onWindowResize = null;
|
|
5150
5313
|
constructor(config = {}) {
|
|
5151
5314
|
this.config = config;
|
|
5152
5315
|
const fallbackDoc = typeof document !== "undefined" ? document : void 0;
|
|
@@ -5203,7 +5366,17 @@ var Game = class {
|
|
|
5203
5366
|
this.textures.invalidateAllGl();
|
|
5204
5367
|
for (let i = 0; i < this.scene.scenes.length; i++) this.scene.scenes[i]._invalidateTextGl();
|
|
5205
5368
|
};
|
|
5206
|
-
|
|
5369
|
+
const scaleMode = config.scale?.mode ?? Scale.NONE;
|
|
5370
|
+
this.scale = new ScaleManager(this.canvas, this.renderer, width, height, zoom, scaleMode);
|
|
5371
|
+
if (scaleMode === Scale.FIT) {
|
|
5372
|
+
this.scale.fitToContainer();
|
|
5373
|
+
if (this.win && typeof this.win.addEventListener === "function") {
|
|
5374
|
+
this.onWindowResize = () => {
|
|
5375
|
+
if (!this.destroyed) this.scale.fitToContainer();
|
|
5376
|
+
};
|
|
5377
|
+
this.win.addEventListener("resize", this.onWindowResize);
|
|
5378
|
+
}
|
|
5379
|
+
}
|
|
5207
5380
|
this.cache = { json: new JsonCache() };
|
|
5208
5381
|
this.scene = new SceneManager(this);
|
|
5209
5382
|
this.input = new InputPlugin(this.canvas, this.win, () => this.scene.getPrimaryCamera(), config.input, () => this.clock.frameSeq, () => this.inStep ? this.clock.frameSeq : this.clock.frameSeq + 1);
|
|
@@ -5256,10 +5429,16 @@ var Game = class {
|
|
|
5256
5429
|
try {
|
|
5257
5430
|
if (!this.stepSimOnly(time, delta)) return;
|
|
5258
5431
|
const scenes = this.scene.scenes;
|
|
5432
|
+
const lastDt = this.clock.lastDeltaMs;
|
|
5259
5433
|
this.events.emit("prerender", this.renderer);
|
|
5260
5434
|
for (let i = 0; i < scenes.length; i++) {
|
|
5261
5435
|
const sc = scenes[i];
|
|
5262
|
-
if (sc.sys.settings.status === Scenes.RUNNING)
|
|
5436
|
+
if (sc.sys.settings.status === Scenes.RUNNING) {
|
|
5437
|
+
sc.preRender?.(time, lastDt);
|
|
5438
|
+
this.kernel._prerenderScene(sc, this.renderer, time, lastDt);
|
|
5439
|
+
sc.events.emit("prerender", this.renderer, time, lastDt);
|
|
5440
|
+
this.renderer.render(sc._displayList, sc.cameras.main);
|
|
5441
|
+
}
|
|
5263
5442
|
}
|
|
5264
5443
|
this.kernel._postrender(this.renderer);
|
|
5265
5444
|
this.events.emit("postrender", this.renderer);
|
|
@@ -5272,6 +5451,10 @@ var Game = class {
|
|
|
5272
5451
|
this.pendingDestroy = true;
|
|
5273
5452
|
this.destroyed = true;
|
|
5274
5453
|
this.loop.destroy();
|
|
5454
|
+
if (this.onWindowResize && this.win && typeof this.win.removeEventListener === "function") {
|
|
5455
|
+
this.win.removeEventListener("resize", this.onWindowResize);
|
|
5456
|
+
this.onWindowResize = null;
|
|
5457
|
+
}
|
|
5275
5458
|
this.events.emit("destroy", this);
|
|
5276
5459
|
this.kernel.dispose();
|
|
5277
5460
|
this.scene.destroy();
|
|
@@ -5285,4 +5468,4 @@ var Game = class {
|
|
|
5285
5468
|
else if (removeCanvas) this.canvas.remove();
|
|
5286
5469
|
}
|
|
5287
5470
|
};
|
|
5288
|
-
export {
|
|
5471
|
+
export { CanvasTexture as _, JsonCache as a, TextureManager as b, Scene as c, KeyboardPlugin as d, Pointer as f, SdfPanelBatcher as g, MsdfIconBatcher as h, GameObjectFactory as i, SceneManager as l, PixelAaBatcher as m, Game as n, LoaderPlugin as o, RendererGl as p, GameLoop as r, ScaleManager as s, EngineClock as t, InputPlugin as u, Frame as v, TextureSource as x, Texture as y };
|