@lightningjs/renderer 2.1.1 → 2.2.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.
Files changed (194) hide show
  1. package/README.md +1 -4
  2. package/dist/exports/core-api.d.ts +74 -0
  3. package/dist/exports/core-api.js +96 -0
  4. package/dist/exports/core-api.js.map +1 -0
  5. package/dist/exports/index.d.ts +1 -0
  6. package/dist/exports/index.js +1 -0
  7. package/dist/exports/index.js.map +1 -1
  8. package/dist/exports/main-api.d.ts +30 -0
  9. package/dist/exports/main-api.js +45 -0
  10. package/dist/exports/main-api.js.map +1 -0
  11. package/dist/src/core/CoreExtension.d.ts +12 -0
  12. package/dist/src/core/CoreExtension.js +29 -0
  13. package/dist/src/core/CoreExtension.js.map +1 -0
  14. package/dist/src/core/CoreNode.d.ts +2 -2
  15. package/dist/src/core/CoreNode.js +57 -47
  16. package/dist/src/core/CoreNode.js.map +1 -1
  17. package/dist/src/core/CoreShaderManager.js +1 -0
  18. package/dist/src/core/CoreShaderManager.js.map +1 -1
  19. package/dist/src/core/Matrix2DContext.d.ts +15 -0
  20. package/dist/src/core/Matrix2DContext.js +45 -0
  21. package/dist/src/core/Matrix2DContext.js.map +1 -0
  22. package/dist/src/core/lib/SpatialHash.d.ts +38 -0
  23. package/dist/src/core/lib/SpatialHash.js +93 -0
  24. package/dist/src/core/lib/SpatialHash.js.map +1 -0
  25. package/dist/src/core/lib/WebGlContextWrapper.d.ts +144 -2
  26. package/dist/src/core/lib/WebGlContextWrapper.js +211 -20
  27. package/dist/src/core/lib/WebGlContextWrapper.js.map +1 -1
  28. package/dist/src/core/lib/glm/common.d.ts +162 -0
  29. package/dist/src/core/lib/glm/common.js +81 -0
  30. package/dist/src/core/lib/glm/common.js.map +1 -0
  31. package/dist/src/core/lib/glm/index.d.ts +11 -0
  32. package/dist/src/core/lib/glm/index.js +30 -0
  33. package/dist/src/core/lib/glm/index.js.map +1 -0
  34. package/dist/src/core/lib/glm/mat2.d.ts +219 -0
  35. package/dist/src/core/lib/glm/mat2.js +396 -0
  36. package/dist/src/core/lib/glm/mat2.js.map +1 -0
  37. package/dist/src/core/lib/glm/mat2d.d.ts +237 -0
  38. package/dist/src/core/lib/glm/mat2d.js +442 -0
  39. package/dist/src/core/lib/glm/mat2d.js.map +1 -0
  40. package/dist/src/core/lib/glm/mat3.d.ts +283 -0
  41. package/dist/src/core/lib/glm/mat3.js +680 -0
  42. package/dist/src/core/lib/glm/mat3.js.map +1 -0
  43. package/dist/src/core/lib/glm/mat4.d.ts +550 -0
  44. package/dist/src/core/lib/glm/mat4.js +1802 -0
  45. package/dist/src/core/lib/glm/mat4.js.map +1 -0
  46. package/dist/src/core/lib/glm/quat.d.ts +363 -0
  47. package/dist/src/core/lib/glm/quat.js +693 -0
  48. package/dist/src/core/lib/glm/quat.js.map +1 -0
  49. package/dist/src/core/lib/glm/quat2.d.ts +356 -0
  50. package/dist/src/core/lib/glm/quat2.js +754 -0
  51. package/dist/src/core/lib/glm/quat2.js.map +1 -0
  52. package/dist/src/core/lib/glm/vec2.d.ts +365 -0
  53. package/dist/src/core/lib/glm/vec2.js +569 -0
  54. package/dist/src/core/lib/glm/vec2.js.map +1 -0
  55. package/dist/src/core/lib/glm/vec3.d.ts +406 -0
  56. package/dist/src/core/lib/glm/vec3.js +720 -0
  57. package/dist/src/core/lib/glm/vec3.js.map +1 -0
  58. package/dist/src/core/lib/glm/vec4.d.ts +330 -0
  59. package/dist/src/core/lib/glm/vec4.js +608 -0
  60. package/dist/src/core/lib/glm/vec4.js.map +1 -0
  61. package/dist/src/core/lib/renderToTexture.d.ts +1 -0
  62. package/dist/src/core/lib/renderToTexture.js +2 -0
  63. package/dist/src/core/lib/renderToTexture.js.map +1 -0
  64. package/dist/src/core/lib/textcompression-utils.d.ts +1 -0
  65. package/dist/src/core/lib/textcompression-utils.js +2 -0
  66. package/dist/src/core/lib/textcompression-utils.js.map +1 -0
  67. package/dist/src/core/lib/txcompression-utils.d.ts +1 -0
  68. package/dist/src/core/lib/txcompression-utils.js +2 -0
  69. package/dist/src/core/lib/txcompression-utils.js.map +1 -0
  70. package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js +3 -2
  71. package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js.map +1 -1
  72. package/dist/src/core/renderers/webgl/WebGlCoreShader.d.ts +1 -1
  73. package/dist/src/core/renderers/webgl/WebGlCoreShader.js +8 -9
  74. package/dist/src/core/renderers/webgl/WebGlCoreShader.js.map +1 -1
  75. package/dist/src/core/renderers/webgl/WebGlRenderTexture.d.ts +29 -0
  76. package/dist/src/core/renderers/webgl/WebGlRenderTexture.js +86 -0
  77. package/dist/src/core/renderers/webgl/WebGlRenderTexture.js.map +1 -0
  78. package/dist/src/core/renderers/webgl/shaders/DefaultShaderBatched.js +1 -1
  79. package/dist/src/core/renderers/webgl/shaders/DefaultShaderBatched.js.map +1 -1
  80. package/dist/src/core/renderers/webgl/shaders/DistortShader.d.ts +44 -0
  81. package/dist/src/core/renderers/webgl/shaders/DistortShader.js +172 -0
  82. package/dist/src/core/renderers/webgl/shaders/DistortShader.js.map +1 -0
  83. package/dist/src/core/renderers/webgl/shaders/DynamicShader.d.ts +2 -1
  84. package/dist/src/core/renderers/webgl/shaders/DynamicShader.js +55 -2
  85. package/dist/src/core/renderers/webgl/shaders/DynamicShader.js.map +1 -1
  86. package/dist/src/core/renderers/webgl/shaders/RefractionShader.d.ts +78 -0
  87. package/dist/src/core/renderers/webgl/shaders/RefractionShader.js +172 -0
  88. package/dist/src/core/renderers/webgl/shaders/RefractionShader.js.map +1 -0
  89. package/dist/src/core/renderers/webgl/shaders/RoundedRectangle.js +1 -1
  90. package/dist/src/core/renderers/webgl/shaders/RoundedRectangle.js.map +1 -1
  91. package/dist/src/core/renderers/webgl/shaders/SdfShader.js +6 -6
  92. package/dist/src/core/renderers/webgl/shaders/SdfShader.js.map +1 -1
  93. package/dist/src/core/renderers/webgl/shaders/effects/ShaderEffect.d.ts +2 -0
  94. package/dist/src/core/renderers/webgl/shaders/effects/ShaderEffect.js.map +1 -1
  95. package/dist/src/core/scene/Scene.d.ts +59 -0
  96. package/dist/src/core/scene/Scene.js +106 -0
  97. package/dist/src/core/scene/Scene.js.map +1 -0
  98. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.d.ts +20 -0
  99. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.js +55 -0
  100. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.js.map +1 -0
  101. package/dist/src/core/text-rendering/renderers/TextRenderer.js +12 -9
  102. package/dist/src/core/text-rendering/renderers/TextRenderer.js.map +1 -1
  103. package/dist/src/main-api/ICoreDriver.d.ts +24 -0
  104. package/dist/src/main-api/ICoreDriver.js +20 -0
  105. package/dist/src/main-api/ICoreDriver.js.map +1 -0
  106. package/dist/src/main-api/IRenderDriver.d.ts +20 -0
  107. package/dist/src/main-api/IRenderDriver.js +20 -0
  108. package/dist/src/main-api/IRenderDriver.js.map +1 -0
  109. package/dist/src/main-api/IShaderController.d.ts +14 -0
  110. package/dist/src/main-api/IShaderController.js +30 -0
  111. package/dist/src/main-api/IShaderController.js.map +1 -0
  112. package/dist/src/main-api/RendererMain.d.ts +378 -0
  113. package/dist/src/main-api/RendererMain.js +367 -0
  114. package/dist/src/main-api/RendererMain.js.map +1 -0
  115. package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.d.ts +9 -0
  116. package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.js +38 -0
  117. package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.js.map +1 -0
  118. package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.d.ts +56 -0
  119. package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.js +101 -0
  120. package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.js.map +1 -0
  121. package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.d.ts +32 -0
  122. package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.js +28 -0
  123. package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.js.map +1 -0
  124. package/dist/src/render-drivers/main/MainCoreDriver.d.ts +21 -0
  125. package/dist/src/render-drivers/main/MainCoreDriver.js +115 -0
  126. package/dist/src/render-drivers/main/MainCoreDriver.js.map +1 -0
  127. package/dist/src/render-drivers/main/MainOnlyNode.d.ts +101 -0
  128. package/dist/src/render-drivers/main/MainOnlyNode.js +425 -0
  129. package/dist/src/render-drivers/main/MainOnlyNode.js.map +1 -0
  130. package/dist/src/render-drivers/main/MainOnlyShaderController.d.ts +6 -0
  131. package/dist/src/render-drivers/main/MainOnlyShaderController.js +15 -0
  132. package/dist/src/render-drivers/main/MainOnlyShaderController.js.map +1 -0
  133. package/dist/src/render-drivers/main/MainOnlyTextNode.d.ts +47 -0
  134. package/dist/src/render-drivers/main/MainOnlyTextNode.js +204 -0
  135. package/dist/src/render-drivers/main/MainOnlyTextNode.js.map +1 -0
  136. package/dist/src/render-drivers/main/MainRenderDriver.d.ts +17 -0
  137. package/dist/src/render-drivers/main/MainRenderDriver.js +88 -0
  138. package/dist/src/render-drivers/main/MainRenderDriver.js.map +1 -0
  139. package/dist/src/render-drivers/threadx/NodeStruct.d.ts +93 -0
  140. package/dist/src/render-drivers/threadx/NodeStruct.js +290 -0
  141. package/dist/src/render-drivers/threadx/NodeStruct.js.map +1 -0
  142. package/dist/src/render-drivers/threadx/SharedNode.d.ts +40 -0
  143. package/dist/src/render-drivers/threadx/SharedNode.js +61 -0
  144. package/dist/src/render-drivers/threadx/SharedNode.js.map +1 -0
  145. package/dist/src/render-drivers/threadx/TextNodeStruct.d.ts +44 -0
  146. package/dist/src/render-drivers/threadx/TextNodeStruct.js +203 -0
  147. package/dist/src/render-drivers/threadx/TextNodeStruct.js.map +1 -0
  148. package/dist/src/render-drivers/threadx/ThreadXCoreDriver.d.ts +25 -0
  149. package/dist/src/render-drivers/threadx/ThreadXCoreDriver.js +232 -0
  150. package/dist/src/render-drivers/threadx/ThreadXCoreDriver.js.map +1 -0
  151. package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.d.ts +20 -0
  152. package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.js +84 -0
  153. package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.js.map +1 -0
  154. package/dist/src/render-drivers/threadx/ThreadXMainNode.d.ts +46 -0
  155. package/dist/src/render-drivers/threadx/ThreadXMainNode.js +160 -0
  156. package/dist/src/render-drivers/threadx/ThreadXMainNode.js.map +1 -0
  157. package/dist/src/render-drivers/threadx/ThreadXMainShaderController.d.ts +6 -0
  158. package/dist/src/render-drivers/threadx/ThreadXMainShaderController.js +15 -0
  159. package/dist/src/render-drivers/threadx/ThreadXMainShaderController.js.map +1 -0
  160. package/dist/src/render-drivers/threadx/ThreadXMainTextNode.d.ts +28 -0
  161. package/dist/src/render-drivers/threadx/ThreadXMainTextNode.js +55 -0
  162. package/dist/src/render-drivers/threadx/ThreadXMainTextNode.js.map +1 -0
  163. package/dist/src/render-drivers/threadx/ThreadXRenderDriver.d.ts +21 -0
  164. package/dist/src/render-drivers/threadx/ThreadXRenderDriver.js +198 -0
  165. package/dist/src/render-drivers/threadx/ThreadXRenderDriver.js.map +1 -0
  166. package/dist/src/render-drivers/threadx/ThreadXRendererMessage.d.ts +70 -0
  167. package/dist/src/render-drivers/threadx/ThreadXRendererMessage.js +32 -0
  168. package/dist/src/render-drivers/threadx/ThreadXRendererMessage.js.map +1 -0
  169. package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.d.ts +19 -0
  170. package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.js +178 -0
  171. package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.js.map +1 -0
  172. package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.d.ts +27 -0
  173. package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.js +109 -0
  174. package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.js.map +1 -0
  175. package/dist/src/render-drivers/threadx/worker/renderer.d.ts +1 -0
  176. package/dist/src/render-drivers/threadx/worker/renderer.js +147 -0
  177. package/dist/src/render-drivers/threadx/worker/renderer.js.map +1 -0
  178. package/dist/src/render-drivers/utils.d.ts +12 -0
  179. package/dist/src/render-drivers/utils.js +69 -0
  180. package/dist/src/render-drivers/utils.js.map +1 -0
  181. package/dist/tsconfig.dist.tsbuildinfo +1 -1
  182. package/exports/index.ts +1 -0
  183. package/package.json +1 -1
  184. package/src/core/CoreNode.ts +69 -54
  185. package/src/core/CoreShaderManager.ts +1 -0
  186. package/src/core/lib/WebGlContextWrapper.ts +288 -26
  187. package/src/core/renderers/webgl/WebGlCoreRenderer.ts +3 -2
  188. package/src/core/renderers/webgl/WebGlCoreShader.ts +21 -17
  189. package/src/core/renderers/webgl/shaders/DefaultShaderBatched.ts +1 -1
  190. package/src/core/renderers/webgl/shaders/DynamicShader.ts +75 -3
  191. package/src/core/renderers/webgl/shaders/RoundedRectangle.ts +4 -1
  192. package/src/core/renderers/webgl/shaders/SdfShader.ts +21 -6
  193. package/src/core/renderers/webgl/shaders/effects/ShaderEffect.ts +3 -0
  194. package/src/core/text-rendering/renderers/TextRenderer.ts +18 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightningjs/renderer",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "description": "Lightning 3 Renderer",
5
5
  "type": "module",
6
6
  "main": "./dist/exports/index.js",
@@ -192,7 +192,7 @@ export enum UpdateType {
192
192
  /**
193
193
  * All
194
194
  */
195
- All = 8191,
195
+ All = 14335,
196
196
  }
197
197
 
198
198
  /**
@@ -852,10 +852,15 @@ export class CoreNode extends EventEmitter {
852
852
  if (parent !== null && !(parent.updateType & UpdateType.Children)) {
853
853
  parent.setUpdateType(UpdateType.Children);
854
854
  }
855
+
855
856
  // If node is part of RTT texture
856
857
  // Flag that we need to update
857
858
  if (this.parentHasRenderTexture) {
858
859
  this.setRTTUpdates(type);
860
+
861
+ if (parent !== null) {
862
+ parent.setUpdateType(UpdateType.RenderTexture);
863
+ }
859
864
  }
860
865
  }
861
866
 
@@ -959,6 +964,7 @@ export class CoreNode extends EventEmitter {
959
964
  }
960
965
 
961
966
  const parent = this.props.parent;
967
+ let renderState = null;
962
968
 
963
969
  if (this.updateType & UpdateType.ParentRenderTexture) {
964
970
  let p = this.parent;
@@ -975,9 +981,9 @@ export class CoreNode extends EventEmitter {
975
981
  this.updateType ^ UpdateType.All &&
976
982
  this.updateType & UpdateType.RenderTexture
977
983
  ) {
978
- this.children.forEach((child) => {
979
- child.setUpdateType(UpdateType.All);
980
- });
984
+ for (let i = 0, length = this.children.length; i < length; i++) {
985
+ this.children[i]?.setUpdateType(UpdateType.All);
986
+ }
981
987
  }
982
988
 
983
989
  if (this.updateType & UpdateType.Global) {
@@ -1015,8 +1021,29 @@ export class CoreNode extends EventEmitter {
1015
1021
  }
1016
1022
 
1017
1023
  if (this.updateType & UpdateType.RenderState) {
1018
- this.updateRenderState();
1024
+ renderState = this.checkRenderBounds();
1019
1025
  this.setUpdateType(UpdateType.IsRenderable);
1026
+
1027
+ // if we're not going out of bounds, update the render state
1028
+ // this is done so the update loop can finish before we mark a node
1029
+ // as out of bounds
1030
+ if (renderState !== CoreNodeRenderState.OutOfBounds) {
1031
+ this.updateRenderState(renderState);
1032
+ }
1033
+ }
1034
+
1035
+ if (this.updateType & UpdateType.WorldAlpha) {
1036
+ if (parent) {
1037
+ this.worldAlpha = parent.worldAlpha * this.props.alpha;
1038
+ } else {
1039
+ this.worldAlpha = this.props.alpha;
1040
+ }
1041
+ this.setUpdateType(
1042
+ UpdateType.Children |
1043
+ UpdateType.PremultipliedColors |
1044
+ UpdateType.IsRenderable,
1045
+ );
1046
+ this.childUpdateType |= UpdateType.WorldAlpha;
1020
1047
  }
1021
1048
 
1022
1049
  if (this.updateType & UpdateType.IsRenderable) {
@@ -1035,20 +1062,6 @@ export class CoreNode extends EventEmitter {
1035
1062
  this.childUpdateType |= UpdateType.RenderBounds;
1036
1063
  }
1037
1064
 
1038
- if (this.updateType & UpdateType.WorldAlpha) {
1039
- if (parent) {
1040
- this.worldAlpha = parent.worldAlpha * this.props.alpha;
1041
- } else {
1042
- this.worldAlpha = this.props.alpha;
1043
- }
1044
- this.setUpdateType(
1045
- UpdateType.Children |
1046
- UpdateType.PremultipliedColors |
1047
- UpdateType.IsRenderable,
1048
- );
1049
- this.childUpdateType |= UpdateType.WorldAlpha;
1050
- }
1051
-
1052
1065
  if (this.updateType & UpdateType.PremultipliedColors) {
1053
1066
  this.premultipliedColorTl = mergeColorAlphaPremultiplied(
1054
1067
  this.props.colorTl,
@@ -1097,11 +1110,8 @@ export class CoreNode extends EventEmitter {
1097
1110
  this.children.length > 0 &&
1098
1111
  this.rtt === false
1099
1112
  ) {
1100
- for (let i = 0; i < this.children.length; i++) {
1101
- const child = this.children[i];
1102
- if (child === undefined) {
1103
- continue;
1104
- }
1113
+ for (let i = 0, length = this.children.length; i < length; i++) {
1114
+ const child = this.children[i] as CoreNode;
1105
1115
 
1106
1116
  child.setUpdateType(this.childUpdateType);
1107
1117
 
@@ -1120,6 +1130,13 @@ export class CoreNode extends EventEmitter {
1120
1130
  this.sortChildren();
1121
1131
  }
1122
1132
 
1133
+ // If we're out of bounds, apply the render state now
1134
+ // this is done so nodes can finish their entire update loop before
1135
+ // being marked as out of bounds
1136
+ if (renderState === CoreNodeRenderState.OutOfBounds) {
1137
+ this.updateRenderState(renderState);
1138
+ }
1139
+
1123
1140
  // reset update type
1124
1141
  this.updateType = 0;
1125
1142
  this.childUpdateType = 0;
@@ -1219,7 +1236,6 @@ export class CoreNode extends EventEmitter {
1219
1236
  strictBound.y1 - renderM[0],
1220
1237
  strictBound.x2 + renderM[1],
1221
1238
  strictBound.y2 + renderM[2],
1222
- this.preloadBound,
1223
1239
  );
1224
1240
  }
1225
1241
 
@@ -1249,16 +1265,19 @@ export class CoreNode extends EventEmitter {
1249
1265
 
1250
1266
  // no clipping, use parent's bounds
1251
1267
  if (this.clipping === false) {
1252
- if (this.parent !== null) {
1253
- this.strictBound =
1254
- this.parent.strictBound ??
1255
- createBound(0, 0, this.stage.root.width, this.stage.root.height);
1256
-
1257
- this.preloadBound =
1258
- this.parent.preloadBound ??
1259
- this.createPreloadBounds(this.strictBound);
1268
+ if (this.parent !== null && this.parent.strictBound !== undefined) {
1269
+ // we have a parent with a valid bound, copy it
1270
+ this.strictBound = createBound(
1271
+ this.parent.strictBound.x1,
1272
+ this.parent.strictBound.y1,
1273
+ this.parent.strictBound.x2,
1274
+ this.parent.strictBound.y2,
1275
+ );
1276
+
1277
+ this.preloadBound = this.createPreloadBounds(this.strictBound);
1260
1278
  return;
1261
1279
  } else {
1280
+ // no parent or parent does not have a bound, take the stage dimensions
1262
1281
  this.strictBound = createBound(
1263
1282
  0,
1264
1283
  0,
@@ -1287,9 +1306,7 @@ export class CoreNode extends EventEmitter {
1287
1306
  this.preloadBound = this.createPreloadBounds(this.strictBound);
1288
1307
  }
1289
1308
 
1290
- updateRenderState() {
1291
- const renderState = this.checkRenderBounds();
1292
-
1309
+ updateRenderState(renderState: CoreNodeRenderState) {
1293
1310
  if (renderState === this.renderState) {
1294
1311
  return;
1295
1312
  }
@@ -1439,8 +1456,7 @@ export class CoreNode extends EventEmitter {
1439
1456
  this.props.shader = this.stage.defShaderCtr;
1440
1457
 
1441
1458
  const children = [...this.children];
1442
- for (let i = 0; i < children.length; i++) {
1443
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1459
+ for (let i = 0, length = children.length; i < length; i++) {
1444
1460
  children[i]!.destroy();
1445
1461
  }
1446
1462
  // This very action will also remove the node from the parent's children array
@@ -1730,9 +1746,10 @@ export class CoreNode extends EventEmitter {
1730
1746
  this.setUpdateType(
1731
1747
  UpdateType.PremultipliedColors |
1732
1748
  UpdateType.WorldAlpha |
1733
- UpdateType.Children,
1749
+ UpdateType.Children |
1750
+ UpdateType.IsRenderable,
1734
1751
  );
1735
- this.childUpdateType |= UpdateType.Global;
1752
+ this.childUpdateType |= UpdateType.WorldAlpha;
1736
1753
  }
1737
1754
 
1738
1755
  get autosize(): boolean {
@@ -1866,9 +1883,9 @@ export class CoreNode extends EventEmitter {
1866
1883
  set zIndexLocked(value: number) {
1867
1884
  this.props.zIndexLocked = value;
1868
1885
  this.setUpdateType(UpdateType.CalculatedZIndex | UpdateType.Children);
1869
- this.children.forEach((child) => {
1870
- child.setUpdateType(UpdateType.CalculatedZIndex);
1871
- });
1886
+ for (let i = 0, length = this.children.length; i < length; i++) {
1887
+ this.children[i]!.setUpdateType(UpdateType.CalculatedZIndex);
1888
+ }
1872
1889
  }
1873
1890
 
1874
1891
  get zIndex(): number {
@@ -1878,9 +1895,9 @@ export class CoreNode extends EventEmitter {
1878
1895
  set zIndex(value: number) {
1879
1896
  this.props.zIndex = value;
1880
1897
  this.setUpdateType(UpdateType.CalculatedZIndex | UpdateType.Children);
1881
- this.children.forEach((child) => {
1882
- child.setUpdateType(UpdateType.CalculatedZIndex);
1883
- });
1898
+ for (let i = 0, length = this.children.length; i < length; i++) {
1899
+ this.children[i]!.setUpdateType(UpdateType.CalculatedZIndex);
1900
+ }
1884
1901
  }
1885
1902
 
1886
1903
  get parent(): CoreNode | null {
@@ -1943,11 +1960,9 @@ export class CoreNode extends EventEmitter {
1943
1960
  if (value === false && this.texture !== null) {
1944
1961
  this.unloadTexture();
1945
1962
  this.setUpdateType(UpdateType.All);
1946
-
1947
- this.children.forEach((child) => {
1948
- child.parentHasRenderTexture = false;
1949
- });
1950
-
1963
+ for (let i = 0, length = this.children.length; i < length; i++) {
1964
+ this.children[i]!.parentHasRenderTexture = false;
1965
+ }
1951
1966
  this.stage.renderer?.removeRTTNode(this);
1952
1967
  return;
1953
1968
  }
@@ -1969,9 +1984,9 @@ export class CoreNode extends EventEmitter {
1969
1984
  this.hasRTTupdates = true;
1970
1985
  this.setUpdateType(UpdateType.All);
1971
1986
 
1972
- this.children.forEach((child) => {
1973
- child.setUpdateType(UpdateType.All);
1974
- });
1987
+ for (let i = 0, length = this.children.length; i < length; i++) {
1988
+ this.children[i]!.setUpdateType(UpdateType.All);
1989
+ }
1975
1990
 
1976
1991
  // Store RTT nodes in a separate list
1977
1992
  this.stage.renderer?.renderToTexture(this);
@@ -275,6 +275,7 @@ export class CoreShaderManager {
275
275
  shader: InstanceType<ShaderMap['DynamicShader']>,
276
276
  props: ExtractProps<ShaderMap['DynamicShader']>,
277
277
  ): DynamicShaderController<T> {
278
+ shader.bindUniformMethods(props);
278
279
  return new DynamicShaderController(shader, props, this);
279
280
  }
280
281
 
@@ -45,10 +45,6 @@ export class WebGlContextWrapper {
45
45
  private boundArrayBuffer: WebGLBuffer | null;
46
46
  private boundElementArrayBuffer: WebGLBuffer | null;
47
47
  private curProgram: WebGLProgram | null;
48
- private programUniforms: WeakMap<
49
- WebGLProgram,
50
- Map<WebGLUniformLocation, any[]>
51
- > = new WeakMap();
52
48
  //#endregion Cached WebGL State
53
49
 
54
50
  //#region Canvas
@@ -708,22 +704,279 @@ export class WebGlContextWrapper {
708
704
  this.curProgram = program;
709
705
  }
710
706
 
711
- setUniform<T extends keyof UniformMethodMap>(
712
- type: T,
713
- location: WebGLUniformLocation,
714
- ...args: UniformMethodMap[T]
707
+ /**
708
+ * Sets the value of a single float uniform variable.
709
+ *
710
+ * @param location - The location of the uniform variable.
711
+ * @param v0 - The value to set.
712
+ */
713
+ uniform1f(location: WebGLUniformLocation | null, v0: number) {
714
+ const { gl } = this;
715
+ gl.uniform1f(location, v0);
716
+ }
717
+
718
+ /**
719
+ * Sets the value of a float array uniform variable.
720
+ *
721
+ * @param location - The location of the uniform variable.
722
+ * @param value - The array of values to set.
723
+ */
724
+ uniform1fv(
725
+ location: WebGLUniformLocation | null,
726
+ value: Float32Array | number[],
715
727
  ) {
716
- const { gl, programUniforms } = this;
717
- let uniforms = programUniforms.get(this.curProgram!);
718
- if (!uniforms) {
719
- uniforms = new Map();
720
- programUniforms.set(this.curProgram!, uniforms);
721
- }
722
- const uniformArgs = uniforms.get(location);
723
- if (!uniformArgs || !compareArrays(uniformArgs, args)) {
724
- uniforms.set(location, args);
725
- gl[type](location, ...(args as [never, never, never, never]));
726
- }
728
+ const { gl } = this;
729
+ gl.uniform1fv(location, value);
730
+ }
731
+
732
+ /**
733
+ * Sets the value of a single integer uniform variable.
734
+ *
735
+ * @param location - The location of the uniform variable.
736
+ * @param v0 - The value to set.
737
+ */
738
+ uniform1i(location: WebGLUniformLocation | null, v0: number) {
739
+ const { gl } = this;
740
+ gl.uniform1i(location, v0);
741
+ }
742
+
743
+ /**
744
+ * Sets the value of an integer array uniform variable.
745
+ *
746
+ * @param location - The location of the uniform variable.
747
+ * @param value - The array of values to set.
748
+ */
749
+ uniform1iv(
750
+ location: WebGLUniformLocation | null,
751
+ value: Int32Array | number[],
752
+ ) {
753
+ const { gl } = this;
754
+ gl.uniform1iv(location, value);
755
+ }
756
+
757
+ /**
758
+ * Sets the value of a vec2 uniform variable.
759
+ *
760
+ * @param location - The location of the uniform variable.
761
+ * @param v0 - The first component of the vector.
762
+ * @param v1 - The second component of the vector.
763
+ */
764
+ uniform2f(location: WebGLUniformLocation | null, v0: number, v1: number) {
765
+ const { gl } = this;
766
+ gl.uniform2f(location, v0, v1);
767
+ }
768
+
769
+ /**
770
+ * Sets the value of a vec2 array uniform variable.
771
+ *
772
+ * @param location - The location of the uniform variable.
773
+ * @param value - The array of vec2 values to set.
774
+ */
775
+ uniform2fv(
776
+ location: WebGLUniformLocation | null,
777
+ value: Float32Array | number[],
778
+ ) {
779
+ const { gl } = this;
780
+ gl.uniform2fv(location, value);
781
+ }
782
+
783
+ /**
784
+ * Sets the value of a ivec2 uniform variable.
785
+ *
786
+ * @param location - The location of the uniform variable.
787
+ * @param v0 - The first component of the vector.
788
+ * @param v1 - The second component of the vector.
789
+ */
790
+ uniform2i(location: WebGLUniformLocation | null, v0: number, v1: number) {
791
+ const { gl } = this;
792
+ gl.uniform2i(location, v0, v1);
793
+ }
794
+
795
+ /**
796
+ * Sets the value of an ivec2 array uniform variable.
797
+ *
798
+ * @param location - The location of the uniform variable.
799
+ * @param value - The array of ivec2 values to set.
800
+ */
801
+ uniform2iv(
802
+ location: WebGLUniformLocation | null,
803
+ value: Int32Array | number[],
804
+ ) {
805
+ const { gl } = this;
806
+ gl.uniform2iv(location, value);
807
+ }
808
+
809
+ /**
810
+ * Sets the value of a vec3 uniform variable.
811
+ *
812
+ * @param location - The location of the uniform variable.
813
+ * @param v0 - The first component of the vector.
814
+ * @param v1 - The second component of the vector.
815
+ * @param v2 - The third component of the vector.
816
+ */
817
+ uniform3f(
818
+ location: WebGLUniformLocation | null,
819
+ v0: number,
820
+ v1: number,
821
+ v2: number,
822
+ ) {
823
+ const { gl } = this;
824
+ gl.uniform3f(location, v0, v1, v2);
825
+ }
826
+
827
+ /**
828
+ * Sets the value of a vec3 array uniform variable.
829
+ *
830
+ * @param location - The location of the uniform variable.
831
+ * @param value - The array of vec3 values to set.
832
+ */
833
+ uniform3fv(
834
+ location: WebGLUniformLocation | null,
835
+ value: Float32Array | number[],
836
+ ) {
837
+ const { gl } = this;
838
+ gl.uniform3fv(location, value);
839
+ }
840
+
841
+ /**
842
+ * Sets the value of a ivec3 uniform variable.
843
+ *
844
+ * @param location - The location of the uniform variable.
845
+ * @param v0 - The first component of the vector.
846
+ * @param v1 - The second component of the vector.
847
+ * @param v2 - The third component of the vector.
848
+ */
849
+ uniform3i(
850
+ location: WebGLUniformLocation | null,
851
+ v0: number,
852
+ v1: number,
853
+ v2: number,
854
+ ) {
855
+ const { gl } = this;
856
+ gl.uniform3i(location, v0, v1, v2);
857
+ }
858
+
859
+ /**
860
+ * Sets the value of an ivec3 array uniform variable.
861
+ *
862
+ * @param location - The location of the uniform variable.
863
+ * @param value - The array of ivec3 values to set.
864
+ */
865
+ uniform3iv(
866
+ location: WebGLUniformLocation | null,
867
+ value: Int32Array | number[],
868
+ ) {
869
+ const { gl } = this;
870
+ gl.uniform3iv(location, value);
871
+ }
872
+
873
+ /**
874
+ * Sets the value of a vec4 uniform variable.
875
+ *
876
+ * @param location - The location of the uniform variable.
877
+ * @param v0 - The first component of the vector.
878
+ * @param v1 - The second component of the vector.
879
+ * @param v2 - The third component of the vector.
880
+ * @param v3 - The fourth component of the vector.
881
+ */
882
+ uniform4f(
883
+ location: WebGLUniformLocation | null,
884
+ v0: number,
885
+ v1: number,
886
+ v2: number,
887
+ v3: number,
888
+ ) {
889
+ const { gl } = this;
890
+ gl.uniform4f(location, v0, v1, v2, v3);
891
+ }
892
+
893
+ /**
894
+ * Sets the value of a vec4 array uniform variable.
895
+ *
896
+ * @param location - The location of the uniform variable.
897
+ * @param value - The array of vec4 values to set.
898
+ */
899
+ uniform4fv(
900
+ location: WebGLUniformLocation | null,
901
+ value: Float32Array | number[],
902
+ ) {
903
+ const { gl } = this;
904
+ gl.uniform4fv(location, value);
905
+ }
906
+
907
+ /**
908
+ * Sets the value of a ivec4 uniform variable.
909
+ *
910
+ * @param location - The location of the uniform variable.
911
+ * @param v0 - The first component of the vector.
912
+ * @param v1 - The second component of the vector.
913
+ * @param v2 - The third component of the vector.
914
+ * @param v3 - The fourth component of the vector.
915
+ */
916
+ uniform4i(
917
+ location: WebGLUniformLocation | null,
918
+ v0: number,
919
+ v1: number,
920
+ v2: number,
921
+ v3: number,
922
+ ) {
923
+ const { gl } = this;
924
+ gl.uniform4i(location, v0, v1, v2, v3);
925
+ }
926
+
927
+ /**
928
+ * Sets the value of an ivec4 array uniform variable.
929
+ *
930
+ * @param location - The location of the uniform variable.
931
+ * @param value - The array of ivec4 values to set.
932
+ */
933
+ uniform4iv(
934
+ location: WebGLUniformLocation | null,
935
+ value: Int32Array | number[],
936
+ ) {
937
+ const { gl } = this;
938
+ gl.uniform4iv(location, value);
939
+ }
940
+
941
+ /**
942
+ * Sets the value of a mat2 uniform variable.
943
+ *
944
+ * @param location - The location of the uniform variable.
945
+ * @param transpose - Whether to transpose the matrix.
946
+ * @param value - The array of mat2 values to set.
947
+ */
948
+ uniformMatrix2fv(
949
+ location: WebGLUniformLocation | null,
950
+ value: Float32Array | number[],
951
+ ) {
952
+ const { gl } = this;
953
+ gl.uniformMatrix2fv(location, false, value);
954
+ }
955
+
956
+ /**
957
+ * Sets the value of a mat2 uniform variable.
958
+ * @param location - The location of the uniform variable.
959
+ * @param value - The array of mat2 values to set.
960
+ */
961
+ uniformMatrix3fv(
962
+ location: WebGLUniformLocation | null,
963
+ value: Float32Array | number[],
964
+ ) {
965
+ const { gl } = this;
966
+ gl.uniformMatrix3fv(location, false, value);
967
+ }
968
+
969
+ /**
970
+ * Sets the value of a mat4 uniform variable.
971
+ * @param location - The location of the uniform variable.
972
+ * @param value - The array of mat4 values to set.
973
+ */
974
+ uniformMatrix4fv(
975
+ location: WebGLUniformLocation | null,
976
+ value: Float32Array | number[],
977
+ ) {
978
+ const { gl } = this;
979
+ gl.uniformMatrix4fv(location, false, value);
727
980
  }
728
981
 
729
982
  /**
@@ -1031,12 +1284,21 @@ export function compareArrays<T>(a: T[], b: T[]): boolean {
1031
1284
  if (a.length !== b.length) {
1032
1285
  return false;
1033
1286
  }
1034
- return a.every((v, i) => {
1035
- // Don't bother to compare nested arrays or Float32Arrays
1036
- if (Array.isArray(v) || v instanceof Float32Array) {
1037
- return false;
1038
- } else {
1039
- return v === b[i];
1287
+
1288
+ let result = false;
1289
+ for (let i = 0; i < a.length; i++) {
1290
+ if (Array.isArray(a[i]) || a[i] instanceof Float32Array) {
1291
+ result = false;
1292
+ break;
1040
1293
  }
1041
- });
1294
+
1295
+ if (a[i] !== b[i]) {
1296
+ result = false;
1297
+ break;
1298
+ }
1299
+
1300
+ result = true;
1301
+ }
1302
+
1303
+ return result;
1042
1304
  }
@@ -619,12 +619,13 @@ export class WebGlCoreRenderer extends CoreRenderer {
619
619
  console.log('renderOps', this.renderOps.length);
620
620
  }
621
621
 
622
- this.renderOps.forEach((renderOp, i) => {
622
+ for (let i = 0, length = this.renderOps.length; i < length; i++) {
623
+ const renderOp = this.renderOps[i] as WebGlCoreRenderOp;
623
624
  if (doLog) {
624
625
  console.log('Quads per operation', renderOp.numQuads);
625
626
  }
626
627
  renderOp.draw();
627
- });
628
+ }
628
629
  this.quadBufferUsage = this.curBufferIdx * arr.BYTES_PER_ELEMENT;
629
630
  }
630
631
 
@@ -274,18 +274,23 @@ export abstract class WebGlCoreShader extends CoreShader {
274
274
  const { width, height } = renderOp.framebufferDimensions || {};
275
275
  // Force pixel ratio to 1.0 for render textures since they are always 1:1
276
276
  // the final render texture will be rendered to the screen with the correct pixel ratio
277
- this.setUniform('u_pixelRatio', 1.0);
277
+ glw.uniform1f(this.getUniformLocation('u_pixelRatio'), 1.0);
278
278
 
279
279
  // Set resolution to the framebuffer dimensions
280
- this.setUniform(
281
- 'u_resolution',
282
- new Float32Array([width ?? 0, height ?? 0]),
280
+ glw.uniform2f(
281
+ this.getUniformLocation('u_resolution'),
282
+ width ?? 0,
283
+ height ?? 0,
283
284
  );
284
285
  } else {
285
- this.setUniform('u_pixelRatio', renderOp.options.pixelRatio);
286
- this.setUniform(
287
- 'u_resolution',
288
- new Float32Array([glw.canvas.width, glw.canvas.height]),
286
+ glw.uniform1f(
287
+ this.getUniformLocation('u_pixelRatio'),
288
+ renderOp.options.pixelRatio,
289
+ );
290
+ glw.uniform2f(
291
+ this.getUniformLocation('u_resolution'),
292
+ glw.canvas.width,
293
+ glw.canvas.height,
289
294
  );
290
295
  }
291
296
 
@@ -297,26 +302,25 @@ export abstract class WebGlCoreShader extends CoreShader {
297
302
  if (!dimensions) {
298
303
  dimensions = renderOp.dimensions;
299
304
  }
300
- this.setUniform('u_dimensions', [dimensions.width, dimensions.height]);
305
+ glw.uniform2f(
306
+ this.getUniformLocation('u_dimensions'),
307
+ dimensions.width,
308
+ dimensions.height,
309
+ );
301
310
  }
302
311
  if (hasOwn(props, '$alpha')) {
303
312
  let alpha = props.$alpha as number | null;
304
313
  if (!alpha) {
305
314
  alpha = renderOp.alpha;
306
315
  }
307
- this.setUniform('u_alpha', alpha);
316
+ glw.uniform1f(this.getUniformLocation('u_alpha'), alpha);
308
317
  }
309
318
  this.bindProps(props);
310
319
  }
311
320
  }
312
321
 
313
- setUniform(name: string, ...value: any[]): void {
314
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unsafe-argument
315
- this.glw.setUniform(
316
- this.uniformTypes[name]!,
317
- this.uniformLocations[name]!,
318
- ...(value as any),
319
- );
322
+ getUniformLocation(name: string): WebGLUniformLocation | null {
323
+ return this.uniformLocations[name] || null;
320
324
  }
321
325
 
322
326
  bindBufferCollection(buffer: BufferCollection) {
@@ -57,7 +57,7 @@ export class DefaultShaderBatched extends WebGlCoreShader {
57
57
  glw.bindTexture(t.ctxTexture);
58
58
  });
59
59
  const samplers = Array.from(Array(texture.length).keys());
60
- this.setUniform('u_textures[0]', samplers);
60
+ this.glw.uniform1iv(this.getUniformLocation('u_textures[0]'), samplers);
61
61
  }
62
62
 
63
63
  static override shaderSources: ShaderProgramSources = {