@luma.gl/webgl 9.1.0-alpha.2 → 9.1.0-beta.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 (216) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts +3 -3
  2. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  3. package/dist/adapter/converters/device-parameters.js +19 -11
  4. package/dist/adapter/converters/device-parameters.js.map +1 -0
  5. package/dist/adapter/converters/sampler-parameters.js +7 -4
  6. package/dist/adapter/converters/sampler-parameters.js.map +1 -0
  7. package/dist/adapter/converters/shader-formats.js +1 -0
  8. package/dist/adapter/converters/shader-formats.js.map +1 -0
  9. package/dist/adapter/converters/vertex-formats.js +1 -0
  10. package/dist/adapter/converters/vertex-formats.js.map +1 -0
  11. package/dist/adapter/converters/webgl-texture-table.d.ts +40 -0
  12. package/dist/adapter/converters/webgl-texture-table.d.ts.map +1 -0
  13. package/dist/adapter/converters/webgl-texture-table.js +304 -0
  14. package/dist/adapter/converters/webgl-texture-table.js.map +1 -0
  15. package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
  16. package/dist/adapter/device-helpers/webgl-device-features.js +2 -3
  17. package/dist/adapter/device-helpers/webgl-device-features.js.map +1 -0
  18. package/dist/adapter/device-helpers/webgl-device-info.js +1 -0
  19. package/dist/adapter/device-helpers/webgl-device-info.js.map +1 -0
  20. package/dist/adapter/device-helpers/webgl-device-limits.js +1 -0
  21. package/dist/adapter/device-helpers/webgl-device-limits.js.map +1 -0
  22. package/dist/adapter/helpers/decode-webgl-types.js +1 -0
  23. package/dist/adapter/helpers/decode-webgl-types.js.map +1 -0
  24. package/dist/adapter/helpers/format-utils.d.ts.map +1 -0
  25. package/dist/{classic → adapter/helpers}/format-utils.js +7 -0
  26. package/dist/adapter/helpers/format-utils.js.map +1 -0
  27. package/dist/adapter/helpers/get-shader-layout.d.ts +1 -1
  28. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  29. package/dist/adapter/helpers/get-shader-layout.js +5 -4
  30. package/dist/adapter/helpers/get-shader-layout.js.map +1 -0
  31. package/dist/adapter/helpers/parse-shader-compiler-log.js +1 -0
  32. package/dist/adapter/helpers/parse-shader-compiler-log.js.map +1 -0
  33. package/dist/adapter/helpers/set-uniform.js +1 -0
  34. package/dist/adapter/helpers/set-uniform.js.map +1 -0
  35. package/dist/adapter/helpers/typed-array-utils.d.ts.map +1 -0
  36. package/dist/{classic → adapter/helpers}/typed-array-utils.js +1 -0
  37. package/dist/adapter/helpers/typed-array-utils.js.map +1 -0
  38. package/dist/adapter/helpers/webgl-texture-utils.d.ts +100 -29
  39. package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
  40. package/dist/adapter/helpers/webgl-texture-utils.js +231 -240
  41. package/dist/adapter/helpers/webgl-texture-utils.js.map +1 -0
  42. package/dist/adapter/helpers/webgl-topology-utils.js +1 -0
  43. package/dist/adapter/helpers/webgl-topology-utils.js.map +1 -0
  44. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  45. package/dist/adapter/resources/webgl-buffer.js +4 -1
  46. package/dist/adapter/resources/webgl-buffer.js.map +1 -0
  47. package/dist/adapter/resources/webgl-command-buffer.d.ts +59 -2
  48. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  49. package/dist/adapter/resources/webgl-command-buffer.js +89 -32
  50. package/dist/adapter/resources/webgl-command-buffer.js.map +1 -0
  51. package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
  52. package/dist/adapter/resources/webgl-command-encoder.js +4 -0
  53. package/dist/adapter/resources/webgl-command-encoder.js.map +1 -0
  54. package/dist/adapter/resources/webgl-external-texture.js +15 -0
  55. package/dist/adapter/resources/webgl-external-texture.js.map +1 -0
  56. package/dist/adapter/resources/webgl-framebuffer.d.ts +33 -35
  57. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  58. package/dist/adapter/resources/webgl-framebuffer.js +71 -76
  59. package/dist/adapter/resources/webgl-framebuffer.js.map +1 -0
  60. package/dist/adapter/resources/webgl-query-set.js +1 -0
  61. package/dist/adapter/resources/webgl-query-set.js.map +1 -0
  62. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  63. package/dist/adapter/resources/webgl-render-pass.js +49 -21
  64. package/dist/adapter/resources/webgl-render-pass.js.map +1 -0
  65. package/dist/adapter/resources/webgl-render-pipeline.d.ts +3 -4
  66. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  67. package/dist/adapter/resources/webgl-render-pipeline.js +45 -23
  68. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -0
  69. package/dist/adapter/resources/webgl-sampler.js +1 -0
  70. package/dist/adapter/resources/webgl-sampler.js.map +1 -0
  71. package/dist/adapter/resources/webgl-shader.d.ts +1 -0
  72. package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
  73. package/dist/adapter/resources/webgl-shader.js +13 -6
  74. package/dist/adapter/resources/webgl-shader.js.map +1 -0
  75. package/dist/adapter/resources/webgl-texture-view.js +1 -0
  76. package/dist/adapter/resources/webgl-texture-view.js.map +1 -0
  77. package/dist/adapter/resources/webgl-texture.d.ts +33 -21
  78. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  79. package/dist/adapter/resources/webgl-texture.js +172 -242
  80. package/dist/adapter/resources/webgl-texture.js.map +1 -0
  81. package/dist/adapter/resources/webgl-transform-feedback.js +1 -0
  82. package/dist/adapter/resources/webgl-transform-feedback.js.map +1 -0
  83. package/dist/adapter/resources/webgl-vertex-array.js +1 -0
  84. package/dist/adapter/resources/webgl-vertex-array.js.map +1 -0
  85. package/dist/adapter/webgl-adapter.d.ts +21 -0
  86. package/dist/adapter/webgl-adapter.d.ts.map +1 -0
  87. package/dist/adapter/webgl-adapter.js +86 -0
  88. package/dist/adapter/webgl-adapter.js.map +1 -0
  89. package/dist/adapter/webgl-canvas-context.d.ts +4 -6
  90. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  91. package/dist/adapter/webgl-canvas-context.js +13 -17
  92. package/dist/adapter/webgl-canvas-context.js.map +1 -0
  93. package/dist/adapter/webgl-device.d.ts +35 -46
  94. package/dist/adapter/webgl-device.d.ts.map +1 -1
  95. package/dist/adapter/webgl-device.js +100 -156
  96. package/dist/adapter/webgl-device.js.map +1 -0
  97. package/dist/context/debug/spector-types.d.ts +1108 -0
  98. package/dist/context/debug/spector-types.d.ts.map +1 -0
  99. package/dist/context/debug/spector-types.js +698 -0
  100. package/dist/context/debug/spector-types.js.map +1 -0
  101. package/dist/context/debug/spector.d.ts +12 -8
  102. package/dist/context/debug/spector.d.ts.map +1 -1
  103. package/dist/context/debug/spector.js +24 -17
  104. package/dist/context/debug/spector.js.map +1 -0
  105. package/dist/context/debug/webgl-developer-tools.d.ts +2 -3
  106. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  107. package/dist/context/debug/webgl-developer-tools.js +7 -19
  108. package/dist/context/debug/webgl-developer-tools.js.map +1 -0
  109. package/dist/context/helpers/create-browser-context.d.ts +6 -22
  110. package/dist/context/helpers/create-browser-context.d.ts.map +1 -1
  111. package/dist/context/helpers/create-browser-context.js +41 -32
  112. package/dist/context/helpers/create-browser-context.js.map +1 -0
  113. package/dist/context/helpers/webgl-context-data.js +1 -0
  114. package/dist/context/helpers/webgl-context-data.js.map +1 -0
  115. package/dist/context/helpers/webgl-extensions.js +1 -0
  116. package/dist/context/helpers/webgl-extensions.js.map +1 -0
  117. package/dist/context/parameters/unified-parameter-api.js +1 -0
  118. package/dist/context/parameters/unified-parameter-api.js.map +1 -0
  119. package/dist/context/parameters/webgl-parameter-tables.d.ts +1 -1
  120. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  121. package/dist/context/parameters/webgl-parameter-tables.js +3 -2
  122. package/dist/context/parameters/webgl-parameter-tables.js.map +1 -0
  123. package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts +9 -0
  124. package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts.map +1 -0
  125. package/dist/context/polyfills/polyfill-webgl1-extensions.js +182 -0
  126. package/dist/context/polyfills/polyfill-webgl1-extensions.js.map +1 -0
  127. package/dist/context/state-tracker/deep-array-equal.js +1 -0
  128. package/dist/context/state-tracker/deep-array-equal.js.map +1 -0
  129. package/dist/context/state-tracker/webgl-state-tracker.d.ts +43 -0
  130. package/dist/context/state-tracker/webgl-state-tracker.d.ts.map +1 -0
  131. package/dist/context/state-tracker/{track-context-state.js → webgl-state-tracker.js} +45 -74
  132. package/dist/context/state-tracker/webgl-state-tracker.js.map +1 -0
  133. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  134. package/dist/context/state-tracker/with-parameters.js +6 -4
  135. package/dist/context/state-tracker/with-parameters.js.map +1 -0
  136. package/dist/deprecated/accessor.d.ts.map +1 -0
  137. package/dist/{classic → deprecated}/accessor.js +37 -1
  138. package/dist/deprecated/accessor.js.map +1 -0
  139. package/dist/dist.dev.js +2397 -2430
  140. package/dist/dist.min.js +2 -2
  141. package/dist/index.cjs +2273 -2298
  142. package/dist/index.cjs.map +4 -4
  143. package/dist/index.d.ts +5 -4
  144. package/dist/index.d.ts.map +1 -1
  145. package/dist/index.js +6 -6
  146. package/dist/index.js.map +1 -0
  147. package/dist/types.js +1 -0
  148. package/dist/types.js.map +1 -0
  149. package/dist/utils/fill-array.d.ts +4 -4
  150. package/dist/utils/fill-array.d.ts.map +1 -1
  151. package/dist/utils/fill-array.js +1 -0
  152. package/dist/utils/fill-array.js.map +1 -0
  153. package/dist/utils/load-script.js +1 -0
  154. package/dist/utils/load-script.js.map +1 -0
  155. package/dist/utils/split-uniforms-and-bindings.d.ts +1 -1
  156. package/dist/utils/split-uniforms-and-bindings.d.ts.map +1 -1
  157. package/dist/utils/split-uniforms-and-bindings.js +1 -0
  158. package/dist/utils/split-uniforms-and-bindings.js.map +1 -0
  159. package/dist/utils/uid.d.ts +7 -0
  160. package/dist/utils/uid.d.ts.map +1 -0
  161. package/dist/utils/uid.js +15 -0
  162. package/dist/utils/uid.js.map +1 -0
  163. package/package.json +5 -5
  164. package/src/adapter/converters/device-parameters.ts +21 -15
  165. package/src/adapter/converters/sampler-parameters.ts +6 -4
  166. package/src/adapter/converters/webgl-texture-table.ts +404 -0
  167. package/src/adapter/device-helpers/webgl-device-features.ts +5 -3
  168. package/src/{classic → adapter/helpers}/format-utils.ts +6 -0
  169. package/src/adapter/helpers/get-shader-layout.ts +7 -4
  170. package/src/adapter/helpers/webgl-texture-utils.ts +410 -64
  171. package/src/adapter/resources/webgl-buffer.ts +3 -1
  172. package/src/adapter/resources/webgl-command-buffer.ts +125 -41
  173. package/src/adapter/resources/webgl-command-encoder.ts +6 -0
  174. package/src/adapter/resources/webgl-external-texture.ts +14 -0
  175. package/src/adapter/resources/webgl-framebuffer.ts +80 -86
  176. package/src/adapter/resources/webgl-render-pass.ts +72 -45
  177. package/src/adapter/resources/webgl-render-pipeline.ts +58 -27
  178. package/src/adapter/resources/webgl-shader.ts +15 -7
  179. package/src/adapter/resources/webgl-texture.ts +202 -274
  180. package/src/adapter/webgl-adapter.ts +105 -0
  181. package/src/adapter/webgl-canvas-context.ts +16 -19
  182. package/src/adapter/webgl-device.ts +144 -210
  183. package/src/context/debug/spector-types.ts +1154 -0
  184. package/src/context/debug/spector.ts +38 -29
  185. package/src/context/debug/webgl-developer-tools.ts +8 -31
  186. package/src/context/helpers/create-browser-context.ts +53 -63
  187. package/src/context/parameters/webgl-parameter-tables.ts +2 -2
  188. package/src/context/polyfills/polyfill-webgl1-extensions.ts +202 -0
  189. package/src/context/state-tracker/{track-context-state.ts → webgl-state-tracker.ts} +55 -94
  190. package/src/context/state-tracker/with-parameters.ts +5 -4
  191. package/src/{classic → deprecated}/accessor.ts +44 -3
  192. package/src/index.ts +7 -12
  193. package/src/utils/fill-array.ts +4 -4
  194. package/src/utils/split-uniforms-and-bindings.ts +3 -3
  195. package/src/utils/uid.ts +16 -0
  196. package/dist/adapter/converters/texture-formats.d.ts +0 -83
  197. package/dist/adapter/converters/texture-formats.d.ts.map +0 -1
  198. package/dist/adapter/converters/texture-formats.js +0 -518
  199. package/dist/classic/accessor.d.ts.map +0 -1
  200. package/dist/classic/clear.d.ts +0 -22
  201. package/dist/classic/clear.d.ts.map +0 -1
  202. package/dist/classic/clear.js +0 -86
  203. package/dist/classic/copy-and-blit.d.ts +0 -63
  204. package/dist/classic/copy-and-blit.d.ts.map +0 -1
  205. package/dist/classic/copy-and-blit.js +0 -193
  206. package/dist/classic/format-utils.d.ts.map +0 -1
  207. package/dist/classic/typed-array-utils.d.ts.map +0 -1
  208. package/dist/context/state-tracker/track-context-state.d.ts +0 -22
  209. package/dist/context/state-tracker/track-context-state.d.ts.map +0 -1
  210. package/src/adapter/converters/texture-formats.ts +0 -665
  211. package/src/classic/clear.ts +0 -115
  212. package/src/classic/copy-and-blit.ts +0 -318
  213. /package/dist/{classic → adapter/helpers}/format-utils.d.ts +0 -0
  214. /package/dist/{classic → adapter/helpers}/typed-array-utils.d.ts +0 -0
  215. /package/dist/{classic → deprecated}/accessor.d.ts +0 -0
  216. /package/src/{classic → adapter/helpers}/typed-array-utils.ts +0 -0
@@ -7,15 +7,24 @@ import type {
7
7
  CopyBufferToTextureOptions,
8
8
  CopyTextureToBufferOptions,
9
9
  CopyTextureToTextureOptions
10
+ // ClearTextureOptions,
11
+ // ReadTextureOptions
10
12
  } from '@luma.gl/core';
11
13
  import {CommandBuffer, Texture, Framebuffer} from '@luma.gl/core';
12
- import {GL} from '@luma.gl/constants';
14
+ import {
15
+ GL,
16
+ GLTextureTarget,
17
+ GLTextureCubeMapTarget
18
+ // GLTexelDataFormat,
19
+ // GLPixelType,
20
+ // GLDataType
21
+ } from '@luma.gl/constants';
13
22
 
14
23
  import {WebGLDevice} from '../webgl-device';
15
24
  import {WEBGLBuffer} from './webgl-buffer';
16
25
  import {WEBGLTexture} from './webgl-texture';
17
26
  import {WEBGLFramebuffer} from './webgl-framebuffer';
18
- import {getTextureFormatWebGL} from '../converters/texture-formats';
27
+ import {getTextureFormatWebGL} from '../converters/webgl-texture-table';
19
28
 
20
29
  type CopyBufferToBufferCommand = {
21
30
  name: 'copy-buffer-to-buffer';
@@ -37,11 +46,23 @@ type CopyTextureToTextureCommand = {
37
46
  options: CopyTextureToTextureOptions;
38
47
  };
39
48
 
49
+ type ClearTextureCommand = {
50
+ name: 'clear-texture';
51
+ options: {}; // ClearTextureOptions;
52
+ };
53
+
54
+ type ReadTextureCommand = {
55
+ name: 'read-texture';
56
+ options: {}; // ReadTextureOptions;
57
+ };
58
+
40
59
  type Command =
41
60
  | CopyBufferToBufferCommand
42
61
  | CopyBufferToTextureCommand
43
62
  | CopyTextureToBufferCommand
44
- | CopyTextureToTextureCommand;
63
+ | CopyTextureToTextureCommand
64
+ | ClearTextureCommand
65
+ | ReadTextureCommand;
45
66
 
46
67
  export class WEBGLCommandBuffer extends CommandBuffer {
47
68
  device: WebGLDevice;
@@ -67,14 +88,19 @@ export class WEBGLCommandBuffer extends CommandBuffer {
67
88
  case 'copy-texture-to-texture':
68
89
  _copyTextureToTexture(this.device, command.options);
69
90
  break;
91
+ // case 'clear-texture':
92
+ // _clearTexture(this.device, command.options);
93
+ // break;
94
+ default:
95
+ throw new Error(command.name);
70
96
  }
71
97
  }
72
98
  }
73
99
  }
74
100
 
75
101
  function _copyBufferToBuffer(device: WebGLDevice, options: CopyBufferToBufferOptions): void {
76
- const source = options.source as WEBGLBuffer;
77
- const destination = options.destination as WEBGLBuffer;
102
+ const source = options.sourceBuffer as WEBGLBuffer;
103
+ const destination = options.destinationBuffer as WEBGLBuffer;
78
104
 
79
105
  // {In WebGL2 we can p}erform the copy on the GPU
80
106
  // Use GL.COPY_READ_BUFFER+GL.COPY_WRITE_BUFFER avoid disturbing other targets and locking type
@@ -106,22 +132,22 @@ function _copyBufferToTexture(device: WebGLDevice, options: CopyBufferToTextureO
106
132
  function _copyTextureToBuffer(device: WebGLDevice, options: CopyTextureToBufferOptions): void {
107
133
  const {
108
134
  /** Texture to copy to/from. */
109
- source,
135
+ sourceTexture,
110
136
  /** Mip-map level of the texture to copy to/from. (Default 0) */
111
137
  mipLevel = 0,
112
138
  /** Defines which aspects of the texture to copy to/from. */
113
139
  aspect = 'all',
114
140
 
115
141
  /** Width to copy */
116
- width = options.source.width,
142
+ width = options.sourceTexture.width,
117
143
  /** Height to copy */
118
- height = options.source.height,
144
+ height = options.sourceTexture.height,
119
145
  depthOrArrayLayers = 0,
120
146
  /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
121
147
  origin = [0, 0],
122
148
 
123
149
  /** Destination buffer */
124
- destination,
150
+ destinationBuffer,
125
151
  /** Offset, in bytes, from the beginning of the buffer to the start of the image data (default 0) */
126
152
  byteOffset = 0,
127
153
  /**
@@ -139,7 +165,7 @@ function _copyTextureToBuffer(device: WebGLDevice, options: CopyTextureToBufferO
139
165
 
140
166
  // TODO - Not possible to read just stencil or depth part in WebGL?
141
167
  if (aspect !== 'all') {
142
- throw new Error('not supported');
168
+ throw new Error('aspect not supported in WebGL');
143
169
  }
144
170
 
145
171
  // TODO - mipLevels are set when attaching texture to framebuffer
@@ -148,10 +174,10 @@ function _copyTextureToBuffer(device: WebGLDevice, options: CopyTextureToBufferO
148
174
  }
149
175
 
150
176
  // Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature
151
- const {framebuffer, destroyFramebuffer} = getFramebuffer(source);
177
+ const {framebuffer, destroyFramebuffer} = getFramebuffer(sourceTexture);
152
178
  let prevHandle: WebGLFramebuffer | null | undefined;
153
179
  try {
154
- const webglBuffer = destination as WEBGLBuffer;
180
+ const webglBuffer = destinationBuffer as WEBGLBuffer;
155
181
  const sourceWidth = width || framebuffer.width;
156
182
  const sourceHeight = height || framebuffer.height;
157
183
  const sourceParams = getTextureFormatWebGL(
@@ -220,7 +246,7 @@ export function readPixelsToBuffer(
220
246
  function _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextureOptions): void {
221
247
  const {
222
248
  /** Texture to copy to/from. */
223
- source,
249
+ sourceTexture,
224
250
  /** Mip-map level of the texture to copy to (Default 0) */
225
251
  destinationMipLevel = 0,
226
252
  /** Defines which aspects of the texture to copy to/from. */
@@ -232,7 +258,7 @@ function _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextur
232
258
  destinationOrigin = [0, 0],
233
259
 
234
260
  /** Texture to copy to/from. */
235
- destination
261
+ destinationTexture
236
262
  /** Mip-map level of the texture to copy to/from. (Default 0) */
237
263
  // destinationMipLevel = options.mipLevel,
238
264
  /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
@@ -242,12 +268,12 @@ function _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextur
242
268
  } = options;
243
269
 
244
270
  let {
245
- width = options.destination.width,
246
- height = options.destination.height
271
+ width = options.destinationTexture.width,
272
+ height = options.destinationTexture.height
247
273
  // depthOrArrayLayers = 0
248
274
  } = options;
249
275
 
250
- const {framebuffer, destroyFramebuffer} = getFramebuffer(source);
276
+ const {framebuffer, destroyFramebuffer} = getFramebuffer(sourceTexture);
251
277
  const [sourceX, sourceY] = origin;
252
278
  const [destinationX, destinationY, destinationZ] = destinationOrigin;
253
279
 
@@ -261,8 +287,8 @@ function _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextur
261
287
 
262
288
  let texture: WEBGLTexture = null;
263
289
  let textureTarget: GL;
264
- if (destination instanceof WEBGLTexture) {
265
- texture = destination;
290
+ if (destinationTexture instanceof WEBGLTexture) {
291
+ texture = destinationTexture;
266
292
  width = Number.isFinite(width) ? width : texture.width;
267
293
  height = Number.isFinite(height) ? height : texture.height;
268
294
  texture.bind(0);
@@ -311,7 +337,82 @@ function _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextur
311
337
  }
312
338
  }
313
339
 
314
- // Returns number of components in a specific readPixels WebGL format
340
+ /** Clear one mip level of a texture *
341
+ function _clearTexture(device: WebGLDevice, options: ClearTextureOptions) {
342
+ const BORDER = 0;
343
+ const {dimension, width, height, depth = 0, mipLevel = 0} = options;
344
+ const {glInternalFormat, glFormat, glType, compressed} = options;
345
+ const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
346
+
347
+ switch (dimension) {
348
+ case '2d-array':
349
+ case '3d':
350
+ if (compressed) {
351
+ // prettier-ignore
352
+ device.gl.compressedTexImage3D(glTarget, mipLevel, glInternalFormat, width, height, depth, BORDER, null);
353
+ } else {
354
+ // prettier-ignore
355
+ device.gl.texImage3D( glTarget, mipLevel, glInternalFormat, width, height, depth, BORDER, glFormat, glType, null);
356
+ }
357
+ break;
358
+
359
+ case '2d':
360
+ case 'cube':
361
+ if (compressed) {
362
+ // prettier-ignore
363
+ device.gl.compressedTexImage2D(glTarget, mipLevel, glInternalFormat, width, height, BORDER, null);
364
+ } else {
365
+ // prettier-ignore
366
+ device.gl.texImage2D(glTarget, mipLevel, glInternalFormat, width, height, BORDER, glFormat, glType, null);
367
+ }
368
+ break;
369
+
370
+ default:
371
+ throw new Error(dimension);
372
+ }
373
+ }
374
+ */
375
+
376
+ // function _readTexture(device: WebGLDevice, options: CopyTextureToBufferOptions) {}
377
+
378
+ // HELPERS
379
+
380
+ /**
381
+ * In WebGL, cube maps specify faces by overriding target instead of using the depth parameter.
382
+ * @note We still bind the texture using GL.TEXTURE_CUBE_MAP, but we need to use the face-specific target when setting mip levels.
383
+ * @returns glTarget unchanged, if dimension !== 'cube'.
384
+ */
385
+ export function getWebGLCubeFaceTarget(
386
+ glTarget: GLTextureTarget,
387
+ dimension: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d',
388
+ level: number
389
+ ): GLTextureTarget | GLTextureCubeMapTarget {
390
+ return dimension === 'cube' ? GL.TEXTURE_CUBE_MAP_POSITIVE_X + level : glTarget;
391
+ }
392
+
393
+ /** Wrap a texture in a framebuffer so that we can use WebGL APIs that work on framebuffers */
394
+ function getFramebuffer(source: Texture | Framebuffer): {
395
+ framebuffer: WEBGLFramebuffer;
396
+ destroyFramebuffer: boolean;
397
+ } {
398
+ if (source instanceof Texture) {
399
+ const {width, height, id} = source;
400
+ const framebuffer = source.device.createFramebuffer({
401
+ id: `framebuffer-for-${id}`,
402
+ width,
403
+ height,
404
+ colorAttachments: [source]
405
+ }) as unknown as WEBGLFramebuffer;
406
+
407
+ return {framebuffer, destroyFramebuffer: true};
408
+ }
409
+ return {framebuffer: source as unknown as WEBGLFramebuffer, destroyFramebuffer: false};
410
+ }
411
+
412
+ /**
413
+ * Returns number of components in a specific readPixels WebGL format
414
+ * @todo use shadertypes utils instead?
415
+ */
315
416
  export function glFormatToComponents(format): 1 | 2 | 3 | 4 {
316
417
  switch (format) {
317
418
  case GL.ALPHA:
@@ -333,7 +434,10 @@ export function glFormatToComponents(format): 1 | 2 | 3 | 4 {
333
434
  }
334
435
  }
335
436
 
336
- // Return byte count for given readPixels WebGL type
437
+ /**
438
+ * Return byte count for given readPixels WebGL type
439
+ * @todo use shadertypes utils instead?
440
+ */
337
441
  export function glTypeToBytes(type: GL): 1 | 2 | 4 {
338
442
  switch (type) {
339
443
  case GL.UNSIGNED_BYTE:
@@ -349,23 +453,3 @@ export function glTypeToBytes(type: GL): 1 | 2 | 4 {
349
453
  throw new Error('GLType');
350
454
  }
351
455
  }
352
-
353
- // Helper methods
354
-
355
- function getFramebuffer(source: Texture | Framebuffer): {
356
- framebuffer: WEBGLFramebuffer;
357
- destroyFramebuffer: boolean;
358
- } {
359
- if (source instanceof Texture) {
360
- const {width, height, id} = source;
361
- const framebuffer = source.device.createFramebuffer({
362
- id: `framebuffer-for-${id}`,
363
- width,
364
- height,
365
- colorAttachments: [source]
366
- }) as unknown as WEBGLFramebuffer;
367
-
368
- return {framebuffer, destroyFramebuffer: true};
369
- }
370
- return {framebuffer: source as unknown as WEBGLFramebuffer, destroyFramebuffer: false};
371
- }
@@ -8,6 +8,8 @@ import type {
8
8
  CopyBufferToTextureOptions,
9
9
  CopyTextureToBufferOptions,
10
10
  CopyTextureToTextureOptions,
11
+ // ClearTextureOptions,
12
+ // ReadTextureOptions,
11
13
  QuerySet,
12
14
  Buffer
13
15
  } from '@luma.gl/core';
@@ -52,6 +54,10 @@ export class WEBGLCommandEncoder extends CommandEncoder {
52
54
  this.commandBuffer.commands.push({name: 'copy-texture-to-texture', options});
53
55
  }
54
56
 
57
+ // clearTexture(options: ClearTextureOptions): void {
58
+ // this.commandBuffer.commands.push({name: 'copy-texture-to-texture', options});
59
+ // }
60
+
55
61
  override pushDebugGroup(groupLabel: string): void {}
56
62
  override popDebugGroup() {}
57
63
 
@@ -72,6 +72,20 @@ export class WEBGLExternalTexture extends WEBGLTexture {
72
72
  data.addEventListener('loadeddata', () => this.initialize(props));
73
73
  return this;
74
74
  }
75
+ }
76
+
77
+ initialize() {
78
+ // TODO - Video handling, move to ExternalTexture?
79
+ // if (isVideo) {
80
+ // this._video = {
81
+ // video: data,
82
+ // // TODO - should we be using the sampler parameters here?
83
+ // parameters: {},
84
+ // // @ts-expect-error HTMLVideoElement.HAVE_CURRENT_DATA is not declared
85
+ // lastTime: data.readyState >= HTMLVideoElement.HAVE_CURRENT_DATA ? data.currentTime : -1
86
+ // };
87
+ // }
88
+ }
75
89
 
76
90
  update(): this {
77
91
  if (this._video) {
@@ -2,13 +2,13 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {FramebufferProps, TextureFormat} from '@luma.gl/core';
6
- import {Framebuffer, Texture} from '@luma.gl/core';
5
+ import type {FramebufferProps} from '@luma.gl/core';
6
+ import {Framebuffer} from '@luma.gl/core';
7
7
  import {GL} from '@luma.gl/constants';
8
8
  import {WebGLDevice} from '../webgl-device';
9
9
  import {WEBGLTexture} from './webgl-texture';
10
10
  import {WEBGLTextureView} from './webgl-texture-view';
11
- import {getDepthStencilAttachmentWebGL} from '../converters/texture-formats';
11
+ import {getDepthStencilAttachmentWebGL} from '../converters/webgl-texture-table';
12
12
 
13
13
  export type Attachment = WEBGLTextureView | WEBGLTexture; // | WEBGLRenderbuffer;
14
14
 
@@ -33,45 +33,13 @@ export class WEBGLFramebuffer extends Framebuffer {
33
33
  this.props.handle || isDefaultFramebuffer ? this.props.handle : this.gl.createFramebuffer();
34
34
 
35
35
  if (!isDefaultFramebuffer) {
36
- // default framebuffer handle is null, so we can't set spector metadata...
37
- device.setSpectorMetadata(this.handle, {id: this.props.id, props: this.props});
36
+ // default framebuffer handle is null, so we can't set debug metadata...
37
+ device._setWebGLDebugMetadata(this.handle, this, {spector: this.props});
38
38
 
39
39
  // Auto create textures for attachments if needed
40
40
  this.autoCreateAttachmentTextures();
41
41
 
42
- /** Attach from a map of attachments */
43
- // @ts-expect-error native bindFramebuffer is overridden by our state tracker
44
- const prevHandle: WebGLFramebuffer | null = this.gl.bindFramebuffer(
45
- GL.FRAMEBUFFER,
46
- this.handle
47
- );
48
-
49
- // Walk the attachments
50
- for (let i = 0; i < this.colorAttachments.length; ++i) {
51
- const attachment = this.colorAttachments[i];
52
- const attachmentPoint = GL.COLOR_ATTACHMENT0 + i;
53
- if (attachment) {
54
- this._attachTexture(attachmentPoint, attachment);
55
- }
56
- }
57
-
58
- if (this.depthStencilAttachment) {
59
- this._attachTexture(
60
- getDepthStencilAttachmentWebGL(this.depthStencilAttachment.props.format),
61
- this.depthStencilAttachment
62
- );
63
- }
64
-
65
- /** Check the status */
66
- // @ts-expect-error
67
- if (props.check !== false) {
68
- const status = this.gl.checkFramebufferStatus(GL.FRAMEBUFFER) as GL;
69
- if (status !== GL.FRAMEBUFFER_COMPLETE) {
70
- throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
71
- }
72
- }
73
-
74
- this.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle);
42
+ this.updateAttachments();
75
43
  }
76
44
  }
77
45
 
@@ -84,60 +52,55 @@ export class WEBGLFramebuffer extends Framebuffer {
84
52
  }
85
53
  }
86
54
 
87
- // PRIVATE
88
-
89
- /** In WebGL we must use renderbuffers for depth/stencil attachments (unless we have extensions) */
90
- protected override createDepthStencilTexture(format: TextureFormat): Texture {
91
- // return new WEBGLRenderbuffer(this.device, {
92
- return new WEBGLTexture(this.device, {
93
- id: `${this.id}-depth-stencil`,
94
- format,
95
- width: this.width,
96
- height: this.height,
97
- mipmaps: false
98
- });
99
- }
100
-
101
- /**
102
- * Attachment resize is expected to be a noop if size is same
103
- *
104
- protected override resizeAttachments(width: number, height: number): this {
105
- // for default framebuffer, just update the stored size
106
- if (this.handle === null) {
107
- // assert(width === undefined && height === undefined);
108
- this.width = this.gl.drawingBufferWidth;
109
- this.height = this.gl.drawingBufferHeight;
110
- return this;
55
+ protected updateAttachments(): void {
56
+ /** Attach from a map of attachments */
57
+ // @ts-expect-error native bindFramebuffer is overridden by our state tracker
58
+ const prevHandle: WebGLFramebuffer | null = this.gl.bindFramebuffer(
59
+ GL.FRAMEBUFFER,
60
+ this.handle
61
+ );
62
+
63
+ // Walk the attachments
64
+ for (let i = 0; i < this.colorAttachments.length; ++i) {
65
+ const attachment = this.colorAttachments[i];
66
+ if (attachment) {
67
+ const attachmentPoint = GL.COLOR_ATTACHMENT0 + i;
68
+ this._attachTextureView(attachmentPoint, attachment);
69
+ }
111
70
  }
112
71
 
113
- if (width === undefined) {
114
- width = this.gl.drawingBufferWidth;
115
- }
116
- if (height === undefined) {
117
- height = this.gl.drawingBufferHeight;
72
+ if (this.depthStencilAttachment) {
73
+ const attachmentPoint = getDepthStencilAttachmentWebGL(
74
+ this.depthStencilAttachment.props.format
75
+ );
76
+ this._attachTextureView(attachmentPoint, this.depthStencilAttachment);
118
77
  }
119
78
 
120
- // TODO Not clear that this is better than default destroy/create implementation
121
-
122
- for (const colorAttachment of this.colorAttachments) {
123
- colorAttachment.texture.clone({width, height});
124
- }
125
- if (this.depthStencilAttachment) {
126
- this.depthStencilAttachment.texture.resize({width, height});
79
+ /** Check the status */
80
+ if (this.device.props.debug) {
81
+ const status = this.gl.checkFramebufferStatus(GL.FRAMEBUFFER) as GL;
82
+ if (status !== GL.FRAMEBUFFER_COMPLETE) {
83
+ throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
84
+ }
127
85
  }
128
- return this;
129
- }
130
- */
131
-
132
- /** Attach one attachment */
133
- protected _attachTexture(attachmentPoint: GL, textureView: WEBGLTextureView): void {
134
- // if (attachment instanceof WEBGLRenderbuffer) {
135
- // this._attachWEBGLRenderbuffer(attachmentPoint, attachment);
136
- // return attachment;
137
- // }
138
- this._attachTextureView(attachmentPoint, textureView);
86
+
87
+ this.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle);
139
88
  }
140
89
 
90
+ // PRIVATE
91
+
92
+ /** In WebGL we must use renderbuffers for depth/stencil attachments (unless we have extensions) */
93
+ // protected override createDepthStencilTexture(format: TextureFormat): Texture {
94
+ // // return new WEBGLRenderbuffer(this.device, {
95
+ // return new WEBGLTexture(this.device, {
96
+ // id: `${this.id}-depth-stencil`,
97
+ // format,
98
+ // width: this.width,
99
+ // height: this.height,
100
+ // mipmaps: false
101
+ // });
102
+ // }
103
+
141
104
  /**
142
105
  * @param attachment
143
106
  * @param texture
@@ -155,7 +118,7 @@ export class WEBGLFramebuffer extends Framebuffer {
155
118
  switch (texture.glTarget) {
156
119
  case GL.TEXTURE_2D_ARRAY:
157
120
  case GL.TEXTURE_3D:
158
- gl.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.glTarget, level, layer);
121
+ gl.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.handle, level, layer);
159
122
  break;
160
123
 
161
124
  case GL.TEXTURE_CUBE_MAP:
@@ -210,3 +173,34 @@ function _getFrameBufferStatus(status: GL) {
210
173
  return `${status}`;
211
174
  }
212
175
  }
176
+
177
+ /**
178
+ * Attachment resize is expected to be a noop if size is same
179
+ *
180
+ protected override resizeAttachments(width: number, height: number): this {
181
+ // for default framebuffer, just update the stored size
182
+ if (this.handle === null) {
183
+ // assert(width === undefined && height === undefined);
184
+ this.width = this.gl.drawingBufferWidth;
185
+ this.height = this.gl.drawingBufferHeight;
186
+ return this;
187
+ }
188
+
189
+ if (width === undefined) {
190
+ width = this.gl.drawingBufferWidth;
191
+ }
192
+ if (height === undefined) {
193
+ height = this.gl.drawingBufferHeight;
194
+ }
195
+
196
+ // TODO Not clear that this is better than default destroy/create implementation
197
+
198
+ for (const colorAttachment of this.colorAttachments) {
199
+ colorAttachment.texture.clone({width, height});
200
+ }
201
+ if (this.depthStencilAttachment) {
202
+ this.depthStencilAttachment.texture.resize({width, height});
203
+ }
204
+ return this;
205
+ }
206
+ */