@luma.gl/core 9.0.0-beta.4 → 9.0.0-beta.6

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 (291) hide show
  1. package/dist/adapter/attribute-utils/get-attribute-from-layouts.d.ts +4 -4
  2. package/dist/adapter/attribute-utils/get-attribute-from-layouts.d.ts.map +1 -1
  3. package/dist/adapter/attribute-utils/get-attribute-from-layouts.js +138 -106
  4. package/dist/adapter/canvas-context.d.ts +2 -2
  5. package/dist/adapter/canvas-context.d.ts.map +1 -1
  6. package/dist/adapter/canvas-context.js +306 -232
  7. package/dist/adapter/device.d.ts +112 -69
  8. package/dist/adapter/device.d.ts.map +1 -1
  9. package/dist/adapter/device.js +145 -94
  10. package/dist/adapter/resources/buffer.d.ts +3 -3
  11. package/dist/adapter/resources/buffer.d.ts.map +1 -1
  12. package/dist/adapter/resources/buffer.js +70 -56
  13. package/dist/adapter/resources/command-buffer.d.ts +2 -2
  14. package/dist/adapter/resources/command-buffer.d.ts.map +1 -1
  15. package/dist/adapter/resources/command-buffer.js +15 -12
  16. package/dist/adapter/resources/command-encoder.d.ts +22 -7
  17. package/dist/adapter/resources/command-encoder.d.ts.map +1 -1
  18. package/dist/adapter/resources/command-encoder.js +16 -16
  19. package/dist/adapter/resources/compute-pass.d.ts +16 -5
  20. package/dist/adapter/resources/compute-pass.d.ts.map +1 -1
  21. package/dist/adapter/resources/compute-pass.js +15 -12
  22. package/dist/adapter/resources/compute-pipeline.d.ts +4 -4
  23. package/dist/adapter/resources/compute-pipeline.d.ts.map +1 -1
  24. package/dist/adapter/resources/compute-pipeline.js +20 -17
  25. package/dist/adapter/resources/external-texture.d.ts +2 -2
  26. package/dist/adapter/resources/external-texture.d.ts.map +1 -1
  27. package/dist/adapter/resources/external-texture.js +14 -14
  28. package/dist/adapter/resources/framebuffer.d.ts +9 -8
  29. package/dist/adapter/resources/framebuffer.d.ts.map +1 -1
  30. package/dist/adapter/resources/framebuffer.js +191 -91
  31. package/dist/adapter/resources/query-set.d.ts +26 -0
  32. package/dist/adapter/resources/query-set.d.ts.map +1 -0
  33. package/dist/adapter/resources/query-set.js +18 -0
  34. package/dist/adapter/resources/render-pass.d.ts +22 -9
  35. package/dist/adapter/resources/render-pass.d.ts.map +1 -1
  36. package/dist/adapter/resources/render-pass.js +34 -20
  37. package/dist/adapter/resources/render-pipeline.d.ts +22 -18
  38. package/dist/adapter/resources/render-pipeline.d.ts.map +1 -1
  39. package/dist/adapter/resources/render-pipeline.js +50 -33
  40. package/dist/adapter/resources/resource.d.ts +1 -1
  41. package/dist/adapter/resources/resource.d.ts.map +1 -1
  42. package/dist/adapter/resources/resource.js +133 -92
  43. package/dist/adapter/resources/sampler.d.ts +3 -3
  44. package/dist/adapter/resources/sampler.d.ts.map +1 -1
  45. package/dist/adapter/resources/sampler.js +24 -23
  46. package/dist/adapter/resources/shader.d.ts +8 -6
  47. package/dist/adapter/resources/shader.d.ts.map +1 -1
  48. package/dist/adapter/resources/shader.js +98 -74
  49. package/dist/adapter/resources/texture-view.d.ts +32 -0
  50. package/dist/adapter/resources/texture-view.d.ts.map +1 -0
  51. package/dist/adapter/resources/texture-view.js +24 -0
  52. package/dist/adapter/resources/texture.d.ts +10 -15
  53. package/dist/adapter/resources/texture.d.ts.map +1 -1
  54. package/dist/adapter/resources/texture.js +54 -42
  55. package/dist/adapter/resources/transform-feedback.d.ts +7 -7
  56. package/dist/adapter/resources/transform-feedback.d.ts.map +1 -1
  57. package/dist/adapter/resources/transform-feedback.js +15 -14
  58. package/dist/adapter/resources/vertex-array.d.ts +9 -9
  59. package/dist/adapter/resources/vertex-array.d.ts.map +1 -1
  60. package/dist/adapter/resources/vertex-array.js +36 -20
  61. package/dist/adapter/type-utils/decode-attribute-type.d.ts +2 -2
  62. package/dist/adapter/type-utils/decode-attribute-type.d.ts.map +1 -1
  63. package/dist/adapter/type-utils/decode-attribute-type.js +59 -52
  64. package/dist/adapter/type-utils/decode-data-type.d.ts +1 -1
  65. package/dist/adapter/type-utils/decode-data-type.d.ts.map +1 -1
  66. package/dist/adapter/type-utils/decode-data-type.js +39 -35
  67. package/dist/adapter/type-utils/decode-shader-types.d.ts +1 -1
  68. package/dist/adapter/type-utils/decode-shader-types.d.ts.map +1 -1
  69. package/dist/adapter/type-utils/decode-shader-types.js +36 -96
  70. package/dist/adapter/type-utils/decode-texture-format.d.ts +6 -2
  71. package/dist/adapter/type-utils/decode-texture-format.d.ts.map +1 -1
  72. package/dist/adapter/type-utils/decode-texture-format.js +172 -92
  73. package/dist/adapter/type-utils/decode-vertex-format.d.ts +1 -1
  74. package/dist/adapter/type-utils/decode-vertex-format.d.ts.map +1 -1
  75. package/dist/adapter/type-utils/decode-vertex-format.js +30 -22
  76. package/dist/adapter/type-utils/vertex-format-from-attribute.d.ts +2 -2
  77. package/dist/adapter/type-utils/vertex-format-from-attribute.d.ts.map +1 -1
  78. package/dist/adapter/type-utils/vertex-format-from-attribute.js +72 -65
  79. package/dist/adapter/type-utils/wgsl-utils.d.ts +1 -1
  80. package/dist/adapter/type-utils/wgsl-utils.d.ts.map +1 -1
  81. package/dist/adapter/type-utils/wgsl-utils.js +17 -13
  82. package/dist/adapter/types/accessor.d.ts +1 -1
  83. package/dist/adapter/types/accessor.d.ts.map +1 -1
  84. package/dist/adapter/types/accessor.js +3 -1
  85. package/dist/adapter/types/buffer-layout.d.ts +1 -1
  86. package/dist/adapter/types/buffer-layout.d.ts.map +1 -1
  87. package/dist/adapter/types/buffer-layout.js +3 -1
  88. package/dist/adapter/types/parameters.d.ts +28 -6
  89. package/dist/adapter/types/parameters.d.ts.map +1 -1
  90. package/dist/adapter/types/parameters.js +46 -26
  91. package/dist/adapter/types/shader-layout.d.ts +8 -7
  92. package/dist/adapter/types/shader-layout.d.ts.map +1 -1
  93. package/dist/adapter/types/shader-layout.js +3 -1
  94. package/dist/adapter/types/shader-types.d.ts.map +1 -1
  95. package/dist/adapter/types/shader-types.js +3 -1
  96. package/dist/adapter/types/texture-formats.d.ts +2 -2
  97. package/dist/adapter/types/texture-formats.d.ts.map +1 -1
  98. package/dist/adapter/types/texture-formats.js +3 -1
  99. package/dist/adapter/types/types.d.ts +4 -4
  100. package/dist/adapter/types/types.d.ts.map +1 -1
  101. package/dist/adapter/types/types.js +3 -1
  102. package/dist/adapter/types/vertex-formats.d.ts.map +1 -1
  103. package/dist/adapter/types/vertex-formats.js +3 -1
  104. package/dist/dist.dev.js +614 -406
  105. package/dist/index.cjs +344 -369
  106. package/dist/index.cjs.map +7 -0
  107. package/dist/index.d.ts +80 -76
  108. package/dist/index.d.ts.map +1 -1
  109. package/dist/index.js +19 -5
  110. package/dist/init.d.ts.map +1 -1
  111. package/dist/init.js +30 -17
  112. package/dist/lib/compiler-log/compiler-message.d.ts.map +1 -1
  113. package/dist/lib/compiler-log/compiler-message.js +3 -1
  114. package/dist/lib/compiler-log/format-compiler-log.d.ts +1 -1
  115. package/dist/lib/compiler-log/format-compiler-log.d.ts.map +1 -1
  116. package/dist/lib/compiler-log/format-compiler-log.js +69 -48
  117. package/dist/lib/compiler-log/get-shader-info.d.ts.map +1 -1
  118. package/dist/lib/compiler-log/get-shader-info.js +23 -19
  119. package/dist/lib/luma.d.ts +3 -3
  120. package/dist/lib/luma.d.ts.map +1 -1
  121. package/dist/lib/luma.js +60 -51
  122. package/dist/lib/uniforms/uniform-block.d.ts +3 -4
  123. package/dist/lib/uniforms/uniform-block.d.ts.map +1 -1
  124. package/dist/lib/uniforms/uniform-block.js +52 -42
  125. package/dist/lib/uniforms/uniform-buffer-layout.d.ts +2 -2
  126. package/dist/lib/uniforms/uniform-buffer-layout.d.ts.map +1 -1
  127. package/dist/lib/uniforms/uniform-buffer-layout.js +86 -66
  128. package/dist/lib/uniforms/uniform-store.d.ts +6 -6
  129. package/dist/lib/uniforms/uniform-store.d.ts.map +1 -1
  130. package/dist/lib/uniforms/uniform-store.js +111 -75
  131. package/dist/lib/uniforms/uniform.d.ts +2 -2
  132. package/dist/lib/uniforms/uniform.d.ts.map +1 -1
  133. package/dist/lib/uniforms/uniform.js +15 -15
  134. package/dist/types.d.ts.map +1 -1
  135. package/dist/types.js +4 -3
  136. package/dist/utils/array-equal.d.ts.map +1 -1
  137. package/dist/utils/array-equal.js +25 -22
  138. package/dist/utils/array-utils-flat.d.ts +1 -1
  139. package/dist/utils/array-utils-flat.d.ts.map +1 -1
  140. package/dist/utils/array-utils-flat.js +29 -28
  141. package/dist/utils/assert.d.ts.map +1 -1
  142. package/dist/utils/assert.js +8 -4
  143. package/dist/utils/cast.d.ts.map +1 -1
  144. package/dist/utils/cast.js +5 -2
  145. package/dist/utils/check-props.d.ts.map +1 -1
  146. package/dist/utils/check-props.js +30 -26
  147. package/dist/utils/deep-equal.d.ts.map +1 -1
  148. package/dist/utils/deep-equal.js +42 -32
  149. package/dist/utils/format-value.d.ts +1 -1
  150. package/dist/utils/format-value.d.ts.map +1 -1
  151. package/dist/utils/format-value.js +36 -39
  152. package/dist/utils/is-array.d.ts +1 -1
  153. package/dist/utils/is-array.d.ts.map +1 -1
  154. package/dist/utils/is-array.js +20 -6
  155. package/dist/utils/load-file.d.ts.map +1 -1
  156. package/dist/utils/load-file.js +63 -37
  157. package/dist/utils/log.d.ts.map +1 -1
  158. package/dist/utils/log.js +5 -4
  159. package/dist/utils/random.d.ts.map +1 -1
  160. package/dist/utils/random.js +13 -9
  161. package/dist/utils/request-animation-frame.d.ts.map +1 -1
  162. package/dist/utils/request-animation-frame.js +12 -3
  163. package/dist/utils/stats-manager.d.ts.map +1 -1
  164. package/dist/utils/stats-manager.js +16 -14
  165. package/dist/utils/stub-methods.d.ts.map +1 -1
  166. package/dist/utils/stub-methods.js +15 -12
  167. package/dist/utils/utils.d.ts +0 -6
  168. package/dist/utils/utils.d.ts.map +1 -1
  169. package/dist/utils/utils.js +21 -15
  170. package/dist.min.js +8 -23
  171. package/package.json +6 -6
  172. package/src/adapter/attribute-utils/get-attribute-from-layouts.ts +6 -5
  173. package/src/adapter/canvas-context.ts +8 -5
  174. package/src/adapter/device.ts +181 -127
  175. package/src/adapter/resources/buffer.ts +19 -6
  176. package/src/adapter/resources/command-buffer.ts +7 -5
  177. package/src/adapter/resources/command-encoder.ts +40 -29
  178. package/src/adapter/resources/compute-pass.ts +23 -9
  179. package/src/adapter/resources/compute-pipeline.ts +5 -2
  180. package/src/adapter/resources/external-texture.ts +8 -2
  181. package/src/adapter/resources/framebuffer.ts +115 -102
  182. package/src/adapter/resources/query-set.ts +41 -0
  183. package/src/adapter/resources/render-pass.ts +48 -54
  184. package/src/adapter/resources/render-pipeline.ts +22 -9
  185. package/src/adapter/resources/resource.ts +13 -10
  186. package/src/adapter/resources/sampler.ts +4 -3
  187. package/src/adapter/resources/shader.ts +19 -7
  188. package/src/adapter/resources/texture-view.ts +51 -0
  189. package/src/adapter/resources/texture.ts +28 -26
  190. package/src/adapter/resources/transform-feedback.ts +6 -3
  191. package/src/adapter/resources/vertex-array.ts +11 -3
  192. package/src/adapter/type-utils/decode-attribute-type.ts +24 -10
  193. package/src/adapter/type-utils/decode-data-type.ts +5 -1
  194. package/src/adapter/type-utils/decode-shader-types.ts +12 -9
  195. package/src/adapter/type-utils/decode-texture-format.ts +28 -12
  196. package/src/adapter/type-utils/decode-vertex-format.ts +4 -0
  197. package/src/adapter/type-utils/vertex-format-from-attribute.ts +4 -1
  198. package/src/adapter/type-utils/wgsl-utils.ts +6 -2
  199. package/src/adapter/types/accessor.ts +5 -2
  200. package/src/adapter/types/buffer-layout.ts +11 -8
  201. package/src/adapter/types/parameters.ts +98 -93
  202. package/src/adapter/types/shader-layout.ts +11 -2
  203. package/src/adapter/types/shader-types.ts +2 -1
  204. package/src/adapter/types/texture-formats.ts +130 -129
  205. package/src/adapter/types/types.ts +12 -6
  206. package/src/adapter/types/vertex-formats.ts +4 -5
  207. package/src/index.ts +30 -15
  208. package/src/init.ts +10 -4
  209. package/src/lib/compiler-log/compiler-message.ts +3 -2
  210. package/src/lib/compiler-log/format-compiler-log.ts +8 -3
  211. package/src/lib/compiler-log/get-shader-info.ts +2 -1
  212. package/src/lib/luma.ts +13 -8
  213. package/src/lib/uniforms/uniform-block.ts +7 -3
  214. package/src/lib/uniforms/uniform-buffer-layout.ts +16 -10
  215. package/src/lib/uniforms/uniform-store.ts +4 -1
  216. package/src/lib/uniforms/uniform.ts +12 -6
  217. package/src/types.ts +7 -3
  218. package/src/utils/array-equal.ts +2 -1
  219. package/src/utils/array-utils-flat.ts +9 -3
  220. package/src/utils/assert.ts +4 -0
  221. package/src/utils/cast.ts +4 -0
  222. package/src/utils/check-props.ts +9 -1
  223. package/src/utils/deep-equal.ts +4 -0
  224. package/src/utils/format-value.ts +9 -2
  225. package/src/utils/is-array.ts +4 -0
  226. package/src/utils/load-file.ts +5 -3
  227. package/src/utils/log.ts +4 -0
  228. package/src/utils/random.ts +4 -0
  229. package/src/utils/request-animation-frame.ts +4 -0
  230. package/src/utils/stats-manager.ts +6 -2
  231. package/src/utils/stub-methods.ts +10 -1
  232. package/src/utils/utils.ts +2 -10
  233. package/dist/adapter/attribute-utils/get-attribute-from-layouts.js.map +0 -1
  234. package/dist/adapter/canvas-context.js.map +0 -1
  235. package/dist/adapter/device.js.map +0 -1
  236. package/dist/adapter/resources/buffer.js.map +0 -1
  237. package/dist/adapter/resources/command-buffer.js.map +0 -1
  238. package/dist/adapter/resources/command-encoder.js.map +0 -1
  239. package/dist/adapter/resources/compute-pass.js.map +0 -1
  240. package/dist/adapter/resources/compute-pipeline.js.map +0 -1
  241. package/dist/adapter/resources/external-texture.js.map +0 -1
  242. package/dist/adapter/resources/framebuffer.js.map +0 -1
  243. package/dist/adapter/resources/render-pass.js.map +0 -1
  244. package/dist/adapter/resources/render-pipeline.js.map +0 -1
  245. package/dist/adapter/resources/resource.js.map +0 -1
  246. package/dist/adapter/resources/sampler.js.map +0 -1
  247. package/dist/adapter/resources/shader.js.map +0 -1
  248. package/dist/adapter/resources/texture.js.map +0 -1
  249. package/dist/adapter/resources/transform-feedback.js.map +0 -1
  250. package/dist/adapter/resources/vertex-array.js.map +0 -1
  251. package/dist/adapter/type-utils/decode-attribute-type.js.map +0 -1
  252. package/dist/adapter/type-utils/decode-data-type.js.map +0 -1
  253. package/dist/adapter/type-utils/decode-shader-types.js.map +0 -1
  254. package/dist/adapter/type-utils/decode-texture-format.js.map +0 -1
  255. package/dist/adapter/type-utils/decode-vertex-format.js.map +0 -1
  256. package/dist/adapter/type-utils/vertex-format-from-attribute.js.map +0 -1
  257. package/dist/adapter/type-utils/wgsl-utils.js.map +0 -1
  258. package/dist/adapter/types/accessor.js.map +0 -1
  259. package/dist/adapter/types/buffer-layout.js.map +0 -1
  260. package/dist/adapter/types/parameters.js.map +0 -1
  261. package/dist/adapter/types/shader-layout.js.map +0 -1
  262. package/dist/adapter/types/shader-types.js.map +0 -1
  263. package/dist/adapter/types/texture-formats.js.map +0 -1
  264. package/dist/adapter/types/types.js.map +0 -1
  265. package/dist/adapter/types/vertex-formats.js.map +0 -1
  266. package/dist/index.js.map +0 -1
  267. package/dist/init.js.map +0 -1
  268. package/dist/lib/compiler-log/compiler-message.js.map +0 -1
  269. package/dist/lib/compiler-log/format-compiler-log.js.map +0 -1
  270. package/dist/lib/compiler-log/get-shader-info.js.map +0 -1
  271. package/dist/lib/luma.js.map +0 -1
  272. package/dist/lib/uniforms/uniform-block.js.map +0 -1
  273. package/dist/lib/uniforms/uniform-buffer-layout.js.map +0 -1
  274. package/dist/lib/uniforms/uniform-store.js.map +0 -1
  275. package/dist/lib/uniforms/uniform.js.map +0 -1
  276. package/dist/types.js.map +0 -1
  277. package/dist/utils/array-equal.js.map +0 -1
  278. package/dist/utils/array-utils-flat.js.map +0 -1
  279. package/dist/utils/assert.js.map +0 -1
  280. package/dist/utils/cast.js.map +0 -1
  281. package/dist/utils/check-props.js.map +0 -1
  282. package/dist/utils/deep-equal.js.map +0 -1
  283. package/dist/utils/format-value.js.map +0 -1
  284. package/dist/utils/is-array.js.map +0 -1
  285. package/dist/utils/load-file.js.map +0 -1
  286. package/dist/utils/log.js.map +0 -1
  287. package/dist/utils/random.js.map +0 -1
  288. package/dist/utils/request-animation-frame.js.map +0 -1
  289. package/dist/utils/stats-manager.js.map +0 -1
  290. package/dist/utils/stub-methods.js.map +0 -1
  291. package/dist/utils/utils.js.map +0 -1
@@ -1,101 +1,142 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  import { uid } from "../../utils/utils.js";
5
+ /**
6
+ * Base class for GPU (WebGPU/WebGL) Resources
7
+ */
2
8
  export class Resource {
3
- constructor(device, props, defaultProps) {
4
- this.id = void 0;
5
- this.props = void 0;
6
- this.userData = {};
7
- this.device = void 0;
8
- this._device = void 0;
9
- this.destroyed = false;
10
- this.allocatedBytes = 0;
11
- this._attachedResources = new Set();
12
- if (!device) {
13
- throw new Error('no device');
9
+ /** Default properties for resource */
10
+ static defaultProps = {
11
+ id: 'undefined',
12
+ handle: undefined,
13
+ userData: undefined
14
+ };
15
+ /** props.id, for debugging. */
16
+ id;
17
+ props;
18
+ userData = {};
19
+ _device;
20
+ /** Whether this resource has been destroyed */
21
+ destroyed = false;
22
+ /** For resources that allocate GPU memory */
23
+ allocatedBytes = 0;
24
+ /** Attached resources will be destroyed when this resource is destroyed. Tracks auto-created "sub" resources. */
25
+ _attachedResources = new Set();
26
+ /**
27
+ * Create a new Resource. Called from Subclass
28
+ */
29
+ constructor(device, props, defaultProps) {
30
+ if (!device) {
31
+ throw new Error('no device');
32
+ }
33
+ this._device = device;
34
+ this.props = selectivelyMerge(props, defaultProps);
35
+ const id = this.props.id !== 'undefined' ? this.props.id : uid(this[Symbol.toStringTag]);
36
+ this.props.id = id;
37
+ this.id = id;
38
+ this.userData = this.props.userData || {};
39
+ this.addStats();
14
40
  }
15
- this._device = device;
16
- this.props = selectivelyMerge(props, defaultProps);
17
- const id = this.props.id !== 'undefined' ? this.props.id : uid(this[Symbol.toStringTag]);
18
- this.props.id = id;
19
- this.id = id;
20
- this.userData = this.props.userData || {};
21
- this.addStats();
22
- }
23
- destroy() {
24
- this.destroyResource();
25
- }
26
- delete() {
27
- this.destroy();
28
- return this;
29
- }
30
- toString() {
31
- return `${this[Symbol.toStringTag] || this.constructor.name}(${this.id})`;
32
- }
33
- getProps() {
34
- return this.props;
35
- }
36
- attachResource(resource) {
37
- this._attachedResources.add(resource);
38
- }
39
- detachResource(resource) {
40
- this._attachedResources.delete(resource);
41
- }
42
- destroyAttachedResource(resource) {
43
- if (this._attachedResources.delete(resource)) {
44
- resource.destroy();
41
+ /**
42
+ * destroy can be called on any resource to release it before it is garbage collected.
43
+ */
44
+ destroy() {
45
+ this.destroyResource();
45
46
  }
46
- }
47
- destroyAttachedResources() {
48
- for (const resource of Object.values(this._attachedResources)) {
49
- resource.destroy();
47
+ /** @deprecated Use destroy() */
48
+ delete() {
49
+ this.destroy();
50
+ return this;
51
+ }
52
+ toString() {
53
+ return `${this[Symbol.toStringTag] || this.constructor.name}(${this.id})`;
54
+ }
55
+ /**
56
+ * Combines a map of user props and default props, only including props from defaultProps
57
+ * @returns returns a map of overridden default props
58
+ */
59
+ getProps() {
60
+ return this.props;
61
+ }
62
+ // ATTACHED RESOURCES
63
+ /**
64
+ * Attaches a resource. Attached resources are auto destroyed when this resource is destroyed
65
+ * Called automatically when sub resources are auto created but can be called by application
66
+ */
67
+ attachResource(resource) {
68
+ this._attachedResources.add(resource);
69
+ }
70
+ /**
71
+ * Detach an attached resource. The resource will no longer be auto-destroyed when this resource is destroyed.
72
+ */
73
+ detachResource(resource) {
74
+ this._attachedResources.delete(resource);
75
+ }
76
+ /**
77
+ * Destroys a resource (only if owned), and removes from the owned (auto-destroy) list for this resource.
78
+ */
79
+ destroyAttachedResource(resource) {
80
+ if (this._attachedResources.delete(resource)) {
81
+ resource.destroy();
82
+ }
83
+ }
84
+ /** Destroy all owned resources. Make sure the resources are no longer needed before calling. */
85
+ destroyAttachedResources() {
86
+ for (const resource of Object.values(this._attachedResources)) {
87
+ resource.destroy();
88
+ }
89
+ // don't remove while we are iterating
90
+ this._attachedResources = new Set();
91
+ }
92
+ // PROTECTED METHODS
93
+ /** Perform all destroy steps. Can be called by derived resources when overriding destroy() */
94
+ destroyResource() {
95
+ this.destroyAttachedResources();
96
+ this.removeStats();
97
+ this.destroyed = true;
98
+ }
99
+ /** Called by .destroy() to track object destruction. Subclass must call if overriding destroy() */
100
+ removeStats() {
101
+ const stats = this._device.statsManager.getStats('Resource Counts');
102
+ const name = this[Symbol.toStringTag];
103
+ stats.get(`${name}s Active`).decrementCount();
104
+ }
105
+ /** Called by subclass to track memory allocations */
106
+ trackAllocatedMemory(bytes, name = this[Symbol.toStringTag]) {
107
+ const stats = this._device.statsManager.getStats('Resource Counts');
108
+ stats.get('GPU Memory').addCount(bytes);
109
+ stats.get(`${name} Memory`).addCount(bytes);
110
+ this.allocatedBytes = bytes;
111
+ }
112
+ /** Called by subclass to track memory deallocations */
113
+ trackDeallocatedMemory(name = this[Symbol.toStringTag]) {
114
+ const stats = this._device.statsManager.getStats('Resource Counts');
115
+ stats.get('GPU Memory').subtractCount(this.allocatedBytes);
116
+ stats.get(`${name} Memory`).subtractCount(this.allocatedBytes);
117
+ this.allocatedBytes = 0;
118
+ }
119
+ /** Called by resource constructor to track object creation */
120
+ addStats() {
121
+ const stats = this._device.statsManager.getStats('Resource Counts');
122
+ const name = this[Symbol.toStringTag];
123
+ stats.get('Resources Created').incrementCount();
124
+ stats.get(`${name}s Created`).incrementCount();
125
+ stats.get(`${name}s Active`).incrementCount();
50
126
  }
51
- this._attachedResources = new Set();
52
- }
53
- destroyResource() {
54
- this.destroyAttachedResources();
55
- this.removeStats();
56
- this.destroyed = true;
57
- }
58
- removeStats() {
59
- const stats = this._device.statsManager.getStats('Resource Counts');
60
- const name = this[Symbol.toStringTag];
61
- stats.get(`${name}s Active`).decrementCount();
62
- }
63
- trackAllocatedMemory(bytes) {
64
- let name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this[Symbol.toStringTag];
65
- const stats = this._device.statsManager.getStats('Resource Counts');
66
- stats.get('GPU Memory').addCount(bytes);
67
- stats.get(`${name} Memory`).addCount(bytes);
68
- this.allocatedBytes = bytes;
69
- }
70
- trackDeallocatedMemory() {
71
- let name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this[Symbol.toStringTag];
72
- const stats = this._device.statsManager.getStats('Resource Counts');
73
- stats.get('GPU Memory').subtractCount(this.allocatedBytes);
74
- stats.get(`${name} Memory`).subtractCount(this.allocatedBytes);
75
- this.allocatedBytes = 0;
76
- }
77
- addStats() {
78
- const stats = this._device.statsManager.getStats('Resource Counts');
79
- const name = this[Symbol.toStringTag];
80
- stats.get('Resources Created').incrementCount();
81
- stats.get(`${name}s Created`).incrementCount();
82
- stats.get(`${name}s Active`).incrementCount();
83
- }
84
127
  }
85
- Resource.defaultProps = {
86
- id: 'undefined',
87
- handle: undefined,
88
- userData: undefined
89
- };
128
+ /**
129
+ * Combines a map of user props and default props, only including props from defaultProps
130
+ * @param props
131
+ * @param defaultProps
132
+ * @returns returns a map of overridden default props
133
+ */
90
134
  function selectivelyMerge(props, defaultProps) {
91
- const mergedProps = {
92
- ...defaultProps
93
- };
94
- for (const key in props) {
95
- if (props[key] !== undefined) {
96
- mergedProps[key] = props[key];
135
+ const mergedProps = { ...defaultProps };
136
+ for (const key in props) {
137
+ if (props[key] !== undefined) {
138
+ mergedProps[key] = props[key];
139
+ }
97
140
  }
98
- }
99
- return mergedProps;
141
+ return mergedProps;
100
142
  }
101
- //# sourceMappingURL=resource.js.map
@@ -1,6 +1,6 @@
1
- import type { Device } from '../device';
2
- import { CompareFunction } from '../types/parameters';
3
- import { Resource, ResourceProps } from './resource';
1
+ import type { Device } from "../device.js";
2
+ import { CompareFunction } from "../types/parameters.js";
3
+ import { Resource, ResourceProps } from "./resource.js";
4
4
  /** Edge values sampling mode */
5
5
  export type SamplerAddressMode = 'clamp-to-edge' | 'repeat' | 'mirror-repeat';
6
6
  /** Sampler filtering mode */
@@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M,CAAC;IACrB,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8FAA8F;IAC9F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iHAAiH;IACjH,OAAO,CAAC,EAAE,eAAe,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,YAAY,EAAE,MAAM,aAAa,CAAC,CAAC;AAExE,+BAA+B;AAC/B,8BAAsB,OAAQ,SAAQ,QAAQ,CAAC,YAAY,CAAC;IAC1D,OAAgB,YAAY,EAAE,QAAQ,CAAC,YAAY,CAAC,CAalD;IAEF,IAAa,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAE1C;gBAEW,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY;CAGhD"}
@@ -1,26 +1,27 @@
1
- let _Symbol$toStringTag;
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
2
4
  import { Resource } from "./resource.js";
3
- _Symbol$toStringTag = Symbol.toStringTag;
5
+ /** Immutable Sampler object */
4
6
  export class Sampler extends Resource {
5
- get [_Symbol$toStringTag]() {
6
- return 'Sampler';
7
- }
8
- constructor(device, props) {
9
- super(device, props, Sampler.defaultProps);
10
- }
7
+ static defaultProps = {
8
+ ...Resource.defaultProps,
9
+ type: 'color-sampler',
10
+ addressModeU: 'clamp-to-edge',
11
+ addressModeV: 'clamp-to-edge',
12
+ addressModeW: 'clamp-to-edge',
13
+ magFilter: 'nearest',
14
+ minFilter: 'nearest',
15
+ mipmapFilter: 'nearest',
16
+ lodMinClamp: 0,
17
+ lodMaxClamp: 32, // Per WebGPU spec
18
+ compare: 'less-equal',
19
+ maxAnisotropy: 1
20
+ };
21
+ get [Symbol.toStringTag]() {
22
+ return 'Sampler';
23
+ }
24
+ constructor(device, props) {
25
+ super(device, props, Sampler.defaultProps);
26
+ }
11
27
  }
12
- Sampler.defaultProps = {
13
- ...Resource.defaultProps,
14
- type: 'color-sampler',
15
- addressModeU: 'clamp-to-edge',
16
- addressModeV: 'clamp-to-edge',
17
- addressModeW: 'clamp-to-edge',
18
- magFilter: 'nearest',
19
- minFilter: 'nearest',
20
- mipmapFilter: 'nearest',
21
- lodMinClamp: 0,
22
- lodMaxClamp: 32,
23
- compare: 'less-equal',
24
- maxAnisotropy: 1
25
- };
26
- //# sourceMappingURL=sampler.js.map
@@ -1,6 +1,6 @@
1
- import type { Device } from '../device';
2
- import { Resource, ResourceProps } from './resource';
3
- import { CompilerMessage } from '../../lib/compiler-log/compiler-message';
1
+ import type { Device } from "../device.js";
2
+ import { Resource, ResourceProps } from "./resource.js";
3
+ import { CompilerMessage } from "../../lib/compiler-log/compiler-message.js";
4
4
  /**
5
5
  * Properties for a Shader
6
6
  */
@@ -29,16 +29,18 @@ export declare abstract class Shader extends Resource<ShaderProps> {
29
29
  readonly stage: 'vertex' | 'fragment' | 'compute';
30
30
  /** The source code of this shader */
31
31
  readonly source: string;
32
- /** The compilation status of this shader. May be 'pending' if compilation is done asynchronously */
33
- compilationStatus: 'success' | 'error' | 'pending';
32
+ /** The compilation status of the shader. 'pending' if compilation is asynchronous, and on production */
33
+ compilationStatus: 'pending' | 'success' | 'error';
34
34
  /** Create a new Shader instance */
35
35
  constructor(device: Device, props: ShaderProps);
36
36
  /** Get compiler log asynchronously */
37
37
  abstract getCompilationInfo(): Promise<readonly CompilerMessage[]>;
38
38
  /** Get compiler log synchronously (WebGL only) */
39
39
  getCompilationInfoSync(): readonly CompilerMessage[] | null;
40
+ /** Get translated shader source in host platform's native language (HLSL, GLSL, and even GLSL ES), if available */
41
+ getTranslatedSource(): string | null;
40
42
  /** In browser logging of errors */
41
- debugShader(): Promise<void>;
43
+ debugShader(trigger?: "never" | "errors" | "warnings" | "always"): Promise<void>;
42
44
  /** In-browser UI logging of errors */
43
45
  protected _displayShaderLog(messages: readonly CompilerMessage[]): void;
44
46
  }
@@ -1 +1 @@
1
- {"version":3,"file":"shader.d.ts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wGAAwG;IACxG,iBAAiB,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,CAAa;IAE/D,mCAAmC;gBACvB,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW;IAM9C,sCAAsC;IACtC,QAAQ,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAAS,eAAe,EAAE,CAAC;IAElE,kDAAkD;IAClD,sBAAsB,IAAI,SAAS,eAAe,EAAE,GAAG,IAAI;IAI3D,mHAAmH;IACnH,mBAAmB,IAAI,MAAM,GAAG,IAAI;IAMpC,mCAAmC;IAC7B,WAAW,CAAC,OAAO,6CAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB5D,sCAAsC;IACtC,SAAS,CAAC,iBAAiB,CAAC,QAAQ,EAAE,SAAS,eAAe,EAAE,GAAG,IAAI;CA2CxE"}
@@ -1,90 +1,114 @@
1
- let _Symbol$toStringTag;
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
2
4
  import { Resource } from "./resource.js";
5
+ // import { log } from '../../utils/log';
3
6
  import { uid } from "../../utils/utils.js";
4
7
  import { formatCompilerLog } from "../../lib/compiler-log/format-compiler-log.js";
5
8
  import { getShaderInfo } from "../../lib/compiler-log/get-shader-info.js";
6
- _Symbol$toStringTag = Symbol.toStringTag;
9
+ /**
10
+ * Immutable Shader object
11
+ * In WebGPU the handle can be copied between threads
12
+ */
7
13
  export class Shader extends Resource {
8
- get [_Symbol$toStringTag]() {
9
- return 'Shader';
10
- }
11
- constructor(device, props) {
12
- super(device, {
13
- id: getShaderIdFromProps(props),
14
- ...props
15
- }, Shader.defaultProps);
16
- this.stage = void 0;
17
- this.source = void 0;
18
- this.compilationStatus = 'pending';
19
- this.stage = this.props.stage;
20
- this.source = this.props.source;
21
- }
22
- getCompilationInfoSync() {
23
- return null;
24
- }
25
- async debugShader() {
26
- switch (this.props.debug) {
27
- case 'never':
28
- return;
29
- case 'errors':
30
- if (this.compilationStatus === 'success') {
31
- return;
32
- }
33
- break;
34
- case 'warnings':
35
- case 'always':
36
- break;
14
+ static defaultProps = {
15
+ ...Resource.defaultProps,
16
+ language: 'auto',
17
+ stage: 'vertex',
18
+ source: '',
19
+ sourceMap: null,
20
+ entryPoint: 'main',
21
+ debug: 'errors'
22
+ };
23
+ get [Symbol.toStringTag]() {
24
+ return 'Shader';
25
+ }
26
+ /** The stage of this shader */
27
+ stage;
28
+ /** The source code of this shader */
29
+ source;
30
+ /** The compilation status of the shader. 'pending' if compilation is asynchronous, and on production */
31
+ compilationStatus = 'pending';
32
+ /** Create a new Shader instance */
33
+ constructor(device, props) {
34
+ super(device, { id: getShaderIdFromProps(props), ...props }, Shader.defaultProps);
35
+ this.stage = this.props.stage;
36
+ this.source = this.props.source;
37
37
  }
38
- const messages = await this.getCompilationInfo();
39
- if (this.props.debug === 'warnings' && (messages === null || messages === void 0 ? void 0 : messages.length) === 0) {
40
- return;
38
+ /** Get compiler log synchronously (WebGL only) */
39
+ getCompilationInfoSync() {
40
+ return null;
41
41
  }
42
- this._displayShaderLog(messages);
43
- }
44
- _displayShaderLog(messages) {
45
- var _document, _errors$;
46
- if (typeof document === 'undefined' || !((_document = document) !== null && _document !== void 0 && _document.createElement)) {
47
- return;
42
+ /** Get translated shader source in host platform's native language (HLSL, GLSL, and even GLSL ES), if available */
43
+ getTranslatedSource() {
44
+ return null;
45
+ }
46
+ // PORTABLE HELPERS
47
+ /** In browser logging of errors */
48
+ async debugShader(trigger = this.props.debug) {
49
+ switch (trigger) {
50
+ case 'never':
51
+ return;
52
+ case 'errors':
53
+ // On WebGL - Don't extract the log unless errors
54
+ if (this.compilationStatus === 'success') {
55
+ return;
56
+ }
57
+ break;
58
+ case 'warnings':
59
+ case 'always':
60
+ break;
61
+ }
62
+ const messages = await this.getCompilationInfo();
63
+ if (this.props.debug === 'warnings' && messages?.length === 0) {
64
+ return;
65
+ }
66
+ this._displayShaderLog(messages);
48
67
  }
49
- const shaderName = getShaderInfo(this.source).name;
50
- const shaderTitle = `${this.stage} ${shaderName}`;
51
- const htmlLog = formatCompilerLog(messages, this.source, {
52
- showSourceCode: 'all',
53
- html: true
54
- });
55
- const button = document.createElement('Button');
56
- button.innerHTML = `
68
+ // PRIVATE
69
+ /** In-browser UI logging of errors */
70
+ _displayShaderLog(messages) {
71
+ // Return if under Node.js / incomplete `document` polyfills
72
+ if (typeof document === 'undefined' || !document?.createElement) {
73
+ return;
74
+ }
75
+ const shaderName = getShaderInfo(this.source).name;
76
+ const shaderTitle = `${this.stage} ${shaderName}`;
77
+ let htmlLog = formatCompilerLog(messages, this.source, { showSourceCode: 'all', html: true });
78
+ // Show translated source if available
79
+ const translatedSource = this.getTranslatedSource();
80
+ if (translatedSource) {
81
+ htmlLog += `<br /><br /><h1>Translated Source</h1><br /><br /><code style="user-select:text;"><pre>${translatedSource}</pre></code>`;
82
+ }
83
+ // Make it clickable so we can copy to clipboard
84
+ const button = document.createElement('Button');
85
+ button.innerHTML = `
57
86
  <h1>Shader Compilation Error in ${shaderTitle}</h1><br /><br />
58
87
  <code style="user-select:text;"><pre>
59
88
  ${htmlLog}
60
89
  </pre></code>`;
61
- button.style.top = '10px';
62
- button.style.left = '10px';
63
- button.style.position = 'absolute';
64
- button.style.zIndex = '9999';
65
- button.style.width = '100%';
66
- button.style.textAlign = 'left';
67
- document.body.appendChild(button);
68
- const errors = document.getElementsByClassName('luma-compiler-log-error');
69
- if ((_errors$ = errors[0]) !== null && _errors$ !== void 0 && _errors$.scrollIntoView) {
70
- errors[0].scrollIntoView();
90
+ button.style.top = '10px';
91
+ button.style.left = '10px';
92
+ button.style.position = 'absolute';
93
+ button.style.zIndex = '9999';
94
+ button.style.width = '100%';
95
+ button.style.textAlign = 'left';
96
+ document.body.appendChild(button);
97
+ const errors = document.getElementsByClassName('luma-compiler-log-error');
98
+ if (errors[0]?.scrollIntoView) {
99
+ errors[0].scrollIntoView();
100
+ }
101
+ // TODO - add a small embedded copy button (instead of main button)
102
+ button.onclick = () => {
103
+ // const source = this.source.replaceAll('\n', '<br />');
104
+ const dataURI = `data:text/plain,${encodeURIComponent(this.source)}`;
105
+ navigator.clipboard.writeText(dataURI);
106
+ };
107
+ // TODO - add a small embedded close button
71
108
  }
72
- button.onclick = () => {
73
- const dataURI = `data:text/plain,${encodeURIComponent(this.source)}`;
74
- navigator.clipboard.writeText(dataURI);
75
- };
76
- }
77
109
  }
78
- Shader.defaultProps = {
79
- ...Resource.defaultProps,
80
- language: 'auto',
81
- stage: 'vertex',
82
- source: '',
83
- sourceMap: null,
84
- entryPoint: 'main',
85
- debug: 'errors'
86
- };
110
+ // HELPERS
111
+ /** Deduce an id, from shader source, or supplied id, or shader type */
87
112
  function getShaderIdFromProps(props) {
88
- return getShaderInfo(props.source).name || props.id || uid(`unnamed ${props.stage}-shader`);
113
+ return getShaderInfo(props.source).name || props.id || uid(`unnamed ${props.stage}-shader`);
89
114
  }
90
- //# sourceMappingURL=shader.js.map
@@ -0,0 +1,32 @@
1
+ import type { Device } from "../device.js";
2
+ import type { Texture } from "./texture.js";
3
+ import type { TextureFormat } from "../types/texture-formats.js";
4
+ import { Resource, ResourceProps } from "./resource.js";
5
+ /** Properties for initializing a texture view */
6
+ export type TextureViewProps = ResourceProps & {
7
+ /** The format of the texture view. Must be either the format of the texture or one of the viewFormats specified during its creation. */
8
+ format?: TextureFormat;
9
+ /** The dimension to view the texture as. */
10
+ dimension?: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';
11
+ /** Which aspect(s) of the texture are accessible to the texture view. default "all"*/
12
+ aspect?: 'all' | 'stencil-only' | 'depth-only';
13
+ /** The first (most detailed) mipmap level accessible to the texture view. default 0*/
14
+ baseMipLevel?: number;
15
+ /** How many mipmap levels, starting with baseMipLevel, are accessible to the texture view. */
16
+ mipLevelCount: number;
17
+ /** The index of the first array layer accessible to the texture view. default 0 */
18
+ baseArrayLayer?: number;
19
+ /** How many array layers, starting with baseArrayLayer, are accessible to the texture view. */
20
+ arrayLayerCount: number;
21
+ };
22
+ /** Immutable TextureView object */
23
+ export declare abstract class TextureView extends Resource<TextureViewProps> {
24
+ static defaultProps: Required<TextureViewProps>;
25
+ abstract texture: Texture;
26
+ get [Symbol.toStringTag](): string;
27
+ /** Should not be constructed directly. Use `texture.createView(props)` */
28
+ constructor(device: Device, props: TextureViewProps & {
29
+ texture: Texture;
30
+ });
31
+ }
32
+ //# sourceMappingURL=texture-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"texture-view.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/texture-view.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,qBAAkB;AACtC,OAAO,KAAK,EAAC,OAAO,EAAC,qBAAkB;AACvC,OAAO,KAAK,EAAC,aAAa,EAAC,oCAAiC;AAC5D,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAC,sBAAmB;AAEnD,iDAAiD;AACjD,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,wIAAwI;IACxI,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,UAAU,GAAG,MAAM,GAAG,YAAY,GAAG,IAAI,CAAC;IACpE,sFAAsF;IACtF,MAAM,CAAC,EAAE,KAAK,GAAG,cAAc,GAAG,YAAY,CAAC;IAC/C,uFAAuF;IACvF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8FAA8F;IAC9F,aAAa,EAAE,MAAM,CAAC;IACtB,mFAAmF;IACnF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,+FAA+F;IAC/F,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,mCAAmC;AACnC,8BAAsB,WAAY,SAAQ,QAAQ,CAAC,gBAAgB,CAAC;IAClE,OAAgB,YAAY,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAStD;IAEF,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B,IAAa,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAE1C;IAED,0EAA0E;gBAC9D,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG;QAAC,OAAO,EAAE,OAAO,CAAA;KAAC;CAGzE"}
@@ -0,0 +1,24 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { Resource } from "./resource.js";
5
+ /** Immutable TextureView object */
6
+ export class TextureView extends Resource {
7
+ static defaultProps = {
8
+ ...Resource.defaultProps,
9
+ format: undefined,
10
+ dimension: undefined,
11
+ aspect: 'all',
12
+ baseMipLevel: 0,
13
+ mipLevelCount: undefined,
14
+ baseArrayLayer: 0,
15
+ arrayLayerCount: undefined
16
+ };
17
+ get [Symbol.toStringTag]() {
18
+ return 'TextureView';
19
+ }
20
+ /** Should not be constructed directly. Use `texture.createView(props)` */
21
+ constructor(device, props) {
22
+ super(device, props, TextureView.defaultProps);
23
+ }
24
+ }
@@ -1,9 +1,10 @@
1
1
  /// <reference types="node" />
2
- import type { Device } from '../device';
3
- import type { TypedArray } from '../../types';
4
- import type { TextureFormat } from '../types/texture-formats';
5
- import { Resource, ResourceProps } from './resource';
6
- import { Sampler, SamplerProps } from './sampler';
2
+ import type { Device } from "../device.js";
3
+ import type { TypedArray } from "../../types.js";
4
+ import type { TextureFormat } from "../types/texture-formats.js";
5
+ import { Resource, ResourceProps } from "./resource.js";
6
+ import { Sampler, SamplerProps } from "./sampler.js";
7
+ import { TextureView, TextureViewProps } from "./texture-view.js";
7
8
  /** Data types that can be used to initialize textures */
8
9
  export type TextureData = TypedArray | ArrayBuffer | Buffer | ImageBitmap | HTMLImageElement;
9
10
  export type CubeTextureData = Record<string, TextureData> | Record<string, Promise<TextureData>>;
@@ -18,11 +19,12 @@ export type TextureProps = ResourceProps & {
18
19
  usage?: number;
19
20
  data?: TextureData | Promise<TextureData> | CubeTextureData | string | HTMLVideoElement | null;
20
21
  mipmaps?: boolean;
21
- sampler?: Sampler | SamplerProps;
22
22
  mipLevels?: number;
23
23
  samples?: number;
24
24
  type?: number;
25
25
  compressed?: boolean;
26
+ sampler?: Sampler | SamplerProps;
27
+ view?: TextureViewProps;
26
28
  };
27
29
  export type WebGPUTextureProps = ResourceProps & {
28
30
  width: number;
@@ -31,15 +33,6 @@ export type WebGPUTextureProps = ResourceProps & {
31
33
  mipLevels?: number;
32
34
  format?: string;
33
35
  };
34
- export type TextureViewProps = {
35
- format: string;
36
- dimension: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';
37
- aspect?: 'all' | 'stencil-only' | 'depth-only';
38
- arrayLayerCount: number;
39
- baseArrayLayer?: number;
40
- mipLevels?: number;
41
- baseMipLevel?: number;
42
- };
43
36
  /**
44
37
  * @deprecated
45
38
  * @todo remove, are these even used anymore?
@@ -85,6 +78,8 @@ export declare abstract class Texture<Props extends TextureProps = TextureProps>
85
78
  readonly depth: number;
86
79
  /** Default sampler for this texture */
87
80
  abstract sampler: Sampler;
81
+ /** Default view for this texture */
82
+ abstract view: TextureView;
88
83
  constructor(device: Device, props: Props, defaultProps?: Required<Props>);
89
84
  }
90
85
  //# sourceMappingURL=texture.d.ts.map