@lightningjs/renderer 3.0.0-beta17 → 3.0.0-beta19

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 (151) hide show
  1. package/dist/src/core/Autosizer.d.ts +29 -0
  2. package/dist/src/core/Autosizer.js +178 -0
  3. package/dist/src/core/Autosizer.js.map +1 -0
  4. package/dist/src/core/CoreNode.d.ts +44 -26
  5. package/dist/src/core/CoreNode.js +253 -150
  6. package/dist/src/core/CoreNode.js.map +1 -1
  7. package/dist/src/core/CoreTextNode.d.ts +1 -0
  8. package/dist/src/core/CoreTextNode.js +8 -4
  9. package/dist/src/core/CoreTextNode.js.map +1 -1
  10. package/dist/src/core/CoreTextureManager.d.ts +16 -2
  11. package/dist/src/core/CoreTextureManager.js +38 -51
  12. package/dist/src/core/CoreTextureManager.js.map +1 -1
  13. package/dist/src/core/Stage.d.ts +18 -2
  14. package/dist/src/core/Stage.js +46 -15
  15. package/dist/src/core/Stage.js.map +1 -1
  16. package/dist/src/core/TextureError.d.ts +11 -0
  17. package/dist/src/core/TextureError.js +37 -0
  18. package/dist/src/core/TextureError.js.map +1 -0
  19. package/dist/src/core/TextureMemoryManager.d.ts +2 -4
  20. package/dist/src/core/TextureMemoryManager.js +80 -95
  21. package/dist/src/core/TextureMemoryManager.js.map +1 -1
  22. package/dist/src/core/lib/WebGlContextWrapper.d.ts +11 -0
  23. package/dist/src/core/lib/WebGlContextWrapper.js +34 -0
  24. package/dist/src/core/lib/WebGlContextWrapper.js.map +1 -1
  25. package/dist/src/core/lib/textureCompression.d.ts +14 -2
  26. package/dist/src/core/lib/textureCompression.js +320 -67
  27. package/dist/src/core/lib/textureCompression.js.map +1 -1
  28. package/dist/src/core/platforms/web/WebPlatform.js +2 -2
  29. package/dist/src/core/platforms/web/WebPlatform.js.map +1 -1
  30. package/dist/src/core/renderers/CoreContextTexture.d.ts +1 -0
  31. package/dist/src/core/renderers/CoreContextTexture.js.map +1 -1
  32. package/dist/src/core/renderers/CoreRenderer.d.ts +3 -1
  33. package/dist/src/core/renderers/CoreRenderer.js +1 -0
  34. package/dist/src/core/renderers/CoreRenderer.js.map +1 -1
  35. package/dist/src/core/renderers/CoreShaderNode.d.ts +6 -0
  36. package/dist/src/core/renderers/CoreShaderNode.js +2 -0
  37. package/dist/src/core/renderers/CoreShaderNode.js.map +1 -1
  38. package/dist/src/core/renderers/canvas/CanvasTexture.d.ts +1 -0
  39. package/dist/src/core/renderers/canvas/CanvasTexture.js +4 -1
  40. package/dist/src/core/renderers/canvas/CanvasTexture.js.map +1 -1
  41. package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.d.ts +2 -0
  42. package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js +6 -0
  43. package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js.map +1 -1
  44. package/dist/src/core/renderers/webgl/WebGlCtxTexture.d.ts +11 -0
  45. package/dist/src/core/renderers/webgl/WebGlCtxTexture.js +51 -14
  46. package/dist/src/core/renderers/webgl/WebGlCtxTexture.js.map +1 -1
  47. package/dist/src/core/renderers/webgl/WebGlRenderOp.d.ts +2 -1
  48. package/dist/src/core/renderers/webgl/WebGlRenderOp.js +2 -0
  49. package/dist/src/core/renderers/webgl/WebGlRenderOp.js.map +1 -1
  50. package/dist/src/core/renderers/webgl/WebGlRenderer.d.ts +1 -1
  51. package/dist/src/core/renderers/webgl/WebGlRenderer.js +57 -61
  52. package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +1 -1
  53. package/dist/src/core/renderers/webgl/WebGlShaderProgram.d.ts +1 -0
  54. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js +12 -0
  55. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js.map +1 -1
  56. package/dist/src/core/shaders/canvas/RadialGradient.js +1 -1
  57. package/dist/src/core/shaders/canvas/RadialGradient.js.map +1 -1
  58. package/dist/src/core/shaders/templates/RadialGradientTemplate.d.ts +6 -4
  59. package/dist/src/core/shaders/templates/RadialGradientTemplate.js.map +1 -1
  60. package/dist/src/core/shaders/webgl/LinearGradient.js +2 -1
  61. package/dist/src/core/shaders/webgl/LinearGradient.js.map +1 -1
  62. package/dist/src/core/shaders/webgl/RadialGradient.js +8 -7
  63. package/dist/src/core/shaders/webgl/RadialGradient.js.map +1 -1
  64. package/dist/src/core/shaders/webgl/Rounded.js +3 -1
  65. package/dist/src/core/shaders/webgl/Rounded.js.map +1 -1
  66. package/dist/src/core/shaders/webgl/RoundedWithBorder.js +3 -2
  67. package/dist/src/core/shaders/webgl/RoundedWithBorder.js.map +1 -1
  68. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js +3 -2
  69. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js.map +1 -1
  70. package/dist/src/core/shaders/webgl/RoundedWithShadow.js +2 -1
  71. package/dist/src/core/shaders/webgl/RoundedWithShadow.js.map +1 -1
  72. package/dist/src/core/text-rendering/CanvasTextRenderer.js +1 -1
  73. package/dist/src/core/text-rendering/CanvasTextRenderer.js.map +1 -1
  74. package/dist/src/core/text-rendering/SdfFontHandler.js +1 -1
  75. package/dist/src/core/text-rendering/SdfFontHandler.js.map +1 -1
  76. package/dist/src/core/textures/ColorTexture.d.ts +1 -1
  77. package/dist/src/core/textures/ColorTexture.js +2 -3
  78. package/dist/src/core/textures/ColorTexture.js.map +1 -1
  79. package/dist/src/core/textures/ImageTexture.d.ts +7 -1
  80. package/dist/src/core/textures/ImageTexture.js +20 -36
  81. package/dist/src/core/textures/ImageTexture.js.map +1 -1
  82. package/dist/src/core/textures/NoiseTexture.d.ts +1 -1
  83. package/dist/src/core/textures/NoiseTexture.js +2 -2
  84. package/dist/src/core/textures/NoiseTexture.js.map +1 -1
  85. package/dist/src/core/textures/RenderTexture.d.ts +1 -1
  86. package/dist/src/core/textures/RenderTexture.js +2 -2
  87. package/dist/src/core/textures/RenderTexture.js.map +1 -1
  88. package/dist/src/core/textures/SubTexture.d.ts +2 -4
  89. package/dist/src/core/textures/SubTexture.js +13 -31
  90. package/dist/src/core/textures/SubTexture.js.map +1 -1
  91. package/dist/src/core/textures/Texture.d.ts +67 -8
  92. package/dist/src/core/textures/Texture.js +127 -15
  93. package/dist/src/core/textures/Texture.js.map +1 -1
  94. package/dist/src/core/utils.d.ts +1 -1
  95. package/dist/src/main-api/Renderer.d.ts +15 -2
  96. package/dist/src/main-api/Renderer.js +19 -12
  97. package/dist/src/main-api/Renderer.js.map +1 -1
  98. package/dist/tsconfig.dist.tsbuildinfo +1 -1
  99. package/package.json +1 -1
  100. package/src/core/CoreNode.test.ts +0 -1
  101. package/src/core/CoreNode.ts +296 -177
  102. package/src/core/CoreTextNode.ts +9 -4
  103. package/src/core/CoreTextureManager.ts +69 -57
  104. package/src/core/Stage.ts +54 -18
  105. package/src/core/TextureError.ts +46 -0
  106. package/src/core/TextureMemoryManager.ts +95 -122
  107. package/src/core/lib/WebGlContextWrapper.ts +40 -0
  108. package/src/core/lib/collectionUtils.ts +118 -0
  109. package/src/core/lib/textureCompression.ts +433 -77
  110. package/src/core/platforms/web/WebPlatform.ts +2 -2
  111. package/src/core/renderers/CoreContextTexture.ts +1 -0
  112. package/src/core/renderers/CoreRenderer.ts +3 -2
  113. package/src/core/renderers/CoreShaderNode.ts +7 -0
  114. package/src/core/renderers/canvas/CanvasTexture.ts +5 -1
  115. package/src/core/renderers/webgl/WebGlCtxRenderTexture.ts +8 -0
  116. package/src/core/renderers/webgl/WebGlCtxTexture.ts +58 -15
  117. package/src/core/renderers/webgl/WebGlRenderOp.ts +4 -1
  118. package/src/core/renderers/webgl/WebGlRenderer.ts +66 -68
  119. package/src/core/renderers/webgl/WebGlShaderProgram.ts +16 -0
  120. package/src/core/shaders/canvas/RadialGradient.ts +1 -1
  121. package/src/core/shaders/templates/RadialGradientTemplate.ts +6 -4
  122. package/src/core/shaders/webgl/LinearGradient.ts +2 -1
  123. package/src/core/shaders/webgl/RadialGradient.ts +8 -7
  124. package/src/core/shaders/webgl/Rounded.ts +3 -1
  125. package/src/core/shaders/webgl/RoundedWithBorder.ts +3 -2
  126. package/src/core/shaders/webgl/RoundedWithBorderAndShadow.ts +3 -2
  127. package/src/core/shaders/webgl/RoundedWithShadow.ts +2 -1
  128. package/src/core/text-rendering/CanvasTextRenderer.ts +1 -1
  129. package/src/core/text-rendering/SdfFontHandler.ts +1 -1
  130. package/src/core/textures/ColorTexture.ts +6 -4
  131. package/src/core/textures/ImageTexture.ts +35 -42
  132. package/src/core/textures/NoiseTexture.ts +6 -4
  133. package/src/core/textures/RenderTexture.ts +6 -4
  134. package/src/core/textures/SubTexture.ts +17 -38
  135. package/src/core/textures/Texture.ts +159 -20
  136. package/src/main-api/Renderer.ts +36 -14
  137. package/dist/src/core/animations/Animation.d.ts +0 -16
  138. package/dist/src/core/animations/Animation.js +0 -111
  139. package/dist/src/core/animations/Animation.js.map +0 -1
  140. package/dist/src/core/animations/CoreTransition.d.ts +0 -24
  141. package/dist/src/core/animations/CoreTransition.js +0 -63
  142. package/dist/src/core/animations/CoreTransition.js.map +0 -1
  143. package/dist/src/core/animations/Playback.d.ts +0 -62
  144. package/dist/src/core/animations/Playback.js +0 -155
  145. package/dist/src/core/animations/Playback.js.map +0 -1
  146. package/dist/src/core/animations/Transition.d.ts +0 -25
  147. package/dist/src/core/animations/Transition.js +0 -63
  148. package/dist/src/core/animations/Transition.js.map +0 -1
  149. package/dist/src/core/animations/utils.d.ts +0 -2
  150. package/dist/src/core/animations/utils.js +0 -137
  151. package/dist/src/core/animations/utils.js.map +0 -1
@@ -21,8 +21,10 @@ import type { Dimensions } from '../../../common/CommonTypes.js';
21
21
  import type { TextureMemoryManager } from '../../TextureMemoryManager.js';
22
22
  import type { WebGlContextWrapper } from '../../lib/WebGlContextWrapper.js';
23
23
  import type { Texture } from '../../textures/Texture.js';
24
+ import { uploadCompressedTexture } from '../../lib/textureCompression.js';
24
25
  import { CoreContextTexture } from '../CoreContextTexture.js';
25
26
  import { isHTMLImageElement } from './internal/RendererUtils.js';
27
+ import type { Bound } from '../../lib/utils.js';
26
28
 
27
29
  const TRANSPARENT_TEXTURE_DATA = new Uint8Array([0, 0, 0, 0]);
28
30
 
@@ -42,6 +44,13 @@ export class WebGlCtxTexture extends CoreContextTexture {
42
44
  private _w = 0;
43
45
  private _h = 0;
44
46
 
47
+ txCoords: Bound = {
48
+ x1: 0,
49
+ y1: 0,
50
+ x2: 1,
51
+ y2: 1,
52
+ };
53
+
45
54
  constructor(
46
55
  protected glw: WebGlContextWrapper,
47
56
  memManager: TextureMemoryManager,
@@ -50,6 +59,25 @@ export class WebGlCtxTexture extends CoreContextTexture {
50
59
  super(memManager, textureSource);
51
60
  }
52
61
 
62
+ /**
63
+ * GL error check with direct state marking
64
+ * Uses cached error result to minimize function calls
65
+ */
66
+ private checkGLError(): boolean {
67
+ // Skip if already failed to prevent double-processing
68
+ if (this.state === 'failed') {
69
+ return true;
70
+ }
71
+
72
+ const error = this.glw.getError();
73
+ if (error !== 0) {
74
+ this.state = 'failed';
75
+ this.textureSource.setState('failed', new Error(`WebGL Error: ${error}`));
76
+ return true;
77
+ }
78
+ return false;
79
+ }
80
+
53
81
  get ctxTexture(): WebGLTexture | null {
54
82
  if (this.state === 'freed') {
55
83
  this.load();
@@ -117,9 +145,7 @@ export class WebGlCtxTexture extends CoreContextTexture {
117
145
  // to the GL context before freeing the source data.
118
146
  // This is important to avoid issues with the texture data being
119
147
  // freed while the texture is still being loaded or used.
120
- queueMicrotask(() => {
121
- this.textureSource.freeTextureData();
122
- });
148
+ this.textureSource.freeTextureData();
123
149
  } catch (err: unknown) {
124
150
  // If the texture has been freed while loading, return early.
125
151
  // Type assertion needed because state could change during async operations
@@ -180,6 +206,11 @@ export class WebGlCtxTexture extends CoreContextTexture {
180
206
 
181
207
  glw.texImage2D(0, format, format, glw.UNSIGNED_BYTE, tdata);
182
208
 
209
+ // Check for errors after compressed texture operations
210
+ if (this.checkGLError() === true) {
211
+ return { w: 0, h: 0 };
212
+ }
213
+
183
214
  this.setTextureMemUse(h * w * formatBytes * memoryPadding);
184
215
  } else if (tdata === null) {
185
216
  w = 0;
@@ -199,21 +230,21 @@ export class WebGlCtxTexture extends CoreContextTexture {
199
230
  );
200
231
  this.setTextureMemUse(TRANSPARENT_TEXTURE_DATA.byteLength);
201
232
  } else if ('mipmaps' in tdata && tdata.mipmaps) {
202
- const { mipmaps, w = 0, h = 0, type, glInternalFormat } = tdata;
203
- const view =
204
- type === 'ktx'
205
- ? new DataView(mipmaps[0] ?? new ArrayBuffer(0))
206
- : (mipmaps[0] as unknown as ArrayBufferView);
233
+ const { mipmaps, type, blockInfo } = tdata;
234
+ uploadCompressedTexture[type]!(glw, this._nativeCtxTexture, tdata);
207
235
 
208
- glw.bindTexture(this._nativeCtxTexture);
236
+ // Check for errors after compressed texture operations
237
+ if (this.checkGLError() === true) {
238
+ return { w: 0, h: 0 };
239
+ }
209
240
 
210
- glw.compressedTexImage2D(0, glInternalFormat, w, h, 0, view);
211
- glw.texParameteri(glw.TEXTURE_WRAP_S, glw.CLAMP_TO_EDGE);
212
- glw.texParameteri(glw.TEXTURE_WRAP_T, glw.CLAMP_TO_EDGE);
213
- glw.texParameteri(glw.TEXTURE_MAG_FILTER, glw.LINEAR);
214
- glw.texParameteri(glw.TEXTURE_MIN_FILTER, glw.LINEAR);
241
+ w = tdata.w;
242
+ h = tdata.h;
243
+ this.txCoords.x2 = w / (Math.ceil(w / blockInfo.width) * blockInfo.width);
244
+ this.txCoords.y2 =
245
+ h / (Math.ceil(h / blockInfo.height) * blockInfo.height);
215
246
 
216
- this.setTextureMemUse(view.byteLength);
247
+ this.setTextureMemUse(mipmaps[0]?.byteLength ?? 0);
217
248
  } else if (tdata && tdata instanceof Uint8Array) {
218
249
  // Color Texture
219
250
  w = 1;
@@ -227,6 +258,11 @@ export class WebGlCtxTexture extends CoreContextTexture {
227
258
 
228
259
  glw.texImage2D(0, format, w, h, 0, format, glw.UNSIGNED_BYTE, tdata);
229
260
 
261
+ // Check for errors after compressed texture operations
262
+ if (this.checkGLError() === true) {
263
+ return { w: 0, h: 0 };
264
+ }
265
+
230
266
  this.setTextureMemUse(w * h * formatBytes);
231
267
  } else {
232
268
  console.error(
@@ -253,6 +289,13 @@ export class WebGlCtxTexture extends CoreContextTexture {
253
289
 
254
290
  this.state = 'freed';
255
291
  this.textureSource.setState('freed');
292
+ this.release();
293
+ }
294
+
295
+ /**
296
+ * Release the WebGLTexture from the GPU without changing state
297
+ */
298
+ release(): void {
256
299
  this._w = 0;
257
300
  this._h = 0;
258
301
 
@@ -34,7 +34,8 @@ type ReqQuad =
34
34
  | 'rtt'
35
35
  | 'clippingRect'
36
36
  | 'height'
37
- | 'width';
37
+ | 'width'
38
+ | 'time';
38
39
  type RenderOpQuadOptions = Pick<QuadOptions, ReqQuad> &
39
40
  Partial<Omit<QuadOptions, ReqQuad>> & {
40
41
  sdfShaderProps?: Record<string, unknown>;
@@ -65,6 +66,7 @@ export class WebGlRenderOp extends CoreRenderOp {
65
66
  readonly framebufferDimensions?: Dimensions | null;
66
67
  readonly alpha: number;
67
68
  readonly pixelRatio: number;
69
+ readonly time?: number | null;
68
70
 
69
71
  constructor(
70
72
  readonly renderer: WebGlRenderer,
@@ -83,6 +85,7 @@ export class WebGlRenderOp extends CoreRenderOp {
83
85
  this.alpha = quad.alpha;
84
86
  this.pixelRatio =
85
87
  this.parentHasRenderTexture === true ? 1 : renderer.stage.pixelRatio;
88
+ this.time = quad.time;
86
89
 
87
90
  /**
88
91
  * related to line 51
@@ -52,6 +52,7 @@ import { WebGlCtxRenderTexture } from './WebGlCtxRenderTexture.js';
52
52
  import { Default } from '../../shaders/webgl/Default.js';
53
53
  import type { WebGlShaderType } from './WebGlShaderNode.js';
54
54
  import { WebGlShaderNode } from './WebGlShaderNode.js';
55
+ import type { Dimensions } from '../../../common/CommonTypes.js';
55
56
 
56
57
  export type WebGlRendererOptions = CoreRendererOptions;
57
58
 
@@ -77,7 +78,7 @@ export class WebGlRenderer extends CoreRenderer {
77
78
  override rttNodes: CoreNode[] = [];
78
79
  activeRttNode: CoreNode | null = null;
79
80
 
80
- defaultTextureCoords: TextureCoords = {
81
+ override defaultTextureCoords: TextureCoords = {
81
82
  x1: 0,
82
83
  y1: 0,
83
84
  x2: 1,
@@ -640,85 +641,82 @@ export class WebGlRenderer extends CoreRenderer {
640
641
  return this.defaultShaderNode;
641
642
  }
642
643
 
643
- override getTextureCoords(node: CoreNode): TextureCoords {
644
+ override getTextureCoords(node: CoreNode): TextureCoords | undefined {
644
645
  const texture = node.texture;
645
646
  if (texture === null) {
646
- return this.defaultTextureCoords;
647
+ return undefined;
647
648
  }
648
649
 
649
- const textureOptions = node.textureOptions;
650
+ //this stuff needs to be properly moved to CtxSubTexture at some point in the future.
651
+ const ctxTexture =
652
+ (texture as SubTexture).parentTexture !== undefined
653
+ ? (texture as SubTexture).parentTexture.ctxTexture
654
+ : texture.ctxTexture;
655
+ if (ctxTexture === undefined) {
656
+ return undefined;
657
+ }
658
+
659
+ const textureOptions = node.props.textureOptions;
660
+
661
+ //early exit for textures with no options unless its a subtexture
650
662
  if (
651
- texture.type === TextureType.subTexture ||
652
- texture.type === TextureType.image ||
653
- texture.type === TextureType.renderToTexture ||
654
- textureOptions !== null
663
+ texture.type !== TextureType.subTexture &&
664
+ textureOptions === undefined
655
665
  ) {
656
- const result = {
657
- x1: 0,
658
- y1: 0,
659
- x2: 1,
660
- y2: 1,
661
- };
662
-
663
- if (texture.type === TextureType.subTexture) {
664
- const props = (texture as SubTexture).props;
665
- const { w: parentW = 0, h: parentH = 0 } = (texture as SubTexture)
666
- .parentTexture.dimensions || { w: 0, h: 0 };
667
- result.x1 = props.x / parentW;
668
- result.x2 = result.x1 + props.w / parentW;
669
- result.y1 = props.y / parentH;
670
- result.y2 = result.y1 + props.h / parentH;
671
- }
672
-
673
- if (
674
- texture.type === TextureType.image &&
675
- textureOptions !== null &&
676
- textureOptions.resizeMode !== undefined &&
677
- texture.dimensions !== null
678
- ) {
679
- const resizeMode = textureOptions.resizeMode;
680
- const dimensions = texture.dimensions;
681
- if (resizeMode.type === 'cover') {
682
- const scaleX = node.props.w / dimensions.w;
683
- const scaleY = node.props.h / dimensions.h;
684
- const scale = Math.max(scaleX, scaleY);
685
- const precision = 1 / scale;
686
- // Determine based on width
687
- if (scaleX < scale) {
688
- const desiredSize = precision * node.props.w;
689
- result.x1 =
690
- (1 - desiredSize / dimensions.w) * (resizeMode.clipX ?? 0.5);
691
- result.x2 = result.x1 + desiredSize / dimensions.w;
692
- }
693
- // Determine based on height
694
- if (scaleY < scale) {
695
- const desiredSize = precision * node.props.h;
696
- result.y1 =
697
- (1 - desiredSize / dimensions.h) * (resizeMode.clipY ?? 0.5);
698
- result.y2 = result.y1 + desiredSize / dimensions.h;
699
- }
700
- }
701
- }
666
+ return (ctxTexture as WebGlCtxTexture).txCoords;
667
+ }
702
668
 
703
- // Flip texture coordinates if dictated by texture options
704
- let flipY = 0;
705
- if (textureOptions !== null) {
706
- if (textureOptions.flipX === true) {
707
- [result.x1, result.x2] = [result.x2, result.x1];
708
- }
669
+ let { x1, x2, y1, y2 } = (ctxTexture as WebGlCtxTexture).txCoords;
670
+ if (texture.type === TextureType.subTexture) {
671
+ const { w: parentW, h: parentH } = (texture as SubTexture).parentTexture
672
+ .dimensions!;
673
+ const { x, y, w, h } = (texture as SubTexture).props;
674
+ x1 = x / parentW;
675
+ y1 = y / parentH;
676
+ x2 = x1 + w / parentW;
677
+ y2 = y1 + h / parentH;
678
+ }
709
679
 
710
- // convert to integer for bitwise operation below
711
- flipY = +(textureOptions.flipY || false);
680
+ const resizeMode = textureOptions.resizeMode;
681
+ if (
682
+ resizeMode !== undefined &&
683
+ resizeMode.type === 'cover' &&
684
+ texture.dimensions !== null
685
+ ) {
686
+ const dimensions = texture.dimensions as Dimensions;
687
+ const w = node.props.w;
688
+ const h = node.props.h;
689
+ const scaleX = w / dimensions.w;
690
+ const scaleY = h / dimensions.h;
691
+ const scale = Math.max(scaleX, scaleY);
692
+ const precision = 1 / scale;
693
+
694
+ // Determine based on width
695
+ if (scaleX < scale) {
696
+ const desiredSize = precision * node.props.w;
697
+ x1 = (1 - desiredSize / dimensions.w) * (resizeMode.clipX ?? 0.5);
698
+ x2 = x1 + desiredSize / dimensions.w;
712
699
  }
713
-
714
- // Eitherone should be true
715
- if (flipY ^ +(texture.type === TextureType.renderToTexture)) {
716
- [result.y1, result.y2] = [result.y2, result.y1];
700
+ // Determine based on height
701
+ if (scaleY < scale) {
702
+ const desiredSize = precision * node.props.h;
703
+ y1 = (1 - desiredSize / dimensions.h) * (resizeMode.clipY ?? 0.5);
704
+ y2 = y1 + desiredSize / dimensions.h;
717
705
  }
718
- return result as TextureCoords;
719
706
  }
720
707
 
721
- return this.defaultTextureCoords;
708
+ if (textureOptions.flipX === true) {
709
+ [x1, x2] = [x2, x1];
710
+ }
711
+ if (textureOptions.flipY === true) {
712
+ [y1, y2] = [y2, y1];
713
+ }
714
+ return {
715
+ x1,
716
+ y1,
717
+ x2,
718
+ y2,
719
+ };
722
720
  }
723
721
 
724
722
  /**
@@ -50,6 +50,7 @@ export class WebGlShaderProgram implements CoreShaderProgram {
50
50
  protected lifecycle: Pick<WebGlShaderType, 'update' | 'canBatch'>;
51
51
  protected useSystemAlpha = false;
52
52
  protected useSystemDimensions = false;
53
+ protected useTimeValue = false;
53
54
  public isDestroyed = false;
54
55
  supportsIndexedTextures = false;
55
56
 
@@ -123,6 +124,10 @@ export class WebGlShaderProgram implements CoreShaderProgram {
123
124
  this.useSystemAlpha = uniLocs['u_alpha'] !== undefined;
124
125
  this.useSystemDimensions = uniLocs['u_dimensions'] !== undefined;
125
126
 
127
+ this.useTimeValue =
128
+ this.glw.getUniformLocation(program, 'u_dimensions') !== null &&
129
+ config.time !== undefined;
130
+
126
131
  this.lifecycle = {
127
132
  update: config.update,
128
133
  canBatch: config.canBatch,
@@ -149,6 +154,12 @@ export class WebGlShaderProgram implements CoreShaderProgram {
149
154
  return this.lifecycle.canBatch(incomingQuad, currentRenderOp);
150
155
  }
151
156
 
157
+ if (this.useTimeValue === true) {
158
+ if (incomingQuad.time !== currentRenderOp.time) {
159
+ return false;
160
+ }
161
+ }
162
+
152
163
  if (this.useSystemAlpha === true) {
153
164
  if (incomingQuad.alpha !== currentRenderOp.alpha) {
154
165
  return false;
@@ -169,6 +180,7 @@ export class WebGlShaderProgram implements CoreShaderProgram {
169
180
  if (incomingQuad.shader !== null) {
170
181
  shaderPropsA = incomingQuad.shader.resolvedProps;
171
182
  }
183
+
172
184
  if (currentRenderOp.shader !== null) {
173
185
  shaderPropsB = currentRenderOp.shader.resolvedProps;
174
186
  }
@@ -221,6 +233,10 @@ export class WebGlShaderProgram implements CoreShaderProgram {
221
233
  );
222
234
  }
223
235
 
236
+ if (this.useTimeValue === true) {
237
+ this.glw.uniform1f('u_time', renderOp.time as number);
238
+ }
239
+
224
240
  if (this.useSystemAlpha === true) {
225
241
  this.glw.uniform1f('u_alpha', renderOp.alpha);
226
242
  }
@@ -52,7 +52,7 @@ export const RadialGradient: CanvasShaderType<
52
52
  pivotY: props.pivot[1] * node.h,
53
53
  scaleX,
54
54
  scaleY,
55
- size: Math.min(pWidth, pHeight) * 0.5,
55
+ size: Math.min(pWidth, pHeight),
56
56
  colors: props.colors.map((value) => this.toColorString(value)),
57
57
  };
58
58
  },
@@ -32,13 +32,15 @@ export interface RadialGradientProps {
32
32
  */
33
33
  stops: number[];
34
34
  /**
35
- * Width of the RadialGradientEffect
35
+ * radial width of the RadialGradientEffect
36
+ *
37
+ * @remarks from the center to the outer edge of the gradient
36
38
  */
37
39
  w: number;
38
40
  /**
39
- * height of the RadialGradientEffect
40
- *
41
- * @remarks if not defined uses the width value
41
+ * radial height of the RadialGradientEffect
42
+ * if not defined uses the width value
43
+ * @remarks from the center to the outer edge of the gradient
42
44
  */
43
45
  h: number;
44
46
  /**
@@ -98,7 +98,8 @@ export const LinearGradient: WebGlShaderType<LinearGradientProps> = {
98
98
  vec2 gradVec = t - f;
99
99
  float dist = dot(v_textureCoords.xy * u_dimensions - f, gradVec) / dot(gradVec, gradVec);
100
100
  vec4 colorOut = getGradientColor(dist);
101
- gl_FragColor = mix(color, colorOut, clamp(colorOut.a, 0.0, 1.0));
101
+ vec3 blendedRGB = mix(color.rgb, colorOut.rgb, clamp(colorOut.a, 0.0, 1.0));
102
+ gl_FragColor = vec4(blendedRGB, color.a);
102
103
  }
103
104
  `;
104
105
  },
@@ -33,7 +33,7 @@ export const RadialGradient: WebGlShaderType<RadialGradientProps> = {
33
33
  props.pivot[0] * node.w,
34
34
  props.pivot[1] * node.h,
35
35
  );
36
- this.uniform2f('u_size', props.w * 0.5, props.h * 0.5);
36
+ this.uniform2f('u_size', props.w, props.h);
37
37
  this.uniform1fv('u_stops', new Float32Array(props.stops));
38
38
  const colors: number[] = [];
39
39
  for (let i = 0; i < props.colors.length; i++) {
@@ -63,15 +63,13 @@ export const RadialGradient: WebGlShaderType<RadialGradientProps> = {
63
63
 
64
64
  uniform vec2 u_projection;
65
65
  uniform vec2 u_size;
66
+
66
67
  uniform float u_stops[MAX_STOPS];
67
68
  uniform vec4 u_colors[MAX_STOPS];
68
69
 
69
70
  varying vec4 v_color;
70
71
  varying vec2 v_textureCoords;
71
-
72
- vec2 calcPoint(float d, float angle) {
73
- return d * vec2(cos(angle), sin(angle)) + (u_dimensions * 0.5);
74
- }
72
+ varying vec2 v_nodeCoords;
75
73
 
76
74
  vec4 getGradientColor(float dist) {
77
75
  dist = clamp(dist, 0.0, 1.0);
@@ -92,15 +90,18 @@ export const RadialGradient: WebGlShaderType<RadialGradientProps> = {
92
90
  return mix(u_colors[i], u_colors[i + 1], lDist);
93
91
  }
94
92
  }
93
+
94
+ return u_colors[LAST_STOP];
95
95
  }
96
96
 
97
97
  void main() {
98
98
  vec4 color = texture2D(u_texture, v_textureCoords) * v_color;
99
- vec2 point = v_textureCoords.xy * u_dimensions;
99
+ vec2 point = v_nodeCoords.xy * u_dimensions;
100
100
  float dist = length((point - u_projection) / u_size);
101
101
 
102
102
  vec4 colorOut = getGradientColor(dist);
103
- gl_FragColor = mix(color, colorOut, clamp(colorOut.a, 0.0, 1.0));
103
+ vec3 blendedRGB = mix(color.rgb, colorOut.rgb, clamp(colorOut.a, 0.0, 1.0));
104
+ gl_FragColor = vec4(blendedRGB, color.a);
104
105
  }
105
106
  `;
106
107
  },
@@ -80,6 +80,7 @@ export const Rounded: WebGlShaderType<RoundedProps> = {
80
80
  uniform vec2 u_resolution;
81
81
  uniform vec2 u_dimensions;
82
82
  uniform float u_alpha;
83
+ uniform float u_pixelRatio;
83
84
  uniform sampler2D u_texture;
84
85
 
85
86
  //custom uniforms
@@ -103,7 +104,8 @@ export const Rounded: WebGlShaderType<RoundedProps> = {
103
104
  vec2 boxUv = v_nodeCoords.xy * u_dimensions - halfDimensions;
104
105
  float boxDist = roundedBox(boxUv, halfDimensions, u_radius);
105
106
 
106
- float roundedAlpha = 1.0 - smoothstep(0.0, 1.0, boxDist);
107
+ float edgeWidth = 1.0 / u_pixelRatio;
108
+ float roundedAlpha = 1.0 - smoothstep(-0.5 * edgeWidth, 0.5 * edgeWidth, boxDist);
107
109
 
108
110
  vec4 resColor = vec4(0.0);
109
111
  resColor = mix(resColor, color, roundedAlpha);
@@ -130,7 +130,8 @@ export const RoundedWithBorder: WebGlShaderType<RoundedWithBorderProps> = {
130
130
  vec2 boxUv = v_nodeCoords.xy * u_dimensions - v_halfDimensions;
131
131
  float outerDist = roundedBox(boxUv, v_halfDimensions, u_radius);
132
132
 
133
- float outerAlpha = 1.0 - smoothstep(0.0, 1.0, outerDist);
133
+ float edgeWidth = 1.0 / u_pixelRatio;
134
+ float outerAlpha = 1.0 - smoothstep(-0.5 * edgeWidth, 0.5 * edgeWidth, outerDist);
134
135
 
135
136
  if(v_borderZero == 1.0) {
136
137
  gl_FragColor = mix(vec4(0.0), color, outerAlpha) * u_alpha;
@@ -141,7 +142,7 @@ export const RoundedWithBorder: WebGlShaderType<RoundedWithBorderProps> = {
141
142
  boxUv.y += u_borderWidth.z > u_borderWidth.x ? ((u_borderWidth.z - u_borderWidth.x) * 0.5 + 0.5) : -(u_borderWidth.x - u_borderWidth.z) * 0.5;
142
143
 
143
144
  float innerDist = roundedBox(boxUv, v_innerSize, v_innerRadius);
144
- float innerAlpha = 1.0 - smoothstep(0.0, 1.0, innerDist);
145
+ float innerAlpha = 1.0 - smoothstep(-0.5 * edgeWidth, 0.5 * edgeWidth, innerDist);
145
146
 
146
147
  vec4 resColor = mix(u_borderColor, color, innerAlpha);
147
148
  resColor = mix(vec4(0.0), resColor, outerAlpha);
@@ -151,7 +151,8 @@ export const RoundedWithBorderAndShadow: WebGlShaderType<RoundedWithBorderAndSha
151
151
  vec2 boxUv = v_nodeCoords.xy * u_dimensions - v_halfDimensions;
152
152
  float outerDist = roundedBox(boxUv, v_halfDimensions - 1.0, u_radius);
153
153
 
154
- float outerAlpha = 1.0 - smoothstep(0.0, 1.0, outerDist);
154
+ float edgeWidth = 1.0 / u_pixelRatio;
155
+ float outerAlpha = 1.0 - smoothstep(-0.5 * edgeWidth, 0.5 * edgeWidth, outerDist);
155
156
 
156
157
  float shadowAlpha = shadowBox(boxUv - u_shadow.xy, v_halfDimensions + u_shadow.w, u_radius + u_shadow.z);
157
158
  vec4 shadow = mix(vec4(0.0), u_shadowColor, shadowAlpha);
@@ -165,7 +166,7 @@ export const RoundedWithBorderAndShadow: WebGlShaderType<RoundedWithBorderAndSha
165
166
  boxUv.y += u_borderWidth.z > u_borderWidth.x ? ((u_borderWidth.z - u_borderWidth.x) * 0.5 + 0.5) : -(u_borderWidth.x - u_borderWidth.z) * 0.5;
166
167
 
167
168
  float innerDist = roundedBox(boxUv, v_innerSize, v_innerRadius);
168
- float innerAlpha = 1.0 - smoothstep(0.0, 1.0, innerDist);
169
+ float innerAlpha = 1.0 - smoothstep(-0.5 * edgeWidth, 0.5 * edgeWidth, innerDist);
169
170
 
170
171
  vec4 resColor = mix(u_borderColor, color, innerAlpha);
171
172
  resColor = mix(shadow, resColor, outerAlpha);
@@ -81,7 +81,8 @@ export const RoundedWithShadow: WebGlShaderType<RoundedWithShadowProps> = {
81
81
  vec2 boxUv = v_nodeCoords.xy * u_dimensions - halfDimensions;
82
82
  float boxDist = roundedBox(boxUv, halfDimensions, u_radius);
83
83
 
84
- float roundedAlpha = 1.0 - smoothstep(0.0, u_pixelRatio, boxDist);
84
+ float edgeWidth = 1.0 / u_pixelRatio;
85
+ float roundedAlpha = 1.0 - smoothstep(-0.5 * edgeWidth, 0.5 * edgeWidth, boxDist);
85
86
 
86
87
  float shadowAlpha = shadowBox(boxUv - u_shadow.xy, halfDimensions + u_shadow.w, u_radius + u_shadow.z);
87
88
 
@@ -56,7 +56,7 @@ const layoutCache = new Map<
56
56
 
57
57
  // Initialize the Text Renderer
58
58
  const init = (stage: Stage): void => {
59
- const dpr = window.devicePixelRatio || 1;
59
+ const dpr = stage.options.devicePhysicalPixelRatio;
60
60
 
61
61
  // Drawing canvas and context
62
62
  canvas = stage.platform.createCanvas() as HTMLCanvasElement | OffscreenCanvas;
@@ -326,7 +326,7 @@ export const loadFont = async (
326
326
  premultiplyAlpha: false,
327
327
  });
328
328
 
329
- atlasTexture.setRenderableOwner(this, true);
329
+ atlasTexture.setRenderableOwner(fontFamily, true);
330
330
  atlasTexture.preventCleanup = true; // Prevent automatic cleanup
331
331
 
332
332
  if (atlasTexture.state === 'loaded') {
@@ -49,9 +49,12 @@ export class ColorTexture extends Texture {
49
49
 
50
50
  props: Required<ColorTextureProps>;
51
51
 
52
- constructor(txManager: CoreTextureManager, props?: ColorTextureProps) {
52
+ constructor(
53
+ txManager: CoreTextureManager,
54
+ props: Required<ColorTextureProps>,
55
+ ) {
53
56
  super(txManager);
54
- this.props = ColorTexture.resolveDefaults(props || {});
57
+ this.props = props;
55
58
  }
56
59
 
57
60
  get color() {
@@ -86,8 +89,7 @@ export class ColorTexture extends Texture {
86
89
  }
87
90
 
88
91
  static override makeCacheKey(props: ColorTextureProps): string {
89
- const resolvedProps = ColorTexture.resolveDefaults(props);
90
- return `ColorTexture,${resolvedProps.color}`;
92
+ return `ColorTexture,${props.color}`;
91
93
  }
92
94
 
93
95
  static override resolveDefaults(