@lightningjs/renderer 2.3.1 → 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/TrFontManager.d.ts +2 -1
- package/dist/src/core/text-rendering/TrFontManager.js +5 -5
- package/dist/src/core/text-rendering/TrFontManager.js.map +1 -1
- package/dist/src/core/text-rendering/renderers/CanvasTextRenderer.js +1 -1
- package/dist/src/core/text-rendering/renderers/CanvasTextRenderer.js.map +1 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.js +4 -4
- 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/core/utils.d.ts +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/TrFontManager.ts +6 -6
- package/src/core/text-rendering/renderers/CanvasTextRenderer.ts +1 -1
- package/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.ts +4 -4
- 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/dist/exports/core-api.d.ts +0 -74
- package/dist/exports/core-api.js +0 -96
- package/dist/exports/core-api.js.map +0 -1
- package/dist/exports/main-api.d.ts +0 -30
- package/dist/exports/main-api.js +0 -45
- package/dist/exports/main-api.js.map +0 -1
- package/dist/src/core/CoreExtension.d.ts +0 -12
- package/dist/src/core/CoreExtension.js +0 -29
- package/dist/src/core/CoreExtension.js.map +0 -1
- package/dist/src/main-api/ICoreDriver.d.ts +0 -24
- package/dist/src/main-api/ICoreDriver.js +0 -20
- package/dist/src/main-api/ICoreDriver.js.map +0 -1
- package/dist/src/main-api/RendererMain.d.ts +0 -378
- package/dist/src/main-api/RendererMain.js +0 -367
- package/dist/src/main-api/RendererMain.js.map +0 -1
- package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.d.ts +0 -9
- package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.js +0 -38
- package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.js.map +0 -1
- package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.d.ts +0 -56
- package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.js +0 -101
- package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.js.map +0 -1
- package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.d.ts +0 -32
- package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.js +0 -28
- package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.js.map +0 -1
- package/dist/src/render-drivers/main/MainCoreDriver.d.ts +0 -21
- package/dist/src/render-drivers/main/MainCoreDriver.js +0 -115
- package/dist/src/render-drivers/main/MainCoreDriver.js.map +0 -1
- package/dist/src/render-drivers/main/MainOnlyNode.d.ts +0 -101
- package/dist/src/render-drivers/main/MainOnlyNode.js +0 -425
- package/dist/src/render-drivers/main/MainOnlyNode.js.map +0 -1
- package/dist/src/render-drivers/main/MainOnlyTextNode.d.ts +0 -47
- package/dist/src/render-drivers/main/MainOnlyTextNode.js +0 -204
- package/dist/src/render-drivers/main/MainOnlyTextNode.js.map +0 -1
- package/dist/src/render-drivers/threadx/NodeStruct.d.ts +0 -93
- package/dist/src/render-drivers/threadx/NodeStruct.js +0 -290
- package/dist/src/render-drivers/threadx/NodeStruct.js.map +0 -1
- package/dist/src/render-drivers/threadx/SharedNode.d.ts +0 -40
- package/dist/src/render-drivers/threadx/SharedNode.js +0 -61
- package/dist/src/render-drivers/threadx/SharedNode.js.map +0 -1
- package/dist/src/render-drivers/threadx/TextNodeStruct.d.ts +0 -44
- package/dist/src/render-drivers/threadx/TextNodeStruct.js +0 -203
- package/dist/src/render-drivers/threadx/TextNodeStruct.js.map +0 -1
- package/dist/src/render-drivers/threadx/ThreadXCoreDriver.d.ts +0 -25
- package/dist/src/render-drivers/threadx/ThreadXCoreDriver.js +0 -232
- package/dist/src/render-drivers/threadx/ThreadXCoreDriver.js.map +0 -1
- package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.d.ts +0 -24
- package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.js +0 -113
- package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.js.map +0 -1
- package/dist/src/render-drivers/threadx/ThreadXMainNode.d.ts +0 -46
- package/dist/src/render-drivers/threadx/ThreadXMainNode.js +0 -160
- package/dist/src/render-drivers/threadx/ThreadXMainNode.js.map +0 -1
- package/dist/src/render-drivers/threadx/ThreadXMainTextNode.d.ts +0 -28
- package/dist/src/render-drivers/threadx/ThreadXMainTextNode.js +0 -55
- package/dist/src/render-drivers/threadx/ThreadXMainTextNode.js.map +0 -1
- package/dist/src/render-drivers/threadx/ThreadXRendererMessage.d.ts +0 -70
- package/dist/src/render-drivers/threadx/ThreadXRendererMessage.js +0 -32
- package/dist/src/render-drivers/threadx/ThreadXRendererMessage.js.map +0 -1
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.d.ts +0 -19
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.js +0 -184
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.js.map +0 -1
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.d.ts +0 -27
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.js +0 -109
- package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.js.map +0 -1
- package/dist/src/render-drivers/threadx/worker/renderer.d.ts +0 -1
- package/dist/src/render-drivers/threadx/worker/renderer.js +0 -147
- package/dist/src/render-drivers/threadx/worker/renderer.js.map +0 -1
- package/dist/src/render-drivers/utils.d.ts +0 -12
- package/dist/src/render-drivers/utils.js +0 -74
- package/dist/src/render-drivers/utils.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
getWebGlExtensions,
|
|
35
35
|
} from './internal/RendererUtils.js';
|
|
36
36
|
import { WebGlCoreCtxTexture } from './WebGlCoreCtxTexture.js';
|
|
37
|
-
import { Texture } from '../../textures/Texture.js';
|
|
37
|
+
import { Texture, TextureType } from '../../textures/Texture.js';
|
|
38
38
|
import { ColorTexture } from '../../textures/ColorTexture.js';
|
|
39
39
|
import { SubTexture } from '../../textures/SubTexture.js';
|
|
40
40
|
import { WebGlCoreCtxSubTexture } from './WebGlCoreCtxSubTexture.js';
|
|
@@ -231,232 +231,220 @@ export class WebGlCoreRenderer extends CoreRenderer {
|
|
|
231
231
|
*/
|
|
232
232
|
addQuad(params: QuadOptions) {
|
|
233
233
|
const { fQuadBuffer, uiQuadBuffer } = this;
|
|
234
|
-
|
|
235
|
-
width,
|
|
236
|
-
height,
|
|
237
|
-
colorTl,
|
|
238
|
-
colorTr,
|
|
239
|
-
colorBl,
|
|
240
|
-
colorBr,
|
|
241
|
-
textureOptions,
|
|
242
|
-
shader,
|
|
243
|
-
shaderProps,
|
|
244
|
-
alpha,
|
|
245
|
-
clippingRect,
|
|
246
|
-
tx,
|
|
247
|
-
ty,
|
|
248
|
-
ta,
|
|
249
|
-
tb,
|
|
250
|
-
tc,
|
|
251
|
-
td,
|
|
252
|
-
renderCoords,
|
|
253
|
-
rtt: renderToTexture,
|
|
254
|
-
parentHasRenderTexture,
|
|
255
|
-
framebufferDimensions,
|
|
256
|
-
} = params;
|
|
257
|
-
let { texture } = params;
|
|
234
|
+
let texture = params.texture || this.defaultTexture;
|
|
258
235
|
|
|
259
236
|
/**
|
|
260
237
|
* If the shader props contain any automatic properties, update it with the
|
|
261
238
|
* current dimensions and or alpha that will be used to render the quad.
|
|
262
239
|
*/
|
|
263
|
-
if (shaderProps !== null) {
|
|
264
|
-
if (hasOwn(shaderProps, '$dimensions')) {
|
|
265
|
-
const dimensions = shaderProps.$dimensions as Dimensions;
|
|
266
|
-
dimensions.width = width;
|
|
267
|
-
dimensions.height = height;
|
|
240
|
+
if (params.shaderProps !== null) {
|
|
241
|
+
if (hasOwn(params.shaderProps, '$dimensions') == true) {
|
|
242
|
+
const dimensions = params.shaderProps.$dimensions as Dimensions;
|
|
243
|
+
dimensions.width = params.width;
|
|
244
|
+
dimensions.height = params.height;
|
|
268
245
|
}
|
|
269
246
|
|
|
270
|
-
if (hasOwn(shaderProps, '$alpha')) {
|
|
271
|
-
shaderProps.$alpha = alpha;
|
|
247
|
+
if (hasOwn(params.shaderProps, '$alpha') === true) {
|
|
248
|
+
params.shaderProps.$alpha = params.alpha;
|
|
272
249
|
}
|
|
273
250
|
}
|
|
274
251
|
|
|
275
|
-
texture
|
|
276
|
-
assertTruthy(texture instanceof Texture, 'Invalid texture type');
|
|
252
|
+
assertTruthy(texture.ctxTexture !== undefined, 'Invalid texture type');
|
|
277
253
|
|
|
278
254
|
let { curBufferIdx: bufferIdx, curRenderOp } = this;
|
|
279
|
-
const targetDims = {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const targetShader =
|
|
284
|
-
|
|
255
|
+
const targetDims = { width: -1, height: -1 };
|
|
256
|
+
targetDims.width = params.width;
|
|
257
|
+
targetDims.height = params.height;
|
|
258
|
+
|
|
259
|
+
const targetShader =
|
|
260
|
+
(params.shader as WebGlCoreShader) || this.defaultShader;
|
|
261
|
+
assertTruthy(
|
|
262
|
+
targetShader.getUniformLocation !== undefined,
|
|
263
|
+
'Invalid WebGL shader',
|
|
264
|
+
);
|
|
285
265
|
|
|
286
|
-
if (
|
|
266
|
+
if (this.reuseRenderOp(params) === false) {
|
|
287
267
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
288
268
|
this.newRenderOp(
|
|
289
269
|
targetShader,
|
|
290
|
-
shaderProps as Record<string, unknown>,
|
|
291
|
-
alpha,
|
|
270
|
+
params.shaderProps as Record<string, unknown>,
|
|
271
|
+
params.alpha,
|
|
292
272
|
targetDims,
|
|
293
|
-
clippingRect,
|
|
273
|
+
params.clippingRect,
|
|
294
274
|
bufferIdx,
|
|
295
|
-
|
|
296
|
-
parentHasRenderTexture,
|
|
297
|
-
framebufferDimensions,
|
|
275
|
+
params.rtt,
|
|
276
|
+
params.parentHasRenderTexture,
|
|
277
|
+
params.framebufferDimensions,
|
|
298
278
|
);
|
|
299
279
|
curRenderOp = this.curRenderOp;
|
|
300
280
|
assertTruthy(curRenderOp);
|
|
301
281
|
}
|
|
302
282
|
|
|
303
|
-
const flipX = textureOptions?.flipX ?? false;
|
|
304
|
-
let flipY = textureOptions?.flipY ?? false;
|
|
305
|
-
|
|
306
|
-
// always flip flipY for render textures
|
|
307
|
-
if (texture instanceof RenderTexture) {
|
|
308
|
-
flipY = !flipY;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
283
|
let texCoordX1 = 0;
|
|
312
284
|
let texCoordY1 = 0;
|
|
313
285
|
let texCoordX2 = 1;
|
|
314
286
|
let texCoordY2 = 1;
|
|
315
287
|
|
|
316
|
-
if (texture
|
|
317
|
-
const {
|
|
318
|
-
|
|
319
|
-
|
|
288
|
+
if (texture.type === TextureType.subTexture) {
|
|
289
|
+
const {
|
|
290
|
+
x: tx,
|
|
291
|
+
y: ty,
|
|
292
|
+
width: tw,
|
|
293
|
+
height: th,
|
|
294
|
+
} = (texture as SubTexture).props;
|
|
295
|
+
const { width: parentW = 0, height: parentH = 0 } = (
|
|
296
|
+
texture as SubTexture
|
|
297
|
+
).parentTexture.dimensions || { width: 0, height: 0 };
|
|
320
298
|
texCoordX1 = tx / parentW;
|
|
321
299
|
texCoordX2 = texCoordX1 + tw / parentW;
|
|
322
300
|
texCoordY1 = ty / parentH;
|
|
323
301
|
texCoordY2 = texCoordY1 + th / parentH;
|
|
324
|
-
texture = texture.parentTexture;
|
|
302
|
+
texture = (texture as SubTexture).parentTexture;
|
|
325
303
|
}
|
|
326
304
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
305
|
+
if (
|
|
306
|
+
texture.type === TextureType.image &&
|
|
307
|
+
params.textureOptions !== null &&
|
|
308
|
+
params.textureOptions.resizeMode !== undefined &&
|
|
309
|
+
texture.dimensions !== null
|
|
310
|
+
) {
|
|
311
|
+
const resizeMode = params.textureOptions.resizeMode;
|
|
312
|
+
const { width: tw, height: th } = texture.dimensions;
|
|
313
|
+
if (resizeMode.type === 'cover') {
|
|
314
|
+
const scaleX = params.width / tw;
|
|
315
|
+
const scaleY = params.height / th;
|
|
316
|
+
const scale = Math.max(scaleX, scaleY);
|
|
317
|
+
const precision = 1 / scale;
|
|
318
|
+
// Determine based on width
|
|
319
|
+
if (scale && scaleX && scaleX < scale) {
|
|
320
|
+
const desiredSize = precision * params.width;
|
|
321
|
+
texCoordX1 = (1 - desiredSize / tw) * (resizeMode.clipX ?? 0.5);
|
|
322
|
+
texCoordX2 = texCoordX1 + desiredSize / tw;
|
|
323
|
+
}
|
|
324
|
+
// Determine based on height
|
|
325
|
+
if (scale && scaleY && scaleY < scale) {
|
|
326
|
+
const desiredSize = precision * params.height;
|
|
327
|
+
texCoordY1 = (1 - desiredSize / th) * (resizeMode.clipY ?? 0.5);
|
|
328
|
+
texCoordY2 = texCoordY1 + desiredSize / th;
|
|
349
329
|
}
|
|
350
330
|
}
|
|
351
331
|
}
|
|
352
332
|
|
|
353
333
|
// Flip texture coordinates if dictated by texture options
|
|
354
|
-
|
|
355
|
-
|
|
334
|
+
let flipY = 0;
|
|
335
|
+
if (params.textureOptions !== null) {
|
|
336
|
+
if (params.textureOptions.flipX === true) {
|
|
337
|
+
[texCoordX1, texCoordX2] = [texCoordX2, texCoordX1];
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// convert to integer for bitwise operation below
|
|
341
|
+
flipY = +(params.textureOptions.flipY || false);
|
|
356
342
|
}
|
|
357
|
-
|
|
343
|
+
|
|
344
|
+
// Eitherone should be true
|
|
345
|
+
if (flipY ^ +(texture.type === TextureType.renderToTexture)) {
|
|
358
346
|
[texCoordY1, texCoordY2] = [texCoordY2, texCoordY1];
|
|
359
347
|
}
|
|
360
348
|
|
|
361
|
-
const ctxTexture = texture.ctxTexture;
|
|
362
|
-
assertTruthy(ctxTexture
|
|
349
|
+
const ctxTexture = texture.ctxTexture as WebGlCoreCtxTexture;
|
|
350
|
+
assertTruthy(ctxTexture.ctxTexture !== undefined);
|
|
363
351
|
const textureIdx = this.addTexture(ctxTexture, bufferIdx);
|
|
364
352
|
|
|
365
|
-
curRenderOp
|
|
366
|
-
|
|
367
|
-
if (renderCoords) {
|
|
368
|
-
const { x1, y1, x2, y2, x3, y3, x4, y4 } = renderCoords;
|
|
353
|
+
assertTruthy(this.curRenderOp !== null);
|
|
354
|
+
if (params.renderCoords) {
|
|
369
355
|
// Upper-Left
|
|
370
|
-
fQuadBuffer[bufferIdx++] = x1; // vertexX
|
|
371
|
-
fQuadBuffer[bufferIdx++] = y1; // vertexY
|
|
356
|
+
fQuadBuffer[bufferIdx++] = params.renderCoords.x1; // vertexX
|
|
357
|
+
fQuadBuffer[bufferIdx++] = params.renderCoords.y1; // vertexY
|
|
372
358
|
fQuadBuffer[bufferIdx++] = texCoordX1; // texCoordX
|
|
373
359
|
fQuadBuffer[bufferIdx++] = texCoordY1; // texCoordY
|
|
374
|
-
uiQuadBuffer[bufferIdx++] = colorTl; // color
|
|
360
|
+
uiQuadBuffer[bufferIdx++] = params.colorTl; // color
|
|
375
361
|
fQuadBuffer[bufferIdx++] = textureIdx; // texIndex
|
|
376
362
|
|
|
377
363
|
// Upper-Right
|
|
378
|
-
fQuadBuffer[bufferIdx++] = x2;
|
|
379
|
-
fQuadBuffer[bufferIdx++] = y2;
|
|
364
|
+
fQuadBuffer[bufferIdx++] = params.renderCoords.x2;
|
|
365
|
+
fQuadBuffer[bufferIdx++] = params.renderCoords.y2;
|
|
380
366
|
fQuadBuffer[bufferIdx++] = texCoordX2;
|
|
381
367
|
fQuadBuffer[bufferIdx++] = texCoordY1;
|
|
382
|
-
uiQuadBuffer[bufferIdx++] = colorTr;
|
|
368
|
+
uiQuadBuffer[bufferIdx++] = params.colorTr;
|
|
383
369
|
fQuadBuffer[bufferIdx++] = textureIdx;
|
|
384
370
|
|
|
385
371
|
// Lower-Left
|
|
386
|
-
fQuadBuffer[bufferIdx++] = x4;
|
|
387
|
-
fQuadBuffer[bufferIdx++] = y4;
|
|
372
|
+
fQuadBuffer[bufferIdx++] = params.renderCoords.x4;
|
|
373
|
+
fQuadBuffer[bufferIdx++] = params.renderCoords.y4;
|
|
388
374
|
fQuadBuffer[bufferIdx++] = texCoordX1;
|
|
389
375
|
fQuadBuffer[bufferIdx++] = texCoordY2;
|
|
390
|
-
uiQuadBuffer[bufferIdx++] = colorBl;
|
|
376
|
+
uiQuadBuffer[bufferIdx++] = params.colorBl;
|
|
391
377
|
fQuadBuffer[bufferIdx++] = textureIdx;
|
|
392
378
|
|
|
393
379
|
// Lower-Right
|
|
394
|
-
fQuadBuffer[bufferIdx++] = x3;
|
|
395
|
-
fQuadBuffer[bufferIdx++] = y3;
|
|
380
|
+
fQuadBuffer[bufferIdx++] = params.renderCoords.x3;
|
|
381
|
+
fQuadBuffer[bufferIdx++] = params.renderCoords.y3;
|
|
396
382
|
fQuadBuffer[bufferIdx++] = texCoordX2;
|
|
397
383
|
fQuadBuffer[bufferIdx++] = texCoordY2;
|
|
398
|
-
uiQuadBuffer[bufferIdx++] = colorBr;
|
|
384
|
+
uiQuadBuffer[bufferIdx++] = params.colorBr;
|
|
399
385
|
fQuadBuffer[bufferIdx++] = textureIdx;
|
|
400
|
-
} else if (tb !== 0 || tc !== 0) {
|
|
386
|
+
} else if (params.tb !== 0 || params.tc !== 0) {
|
|
401
387
|
// Upper-Left
|
|
402
|
-
fQuadBuffer[bufferIdx++] = tx; // vertexX
|
|
403
|
-
fQuadBuffer[bufferIdx++] = ty; // vertexY
|
|
388
|
+
fQuadBuffer[bufferIdx++] = params.tx; // vertexX
|
|
389
|
+
fQuadBuffer[bufferIdx++] = params.ty; // vertexY
|
|
404
390
|
fQuadBuffer[bufferIdx++] = texCoordX1; // texCoordX
|
|
405
391
|
fQuadBuffer[bufferIdx++] = texCoordY1; // texCoordY
|
|
406
|
-
uiQuadBuffer[bufferIdx++] = colorTl; // color
|
|
392
|
+
uiQuadBuffer[bufferIdx++] = params.colorTl; // color
|
|
407
393
|
fQuadBuffer[bufferIdx++] = textureIdx; // texIndex
|
|
408
394
|
|
|
409
395
|
// Upper-Right
|
|
410
|
-
fQuadBuffer[bufferIdx++] = tx + width * ta;
|
|
411
|
-
fQuadBuffer[bufferIdx++] = ty + width * tc;
|
|
396
|
+
fQuadBuffer[bufferIdx++] = params.tx + params.width * params.ta;
|
|
397
|
+
fQuadBuffer[bufferIdx++] = params.ty + params.width * params.tc;
|
|
412
398
|
fQuadBuffer[bufferIdx++] = texCoordX2;
|
|
413
399
|
fQuadBuffer[bufferIdx++] = texCoordY1;
|
|
414
|
-
uiQuadBuffer[bufferIdx++] = colorTr;
|
|
400
|
+
uiQuadBuffer[bufferIdx++] = params.colorTr;
|
|
415
401
|
fQuadBuffer[bufferIdx++] = textureIdx;
|
|
416
402
|
|
|
417
403
|
// Lower-Left
|
|
418
|
-
fQuadBuffer[bufferIdx++] = tx + height * tb;
|
|
419
|
-
fQuadBuffer[bufferIdx++] = ty + height * td;
|
|
404
|
+
fQuadBuffer[bufferIdx++] = params.tx + params.height * params.tb;
|
|
405
|
+
fQuadBuffer[bufferIdx++] = params.ty + params.height * params.td;
|
|
420
406
|
fQuadBuffer[bufferIdx++] = texCoordX1;
|
|
421
407
|
fQuadBuffer[bufferIdx++] = texCoordY2;
|
|
422
|
-
uiQuadBuffer[bufferIdx++] = colorBl;
|
|
408
|
+
uiQuadBuffer[bufferIdx++] = params.colorBl;
|
|
423
409
|
fQuadBuffer[bufferIdx++] = textureIdx;
|
|
424
410
|
|
|
425
411
|
// Lower-Right
|
|
426
|
-
fQuadBuffer[bufferIdx++] =
|
|
427
|
-
|
|
412
|
+
fQuadBuffer[bufferIdx++] =
|
|
413
|
+
params.tx + params.width * params.ta + params.height * params.tb;
|
|
414
|
+
fQuadBuffer[bufferIdx++] =
|
|
415
|
+
params.ty + params.width * params.tc + params.height * params.td;
|
|
428
416
|
fQuadBuffer[bufferIdx++] = texCoordX2;
|
|
429
417
|
fQuadBuffer[bufferIdx++] = texCoordY2;
|
|
430
|
-
uiQuadBuffer[bufferIdx++] = colorBr;
|
|
418
|
+
uiQuadBuffer[bufferIdx++] = params.colorBr;
|
|
431
419
|
fQuadBuffer[bufferIdx++] = textureIdx;
|
|
432
420
|
} else {
|
|
433
421
|
// Calculate the right corner of the quad
|
|
434
422
|
// multiplied by the scale
|
|
435
|
-
const rightCornerX = tx + width * ta;
|
|
436
|
-
const rightCornerY = ty + height * td;
|
|
423
|
+
const rightCornerX = params.tx + params.width * params.ta;
|
|
424
|
+
const rightCornerY = params.ty + params.height * params.td;
|
|
437
425
|
|
|
438
426
|
// Upper-Left
|
|
439
|
-
fQuadBuffer[bufferIdx++] = tx; // vertexX
|
|
440
|
-
fQuadBuffer[bufferIdx++] = ty; // vertexY
|
|
427
|
+
fQuadBuffer[bufferIdx++] = params.tx; // vertexX
|
|
428
|
+
fQuadBuffer[bufferIdx++] = params.ty; // vertexY
|
|
441
429
|
fQuadBuffer[bufferIdx++] = texCoordX1; // texCoordX
|
|
442
430
|
fQuadBuffer[bufferIdx++] = texCoordY1; // texCoordY
|
|
443
|
-
uiQuadBuffer[bufferIdx++] = colorTl; // color
|
|
431
|
+
uiQuadBuffer[bufferIdx++] = params.colorTl; // color
|
|
444
432
|
fQuadBuffer[bufferIdx++] = textureIdx; // texIndex
|
|
445
433
|
|
|
446
434
|
// Upper-Right
|
|
447
435
|
fQuadBuffer[bufferIdx++] = rightCornerX;
|
|
448
|
-
fQuadBuffer[bufferIdx++] = ty;
|
|
436
|
+
fQuadBuffer[bufferIdx++] = params.ty;
|
|
449
437
|
fQuadBuffer[bufferIdx++] = texCoordX2;
|
|
450
438
|
fQuadBuffer[bufferIdx++] = texCoordY1;
|
|
451
|
-
uiQuadBuffer[bufferIdx++] = colorTr;
|
|
439
|
+
uiQuadBuffer[bufferIdx++] = params.colorTr;
|
|
452
440
|
fQuadBuffer[bufferIdx++] = textureIdx;
|
|
453
441
|
|
|
454
442
|
// Lower-Left
|
|
455
|
-
fQuadBuffer[bufferIdx++] = tx;
|
|
443
|
+
fQuadBuffer[bufferIdx++] = params.tx;
|
|
456
444
|
fQuadBuffer[bufferIdx++] = rightCornerY;
|
|
457
445
|
fQuadBuffer[bufferIdx++] = texCoordX1;
|
|
458
446
|
fQuadBuffer[bufferIdx++] = texCoordY2;
|
|
459
|
-
uiQuadBuffer[bufferIdx++] = colorBl;
|
|
447
|
+
uiQuadBuffer[bufferIdx++] = params.colorBl;
|
|
460
448
|
fQuadBuffer[bufferIdx++] = textureIdx;
|
|
461
449
|
|
|
462
450
|
// Lower-Right
|
|
@@ -464,12 +452,12 @@ export class WebGlCoreRenderer extends CoreRenderer {
|
|
|
464
452
|
fQuadBuffer[bufferIdx++] = rightCornerY;
|
|
465
453
|
fQuadBuffer[bufferIdx++] = texCoordX2;
|
|
466
454
|
fQuadBuffer[bufferIdx++] = texCoordY2;
|
|
467
|
-
uiQuadBuffer[bufferIdx++] = colorBr;
|
|
455
|
+
uiQuadBuffer[bufferIdx++] = params.colorBr;
|
|
468
456
|
fQuadBuffer[bufferIdx++] = textureIdx;
|
|
469
457
|
}
|
|
470
458
|
// Update the length of the current render op
|
|
471
|
-
curRenderOp.length += WORDS_PER_QUAD;
|
|
472
|
-
curRenderOp.numQuads++;
|
|
459
|
+
this.curRenderOp.length += WORDS_PER_QUAD;
|
|
460
|
+
this.curRenderOp.numQuads++;
|
|
473
461
|
this.curBufferIdx = bufferIdx;
|
|
474
462
|
}
|
|
475
463
|
|
|
@@ -536,14 +524,12 @@ export class WebGlCoreRenderer extends CoreRenderer {
|
|
|
536
524
|
throw new Error('Unable to add texture to render op');
|
|
537
525
|
}
|
|
538
526
|
|
|
539
|
-
const { shader, shaderProps, dimensions, clippingRect, alpha } =
|
|
540
|
-
curRenderOp;
|
|
541
527
|
this.newRenderOp(
|
|
542
|
-
shader,
|
|
543
|
-
shaderProps,
|
|
544
|
-
alpha,
|
|
545
|
-
dimensions,
|
|
546
|
-
clippingRect,
|
|
528
|
+
curRenderOp.shader,
|
|
529
|
+
curRenderOp.shaderProps,
|
|
530
|
+
curRenderOp.alpha,
|
|
531
|
+
curRenderOp.dimensions,
|
|
532
|
+
curRenderOp.clippingRect,
|
|
547
533
|
bufferIdx,
|
|
548
534
|
);
|
|
549
535
|
return this.addTexture(texture, bufferIdx, true);
|
|
@@ -556,7 +542,7 @@ export class WebGlCoreRenderer extends CoreRenderer {
|
|
|
556
542
|
* @param params
|
|
557
543
|
* @returns
|
|
558
544
|
*/
|
|
559
|
-
reuseRenderOp(params: QuadOptions) {
|
|
545
|
+
reuseRenderOp(params: QuadOptions): boolean {
|
|
560
546
|
const { shader, shaderProps, parentHasRenderTexture, rtt, clippingRect } =
|
|
561
547
|
params;
|
|
562
548
|
|
|
@@ -20,8 +20,6 @@
|
|
|
20
20
|
import type { TrFontFace } from './font-face-types/TrFontFace.js';
|
|
21
21
|
import type { TextRendererMap, TrFontProps } from './renderers/TextRenderer.js';
|
|
22
22
|
|
|
23
|
-
const fontCache = new Map<string, TrFontFace>();
|
|
24
|
-
|
|
25
23
|
const weightConversions: { [key: string]: number } = {
|
|
26
24
|
normal: 400,
|
|
27
25
|
bold: 700,
|
|
@@ -129,6 +127,8 @@ export interface FontFamilyMap {
|
|
|
129
127
|
}
|
|
130
128
|
|
|
131
129
|
export class TrFontManager {
|
|
130
|
+
private fontCache = new Map<string, TrFontFace>();
|
|
131
|
+
|
|
132
132
|
constructor(private textRenderers: Partial<TextRendererMap>) {
|
|
133
133
|
// Intentionally left blank
|
|
134
134
|
}
|
|
@@ -154,15 +154,15 @@ export class TrFontManager {
|
|
|
154
154
|
* @param props
|
|
155
155
|
* @returns
|
|
156
156
|
*/
|
|
157
|
-
public
|
|
157
|
+
public resolveFontFace(
|
|
158
158
|
familyMapsByPriority: FontFamilyMap[],
|
|
159
159
|
props: TrFontProps,
|
|
160
160
|
): TrFontFace | undefined {
|
|
161
161
|
const { fontFamily, fontWeight, fontStyle, fontStretch } = props;
|
|
162
162
|
const fontCacheString = `${fontFamily}${fontStyle}${fontWeight}${fontStretch}`;
|
|
163
163
|
|
|
164
|
-
if (fontCache.has(fontCacheString) === true) {
|
|
165
|
-
return fontCache.get(fontCacheString);
|
|
164
|
+
if (this.fontCache.has(fontCacheString) === true) {
|
|
165
|
+
return this.fontCache.get(fontCacheString);
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
const resolvedFont = resolveFontToUse(
|
|
@@ -173,7 +173,7 @@ export class TrFontManager {
|
|
|
173
173
|
fontStretch,
|
|
174
174
|
);
|
|
175
175
|
if (resolvedFont !== undefined) {
|
|
176
|
-
fontCache.set(fontCacheString, resolvedFont);
|
|
176
|
+
this.fontCache.set(fontCacheString, resolvedFont);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
return resolvedFont;
|
|
@@ -384,7 +384,7 @@ export class CanvasTextRenderer extends TextRenderer<CanvasTextRendererState> {
|
|
|
384
384
|
|
|
385
385
|
loadFont = (state: CanvasTextRendererState): void => {
|
|
386
386
|
const cssString = getFontCssString(state.props);
|
|
387
|
-
const trFontFace =
|
|
387
|
+
const trFontFace = this.stage.fontManager.resolveFontFace(
|
|
388
388
|
this.fontFamilyArray,
|
|
389
389
|
state.props,
|
|
390
390
|
) as WebTrFontFace | undefined;
|
|
@@ -396,10 +396,10 @@ export class SdfTextRenderer extends TextRenderer<SdfTextRendererState> {
|
|
|
396
396
|
}
|
|
397
397
|
|
|
398
398
|
// Resolve font face if we haven't yet
|
|
399
|
-
if (
|
|
399
|
+
if (trFontFace === undefined) {
|
|
400
400
|
trFontFace = this.resolveFontFace(state.props);
|
|
401
401
|
state.trFontFace = trFontFace;
|
|
402
|
-
if (
|
|
402
|
+
if (trFontFace === undefined) {
|
|
403
403
|
const msg = `SdfTextRenderer: Could not resolve font face for family: '${state.props.fontFamily}'`;
|
|
404
404
|
console.error(msg);
|
|
405
405
|
this.setStatus(state, 'failed', new Error(msg));
|
|
@@ -410,7 +410,7 @@ export class SdfTextRenderer extends TextRenderer<SdfTextRendererState> {
|
|
|
410
410
|
|
|
411
411
|
// If the font hasn't been loaded yet, stop here.
|
|
412
412
|
// Listen for the 'loaded' event and forward fontLoaded event
|
|
413
|
-
if (
|
|
413
|
+
if (trFontFace.loaded === false) {
|
|
414
414
|
trFontFace.once('loaded', () => {
|
|
415
415
|
this.scheduleUpdateState(state);
|
|
416
416
|
});
|
|
@@ -791,7 +791,7 @@ export class SdfTextRenderer extends TextRenderer<SdfTextRendererState> {
|
|
|
791
791
|
//#endregion Overrides
|
|
792
792
|
|
|
793
793
|
public resolveFontFace(props: TrFontProps): SdfTrFontFace | undefined {
|
|
794
|
-
return
|
|
794
|
+
return this.stage.fontManager.resolveFontFace(this.fontFamilyArray, props) as
|
|
795
795
|
| SdfTrFontFace
|
|
796
796
|
| undefined;
|
|
797
797
|
}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import type { CoreTextureManager } from '../CoreTextureManager.js';
|
|
21
|
-
import { Texture, type TextureData } from './Texture.js';
|
|
21
|
+
import { Texture, TextureType, type TextureData } from './Texture.js';
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Properties of the {@link ColorTexture}
|
|
@@ -45,6 +45,8 @@ export interface ColorTextureProps {
|
|
|
45
45
|
* a Node are.
|
|
46
46
|
*/
|
|
47
47
|
export class ColorTexture extends Texture {
|
|
48
|
+
public override type: TextureType = TextureType.color;
|
|
49
|
+
|
|
48
50
|
props: Required<ColorTextureProps>;
|
|
49
51
|
|
|
50
52
|
constructor(txManager: CoreTextureManager, props?: ColorTextureProps) {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import type { CoreTextureManager } from '../CoreTextureManager.js';
|
|
21
|
-
import { Texture, type TextureData } from './Texture.js';
|
|
21
|
+
import { Texture, TextureType, type TextureData } from './Texture.js';
|
|
22
22
|
import {
|
|
23
23
|
isCompressedTextureContainer,
|
|
24
24
|
loadCompressedTexture,
|
|
@@ -121,6 +121,8 @@ export interface ImageTextureProps {
|
|
|
121
121
|
export class ImageTexture extends Texture {
|
|
122
122
|
props: Required<ImageTextureProps>;
|
|
123
123
|
|
|
124
|
+
public override type: TextureType = TextureType.image;
|
|
125
|
+
|
|
124
126
|
constructor(txManager: CoreTextureManager, props: ImageTextureProps) {
|
|
125
127
|
super(txManager);
|
|
126
128
|
this.props = ImageTexture.resolveDefaults(props);
|
|
@@ -168,8 +170,8 @@ export class ImageTexture extends Texture {
|
|
|
168
170
|
premultiplyAlpha: hasAlphaChannel,
|
|
169
171
|
};
|
|
170
172
|
} else {
|
|
171
|
-
const img = new Image(
|
|
172
|
-
if (!
|
|
173
|
+
const img = new Image();
|
|
174
|
+
if (!src.startsWith('data:')) {
|
|
173
175
|
img.crossOrigin = 'Anonymous';
|
|
174
176
|
}
|
|
175
177
|
img.src = src;
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import type { CoreTextureManager } from '../CoreTextureManager.js';
|
|
21
|
-
import { Texture, type TextureData } from './Texture.js';
|
|
21
|
+
import { Texture, TextureType, type TextureData } from './Texture.js';
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Properties of the {@link NoiseTexture}
|
|
@@ -56,6 +56,8 @@ export interface NoiseTextureProps {
|
|
|
56
56
|
export class NoiseTexture extends Texture {
|
|
57
57
|
props: Required<NoiseTextureProps>;
|
|
58
58
|
|
|
59
|
+
public override type: TextureType = TextureType.noise;
|
|
60
|
+
|
|
59
61
|
constructor(txManager: CoreTextureManager, props: NoiseTextureProps) {
|
|
60
62
|
super(txManager);
|
|
61
63
|
this.props = NoiseTexture.resolveDefaults(props);
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import type { CoreTextureManager } from '../CoreTextureManager.js';
|
|
21
|
-
import { Texture, type TextureData } from './Texture.js';
|
|
21
|
+
import { Texture, TextureType, type TextureData } from './Texture.js';
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Properties of the {@link RenderTexture}
|
|
@@ -40,6 +40,8 @@ export interface RenderTextureProps {
|
|
|
40
40
|
export class RenderTexture extends Texture {
|
|
41
41
|
props: Required<RenderTextureProps>;
|
|
42
42
|
|
|
43
|
+
public override type: TextureType = TextureType.renderToTexture;
|
|
44
|
+
|
|
43
45
|
constructor(txManager: CoreTextureManager, props?: RenderTextureProps) {
|
|
44
46
|
super(txManager);
|
|
45
47
|
this.props = RenderTexture.resolveDefaults(props || {});
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
import type { CoreTextureManager } from '../CoreTextureManager.js';
|
|
21
21
|
import {
|
|
22
22
|
Texture,
|
|
23
|
+
TextureType,
|
|
23
24
|
type TextureData,
|
|
24
25
|
type TextureFailedEventHandler,
|
|
25
26
|
type TextureLoadedEventHandler,
|
|
@@ -77,6 +78,8 @@ export class SubTexture extends Texture {
|
|
|
77
78
|
props: Required<SubTextureProps>;
|
|
78
79
|
parentTexture: Texture;
|
|
79
80
|
|
|
81
|
+
public override type: TextureType = TextureType.subTexture;
|
|
82
|
+
|
|
80
83
|
constructor(txManager: CoreTextureManager, props: SubTextureProps) {
|
|
81
84
|
super(txManager);
|
|
82
85
|
this.props = SubTexture.resolveDefaults(props || {});
|
|
@@ -102,6 +102,15 @@ export interface TextureData {
|
|
|
102
102
|
|
|
103
103
|
export type TextureState = 'freed' | 'loading' | 'loaded' | 'failed';
|
|
104
104
|
|
|
105
|
+
export enum TextureType {
|
|
106
|
+
'generic' = 0,
|
|
107
|
+
'color' = 1,
|
|
108
|
+
'image' = 2,
|
|
109
|
+
'noise' = 3,
|
|
110
|
+
'renderToTexture' = 4,
|
|
111
|
+
'subTexture' = 5,
|
|
112
|
+
}
|
|
113
|
+
|
|
105
114
|
export interface TextureStateEventMap {
|
|
106
115
|
freed: TextureFreedEventHandler;
|
|
107
116
|
loading: TextureLoadingEventHandler;
|
|
@@ -150,6 +159,8 @@ export abstract class Texture extends EventEmitter {
|
|
|
150
159
|
|
|
151
160
|
readonly lastRenderableChangeTime = 0;
|
|
152
161
|
|
|
162
|
+
public type: TextureType = TextureType.generic;
|
|
163
|
+
|
|
153
164
|
public preventCleanup = false;
|
|
154
165
|
|
|
155
166
|
constructor(protected txManager: CoreTextureManager) {
|
package/src/main-api/Renderer.ts
CHANGED
package/src/utils.ts
CHANGED
|
@@ -80,7 +80,7 @@ export function assertTruthy(
|
|
|
80
80
|
condition: unknown,
|
|
81
81
|
message?: string,
|
|
82
82
|
): asserts condition {
|
|
83
|
-
if (isProductionEnvironment()) return;
|
|
83
|
+
if (isProductionEnvironment() === true) return;
|
|
84
84
|
if (!condition) {
|
|
85
85
|
throw new Error(message || 'Assertion failed');
|
|
86
86
|
}
|