@lightningtv/renderer 3.2.3 → 3.2.5

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.
Files changed (36) hide show
  1. package/dist/src/core/CoreNode.d.ts +9 -1
  2. package/dist/src/core/CoreNode.js +12 -1
  3. package/dist/src/core/CoreNode.js.map +1 -1
  4. package/dist/src/core/CoreTextNode.js +2 -1
  5. package/dist/src/core/CoreTextNode.js.map +1 -1
  6. package/dist/src/core/CoreTextureManager.js +4 -4
  7. package/dist/src/core/CoreTextureManager.js.map +1 -1
  8. package/dist/src/core/animations/CoreAnimation.js +2 -1
  9. package/dist/src/core/animations/CoreAnimation.js.map +1 -1
  10. package/dist/src/core/lib/WebGlContextWrapper.d.ts +5 -5
  11. package/dist/src/core/renderers/webgl/BatchRenderOp.d.ts +25 -0
  12. package/dist/src/core/renderers/webgl/BatchRenderOp.js +60 -0
  13. package/dist/src/core/renderers/webgl/BatchRenderOp.js.map +1 -0
  14. package/dist/src/core/shaders/webgl/Border.js +0 -1
  15. package/dist/src/core/shaders/webgl/Border.js.map +1 -1
  16. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js +1 -0
  17. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js.map +1 -1
  18. package/dist/src/core/text-rendering/SdfFontHandler.js +5 -5
  19. package/dist/src/core/text-rendering/SdfFontHandler.js.map +1 -1
  20. package/dist/src/core/text-rendering/SdfTextRenderer.js +11 -9
  21. package/dist/src/core/text-rendering/SdfTextRenderer.js.map +1 -1
  22. package/dist/tsconfig.dist.tsbuildinfo +1 -1
  23. package/dist/tsconfig.tsbuildinfo +1 -1
  24. package/package.json +3 -1
  25. package/src/core/CoreNode.test.ts +1 -0
  26. package/src/core/CoreNode.ts +22 -1
  27. package/src/core/CoreTextNode.ts +2 -1
  28. package/src/core/CoreTextureManager.ts +16 -4
  29. package/src/core/animations/CoreAnimation.ts +6 -1
  30. package/src/core/shaders/webgl/Border.ts +0 -1
  31. package/src/core/shaders/webgl/RoundedWithBorderAndShadow.ts +1 -0
  32. package/src/core/text-rendering/SdfFontHandler.ts +5 -5
  33. package/src/core/text-rendering/SdfTextRenderer.ts +12 -9
  34. package/dist/src/core/shaders/webgl/DefaultBatched.d.ts +0 -2
  35. package/dist/src/core/shaders/webgl/DefaultBatched.js +0 -104
  36. package/dist/src/core/shaders/webgl/DefaultBatched.js.map +0 -1
@@ -95,6 +95,7 @@ export class CoreTextNode extends CoreNode implements CoreTextNodeProps {
95
95
  dimensions,
96
96
  } satisfies NodeTextureLoadedPayload);
97
97
  }
98
+ this.textureLoaded = true;
98
99
  this.setUpdateType(UpdateType.IsRenderable);
99
100
  };
100
101
 
@@ -208,7 +209,7 @@ export class CoreTextNode extends CoreNode implements CoreTextNodeProps {
208
209
  * Override is renderable check for SDF text nodes
209
210
  */
210
211
  override updateIsRenderable(): void {
211
- // SDF text nodes are always renderable if they have a valid layout
212
+ // Canvas text relies on CoreNode's standard textureLoaded logic.
212
213
  if (this._type === 'canvas') {
213
214
  super.updateIsRenderable();
214
215
  return;
@@ -311,7 +311,10 @@ export class CoreTextureManager extends EventEmitter {
311
311
  let texture: Texture | undefined;
312
312
  const TextureClass = this.txConstructors[textureType];
313
313
  if (!TextureClass) {
314
- throw new Error(`Texture type "${textureType}" is not registered`);
314
+ throw new TextureError(
315
+ TextureErrorCode.TEXTURE_TYPE_NOT_REGISTERED,
316
+ `Texture type "${textureType}" is not registered`,
317
+ );
315
318
  }
316
319
  const resolvedProps = TextureClass.resolveDefaults(props as any);
317
320
  const cacheKey = TextureClass.makeCacheKey(resolvedProps as any);
@@ -360,7 +363,10 @@ export class CoreTextureManager extends EventEmitter {
360
363
  // Get texture data - early return on failure
361
364
  const textureDataResult = await texture.getTextureData().catch((err) => {
362
365
  console.error(err);
363
- texture.setState('failed');
366
+ texture.setState(
367
+ 'failed',
368
+ new TextureError(TextureErrorCode.TEXTURE_DATA_NULL),
369
+ );
364
370
  return null;
365
371
  });
366
372
 
@@ -375,7 +381,10 @@ export class CoreTextureManager extends EventEmitter {
375
381
  if (shouldUploadImmediately === true) {
376
382
  await this.uploadTexture(texture).catch((err) => {
377
383
  console.error(`Failed to upload texture:`, err);
378
- texture.setState('failed');
384
+ texture.setState(
385
+ 'failed',
386
+ new TextureError(TextureErrorCode.TEXTURE_DATA_NULL),
387
+ );
379
388
  });
380
389
  return;
381
390
  }
@@ -396,7 +405,10 @@ export class CoreTextureManager extends EventEmitter {
396
405
  this.stage.txMemManager.criticalCleanupRequested === true
397
406
  ) {
398
407
  // we're at a critical memory threshold, don't upload textures
399
- texture.setState('failed');
408
+ texture.setState(
409
+ 'failed',
410
+ new TextureError(TextureErrorCode.MEMORY_THRESHOLD_EXCEEDED),
411
+ );
400
412
  return;
401
413
  }
402
414
 
@@ -1,4 +1,8 @@
1
- import { type CoreNode, type CoreNodeAnimateProps } from '../CoreNode.js';
1
+ import {
2
+ type CoreNode,
3
+ type CoreNodeAnimateProps,
4
+ UpdateType,
5
+ } from '../CoreNode.js';
2
6
  import { getTimingFunction, type TimingFunction } from '../utils.js';
3
7
  import { mergeColorProgress } from '../../utils.js';
4
8
  import { EventEmitter } from '../../common/EventEmitter.js';
@@ -258,6 +262,7 @@ export class CoreAnimation extends EventEmitter {
258
262
  this.propValuesMap['shaderProps'],
259
263
  easing,
260
264
  );
265
+ this.node.setUpdateType(UpdateType.RecalcUniforms);
261
266
  }
262
267
 
263
268
  if (this.progress === 1) {
@@ -29,7 +29,6 @@ export const Border: WebGlShaderType<BorderProps> = {
29
29
  uniform float u_pixelRatio;
30
30
  uniform vec2 u_dimensions;
31
31
 
32
- uniform vec4 u_radius;
33
32
  uniform vec4 u_borderWidth;
34
33
  uniform float u_borderGap;
35
34
  uniform float u_borderAlign;
@@ -154,6 +154,7 @@ export const RoundedWithBorderAndShadow: WebGlShaderType<RoundedWithBorderAndSha
154
154
  uniform vec4 u_borderColor;
155
155
  uniform vec4 u_shadowColor;
156
156
  uniform vec4 u_shadow;
157
+ uniform float u_borderGap;
157
158
 
158
159
  varying vec4 v_color;
159
160
  varying vec2 v_textureCoords;
@@ -520,7 +520,7 @@ export const measureText = (
520
520
  }
521
521
 
522
522
  let width = 0;
523
- let prevCodepoint = 0;
523
+ let prevGlyphId = 0;
524
524
  for (let i = 0; i < textLength; i++) {
525
525
  const codepoint = text.codePointAt(i) as number;
526
526
  if (codepoint > 0xffff) {
@@ -548,10 +548,10 @@ export const measureText = (
548
548
  let advance = glyph.xadvance;
549
549
 
550
550
  // Add kerning if there's a previous character
551
- if (prevCodepoint !== 0) {
552
- const seconds = kernings[codepoint];
551
+ if (prevGlyphId !== 0) {
552
+ const seconds = kernings[glyph.id];
553
553
  if (seconds !== undefined) {
554
- const amount = seconds[prevCodepoint];
554
+ const amount = seconds[prevGlyphId];
555
555
  if (amount !== undefined) {
556
556
  advance += amount;
557
557
  }
@@ -559,7 +559,7 @@ export const measureText = (
559
559
  }
560
560
 
561
561
  width += advance + letterSpacing;
562
- prevCodepoint = codepoint;
562
+ prevGlyphId = glyph.id;
563
563
  }
564
564
 
565
565
  return width;
@@ -311,7 +311,7 @@ const generateTextLayout = (
311
311
  const line = lines[i] as TextLineStruct;
312
312
  const textLine = line[0];
313
313
  const textLineLength = textLine.length;
314
- let prevCodepoint = 0;
314
+ let prevGlyphId = 0;
315
315
  currentX = line[3];
316
316
  //convert Y coord to vertex value
317
317
  currentY = line[4] / fontScale;
@@ -340,20 +340,23 @@ const generateTextLayout = (
340
340
  }
341
341
  }
342
342
 
343
- // Calculate advance with kerning (in design units)
344
- let advance = glyph.xadvance;
343
+ // Kerning offsets the current glyph relative to the previous glyph.
344
+ let kerning = 0;
345
345
 
346
346
  // Add kerning if there's a previous character
347
- if (prevCodepoint !== 0) {
348
- const seconds = kernings[codepoint];
347
+ if (prevGlyphId !== 0) {
348
+ const seconds = kernings[glyph.id];
349
349
  if (seconds !== undefined) {
350
- const amount = seconds[prevCodepoint];
350
+ const amount = seconds[prevGlyphId];
351
351
  if (amount !== undefined) {
352
- advance += amount;
352
+ kerning = amount;
353
353
  }
354
354
  }
355
355
  }
356
356
 
357
+ // Apply pair kerning before placing this glyph.
358
+ currentX += kerning;
359
+
357
360
  // Calculate glyph position and atlas coordinates (in design units)
358
361
  const glyphLayout: GlyphLayout = {
359
362
  codepoint,
@@ -373,8 +376,8 @@ const generateTextLayout = (
373
376
  glyphs.push(glyphLayout);
374
377
 
375
378
  // Advance position with letter spacing (in design units)
376
- currentX += advance + letterSpacing;
377
- prevCodepoint = codepoint;
379
+ currentX += glyph.xadvance + letterSpacing;
380
+ prevGlyphId = glyph.id;
378
381
  }
379
382
  currentY += lineHeightPx;
380
383
  }
@@ -1,2 +0,0 @@
1
- import type { WebGlShaderType } from '../../renderers/webgl/WebGlShaderNode.js';
2
- export declare const DefaultBatched: WebGlShaderType;
@@ -1,104 +0,0 @@
1
- /*
2
- * Copyright 2023 Comcast Cable Communications Management, LLC
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- *
15
- * SPDX-License-Identifier: Apache-2.0
16
- */
17
- export const DefaultBatched = {
18
- supportsIndexedTextures: true,
19
- // override bindTextures(texture: WebGlCoreCtxTexture[]) {
20
- // const { renderer, glw } = this;
21
- // if (
22
- // texture.length > renderer.system.parameters.MAX_VERTEX_TEXTURE_IMAGE_UNITS
23
- // ) {
24
- // throw new Error(
25
- // `DefaultShaderBatched: Cannot bind more than ${renderer.system.parameters.MAX_VERTEX_TEXTURE_IMAGE_UNITS} textures`,
26
- // );
27
- // }
28
- // texture.forEach((t, i) => {
29
- // glw.activeTexture(i);
30
- // glw.bindTexture(t.ctxTexture);
31
- // });
32
- // const samplers = Array.from(Array(texture.length).keys());
33
- // this.glw.uniform1iv('u_textures[0]', samplers);
34
- // }
35
- vertex: `
36
- # ifdef GL_FRAGMENT_PRECISION_HIGH
37
- precision highp float;
38
- # else
39
- precision mediump float;
40
- # endif
41
-
42
- attribute vec2 a_textureCoords;
43
- attribute vec2 a_position;
44
- attribute vec4 a_color;
45
- attribute float a_textureIndex;
46
- attribute float a_depth;
47
-
48
- uniform vec2 u_resolution;
49
- uniform float u_pixelRatio;
50
-
51
- varying vec4 v_color;
52
- varying vec2 v_textureCoords;
53
- varying float v_textureIndex;
54
-
55
- void main(){
56
- vec2 normalized = a_position * u_pixelRatio / u_resolution;
57
- vec2 zero_two = normalized * 2.0;
58
- vec2 clip_space = zero_two - 1.0;
59
-
60
- // pass to fragment
61
- v_color = a_color;
62
- v_textureCoords = a_textureCoords;
63
- v_textureIndex = a_textureIndex;
64
-
65
- // flip y
66
- gl_Position = vec4(clip_space * vec2(1.0, -1.0), 0, 1);
67
- }
68
- `,
69
- fragment(renderer) {
70
- const textureUnits = renderer.system.parameters.MAX_VERTEX_TEXTURE_IMAGE_UNITS;
71
- return `
72
- #define txUnits ${textureUnits}
73
- # ifdef GL_FRAGMENT_PRECISION_HIGH
74
- precision highp float;
75
- # else
76
- precision mediump float;
77
- # endif
78
-
79
- uniform vec2 u_resolution;
80
- uniform sampler2D u_image;
81
- uniform sampler2D u_textures[txUnits];
82
-
83
- varying vec4 v_color;
84
- varying vec2 v_textureCoords;
85
- varying float v_textureIndex;
86
-
87
- vec4 sampleFromTexture(sampler2D textures[${textureUnits}], int idx, vec2 uv) {
88
- ${Array.from(Array(textureUnits).keys())
89
- .map((idx) => `
90
- ${idx !== 0 ? 'else ' : ''}if (idx == ${idx}) {
91
- return texture2D(textures[${idx}], uv);
92
- }
93
- `)
94
- .join('')}
95
- return texture2D(textures[0], uv);
96
- }
97
-
98
- void main(){
99
- gl_FragColor = vec4(v_color) * sampleFromTexture(u_textures, int(v_textureIndex), v_textureCoords);
100
- }
101
- `;
102
- },
103
- };
104
- //# sourceMappingURL=DefaultBatched.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DefaultBatched.js","sourceRoot":"","sources":["../../../../../src/core/shaders/webgl/DefaultBatched.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAsBH,MAAM,CAAC,MAAM,cAAc,GAAoB;IAC7C,uBAAuB,EAAE,IAAI;IAE7B,0DAA0D;IAC1D,oCAAoC;IACpC,SAAS;IACT,iFAAiF;IACjF,QAAQ;IACR,uBAAuB;IACvB,6HAA6H;IAC7H,SAAS;IACT,MAAM;IACN,gCAAgC;IAChC,4BAA4B;IAC5B,qCAAqC;IACrC,QAAQ;IACR,+DAA+D;IAC/D,oDAAoD;IACpD,IAAI;IAEJ,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCP;IACD,QAAQ,CAAC,QAAQ;QACf,MAAM,YAAY,GAChB,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,8BAA8B,CAAC;QAC5D,OAAO;sBACW,YAAY;;;;;;;;;;;;;;;kDAegB,YAAY;UACpD,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,IAAI,EAAE,CAAC;aACrC,GAAG,CACF,CAAC,GAAG,EAAE,EAAE,CAAC;YACT,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,cAAc,GAAG;wCACb,GAAG;;SAElC,CACE;aACA,IAAI,CAAC,EAAE,CAAC;;;;;;;KAOd,CAAC;IACJ,CAAC;CACF,CAAC"}