@lightningjs/renderer 2.3.2 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/common/CommonTypes.d.ts +6 -0
- package/dist/src/core/CoreNode.js +37 -39
- package/dist/src/core/CoreNode.js.map +1 -1
- package/dist/src/core/Stage.d.ts +1 -0
- package/dist/src/core/Stage.js +4 -1
- package/dist/src/core/Stage.js.map +1 -1
- package/dist/src/core/animations/CoreAnimation.d.ts +1 -0
- package/dist/src/core/animations/CoreAnimation.js +6 -0
- package/dist/src/core/animations/CoreAnimation.js.map +1 -1
- package/dist/src/core/animations/CoreAnimationController.d.ts +1 -0
- package/dist/src/core/animations/CoreAnimationController.js +6 -0
- package/dist/src/core/animations/CoreAnimationController.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlCoreCtxTexture.d.ts +1 -1
- package/dist/src/core/renderers/webgl/WebGlCoreCtxTexture.js +7 -1
- package/dist/src/core/renderers/webgl/WebGlCoreCtxTexture.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlCoreRenderOp.js +11 -4
- package/dist/src/core/renderers/webgl/WebGlCoreRenderOp.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js +94 -98
- package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js.map +1 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.js +3 -3
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.js.map +1 -1
- package/dist/src/core/textures/ColorTexture.d.ts +2 -1
- package/dist/src/core/textures/ColorTexture.js +2 -1
- package/dist/src/core/textures/ColorTexture.js.map +1 -1
- package/dist/src/core/textures/ImageTexture.d.ts +2 -1
- package/dist/src/core/textures/ImageTexture.js +4 -3
- package/dist/src/core/textures/ImageTexture.js.map +1 -1
- package/dist/src/core/textures/NoiseTexture.d.ts +2 -1
- package/dist/src/core/textures/NoiseTexture.js +2 -1
- package/dist/src/core/textures/NoiseTexture.js.map +1 -1
- package/dist/src/core/textures/RenderTexture.d.ts +2 -1
- package/dist/src/core/textures/RenderTexture.js +2 -1
- package/dist/src/core/textures/RenderTexture.js.map +1 -1
- package/dist/src/core/textures/SubTexture.d.ts +2 -1
- package/dist/src/core/textures/SubTexture.js +2 -1
- package/dist/src/core/textures/SubTexture.js.map +1 -1
- package/dist/src/core/textures/Texture.d.ts +9 -0
- package/dist/src/core/textures/Texture.js +10 -0
- package/dist/src/core/textures/Texture.js.map +1 -1
- package/dist/src/main-api/Renderer.js +1 -0
- package/dist/src/main-api/Renderer.js.map +1 -1
- package/dist/src/utils.js +1 -1
- package/dist/src/utils.js.map +1 -1
- package/dist/tsconfig.dist.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/common/CommonTypes.ts +7 -0
- package/src/core/CoreNode.ts +38 -55
- package/src/core/Stage.ts +6 -1
- package/src/core/animations/CoreAnimation.ts +7 -0
- package/src/core/animations/CoreAnimationController.ts +12 -0
- package/src/core/renderers/webgl/WebGlCoreCtxTexture.ts +7 -1
- package/src/core/renderers/webgl/WebGlCoreRenderOp.ts +13 -4
- package/src/core/renderers/webgl/WebGlCoreRenderer.ts +122 -136
- package/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.ts +3 -3
- package/src/core/textures/ColorTexture.ts +3 -1
- package/src/core/textures/ImageTexture.ts +5 -3
- package/src/core/textures/NoiseTexture.ts +3 -1
- package/src/core/textures/RenderTexture.ts +3 -1
- package/src/core/textures/SubTexture.ts +3 -0
- package/src/core/textures/Texture.ts +11 -0
- package/src/main-api/Renderer.ts +1 -0
- package/src/utils.ts +1 -1
package/src/core/CoreNode.ts
CHANGED
|
@@ -759,10 +759,11 @@ export class CoreNode extends EventEmitter {
|
|
|
759
759
|
this.src = props.src;
|
|
760
760
|
this.rtt = props.rtt;
|
|
761
761
|
|
|
762
|
-
this.updateScaleRotateTransform();
|
|
763
|
-
|
|
764
762
|
this.setUpdateType(
|
|
765
|
-
UpdateType.
|
|
763
|
+
UpdateType.ScaleRotate |
|
|
764
|
+
UpdateType.Local |
|
|
765
|
+
UpdateType.RenderBounds |
|
|
766
|
+
UpdateType.RenderState,
|
|
766
767
|
);
|
|
767
768
|
}
|
|
768
769
|
|
|
@@ -797,7 +798,7 @@ export class CoreNode extends EventEmitter {
|
|
|
797
798
|
}
|
|
798
799
|
|
|
799
800
|
unloadTexture(): void {
|
|
800
|
-
if (this.texture) {
|
|
801
|
+
if (this.texture !== null) {
|
|
801
802
|
this.texture.off('loaded', this.onTextureLoaded);
|
|
802
803
|
this.texture.off('failed', this.onTextureFailed);
|
|
803
804
|
this.texture.off('freed', this.onTextureFreed);
|
|
@@ -1459,24 +1460,23 @@ export class CoreNode extends EventEmitter {
|
|
|
1459
1460
|
this.unloadTexture();
|
|
1460
1461
|
|
|
1461
1462
|
this.clippingRect.valid = false;
|
|
1462
|
-
|
|
1463
1463
|
this.isRenderable = false;
|
|
1464
1464
|
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1465
|
+
this.renderCoords = undefined;
|
|
1466
|
+
this.renderBound = undefined;
|
|
1467
|
+
this.strictBound = undefined;
|
|
1468
|
+
this.preloadBound = undefined;
|
|
1469
|
+
this.globalTransform = undefined;
|
|
1470
|
+
this.scaleRotateTransform = undefined;
|
|
1471
|
+
this.localTransform = undefined;
|
|
1472
1472
|
|
|
1473
1473
|
this.props.texture = null;
|
|
1474
1474
|
this.props.shader = this.stage.defShaderCtr;
|
|
1475
1475
|
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
children[i]!.destroy();
|
|
1476
|
+
while (this.children.length > 0) {
|
|
1477
|
+
this.children[0]?.destroy();
|
|
1479
1478
|
}
|
|
1479
|
+
|
|
1480
1480
|
// This very action will also remove the node from the parent's children array
|
|
1481
1481
|
this.parent = null;
|
|
1482
1482
|
|
|
@@ -1488,8 +1488,6 @@ export class CoreNode extends EventEmitter {
|
|
|
1488
1488
|
}
|
|
1489
1489
|
|
|
1490
1490
|
renderQuads(renderer: CoreRenderer): void {
|
|
1491
|
-
const { texture, width, height, textureOptions, rtt, shader } = this.props;
|
|
1492
|
-
|
|
1493
1491
|
// Prevent quad rendering if parent has a render texture
|
|
1494
1492
|
// and renderer is not currently rendering to a texture
|
|
1495
1493
|
if (this.parentHasRenderTexture) {
|
|
@@ -1502,47 +1500,32 @@ export class CoreNode extends EventEmitter {
|
|
|
1502
1500
|
}
|
|
1503
1501
|
}
|
|
1504
1502
|
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
premultipliedColorTr,
|
|
1508
|
-
premultipliedColorBl,
|
|
1509
|
-
premultipliedColorBr,
|
|
1510
|
-
} = this;
|
|
1511
|
-
|
|
1512
|
-
const {
|
|
1513
|
-
zIndex,
|
|
1514
|
-
worldAlpha,
|
|
1515
|
-
globalTransform: gt,
|
|
1516
|
-
clippingRect,
|
|
1517
|
-
renderCoords,
|
|
1518
|
-
} = this;
|
|
1519
|
-
|
|
1520
|
-
assertTruthy(gt);
|
|
1521
|
-
assertTruthy(renderCoords);
|
|
1503
|
+
assertTruthy(this.globalTransform);
|
|
1504
|
+
assertTruthy(this.renderCoords);
|
|
1522
1505
|
|
|
1523
1506
|
// add to list of renderables to be sorted before rendering
|
|
1524
1507
|
renderer.addQuad({
|
|
1525
|
-
width,
|
|
1526
|
-
height,
|
|
1527
|
-
colorTl: premultipliedColorTl,
|
|
1528
|
-
colorTr: premultipliedColorTr,
|
|
1529
|
-
colorBl: premultipliedColorBl,
|
|
1530
|
-
colorBr: premultipliedColorBr,
|
|
1531
|
-
texture,
|
|
1532
|
-
textureOptions,
|
|
1533
|
-
zIndex,
|
|
1534
|
-
shader: shader.shader,
|
|
1535
|
-
shaderProps: shader.getResolvedProps(),
|
|
1536
|
-
alpha: worldAlpha,
|
|
1537
|
-
clippingRect,
|
|
1538
|
-
tx:
|
|
1539
|
-
ty:
|
|
1540
|
-
ta:
|
|
1541
|
-
tb:
|
|
1542
|
-
tc:
|
|
1543
|
-
td:
|
|
1544
|
-
renderCoords,
|
|
1545
|
-
rtt,
|
|
1508
|
+
width: this.props.width,
|
|
1509
|
+
height: this.props.height,
|
|
1510
|
+
colorTl: this.premultipliedColorTl,
|
|
1511
|
+
colorTr: this.premultipliedColorTr,
|
|
1512
|
+
colorBl: this.premultipliedColorBl,
|
|
1513
|
+
colorBr: this.premultipliedColorBr,
|
|
1514
|
+
texture: this.texture,
|
|
1515
|
+
textureOptions: this.textureOptions,
|
|
1516
|
+
zIndex: this.zIndex,
|
|
1517
|
+
shader: this.shader.shader,
|
|
1518
|
+
shaderProps: this.shader.getResolvedProps(),
|
|
1519
|
+
alpha: this.worldAlpha,
|
|
1520
|
+
clippingRect: this.clippingRect,
|
|
1521
|
+
tx: this.globalTransform.tx,
|
|
1522
|
+
ty: this.globalTransform.ty,
|
|
1523
|
+
ta: this.globalTransform.ta,
|
|
1524
|
+
tb: this.globalTransform.tb,
|
|
1525
|
+
tc: this.globalTransform.tc,
|
|
1526
|
+
td: this.globalTransform.td,
|
|
1527
|
+
renderCoords: this.renderCoords,
|
|
1528
|
+
rtt: this.rtt,
|
|
1546
1529
|
parentHasRenderTexture: this.parentHasRenderTexture,
|
|
1547
1530
|
framebufferDimensions: this.framebufferDimensions,
|
|
1548
1531
|
});
|
package/src/core/Stage.ts
CHANGED
|
@@ -70,6 +70,7 @@ export interface StageOptions {
|
|
|
70
70
|
eventBus: EventEmitter;
|
|
71
71
|
quadBufferSize: number;
|
|
72
72
|
fontEngines: (typeof CanvasTextRenderer | typeof SdfTextRenderer)[];
|
|
73
|
+
inspector: boolean;
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
export type StageFpsUpdateHandler = (
|
|
@@ -580,7 +581,11 @@ export class Stage {
|
|
|
580
581
|
props.colorBl ?? props.colorBottom ?? props.colorLeft ?? color;
|
|
581
582
|
const colorBr =
|
|
582
583
|
props.colorBr ?? props.colorBottom ?? props.colorRight ?? color;
|
|
583
|
-
|
|
584
|
+
|
|
585
|
+
let data = {};
|
|
586
|
+
if (this.options.inspector === true) {
|
|
587
|
+
data = santizeCustomDataMap(props.data ?? {});
|
|
588
|
+
}
|
|
584
589
|
|
|
585
590
|
return {
|
|
586
591
|
x: props.x ?? 0,
|
|
@@ -42,6 +42,7 @@ export class CoreAnimation extends EventEmitter {
|
|
|
42
42
|
public settings: AnimationSettings;
|
|
43
43
|
private progress = 0;
|
|
44
44
|
private delayFor = 0;
|
|
45
|
+
private delay = 0;
|
|
45
46
|
private timingFunction: (t: number) => number | undefined;
|
|
46
47
|
|
|
47
48
|
propValuesMap: PropValuesMap = {};
|
|
@@ -109,6 +110,7 @@ export class CoreAnimation extends EventEmitter {
|
|
|
109
110
|
};
|
|
110
111
|
this.timingFunction = getTimingFunction(easing);
|
|
111
112
|
this.delayFor = delay;
|
|
113
|
+
this.delay = delay;
|
|
112
114
|
}
|
|
113
115
|
|
|
114
116
|
reset() {
|
|
@@ -287,6 +289,7 @@ export class CoreAnimation extends EventEmitter {
|
|
|
287
289
|
|
|
288
290
|
if (this.progress > 1) {
|
|
289
291
|
this.progress = loop ? 0 : 1;
|
|
292
|
+
this.delayFor = this.delay;
|
|
290
293
|
if (stopMethod) {
|
|
291
294
|
// If there's a stop method emit finished so the stop method can be applied.
|
|
292
295
|
// TODO: We should probably reevaluate how stopMethod is implemented as currently
|
|
@@ -326,6 +329,10 @@ export class CoreAnimation extends EventEmitter {
|
|
|
326
329
|
}
|
|
327
330
|
}
|
|
328
331
|
|
|
332
|
+
if (this.progress < 1) {
|
|
333
|
+
this.emit('tick', { progress: this.progress });
|
|
334
|
+
}
|
|
335
|
+
|
|
329
336
|
if (this.progress === 1) {
|
|
330
337
|
this.emit('finished', {});
|
|
331
338
|
}
|
|
@@ -26,6 +26,7 @@ import type { AnimationManager } from './AnimationManager.js';
|
|
|
26
26
|
import type { CoreAnimation } from './CoreAnimation.js';
|
|
27
27
|
import { assertTruthy } from '../../utils.js';
|
|
28
28
|
import { EventEmitter } from '../../common/EventEmitter.js';
|
|
29
|
+
import type { AnimationTickPayload } from '../../common/CommonTypes.js';
|
|
29
30
|
|
|
30
31
|
export class CoreAnimationController
|
|
31
32
|
extends EventEmitter
|
|
@@ -50,6 +51,7 @@ export class CoreAnimationController
|
|
|
50
51
|
// Bind event handlers
|
|
51
52
|
this.onAnimating = this.onAnimating.bind(this);
|
|
52
53
|
this.onFinished = this.onFinished.bind(this);
|
|
54
|
+
this.onTick = this.onTick.bind(this);
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
start(): IAnimationController {
|
|
@@ -93,6 +95,7 @@ export class CoreAnimationController
|
|
|
93
95
|
// Hook up event listeners
|
|
94
96
|
this.animation.once('finished', this.onFinished);
|
|
95
97
|
this.animation.on('animating', this.onAnimating);
|
|
98
|
+
this.animation.on('tick', this.onTick);
|
|
96
99
|
// Then register the animation
|
|
97
100
|
this.manager.registerAnimation(this.animation);
|
|
98
101
|
}
|
|
@@ -103,6 +106,7 @@ export class CoreAnimationController
|
|
|
103
106
|
// Then unhook event listeners
|
|
104
107
|
this.animation.off('finished', this.onFinished);
|
|
105
108
|
this.animation.off('animating', this.onAnimating);
|
|
109
|
+
this.animation.off('tick', this.onTick);
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
private makeStoppedPromise(): void {
|
|
@@ -142,4 +146,12 @@ export class CoreAnimationController
|
|
|
142
146
|
this.state = 'running';
|
|
143
147
|
this.emit('animating', this);
|
|
144
148
|
}
|
|
149
|
+
|
|
150
|
+
private onTick(
|
|
151
|
+
this: CoreAnimationController,
|
|
152
|
+
_animation: CoreAnimation,
|
|
153
|
+
data: AnimationTickPayload,
|
|
154
|
+
): void {
|
|
155
|
+
this.emit('tick', data);
|
|
156
|
+
}
|
|
145
157
|
}
|
|
@@ -86,6 +86,12 @@ export class WebGlCoreCtxTexture extends CoreContextTexture {
|
|
|
86
86
|
this._state = 'loading';
|
|
87
87
|
this.textureSource.setState('loading');
|
|
88
88
|
this._nativeCtxTexture = this.createNativeCtxTexture();
|
|
89
|
+
if (this._nativeCtxTexture === null) {
|
|
90
|
+
this._state = 'failed';
|
|
91
|
+
this.textureSource.setState('failed', new Error('Could not create WebGL Texture'));
|
|
92
|
+
console.error('Could not create WebGL Texture');
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
89
95
|
this.onLoadRequest()
|
|
90
96
|
.then(({ width, height }) => {
|
|
91
97
|
// If the texture has been freed while loading, return early.
|
|
@@ -245,7 +251,7 @@ export class WebGlCoreCtxTexture extends CoreContextTexture {
|
|
|
245
251
|
const { glw } = this;
|
|
246
252
|
const nativeTexture = glw.createTexture();
|
|
247
253
|
if (!nativeTexture) {
|
|
248
|
-
|
|
254
|
+
return null;
|
|
249
255
|
}
|
|
250
256
|
|
|
251
257
|
// On initial load request, create a 1x1 transparent texture to use until
|
|
@@ -61,16 +61,25 @@ export class WebGlCoreRenderOp extends CoreRenderOp {
|
|
|
61
61
|
|
|
62
62
|
addTexture(texture: WebGlCoreCtxTexture): number {
|
|
63
63
|
const { textures, maxTextures } = this;
|
|
64
|
-
|
|
64
|
+
let existingIdx = -1;
|
|
65
|
+
const texturesLength = textures.length;
|
|
66
|
+
for (let i = 0; i < texturesLength; i++) {
|
|
67
|
+
const t = textures[i];
|
|
68
|
+
if (t === texture) {
|
|
69
|
+
existingIdx = i;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
65
74
|
if (existingIdx !== -1) {
|
|
66
75
|
return existingIdx;
|
|
67
76
|
}
|
|
68
|
-
|
|
69
|
-
if (
|
|
77
|
+
|
|
78
|
+
if (texturesLength >= maxTextures) {
|
|
70
79
|
return 0xffffffff;
|
|
71
80
|
}
|
|
72
81
|
this.textures.push(texture);
|
|
73
|
-
return
|
|
82
|
+
return texturesLength;
|
|
74
83
|
}
|
|
75
84
|
|
|
76
85
|
draw() {
|