@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
@@ -4,7 +4,7 @@
4
4
 
5
5
  import type {Device} from '../device';
6
6
  import type {Texture} from './texture';
7
- import type {TextureFormat} from '../types/texture-formats';
7
+ import type {TextureFormat} from '../../gpu-type-utils/texture-formats';
8
8
  import {Resource, ResourceProps} from './resource';
9
9
 
10
10
  /** Properties for initializing a texture view */
@@ -29,13 +29,13 @@ export type TextureViewProps = ResourceProps & {
29
29
  export abstract class TextureView extends Resource<TextureViewProps> {
30
30
  static override defaultProps: Required<TextureViewProps> = {
31
31
  ...Resource.defaultProps,
32
- format: undefined,
33
- dimension: undefined,
32
+ format: undefined!,
33
+ dimension: undefined!,
34
34
  aspect: 'all',
35
35
  baseMipLevel: 0,
36
- mipLevelCount: undefined,
36
+ mipLevelCount: undefined!,
37
37
  baseArrayLayer: 0,
38
- arrayLayerCount: undefined
38
+ arrayLayerCount: undefined!
39
39
  };
40
40
 
41
41
  abstract texture: Texture;
@@ -4,81 +4,138 @@
4
4
 
5
5
  import type {Device} from '../device';
6
6
  import type {TypedArray} from '../../types';
7
- import type {TextureFormat} from '../types/texture-formats';
7
+ import type {TextureFormat} from '../../gpu-type-utils/texture-formats';
8
+ import type {TextureView, TextureViewProps} from './texture-view';
8
9
  import {Resource, ResourceProps} from './resource';
9
10
  import {Sampler, SamplerProps} from './sampler';
10
- import {TextureView, TextureViewProps} from './texture-view';
11
11
 
12
- // required GPUExtent3D size;
13
- // GPUIntegerCoordinate mipLevelCount = 1;
14
- // GPUSize32 sampleCount = 1;
15
- // GPUTextureDimension dimension = "2d";
16
- // required GPUTextureFormat format;
17
- // required GPUTextureUsageFlags usage;
18
-
19
- /** Data types that can be used to initialize textures */
20
- export type TextureData = TypedArray | ArrayBuffer | Buffer | ImageBitmap | HTMLImageElement;
21
-
22
- export type CubeTextureData = Record<string, TextureData> | Record<string, Promise<TextureData>>;
12
+ /**
13
+ * These represent the main compressed texture formats
14
+ * Each format typically has a number of more specific subformats
15
+ */
16
+ export type TextureCompressionFormat =
17
+ | 'dxt'
18
+ | 'dxt-srgb'
19
+ | 'etc1'
20
+ | 'etc2'
21
+ | 'pvrtc'
22
+ | 'atc'
23
+ | 'astc'
24
+ | 'rgtc';
23
25
 
24
- export type ExternalTextureData = HTMLVideoElement;
26
+ /** Names of cube texture faces */
27
+ export type TextureCubeFace = '+X' | '-X' | '+Y' | '-Y' | '+Z' | '-Z';
25
28
 
26
- /** Abstract Texture interface */
27
- export type TextureProps = ResourceProps & {
29
+ /**
30
+ * One mip level
31
+ * Basic data structure is similar to `ImageData`
32
+ * additional optional fields can describe compressed texture data.
33
+ */
34
+ export type TextureLevelData = {
35
+ /** WebGPU style format string. Defaults to 'rgba8unorm' */
28
36
  format?: TextureFormat;
29
- dimension?: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';
30
- width?: number | undefined;
31
- height?: number | undefined;
32
- depth?: number;
33
- usage?: number;
34
-
35
- data?: TextureData | Promise<TextureData> | CubeTextureData | string | HTMLVideoElement | null;
36
- mipmaps?: boolean;
37
-
38
- mipLevels?: number;
39
- samples?: number;
40
- type?: number;
41
- compressed?: boolean;
42
-
43
- sampler?: Sampler | SamplerProps;
44
- view?: TextureViewProps;
45
- };
46
-
47
- export type WebGPUTextureProps = ResourceProps & {
37
+ data: TypedArray;
48
38
  width: number;
49
39
  height: number;
50
- depth?: number;
51
- mipLevels?: number;
52
- format?: string;
40
+
41
+ compressed?: boolean;
42
+ byteLength?: number;
43
+ hasAlpha?: boolean;
53
44
  };
54
45
 
55
46
  /**
56
- * @deprecated
57
- * @todo remove, are these even used anymore?
47
+ * Built-in data types that can be used to initialize textures
48
+ * @note WebGL supports OffscreenCanvas but seems WebGPU does not?
58
49
  */
59
- export type DeprecatedWebGLTextureProps = {
60
- /** @deprecated use props.sampler */
61
- parameters?: Record<number, number>;
62
- /** @deprecated use props.data */
63
- pixels?: any;
64
- /** @deprecated use props.format */
65
- dataFormat?: number | null;
66
- /** @deprecated rarely supported */
67
- border?: number;
68
- /** @deprecated WebGL only. */
69
- pixelStore?: object;
70
- /** @deprecated WebGL only. */
71
- textureUnit?: number;
72
- /** @deprecated WebGL only. Use dimension. */
73
- target?: number;
74
- };
50
+ export type ExternalImage =
51
+ | ImageData
52
+ | ImageBitmap
53
+ | HTMLImageElement
54
+ | HTMLVideoElement
55
+ | HTMLCanvasElement;
56
+
57
+ export type TextureLevelSource = TextureLevelData | ExternalImage;
58
+
59
+ /** Texture data can be one or more mip levels */
60
+ export type TextureData = TextureLevelData | ExternalImage | (TextureLevelData | ExternalImage)[];
61
+
62
+ /** @todo - define what data type is supported for 1D textures */
63
+ export type Texture1DData = TypedArray | TextureLevelData;
64
+
65
+ /** Texture data can be one or more mip levels */
66
+ export type Texture2DData =
67
+ | TypedArray
68
+ | TextureLevelData
69
+ | ExternalImage
70
+ | (TextureLevelData | ExternalImage)[];
71
+
72
+ /** Array of textures */
73
+ export type Texture3DData = TypedArray | TextureData[];
74
+
75
+ /** 6 face textures */
76
+ export type TextureCubeData = Record<TextureCubeFace, Texture2DData>;
77
+
78
+ /** Array of textures */
79
+ export type TextureArrayData = TextureData[];
80
+
81
+ /** Array of 6 face textures */
82
+ export type TextureCubeArrayData = Record<TextureCubeFace, TextureData>[];
83
+
84
+ type TextureDataProps =
85
+ | Texture1DProps
86
+ | Texture2DProps
87
+ | Texture3DProps
88
+ | TextureArrayProps
89
+ | TextureCubeProps
90
+ | TextureCubeArrayProps;
91
+
92
+ type Texture1DProps = {dimension: '1d'; data?: Texture1DData | null};
93
+ type Texture2DProps = {dimension?: '2d'; data?: Texture2DData | null};
94
+ type Texture3DProps = {dimension: '3d'; data?: Texture3DData | null};
95
+ type TextureArrayProps = {dimension: '2d-array'; data?: TextureArrayData | null};
96
+ type TextureCubeProps = {dimension: 'cube'; data?: TextureCubeData | null};
97
+ type TextureCubeArrayProps = {dimension: 'cube-array'; data: TextureCubeArrayData | null};
98
+
99
+ /** Texture properties */
100
+ export type TextureProps = ResourceProps &
101
+ TextureDataProps & {
102
+ format?: TextureFormat;
103
+ width?: number | undefined;
104
+ height?: number | undefined;
105
+ depth?: number;
106
+ usage?: number;
107
+
108
+ /** How many mip levels */
109
+ mipLevels?: number | 'pyramid';
110
+ /** Multi sampling */
111
+ samples?: number;
112
+
113
+ /** Specifying mipmaps will default mipLevels to 'pyramid' and attempt to generate mipmaps */
114
+ mipmaps?: boolean;
115
+
116
+ /** Sampler (or SamplerProps) for the default sampler for this texture. Used if no sampler provided. Note that other samplers can still be used. */
117
+ sampler?: Sampler | SamplerProps;
118
+ /** Props for the default TextureView for this texture. Note that other views can still be created and used. */
119
+ view?: TextureViewProps;
120
+
121
+ /** @deprecated - this is implicit from format */
122
+ compressed?: boolean;
123
+ };
75
124
 
76
125
  /**
77
126
  * Abstract Texture interface
78
127
  * Texture Object
79
128
  * https://gpuweb.github.io/gpuweb/#gputexture
80
129
  */
81
- export abstract class Texture<Props extends TextureProps = TextureProps> extends Resource<Props> {
130
+ export abstract class Texture extends Resource<TextureProps> {
131
+ static COPY_SRC = 0x01;
132
+ static COPY_DST = 0x02;
133
+ static TEXTURE = 0x04;
134
+ static STORAGE = 0x08;
135
+ static RENDER_ATTACHMENT = 0x10;
136
+
137
+ static CubeFaces: TextureCubeFace[] = ['+X', '-X', '+Y', '-Y', '+Z', '-Z'];
138
+
82
139
  static override defaultProps: Required<TextureProps> = {
83
140
  ...Resource.defaultProps,
84
141
  data: null,
@@ -87,25 +144,15 @@ export abstract class Texture<Props extends TextureProps = TextureProps> extends
87
144
  width: undefined!,
88
145
  height: undefined!,
89
146
  depth: 1,
90
- mipmaps: true,
91
- // type: undefined,
147
+ mipmaps: false,
92
148
  compressed: false,
93
- // mipLevels: 1,
94
149
  usage: 0,
95
- // usage: GPUTextureUsage.COPY_DST
96
150
  mipLevels: undefined!,
97
151
  samples: undefined!,
98
- type: undefined!,
99
152
  sampler: {},
100
153
  view: undefined!
101
154
  };
102
155
 
103
- static COPY_SRC = 0x01;
104
- static COPY_DST = 0x02;
105
- static TEXTURE_BINDING = 0x04;
106
- static STORAGE_BINDING = 0x08;
107
- static RENDER_ATTACHMENT = 0x10;
108
-
109
156
  override get [Symbol.toStringTag](): string {
110
157
  return 'Texture';
111
158
  }
@@ -119,34 +166,136 @@ export abstract class Texture<Props extends TextureProps = TextureProps> extends
119
166
  /** height in pixels of this texture */
120
167
  height: number;
121
168
  /** depth of this texture */
122
- readonly depth: number;
169
+ depth: number;
170
+ /** mip levels in this texture */
171
+ mipLevels: number;
123
172
 
124
173
  /** Default sampler for this texture */
125
174
  abstract sampler: Sampler;
126
-
127
175
  /** Default view for this texture */
128
176
  abstract view: TextureView;
129
177
 
130
178
  /** "Time" of last update. Monotonically increasing timestamp */
131
179
  updateTimestamp: number;
132
180
 
181
+ /** Check if data is an external image */
182
+ static isExternalImage(data: unknown): data is ExternalImage {
183
+ return (
184
+ (typeof ImageData !== 'undefined' && data instanceof ImageData) ||
185
+ (typeof ImageBitmap !== 'undefined' && data instanceof ImageBitmap) ||
186
+ (typeof HTMLImageElement !== 'undefined' && data instanceof HTMLImageElement) ||
187
+ (typeof HTMLCanvasElement !== 'undefined' && data instanceof HTMLCanvasElement) ||
188
+ (typeof HTMLVideoElement !== 'undefined' && data instanceof HTMLVideoElement)
189
+ );
190
+ }
191
+
192
+ /** Determine size (width and height) of provided image data */
193
+ static getExternalImageSize(data: ExternalImage): {width: number; height: number} | null {
194
+ if (
195
+ (typeof ImageData !== 'undefined' && data instanceof ImageData) ||
196
+ (typeof ImageBitmap !== 'undefined' && data instanceof ImageBitmap) ||
197
+ (typeof HTMLCanvasElement !== 'undefined' && data instanceof HTMLCanvasElement)
198
+ ) {
199
+ return {width: data.width, height: data.height};
200
+ }
201
+ if (typeof HTMLImageElement !== 'undefined' && data instanceof HTMLImageElement) {
202
+ return {width: data.naturalWidth, height: data.naturalHeight};
203
+ }
204
+ if (typeof HTMLVideoElement !== 'undefined' && data instanceof HTMLVideoElement) {
205
+ return {width: data.videoWidth, height: data.videoHeight};
206
+ }
207
+ return null;
208
+ }
209
+
210
+ /** Check if texture data is a typed array */
211
+ isTextureLevelData(data: TextureData): data is TextureLevelData {
212
+ const typedArray = (data as TextureLevelData)?.data;
213
+ return ArrayBuffer.isView(typedArray);
214
+ }
215
+
216
+ /** Get the size of the texture described by the provided TextureData */
217
+ getTextureDataSize(
218
+ data: TextureData | TextureCubeData | TextureArrayData | TextureCubeArrayData | TypedArray
219
+ ): {width: number; height: number} | null {
220
+ if (!data) {
221
+ return null;
222
+ }
223
+ if (ArrayBuffer.isView(data)) {
224
+ return null;
225
+ }
226
+ // Recurse into arrays (array of miplevels)
227
+ if (Array.isArray(data)) {
228
+ return this.getTextureDataSize(data[0]);
229
+ }
230
+ if (Texture.isExternalImage(data)) {
231
+ return Texture.getExternalImageSize(data);
232
+ }
233
+ if (data && typeof data === 'object' && data.constructor === Object) {
234
+ const untypedData = data as unknown as Record<string, number>;
235
+ return {width: untypedData.width, height: untypedData.height};
236
+ }
237
+ throw new Error('texture size deduction failed');
238
+ }
239
+
240
+ /** Calculate the number of mip levels for a texture of width and height */
241
+ getMipLevelCount(width: number, height: number): number {
242
+ return Math.floor(Math.log2(Math.max(width, height))) + 1;
243
+ }
244
+
245
+ /** Convert luma.gl cubemap face constants to depth index */
246
+ getCubeFaceDepth(face: TextureCubeFace): number {
247
+ // prettier-ignore
248
+ switch (face) {
249
+ case '+X': return 0;
250
+ case '-X': return 1;
251
+ case '+Y': return 2;
252
+ case '-Y': return 3;
253
+ case '+Z': return 4;
254
+ case '-Z': return 5;
255
+ default: throw new Error(face);
256
+ }
257
+ }
258
+
133
259
  /** Do not use directly. Create with device.createTexture() */
134
- constructor(
135
- device: Device,
136
- props: Props,
137
- defaultProps = Texture.defaultProps as Required<Props>
138
- ) {
139
- super(device, props, defaultProps);
260
+ constructor(device: Device, props: TextureProps) {
261
+ super(device, props, Texture.defaultProps);
140
262
  this.dimension = this.props.dimension;
141
263
  this.format = this.props.format;
264
+
265
+ // Size
142
266
  this.width = this.props.width;
143
267
  this.height = this.props.height;
144
268
  this.depth = this.props.depth;
145
269
 
270
+ // Calculate size, if not provided
271
+ if (this.props.width === undefined || this.props.height === undefined) {
272
+ // @ts-ignore
273
+ const size = this.getTextureDataSize(this.props.data);
274
+ this.width = size?.width || 1;
275
+ this.height = size?.height || 1;
276
+ }
277
+
278
+ // mipLevels
279
+
280
+ // If mipmap generation is requested and mipLevels is not provided, initialize a full pyramid
281
+ if (this.props.mipmaps && this.props.mipLevels === undefined) {
282
+ this.props.mipLevels = 'pyramid';
283
+ }
284
+
285
+ // Auto-calculate the number of mip levels as a convenience
286
+ // TODO - Should we clamp to 1-getMipLevelCount?
287
+ this.mipLevels =
288
+ this.props.mipLevels === 'pyramid'
289
+ ? this.getMipLevelCount(this.width, this.height)
290
+ : this.props.mipLevels || 1;
291
+
146
292
  // TODO - perhaps this should be set on async write completion?
147
293
  this.updateTimestamp = device.incrementTimestamp();
148
294
  }
149
295
 
150
296
  /** Create a texture view for this texture */
151
- abstract createView(props?: TextureViewProps): TextureView;
297
+ abstract createView(props: TextureViewProps): TextureView;
298
+
299
+ /** Set sampler props associated with this texture */
300
+ abstract setSampler(sampler?: Sampler | SamplerProps): void;
152
301
  }
@@ -35,7 +35,7 @@ export abstract class TransformFeedback extends Resource<TransformFeedbackProps>
35
35
  return 'TransformFeedback';
36
36
  }
37
37
 
38
- constructor(device: Device, props?: TransformFeedbackProps) {
38
+ constructor(device: Device, props: TransformFeedbackProps) {
39
39
  super(device, props, TransformFeedback.defaultProps);
40
40
  }
41
41
 
@@ -6,7 +6,7 @@ import type {TypedArray} from '../../types';
6
6
  import {
7
7
  AttributeInfo,
8
8
  getAttributeInfosByLocation
9
- } from '../attribute-utils/get-attribute-from-layouts';
9
+ } from '../../adapter-utils/get-attribute-from-layouts';
10
10
  import type {Device} from '../device';
11
11
  import type {Buffer} from './buffer';
12
12
  import type {RenderPass} from './render-pass';
@@ -49,9 +49,13 @@ export abstract class VertexArray extends Resource<VertexArrayProps> {
49
49
  super(device, props, VertexArray.defaultProps);
50
50
  this.maxVertexAttributes = device.limits.maxVertexAttributes;
51
51
  this.attributes = new Array(this.maxVertexAttributes).fill(null);
52
+ const {shaderLayout, bufferLayout} = props.renderPipeline || {};
53
+ if (!shaderLayout || !bufferLayout) {
54
+ throw new Error('VertexArray');
55
+ }
52
56
  this.attributeInfos = getAttributeInfosByLocation(
53
- props.renderPipeline.shaderLayout,
54
- props.renderPipeline.bufferLayout,
57
+ shaderLayout,
58
+ bufferLayout,
55
59
  this.maxVertexAttributes
56
60
  );
57
61
  }
@@ -3,20 +3,19 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import {NumberArray} from '../../types';
6
- import type {ColorTextureFormat, DepthStencilTextureFormat, TextureFormat} from './texture-formats';
7
- import type {Buffer} from '../resources/buffer';
6
+ import type {
7
+ ColorTextureFormat,
8
+ DepthStencilTextureFormat,
9
+ TextureFormat
10
+ } from '../../gpu-type-utils/texture-formats';
8
11
  import type {Texture} from '../resources/texture'; // TextureView...
12
+ import type {TextureView} from '../resources/texture-view'; // TextureView...
9
13
 
10
14
  // UNIFORMS
11
15
 
12
16
  /** Valid values for uniforms. @note boolean values get converted to 0 or 1 before setting */
13
17
  export type UniformValue = number | boolean | Readonly<NumberArray>; // Float32Array> | Readonly<Int32Array> | Readonly<Uint32Array> | Readonly<number[]>;
14
18
 
15
- // BINDINGS
16
-
17
- /** Buffer bindings */
18
- export type Binding = Texture | Buffer | {buffer: Buffer; offset?: number; size?: number};
19
-
20
19
  // BINDING LAYOUTS
21
20
 
22
21
  /** Describes a buffer binding layout */
@@ -55,14 +54,6 @@ export type BindingDeclaration =
55
54
  | TextureBindingLayout
56
55
  | StorageTextureBindingLayout;
57
56
 
58
- // TEXTURE VIEWS
59
-
60
- export type TextureView = {
61
- texture: WebGLTexture;
62
- layer?: number; // = 0
63
- level?: number; // = 0
64
- };
65
-
66
57
  // ATTACHMENTS (See Framebuffer)
67
58
 
68
59
  /**
@@ -71,7 +62,7 @@ export type TextureView = {
71
62
  */
72
63
  export type ColorAttachment = {
73
64
  /** Describes the texture subresource that will be output to for this color attachment. */
74
- texture?: Texture;
65
+ texture?: TextureView | Texture;
75
66
  /** Format of the texture resource. Used to auto create texture if not supplied */
76
67
  format?: ColorTextureFormat;
77
68
  /* Describes the texture subresource that will receive resolved output for this color attachment if multisampled. */
@@ -91,7 +82,7 @@ export type ColorAttachment = {
91
82
  */
92
83
  export type DepthStencilAttachment = {
93
84
  /** Describes the texture subresource that will be output to and read from for this depth/stencil attachment. */
94
- texture?: Texture;
85
+ texture?: TextureView | Texture;
95
86
  /** Format of the texture resource. Used to auto create texture if not supplied */
96
87
  format?: DepthStencilTextureFormat;
97
88
 
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {VertexFormat} from './vertex-formats';
5
+ import type {VertexFormat} from '../../gpu-type-utils/vertex-formats';
6
6
 
7
7
  /**
8
8
  * Provides specific details about the memory layout of the actual buffers
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {DepthStencilTextureFormat} from './texture-formats';
5
+ import {DepthStencilTextureFormat} from '../../gpu-type-utils/texture-formats';
6
6
 
7
7
  export type CompareFunction =
8
8
  | 'never'
@@ -20,12 +20,8 @@ export type PrimitiveTopology =
20
20
  | 'point-list'
21
21
  | 'line-list'
22
22
  | 'line-strip'
23
- /** @deprecated */
24
- | 'line-loop-webgl'
25
23
  | 'triangle-list'
26
- | 'triangle-strip'
27
- /** @deprecated */
28
- | 'triangle-fan-webgl';
24
+ | 'triangle-strip';
29
25
 
30
26
  export type IndexFormat = 'uint16' | 'uint32';
31
27
 
@@ -251,12 +247,12 @@ export const DEFAULT_PARAMETERS: Required<Parameters> = {
251
247
  polygonMode: 'fill',
252
248
  polygonOffsetLine: false,
253
249
 
254
- clipDistance0: undefined,
255
- clipDistance1: undefined,
256
- clipDistance2: undefined,
257
- clipDistance3: undefined,
258
- clipDistance4: undefined,
259
- clipDistance5: undefined,
260
- clipDistance6: undefined,
261
- clipDistance7: undefined
250
+ clipDistance0: undefined!,
251
+ clipDistance1: undefined!,
252
+ clipDistance2: undefined!,
253
+ clipDistance3: undefined!,
254
+ clipDistance4: undefined!,
255
+ clipDistance5: undefined!,
256
+ clipDistance6: undefined!,
257
+ clipDistance7: undefined!
262
258
  };
@@ -2,9 +2,8 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {TextureFormat} from '../types/texture-formats';
6
- import type {ShaderUniformType, ShaderAttributeType} from './shader-types';
7
- import {AccessorObject} from '../types/accessor';
5
+ import type {TextureFormat} from '../../gpu-type-utils/texture-formats';
6
+ import type {ShaderUniformType, ShaderAttributeType} from '../../gpu-type-utils/shader-types';
8
7
  import type {Buffer} from '../resources/buffer';
9
8
  import type {Sampler} from '../resources/sampler';
10
9
  import type {Texture} from '../resources/texture';
@@ -64,32 +63,6 @@ export type AttributeDeclaration = {
64
63
 
65
64
  // BINDING LAYOUTS
66
65
 
67
- /*
68
- type Binding = {
69
- binding: number;
70
- visibility: number;
71
-
72
- buffer?: {
73
- type?: 'uniform' | 'storage' | 'read-only-storage';
74
- hasDynamicOffset?: false;
75
- minBindingSize?: number;
76
- };
77
-
78
- // type = sampler
79
- samplerType?: 'filtering' | 'non-filtering' | 'comparison';
80
-
81
- // type = texture
82
- viewDimension?: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';
83
- sampleType?: 'float' | 'unfilterable-float' | 'depth' | 'sint' | 'uint';
84
- multisampled?: boolean;
85
-
86
- // type = storage
87
- viewDimension?: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';
88
- access: 'read-only' | 'write-only';
89
- format: string;
90
- };
91
- */
92
-
93
66
  /** ShaderLayout for bindings */
94
67
  export type BindingDeclaration =
95
68
  | UniformBufferBindingLayout
@@ -205,3 +178,32 @@ export type AttributeBinding = {
205
178
  location: number;
206
179
  accessor: AccessorObject;
207
180
  };
181
+
182
+ /**
183
+ * Attribute descriptor object
184
+ * @deprecated Use ShaderLayout
185
+ */
186
+ export interface AccessorObject {
187
+ buffer?: Buffer;
188
+ // format: VertexFormat;
189
+ offset?: number;
190
+ // can now be described with single WebGPU-style `format` string
191
+
192
+ //
193
+ stride?: number;
194
+
195
+ /** @deprecated - Use accessor.stepMode */
196
+ divisor?: number;
197
+
198
+ /** @deprecated - Infer from format */
199
+ type?: number;
200
+ /** @deprecated - Infer from format */
201
+ size?: number;
202
+ /** @deprecated - Infer from format */
203
+ normalized?: boolean;
204
+ /** @deprecated - Infer from format */
205
+ integer?: boolean;
206
+
207
+ /** @deprecated */
208
+ index?: number;
209
+ }
@@ -0,0 +1,10 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import {NumberArray} from '../../types';
6
+
7
+ // UNIFORMS
8
+
9
+ /** Valid values for uniforms. @note boolean values get converted to 0 or 1 before setting */
10
+ export type UniformValue = number | boolean | Readonly<NumberArray>; // Float32Array> | Readonly<Int32Array> | Readonly<Uint32Array> | Readonly<number[]>;
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {CompilerMessage} from './compiler-message';
5
+ import type {CompilerMessage} from '../adapter/types/compiler-message';
6
6
 
7
7
  /** @returns annotated errors or warnings */
8
8
  export function formatCompilerLog(