@lightningjs/renderer 3.0.0-beta20 → 3.0.0-beta21

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 (152) hide show
  1. package/dist/src/core/CoreNode.d.ts +53 -7
  2. package/dist/src/core/CoreNode.js +175 -65
  3. package/dist/src/core/CoreNode.js.map +1 -1
  4. package/dist/src/core/CoreTextNode.d.ts +1 -1
  5. package/dist/src/core/CoreTextNode.js +3 -5
  6. package/dist/src/core/CoreTextNode.js.map +1 -1
  7. package/dist/src/core/CoreTextureManager.js +1 -1
  8. package/dist/src/core/CoreTextureManager.js.map +1 -1
  9. package/dist/src/core/Stage.d.ts +2 -1
  10. package/dist/src/core/Stage.js +9 -7
  11. package/dist/src/core/Stage.js.map +1 -1
  12. package/dist/src/core/TextureMemoryManager.d.ts +1 -1
  13. package/dist/src/core/TextureMemoryManager.js +3 -3
  14. package/dist/src/core/TextureMemoryManager.js.map +1 -1
  15. package/dist/src/core/animations/Animation.d.ts +21 -0
  16. package/dist/src/core/animations/Animation.js +194 -0
  17. package/dist/src/core/animations/Animation.js.map +1 -0
  18. package/dist/src/core/animations/Playback.d.ts +64 -0
  19. package/dist/src/core/animations/Playback.js +169 -0
  20. package/dist/src/core/animations/Playback.js.map +1 -0
  21. package/dist/src/core/animations/Transition.d.ts +27 -0
  22. package/dist/src/core/animations/Transition.js +52 -0
  23. package/dist/src/core/animations/Transition.js.map +1 -0
  24. package/dist/src/core/animations/utils.d.ts +2 -0
  25. package/dist/src/core/animations/utils.js +136 -0
  26. package/dist/src/core/animations/utils.js.map +1 -0
  27. package/dist/src/core/lib/ImageWorker.d.ts +2 -2
  28. package/dist/src/core/lib/ImageWorker.js +30 -11
  29. package/dist/src/core/lib/ImageWorker.js.map +1 -1
  30. package/dist/src/core/lib/WebGlContextWrapper.js +1 -1
  31. package/dist/src/core/lib/WebGlContextWrapper.js.map +1 -1
  32. package/dist/src/core/lib/utils.d.ts +6 -2
  33. package/dist/src/core/lib/utils.js +21 -21
  34. package/dist/src/core/lib/utils.js.map +1 -1
  35. package/dist/src/core/renderers/CoreRenderer.d.ts +1 -31
  36. package/dist/src/core/renderers/CoreRenderer.js.map +1 -1
  37. package/dist/src/core/renderers/CoreShaderNode.d.ts +4 -0
  38. package/dist/src/core/renderers/CoreShaderNode.js +15 -0
  39. package/dist/src/core/renderers/CoreShaderNode.js.map +1 -1
  40. package/dist/src/core/renderers/canvas/CanvasRenderer.d.ts +3 -3
  41. package/dist/src/core/renderers/canvas/CanvasRenderer.js +38 -33
  42. package/dist/src/core/renderers/canvas/CanvasRenderer.js.map +1 -1
  43. package/dist/src/core/renderers/canvas/CanvasShaderNode.d.ts +1 -2
  44. package/dist/src/core/renderers/canvas/CanvasShaderNode.js.map +1 -1
  45. package/dist/src/core/renderers/webgl/SdfRenderOp.d.ts +33 -0
  46. package/dist/src/core/renderers/webgl/SdfRenderOp.js +97 -0
  47. package/dist/src/core/renderers/webgl/SdfRenderOp.js.map +1 -0
  48. package/dist/src/core/renderers/webgl/WebGlCoreCtxTexture.js +1 -1
  49. package/dist/src/core/renderers/webgl/WebGlCoreCtxTexture.js.map +1 -1
  50. package/dist/src/core/renderers/webgl/WebGlCtxTexture.js +12 -8
  51. package/dist/src/core/renderers/webgl/WebGlCtxTexture.js.map +1 -1
  52. package/dist/src/core/renderers/webgl/WebGlRenderOp.d.ts +2 -3
  53. package/dist/src/core/renderers/webgl/WebGlRenderOp.js +1 -3
  54. package/dist/src/core/renderers/webgl/WebGlRenderOp.js.map +1 -1
  55. package/dist/src/core/renderers/webgl/WebGlRenderer.d.ts +6 -18
  56. package/dist/src/core/renderers/webgl/WebGlRenderer.js +48 -61
  57. package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +1 -1
  58. package/dist/src/core/renderers/webgl/WebGlShaderNode.d.ts +2 -4
  59. package/dist/src/core/renderers/webgl/WebGlShaderNode.js.map +1 -1
  60. package/dist/src/core/renderers/webgl/WebGlShaderProgram.d.ts +3 -4
  61. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js +40 -29
  62. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js.map +1 -1
  63. package/dist/src/core/shaders/canvas/Border.d.ts +8 -2
  64. package/dist/src/core/shaders/canvas/Border.js +62 -23
  65. package/dist/src/core/shaders/canvas/Border.js.map +1 -1
  66. package/dist/src/core/shaders/canvas/HolePunch.js +2 -1
  67. package/dist/src/core/shaders/canvas/HolePunch.js.map +1 -1
  68. package/dist/src/core/shaders/canvas/LinearGradient.js +5 -3
  69. package/dist/src/core/shaders/canvas/LinearGradient.js.map +1 -1
  70. package/dist/src/core/shaders/canvas/RadialGradient.js +7 -5
  71. package/dist/src/core/shaders/canvas/RadialGradient.js.map +1 -1
  72. package/dist/src/core/shaders/canvas/Rounded.js +2 -2
  73. package/dist/src/core/shaders/canvas/Rounded.js.map +1 -1
  74. package/dist/src/core/shaders/canvas/RoundedWithBorder.d.ts +6 -3
  75. package/dist/src/core/shaders/canvas/RoundedWithBorder.js +39 -9
  76. package/dist/src/core/shaders/canvas/RoundedWithBorder.js.map +1 -1
  77. package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.d.ts +2 -3
  78. package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js +44 -7
  79. package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js.map +1 -1
  80. package/dist/src/core/shaders/canvas/RoundedWithShadow.js +5 -4
  81. package/dist/src/core/shaders/canvas/RoundedWithShadow.js.map +1 -1
  82. package/dist/src/core/shaders/canvas/Shadow.js +4 -2
  83. package/dist/src/core/shaders/canvas/Shadow.js.map +1 -1
  84. package/dist/src/core/shaders/canvas/utils/render.d.ts +1 -1
  85. package/dist/src/core/shaders/canvas/utils/render.js +31 -18
  86. package/dist/src/core/shaders/canvas/utils/render.js.map +1 -1
  87. package/dist/src/core/shaders/templates/BorderTemplate.d.ts +10 -0
  88. package/dist/src/core/shaders/templates/BorderTemplate.js +20 -0
  89. package/dist/src/core/shaders/templates/BorderTemplate.js.map +1 -1
  90. package/dist/src/core/shaders/webgl/Border.js +72 -14
  91. package/dist/src/core/shaders/webgl/Border.js.map +1 -1
  92. package/dist/src/core/shaders/webgl/RoundedWithBorder.js +101 -31
  93. package/dist/src/core/shaders/webgl/RoundedWithBorder.js.map +1 -1
  94. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js +102 -38
  95. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js.map +1 -1
  96. package/dist/src/core/shaders/webgl/RoundedWithShadow.js +5 -4
  97. package/dist/src/core/shaders/webgl/RoundedWithShadow.js.map +1 -1
  98. package/dist/src/core/shaders/webgl/SdfShadowShader.d.ts +9 -0
  99. package/dist/src/core/shaders/webgl/SdfShadowShader.js +100 -0
  100. package/dist/src/core/shaders/webgl/SdfShadowShader.js.map +1 -0
  101. package/dist/src/core/shaders/webgl/Shadow.js +12 -6
  102. package/dist/src/core/shaders/webgl/Shadow.js.map +1 -1
  103. package/dist/src/core/text-rendering/SdfTextRenderer.js +12 -20
  104. package/dist/src/core/text-rendering/SdfTextRenderer.js.map +1 -1
  105. package/dist/src/core/utils.d.ts +1 -1
  106. package/dist/src/main-api/Inspector.d.ts +1 -1
  107. package/dist/src/main-api/Inspector.js +4 -1
  108. package/dist/src/main-api/Inspector.js.map +1 -1
  109. package/dist/src/main-api/Renderer.d.ts +10 -0
  110. package/dist/src/main-api/Renderer.js +2 -0
  111. package/dist/src/main-api/Renderer.js.map +1 -1
  112. package/dist/tsconfig.dist.tsbuildinfo +1 -1
  113. package/package.json +1 -1
  114. package/src/core/Autosizer.ts +224 -0
  115. package/src/core/CoreNode.test.ts +116 -2
  116. package/src/core/CoreNode.ts +247 -78
  117. package/src/core/CoreTextNode.ts +3 -5
  118. package/src/core/CoreTextureManager.ts +1 -1
  119. package/src/core/Stage.ts +10 -7
  120. package/src/core/TextureMemoryManager.ts +3 -3
  121. package/src/core/lib/ImageWorker.ts +36 -11
  122. package/src/core/lib/WebGlContextWrapper.ts +1 -1
  123. package/src/core/lib/utils.ts +28 -25
  124. package/src/core/renderers/CoreRenderer.ts +1 -32
  125. package/src/core/renderers/CoreShaderNode.ts +20 -0
  126. package/src/core/renderers/canvas/CanvasRenderer.ts +43 -51
  127. package/src/core/renderers/canvas/CanvasShaderNode.ts +1 -2
  128. package/src/core/renderers/webgl/SdfRenderOp.ts +105 -0
  129. package/src/core/renderers/webgl/WebGlCtxTexture.ts +16 -9
  130. package/src/core/renderers/webgl/WebGlRenderer.ts +56 -78
  131. package/src/core/renderers/webgl/WebGlShaderNode.ts +2 -7
  132. package/src/core/renderers/webgl/WebGlShaderProgram.ts +48 -38
  133. package/src/core/shaders/canvas/Border.ts +86 -29
  134. package/src/core/shaders/canvas/HolePunch.ts +2 -1
  135. package/src/core/shaders/canvas/LinearGradient.ts +8 -6
  136. package/src/core/shaders/canvas/RadialGradient.ts +7 -10
  137. package/src/core/shaders/canvas/Rounded.ts +5 -5
  138. package/src/core/shaders/canvas/RoundedWithBorder.ts +68 -18
  139. package/src/core/shaders/canvas/RoundedWithBorderAndShadow.ts +71 -23
  140. package/src/core/shaders/canvas/RoundedWithShadow.ts +6 -5
  141. package/src/core/shaders/canvas/Shadow.ts +7 -5
  142. package/src/core/shaders/canvas/utils/render.ts +45 -36
  143. package/src/core/shaders/templates/BorderTemplate.ts +30 -0
  144. package/src/core/shaders/webgl/Border.ts +72 -15
  145. package/src/core/shaders/webgl/RoundedWithBorder.ts +101 -31
  146. package/src/core/shaders/webgl/RoundedWithBorderAndShadow.ts +102 -38
  147. package/src/core/shaders/webgl/RoundedWithShadow.ts +5 -4
  148. package/src/core/shaders/webgl/Shadow.ts +12 -6
  149. package/src/core/text-rendering/SdfTextRenderer.ts +18 -21
  150. package/src/main-api/Inspector.ts +6 -3
  151. package/src/main-api/Renderer.ts +13 -0
  152. package/src/core/renderers/webgl/WebGlRenderOp.ts +0 -170
@@ -1,4 +1,7 @@
1
1
  import type { TextureOptions } from './CoreTextureManager.js';
2
+ import type { WebGlRenderer } from './renderers/webgl/WebGlRenderer.js';
3
+ import type { WebGlCtxTexture } from './renderers/webgl/WebGlCtxTexture.js';
4
+ import type { BufferCollection } from './renderers/webgl/internal/BufferCollection.js';
2
5
  import type { CoreRenderer } from './renderers/CoreRenderer.js';
3
6
  import type { Stage } from './Stage.js';
4
7
  import { type Texture, type TextureCoords, type TextureLoadedEventHandler } from './textures/Texture.js';
@@ -10,6 +13,7 @@ import { RenderCoords } from './lib/RenderCoords.js';
10
13
  import type { AnimationSettings } from './animations/CoreAnimation.js';
11
14
  import type { IAnimationController } from '../common/IAnimationController.js';
12
15
  import type { CoreShaderNode } from './renderers/CoreShaderNode.js';
16
+ import { Autosizer } from './Autosizer.js';
13
17
  export declare enum CoreNodeRenderState {
14
18
  Init = 0,
15
19
  OutOfBounds = 2,
@@ -106,6 +110,10 @@ export declare enum UpdateType {
106
110
  * RecalcUniforms
107
111
  */
108
112
  RecalcUniforms = 4096,
113
+ /**
114
+ * Autosize update
115
+ */
116
+ Autosize = 8192,
109
117
  /**
110
118
  * None
111
119
  */
@@ -113,7 +121,7 @@ export declare enum UpdateType {
113
121
  /**
114
122
  * All
115
123
  */
116
- All = 7167
124
+ All = 16383
117
125
  }
118
126
  /**
119
127
  * A custom data map which can be stored on an CoreNode
@@ -175,14 +183,35 @@ export interface CoreNodeProps {
175
183
  */
176
184
  alpha: number;
177
185
  /**
178
- * Autosize mode
186
+ * Autosize
179
187
  *
180
188
  * @remarks
181
- * When enabled, when a texture is loaded into the Node, the Node will
182
- * automatically resize to the dimensions of the texture.
189
+ * When enabled, the Node automatically resizes based on its content
190
+ *
191
+ * **Texture Autosize Mode:**
192
+ * - When the Node has a texture, it automatically resizes to match the
193
+ * texture's dimensions when the texture loads
194
+ * - This ensures images display at their natural size without manual sizing
195
+ * - Text Nodes always use this mode regardless of this setting
196
+ *
197
+ * **Children Autosize Mode:**
198
+ * - When the Node has no texture but contains children, it automatically
199
+ * resizes to encompass all children's bounds
200
+ * - Calculates the bounding box that contains all child positions, dimensions,
201
+ * and transforms (scale, rotation, mount/pivot points)
202
+ * - Creates container behavior where the parent grows to fit its content
203
+ * - Updates dynamically as children are added, removed, or transformed
204
+ *
205
+ * **Mode Selection Logic:**
206
+ * - Texture mode takes precedence over children mode
207
+ * - Mode switches automatically when texture is added/removed
208
+ * - If no texture and no children, autosize has no effect
209
+ *
210
+ * **Performance:**
211
+ * - Children mode uses efficient transform caching and differential updates
212
+ * - Only recalculates when child transforms actually change
213
+ * - Minimal memory allocation with factory function patterns
183
214
  *
184
- * Text Nodes are always autosized based on their text content regardless
185
- * of this mode setting.
186
215
  *
187
216
  * @default `false`
188
217
  */
@@ -619,6 +648,10 @@ export declare class CoreNode extends EventEmitter {
619
648
  readonly children: CoreNode[];
620
649
  protected _id: number;
621
650
  readonly props: CoreNodeProps;
651
+ readonly isCoreNode: true;
652
+ renderOpBufferIdx: number;
653
+ numQuads: number;
654
+ renderOpTextures: WebGlCtxTexture[];
622
655
  private hasShaderUpdater;
623
656
  hasShaderTimeFn: boolean;
624
657
  private hasColorProps;
@@ -654,6 +687,9 @@ export declare class CoreNode extends EventEmitter {
654
687
  * only used when rtt = true
655
688
  */
656
689
  framebufferDimensions: Dimensions | null;
690
+ /**Autosize properties */
691
+ autosizer: Autosizer | null;
692
+ parentAutosizer: Autosizer | null;
657
693
  destroyed: boolean;
658
694
  constructor(stage: Stage, props: CoreNodeProps);
659
695
  loadTexture(): void;
@@ -730,6 +766,8 @@ export declare class CoreNode extends EventEmitter {
730
766
  */
731
767
  destroy(): void;
732
768
  renderQuads(renderer: CoreRenderer): void;
769
+ get quadBufferCollection(): BufferCollection;
770
+ get time(): number;
733
771
  getTimerValue(): number;
734
772
  sortChildren(): void;
735
773
  removeChild(node: CoreNode, targetParent?: CoreNode | null): void;
@@ -821,7 +859,7 @@ export declare class CoreNode extends EventEmitter {
821
859
  /**
822
860
  * Returns the framebuffer dimensions of the RTT parent
823
861
  */
824
- get parentFramebufferDimensions(): Dimensions;
862
+ get parentFramebufferDimensions(): Dimensions | null;
825
863
  /**
826
864
  * Returns the parent render texture node if it exists.
827
865
  */
@@ -835,5 +873,13 @@ export declare class CoreNode extends EventEmitter {
835
873
  setRTTUpdates(type: number): void;
836
874
  animate(props: Partial<CoreNodeAnimateProps>, settings: Partial<AnimationSettings>): IAnimationController;
837
875
  flush(): void;
876
+ /**
877
+ * Add a texture to the current RenderOp.
878
+ *
879
+ * @param texture
880
+ * @returns Assigned Texture Index of the texture in the render op
881
+ */
882
+ addTexture(texture: WebGlCtxTexture): number;
883
+ draw(renderer: WebGlRenderer): void;
838
884
  }
839
885
  export {};
@@ -24,6 +24,7 @@ import { Matrix3d } from './lib/Matrix3d.js';
24
24
  import { RenderCoords } from './lib/RenderCoords.js';
25
25
  import { CoreAnimation } from './animations/CoreAnimation.js';
26
26
  import { CoreAnimationController } from './animations/CoreAnimationController.js';
27
+ import { AutosizeMode, Autosizer } from './Autosizer.js';
27
28
  import { bucketSortByZIndex, incrementalRepositionByZIndex, removeChild, } from './lib/collectionUtils.js';
28
29
  export var CoreNodeRenderState;
29
30
  (function (CoreNodeRenderState) {
@@ -35,8 +36,8 @@ export var CoreNodeRenderState;
35
36
  const NO_CLIPPING_RECT = {
36
37
  x: 0,
37
38
  y: 0,
38
- width: 0,
39
- height: 0,
39
+ w: 0,
40
+ h: 0,
40
41
  valid: false,
41
42
  };
42
43
  const CoreNodeRenderStateMap = new Map();
@@ -135,6 +136,10 @@ export var UpdateType;
135
136
  * RecalcUniforms
136
137
  */
137
138
  UpdateType[UpdateType["RecalcUniforms"] = 4096] = "RecalcUniforms";
139
+ /**
140
+ * Autosize update
141
+ */
142
+ UpdateType[UpdateType["Autosize"] = 8192] = "Autosize";
138
143
  /**
139
144
  * None
140
145
  */
@@ -142,7 +147,7 @@ export var UpdateType;
142
147
  /**
143
148
  * All
144
149
  */
145
- UpdateType[UpdateType["All"] = 7167] = "All";
150
+ UpdateType[UpdateType["All"] = 16383] = "All";
146
151
  })(UpdateType || (UpdateType = {}));
147
152
  /**
148
153
  * A visual Node in the Renderer scene graph.
@@ -157,6 +162,11 @@ export class CoreNode extends EventEmitter {
157
162
  children = [];
158
163
  _id = getNewId();
159
164
  props;
165
+ isCoreNode = true;
166
+ // WebGL Render Op State
167
+ renderOpBufferIdx = 0;
168
+ numQuads = 0;
169
+ renderOpTextures = [];
160
170
  hasShaderUpdater = false;
161
171
  hasShaderTimeFn = false;
162
172
  hasColorProps = false;
@@ -177,8 +187,8 @@ export class CoreNode extends EventEmitter {
177
187
  clippingRect = {
178
188
  x: 0,
179
189
  y: 0,
180
- width: 0,
181
- height: 0,
190
+ w: 0,
191
+ h: 0,
182
192
  valid: false,
183
193
  };
184
194
  textureCoords;
@@ -198,11 +208,16 @@ export class CoreNode extends EventEmitter {
198
208
  * only used when rtt = true
199
209
  */
200
210
  framebufferDimensions = null;
211
+ /**Autosize properties */
212
+ autosizer = null;
213
+ parentAutosizer = null;
201
214
  destroyed = false;
202
215
  constructor(stage, props) {
203
216
  super();
204
217
  this.stage = stage;
205
218
  const p = (this.props = {});
219
+ // Initialize the renderOpTextures array with a capacity of 16 (typical max textures)
220
+ this.renderOpTextures = [];
206
221
  //inital update type
207
222
  let initialUpdateType = UpdateType.Local | UpdateType.RenderBounds | UpdateType.RenderState;
208
223
  // Fast-path assign only known keys
@@ -252,6 +267,7 @@ export class CoreNode extends EventEmitter {
252
267
  p.srcY = props.srcY;
253
268
  p.srcWidth = props.srcWidth;
254
269
  p.srcHeight = props.srcHeight;
270
+ p.autosize = props.autosize;
255
271
  p.parent = props.parent;
256
272
  p.texture = null;
257
273
  p.shader = null;
@@ -272,6 +288,10 @@ export class CoreNode extends EventEmitter {
272
288
  this.rtt = props.rtt;
273
289
  this.boundsMargin = props.boundsMargin;
274
290
  this.interactive = props.interactive;
291
+ // Initialize autosize if enabled
292
+ if (p.autosize === true) {
293
+ this.autosizer = new Autosizer(this);
294
+ }
275
295
  this.setUpdateType(initialUpdateType);
276
296
  // if the default texture isn't loaded yet, wait for it to load
277
297
  // this only happens when the node is created before the stage is ready
@@ -298,7 +318,11 @@ export class CoreNode extends EventEmitter {
298
318
  * This method is called in a microtask to release the texture.
299
319
  */
300
320
  loadTextureTask = () => {
301
- const texture = this.texture;
321
+ const texture = this.props.texture;
322
+ //it is possible that texture is null here if user sets the texture to null right after loadTexture call
323
+ if (texture === null) {
324
+ return;
325
+ }
302
326
  if (this.textureOptions.preload === true) {
303
327
  this.stage.txManager.loadTexture(texture);
304
328
  }
@@ -336,9 +360,8 @@ export class CoreNode extends EventEmitter {
336
360
  texture.setRenderableOwner(this._id, false);
337
361
  }
338
362
  onTextureLoaded = (_, dimensions) => {
339
- if (this.autosize === true) {
340
- this.w = dimensions.w;
341
- this.h = dimensions.h;
363
+ if (this.autosizer !== null) {
364
+ this.autosizer.update();
342
365
  }
343
366
  this.setUpdateType(UpdateType.IsRenderable);
344
367
  // Texture was loaded. In case the RAF loop has already stopped, we request
@@ -477,6 +500,10 @@ export class CoreNode extends EventEmitter {
477
500
  let updateType = this.updateType;
478
501
  let childUpdateType = this.childUpdateType;
479
502
  let updateParent = false;
503
+ //this needs to be handled before setting updateTypes are reset
504
+ if (updateType & UpdateType.Autosize && this.autosizer !== null) {
505
+ this.autosizer.update();
506
+ }
480
507
  // reset update type
481
508
  this.updateType = 0;
482
509
  this.childUpdateType = 0;
@@ -513,12 +540,13 @@ export class CoreNode extends EventEmitter {
513
540
  }
514
541
  this.calculateRenderCoords();
515
542
  this.updateBoundingRect();
516
- updateType |=
517
- UpdateType.RenderState |
518
- UpdateType.Children |
519
- UpdateType.RecalcUniforms;
543
+ updateType |= UpdateType.RenderState | UpdateType.RecalcUniforms;
520
544
  updateParent = hasParent;
521
- childUpdateType |= UpdateType.Global;
545
+ //only propagate children updates if not autosizing
546
+ if ((updateType & UpdateType.Autosize) === 0) {
547
+ updateType |= UpdateType.Children;
548
+ childUpdateType |= UpdateType.Global;
549
+ }
522
550
  if (this.clipping === true) {
523
551
  updateType |= UpdateType.Clipping | UpdateType.RenderBounds;
524
552
  updateParent = hasParent;
@@ -554,6 +582,12 @@ export class CoreNode extends EventEmitter {
554
582
  if (updateType & UpdateType.IsRenderable) {
555
583
  this.updateIsRenderable();
556
584
  }
585
+ // Handle autosize updates when children transforms change
586
+ if (updateType & UpdateType.Global &&
587
+ this.isRenderable === true &&
588
+ this.parentAutosizer !== null) {
589
+ this.parentAutosizer.patch(this.id);
590
+ }
557
591
  if (updateType & UpdateType.Clipping) {
558
592
  this.calculateClippingRect(parentClippingRect);
559
593
  updateType |= UpdateType.Children;
@@ -909,8 +943,8 @@ export class CoreNode extends EventEmitter {
909
943
  if (clipping === true && isRotated === false) {
910
944
  clippingRect.x = gt.tx;
911
945
  clippingRect.y = gt.ty;
912
- clippingRect.width = this.props.w * gt.ta;
913
- clippingRect.height = this.props.h * gt.td;
946
+ clippingRect.w = this.props.w * gt.ta;
947
+ clippingRect.h = this.props.h * gt.td;
914
948
  clippingRect.valid = true;
915
949
  }
916
950
  else {
@@ -961,44 +995,23 @@ export class CoreNode extends EventEmitter {
961
995
  if (rtt === false || this.parentRenderTexture !== renderer.activeRttNode)
962
996
  return;
963
997
  }
964
- const p = this.props;
965
- const t = this.globalTransform;
966
- const coords = this.renderCoords;
967
- const texture = p.texture || this.stage.defaultTexture;
968
- const textureCoords = this.textureCoords || this.stage.renderer.defaultTextureCoords;
998
+ const texture = this.props.texture || this.stage.defaultTexture;
969
999
  // There is a race condition where the texture can be null
970
1000
  // with RTT nodes. Adding this defensively to avoid errors.
971
- if (texture && texture.state !== 'loaded') {
1001
+ // Also check if we have a valid texture or default texture to render
1002
+ if (!texture || texture.state !== 'loaded') {
972
1003
  return;
973
1004
  }
974
- renderer.addQuad({
975
- width: p.w,
976
- height: p.h,
977
- colorTl: this.premultipliedColorTl,
978
- colorTr: this.premultipliedColorTr,
979
- colorBl: this.premultipliedColorBl,
980
- colorBr: this.premultipliedColorBr,
981
- texture,
982
- textureOptions: p.textureOptions,
983
- textureCoords: textureCoords,
984
- shader: p.shader,
985
- alpha: this.worldAlpha,
986
- clippingRect: this.clippingRect,
987
- tx: t.tx,
988
- ty: t.ty,
989
- ta: t.ta,
990
- tb: t.tb,
991
- tc: t.tc,
992
- td: t.td,
993
- renderCoords: coords,
994
- rtt: p.rtt,
995
- zIndex: this.calcZIndex,
996
- parentHasRenderTexture: this.parentHasRenderTexture,
997
- framebufferDimensions: this.parentHasRenderTexture
998
- ? this.parentFramebufferDimensions
999
- : null,
1000
- time: this.hasShaderTimeFn === true ? this.getTimerValue() : null,
1001
- });
1005
+ renderer.addQuad(this);
1006
+ }
1007
+ get quadBufferCollection() {
1008
+ return this.stage.renderer.quadBufferCollection;
1009
+ }
1010
+ get time() {
1011
+ if (this.hasShaderTimeFn === true) {
1012
+ return this.getTimerValue();
1013
+ }
1014
+ return 0;
1002
1015
  }
1003
1016
  getTimerValue() {
1004
1017
  if (typeof this.shader.time === 'function') {
@@ -1045,10 +1058,14 @@ export class CoreNode extends EventEmitter {
1045
1058
  this.zIndexSortList = [];
1046
1059
  }
1047
1060
  removeChild(node, targetParent = null) {
1048
- if (targetParent === null &&
1049
- this.props.rtt === true &&
1050
- this.parentHasRenderTexture === true) {
1051
- node.clearRTTInheritance();
1061
+ if (targetParent === null) {
1062
+ if (this.props.rtt === true && this.parentHasRenderTexture === true) {
1063
+ node.clearRTTInheritance();
1064
+ }
1065
+ const autosizeTarget = this.autosizer || this.parentAutosizer;
1066
+ if (autosizeTarget !== null) {
1067
+ autosizeTarget.detach(node);
1068
+ }
1052
1069
  }
1053
1070
  removeChild(node, this.children);
1054
1071
  }
@@ -1058,6 +1075,8 @@ export class CoreNode extends EventEmitter {
1058
1075
  const min = this.zIndexMin;
1059
1076
  const max = this.zIndexMax;
1060
1077
  const zIndex = node.zIndex;
1078
+ const autosizeTarget = this.autosizer || this.parentAutosizer;
1079
+ let attachToAutosizer = autosizeTarget !== null;
1061
1080
  node.parentHasRenderTexture = inRttCluster;
1062
1081
  if (previousParent !== null) {
1063
1082
  const previousParentInRttCluster = previousParent.props.rtt === true ||
@@ -1066,6 +1085,18 @@ export class CoreNode extends EventEmitter {
1066
1085
  // update child RTT status
1067
1086
  node.clearRTTInheritance();
1068
1087
  }
1088
+ const previousAutosizer = node.autosizer || node.parentAutosizer;
1089
+ if (previousAutosizer !== null) {
1090
+ if (autosizeTarget === null ||
1091
+ previousAutosizer.id !== autosizeTarget.id) {
1092
+ previousAutosizer.detach(node);
1093
+ }
1094
+ attachToAutosizer = false;
1095
+ }
1096
+ }
1097
+ if (attachToAutosizer === true) {
1098
+ //if this is true, then the autosizer really exists
1099
+ autosizeTarget.attach(node);
1069
1100
  }
1070
1101
  if (inRttCluster === true) {
1071
1102
  node.markChildrenWithRTT(this);
@@ -1119,28 +1150,42 @@ export class CoreNode extends EventEmitter {
1119
1150
  return this.props.w;
1120
1151
  }
1121
1152
  set w(value) {
1122
- if (this.props.w !== value) {
1123
- this.props.w = value;
1124
- this.setUpdateType(UpdateType.Local);
1125
- if (this.props.rtt === true) {
1153
+ const props = this.props;
1154
+ if (props.w !== value) {
1155
+ props.w = value;
1156
+ let updateType = UpdateType.Local;
1157
+ if (props.texture !== null &&
1158
+ this.stage.calculateTextureCoord === true &&
1159
+ props.textureOptions !== null) {
1160
+ this.textureCoords = this.stage.renderer.getTextureCoords(this);
1161
+ }
1162
+ if (props.rtt === true) {
1126
1163
  this.framebufferDimensions.w = value;
1127
1164
  this.texture = this.stage.txManager.createTexture('RenderTexture', this.framebufferDimensions);
1128
- this.setUpdateType(UpdateType.RenderTexture);
1165
+ updateType |= UpdateType.RenderTexture;
1129
1166
  }
1167
+ this.setUpdateType(updateType);
1130
1168
  }
1131
1169
  }
1132
1170
  get h() {
1133
1171
  return this.props.h;
1134
1172
  }
1135
1173
  set h(value) {
1136
- if (this.props.h !== value) {
1137
- this.props.h = value;
1138
- this.setUpdateType(UpdateType.Local);
1139
- if (this.props.rtt === true) {
1174
+ const props = this.props;
1175
+ if (props.h !== value) {
1176
+ props.h = value;
1177
+ let updateType = UpdateType.Local;
1178
+ if (props.texture !== null &&
1179
+ this.stage.calculateTextureCoord === true &&
1180
+ props.textureOptions !== null) {
1181
+ this.textureCoords = this.stage.renderer.getTextureCoords(this);
1182
+ }
1183
+ if (props.rtt === true) {
1140
1184
  this.framebufferDimensions.h = value;
1141
1185
  this.texture = this.stage.txManager.createTexture('RenderTexture', this.framebufferDimensions);
1142
- this.setUpdateType(UpdateType.RenderTexture);
1186
+ updateType |= UpdateType.RenderTexture;
1143
1187
  }
1188
+ this.setUpdateType(updateType);
1144
1189
  }
1145
1190
  }
1146
1191
  get scale() {
@@ -1254,7 +1299,16 @@ export class CoreNode extends EventEmitter {
1254
1299
  return this.props.autosize;
1255
1300
  }
1256
1301
  set autosize(value) {
1302
+ if (this.props.autosize === value) {
1303
+ return;
1304
+ }
1257
1305
  this.props.autosize = value;
1306
+ if (value === true && this.autosizer === null) {
1307
+ this.autosizer = new Autosizer(this);
1308
+ }
1309
+ else {
1310
+ this.autosizer = null;
1311
+ }
1258
1312
  }
1259
1313
  get boundsMargin() {
1260
1314
  const props = this.props;
@@ -1600,7 +1654,7 @@ export class CoreNode extends EventEmitter {
1600
1654
  return this.rttParent.framebufferDimensions;
1601
1655
  }
1602
1656
  this.rttParent = this.findParentRTTNode();
1603
- return this.rttParent.framebufferDimensions;
1657
+ return this.rttParent ? this.rttParent.framebufferDimensions : null;
1604
1658
  }
1605
1659
  /**
1606
1660
  * Returns the parent render texture node if it exists.
@@ -1625,10 +1679,16 @@ export class CoreNode extends EventEmitter {
1625
1679
  const oldTexture = this.props.texture;
1626
1680
  if (oldTexture) {
1627
1681
  this.unloadTexture();
1682
+ if (this.autosizer !== null && value === null) {
1683
+ this.autosizer.setMode(AutosizeMode.Children); // Set to children size mode
1684
+ }
1628
1685
  }
1629
1686
  this.textureCoords = undefined;
1630
1687
  this.props.texture = value;
1631
1688
  if (value !== null) {
1689
+ if (this.autosizer !== null) {
1690
+ this.autosizer.setMode(AutosizeMode.Texture); // Set to texture size mode
1691
+ }
1632
1692
  value.setRenderableOwner(this._id, this.isRenderable);
1633
1693
  this.loadTexture();
1634
1694
  }
@@ -1665,5 +1725,55 @@ export class CoreNode extends EventEmitter {
1665
1725
  flush() {
1666
1726
  // no-op
1667
1727
  }
1728
+ /**
1729
+ * Add a texture to the current RenderOp.
1730
+ *
1731
+ * @param texture
1732
+ * @returns Assigned Texture Index of the texture in the render op
1733
+ */
1734
+ addTexture(texture) {
1735
+ const textures = this.renderOpTextures;
1736
+ const length = textures.length;
1737
+ for (let i = 0; i < length; i++) {
1738
+ if (textures[i] === texture) {
1739
+ return i;
1740
+ }
1741
+ }
1742
+ if (length >= 1) {
1743
+ return 0xffffffff;
1744
+ }
1745
+ textures.push(texture);
1746
+ return length;
1747
+ }
1748
+ draw(renderer) {
1749
+ const { glw, options, stage } = renderer;
1750
+ const shader = this.props.shader;
1751
+ stage.shManager.useShader(shader.program);
1752
+ shader.program.bindRenderOp(this);
1753
+ // Clipping
1754
+ if (this.clippingRect.valid === true) {
1755
+ const pixelRatio = this.parentHasRenderTexture ? 1 : stage.pixelRatio;
1756
+ const clipX = Math.round(this.clippingRect.x * pixelRatio);
1757
+ const clipWidth = Math.round(this.clippingRect.w * pixelRatio);
1758
+ const clipHeight = Math.round(this.clippingRect.h * pixelRatio);
1759
+ let clipY = Math.round(options.canvas.height - clipHeight - this.clippingRect.y * pixelRatio);
1760
+ // if parent has render texture, we need to adjust the scissor rect
1761
+ // to be relative to the parent's framebuffer
1762
+ if (this.parentHasRenderTexture) {
1763
+ const parentFramebufferDimensions = this.parentFramebufferDimensions;
1764
+ clipY =
1765
+ parentFramebufferDimensions !== null
1766
+ ? parentFramebufferDimensions.h - this.props.h
1767
+ : 0;
1768
+ }
1769
+ glw.setScissorTest(true);
1770
+ glw.scissor(clipX, clipY, clipWidth, clipHeight);
1771
+ }
1772
+ else {
1773
+ glw.setScissorTest(false);
1774
+ }
1775
+ const quadIdx = (this.renderOpBufferIdx / 32) * 6 * 2;
1776
+ glw.drawElements(glw.TRIANGLES, 6 * this.numQuads, glw.UNSIGNED_SHORT, quadIdx);
1777
+ }
1668
1778
  }
1669
1779
  //# sourceMappingURL=CoreNode.js.map