@lightningjs/renderer 3.0.0-beta22 → 3.0.0-beta24

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 (190) hide show
  1. package/README.md +93 -0
  2. package/dist/exports/index.d.ts +3 -1
  3. package/dist/exports/index.js +2 -0
  4. package/dist/exports/index.js.map +1 -1
  5. package/dist/exports/platform.d.ts +7 -0
  6. package/dist/exports/platform.js +27 -0
  7. package/dist/exports/platform.js.map +1 -0
  8. package/dist/src/core/AutosizeManager.d.ts +29 -0
  9. package/dist/src/core/AutosizeManager.js +169 -0
  10. package/dist/src/core/AutosizeManager.js.map +1 -0
  11. package/dist/src/core/CoreNode.d.ts +0 -1
  12. package/dist/src/core/CoreNode.js +47 -41
  13. package/dist/src/core/CoreNode.js.map +1 -1
  14. package/dist/src/core/CoreTextureManager.d.ts +0 -13
  15. package/dist/src/core/CoreTextureManager.js +4 -78
  16. package/dist/src/core/CoreTextureManager.js.map +1 -1
  17. package/dist/src/core/Stage.js +2 -12
  18. package/dist/src/core/Stage.js.map +1 -1
  19. package/dist/src/core/animations/Animation.d.ts +21 -0
  20. package/dist/src/core/animations/Animation.js +194 -0
  21. package/dist/src/core/animations/Animation.js.map +1 -0
  22. package/dist/src/core/animations/CoreAnimationController.d.ts +1 -1
  23. package/dist/src/core/animations/CoreAnimationController.js +4 -2
  24. package/dist/src/core/animations/CoreAnimationController.js.map +1 -1
  25. package/dist/src/core/animations/Playback.d.ts +64 -0
  26. package/dist/src/core/animations/Playback.js +169 -0
  27. package/dist/src/core/animations/Playback.js.map +1 -0
  28. package/dist/src/core/animations/Transition.d.ts +27 -0
  29. package/dist/src/core/animations/Transition.js +52 -0
  30. package/dist/src/core/animations/Transition.js.map +1 -0
  31. package/dist/src/core/animations/utils.d.ts +2 -0
  32. package/dist/src/core/animations/utils.js +136 -0
  33. package/dist/src/core/animations/utils.js.map +1 -0
  34. package/dist/src/core/lib/collectionUtils.d.ts +0 -1
  35. package/dist/src/core/lib/collectionUtils.js +0 -28
  36. package/dist/src/core/lib/collectionUtils.js.map +1 -1
  37. package/dist/src/core/lib/utils.d.ts +0 -5
  38. package/dist/src/core/lib/utils.js +0 -63
  39. package/dist/src/core/lib/utils.js.map +1 -1
  40. package/dist/src/core/platforms/GlContextWrapper.d.ts +136 -0
  41. package/dist/src/core/platforms/GlContextWrapper.js +32 -0
  42. package/dist/src/core/platforms/GlContextWrapper.js.map +1 -0
  43. package/dist/src/core/platforms/Platform.d.ts +74 -13
  44. package/dist/src/core/platforms/Platform.js +18 -0
  45. package/dist/src/core/platforms/Platform.js.map +1 -1
  46. package/dist/src/core/platforms/web/WebGlContextWrapper.d.ts +776 -0
  47. package/dist/src/core/platforms/web/WebGlContextWrapper.js +1208 -0
  48. package/dist/src/core/platforms/web/WebGlContextWrapper.js.map +1 -0
  49. package/dist/src/core/platforms/web/WebPlatform.d.ts +13 -2
  50. package/dist/src/core/platforms/web/WebPlatform.js +109 -8
  51. package/dist/src/core/platforms/web/WebPlatform.js.map +1 -1
  52. package/dist/src/core/platforms/web/WebPlatformChrome50.d.ts +17 -0
  53. package/dist/src/core/platforms/web/WebPlatformChrome50.js +50 -0
  54. package/dist/src/core/platforms/web/WebPlatformChrome50.js.map +1 -0
  55. package/dist/src/core/platforms/web/WebPlatformLegacy.d.ts +18 -0
  56. package/dist/src/core/platforms/web/WebPlatformLegacy.js +99 -0
  57. package/dist/src/core/platforms/web/WebPlatformLegacy.js.map +1 -0
  58. package/dist/src/core/platforms/web/WebPlatformNext.d.ts +21 -0
  59. package/dist/src/core/platforms/web/WebPlatformNext.js +52 -0
  60. package/dist/src/core/platforms/web/WebPlatformNext.js.map +1 -0
  61. package/dist/src/core/platforms/web/lib/ImageWorker.d.ts +15 -0
  62. package/dist/src/core/platforms/web/lib/ImageWorker.js +189 -0
  63. package/dist/src/core/platforms/web/lib/ImageWorker.js.map +1 -0
  64. package/dist/src/core/platforms/web/lib/createImageBitmap.d.ts +1 -0
  65. package/dist/src/core/platforms/web/lib/createImageBitmap.js +27 -0
  66. package/dist/src/core/platforms/web/lib/createImageBitmap.js.map +1 -0
  67. package/dist/src/core/platforms/web/lib/textureCompression.d.ts +26 -0
  68. package/dist/src/core/platforms/web/lib/textureCompression.js +301 -0
  69. package/dist/src/core/platforms/web/lib/textureCompression.js.map +1 -0
  70. package/dist/src/core/platforms/web/lib/textureSvg.d.ts +7 -0
  71. package/dist/src/core/platforms/web/lib/textureSvg.js +51 -0
  72. package/dist/src/core/platforms/web/lib/textureSvg.js.map +1 -0
  73. package/dist/src/core/platforms/web/lib/utils.d.ts +5 -0
  74. package/dist/src/core/platforms/web/lib/utils.js +86 -0
  75. package/dist/src/core/platforms/web/lib/utils.js.map +1 -0
  76. package/dist/src/core/renderers/CoreRenderer.d.ts +1 -9
  77. package/dist/src/core/renderers/CoreRenderer.js +2 -4
  78. package/dist/src/core/renderers/CoreRenderer.js.map +1 -1
  79. package/dist/src/core/renderers/canvas/CanvasRenderer.d.ts +3 -2
  80. package/dist/src/core/renderers/canvas/CanvasRenderer.js +6 -5
  81. package/dist/src/core/renderers/canvas/CanvasRenderer.js.map +1 -1
  82. package/dist/src/core/renderers/canvas/CanvasShaderNode.js +3 -3
  83. package/dist/src/core/renderers/canvas/CanvasShaderNode.js.map +1 -1
  84. package/dist/src/core/renderers/webgl/SdfRenderOp.js +3 -2
  85. package/dist/src/core/renderers/webgl/SdfRenderOp.js.map +1 -1
  86. package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.d.ts +2 -2
  87. package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js.map +1 -1
  88. package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.d.ts +2 -2
  89. package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.js.map +1 -1
  90. package/dist/src/core/renderers/webgl/WebGlCtxTexture.d.ts +3 -3
  91. package/dist/src/core/renderers/webgl/WebGlCtxTexture.js +1 -2
  92. package/dist/src/core/renderers/webgl/WebGlCtxTexture.js.map +1 -1
  93. package/dist/src/core/renderers/webgl/WebGlRenderer.d.ts +5 -5
  94. package/dist/src/core/renderers/webgl/WebGlRenderer.js +10 -11
  95. package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +1 -1
  96. package/dist/src/core/renderers/webgl/WebGlShaderNode.d.ts +2 -2
  97. package/dist/src/core/renderers/webgl/WebGlShaderNode.js +3 -3
  98. package/dist/src/core/renderers/webgl/WebGlShaderNode.js.map +1 -1
  99. package/dist/src/core/renderers/webgl/WebGlShaderProgram.d.ts +2 -2
  100. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js +0 -3
  101. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js.map +1 -1
  102. package/dist/src/core/renderers/webgl/internal/RendererUtils.d.ts +4 -4
  103. package/dist/src/core/renderers/webgl/internal/RendererUtils.js.map +1 -1
  104. package/dist/src/core/renderers/webgl/internal/ShaderUtils.d.ts +3 -3
  105. package/dist/src/core/renderers/webgl/internal/ShaderUtils.js +3 -2
  106. package/dist/src/core/renderers/webgl/internal/ShaderUtils.js.map +1 -1
  107. package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js +24 -8
  108. package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js.map +1 -1
  109. package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js +25 -8
  110. package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js.map +1 -1
  111. package/dist/src/core/shaders/webgl/Border.js +6 -4
  112. package/dist/src/core/shaders/webgl/Border.js.map +1 -1
  113. package/dist/src/core/shaders/webgl/RoundedWithBorder.js +16 -17
  114. package/dist/src/core/shaders/webgl/RoundedWithBorder.js.map +1 -1
  115. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js +19 -21
  116. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js.map +1 -1
  117. package/dist/src/core/shaders/webgl/SdfShadowShader.d.ts +9 -0
  118. package/dist/src/core/shaders/webgl/SdfShadowShader.js +100 -0
  119. package/dist/src/core/shaders/webgl/SdfShadowShader.js.map +1 -0
  120. package/dist/src/core/text-rendering/CanvasFont.d.ts +1 -1
  121. package/dist/src/core/text-rendering/CanvasFont.js +2 -6
  122. package/dist/src/core/text-rendering/CanvasFont.js.map +1 -1
  123. package/dist/src/core/text-rendering/CoreFont.d.ts +1 -1
  124. package/dist/src/core/text-rendering/CoreFont.js +1 -1
  125. package/dist/src/core/text-rendering/CoreFont.js.map +1 -1
  126. package/dist/src/core/text-rendering/FontManager.js +2 -1
  127. package/dist/src/core/text-rendering/FontManager.js.map +1 -1
  128. package/dist/src/core/text-rendering/SdfFontHandler.js +10 -20
  129. package/dist/src/core/text-rendering/SdfFontHandler.js.map +1 -1
  130. package/dist/src/core/text-rendering/SdfTextRenderer.js +10 -12
  131. package/dist/src/core/text-rendering/SdfTextRenderer.js.map +1 -1
  132. package/dist/src/core/textures/ImageTexture.d.ts +24 -11
  133. package/dist/src/core/textures/ImageTexture.js +32 -95
  134. package/dist/src/core/textures/ImageTexture.js.map +1 -1
  135. package/dist/src/core/textures/SubTexture.js +3 -3
  136. package/dist/src/core/textures/SubTexture.js.map +1 -1
  137. package/dist/src/core/textures/Texture.d.ts +1 -1
  138. package/dist/src/core/textures/Texture.js +1 -1
  139. package/dist/src/core/textures/Texture.js.map +1 -1
  140. package/dist/src/main-api/Renderer.js +18 -21
  141. package/dist/src/main-api/Renderer.js.map +1 -1
  142. package/dist/src/utils.d.ts +0 -2
  143. package/dist/src/utils.js +0 -36
  144. package/dist/src/utils.js.map +1 -1
  145. package/dist/tsconfig.dist.tsbuildinfo +1 -1
  146. package/dist/tsconfig.tsbuildinfo +1 -0
  147. package/exports/index.ts +3 -1
  148. package/exports/platform.ts +31 -0
  149. package/package.json +3 -2
  150. package/src/core/CoreNode.ts +52 -49
  151. package/src/core/CoreTextureManager.ts +10 -103
  152. package/src/core/Stage.ts +1 -14
  153. package/src/core/animations/CoreAnimationController.ts +5 -2
  154. package/src/core/lib/collectionUtils.ts +0 -35
  155. package/src/core/lib/utils.ts +0 -78
  156. package/src/core/platforms/GlContextWrapper.ts +291 -0
  157. package/src/core/platforms/Platform.ts +121 -28
  158. package/src/core/{lib → platforms/web}/WebGlContextWrapper.ts +129 -4
  159. package/src/core/platforms/web/WebPlatform.ts +171 -22
  160. package/src/core/platforms/web/WebPlatformChrome50.ts +57 -0
  161. package/src/core/platforms/web/WebPlatformLegacy.ts +140 -0
  162. package/src/core/platforms/web/WebPlatformNext.ts +57 -0
  163. package/src/core/{lib → platforms/web/lib}/ImageWorker.ts +10 -74
  164. package/src/core/platforms/web/lib/createImageBitmap.ts +40 -0
  165. package/src/core/{lib → platforms/web/lib}/textureCompression.ts +19 -138
  166. package/src/core/{lib → platforms/web/lib}/textureSvg.ts +3 -15
  167. package/src/core/platforms/web/lib/utils.ts +105 -0
  168. package/src/core/renderers/CoreRenderer.ts +2 -11
  169. package/src/core/renderers/canvas/CanvasRenderer.ts +8 -6
  170. package/src/core/renderers/canvas/CanvasShaderNode.ts +3 -3
  171. package/src/core/renderers/webgl/SdfRenderOp.ts +3 -2
  172. package/src/core/renderers/webgl/WebGlCtxRenderTexture.ts +2 -2
  173. package/src/core/renderers/webgl/WebGlCtxSubTexture.ts +2 -2
  174. package/src/core/renderers/webgl/WebGlCtxTexture.ts +3 -4
  175. package/src/core/renderers/webgl/WebGlRenderer.ts +15 -22
  176. package/src/core/renderers/webgl/WebGlShaderNode.ts +5 -5
  177. package/src/core/renderers/webgl/WebGlShaderProgram.ts +2 -6
  178. package/src/core/renderers/webgl/internal/RendererUtils.ts +4 -8
  179. package/src/core/renderers/webgl/internal/ShaderUtils.ts +7 -5
  180. package/src/core/shaders/webgl/Border.ts +6 -4
  181. package/src/core/shaders/webgl/RoundedWithBorder.ts +16 -17
  182. package/src/core/shaders/webgl/RoundedWithBorderAndShadow.ts +19 -21
  183. package/src/core/text-rendering/SdfFontHandler.ts +10 -17
  184. package/src/core/text-rendering/SdfTextRenderer.ts +11 -16
  185. package/src/core/textures/ImageTexture.ts +42 -161
  186. package/src/core/textures/SubTexture.ts +3 -3
  187. package/src/core/textures/Texture.ts +2 -2
  188. package/src/main-api/Renderer.ts +24 -22
  189. package/src/utils.ts +0 -47
  190. package/src/core/lib/validateImageBitmap.ts +0 -87
@@ -0,0 +1,291 @@
1
+ /*
2
+ * If not stated otherwise in this file or this component's LICENSE file the
3
+ * following copyright and licenses apply:
4
+ *
5
+ * Copyright 2026 Comcast Cable Communications Management, LLC.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the License);
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ /* eslint-disable @typescript-eslint/no-explicit-any */
21
+
22
+ import type {
23
+ Vec2,
24
+ Vec3,
25
+ Vec4,
26
+ } from '../renderers/webgl/internal/ShaderUtils.js';
27
+
28
+ import type { CompressedData } from '../textures/Texture.js';
29
+
30
+ /**
31
+ * Abstract GL Context Wrapper
32
+ *
33
+ * @remarks
34
+ * This abstract class defines the interface for rendering context wrappers.
35
+ * Implementations should provide optimized state management and caching
36
+ * to avoid redundant API calls when the state is already set to the desired value.
37
+ *
38
+ * The interface is designed to be compatible with WebGL-like rendering contexts
39
+ * but can be adapted for other rendering backends (Canvas2D, WebGPU, Native, etc.).
40
+ */
41
+ export abstract class GlContextWrapper {
42
+ //#region Canvas
43
+ abstract readonly canvas: HTMLCanvasElement | OffscreenCanvas;
44
+ //#endregion Canvas
45
+
46
+ //#region GL Constants
47
+ abstract readonly MAX_RENDERBUFFER_SIZE: number;
48
+ abstract readonly MAX_TEXTURE_SIZE: number;
49
+ abstract readonly MAX_VIEWPORT_DIMS: number;
50
+ abstract readonly MAX_VERTEX_TEXTURE_IMAGE_UNITS: number;
51
+ abstract readonly MAX_TEXTURE_IMAGE_UNITS: number;
52
+ abstract readonly MAX_COMBINED_TEXTURE_IMAGE_UNITS: number;
53
+ abstract readonly MAX_VERTEX_ATTRIBS: number;
54
+ abstract readonly MAX_VARYING_VECTORS: number;
55
+ abstract readonly MAX_VERTEX_UNIFORM_VECTORS: number;
56
+ abstract readonly MAX_FRAGMENT_UNIFORM_VECTORS: number;
57
+ abstract readonly TEXTURE_MAG_FILTER: number;
58
+ abstract readonly TEXTURE_MIN_FILTER: number;
59
+ abstract readonly TEXTURE_WRAP_S: number;
60
+ abstract readonly TEXTURE_WRAP_T: number;
61
+ abstract readonly LINEAR: number;
62
+ abstract readonly LINEAR_MIPMAP_LINEAR: number;
63
+ abstract readonly CLAMP_TO_EDGE: number;
64
+ abstract readonly RGB: number;
65
+ abstract readonly RGBA: number;
66
+ abstract readonly UNSIGNED_BYTE: number;
67
+ abstract readonly UNPACK_PREMULTIPLY_ALPHA_WEBGL: number;
68
+ abstract readonly UNPACK_FLIP_Y_WEBGL: number;
69
+ abstract readonly FLOAT: number;
70
+ abstract readonly TRIANGLES: number;
71
+ abstract readonly UNSIGNED_SHORT: number;
72
+ abstract readonly ONE: number;
73
+ abstract readonly ONE_MINUS_SRC_ALPHA: number;
74
+ abstract readonly VERTEX_SHADER: number;
75
+ abstract readonly FRAGMENT_SHADER: number;
76
+ abstract readonly STATIC_DRAW: number;
77
+ abstract readonly COMPILE_STATUS: number;
78
+ abstract readonly LINK_STATUS: number;
79
+ abstract readonly DYNAMIC_DRAW: number;
80
+ abstract readonly COLOR_ATTACHMENT0: number;
81
+ abstract readonly INVALID_ENUM: number;
82
+ abstract readonly INVALID_OPERATION: number;
83
+ //#endregion GL Constants
84
+
85
+ //#region Texture Management
86
+ abstract activeTexture(textureUnit: number): void;
87
+ abstract bindTexture(texture: any | null): void;
88
+ abstract texParameteri(pname: number, param: number): void;
89
+ abstract texImage2D(
90
+ level: GLint,
91
+ internalformat: GLint,
92
+ width: GLsizei,
93
+ height: GLsizei,
94
+ border: GLint,
95
+ format: GLenum,
96
+ type: GLenum,
97
+ pixels: ArrayBufferView | null,
98
+ ): void;
99
+ abstract texImage2D(
100
+ level: GLint,
101
+ internalformat: GLint,
102
+ format: GLenum,
103
+ type: GLenum,
104
+ source: TexImageSource | Uint8Array,
105
+ ): void;
106
+ abstract compressedTexImage2D(
107
+ level: GLint,
108
+ internalformat: GLenum,
109
+ width: GLsizei,
110
+ height: GLsizei,
111
+ border: GLint,
112
+ data?: ArrayBufferView,
113
+ ): void;
114
+ abstract pixelStorei(pname: GLenum, param: GLint | GLboolean): void;
115
+ abstract generateMipmap(): void;
116
+ abstract createTexture(): any;
117
+ abstract deleteTexture(texture: any | null): void;
118
+ //#endregion Texture Management
119
+
120
+ //#region Viewport & Clear
121
+ abstract viewport(x: GLint, y: GLint, width: GLsizei, height: GLsizei): void;
122
+ abstract clearColor(
123
+ red: GLclampf,
124
+ green: GLclampf,
125
+ blue: GLclampf,
126
+ alpha: GLclampf,
127
+ ): void;
128
+ abstract clear(): void;
129
+ //#endregion Viewport & Clear
130
+
131
+ //#region Scissor & Blend
132
+ abstract setScissorTest(enable: boolean): void;
133
+ abstract scissor(x: GLint, y: GLint, width: GLsizei, height: GLsizei): void;
134
+ abstract setBlend(blend: boolean): void;
135
+ abstract blendFunc(src: GLenum, dst: GLenum): void;
136
+ //#endregion Scissor & Blend
137
+
138
+ //#region Buffer Management
139
+ abstract createBuffer(): any;
140
+ abstract arrayBufferData(
141
+ buffer: any | null,
142
+ data: ArrayBufferView,
143
+ usage: GLenum,
144
+ ): void;
145
+ abstract elementArrayBufferData(
146
+ buffer: any | null,
147
+ data: ArrayBufferView,
148
+ usage: GLenum,
149
+ ): void;
150
+ abstract vertexAttribPointer(
151
+ buffer: any,
152
+ index: GLuint,
153
+ size: GLint,
154
+ type: GLenum,
155
+ normalized: GLboolean,
156
+ stride: GLsizei,
157
+ offset: GLintptr,
158
+ ): void;
159
+ abstract deleteBuffer(buffer: any): void;
160
+ //#endregion Buffer Management
161
+
162
+ //#region Framebuffer Management
163
+ abstract createFramebuffer(): any;
164
+ abstract deleteFramebuffer(framebuffer: any | null): void;
165
+ abstract bindFramebuffer(framebuffer: any | null): void;
166
+ abstract framebufferTexture2D(
167
+ attachment: GLenum,
168
+ texture: any | null,
169
+ level: GLint,
170
+ ): void;
171
+ //#endregion Framebuffer Management
172
+
173
+ //#region Shader & Program Management
174
+ abstract createShader(type: number): any;
175
+ abstract compileShader(shader: any): void;
176
+ abstract attachShader(program: any, shader: any): void;
177
+ abstract linkProgram(program: any): void;
178
+ abstract deleteProgram(shader: any): void;
179
+ abstract getShaderParameter(shader: any, pname: GLenum): any;
180
+ abstract getShaderInfoLog(shader: any): string | null;
181
+ abstract createProgram(): any;
182
+ abstract getProgramParameter(program: any, pname: GLenum): any;
183
+ abstract getProgramInfoLog(program: any): string | null;
184
+ abstract shaderSource(shader: any, source: string): void;
185
+ abstract deleteShader(shader: any): void;
186
+ abstract useProgram(
187
+ program: any | null,
188
+ uniformLocations: Record<string, any>,
189
+ ): void;
190
+ abstract getUniformLocations(program: any): Record<string, any>;
191
+ abstract getAttributeLocations(program: any): string[];
192
+ abstract getAttribLocation(program: any, name: string): number;
193
+ abstract getUniformLocation(program: any, name: string): any;
194
+ abstract enableVertexAttribArray(index: number): void;
195
+ abstract disableVertexAttribArray(index: number): void;
196
+ //#endregion Shader & Program Management
197
+
198
+ //#region Uniform Setters
199
+ abstract uniform1f(location: string, v0: number): void;
200
+ abstract uniform1fv(location: string, value: Float32Array): void;
201
+ abstract uniform1i(location: string, v0: number): void;
202
+ abstract uniform1iv(location: string, value: Int32Array): void;
203
+ abstract uniform2f(location: string, v0: number, v1: number): void;
204
+ abstract uniform2fa(location: string, value: Vec2): void;
205
+ abstract uniform2fv(location: string, value: Float32Array): void;
206
+ abstract uniform2i(location: string, v0: number, v1: number): void;
207
+ abstract uniform2iv(location: string, value: Int32Array): void;
208
+ abstract uniform3f(
209
+ location: string,
210
+ v0: number,
211
+ v1: number,
212
+ v2: number,
213
+ ): void;
214
+ abstract uniform3fa(location: string, value: Vec3): void;
215
+ abstract uniform3fv(location: string, value: Float32Array): void;
216
+ abstract uniform3i(
217
+ location: string,
218
+ v0: number,
219
+ v1: number,
220
+ v2: number,
221
+ ): void;
222
+ abstract uniform3iv(location: string, value: Int32Array): void;
223
+ abstract uniform4f(
224
+ location: string,
225
+ v0: number,
226
+ v1: number,
227
+ v2: number,
228
+ v3: number,
229
+ ): void;
230
+ abstract uniform4fa(location: string, value: Vec4): void;
231
+ abstract uniform4fv(location: string, value: Float32Array): void;
232
+ abstract uniform4i(
233
+ location: string,
234
+ v0: number,
235
+ v1: number,
236
+ v2: number,
237
+ v3: number,
238
+ ): void;
239
+ abstract uniform4iv(location: string, value: Int32Array): void;
240
+ abstract uniformMatrix2fv(location: string, value: Float32Array): void;
241
+ abstract uniformMatrix3fv(location: string, value: Float32Array): void;
242
+ abstract uniformMatrix4fv(location: string, value: Float32Array): void;
243
+ //#endregion Uniform Setters
244
+
245
+ //#region Vertex Array Objects
246
+ abstract createVertexArray(): any;
247
+ abstract bindVertexArray(vertexArray: any | null): void;
248
+ abstract deleteVertexArray(vertexArray: any): void;
249
+ //#endregion Vertex Array Objects
250
+
251
+ //#region Drawing
252
+ abstract drawElements(
253
+ mode: GLenum,
254
+ count: GLsizei,
255
+ type: GLenum,
256
+ offset: GLintptr,
257
+ ): void;
258
+ abstract drawArrays(mode: GLenum, first: GLint, count: GLsizei): void;
259
+ //#endregion Drawing
260
+
261
+ //#region Context Info & Extensions
262
+ abstract getParameter(pname: GLenum): any;
263
+ abstract getExtension(name: string): any;
264
+ abstract getError(): number;
265
+ abstract checkError(
266
+ operation: string,
267
+ ): { error: number; errorName: string; message: string } | null;
268
+ //#endregion Context Info & Extensions
269
+
270
+ //#region compressed texture support
271
+ abstract uploadKTX(
272
+ glw: GlContextWrapper,
273
+ texture: WebGLTexture,
274
+ data: CompressedData,
275
+ ): void;
276
+ abstract uploadPVR(
277
+ glw: GlContextWrapper,
278
+ texture: WebGLTexture,
279
+ data: CompressedData,
280
+ ): void;
281
+ abstract uploadASTC(
282
+ glw: GlContextWrapper,
283
+ texture: WebGLTexture,
284
+ data: CompressedData,
285
+ ): void;
286
+ //#endregion compressed texture support
287
+
288
+ //#region WebGL 2 specific methods (optional)
289
+ abstract isWebGl2(): boolean;
290
+ //#endregion WebGL 2 specific methods
291
+ }
@@ -18,14 +18,65 @@
18
18
  */
19
19
 
20
20
  import { type Stage } from '../Stage.js';
21
+ import type { WebGlContextWrapper } from './web/WebGlContextWrapper.js';
22
+ import type { ImageResponse } from '../textures/ImageTexture.js';
23
+ import type { GlContextWrapper } from './GlContextWrapper.js';
24
+
25
+ /**
26
+ * Settings for the Platform
27
+ */
28
+ export interface PlatformSettings {
29
+ /**
30
+ * Number of image workers to spawn for parallel image processing
31
+ * @default 2
32
+ */
33
+ numImageWorkers?: number;
34
+
35
+ /**
36
+ * Whether to force the use of WebGL2 (if supported by the platform) or WebGL1. By default, the platform will use WebGL2 if it is available, and fall back to WebGL1 if it is not.
37
+ * @default false
38
+ */
39
+ forceWebGL2?: boolean;
40
+
41
+ /**
42
+ * Optional provided canvas element to use for rendering. If not provided, the platform will create its own canvas element.
43
+ */
44
+ canvas?: HTMLCanvasElement | null;
45
+ }
21
46
 
22
47
  export abstract class Platform {
48
+ public readonly settings: Required<PlatformSettings>;
49
+
50
+ public glw: GlContextWrapper | null = null;
51
+ public canvas: HTMLCanvasElement | null = null;
52
+
53
+ constructor(settings: PlatformSettings = {}) {
54
+ // Apply default settings
55
+ this.settings = {
56
+ numImageWorkers: settings.numImageWorkers ?? 2,
57
+ forceWebGL2: settings.forceWebGL2 ?? false,
58
+ canvas: settings.canvas ?? null,
59
+ };
60
+
61
+ // If a canvas was provided in the settings, use it. Otherwise, create a new one.
62
+ if (this.settings.canvas !== null) {
63
+ this.canvas = this.settings.canvas;
64
+ } else {
65
+ this.canvas = this.createCanvas();
66
+ }
67
+ }
68
+
23
69
  /**
24
70
  * Creates a new canvas element.
25
71
  * @returns The created HTMLCanvasElement.
26
72
  */
27
73
  abstract createCanvas(): HTMLCanvasElement;
28
74
 
75
+ /**
76
+ * Create new rendering context (only for WebGL, Canvas does not require a context)
77
+ */
78
+ abstract createContext(): GlContextWrapper;
79
+
29
80
  /**
30
81
  * Get a DOM element by ID
31
82
  * @returns The DOM element (or null)
@@ -39,35 +90,77 @@ export abstract class Platform {
39
90
  abstract startLoop(stage: Stage): void;
40
91
 
41
92
  /**
42
- * Abstracted createImageBitmap method.
43
- * @param blob - The image source to create the ImageBitmap from.
44
- * @param sxOrOptions - The source rectangle x coordinate or ImageBitmapOptions.
45
- * @param sy - The source rectangle y coordinate.
46
- * @param sw - The source rectangle width.
47
- * @param sh - The source rectangle height.
48
- * @param options - The ImageBitmapOptions.
49
- * @returns A promise that resolves with the created ImageBitmap.
93
+ * Fetches a resource from the network.
94
+ * @param url - The URL of the resource to fetch.
95
+ * @returns A promise that resolves with the response.
96
+ */
97
+ abstract fetch(url: string): Promise<unknown>;
98
+
99
+ /**
100
+ * Loads an image from a UR and returns it as an ImageBitmap or HTMLImageElement.
101
+ * @param src - The source URL or Blob of the image to load.
102
+ * @param premultiplyAlpha - Whether to premultiply alpha (if supported by the platform).
103
+ * @param sx - The x coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
104
+ * @param sy - The y coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
105
+ * @param sw - The width of the sub-rectangle of the source image to draw into the destination context.
106
+ * @param sh - The height of the sub-rectangle of the source image to draw into the destination context.
107
+ * @returns A promise that resolves with an object containing the loaded image and whether alpha was premultiplied.
108
+ */
109
+ abstract loadImage(
110
+ src: string,
111
+ premultiplyAlpha: boolean | null,
112
+ sx?: number | null,
113
+ sy?: number | null,
114
+ sw?: number | null,
115
+ sh?: number | null,
116
+ ): Promise<ImageResponse>;
117
+
118
+ /**
119
+ * Create an image out of a Blob
120
+ *
121
+ * @param blob - The Blob to create an image from
122
+ * @param premultiplyAlpha - Whether to premultiply alpha (if supported by the platform).
123
+ * @param sx - The x coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
124
+ * @param sy - The y coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
125
+ * @param sw - The width of the sub-rectangle of the source image to draw into the destination context.
126
+ * @param sh - The height of the sub-rectangle of the source image to draw into the destination context.
127
+ * @returns A promise that resolves with an object containing the loaded image and whether alpha was premultiplied.
128
+ */
129
+ abstract createImage(
130
+ blob: Blob,
131
+ premultiplyAlpha: boolean | null,
132
+ sx?: number | null,
133
+ sy?: number | null,
134
+ sw?: number | null,
135
+ sh?: number | null,
136
+ ): Promise<ImageResponse>;
137
+
138
+ /**
139
+ * Loads an SVG image from a URL and returns it as an ImageBitmap or HTMLImageElement.
140
+ * @param src - The source URL of the SVG image to load.
141
+ * @param width - The width to render the SVG image.
142
+ * @param height - The height to render the SVG image.
143
+ * @param sx - The x coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
144
+ * @param sy - The y coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
145
+ * @param sw - The width of the sub-rectangle of the source image to draw into the destination context.
146
+ * @param sh - The height of the sub-rectangle of the source image to draw into the destination context.
147
+ */
148
+ abstract loadSvg(
149
+ src: string,
150
+ width: number | null,
151
+ height: number | null,
152
+ sx?: number | null,
153
+ sy?: number | null,
154
+ sw?: number | null,
155
+ sh?: number | null,
156
+ ): Promise<ImageResponse>;
157
+
158
+ /**
159
+ * Loads a compressed texture from a URL and returns it as an ImageBitmap or HTMLImageElement.
160
+ * @param src - The source URL of the compressed texture to load.
161
+ * @returns A promise that resolves with an object containing the loaded image and whether alpha was premultiplied.
50
162
  */
51
- abstract createImageBitmap(blob: ImageBitmapSource): Promise<ImageBitmap>;
52
- abstract createImageBitmap(
53
- blob: ImageBitmapSource,
54
- options: ImageBitmapOptions,
55
- ): Promise<ImageBitmap>;
56
- abstract createImageBitmap(
57
- blob: ImageBitmapSource,
58
- sx: number,
59
- sy: number,
60
- sw: number,
61
- sh: number,
62
- ): Promise<ImageBitmap>;
63
- abstract createImageBitmap(
64
- blob: ImageBitmapSource,
65
- sx: number,
66
- sy: number,
67
- sw: number,
68
- sh: number,
69
- options: ImageBitmapOptions,
70
- ): Promise<ImageBitmap>;
163
+ abstract loadCompressedTexture(src: string): Promise<ImageResponse>;
71
164
 
72
165
  /**
73
166
  * Retrieves the current timestamp.
@@ -1,14 +1,34 @@
1
+ /*
2
+ * If not stated otherwise in this file or this component's LICENSE file the
3
+ * following copyright and licenses apply:
4
+ *
5
+ * Copyright 2026 Comcast Cable Communications Management, LLC.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the License);
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
1
20
  /* eslint-disable @typescript-eslint/no-unsafe-return */
2
21
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
22
  /* eslint-disable @typescript-eslint/no-unsafe-argument */
4
23
 
5
- import { assertTruthy, isProductionEnvironment } from '../../utils.js';
6
24
  import type {
7
25
  Vec2,
8
26
  Vec3,
9
27
  Vec4,
10
- } from '../renderers/webgl/internal/ShaderUtils.js';
11
- import { isWebGl2 } from '../renderers/webgl/internal/WebGlUtils.js';
28
+ } from '../../renderers/webgl/internal/ShaderUtils.js';
29
+ import { isWebGl2 } from '../../renderers/webgl/internal/WebGlUtils.js';
30
+ import { GlContextWrapper } from '../GlContextWrapper.js';
31
+ import type { CompressedData } from '../../textures/Texture.js';
12
32
 
13
33
  /**
14
34
  * Optimized WebGL Context Wrapper
@@ -29,7 +49,7 @@ import { isWebGl2 } from '../renderers/webgl/internal/WebGlUtils.js';
29
49
  * A subset of GLenum constants are also exposed as properties on this class
30
50
  * for convenience.
31
51
  */
32
- export class WebGlContextWrapper {
52
+ export class WebGlContextWrapper extends GlContextWrapper {
33
53
  //#region Cached WebGL State
34
54
  private activeTextureUnit = 0;
35
55
  private texture2dUnits: Array<WebGLTexture | null>;
@@ -97,6 +117,7 @@ export class WebGlContextWrapper {
97
117
  //#endregion WebGL Enums
98
118
 
99
119
  constructor(private gl: WebGLRenderingContext | WebGL2RenderingContext) {
120
+ super();
100
121
  // The following code extracts the current state of the WebGL context
101
122
  // to our local JavaScript cached version of it. This is so we can
102
123
  // avoid making WebGL calls if we don't need to.
@@ -1367,6 +1388,110 @@ export class WebGlContextWrapper {
1367
1388
  }
1368
1389
  return null;
1369
1390
  }
1391
+
1392
+ /**
1393
+ *
1394
+ * Compressed Textures support
1395
+ */
1396
+ uploadKTX(texture: WebGLTexture, data: CompressedData) {
1397
+ const { glInternalFormat, mipmaps, w: width, h: height, blockInfo } = data;
1398
+ if (mipmaps === undefined) {
1399
+ return;
1400
+ }
1401
+
1402
+ this.bindTexture(texture);
1403
+
1404
+ const blockWidth = blockInfo.width;
1405
+ const blockHeight = blockInfo.height;
1406
+ let w = width;
1407
+ let h = height;
1408
+
1409
+ for (let i = 0; i < mipmaps!.length; i++) {
1410
+ let view = new Uint8Array(mipmaps![i]!);
1411
+
1412
+ const uploadW = Math.ceil(w / blockWidth) * blockWidth;
1413
+ const uploadH = Math.ceil(h / blockHeight) * blockHeight;
1414
+
1415
+ const expectedBytes =
1416
+ Math.ceil(w / blockWidth) *
1417
+ Math.ceil(h / blockHeight) *
1418
+ blockInfo.bytes;
1419
+
1420
+ if (view.byteLength < expectedBytes) {
1421
+ const padded = new Uint8Array(expectedBytes);
1422
+ padded.set(view);
1423
+ view = padded;
1424
+ }
1425
+
1426
+ this.compressedTexImage2D(i, glInternalFormat, uploadW, uploadH, 0, view);
1427
+
1428
+ w = Math.max(1, w >> 1);
1429
+ h = Math.max(1, h >> 1);
1430
+ }
1431
+
1432
+ this.texParameteri(this.TEXTURE_WRAP_S, this.CLAMP_TO_EDGE);
1433
+ this.texParameteri(this.TEXTURE_WRAP_T, this.CLAMP_TO_EDGE);
1434
+ this.texParameteri(this.TEXTURE_MAG_FILTER, this.LINEAR);
1435
+ this.texParameteri(
1436
+ this.TEXTURE_MIN_FILTER,
1437
+ mipmaps!.length > 1 ? this.LINEAR_MIPMAP_LINEAR : this.LINEAR,
1438
+ );
1439
+ }
1440
+
1441
+ uploadPVR(texture: WebGLTexture, data: CompressedData) {
1442
+ const { glInternalFormat, mipmaps, w: width, h: height } = data;
1443
+ if (mipmaps === undefined) {
1444
+ return;
1445
+ }
1446
+ this.bindTexture(texture);
1447
+
1448
+ let w = width;
1449
+ let h = height;
1450
+
1451
+ for (let i = 0; i < mipmaps!.length; i++) {
1452
+ this.compressedTexImage2D(
1453
+ i,
1454
+ glInternalFormat,
1455
+ w,
1456
+ h,
1457
+ 0,
1458
+ new Uint8Array(mipmaps[i]!),
1459
+ );
1460
+
1461
+ w = Math.max(1, w >> 1);
1462
+ h = Math.max(1, h >> 1);
1463
+ }
1464
+
1465
+ this.texParameteri(this.TEXTURE_WRAP_S, this.CLAMP_TO_EDGE);
1466
+ this.texParameteri(this.TEXTURE_WRAP_T, this.CLAMP_TO_EDGE);
1467
+ this.texParameteri(this.TEXTURE_MAG_FILTER, this.LINEAR);
1468
+ this.texParameteri(
1469
+ this.TEXTURE_MIN_FILTER,
1470
+ mipmaps.length > 1 ? this.LINEAR_MIPMAP_LINEAR : this.LINEAR,
1471
+ );
1472
+ }
1473
+
1474
+ uploadASTC(texture: WebGLTexture, data: CompressedData) {
1475
+ if (this.getExtension('WEBGL_compressed_texture_astc') === null) {
1476
+ throw new Error('ASTC compressed textures not supported by this device');
1477
+ }
1478
+
1479
+ this.bindTexture(texture);
1480
+
1481
+ const { glInternalFormat, mipmaps, w, h } = data;
1482
+ if (mipmaps === undefined) {
1483
+ return;
1484
+ }
1485
+
1486
+ const view = new Uint8Array(mipmaps[0]!);
1487
+
1488
+ this.compressedTexImage2D(0, glInternalFormat, w, h, 0, view);
1489
+ // ASTC textures MUST use no mipmaps unless stored
1490
+ this.texParameteri(this.TEXTURE_WRAP_S, this.CLAMP_TO_EDGE);
1491
+ this.texParameteri(this.TEXTURE_WRAP_T, this.CLAMP_TO_EDGE);
1492
+ this.texParameteri(this.TEXTURE_MAG_FILTER, this.LINEAR);
1493
+ this.texParameteri(this.TEXTURE_MIN_FILTER, this.LINEAR);
1494
+ }
1370
1495
  }
1371
1496
 
1372
1497
  // prettier-ignore