@luma.gl/webgl 9.0.0-alpha.34 → 9.0.0-alpha.36

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 (73) 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 -109
  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 -1178
  46. package/dist/index.cjs +1026 -971
  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/adapter/converters/device-parameters.ts +34 -2
  54. package/src/adapter/resources/webgl-command-buffer.ts +2 -2
  55. package/src/adapter/resources/webgl-render-pass.ts +8 -6
  56. package/src/adapter/resources/webgl-render-pipeline.ts +141 -173
  57. package/src/adapter/resources/webgl-sampler.ts +1 -1
  58. package/src/adapter/resources/webgl-shader.ts +1 -1
  59. package/src/adapter/resources/webgl-texture.ts +5 -5
  60. package/src/adapter/resources/webgl-vertex-array.ts +278 -0
  61. package/src/adapter/webgl-device.ts +137 -11
  62. package/src/classic/clear.ts +3 -3
  63. package/src/classic/copy-and-blit.ts +19 -15
  64. package/src/context/context/create-browser-context.ts +12 -0
  65. package/src/context/parameters/unified-parameter-api.ts +4 -4
  66. package/src/context/state-tracker/track-context-state.ts +3 -3
  67. package/src/context/state-tracker/with-parameters.ts +3 -3
  68. package/src/index.ts +38 -16
  69. package/dist/adapter/objects/webgl-vertex-array-object.d.ts +0 -55
  70. package/dist/adapter/objects/webgl-vertex-array-object.d.ts.map +0 -1
  71. package/dist/adapter/objects/webgl-vertex-array-object.js +0 -173
  72. package/dist/adapter/objects/webgl-vertex-array-object.js.map +0 -1
  73. package/src/adapter/objects/webgl-vertex-array-object.ts +0 -276
@@ -2,7 +2,7 @@
2
2
  // NOTE: this system does not handle buffer bindings
3
3
  import {assert} from '@luma.gl/core';
4
4
  import {GL_PARAMETER_DEFAULTS, GL_HOOKED_SETTERS, NON_CACHE_PARAMETERS} from '../parameters/webgl-parameter-tables';
5
- import {setParameters, getParameters} from '../parameters/unified-parameter-api';
5
+ import {setGLParameters, getGLParameters} from '../parameters/unified-parameter-api';
6
6
  import {deepArrayEqual} from './deep-array-equal';
7
7
 
8
8
  // HELPER CLASS - GLState
@@ -24,7 +24,7 @@ class GLState {
24
24
  } = {}
25
25
  ) {
26
26
  this.gl = gl;
27
- this.cache = copyState ? getParameters(gl) : Object.assign({}, GL_PARAMETER_DEFAULTS);
27
+ this.cache = copyState ? getGLParameters(gl) : Object.assign({}, GL_PARAMETER_DEFAULTS);
28
28
  this.log = log;
29
29
 
30
30
  this._updateCache = this._updateCache.bind(this);
@@ -39,7 +39,7 @@ class GLState {
39
39
  assert(this.stateStack.length > 0);
40
40
  // Use the saved values in the state stack to restore parameters
41
41
  const oldValues = this.stateStack[this.stateStack.length - 1];
42
- setParameters(this.gl, oldValues);
42
+ setGLParameters(this.gl, oldValues);
43
43
  // Don't pop until we have reset parameters (to make sure other "stack frames" are not affected)
44
44
  this.stateStack.pop();
45
45
  }
@@ -1,6 +1,6 @@
1
1
  import type {Device} from '@luma.gl/core';
2
2
  import {WebGLDevice} from '../../adapter/webgl-device';
3
- import {GLParameters, setParameters} from '../parameters/unified-parameter-api';
3
+ import {GLParameters, setGLParameters} from '../parameters/unified-parameter-api';
4
4
  import {pushContextState, popContextState} from './track-context-state';
5
5
 
6
6
  /**
@@ -11,7 +11,7 @@ import {pushContextState, popContextState} from './track-context-state';
11
11
  * - Restores parameters
12
12
  * - Returns the return value of the supplied function
13
13
  */
14
- export function withParameters(device: Device | WebGLRenderingContext, parameters: GLParameters & {nocatch?: boolean}, func: any): any {
14
+ export function withGLParameters(device: Device | WebGLRenderingContext, parameters: GLParameters & {nocatch?: boolean}, func: any): any {
15
15
  const webglDevice = WebGLDevice.attach(device);
16
16
  const gl = webglDevice.gl;
17
17
 
@@ -23,7 +23,7 @@ export function withParameters(device: Device | WebGLRenderingContext, parameter
23
23
  const {nocatch = true} = parameters;
24
24
 
25
25
  pushContextState(gl);
26
- setParameters(gl, parameters);
26
+ setGLParameters(gl, parameters);
27
27
 
28
28
  // Setup is done, call the function
29
29
  let value;
package/src/index.ts CHANGED
@@ -27,11 +27,11 @@ export {WEBGLRenderPipeline} from './adapter/resources/webgl-render-pipeline';
27
27
  export {WEBGLCommandEncoder} from './adapter/resources/webgl-command-encoder';
28
28
  export {WEBGLRenderPass} from './adapter/resources/webgl-render-pass';
29
29
  // export {WEBGLComputePass} from './adapter/resources/webgl-compute-pass';
30
+ export {WEBGLVertexArray} from './adapter/resources/webgl-vertex-array';
30
31
 
31
32
  // non-api resources
32
33
  export type {RenderbufferProps} from './adapter/objects/webgl-renderbuffer';
33
34
  export {WEBGLRenderbuffer} from './adapter/objects/webgl-renderbuffer';
34
- export {WEBGLVertexArrayObject} from './adapter/objects/webgl-vertex-array-object';
35
35
 
36
36
  // WebGL adapter classes (Legacy will likely be removed)
37
37
  export {Accessor} from './classic/accessor';
@@ -53,32 +53,54 @@ export {setDeviceParameters, withDeviceParameters} from './adapter/converters/de
53
53
 
54
54
  export type {GLParameters} from '@luma.gl/constants';
55
55
  export {
56
- getParameters,
57
- setParameters,
58
- resetParameters
56
+ getGLParameters,
57
+ setGLParameters,
58
+ resetGLParameters
59
59
  } from './context/parameters/unified-parameter-api';
60
60
 
61
+ export {withGLParameters} from './context/state-tracker/with-parameters';
62
+
63
+ // HELPERS - EXPERIMENTAL
64
+ export {getShaderLayout} from './adapter/helpers/get-shader-layout';
61
65
  export {
62
- withParameters
63
- } from './context/state-tracker/with-parameters';
66
+ convertGLToTextureFormat,
67
+ _checkFloat32ColorAttachment
68
+ } from './adapter/converters/texture-formats';
64
69
 
70
+ // TEST EXPORTS
71
+ export {TEXTURE_FORMATS as _TEXTURE_FORMATS} from './adapter/converters/texture-formats';
72
+
73
+ // DEPRECATED EXPORTS
74
+ export {clear} from './classic/clear';
75
+ export {readPixelsToBuffer, readPixelsToArray, copyToTexture} from './classic/copy-and-blit';
65
76
  // State tracking
66
77
  export {
67
78
  trackContextState,
68
79
  pushContextState,
69
80
  popContextState
70
81
  } from './context/state-tracker/track-context-state';
71
-
72
82
  // Polyfills (supports a subset of WebGL2 APIs on WebGL1 contexts)
73
83
  export {polyfillContext} from './context/polyfill/polyfill-context';
74
84
 
75
85
  // HELPERS - EXPERIMENTAL
76
- export {getShaderLayout} from './adapter/helpers/get-shader-layout';
77
- export {convertGLToTextureFormat, _checkFloat32ColorAttachment} from './adapter/converters/texture-formats';
78
-
79
- // TEST EXPORTS
80
- export {TEXTURE_FORMATS as _TEXTURE_FORMATS} from './adapter/converters/texture-formats';
81
-
82
- // DEPRECATED EXPORTS
83
- export {clear} from './classic/clear';
84
- export {readPixelsToBuffer, readPixelsToArray, copyToTexture} from './classic/copy-and-blit';
86
+ // export {getShaderLayout, getProgramBindings} from './adapter/helpers/get-shader-layout';
87
+ // export {convertGLToTextureFormat, _checkFloat32ColorAttachment} from './adapter/converters/texture-formats';
88
+ // export {TEXTURE_FORMATS as _TEXTURE_FORMATS} from './adapter/converters/texture-formats';
89
+
90
+ // // WebGL Types - Experimental exports
91
+ // export type {
92
+ // GLDrawMode,
93
+ // GLPrimitive,
94
+ // GLDataType,
95
+ // GLPixelType,
96
+ // GLUniformType,
97
+ // GLSamplerType,
98
+ // GLCompositeType,
99
+ // GLFunction,
100
+ // GLBlendEquation,
101
+ // GLBlendFunction,
102
+ // GLStencilOp,
103
+ // GLSamplerParameters,
104
+ // GLValueParameters,
105
+ // GLFunctionParameters
106
+ // } from '@luma.gl/constants';
@@ -1,55 +0,0 @@
1
- import type { Device, Buffer, ResourceProps, TypedArray } from '@luma.gl/core';
2
- import { WebGLResource } from './webgl-resource';
3
- import { WEBGLBuffer } from '../resources/webgl-buffer';
4
- import { AccessorObject } from '../..';
5
- /**
6
- * VertexArrayObject properties
7
- * @param constantAttributeZero Attribute 0 can not be disable on most desktop OpenGL based browsers
8
- * and on iOS Safari browser.
9
- */
10
- export type VertexArrayObjectProps = ResourceProps & {
11
- constantAttributeZero?: boolean;
12
- };
13
- /** VertexArrayObject wrapper */
14
- export declare class WEBGLVertexArrayObject extends WebGLResource<VertexArrayObjectProps> {
15
- get [Symbol.toStringTag](): string;
16
- /** Buffer constant */
17
- private buffer;
18
- private bufferValue;
19
- static isConstantAttributeZeroSupported(device: Device): boolean;
20
- constructor(device: Device, props?: VertexArrayObjectProps);
21
- destroy(): void;
22
- _createHandle(): WebGLVertexArrayObject;
23
- _deleteHandle(): void;
24
- _bindHandle(handle: WEBGLVertexArrayObject): void;
25
- /**
26
- * Enabling an attribute location makes it reference the currently bound buffer
27
- * Disabling an attribute location makes it reference the global constant value
28
- * TODO - handle single values for size 1 attributes?
29
- * TODO - convert classic arrays based on known type?
30
- */
31
- enable(location: number, enable?: boolean): void;
32
- setElementBuffer(elementBuffer?: WEBGLBuffer | null, opts?: {}): void;
33
- /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
34
- setBuffer(location: number, buffer: WEBGLBuffer, accessor: AccessorObject): void;
35
- /**
36
- * Set an attribute to a constant value
37
- * @param device
38
- * @param location
39
- * @param array
40
- *
41
- * @note Constants are stored globally on the WebGL context, not the VAO
42
- * so they need to be updated before every render
43
- * @todo - use known type (in configuration or passed in) to allow non-typed arrays?
44
- * @todo - remember/cache values to avoid setting them unnecessarily?
45
- */
46
- setConstant(location: any, array: TypedArray): void;
47
- /**
48
- * Provide a means to create a buffer that is equivalent to a constant.
49
- * NOTE: Desktop OpenGL cannot disable attribute 0.
50
- * https://stackoverflow.com/questions/20305231/webgl-warning-attribute-0-is-disabled-
51
- * this-has-significant-performance-penalty
52
- */
53
- getConstantBuffer(elementCount: number, value: any): Buffer;
54
- }
55
- //# sourceMappingURL=webgl-vertex-array-object.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"webgl-vertex-array-object.d.ts","sourceRoot":"","sources":["../../../src/adapter/objects/webgl-vertex-array-object.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAe,MAAM,eAAe,CAAC;AAM3F,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAC,WAAW,EAAC,MAAM,2BAA2B,CAAC;AAGtD,OAAO,EAAC,cAAc,EAAC,MAAM,OAAO,CAAC;AAIrC;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG,aAAa,GAAG;IACnD,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAEF,gCAAgC;AAChC,qBAAa,sBAAuB,SAAQ,aAAa,CAAC,sBAAsB,CAAC;IAC/E,IAAa,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAE1C;IAED,sBAAsB;IACtB,OAAO,CAAC,MAAM,CAAmC;IACjD,OAAO,CAAC,WAAW,CAAQ;IAE3B,MAAM,CAAC,gCAAgC,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;gBAKpD,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,sBAAsB;IAKjD,OAAO,IAAI,IAAI;IAMf,aAAa;IAIb,aAAa,IAAI,IAAI;IAOrB,WAAW,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI;IAI1D;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,UAAO,GAAG,IAAI;IAgB7C,gBAAgB,CAAC,aAAa,GAAE,WAAW,GAAG,IAAW,EAAE,IAAI,KAAK;IASpE,gGAAgG;IAChG,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,GAAG,IAAI;IA+BhF;;;;;;;;;;OAUG;IACH,WAAW,CAAC,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI;IAgBnD;;;;;OAKG;IACH,iBAAiB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,KAAA,GAAG,MAAM;CA2BvD"}
@@ -1,173 +0,0 @@
1
- let _Symbol$toStringTag;
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
- import { WebGLResource } from "./webgl-resource.js";
6
- const ERR_ELEMENTS = 'elements must be GL.ELEMENT_ARRAY_BUFFER';
7
- _Symbol$toStringTag = Symbol.toStringTag;
8
- export class WEBGLVertexArrayObject extends WebGLResource {
9
- get [_Symbol$toStringTag]() {
10
- return 'BaseVertexArrayObject';
11
- }
12
- static isConstantAttributeZeroSupported(device) {
13
- return device.info.type === 'webgl2' || getBrowser() === 'Chrome';
14
- }
15
- constructor(device, props) {
16
- super(device, props, {
17
- ...Resource.defaultProps,
18
- constantAttributeZero: false
19
- });
20
- this.buffer = null;
21
- this.bufferValue = null;
22
- Object.seal(this);
23
- }
24
- destroy() {
25
- super.destroy();
26
- if (this.buffer) {
27
- var _this$buffer;
28
- (_this$buffer = this.buffer) === null || _this$buffer === void 0 ? void 0 : _this$buffer.destroy();
29
- }
30
- }
31
- _createHandle() {
32
- return this.gl2.createVertexArray();
33
- }
34
- _deleteHandle() {
35
- this.gl2.deleteVertexArray(this.handle);
36
- return [this.elements];
37
- }
38
- _bindHandle(handle) {
39
- this.gl2.bindVertexArray(handle);
40
- }
41
- enable(location) {
42
- let enable = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
43
- const canDisableAttributeZero = this.device.isWebGL2 || getBrowser() === 'Chrome';
44
- const canDisableAttribute = canDisableAttributeZero || location !== 0;
45
- if (enable || canDisableAttribute) {
46
- location = Number(location);
47
- this.bind(() => enable ? this.gl.enableVertexAttribArray(location) : this.gl.disableVertexAttribArray(location));
48
- }
49
- }
50
- setElementBuffer() {
51
- let elementBuffer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
52
- let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
53
- assert(!elementBuffer || elementBuffer.glTarget === GL.ELEMENT_ARRAY_BUFFER, ERR_ELEMENTS);
54
- this.bind(() => {
55
- this.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, elementBuffer ? elementBuffer.handle : null);
56
- });
57
- }
58
- setBuffer(location, buffer, accessor) {
59
- if (buffer.glTarget === GL.ELEMENT_ARRAY_BUFFER) {
60
- this.setElementBuffer(buffer, accessor);
61
- return;
62
- }
63
- const {
64
- size,
65
- type,
66
- stride,
67
- offset,
68
- normalized,
69
- integer,
70
- divisor
71
- } = accessor;
72
- const {
73
- gl,
74
- gl2
75
- } = this;
76
- location = Number(location);
77
- this.bind(() => {
78
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer.handle);
79
- if (integer) {
80
- this.device.assertWebGL2();
81
- gl2.vertexAttribIPointer(location, size, type, stride, offset);
82
- } else {
83
- gl.vertexAttribPointer(location, size, type, normalized, stride, offset);
84
- }
85
- gl.enableVertexAttribArray(location);
86
- gl2.vertexAttribDivisor(location, divisor || 0);
87
- });
88
- }
89
- setConstant(location, array) {
90
- switch (array.constructor) {
91
- case Float32Array:
92
- setConstantFloatArray(this.device, location, array);
93
- break;
94
- case Int32Array:
95
- setConstantIntArray(this.device, location, array);
96
- break;
97
- case Uint32Array:
98
- setConstantUintArray(this.device, location, array);
99
- break;
100
- default:
101
- assert(false);
102
- }
103
- }
104
- getConstantBuffer(elementCount, value) {
105
- const constantValue = normalizeConstantArrayValue(value);
106
- const byteLength = constantValue.byteLength * elementCount;
107
- const length = constantValue.length * elementCount;
108
- let updateNeeded = !this.buffer;
109
- this.buffer = this.buffer || this.device.createBuffer({
110
- byteLength
111
- });
112
- updateNeeded = updateNeeded || this.buffer.reallocate(byteLength);
113
- updateNeeded = updateNeeded || !compareConstantArrayValues(constantValue, this.bufferValue);
114
- if (updateNeeded) {
115
- const typedArray = getScratchArray(value.constructor, length);
116
- fillArray({
117
- target: typedArray,
118
- source: constantValue,
119
- start: 0,
120
- count: length
121
- });
122
- this.buffer.subData(typedArray);
123
- this.bufferValue = value;
124
- }
125
- return this.buffer;
126
- }
127
- }
128
- function setConstantFloatArray(device, location, array) {
129
- switch (array.length) {
130
- case 1:
131
- device.gl.vertexAttrib1fv(location, array);
132
- break;
133
- case 2:
134
- device.gl.vertexAttrib2fv(location, array);
135
- break;
136
- case 3:
137
- device.gl.vertexAttrib3fv(location, array);
138
- break;
139
- case 4:
140
- device.gl.vertexAttrib4fv(location, array);
141
- break;
142
- default:
143
- assert(false);
144
- }
145
- }
146
- function setConstantIntArray(device, location, array) {
147
- var _device$gl;
148
- device.assertWebGL2();
149
- (_device$gl = device.gl2) === null || _device$gl === void 0 ? void 0 : _device$gl.vertexAttribI4iv(location, array);
150
- }
151
- function setConstantUintArray(device, location, array) {
152
- var _device$gl2;
153
- device.assertWebGL2();
154
- (_device$gl2 = device.gl2) === null || _device$gl2 === void 0 ? void 0 : _device$gl2.vertexAttribI4uiv(location, array);
155
- }
156
- function normalizeConstantArrayValue(arrayValue) {
157
- if (Array.isArray(arrayValue)) {
158
- return new Float32Array(arrayValue);
159
- }
160
- return arrayValue;
161
- }
162
- function compareConstantArrayValues(v1, v2) {
163
- if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {
164
- return false;
165
- }
166
- for (let i = 0; i < v1.length; ++i) {
167
- if (v1[i] !== v2[i]) {
168
- return false;
169
- }
170
- }
171
- return true;
172
- }
173
- //# sourceMappingURL=webgl-vertex-array-object.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"webgl-vertex-array-object.js","names":["Resource","assert","getScratchArray","fillArray","GL","getBrowser","WebGLResource","ERR_ELEMENTS","_Symbol$toStringTag","Symbol","toStringTag","WEBGLVertexArrayObject","isConstantAttributeZeroSupported","device","info","type","constructor","props","defaultProps","constantAttributeZero","buffer","bufferValue","Object","seal","destroy","_this$buffer","_createHandle","gl2","createVertexArray","_deleteHandle","deleteVertexArray","handle","elements","_bindHandle","bindVertexArray","enable","location","arguments","length","undefined","canDisableAttributeZero","isWebGL2","canDisableAttribute","Number","bind","gl","enableVertexAttribArray","disableVertexAttribArray","setElementBuffer","elementBuffer","opts","glTarget","ELEMENT_ARRAY_BUFFER","bindBuffer","setBuffer","accessor","size","stride","offset","normalized","integer","divisor","ARRAY_BUFFER","assertWebGL2","vertexAttribIPointer","vertexAttribPointer","vertexAttribDivisor","setConstant","array","Float32Array","setConstantFloatArray","Int32Array","setConstantIntArray","Uint32Array","setConstantUintArray","getConstantBuffer","elementCount","value","constantValue","normalizeConstantArrayValue","byteLength","updateNeeded","createBuffer","reallocate","compareConstantArrayValues","typedArray","target","source","start","count","subData","vertexAttrib1fv","vertexAttrib2fv","vertexAttrib3fv","vertexAttrib4fv","_device$gl","vertexAttribI4iv","_device$gl2","vertexAttribI4uiv","arrayValue","Array","isArray","v1","v2","i"],"sources":["../../../src/adapter/objects/webgl-vertex-array-object.ts"],"sourcesContent":["import type {Device, Buffer, ResourceProps, TypedArray, NumericArray} from '@luma.gl/core';\nimport {Resource, assert, getScratchArray, fillArray} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\nimport {getBrowser} from '@probe.gl/env';\n\nimport {WebGLDevice} from '../webgl-device';\nimport {WebGLResource} from './webgl-resource';\nimport {WEBGLBuffer} from '../resources/webgl-buffer';\n\nimport {BufferWithAccessor} from '../../classic/buffer-with-accessor';\nimport {AccessorObject} from '../..';\n\nconst ERR_ELEMENTS = 'elements must be GL.ELEMENT_ARRAY_BUFFER';\n\n/**\n * VertexArrayObject properties\n * @param constantAttributeZero Attribute 0 can not be disable on most desktop OpenGL based browsers\n * and on iOS Safari browser.\n */\nexport type VertexArrayObjectProps = ResourceProps & {\n constantAttributeZero?: boolean;\n};\n\n/** VertexArrayObject wrapper */\nexport class WEBGLVertexArrayObject extends WebGLResource<VertexArrayObjectProps> {\n override get [Symbol.toStringTag](): string {\n return 'BaseVertexArrayObject';\n }\n\n /** Buffer constant */\n private buffer: BufferWithAccessor | null = null;\n private bufferValue = null;\n\n static isConstantAttributeZeroSupported(device: Device): boolean {\n return device.info.type === 'webgl2' || getBrowser() === 'Chrome';\n }\n\n // Create a VertexArray\n constructor(device: Device, props?: VertexArrayObjectProps) {\n super(device, props, {...Resource.defaultProps, constantAttributeZero: false});\n Object.seal(this);\n }\n\n override destroy(): void {\n super.destroy();\n if (this.buffer) {\n this.buffer?.destroy();\n } }\n\n override _createHandle() {\n return this.gl2.createVertexArray();\n }\n\n override _deleteHandle(): void {\n this.gl2.deleteVertexArray(this.handle);\n // @ts-expect-error\n return [this.elements];\n // return [this.elements, ...this.buffers];\n }\n\n override _bindHandle(handle: WEBGLVertexArrayObject): void {\n this.gl2.bindVertexArray(handle);\n }\n\n /**\n * Enabling an attribute location makes it reference the currently bound buffer\n * Disabling an attribute location makes it reference the global constant value\n * TODO - handle single values for size 1 attributes?\n * TODO - convert classic arrays based on known type?\n */\n enable(location: number, enable = true): void {\n // Attribute 0 cannot be disabled in most desktop OpenGL based browsers...\n const canDisableAttributeZero = this.device.isWebGL2 || getBrowser() === 'Chrome';\n const canDisableAttribute = canDisableAttributeZero || location !== 0;\n\n if (enable || canDisableAttribute) {\n location = Number(location);\n this.bind(() =>\n enable\n ? this.gl.enableVertexAttribArray(location)\n : this.gl.disableVertexAttribArray(location)\n );\n } }\n\n // Set (bind) an elements buffer, for indexed rendering.\n // Must be a Buffer bound to GL.ELEMENT_ARRAY_BUFFER. Constants not supported\n setElementBuffer(elementBuffer: WEBGLBuffer | null = null, opts = {}) {\n assert(!elementBuffer || elementBuffer.glTarget === GL.ELEMENT_ARRAY_BUFFER, ERR_ELEMENTS);\n\n // The GL.ELEMENT_ARRAY_BUFFER_BINDING is stored on the VertexArrayObject...\n this.bind(() => {\n this.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, elementBuffer ? elementBuffer.handle : null);\n });\n }\n\n /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */\n setBuffer(location: number, buffer: WEBGLBuffer, accessor: AccessorObject): void {\n // Check target\n if (buffer.glTarget === GL.ELEMENT_ARRAY_BUFFER) {\n this.setElementBuffer(buffer, accessor);\n return;\n }\n\n const {size, type, stride, offset, normalized, integer, divisor} = accessor;\n\n const {gl, gl2} = this;\n location = Number(location);\n\n this.bind(() => {\n // A non-zero buffer object must be bound to the GL_ARRAY_BUFFER target\n gl.bindBuffer(gl.ARRAY_BUFFER, buffer.handle);\n\n // WebGL2 supports *integer* data formats, i.e. GPU will see integer values\n if (integer) {\n this.device.assertWebGL2();\n gl2.vertexAttribIPointer(location, size, type, stride, offset);\n } else {\n // Attaches ARRAY_BUFFER with specified buffer format to location\n gl.vertexAttribPointer(location, size, type, normalized, stride, offset);\n }\n gl.enableVertexAttribArray(location);\n gl2.vertexAttribDivisor(location, divisor || 0);\n\n // NOTE We don't unbind buffer here, typically another buffer will be bound just after\n });\n }\n\n /**\n * Set an attribute to a constant value\n * @param device\n * @param location\n * @param array\n * \n * @note Constants are stored globally on the WebGL context, not the VAO\n * so they need to be updated before every render\n * @todo - use known type (in configuration or passed in) to allow non-typed arrays?\n * @todo - remember/cache values to avoid setting them unnecessarily?\n */\n setConstant(location: any, array: TypedArray): void {\n switch (array.constructor) {\n case Float32Array:\n setConstantFloatArray(this.device, location, array as Float32Array);\n break;\n case Int32Array:\n setConstantIntArray(this.device, location, array as Int32Array);\n break;\n case Uint32Array:\n setConstantUintArray(this.device, location, array as Uint32Array);\n break;\n default:\n assert(false);\n }\n }\n\n /**\n * Provide a means to create a buffer that is equivalent to a constant.\n * NOTE: Desktop OpenGL cannot disable attribute 0.\n * https://stackoverflow.com/questions/20305231/webgl-warning-attribute-0-is-disabled-\n * this-has-significant-performance-penalty\n */\n getConstantBuffer(elementCount: number, value): Buffer {\n // Create buffer only when needed, and reuse it (avoids inflating buffer creation statistics)\n\n const constantValue = normalizeConstantArrayValue(value);\n\n const byteLength = constantValue.byteLength * elementCount;\n const length = constantValue.length * elementCount;\n\n let updateNeeded = !this.buffer;\n\n this.buffer = this.buffer || this.device.createBuffer({byteLength}) as BufferWithAccessor;\n updateNeeded = updateNeeded || this.buffer.reallocate(byteLength);\n\n // Reallocate and update contents if needed\n updateNeeded =\n updateNeeded || !compareConstantArrayValues(constantValue, this.bufferValue);\n\n if (updateNeeded) {\n // Create a typed array that is big enough, and fill it with the required data\n const typedArray = getScratchArray(value.constructor, length);\n fillArray({target: typedArray, source: constantValue, start: 0, count: length});\n this.buffer.subData(typedArray);\n this.bufferValue = value;\n }\n\n return this.buffer;\n }\n}\n\nfunction setConstantFloatArray(device: WebGLDevice, location: number, array: Float32Array): void {\n switch (array.length) {\n case 1:\n device.gl.vertexAttrib1fv(location, array);\n break;\n case 2:\n device.gl.vertexAttrib2fv(location, array);\n break;\n case 3:\n device.gl.vertexAttrib3fv(location, array);\n break;\n case 4:\n device.gl.vertexAttrib4fv(location, array);\n break;\n default:\n assert(false);\n }\n}\n\nfunction setConstantIntArray(device: WebGLDevice, location: number, array: Int32Array): void {\n device.assertWebGL2();\n device.gl2?.vertexAttribI4iv(location, array);\n // switch (array.length) {\n // case 1:\n // gl.vertexAttribI1iv(location, array);\n // break;\n // case 2:\n // gl.vertexAttribI2iv(location, array);\n // break;\n // case 3:\n // gl.vertexAttribI3iv(location, array);\n // break;\n // case 4:\n // break;\n // default:\n // assert(false);\n // }\n}\n\nfunction setConstantUintArray(device: WebGLDevice, location: number, array: Uint32Array) {\n device.assertWebGL2();\n device.gl2?.vertexAttribI4uiv(location, array);\n // switch (array.length) {\n // case 1:\n // gl.vertexAttribI1uiv(location, array);\n // break;\n // case 2:\n // gl.vertexAttribI2uiv(location, array);\n // break;\n // case 3:\n // gl.vertexAttribI3uiv(location, array);\n // break;\n // case 4:\n // gl.vertexAttribI4uiv(location, array);\n // break;\n // default:\n // assert(false);\n // }\n}\n\n// HELPERS\n\n/**\n * TODO - convert Arrays based on known type? (read type from accessor, don't assume Float32Array)\n * TODO - handle single values for size 1 attributes?\n */\nfunction normalizeConstantArrayValue(arrayValue: NumericArray) {\n if (Array.isArray(arrayValue)) {\n return new Float32Array(arrayValue);\n }\n return arrayValue;\n}\n\n/**\n * \n */\nfunction compareConstantArrayValues(v1: NumericArray, v2: NumericArray): boolean {\n if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {\n return false;\n }\n for (let i = 0; i < v1.length; ++i) {\n if (v1[i] !== v2[i]) {\n return false;\n }\n }\n return true;\n}\n"],"mappings":";AACA,SAAQA,QAAQ,EAAEC,MAAM,EAAEC,eAAe,EAAEC,SAAS,QAAO,eAAe;AAC1E,SAAQC,EAAE,QAAO,oBAAoB;AACrC,SAAQC,UAAU,QAAO,eAAe;AAAC,SAGjCC,aAAa;AAMrB,MAAMC,YAAY,GAAG,0CAA0C;AAACC,mBAAA,GAahDC,MAAM,CAACC,WAAW;AADlC,OAAO,MAAMC,sBAAsB,SAASL,aAAa,CAAyB;EAChF,KAAAE,mBAAA,IAA4C;IAC1C,OAAO,uBAAuB;EAChC;EAMA,OAAOI,gCAAgCA,CAACC,MAAc,EAAW;IAC/D,OAAOA,MAAM,CAACC,IAAI,CAACC,IAAI,KAAK,QAAQ,IAAIV,UAAU,CAAC,CAAC,KAAK,QAAQ;EACnE;EAGAW,WAAWA,CAACH,MAAc,EAAEI,KAA8B,EAAE;IAC1D,KAAK,CAACJ,MAAM,EAAEI,KAAK,EAAE;MAAC,GAAGjB,QAAQ,CAACkB,YAAY;MAAEC,qBAA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