@luma.gl/core 9.0.11 → 9.1.0-alpha.1

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 (237) hide show
  1. package/LICENSE +34 -0
  2. package/dist/adapter/canvas-context.d.ts +5 -0
  3. package/dist/adapter/canvas-context.d.ts.map +1 -1
  4. package/dist/adapter/device.d.ts +10 -8
  5. package/dist/adapter/device.d.ts.map +1 -1
  6. package/dist/adapter/device.js +20 -18
  7. package/dist/{lib → adapter}/luma.d.ts +2 -2
  8. package/dist/adapter/luma.d.ts.map +1 -0
  9. package/dist/{lib → adapter}/luma.js +7 -7
  10. package/dist/adapter/resources/buffer.js +5 -5
  11. package/dist/adapter/resources/compute-pipeline.d.ts +2 -0
  12. package/dist/adapter/resources/compute-pipeline.d.ts.map +1 -1
  13. package/dist/adapter/resources/compute-pipeline.js +3 -0
  14. package/dist/adapter/resources/external-texture.d.ts +1 -1
  15. package/dist/adapter/resources/external-texture.d.ts.map +1 -1
  16. package/dist/adapter/resources/external-texture.js +1 -1
  17. package/dist/adapter/resources/framebuffer.d.ts +3 -3
  18. package/dist/adapter/resources/framebuffer.d.ts.map +1 -1
  19. package/dist/adapter/resources/framebuffer.js +2 -83
  20. package/dist/adapter/resources/render-pass.d.ts +2 -2
  21. package/dist/adapter/resources/render-pass.d.ts.map +1 -1
  22. package/dist/adapter/resources/render-pipeline.d.ts +2 -5
  23. package/dist/adapter/resources/render-pipeline.d.ts.map +1 -1
  24. package/dist/adapter/resources/resource.d.ts +3 -3
  25. package/dist/adapter/resources/resource.d.ts.map +1 -1
  26. package/dist/adapter/resources/resource.js +1 -1
  27. package/dist/adapter/resources/shader.d.ts +5 -2
  28. package/dist/adapter/resources/shader.d.ts.map +1 -1
  29. package/dist/adapter/resources/shader.js +15 -9
  30. package/dist/adapter/resources/texture-view.d.ts +1 -1
  31. package/dist/adapter/resources/texture-view.d.ts.map +1 -1
  32. package/dist/adapter/resources/texture.d.ts +111 -49
  33. package/dist/adapter/resources/texture.d.ts.map +1 -1
  34. package/dist/adapter/resources/texture.js +96 -12
  35. package/dist/adapter/resources/transform-feedback.d.ts +1 -1
  36. package/dist/adapter/resources/transform-feedback.d.ts.map +1 -1
  37. package/dist/adapter/resources/vertex-array.d.ts +1 -1
  38. package/dist/adapter/resources/vertex-array.d.ts.map +1 -1
  39. package/dist/adapter/resources/vertex-array.js +6 -2
  40. package/dist/adapter/types/{types.d.ts → attachments.d.ts} +5 -16
  41. package/dist/adapter/types/attachments.d.ts.map +1 -0
  42. package/dist/adapter/types/buffer-layout.d.ts +1 -1
  43. package/dist/adapter/types/buffer-layout.d.ts.map +1 -1
  44. package/dist/adapter/types/compiler-message.d.ts.map +1 -0
  45. package/dist/adapter/types/parameters.d.ts +2 -6
  46. package/dist/adapter/types/parameters.d.ts.map +1 -1
  47. package/dist/adapter/types/shader-layout.d.ts +23 -3
  48. package/dist/adapter/types/shader-layout.d.ts.map +1 -1
  49. package/dist/adapter/types/uniforms.d.ts +4 -0
  50. package/dist/adapter/types/uniforms.d.ts.map +1 -0
  51. package/dist/{lib/compiler-log → adapter-utils}/format-compiler-log.d.ts +1 -1
  52. package/dist/adapter-utils/format-compiler-log.d.ts.map +1 -0
  53. package/dist/{adapter/attribute-utils → adapter-utils}/get-attribute-from-layouts.d.ts +4 -11
  54. package/dist/adapter-utils/get-attribute-from-layouts.d.ts.map +1 -0
  55. package/dist/{adapter/attribute-utils → adapter-utils}/get-attribute-from-layouts.js +10 -30
  56. package/dist/adapter-utils/is-uniform-value.d.ts +3 -0
  57. package/dist/adapter-utils/is-uniform-value.d.ts.map +1 -0
  58. package/dist/adapter-utils/is-uniform-value.js +7 -0
  59. package/dist/dist.dev.js +266 -588
  60. package/dist/dist.min.js +4 -4
  61. package/dist/{adapter/type-utils → gpu-type-utils}/decode-attribute-type.d.ts +3 -3
  62. package/dist/gpu-type-utils/decode-attribute-type.d.ts.map +1 -0
  63. package/dist/{adapter/type-utils → gpu-type-utils}/decode-data-type.d.ts +1 -1
  64. package/dist/gpu-type-utils/decode-data-type.d.ts.map +1 -0
  65. package/dist/{adapter/type-utils → gpu-type-utils}/decode-shader-types.d.ts +1 -1
  66. package/dist/gpu-type-utils/decode-shader-types.d.ts.map +1 -0
  67. package/dist/{adapter/type-utils → gpu-type-utils}/decode-shader-types.js +0 -2
  68. package/dist/{adapter/type-utils → gpu-type-utils}/decode-texture-format.d.ts +2 -2
  69. package/dist/gpu-type-utils/decode-texture-format.d.ts.map +1 -0
  70. package/dist/{adapter/type-utils → gpu-type-utils}/decode-vertex-format.d.ts +1 -1
  71. package/dist/gpu-type-utils/decode-vertex-format.d.ts.map +1 -0
  72. package/dist/gpu-type-utils/shader-types.d.ts.map +1 -0
  73. package/dist/{adapter/types → gpu-type-utils}/texture-formats.d.ts +1 -1
  74. package/dist/gpu-type-utils/texture-formats.d.ts.map +1 -0
  75. package/dist/{adapter/type-utils → gpu-type-utils}/vertex-format-from-attribute.d.ts +2 -2
  76. package/dist/gpu-type-utils/vertex-format-from-attribute.d.ts.map +1 -0
  77. package/dist/gpu-type-utils/vertex-formats.d.ts.map +1 -0
  78. package/dist/{adapter/type-utils → gpu-type-utils}/wgsl-utils.d.ts +1 -1
  79. package/dist/gpu-type-utils/wgsl-utils.d.ts.map +1 -0
  80. package/dist/index.cjs +190 -411
  81. package/dist/index.cjs.map +4 -4
  82. package/dist/index.d.ts +28 -42
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +19 -36
  85. package/dist/init.js +1 -1
  86. package/dist/{lib/uniforms → portable}/uniform-block.d.ts +3 -3
  87. package/dist/portable/uniform-block.d.ts.map +1 -0
  88. package/dist/{lib/uniforms → portable}/uniform-block.js +2 -2
  89. package/dist/{lib/uniforms → portable}/uniform-buffer-layout.d.ts +2 -2
  90. package/dist/portable/uniform-buffer-layout.d.ts.map +1 -0
  91. package/dist/{lib/uniforms → portable}/uniform-buffer-layout.js +6 -7
  92. package/dist/{lib/uniforms → portable}/uniform-store.d.ts +4 -4
  93. package/dist/portable/uniform-store.d.ts.map +1 -0
  94. package/dist/{lib/uniforms → portable}/uniform-store.js +11 -9
  95. package/dist/types.d.ts +0 -10
  96. package/dist/types.d.ts.map +1 -1
  97. package/dist/utils/array-equal.d.ts.map +1 -1
  98. package/dist/utils/array-equal.js +6 -7
  99. package/dist/utils/array-utils-flat.d.ts +1 -7
  100. package/dist/utils/array-utils-flat.d.ts.map +1 -1
  101. package/dist/utils/array-utils-flat.js +0 -23
  102. package/dist/utils/is-array.d.ts +2 -2
  103. package/dist/utils/is-array.d.ts.map +1 -1
  104. package/dist/utils/is-array.js +2 -2
  105. package/dist/utils/uid.d.ts +7 -0
  106. package/dist/utils/uid.d.ts.map +1 -0
  107. package/dist/utils/{utils.js → uid.js} +0 -11
  108. package/package.json +5 -5
  109. package/src/adapter/canvas-context.ts +6 -0
  110. package/src/adapter/device.ts +34 -31
  111. package/src/{lib → adapter}/luma.ts +9 -9
  112. package/src/adapter/resources/buffer.ts +5 -5
  113. package/src/adapter/resources/command-encoder.ts +1 -1
  114. package/src/adapter/resources/compute-pass.ts +3 -3
  115. package/src/adapter/resources/compute-pipeline.ts +6 -3
  116. package/src/adapter/resources/external-texture.ts +2 -2
  117. package/src/adapter/resources/framebuffer.ts +5 -92
  118. package/src/adapter/resources/query-set.ts +2 -2
  119. package/src/adapter/resources/render-pass.ts +11 -7
  120. package/src/adapter/resources/render-pipeline.ts +3 -6
  121. package/src/adapter/resources/resource.ts +7 -7
  122. package/src/adapter/resources/shader.ts +18 -11
  123. package/src/adapter/resources/texture-view.ts +5 -5
  124. package/src/adapter/resources/texture.ts +226 -77
  125. package/src/adapter/resources/transform-feedback.ts +1 -1
  126. package/src/adapter/resources/vertex-array.ts +7 -3
  127. package/src/adapter/types/{types.ts → attachments.ts} +8 -17
  128. package/src/adapter/types/buffer-layout.ts +1 -1
  129. package/src/adapter/types/parameters.ts +10 -14
  130. package/src/adapter/types/shader-layout.ts +31 -29
  131. package/src/adapter/types/uniforms.ts +10 -0
  132. package/src/{lib/compiler-log → adapter-utils}/format-compiler-log.ts +1 -1
  133. package/src/{adapter/attribute-utils → adapter-utils}/get-attribute-from-layouts.ts +18 -42
  134. package/src/adapter-utils/is-uniform-value.ts +10 -0
  135. package/src/{adapter/type-utils → gpu-type-utils}/decode-attribute-type.ts +3 -3
  136. package/src/{adapter/type-utils → gpu-type-utils}/decode-data-type.ts +1 -1
  137. package/src/{adapter/type-utils → gpu-type-utils}/decode-shader-types.ts +1 -3
  138. package/src/{adapter/type-utils → gpu-type-utils}/decode-texture-format.ts +2 -2
  139. package/src/{adapter/type-utils → gpu-type-utils}/decode-vertex-format.ts +1 -1
  140. package/src/{adapter/types → gpu-type-utils}/texture-formats.ts +1 -1
  141. package/src/{adapter/type-utils → gpu-type-utils}/vertex-format-from-attribute.ts +2 -2
  142. package/src/{adapter/type-utils → gpu-type-utils}/wgsl-utils.ts +1 -1
  143. package/src/index.ts +69 -84
  144. package/src/{lib/uniforms → portable}/uniform-block.ts +5 -5
  145. package/src/{lib/uniforms → portable}/uniform-buffer-layout.ts +9 -9
  146. package/src/{lib/uniforms → portable}/uniform-store.ts +14 -12
  147. package/src/types.ts +0 -12
  148. package/src/utils/array-equal.ts +6 -7
  149. package/src/utils/array-utils-flat.ts +1 -31
  150. package/src/utils/is-array.ts +4 -4
  151. package/src/utils/{utils.ts → uid.ts} +0 -12
  152. package/dist/adapter/attribute-utils/get-attribute-from-layouts.d.ts.map +0 -1
  153. package/dist/adapter/type-utils/decode-attribute-type.d.ts.map +0 -1
  154. package/dist/adapter/type-utils/decode-data-type.d.ts.map +0 -1
  155. package/dist/adapter/type-utils/decode-shader-types.d.ts.map +0 -1
  156. package/dist/adapter/type-utils/decode-texture-format.d.ts.map +0 -1
  157. package/dist/adapter/type-utils/decode-vertex-format.d.ts.map +0 -1
  158. package/dist/adapter/type-utils/vertex-format-from-attribute.d.ts.map +0 -1
  159. package/dist/adapter/type-utils/wgsl-utils.d.ts.map +0 -1
  160. package/dist/adapter/types/accessor.d.ts +0 -23
  161. package/dist/adapter/types/accessor.d.ts.map +0 -1
  162. package/dist/adapter/types/shader-types.d.ts.map +0 -1
  163. package/dist/adapter/types/texture-formats.d.ts.map +0 -1
  164. package/dist/adapter/types/types.d.ts.map +0 -1
  165. package/dist/adapter/types/vertex-formats.d.ts.map +0 -1
  166. package/dist/lib/compiler-log/compiler-message.d.ts.map +0 -1
  167. package/dist/lib/compiler-log/format-compiler-log.d.ts.map +0 -1
  168. package/dist/lib/compiler-log/get-shader-info.d.ts +0 -9
  169. package/dist/lib/compiler-log/get-shader-info.d.ts.map +0 -1
  170. package/dist/lib/compiler-log/get-shader-info.js +0 -29
  171. package/dist/lib/luma.d.ts.map +0 -1
  172. package/dist/lib/uniforms/uniform-block.d.ts.map +0 -1
  173. package/dist/lib/uniforms/uniform-buffer-layout.d.ts.map +0 -1
  174. package/dist/lib/uniforms/uniform-store.d.ts.map +0 -1
  175. package/dist/lib/uniforms/uniform.d.ts +0 -10
  176. package/dist/lib/uniforms/uniform.d.ts.map +0 -1
  177. package/dist/lib/uniforms/uniform.js +0 -20
  178. package/dist/utils/assert.d.ts +0 -2
  179. package/dist/utils/assert.d.ts.map +0 -1
  180. package/dist/utils/assert.js +0 -10
  181. package/dist/utils/cast.d.ts +0 -3
  182. package/dist/utils/cast.d.ts.map +0 -1
  183. package/dist/utils/cast.js +0 -7
  184. package/dist/utils/check-props.d.ts +0 -7
  185. package/dist/utils/check-props.d.ts.map +0 -1
  186. package/dist/utils/check-props.js +0 -36
  187. package/dist/utils/deep-equal.d.ts +0 -9
  188. package/dist/utils/deep-equal.d.ts.map +0 -1
  189. package/dist/utils/deep-equal.js +0 -50
  190. package/dist/utils/format-value.d.ts +0 -7
  191. package/dist/utils/format-value.d.ts.map +0 -1
  192. package/dist/utils/format-value.js +0 -39
  193. package/dist/utils/load-file.d.ts +0 -35
  194. package/dist/utils/load-file.d.ts.map +0 -1
  195. package/dist/utils/load-file.js +0 -74
  196. package/dist/utils/random.d.ts +0 -5
  197. package/dist/utils/random.d.ts.map +0 -1
  198. package/dist/utils/random.js +0 -18
  199. package/dist/utils/request-animation-frame.d.ts +0 -3
  200. package/dist/utils/request-animation-frame.d.ts.map +0 -1
  201. package/dist/utils/request-animation-frame.js +0 -16
  202. package/dist/utils/stub-methods.d.ts +0 -2
  203. package/dist/utils/stub-methods.d.ts.map +0 -1
  204. package/dist/utils/stub-methods.js +0 -19
  205. package/dist/utils/utils.d.ts +0 -9
  206. package/dist/utils/utils.d.ts.map +0 -1
  207. package/src/adapter/types/accessor.ts +0 -37
  208. package/src/lib/compiler-log/get-shader-info.ts +0 -42
  209. package/src/lib/uniforms/uniform.ts +0 -31
  210. package/src/utils/assert.ts +0 -11
  211. package/src/utils/cast.ts +0 -8
  212. package/src/utils/check-props.ts +0 -82
  213. package/src/utils/deep-equal.ts +0 -51
  214. package/src/utils/format-value.ts +0 -47
  215. package/src/utils/load-file.ts +0 -91
  216. package/src/utils/random.ts +0 -21
  217. package/src/utils/request-animation-frame.ts +0 -19
  218. package/src/utils/stub-methods.ts +0 -29
  219. /package/dist/adapter/types/{accessor.js → attachments.js} +0 -0
  220. /package/dist/{lib/compiler-log → adapter/types}/compiler-message.d.ts +0 -0
  221. /package/dist/{lib/compiler-log → adapter/types}/compiler-message.js +0 -0
  222. /package/dist/adapter/types/{shader-types.js → uniforms.js} +0 -0
  223. /package/dist/{lib/compiler-log → adapter-utils}/format-compiler-log.js +0 -0
  224. /package/dist/{adapter/type-utils → gpu-type-utils}/decode-attribute-type.js +0 -0
  225. /package/dist/{adapter/type-utils → gpu-type-utils}/decode-data-type.js +0 -0
  226. /package/dist/{adapter/type-utils → gpu-type-utils}/decode-texture-format.js +0 -0
  227. /package/dist/{adapter/type-utils → gpu-type-utils}/decode-vertex-format.js +0 -0
  228. /package/dist/{adapter/types → gpu-type-utils}/shader-types.d.ts +0 -0
  229. /package/dist/{adapter/types/texture-formats.js → gpu-type-utils/shader-types.js} +0 -0
  230. /package/dist/{adapter/types/types.js → gpu-type-utils/texture-formats.js} +0 -0
  231. /package/dist/{adapter/type-utils → gpu-type-utils}/vertex-format-from-attribute.js +0 -0
  232. /package/dist/{adapter/types → gpu-type-utils}/vertex-formats.d.ts +0 -0
  233. /package/dist/{adapter/types → gpu-type-utils}/vertex-formats.js +0 -0
  234. /package/dist/{adapter/type-utils → gpu-type-utils}/wgsl-utils.js +0 -0
  235. /package/src/{lib/compiler-log → adapter/types}/compiler-message.ts +0 -0
  236. /package/src/{adapter/types → gpu-type-utils}/shader-types.ts +0 -0
  237. /package/src/{adapter/types → gpu-type-utils}/vertex-formats.ts +0 -0
@@ -5,8 +5,8 @@
5
5
  import {VERSION} from '../init';
6
6
  import {StatsManager, lumaStats} from '../utils/stats-manager';
7
7
  import {log} from '../utils/log';
8
- import {uid} from '../utils/utils';
9
- import type {TextureFormat} from './types/texture-formats';
8
+ import {uid} from '../utils/uid';
9
+ import type {TextureFormat} from '../gpu-type-utils//texture-formats';
10
10
  import type {CanvasContext, CanvasContextProps} from './canvas-context';
11
11
  import type {BufferProps} from './resources/buffer';
12
12
  import {Buffer} from './resources/buffer';
@@ -14,7 +14,7 @@ import type {RenderPipeline, RenderPipelineProps} from './resources/render-pipel
14
14
  import type {ComputePipeline, ComputePipelineProps} from './resources/compute-pipeline';
15
15
  import type {Sampler, SamplerProps} from './resources/sampler';
16
16
  import type {Shader, ShaderProps} from './resources/shader';
17
- import type {Texture, TextureProps, TextureData} from './resources/texture';
17
+ import type {Texture, TextureProps} from './resources/texture';
18
18
  import type {ExternalTexture, ExternalTextureProps} from './resources/external-texture';
19
19
  import type {Framebuffer, FramebufferProps} from './resources/framebuffer';
20
20
  import type {RenderPass, RenderPassProps} from './resources/render-pass';
@@ -24,7 +24,7 @@ import type {VertexArray, VertexArrayProps} from './resources/vertex-array';
24
24
  import type {TransformFeedback, TransformFeedbackProps} from './resources/transform-feedback';
25
25
  import type {QuerySet, QuerySetProps} from './resources/query-set';
26
26
 
27
- import {isTextureFormatCompressed} from './type-utils/decode-texture-format';
27
+ import {isTextureFormatCompressed} from '../gpu-type-utils/decode-texture-format';
28
28
 
29
29
  /**
30
30
  * Identifies the GPU vendor and driver.
@@ -131,7 +131,7 @@ export class DeviceFeatures {
131
131
  }
132
132
 
133
133
  has(feature: DeviceFeature): boolean {
134
- return !this.disabledFeatures[feature] && this.features.has(feature);
134
+ return !this.disabledFeatures?.[feature] && this.features.has(feature);
135
135
  }
136
136
  }
137
137
 
@@ -219,24 +219,26 @@ export type DeviceProps = {
219
219
  /** Error handling */
220
220
  onError?: (error: Error) => unknown;
221
221
 
222
- // DEBUG SETTINGS
222
+ // @deprecated Attach to existing context. Rename to handle? Use Device.attach?
223
+ gl?: WebGL2RenderingContext | null;
223
224
 
225
+ // DEBUG SETTINGS
224
226
  /** WebGL: Instrument WebGL2RenderingContext (at the expense of performance) */
225
227
  debug?: boolean;
226
228
  /** Break on WebGL functions matching these strings */
227
229
  break?: string[];
228
230
  /** WebGL: Initialize the SpectorJS WebGL debugger */
229
231
  spector?: boolean;
232
+
233
+ // EXPERIMENTAL SETTINGS
234
+ /** Set to false to disable WebGL state management instrumentation: TODO- Unclear if still supported / useful */
235
+ manageState?: boolean;
230
236
  /** Initialize all features on startup */
231
237
  initalizeFeatures?: boolean;
232
238
  /** Disable specific features */
233
239
  disabledFeatures?: Partial<Record<DeviceFeature, boolean>>;
234
-
235
- /** TODO- Unclear if still supported: Set to false to disable WebGL state management instrumentation */
236
- manageState?: boolean;
237
-
238
- // @deprecated Attach to existing context. Rename to handle? Use Device.attach?
239
- gl?: WebGL2RenderingContext | null;
240
+ /** Never destroy cached shaders and pipelines */
241
+ _factoryDestroyPolicy?: 'unused' | 'never';
240
242
  };
241
243
 
242
244
  /**
@@ -250,17 +252,12 @@ export abstract class Device {
250
252
  manageState: true,
251
253
  width: 800, // width are height are only used by headless gl
252
254
  height: 600,
253
-
254
255
  requestMaxLimits: true,
255
- debug: Boolean(log.get('debug')), // Instrument context (at the expense of performance)
256
- spector: Boolean(log.get('spector')), // Initialize the SpectorJS WebGL debugger
257
- break: [],
258
256
 
259
- // TODO - Change these after confirming things work as expected
260
- initalizeFeatures: true,
261
- disabledFeatures: {
262
- 'compilation-status-async-webgl': true
263
- },
257
+ // Callbacks
258
+ onError: (error: Error) => log.error(error.message),
259
+
260
+ gl: null,
264
261
 
265
262
  // alpha: undefined,
266
263
  // depth: undefined,
@@ -270,10 +267,16 @@ export abstract class Device {
270
267
  // preserveDrawingBuffer: undefined,
271
268
  // failIfMajorPerformanceCaveat: undefined
272
269
 
273
- gl: null,
270
+ debug: Boolean(log.get('debug')), // Instrument context (at the expense of performance)
271
+ spector: Boolean(log.get('spector')), // Initialize the SpectorJS WebGL debugger
272
+ break: (log.get('break') as string[]) || [],
274
273
 
275
- // Callbacks
276
- onError: (error: Error) => log.error(error.message)
274
+ // TODO - Change these after confirming things work as expected
275
+ initalizeFeatures: true,
276
+ disabledFeatures: {
277
+ 'compilation-status-async-webgl': true
278
+ },
279
+ _factoryDestroyPolicy: 'unused'
277
280
  };
278
281
 
279
282
  get [Symbol.toStringTag](): string {
@@ -343,6 +346,11 @@ export abstract class Device {
343
346
  return false;
344
347
  }
345
348
 
349
+ /** Report error (normally for unhandled device errors) */
350
+ error(error: Error): void {
351
+ this.props.onError(error);
352
+ }
353
+
346
354
  // Canvas context
347
355
 
348
356
  /** Default / primary canvas context. Can be null as WebGPU devices can be created without a CanvasContext */
@@ -370,14 +378,9 @@ export abstract class Device {
370
378
  /** Create a texture */
371
379
  abstract _createTexture(props: TextureProps): Texture;
372
380
  createTexture(props: TextureProps): Texture;
373
- createTexture(data: Promise<TextureData>): Texture;
374
- createTexture(url: string): Texture;
381
+ // createTexture(data: Promise<TextureData>): Texture;
375
382
 
376
- createTexture(props: TextureProps | Promise<TextureData> | string): Texture {
377
- // Signature: new Texture2D(gl, url | Promise)
378
- if (props instanceof Promise || typeof props === 'string') {
379
- props = {data: props};
380
- }
383
+ createTexture(props: TextureProps): Texture {
381
384
  return this._createTexture(props);
382
385
  }
383
386
 
@@ -3,12 +3,11 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {Log} from '@probe.gl/log';
6
- import type {DeviceProps} from '../adapter/device';
7
- import {Device} from '../adapter/device';
6
+ import type {DeviceProps} from './device';
7
+ import {Device} from './device';
8
8
  import {StatsManager} from '../utils/stats-manager';
9
9
  import {lumaStats} from '../utils/stats-manager';
10
10
  import {log} from '../utils/log';
11
- import {assert} from '../utils/assert';
12
11
 
13
12
  const deviceMap = new Map<string, typeof Device>();
14
13
 
@@ -46,7 +45,6 @@ export class luma {
46
45
 
47
46
  static registerDevices(deviceClasses: any[] /* : typeof Device */): void {
48
47
  for (const deviceClass of deviceClasses) {
49
- assert(deviceClass.type && deviceClass.isSupported && deviceClass.create);
50
48
  deviceMap.set(deviceClass.type, deviceClass);
51
49
  }
52
50
  }
@@ -67,7 +65,7 @@ export class luma {
67
65
  }
68
66
 
69
67
  static setDefaultDeviceProps(props: CreateDeviceProps): void {
70
- Object.assign(Device.defaultProps, props);
68
+ Object.assign(luma.defaultProps, props);
71
69
  }
72
70
 
73
71
  /** Attach to an existing GPU API handle (WebGL2RenderingContext or GPUDevice). */
@@ -105,23 +103,25 @@ export class luma {
105
103
 
106
104
  /** Creates a device. Asynchronously. */
107
105
  static async createDevice(props: CreateDeviceProps = {}): Promise<Device> {
108
- props = {...Device.defaultProps, ...props};
106
+ props = {...luma.defaultProps, ...props};
109
107
  if (props.gl) {
110
108
  props.type = 'webgl';
111
109
  }
112
110
 
113
111
  const devices = getDeviceMap(props.devices) || deviceMap;
114
112
 
113
+ let WebGPUDevice;
114
+ let WebGLDevice;
115
115
  switch (props.type) {
116
116
  case 'webgpu':
117
- let WebGPUDevice = devices.get('webgpu') as any;
117
+ WebGPUDevice = devices.get('webgpu') as any;
118
118
  if (WebGPUDevice) {
119
119
  return await WebGPUDevice.create(props);
120
120
  }
121
121
  break;
122
122
 
123
123
  case 'webgl':
124
- let WebGLDevice = devices.get('webgl') as any;
124
+ WebGLDevice = devices.get('webgl') as any;
125
125
  if (WebGLDevice) {
126
126
  return await WebGLDevice.create(props);
127
127
  }
@@ -139,7 +139,7 @@ export class luma {
139
139
  if (WebGPUDevice?.isSupported?.()) {
140
140
  return await WebGPUDevice.create(props);
141
141
  }
142
- WebGLDevice = devices.get('webgl');
142
+ WebGLDevice = devices.get('webgl') as any;
143
143
  if (WebGLDevice?.isSupported?.()) {
144
144
  return await WebGLDevice.create(props);
145
145
  }
@@ -107,17 +107,17 @@ export abstract class Buffer extends Resource<BufferProps> {
107
107
  byteOffset: number,
108
108
  byteLength: number
109
109
  ): void {
110
- const buffer: ArrayBuffer | null = ArrayBuffer.isView(data) ? data.buffer : data;
110
+ const arrayBuffer: ArrayBuffer | null = ArrayBuffer.isView(data) ? data.buffer : data;
111
111
  const debugDataLength = Math.min(
112
112
  data ? data.byteLength : byteLength,
113
113
  Buffer.DEBUG_DATA_MAX_LENGTH
114
114
  );
115
- if (data === null) {
115
+ if (arrayBuffer === null) {
116
116
  this.debugData = new ArrayBuffer(debugDataLength);
117
- } else if (byteOffset === 0 && byteLength === data.byteLength) {
118
- this.debugData = buffer.slice(0, debugDataLength);
117
+ } else if (byteOffset === 0 && byteLength === arrayBuffer.byteLength) {
118
+ this.debugData = arrayBuffer.slice(0, debugDataLength);
119
119
  } else {
120
- this.debugData = buffer.slice(byteOffset, byteOffset + debugDataLength);
120
+ this.debugData = arrayBuffer.slice(byteOffset, byteOffset + debugDataLength);
121
121
  }
122
122
  }
123
123
  }
@@ -133,7 +133,7 @@ export type CommandEncoderProps = ResourceProps & {
133
133
  export abstract class CommandEncoder extends Resource<CommandEncoderProps> {
134
134
  static override defaultProps: Required<CommandEncoderProps> = {
135
135
  ...Resource.defaultProps,
136
- measureExecutionTime: undefined
136
+ measureExecutionTime: undefined!
137
137
  };
138
138
 
139
139
  override get [Symbol.toStringTag](): string {
@@ -20,9 +20,9 @@ export type ComputePassProps = ResourceProps & {
20
20
  export abstract class ComputePass extends Resource<ComputePassProps> {
21
21
  static override defaultProps: Required<ComputePassProps> = {
22
22
  ...Resource.defaultProps,
23
- timestampQuerySet: undefined,
24
- beginTimestampIndex: undefined,
25
- endTimestampIndex: undefined
23
+ timestampQuerySet: undefined!,
24
+ beginTimestampIndex: undefined!,
25
+ endTimestampIndex: undefined!
26
26
  };
27
27
 
28
28
  override get [Symbol.toStringTag](): string {
@@ -28,10 +28,10 @@ export type ComputePipelineProps = ResourceProps & {
28
28
  export abstract class ComputePipeline extends Resource<ComputePipelineProps> {
29
29
  static override defaultProps: Required<ComputePipelineProps> = {
30
30
  ...Resource.defaultProps,
31
- shader: undefined,
32
- entryPoint: undefined,
31
+ shader: undefined!,
32
+ entryPoint: undefined!,
33
33
  constants: {},
34
- shaderLayout: undefined
34
+ shaderLayout: undefined!
35
35
  };
36
36
 
37
37
  override get [Symbol.toStringTag](): string {
@@ -39,9 +39,12 @@ export abstract class ComputePipeline extends Resource<ComputePipelineProps> {
39
39
  }
40
40
 
41
41
  hash: string = '';
42
+ /** The merged shader layout */
43
+ shaderLayout: ComputeShaderLayout;
42
44
 
43
45
  constructor(device: Device, props: ComputePipelineProps) {
44
46
  super(device, props, ComputePipeline.defaultProps);
47
+ this.shaderLayout = props.shaderLayout!;
45
48
  }
46
49
 
47
50
  /**
@@ -6,13 +6,13 @@ import type {Device} from '../device';
6
6
  import {Resource, ResourceProps} from './resource';
7
7
 
8
8
  export type ExternalTextureProps = ResourceProps & {
9
- source: HTMLVideoElement | null;
9
+ source: HTMLVideoElement; // | null;
10
10
  colorSpace?: 'srgb';
11
11
  };
12
12
  export abstract class ExternalTexture extends Resource<ExternalTextureProps> {
13
13
  static override defaultProps: Required<ExternalTextureProps> = {
14
14
  ...Resource.defaultProps,
15
- source: null,
15
+ source: undefined!,
16
16
  colorSpace: 'srgb'
17
17
  };
18
18
 
@@ -6,7 +6,7 @@ import type {
6
6
  ColorTextureFormat,
7
7
  DepthStencilTextureFormat,
8
8
  TextureFormat
9
- } from '../types/texture-formats';
9
+ } from '../../gpu-type-utils/texture-formats';
10
10
  import type {Device} from '../device';
11
11
  import {Resource, ResourceProps} from './resource';
12
12
  import {Texture} from './texture';
@@ -42,17 +42,14 @@ export abstract class Framebuffer extends Resource<FramebufferProps> {
42
42
  /** Height of all attachments in this framebuffer */
43
43
  height: number;
44
44
  /** Color attachments */
45
- colorAttachments: TextureView[] = [];
45
+ abstract colorAttachments: TextureView[];
46
46
  /** Depth-stencil attachment, if provided */
47
- depthStencilAttachment: TextureView | null = null;
47
+ abstract depthStencilAttachment: TextureView | null;
48
48
 
49
49
  constructor(device: Device, props: FramebufferProps = {}) {
50
50
  super(device, props, Framebuffer.defaultProps);
51
51
  this.width = this.props.width;
52
52
  this.height = this.props.height;
53
-
54
- // NOTE: call from subclass constructor as we cannot call overridden methods here (subclass not yet constructed)
55
- // this.autoCreateAttachmentTextures();
56
53
  }
57
54
 
58
55
  /**
@@ -139,7 +136,7 @@ export abstract class Framebuffer extends Resource<FramebufferProps> {
139
136
  for (let i = 0; i < this.colorAttachments.length; ++i) {
140
137
  if (this.colorAttachments[i]) {
141
138
  const resizedTexture = this.device._createTexture({
142
- ...this.colorAttachments[i].props,
139
+ ...this.colorAttachments[i].texture.props,
143
140
  width,
144
141
  height
145
142
  });
@@ -151,7 +148,7 @@ export abstract class Framebuffer extends Resource<FramebufferProps> {
151
148
 
152
149
  if (this.depthStencilAttachment) {
153
150
  const resizedTexture = this.device._createTexture({
154
- ...this.depthStencilAttachment.props,
151
+ ...this.depthStencilAttachment.texture.props,
155
152
  width,
156
153
  height
157
154
  });
@@ -161,87 +158,3 @@ export abstract class Framebuffer extends Resource<FramebufferProps> {
161
158
  }
162
159
  }
163
160
  }
164
-
165
- // TODO - remove if not needed
166
-
167
- // Create a color attachment for WebGL *
168
- // protected override createColorTexture(colorAttachment: Required<ColorAttachment>): Required<ColorAttachment> {
169
- // return this.device._createTexture({
170
- // id: `${this.id}-color`,
171
- // data: null, // reserves texture memory, but texels are undefined
172
- // format,
173
- // // type: GL.UNSIGNED_BYTE,
174
- // width: this.width,
175
- // height: this.height,
176
- // // Note: Mipmapping can be disabled by texture resource when we resize the texture
177
- // // to a non-power-of-two dimenstion (NPOT texture) under WebGL1. To have consistant
178
- // // behavior we always disable mipmaps.
179
- // mipmaps: false,
180
- // // Set MIN and MAG filtering parameters so mipmaps are not used in sampling.
181
- // // Use LINEAR so subpixel algos like fxaa work.
182
- // // Set WRAP modes that support NPOT textures too.
183
- // sampler: {
184
- // minFilter: 'linear',
185
- // magFilter: 'linear',
186
- // addressModeU: 'clamp-to-edge',
187
- // addressModeV: 'clamp-to-edge'
188
- // }
189
- // // parameters: {
190
- // // [GL.TEXTURE_MIN_FILTER]: GL.LINEAR,
191
- // // [GL.TEXTURE_MAG_FILTER]: GL.LINEAR,
192
- // // [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
193
- // // [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE
194
- // // }
195
- // });
196
- // }
197
-
198
- // /** Returns fully populated attachment object. */
199
- // protected normalizeColorAttachment(
200
- // attachment: Texture | ColorTextureFormat
201
- // ): Required<ColorAttachment> {
202
-
203
- // const COLOR_ATTACHMENT_DEFAULTS: Required<ColorAttachment> = {
204
- // texture: undefined!,
205
- // format: undefined!,
206
- // clearValue: [0.0, 0.0, 0.0, 0.0],
207
- // loadOp: 'clear',
208
- // storeOp: 'store'
209
- // };
210
-
211
- // if (attachment instanceof Texture) {
212
- // return {...COLOR_ATTACHMENT_DEFAULTS, texture: attachment};
213
- // }
214
- // if (typeof attachment === 'string') {
215
- // return {...COLOR_ATTACHMENT_DEFAULTS, format: attachment};
216
- // }
217
- // return {...COLOR_ATTACHMENT_DEFAULTS, ...attachment};
218
- // }
219
-
220
- // /** Wraps texture inside fully populated attachment object. */
221
- // protected normalizeDepthStencilAttachment(
222
- // attachment: DepthStencilAttachment | Texture | DepthStencilTextureFormat
223
- // ): Required<DepthStencilAttachment> {
224
- // const DEPTH_STENCIL_ATTACHMENT_DEFAULTS: Required<DepthStencilAttachment> = {
225
- // texture: undefined!,
226
- // format: undefined!,
227
-
228
- // depthClearValue: 1.0,
229
- // depthLoadOp: 'clear',
230
- // depthStoreOp: 'store',
231
- // depthReadOnly: false,
232
-
233
- // stencilClearValue: 0,
234
- // stencilLoadOp: 'clear',
235
- // stencilStoreOp: 'store',
236
- // stencilReadOnly: false
237
- // };
238
-
239
- // if (typeof attachment === 'string') {
240
- // return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, format: attachment};
241
- // }
242
- // // @ts-expect-error attachment instanceof Texture doesn't cover Renderbuffer
243
- // if (attachment.handle || attachment instanceof Texture) {
244
- // return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, texture: attachment as Texture};
245
- // }
246
- // return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, ...attachment};
247
- // }
@@ -27,8 +27,8 @@ export type QuerySetProps = ResourceProps & {
27
27
  export abstract class QuerySet extends Resource<QuerySetProps> {
28
28
  static override defaultProps: Required<QuerySetProps> = {
29
29
  ...Resource.defaultProps,
30
- type: undefined,
31
- count: undefined
30
+ type: undefined!,
31
+ count: undefined!
32
32
  };
33
33
 
34
34
  get [Symbol.toStringTag](): string {
@@ -18,8 +18,14 @@ export type RenderPassProps = ResourceProps & {
18
18
  framebuffer?: Framebuffer | null;
19
19
  /** Control viewport, scissor rect, blend constant and stencil ref */
20
20
  parameters?: RenderPassParameters;
21
+
22
+ // TODO - API needs to be able to control multiple render targets
23
+
21
24
  /** Clear value for color attachment, or `load` to preserve the previous value */
22
25
  clearColor?: NumberArray | false;
26
+ /** Whether to disable / discard the output of the rasterizer */
27
+ discard?: boolean;
28
+
23
29
  /** Clear value for depth attachment, or `load` to preserve the previous value */
24
30
  clearDepth?: number | false;
25
31
  /** Clear value for stencil attachment, or `load` to preserve the previous value */
@@ -28,8 +34,6 @@ export type RenderPassProps = ResourceProps & {
28
34
  depthReadOnly?: boolean;
29
35
  /** Indicates that the stencil component is read only. */
30
36
  stencilReadOnly?: boolean;
31
- /** Whether to disable / discard the output of the rasterizer */
32
- discard?: boolean;
33
37
 
34
38
  /** QuerySet to write begin/end timestamps to */
35
39
  occlusionQuerySet?: QuerySet;
@@ -54,7 +58,7 @@ export abstract class RenderPass extends Resource<RenderPassProps> {
54
58
  static override defaultProps: Required<RenderPassProps> = {
55
59
  ...Resource.defaultProps,
56
60
  framebuffer: null,
57
- parameters: undefined,
61
+ parameters: undefined!,
58
62
  clearColor: [0, 0, 0, 0],
59
63
  clearDepth: 1,
60
64
  clearStencil: 0,
@@ -62,10 +66,10 @@ export abstract class RenderPass extends Resource<RenderPassProps> {
62
66
  stencilReadOnly: false,
63
67
  discard: false,
64
68
 
65
- occlusionQuerySet: undefined,
66
- timestampQuerySet: undefined,
67
- beginTimestampIndex: undefined,
68
- endTimestampIndex: undefined
69
+ occlusionQuerySet: undefined!,
70
+ timestampQuerySet: undefined!,
71
+ beginTimestampIndex: undefined!,
72
+ endTimestampIndex: undefined!
69
73
  };
70
74
 
71
75
  override get [Symbol.toStringTag](): string {
@@ -3,7 +3,7 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {Device} from '../device';
6
- import type {UniformValue} from '../types/types';
6
+ import type {UniformValue} from '../types/uniforms';
7
7
  import type {PrimitiveTopology, RenderPipelineParameters} from '../types/parameters';
8
8
  import type {ShaderLayout, Binding} from '../types/shader-layout';
9
9
  import type {BufferLayout} from '../types/buffer-layout';
@@ -32,10 +32,7 @@ export type RenderPipelineProps = ResourceProps & {
32
32
 
33
33
  /** Describes the attributes and bindings exposed by the pipeline shader(s). */
34
34
  shaderLayout?: ShaderLayout | null;
35
- /**
36
- * Describes the buffers accepted by this pipeline and how they are mapped to shader attributes.
37
- * A default mapping of one buffer per attribute is always created.
38
- */
35
+ /** Describes the buffers accepted by this pipeline and how they are mapped to shader attributes. */
39
36
  bufferLayout?: BufferLayout[]; // Record<string, Omit<BufferLayout, 'name'>
40
37
 
41
38
  /** Determines how vertices are read from the 'vertex' attributes */
@@ -102,7 +99,7 @@ export abstract class RenderPipeline extends Resource<RenderPipelineProps> {
102
99
 
103
100
  constructor(device: Device, props: RenderPipelineProps) {
104
101
  super(device, props, RenderPipeline.defaultProps);
105
- this.shaderLayout = this.props.shaderLayout;
102
+ this.shaderLayout = this.props.shaderLayout!;
106
103
  this.bufferLayout = this.props.bufferLayout || [];
107
104
  }
108
105
 
@@ -3,7 +3,7 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {Device} from '../device';
6
- import {uid} from '../../utils/utils';
6
+ import {uid} from '../../utils/uid';
7
7
 
8
8
  export type ResourceProps = {
9
9
  /** Name of resource, mainly for debugging purposes. A unique name will be assigned if not provided */
@@ -22,7 +22,7 @@ export abstract class Resource<Props extends ResourceProps> {
22
22
  static defaultProps: Required<ResourceProps> = {
23
23
  id: 'undefined',
24
24
  handle: undefined,
25
- userData: undefined
25
+ userData: undefined!
26
26
  };
27
27
 
28
28
  abstract get [Symbol.toStringTag](): string;
@@ -39,7 +39,7 @@ export abstract class Resource<Props extends ResourceProps> {
39
39
  /** For resources that allocate GPU memory */
40
40
  private allocatedBytes: number = 0;
41
41
  /** Attached resources will be destroyed when this resource is destroyed. Tracks auto-created "sub" resources. */
42
- private _attachedResources = new Set<Resource<unknown>>();
42
+ private _attachedResources = new Set<Resource<ResourceProps>>();
43
43
 
44
44
  /**
45
45
  * Create a new Resource. Called from Subclass
@@ -91,21 +91,21 @@ export abstract class Resource<Props extends ResourceProps> {
91
91
  * Attaches a resource. Attached resources are auto destroyed when this resource is destroyed
92
92
  * Called automatically when sub resources are auto created but can be called by application
93
93
  */
94
- attachResource(resource: Resource<unknown>): void {
94
+ attachResource(resource: Resource<ResourceProps>): void {
95
95
  this._attachedResources.add(resource);
96
96
  }
97
97
 
98
98
  /**
99
99
  * Detach an attached resource. The resource will no longer be auto-destroyed when this resource is destroyed.
100
100
  */
101
- detachResource(resource: Resource<unknown>): void {
101
+ detachResource(resource: Resource<ResourceProps>): void {
102
102
  this._attachedResources.delete(resource);
103
103
  }
104
104
 
105
105
  /**
106
106
  * Destroys a resource (only if owned), and removes from the owned (auto-destroy) list for this resource.
107
107
  */
108
- destroyAttachedResource(resource: Resource<unknown>): void {
108
+ destroyAttachedResource(resource: Resource<ResourceProps>): void {
109
109
  if (this._attachedResources.delete(resource)) {
110
110
  resource.destroy();
111
111
  }
@@ -117,7 +117,7 @@ export abstract class Resource<Props extends ResourceProps> {
117
117
  resource.destroy();
118
118
  }
119
119
  // don't remove while we are iterating
120
- this._attachedResources = new Set<Resource<unknown>>();
120
+ this._attachedResources = new Set<Resource<ResourceProps>>();
121
121
  }
122
122
 
123
123
  // PROTECTED METHODS
@@ -5,10 +5,9 @@
5
5
  import type {Device} from '../device';
6
6
  import {Resource, ResourceProps} from './resource';
7
7
  // import { log } from '../../utils/log';
8
- import {uid} from '../../utils/utils';
9
- import {CompilerMessage} from '../../lib/compiler-log/compiler-message';
10
- import {formatCompilerLog} from '../../lib/compiler-log/format-compiler-log';
11
- import {getShaderInfo} from '../../lib/compiler-log/get-shader-info';
8
+ import {uid} from '../../utils/uid';
9
+ import {CompilerMessage} from '../types/compiler-message';
10
+ import {formatCompilerLog} from '../../adapter-utils/format-compiler-log';
12
11
 
13
12
  /**
14
13
  * Properties for a Shader
@@ -36,7 +35,7 @@ export abstract class Shader extends Resource<ShaderProps> {
36
35
  static override defaultProps: Required<ShaderProps> = {
37
36
  ...Resource.defaultProps,
38
37
  language: 'auto',
39
- stage: undefined,
38
+ stage: undefined!,
40
39
  source: '',
41
40
  sourceMap: null,
42
41
  entryPoint: 'main',
@@ -101,14 +100,17 @@ export abstract class Shader extends Resource<ShaderProps> {
101
100
 
102
101
  // PRIVATE
103
102
 
104
- /** In-browser UI logging of errors */
103
+ /**
104
+ * In-browser UI logging of errors
105
+ * TODO - this HTML formatting code should not be in Device, should be pluggable
106
+ */
105
107
  protected _displayShaderLog(messages: readonly CompilerMessage[]): void {
106
108
  // Return if under Node.js / incomplete `document` polyfills
107
109
  if (typeof document === 'undefined' || !document?.createElement) {
108
110
  return;
109
111
  }
110
112
 
111
- const shaderName: string = getShaderInfo(this.source).name;
113
+ const shaderName: string = getShaderName(this.source);
112
114
  const shaderTitle: string = `${this.stage} ${shaderName}`;
113
115
  let htmlLog = formatCompilerLog(messages, this.source, {showSourceCode: 'all', html: true});
114
116
  // Show translated source if available
@@ -132,9 +134,7 @@ ${htmlLog}
132
134
  document.body.appendChild(button);
133
135
 
134
136
  const errors = document.getElementsByClassName('luma-compiler-log-error');
135
- if (errors[0]?.scrollIntoView) {
136
- errors[0].scrollIntoView();
137
- }
137
+ errors[0]?.scrollIntoView();
138
138
 
139
139
  // TODO - add a small embedded copy button (instead of main button)
140
140
  button.onclick = () => {
@@ -151,5 +151,12 @@ ${htmlLog}
151
151
 
152
152
  /** Deduce an id, from shader source, or supplied id, or shader type */
153
153
  function getShaderIdFromProps(props: ShaderProps): string {
154
- return getShaderInfo(props.source).name || props.id || uid(`unnamed ${props.stage}-shader`);
154
+ return getShaderName(props.source) || props.id || uid(`unnamed ${props.stage}-shader`);
155
+ }
156
+
157
+ /** Extracts GLSLIFY style naming of shaders: `#define SHADER_NAME ...` */
158
+ function getShaderName(shader: string, defaultName: string = 'unnamed'): string {
159
+ const SHADER_NAME_REGEXP = /#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/;
160
+ const match = SHADER_NAME_REGEXP.exec(shader);
161
+ return match ? match[1] : defaultName;
155
162
  }