@luma.gl/webgl 9.1.0-alpha.10 → 9.1.0-alpha.13

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 (63) hide show
  1. package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
  2. package/dist/adapter/device-helpers/webgl-device-features.js +1 -2
  3. package/dist/adapter/helpers/format-utils.d.ts.map +1 -0
  4. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  5. package/dist/adapter/helpers/get-shader-layout.js +1 -3
  6. package/dist/adapter/helpers/typed-array-utils.d.ts.map +1 -0
  7. package/dist/adapter/helpers/webgl-texture-utils.d.ts +85 -18
  8. package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
  9. package/dist/adapter/helpers/webgl-texture-utils.js +210 -18
  10. package/dist/adapter/resources/webgl-framebuffer.d.ts +1 -2
  11. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  12. package/dist/adapter/resources/webgl-framebuffer.js +27 -31
  13. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  14. package/dist/adapter/resources/webgl-render-pipeline.d.ts +1 -3
  15. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  16. package/dist/adapter/resources/webgl-texture.d.ts +1 -1
  17. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  18. package/dist/adapter/resources/webgl-texture.js +33 -8
  19. package/dist/adapter/webgl-device.d.ts +1 -2
  20. package/dist/adapter/webgl-device.d.ts.map +1 -1
  21. package/dist/adapter/webgl-device.js +2 -2
  22. package/dist/deprecated/accessor.d.ts.map +1 -0
  23. package/dist/{classic → deprecated}/accessor.js +36 -1
  24. package/dist/deprecated/clear.d.ts.map +1 -0
  25. package/dist/{classic → deprecated}/clear.js +2 -0
  26. package/dist/dist.dev.js +514 -457
  27. package/dist/dist.min.js +2 -2
  28. package/dist/index.cjs +509 -459
  29. package/dist/index.cjs.map +4 -4
  30. package/dist/index.d.ts +1 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +1 -1
  33. package/dist/utils/fill-array.d.ts +4 -4
  34. package/dist/utils/fill-array.d.ts.map +1 -1
  35. package/package.json +5 -5
  36. package/src/adapter/device-helpers/webgl-device-features.ts +5 -2
  37. package/src/adapter/helpers/get-shader-layout.ts +1 -3
  38. package/src/adapter/helpers/webgl-texture-utils.ts +356 -37
  39. package/src/adapter/resources/webgl-framebuffer.ts +37 -42
  40. package/src/adapter/resources/webgl-render-pass.ts +3 -3
  41. package/src/adapter/resources/webgl-render-pipeline.ts +10 -3
  42. package/src/adapter/resources/webgl-texture.ts +41 -8
  43. package/src/adapter/webgl-device.ts +13 -4
  44. package/src/{classic → deprecated}/accessor.ts +44 -3
  45. package/src/{classic → deprecated}/clear.ts +3 -1
  46. package/src/index.ts +1 -1
  47. package/src/utils/fill-array.ts +4 -4
  48. package/dist/classic/accessor.d.ts.map +0 -1
  49. package/dist/classic/clear.d.ts.map +0 -1
  50. package/dist/classic/copy-and-blit.d.ts +0 -64
  51. package/dist/classic/copy-and-blit.d.ts.map +0 -1
  52. package/dist/classic/copy-and-blit.js +0 -194
  53. package/dist/classic/format-utils.d.ts.map +0 -1
  54. package/dist/classic/typed-array-utils.d.ts.map +0 -1
  55. package/src/classic/copy-and-blit.ts +0 -323
  56. /package/dist/{classic → adapter/helpers}/format-utils.d.ts +0 -0
  57. /package/dist/{classic → adapter/helpers}/format-utils.js +0 -0
  58. /package/dist/{classic → adapter/helpers}/typed-array-utils.d.ts +0 -0
  59. /package/dist/{classic → adapter/helpers}/typed-array-utils.js +0 -0
  60. /package/dist/{classic → deprecated}/accessor.d.ts +0 -0
  61. /package/dist/{classic → deprecated}/clear.d.ts +0 -0
  62. /package/src/{classic → adapter/helpers}/format-utils.ts +0 -0
  63. /package/src/{classic → adapter/helpers}/typed-array-utils.ts +0 -0
@@ -1,323 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- import {Buffer, Texture, Framebuffer, FramebufferProps} from '@luma.gl/core';
6
- import {GL} from '@luma.gl/constants';
7
-
8
- import {WEBGLFramebuffer} from '../adapter/resources/webgl-framebuffer';
9
- import {getGLTypeFromTypedArray, getTypedArrayFromGLType} from './typed-array-utils';
10
- import {glFormatToComponents, glTypeToBytes} from './format-utils';
11
- import {WEBGLBuffer} from '../adapter/resources/webgl-buffer';
12
- import {WEBGLTexture} from '../adapter/resources/webgl-texture';
13
-
14
- /**
15
- * Copies data from a type or a Texture object into ArrayBuffer object.
16
- * App can provide targetPixelArray or have it auto allocated by this method
17
- * newly allocated by this method unless provided by app.
18
- * @deprecated Use CommandEncoder.copyTextureToBuffer and Buffer.read
19
- * @note Slow requires roundtrip to GPU
20
- *
21
- * @param source
22
- * @param options
23
- * @returns pixel array,
24
- */
25
- export function readPixelsToArray(
26
- source: Framebuffer | Texture,
27
- options?: {
28
- sourceX?: number;
29
- sourceY?: number;
30
- sourceFormat?: number;
31
- sourceAttachment?: number;
32
- target?: Uint8Array | Uint16Array | Float32Array;
33
- // following parameters are auto deduced if not provided
34
- sourceWidth?: number;
35
- sourceHeight?: number;
36
- sourceDepth?: number;
37
- sourceType?: number;
38
- }
39
- ): Uint8Array | Uint16Array | Float32Array {
40
- const {
41
- sourceX = 0,
42
- sourceY = 0,
43
- sourceAttachment = GL.COLOR_ATTACHMENT0 // TODO - support gl.readBuffer
44
- } = options || {};
45
- let {
46
- target = null,
47
- // following parameters are auto deduced if not provided
48
- sourceWidth,
49
- sourceHeight,
50
- sourceDepth,
51
- sourceFormat,
52
- sourceType
53
- } = options || {};
54
-
55
- const {framebuffer, deleteFramebuffer} = getFramebuffer(source);
56
- // assert(framebuffer);
57
- const {gl, handle} = framebuffer;
58
- const attachment = sourceAttachment - GL.COLOR_ATTACHMENT0;
59
-
60
- sourceWidth ||= framebuffer.width;
61
- sourceHeight ||= framebuffer.height;
62
-
63
- // TODO - Set and unset gl.readBuffer
64
- // if (sourceAttachment === GL.COLOR_ATTACHMENT0 && handle === null) {
65
- // sourceAttachment = GL.FRONT;
66
- // }
67
-
68
- sourceDepth = framebuffer.colorAttachments[attachment]?.texture?.depth || 1;
69
-
70
- sourceFormat ||= framebuffer.colorAttachments[attachment]?.texture?.glFormat || GL.RGBA;
71
- // Deduce the type from color attachment if not provided.
72
- sourceType ||= framebuffer.colorAttachments[attachment]?.texture?.glType || GL.UNSIGNED_BYTE;
73
-
74
- // Deduce type and allocated pixelArray if needed
75
- target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight, sourceDepth);
76
-
77
- // Pixel array available, if necessary, deduce type from it.
78
- sourceType = sourceType || getGLTypeFromTypedArray(target);
79
-
80
- const prevHandle = gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
81
- gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
82
- // @ts-expect-error
83
- gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
84
- if (deleteFramebuffer) {
85
- framebuffer.destroy();
86
- }
87
- return target;
88
- }
89
-
90
- /**
91
- * Copies data from a Framebuffer or a Texture object into a Buffer object.
92
- * NOTE: doesn't wait for copy to be complete, it programs GPU to perform a DMA transffer.
93
- * @deprecated Use CommandEncoder
94
- * @param source
95
- * @param options
96
- */
97
- export function readPixelsToBuffer(
98
- source: Framebuffer | Texture,
99
- options?: {
100
- sourceX?: number;
101
- sourceY?: number;
102
- sourceFormat?: number;
103
- target?: Buffer; // A new Buffer object is created when not provided.
104
- targetByteOffset?: number; // byte offset in buffer object
105
- // following parameters are auto deduced if not provided
106
- sourceWidth?: number;
107
- sourceHeight?: number;
108
- sourceType?: number;
109
- }
110
- ): WEBGLBuffer {
111
- const {
112
- target,
113
- sourceX = 0,
114
- sourceY = 0,
115
- sourceFormat = GL.RGBA,
116
- targetByteOffset = 0
117
- } = options || {};
118
- // following parameters are auto deduced if not provided
119
- let {sourceWidth, sourceHeight, sourceType} = options || {};
120
- const {framebuffer, deleteFramebuffer} = getFramebuffer(source);
121
- // assert(framebuffer);
122
- sourceWidth = sourceWidth || framebuffer.width;
123
- sourceHeight = sourceHeight || framebuffer.height;
124
-
125
- // Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature
126
- const webglFramebuffer = framebuffer;
127
-
128
- // deduce type if not available.
129
- sourceType = sourceType || GL.UNSIGNED_BYTE;
130
-
131
- let webglBufferTarget = target as unknown as WEBGLBuffer | undefined;
132
- if (!webglBufferTarget) {
133
- // Create new buffer with enough size
134
- const components = glFormatToComponents(sourceFormat);
135
- const byteCount = glTypeToBytes(sourceType);
136
- const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
137
- webglBufferTarget = webglFramebuffer.device.createBuffer({byteLength});
138
- }
139
-
140
- // TODO(donmccurdy): Do we have tests to confirm this is working?
141
- const commandEncoder = source.device.createCommandEncoder();
142
- commandEncoder.copyTextureToBuffer({
143
- source: source as Texture,
144
- width: sourceWidth,
145
- height: sourceHeight,
146
- origin: [sourceX, sourceY],
147
- destination: webglBufferTarget,
148
- byteOffset: targetByteOffset
149
- });
150
- commandEncoder.destroy();
151
-
152
- if (deleteFramebuffer) {
153
- framebuffer.destroy();
154
- }
155
-
156
- return webglBufferTarget;
157
- }
158
-
159
- /**
160
- * Copy a rectangle from a Framebuffer or Texture object into a texture (at an offset)
161
- * @deprecated Use CommandEncoder
162
- */
163
- // eslint-disable-next-line complexity, max-statements
164
- export function copyToTexture(
165
- source: Framebuffer | Texture,
166
- target: Texture | GL,
167
- options?: {
168
- sourceX?: number;
169
- sourceY?: number;
170
-
171
- targetX?: number;
172
- targetY?: number;
173
- targetZ?: number;
174
- targetMipmaplevel?: number;
175
- targetInternalFormat?: number;
176
-
177
- width?: number; // defaults to target width
178
- height?: number; // defaults to target height
179
- }
180
- ): Texture {
181
- const {
182
- sourceX = 0,
183
- sourceY = 0,
184
- // attachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer
185
- targetMipmaplevel = 0,
186
- targetInternalFormat = GL.RGBA
187
- } = options || {};
188
- let {
189
- targetX,
190
- targetY,
191
- targetZ,
192
- width, // defaults to target width
193
- height // defaults to target height
194
- } = options || {};
195
-
196
- const {framebuffer, deleteFramebuffer} = getFramebuffer(source);
197
- // assert(framebuffer);
198
- const webglFramebuffer = framebuffer;
199
- const {device, handle} = webglFramebuffer;
200
- const isSubCopy =
201
- typeof targetX !== 'undefined' ||
202
- typeof targetY !== 'undefined' ||
203
- typeof targetZ !== 'undefined';
204
- targetX = targetX || 0;
205
- targetY = targetY || 0;
206
- targetZ = targetZ || 0;
207
- const prevHandle = device.gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
208
- // TODO - support gl.readBuffer (WebGL2 only)
209
- // const prevBuffer = gl.readBuffer(attachment);
210
- // assert(target);
211
- let texture: WEBGLTexture | null = null;
212
- let textureTarget: GL;
213
- if (target instanceof WEBGLTexture) {
214
- texture = target;
215
- width = Number.isFinite(width) ? width : texture.width;
216
- height = Number.isFinite(height) ? height : texture.height;
217
- texture?.bind(0);
218
- // @ts-ignore
219
- textureTarget = texture.target;
220
- } else {
221
- // @ts-ignore
222
- textureTarget = target;
223
- }
224
-
225
- if (!isSubCopy) {
226
- device.gl.copyTexImage2D(
227
- textureTarget,
228
- targetMipmaplevel,
229
- targetInternalFormat,
230
- sourceX,
231
- sourceY,
232
- width,
233
- height,
234
- 0 /* border must be 0 */
235
- );
236
- } else {
237
- switch (textureTarget) {
238
- case GL.TEXTURE_2D:
239
- case GL.TEXTURE_CUBE_MAP:
240
- device.gl.copyTexSubImage2D(
241
- textureTarget,
242
- targetMipmaplevel,
243
- targetX,
244
- targetY,
245
- sourceX,
246
- sourceY,
247
- width,
248
- height
249
- );
250
- break;
251
- case GL.TEXTURE_2D_ARRAY:
252
- case GL.TEXTURE_3D:
253
- device.gl.copyTexSubImage3D(
254
- textureTarget,
255
- targetMipmaplevel,
256
- targetX,
257
- targetY,
258
- targetZ,
259
- sourceX,
260
- sourceY,
261
- width,
262
- height
263
- );
264
- break;
265
- default:
266
- }
267
- }
268
- if (texture) {
269
- texture.unbind();
270
- }
271
- // @ts-expect-error
272
- device.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
273
- if (deleteFramebuffer) {
274
- framebuffer.destroy();
275
- }
276
- return texture;
277
- }
278
-
279
- function getFramebuffer(source: Texture | Framebuffer): {
280
- framebuffer: WEBGLFramebuffer;
281
- deleteFramebuffer: boolean;
282
- } {
283
- if (!(source instanceof Framebuffer)) {
284
- return {framebuffer: toFramebuffer(source), deleteFramebuffer: true};
285
- }
286
- return {framebuffer: source as WEBGLFramebuffer, deleteFramebuffer: false};
287
- }
288
-
289
- /**
290
- * Wraps a given texture into a framebuffer object, that can be further used
291
- * to read data from the texture object.
292
- */
293
- export function toFramebuffer(texture: Texture, props?: FramebufferProps): WEBGLFramebuffer {
294
- const {device, width, height, id} = texture;
295
- const framebuffer = device.createFramebuffer({
296
- ...props,
297
- id: `framebuffer-for-${id}`,
298
- width,
299
- height,
300
- colorAttachments: [texture]
301
- });
302
- return framebuffer as WEBGLFramebuffer;
303
- }
304
-
305
- // eslint-disable-next-line max-params
306
- function getPixelArray(
307
- pixelArray,
308
- type,
309
- format,
310
- width: number,
311
- height: number,
312
- depth?: number
313
- ): Uint8Array | Uint16Array | Float32Array {
314
- if (pixelArray) {
315
- return pixelArray;
316
- }
317
- // Allocate pixel array if not already available, using supplied type
318
- type = type || GL.UNSIGNED_BYTE;
319
- const ArrayType = getTypedArrayFromGLType(type, {clamped: false});
320
- const components = glFormatToComponents(format);
321
- // TODO - check for composite type (components = 1).
322
- return new ArrayType(width * height * components) as Uint8Array | Uint16Array | Float32Array;
323
- }
File without changes
File without changes