@luma.gl/webgl 9.0.0-alpha.35 → 9.0.0-alpha.37

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 (76) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts +9 -0
  2. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  3. package/dist/adapter/converters/device-parameters.js +15 -2
  4. package/dist/adapter/converters/device-parameters.js.map +1 -1
  5. package/dist/adapter/resources/webgl-command-buffer.js +0 -1
  6. package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
  7. package/dist/adapter/resources/webgl-render-pass.d.ts +2 -2
  8. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  9. package/dist/adapter/resources/webgl-render-pass.js +5 -3
  10. package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
  11. package/dist/adapter/resources/webgl-render-pipeline.d.ts +23 -28
  12. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  13. package/dist/adapter/resources/webgl-render-pipeline.js +41 -110
  14. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
  15. package/dist/adapter/resources/webgl-sampler.js.map +1 -1
  16. package/dist/adapter/resources/webgl-shader.js +3 -1
  17. package/dist/adapter/resources/webgl-shader.js.map +1 -1
  18. package/dist/adapter/resources/webgl-texture.js +5 -5
  19. package/dist/adapter/resources/webgl-texture.js.map +1 -1
  20. package/dist/adapter/resources/webgl-vertex-array.d.ts +67 -0
  21. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -0
  22. package/dist/adapter/resources/webgl-vertex-array.js +166 -0
  23. package/dist/adapter/resources/webgl-vertex-array.js.map +1 -0
  24. package/dist/adapter/webgl-device.d.ts +11 -1
  25. package/dist/adapter/webgl-device.d.ts.map +1 -1
  26. package/dist/adapter/webgl-device.js +66 -1
  27. package/dist/adapter/webgl-device.js.map +1 -1
  28. package/dist/classic/clear.js +3 -3
  29. package/dist/classic/clear.js.map +1 -1
  30. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  31. package/dist/classic/copy-and-blit.js +7 -9
  32. package/dist/classic/copy-and-blit.js.map +1 -1
  33. package/dist/context/context/create-browser-context.d.ts.map +1 -1
  34. package/dist/context/context/create-browser-context.js.map +1 -1
  35. package/dist/context/parameters/unified-parameter-api.d.ts +3 -3
  36. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  37. package/dist/context/parameters/unified-parameter-api.js +4 -4
  38. package/dist/context/parameters/unified-parameter-api.js.map +1 -1
  39. package/dist/context/state-tracker/track-context-state.js +3 -3
  40. package/dist/context/state-tracker/track-context-state.js.map +1 -1
  41. package/dist/context/state-tracker/with-parameters.d.ts +1 -1
  42. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  43. package/dist/context/state-tracker/with-parameters.js +3 -3
  44. package/dist/context/state-tracker/with-parameters.js.map +1 -1
  45. package/dist/dist.dev.js +1273 -1179
  46. package/dist/index.cjs +1026 -972
  47. package/dist/index.d.ts +5 -5
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +5 -5
  50. package/dist/index.js.map +1 -1
  51. package/dist.min.js +22 -22
  52. package/package.json +5 -5
  53. package/src/.DS_Store +0 -0
  54. package/src/adapter/.DS_Store +0 -0
  55. package/src/adapter/converters/device-parameters.ts +34 -2
  56. package/src/adapter/resources/webgl-command-buffer.ts +2 -2
  57. package/src/adapter/resources/webgl-render-pass.ts +8 -6
  58. package/src/adapter/resources/webgl-render-pipeline.ts +141 -174
  59. package/src/adapter/resources/webgl-sampler.ts +1 -1
  60. package/src/adapter/resources/webgl-shader.ts +1 -1
  61. package/src/adapter/resources/webgl-texture.ts +5 -5
  62. package/src/adapter/resources/webgl-vertex-array.ts +278 -0
  63. package/src/adapter/webgl-device.ts +137 -11
  64. package/src/classic/clear.ts +3 -3
  65. package/src/classic/copy-and-blit.ts +19 -15
  66. package/src/context/.DS_Store +0 -0
  67. package/src/context/context/create-browser-context.ts +12 -0
  68. package/src/context/parameters/unified-parameter-api.ts +4 -4
  69. package/src/context/state-tracker/track-context-state.ts +3 -3
  70. package/src/context/state-tracker/with-parameters.ts +3 -3
  71. package/src/index.ts +38 -16
  72. package/dist/adapter/objects/webgl-vertex-array-object.d.ts +0 -55
  73. package/dist/adapter/objects/webgl-vertex-array-object.d.ts.map +0 -1
  74. package/dist/adapter/objects/webgl-vertex-array-object.js +0 -173
  75. package/dist/adapter/objects/webgl-vertex-array-object.js.map +0 -1
  76. package/src/adapter/objects/webgl-vertex-array-object.ts +0 -276
@@ -1,276 +0,0 @@
1
- import type {Device, Buffer, ResourceProps, TypedArray, NumericArray} from '@luma.gl/core';
2
- import {Resource, assert, getScratchArray, fillArray} from '@luma.gl/core';
3
- import {GL} from '@luma.gl/constants';
4
- import {getBrowser} from '@probe.gl/env';
5
-
6
- import {WebGLDevice} from '../webgl-device';
7
- import {WebGLResource} from './webgl-resource';
8
- import {WEBGLBuffer} from '../resources/webgl-buffer';
9
-
10
- import {BufferWithAccessor} from '../../classic/buffer-with-accessor';
11
- import {AccessorObject} from '../..';
12
-
13
- const ERR_ELEMENTS = 'elements must be GL.ELEMENT_ARRAY_BUFFER';
14
-
15
- /**
16
- * VertexArrayObject properties
17
- * @param constantAttributeZero Attribute 0 can not be disable on most desktop OpenGL based browsers
18
- * and on iOS Safari browser.
19
- */
20
- export type VertexArrayObjectProps = ResourceProps & {
21
- constantAttributeZero?: boolean;
22
- };
23
-
24
- /** VertexArrayObject wrapper */
25
- export class WEBGLVertexArrayObject extends WebGLResource<VertexArrayObjectProps> {
26
- override get [Symbol.toStringTag](): string {
27
- return 'BaseVertexArrayObject';
28
- }
29
-
30
- /** Buffer constant */
31
- private buffer: BufferWithAccessor | null = null;
32
- private bufferValue = null;
33
-
34
- static isConstantAttributeZeroSupported(device: Device): boolean {
35
- return device.info.type === 'webgl2' || getBrowser() === 'Chrome';
36
- }
37
-
38
- // Create a VertexArray
39
- constructor(device: Device, props?: VertexArrayObjectProps) {
40
- super(device, props, {...Resource.defaultProps, constantAttributeZero: false});
41
- Object.seal(this);
42
- }
43
-
44
- override destroy(): void {
45
- super.destroy();
46
- if (this.buffer) {
47
- this.buffer?.destroy();
48
- } }
49
-
50
- override _createHandle() {
51
- return this.gl2.createVertexArray();
52
- }
53
-
54
- override _deleteHandle(): void {
55
- this.gl2.deleteVertexArray(this.handle);
56
- // @ts-expect-error
57
- return [this.elements];
58
- // return [this.elements, ...this.buffers];
59
- }
60
-
61
- override _bindHandle(handle: WEBGLVertexArrayObject): void {
62
- this.gl2.bindVertexArray(handle);
63
- }
64
-
65
- /**
66
- * Enabling an attribute location makes it reference the currently bound buffer
67
- * Disabling an attribute location makes it reference the global constant value
68
- * TODO - handle single values for size 1 attributes?
69
- * TODO - convert classic arrays based on known type?
70
- */
71
- enable(location: number, enable = true): void {
72
- // Attribute 0 cannot be disabled in most desktop OpenGL based browsers...
73
- const canDisableAttributeZero = this.device.isWebGL2 || getBrowser() === 'Chrome';
74
- const canDisableAttribute = canDisableAttributeZero || location !== 0;
75
-
76
- if (enable || canDisableAttribute) {
77
- location = Number(location);
78
- this.bind(() =>
79
- enable
80
- ? this.gl.enableVertexAttribArray(location)
81
- : this.gl.disableVertexAttribArray(location)
82
- );
83
- } }
84
-
85
- // Set (bind) an elements buffer, for indexed rendering.
86
- // Must be a Buffer bound to GL.ELEMENT_ARRAY_BUFFER. Constants not supported
87
- setElementBuffer(elementBuffer: WEBGLBuffer | null = null, opts = {}) {
88
- assert(!elementBuffer || elementBuffer.glTarget === GL.ELEMENT_ARRAY_BUFFER, ERR_ELEMENTS);
89
-
90
- // The GL.ELEMENT_ARRAY_BUFFER_BINDING is stored on the VertexArrayObject...
91
- this.bind(() => {
92
- this.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, elementBuffer ? elementBuffer.handle : null);
93
- });
94
- }
95
-
96
- /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
97
- setBuffer(location: number, buffer: WEBGLBuffer, accessor: AccessorObject): void {
98
- // Check target
99
- if (buffer.glTarget === GL.ELEMENT_ARRAY_BUFFER) {
100
- this.setElementBuffer(buffer, accessor);
101
- return;
102
- }
103
-
104
- const {size, type, stride, offset, normalized, integer, divisor} = accessor;
105
-
106
- const {gl, gl2} = this;
107
- location = Number(location);
108
-
109
- this.bind(() => {
110
- // A non-zero buffer object must be bound to the GL_ARRAY_BUFFER target
111
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer.handle);
112
-
113
- // WebGL2 supports *integer* data formats, i.e. GPU will see integer values
114
- if (integer) {
115
- this.device.assertWebGL2();
116
- gl2.vertexAttribIPointer(location, size, type, stride, offset);
117
- } else {
118
- // Attaches ARRAY_BUFFER with specified buffer format to location
119
- gl.vertexAttribPointer(location, size, type, normalized, stride, offset);
120
- }
121
- gl.enableVertexAttribArray(location);
122
- gl2.vertexAttribDivisor(location, divisor || 0);
123
-
124
- // NOTE We don't unbind buffer here, typically another buffer will be bound just after
125
- });
126
- }
127
-
128
- /**
129
- * Set an attribute to a constant value
130
- * @param device
131
- * @param location
132
- * @param array
133
- *
134
- * @note Constants are stored globally on the WebGL context, not the VAO
135
- * so they need to be updated before every render
136
- * @todo - use known type (in configuration or passed in) to allow non-typed arrays?
137
- * @todo - remember/cache values to avoid setting them unnecessarily?
138
- */
139
- setConstant(location: any, array: TypedArray): void {
140
- switch (array.constructor) {
141
- case Float32Array:
142
- setConstantFloatArray(this.device, location, array as Float32Array);
143
- break;
144
- case Int32Array:
145
- setConstantIntArray(this.device, location, array as Int32Array);
146
- break;
147
- case Uint32Array:
148
- setConstantUintArray(this.device, location, array as Uint32Array);
149
- break;
150
- default:
151
- assert(false);
152
- }
153
- }
154
-
155
- /**
156
- * Provide a means to create a buffer that is equivalent to a constant.
157
- * NOTE: Desktop OpenGL cannot disable attribute 0.
158
- * https://stackoverflow.com/questions/20305231/webgl-warning-attribute-0-is-disabled-
159
- * this-has-significant-performance-penalty
160
- */
161
- getConstantBuffer(elementCount: number, value): Buffer {
162
- // Create buffer only when needed, and reuse it (avoids inflating buffer creation statistics)
163
-
164
- const constantValue = normalizeConstantArrayValue(value);
165
-
166
- const byteLength = constantValue.byteLength * elementCount;
167
- const length = constantValue.length * elementCount;
168
-
169
- let updateNeeded = !this.buffer;
170
-
171
- this.buffer = this.buffer || this.device.createBuffer({byteLength}) as BufferWithAccessor;
172
- updateNeeded = updateNeeded || this.buffer.reallocate(byteLength);
173
-
174
- // Reallocate and update contents if needed
175
- updateNeeded =
176
- updateNeeded || !compareConstantArrayValues(constantValue, this.bufferValue);
177
-
178
- if (updateNeeded) {
179
- // Create a typed array that is big enough, and fill it with the required data
180
- const typedArray = getScratchArray(value.constructor, length);
181
- fillArray({target: typedArray, source: constantValue, start: 0, count: length});
182
- this.buffer.subData(typedArray);
183
- this.bufferValue = value;
184
- }
185
-
186
- return this.buffer;
187
- }
188
- }
189
-
190
- function setConstantFloatArray(device: WebGLDevice, location: number, array: Float32Array): void {
191
- switch (array.length) {
192
- case 1:
193
- device.gl.vertexAttrib1fv(location, array);
194
- break;
195
- case 2:
196
- device.gl.vertexAttrib2fv(location, array);
197
- break;
198
- case 3:
199
- device.gl.vertexAttrib3fv(location, array);
200
- break;
201
- case 4:
202
- device.gl.vertexAttrib4fv(location, array);
203
- break;
204
- default:
205
- assert(false);
206
- }
207
- }
208
-
209
- function setConstantIntArray(device: WebGLDevice, location: number, array: Int32Array): void {
210
- device.assertWebGL2();
211
- device.gl2?.vertexAttribI4iv(location, array);
212
- // switch (array.length) {
213
- // case 1:
214
- // gl.vertexAttribI1iv(location, array);
215
- // break;
216
- // case 2:
217
- // gl.vertexAttribI2iv(location, array);
218
- // break;
219
- // case 3:
220
- // gl.vertexAttribI3iv(location, array);
221
- // break;
222
- // case 4:
223
- // break;
224
- // default:
225
- // assert(false);
226
- // }
227
- }
228
-
229
- function setConstantUintArray(device: WebGLDevice, location: number, array: Uint32Array) {
230
- device.assertWebGL2();
231
- device.gl2?.vertexAttribI4uiv(location, array);
232
- // switch (array.length) {
233
- // case 1:
234
- // gl.vertexAttribI1uiv(location, array);
235
- // break;
236
- // case 2:
237
- // gl.vertexAttribI2uiv(location, array);
238
- // break;
239
- // case 3:
240
- // gl.vertexAttribI3uiv(location, array);
241
- // break;
242
- // case 4:
243
- // gl.vertexAttribI4uiv(location, array);
244
- // break;
245
- // default:
246
- // assert(false);
247
- // }
248
- }
249
-
250
- // HELPERS
251
-
252
- /**
253
- * TODO - convert Arrays based on known type? (read type from accessor, don't assume Float32Array)
254
- * TODO - handle single values for size 1 attributes?
255
- */
256
- function normalizeConstantArrayValue(arrayValue: NumericArray) {
257
- if (Array.isArray(arrayValue)) {
258
- return new Float32Array(arrayValue);
259
- }
260
- return arrayValue;
261
- }
262
-
263
- /**
264
- *
265
- */
266
- function compareConstantArrayValues(v1: NumericArray, v2: NumericArray): boolean {
267
- if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {
268
- return false;
269
- }
270
- for (let i = 0; i < v1.length; ++i) {
271
- if (v1[i] !== v2[i]) {
272
- return false;
273
- }
274
- }
275
- return true;
276
- }