@lightningjs/renderer 2.11.1 → 2.12.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/CoreTextureManager.d.ts +5 -1
- package/dist/src/core/CoreTextureManager.js +40 -12
- package/dist/src/core/CoreTextureManager.js.map +1 -1
- package/dist/src/core/CoreTexturizer.d.ts +14 -0
- package/dist/src/core/CoreTexturizer.js +47 -0
- package/dist/src/core/CoreTexturizer.js.map +1 -0
- package/dist/src/core/Stage.d.ts +9 -0
- package/dist/src/core/Stage.js +20 -1
- package/dist/src/core/Stage.js.map +1 -1
- package/dist/src/core/lib/ImageWorker.js +2 -1
- package/dist/src/core/lib/ImageWorker.js.map +1 -1
- package/dist/src/core/renderers/CoreRenderer.d.ts +1 -0
- package/dist/src/core/renderers/CoreRenderer.js.map +1 -1
- package/dist/src/core/renderers/canvas/CanvasCoreRenderer.d.ts +1 -0
- package/dist/src/core/renderers/canvas/CanvasCoreRenderer.js +3 -0
- package/dist/src/core/renderers/canvas/CanvasCoreRenderer.js.map +1 -1
- package/dist/src/core/renderers/canvas/CanvasCoreTexture.js +3 -0
- package/dist/src/core/renderers/canvas/CanvasCoreTexture.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlCoreCtxTexture.js +5 -0
- package/dist/src/core/renderers/webgl/WebGlCoreCtxTexture.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlCoreRenderer.d.ts +2 -0
- package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js +7 -0
- package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js.map +1 -1
- package/dist/src/core/renderers/webgl/shaders/effects/EffectUtils.js +2 -2
- package/dist/src/core/text-rendering/font-face-types/SdfTrFontFace/SdfTrFontFace.d.ts +1 -1
- package/dist/src/core/text-rendering/font-face-types/SdfTrFontFace/SdfTrFontFace.js +5 -5
- package/dist/src/core/text-rendering/font-face-types/SdfTrFontFace/SdfTrFontFace.js.map +1 -1
- package/dist/src/core/text-rendering/font-face-types/utils.d.ts +1 -0
- package/dist/src/core/text-rendering/font-face-types/utils.js +38 -0
- package/dist/src/core/text-rendering/font-face-types/utils.js.map +1 -0
- package/dist/src/core/textures/ImageTexture.js +2 -1
- package/dist/src/core/textures/ImageTexture.js.map +1 -1
- package/dist/src/core/textures/SubTexture.js +3 -19
- package/dist/src/core/textures/SubTexture.js.map +1 -1
- package/dist/src/core/textures/Texture.js +0 -7
- package/dist/src/core/textures/Texture.js.map +1 -1
- package/dist/src/main-api/Renderer.d.ts +19 -0
- package/dist/src/main-api/Renderer.js +21 -0
- package/dist/src/main-api/Renderer.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/CoreTextureManager.ts +50 -15
- package/src/core/Stage.ts +23 -1
- package/src/core/lib/ImageWorker.ts +2 -1
- package/src/core/renderers/CoreRenderer.ts +1 -0
- package/src/core/renderers/canvas/CanvasCoreRenderer.ts +4 -0
- package/src/core/renderers/canvas/CanvasCoreTexture.ts +3 -0
- package/src/core/renderers/webgl/WebGlCoreCtxTexture.ts +8 -0
- package/src/core/renderers/webgl/WebGlCoreRenderer.ts +9 -0
- package/src/core/renderers/webgl/shaders/effects/EffectUtils.ts +2 -2
- package/src/core/text-rendering/font-face-types/SdfTrFontFace/SdfTrFontFace.ts +5 -5
- package/src/core/text-rendering/font-face-types/utils.ts +39 -0
- package/src/core/textures/ImageTexture.ts +4 -1
- package/src/core/textures/SubTexture.ts +3 -23
- package/src/core/textures/Texture.ts +0 -10
- package/src/main-api/Renderer.ts +22 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* If not stated otherwise in this file or this component's LICENSE file the
|
|
3
|
+
* following copyright and licenses apply:
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2020 Metrological
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the License);
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
export function fetchJson(
|
|
20
|
+
url: string,
|
|
21
|
+
responseType: XMLHttpRequestResponseType = '',
|
|
22
|
+
): Promise<unknown> {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
const xhr = new XMLHttpRequest();
|
|
25
|
+
xhr.responseType = responseType;
|
|
26
|
+
xhr.onreadystatechange = function () {
|
|
27
|
+
if (xhr.readyState == XMLHttpRequest.DONE) {
|
|
28
|
+
// On most devices like WebOS and Tizen, the file protocol returns 0 while http(s) protocol returns 200
|
|
29
|
+
if (xhr.status === 0 || xhr.status === 200) {
|
|
30
|
+
resolve(xhr.response);
|
|
31
|
+
} else {
|
|
32
|
+
reject(xhr.statusText);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
xhr.open('GET', url, true);
|
|
37
|
+
xhr.send(null);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
} from '../lib/textureCompression.js';
|
|
26
26
|
import { convertUrlToAbsolute, isBase64Image } from '../lib/utils.js';
|
|
27
27
|
import { isSvgImage, loadSvg } from '../lib/textureSvg.js';
|
|
28
|
+
import { fetchJson } from '../text-rendering/font-face-types/utils.js';
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* Properties of the {@link ImageTexture}
|
|
@@ -220,7 +221,9 @@ export class ImageTexture extends Texture {
|
|
|
220
221
|
);
|
|
221
222
|
}
|
|
222
223
|
|
|
223
|
-
const blob = await
|
|
224
|
+
const blob = await fetchJson(src, 'blob').then(
|
|
225
|
+
(response) => response as Blob,
|
|
226
|
+
);
|
|
224
227
|
return this.createImageBitmap(blob, premultiplyAlpha, sx, sy, sw, sh);
|
|
225
228
|
}
|
|
226
229
|
|
|
@@ -137,14 +137,10 @@ export class SubTexture extends Texture {
|
|
|
137
137
|
width: this.props.width,
|
|
138
138
|
height: this.props.height,
|
|
139
139
|
});
|
|
140
|
-
|
|
141
|
-
// free our source, if any
|
|
142
|
-
this.freeTextureData();
|
|
143
140
|
};
|
|
144
141
|
|
|
145
142
|
private onParentTxFailed: TextureFailedEventHandler = (target, error) => {
|
|
146
143
|
this.forwardParentTxState('failed', error);
|
|
147
|
-
this.free();
|
|
148
144
|
};
|
|
149
145
|
|
|
150
146
|
private onParentTxFetched = () => {
|
|
@@ -164,7 +160,6 @@ export class SubTexture extends Texture {
|
|
|
164
160
|
|
|
165
161
|
private onParentTxFreed = () => {
|
|
166
162
|
this.forwardParentTxState('freed');
|
|
167
|
-
this.free();
|
|
168
163
|
};
|
|
169
164
|
|
|
170
165
|
private forwardParentTxState(
|
|
@@ -182,24 +177,9 @@ export class SubTexture extends Texture {
|
|
|
182
177
|
override async getTextureSource(): Promise<TextureData> {
|
|
183
178
|
// Check if parent texture is loaded
|
|
184
179
|
return new Promise((resolve, reject) => {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
this.parentTexture.once('loaded', (target, data) => {
|
|
192
|
-
resolve({
|
|
193
|
-
data: this.props,
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
this.parentTexture.once('failed', (target, error) => {
|
|
198
|
-
reject(error);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
this.parentTexture.once('freed', () => {
|
|
202
|
-
reject(new Error('Parent texture was freed'));
|
|
180
|
+
this.setState('fetched');
|
|
181
|
+
resolve({
|
|
182
|
+
data: this.props,
|
|
203
183
|
});
|
|
204
184
|
});
|
|
205
185
|
}
|
|
@@ -200,15 +200,6 @@ export abstract class Texture extends EventEmitter {
|
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
load(): void {
|
|
203
|
-
if (
|
|
204
|
-
this.state === 'fetching' ||
|
|
205
|
-
this.state === 'loading' ||
|
|
206
|
-
this.state === 'loaded' ||
|
|
207
|
-
this.state === 'failed'
|
|
208
|
-
) {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
203
|
this.txManager.loadTexture(this);
|
|
213
204
|
}
|
|
214
205
|
|
|
@@ -245,7 +236,6 @@ export abstract class Texture extends EventEmitter {
|
|
|
245
236
|
*/
|
|
246
237
|
free(): void {
|
|
247
238
|
this.ctxTexture?.free();
|
|
248
|
-
this.textureData = null;
|
|
249
239
|
}
|
|
250
240
|
|
|
251
241
|
/**
|
package/src/main-api/Renderer.ts
CHANGED
|
@@ -319,6 +319,8 @@ export interface RendererMainSettings {
|
|
|
319
319
|
* - Emitted every `fpsUpdateInterval` milliseconds with the current FPS
|
|
320
320
|
* - `frameTick`
|
|
321
321
|
* - Emitted every frame tick
|
|
322
|
+
* - `quadsUpdate`
|
|
323
|
+
* - Emitted when number of quads rendered is updated
|
|
322
324
|
* - `idle`
|
|
323
325
|
* - Emitted when the renderer is idle (no changes to the scene
|
|
324
326
|
* graph/animations running)
|
|
@@ -687,6 +689,26 @@ export class RendererMain extends EventEmitter {
|
|
|
687
689
|
this.stage.requestRender();
|
|
688
690
|
}
|
|
689
691
|
|
|
692
|
+
/**
|
|
693
|
+
* Cleanup textures that are not being used
|
|
694
|
+
*
|
|
695
|
+
* @remarks
|
|
696
|
+
* This can be used to free up GFX memory used by textures that are no longer
|
|
697
|
+
* being displayed.
|
|
698
|
+
*
|
|
699
|
+
* This routine is also called automatically when the memory used by textures
|
|
700
|
+
* exceeds the critical threshold on frame generation **OR** when the renderer
|
|
701
|
+
* is idle and the memory used by textures exceeds the target threshold.
|
|
702
|
+
*
|
|
703
|
+
* **NOTE**: This is a heavy operation and should be used sparingly.
|
|
704
|
+
* **NOTE2**: This will not cleanup textures that are currently being displayed.
|
|
705
|
+
* **NOTE3**: This will not cleanup textures that are marked as `preventCleanup`.
|
|
706
|
+
* **NOTE4**: This has nothing to do with the garbage collection of JavaScript.
|
|
707
|
+
*/
|
|
708
|
+
cleanup() {
|
|
709
|
+
this.stage.cleanup();
|
|
710
|
+
}
|
|
711
|
+
|
|
690
712
|
/**
|
|
691
713
|
* Sets the clear color for the stage.
|
|
692
714
|
*
|