@luma.gl/webgl 9.0.0-alpha.26 → 9.0.0-alpha.29

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 (56) hide show
  1. package/dist/adapter/helpers/get-shader-layout.d.ts +8 -5
  2. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  3. package/dist/adapter/helpers/get-shader-layout.js +59 -16
  4. package/dist/adapter/helpers/get-shader-layout.js.map +1 -1
  5. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts +12 -0
  6. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -0
  7. package/dist/adapter/helpers/get-vertex-buffer-layout.js +84 -0
  8. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -0
  9. package/dist/adapter/objects/webgl-vertex-array-object.d.ts +35 -8
  10. package/dist/adapter/objects/webgl-vertex-array-object.d.ts.map +1 -1
  11. package/dist/adapter/objects/webgl-vertex-array-object.js +116 -16
  12. package/dist/adapter/objects/webgl-vertex-array-object.js.map +1 -1
  13. package/dist/adapter/resources/webgl-buffer.d.ts +13 -4
  14. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  15. package/dist/adapter/resources/webgl-buffer.js +23 -21
  16. package/dist/adapter/resources/webgl-buffer.js.map +1 -1
  17. package/dist/adapter/resources/webgl-external-texture.js.map +1 -1
  18. package/dist/adapter/resources/webgl-render-pipeline.d.ts +38 -5
  19. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  20. package/dist/adapter/resources/webgl-render-pipeline.js +35 -7
  21. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
  22. package/dist/adapter/webgl-device.d.ts.map +1 -1
  23. package/dist/adapter/webgl-device.js +5 -2
  24. package/dist/adapter/webgl-device.js.map +1 -1
  25. package/dist/classic/buffer-with-accessor.d.ts +5 -15
  26. package/dist/classic/buffer-with-accessor.d.ts.map +1 -1
  27. package/dist/classic/buffer-with-accessor.js +25 -30
  28. package/dist/classic/buffer-with-accessor.js.map +1 -1
  29. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  30. package/dist/classic/copy-and-blit.js +2 -2
  31. package/dist/classic/copy-and-blit.js.map +1 -1
  32. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  33. package/dist/context/debug/webgl-developer-tools.js +2 -1
  34. package/dist/context/debug/webgl-developer-tools.js.map +1 -1
  35. package/dist/context/parameters/webgl-parameter-tables.js +2 -2
  36. package/dist/context/parameters/webgl-parameter-tables.js.map +1 -1
  37. package/dist/dist.dev.js +350 -99
  38. package/dist/index.cjs +343 -157
  39. package/dist/index.d.ts +1 -1
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +1 -1
  42. package/dist/index.js.map +1 -1
  43. package/dist.min.js +22 -22
  44. package/package.json +5 -5
  45. package/src/adapter/helpers/get-shader-layout.ts +93 -33
  46. package/src/adapter/helpers/get-vertex-buffer-layout.ts +123 -0
  47. package/src/adapter/objects/webgl-vertex-array-object.ts +192 -28
  48. package/src/adapter/resources/webgl-buffer.ts +40 -41
  49. package/src/adapter/resources/webgl-external-texture.ts +1 -1
  50. package/src/adapter/resources/webgl-render-pipeline.ts +73 -36
  51. package/src/adapter/webgl-device.ts +4 -2
  52. package/src/classic/buffer-with-accessor.ts +42 -43
  53. package/src/classic/copy-and-blit.ts +2 -3
  54. package/src/context/debug/webgl-developer-tools.ts +8 -2
  55. package/src/context/parameters/webgl-parameter-tables.ts +2 -2
  56. package/src/index.ts +1 -1
@@ -1,14 +1,33 @@
1
- import { assert } from '@luma.gl/api';
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ let _Symbol$toStringTag;
3
+ import { Resource, assert, getScratchArray, fillArray } from '@luma.gl/api';
2
4
  import { GL } from '@luma.gl/constants';
3
5
  import { getBrowser } from '@probe.gl/env';
4
6
  import { WebGLResource } from "./webgl-resource.js";
5
7
  const ERR_ELEMENTS = 'elements must be GL.ELEMENT_ARRAY_BUFFER';
8
+ _Symbol$toStringTag = Symbol.toStringTag;
6
9
  export class WEBGLVertexArrayObject extends WebGLResource {
7
- get [Symbol.toStringTag]() {
10
+ get [_Symbol$toStringTag]() {
8
11
  return 'BaseVertexArrayObject';
9
12
  }
13
+ static isConstantAttributeZeroSupported(device) {
14
+ return device.info.type === 'webgl2' || getBrowser() === 'Chrome';
15
+ }
10
16
  constructor(device, props) {
11
- super(device, props, {});
17
+ super(device, props, {
18
+ ...Resource.defaultProps,
19
+ constantAttributeZero: false
20
+ });
21
+ _defineProperty(this, "buffer", null);
22
+ _defineProperty(this, "bufferValue", null);
23
+ Object.seal(this);
24
+ }
25
+ destroy() {
26
+ super.destroy();
27
+ if (this.buffer) {
28
+ var _this$buffer;
29
+ (_this$buffer = this.buffer) === null || _this$buffer === void 0 ? void 0 : _this$buffer.destroy();
30
+ }
12
31
  }
13
32
  _createHandle() {
14
33
  return this.gl2.createVertexArray();
@@ -20,18 +39,27 @@ export class WEBGLVertexArrayObject extends WebGLResource {
20
39
  _bindHandle(handle) {
21
40
  this.gl2.bindVertexArray(handle);
22
41
  }
42
+ enable(location) {
43
+ let enable = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
44
+ const canDisableAttributeZero = this.device.isWebGL2 || getBrowser() === 'Chrome';
45
+ const canDisableAttribute = canDisableAttributeZero || location !== 0;
46
+ if (enable || canDisableAttribute) {
47
+ location = Number(location);
48
+ this.bind(() => enable ? this.gl.enableVertexAttribArray(location) : this.gl.disableVertexAttribArray(location));
49
+ }
50
+ }
23
51
  setElementBuffer() {
24
52
  let elementBuffer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
25
53
  let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
26
- assert(!elementBuffer || elementBuffer.target === GL.ELEMENT_ARRAY_BUFFER, ERR_ELEMENTS);
54
+ assert(!elementBuffer || elementBuffer.glTarget === GL.ELEMENT_ARRAY_BUFFER, ERR_ELEMENTS);
27
55
  this.bind(() => {
28
56
  this.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, elementBuffer ? elementBuffer.handle : null);
29
57
  });
30
- return this;
31
58
  }
32
59
  setBuffer(location, buffer, accessor) {
33
- if (buffer.target === GL.ELEMENT_ARRAY_BUFFER) {
34
- return this.setElementBuffer(buffer, accessor);
60
+ if (buffer.glTarget === GL.ELEMENT_ARRAY_BUFFER) {
61
+ this.setElementBuffer(buffer, accessor);
62
+ return;
35
63
  }
36
64
  const {
37
65
  size,
@@ -58,17 +86,89 @@ export class WEBGLVertexArrayObject extends WebGLResource {
58
86
  gl.enableVertexAttribArray(location);
59
87
  gl2.vertexAttribDivisor(location, divisor || 0);
60
88
  });
61
- return this;
62
89
  }
63
- enable(location) {
64
- let enable = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
65
- const canDisableAttributeZero = this.device.isWebGL2 || getBrowser() === 'Chrome';
66
- const canDisableAttribute = canDisableAttributeZero || location !== 0;
67
- if (enable || canDisableAttribute) {
68
- location = Number(location);
69
- this.bind(() => enable ? this.gl.enableVertexAttribArray(location) : this.gl.disableVertexAttribArray(location));
90
+ setConstant(location, array) {
91
+ switch (array.constructor) {
92
+ case Float32Array:
93
+ setConstantFloatArray(this.device, location, array);
94
+ break;
95
+ case Int32Array:
96
+ setConstantIntArray(this.device, location, array);
97
+ break;
98
+ case Uint32Array:
99
+ setConstantUintArray(this.device, location, array);
100
+ break;
101
+ default:
102
+ assert(false);
103
+ }
104
+ }
105
+ getConstantBuffer(elementCount, value) {
106
+ const constantValue = normalizeConstantArrayValue(value);
107
+ const byteLength = constantValue.byteLength * elementCount;
108
+ const length = constantValue.length * elementCount;
109
+ let updateNeeded = !this.buffer;
110
+ this.buffer = this.buffer || this.device.createBuffer({
111
+ byteLength
112
+ });
113
+ updateNeeded = updateNeeded || this.buffer.reallocate(byteLength);
114
+ updateNeeded = updateNeeded || !compareConstantArrayValues(constantValue, this.bufferValue);
115
+ if (updateNeeded) {
116
+ const typedArray = getScratchArray(value.constructor, length);
117
+ fillArray({
118
+ target: typedArray,
119
+ source: constantValue,
120
+ start: 0,
121
+ count: length
122
+ });
123
+ this.buffer.subData(typedArray);
124
+ this.bufferValue = value;
125
+ }
126
+ return this.buffer;
127
+ }
128
+ }
129
+ function setConstantFloatArray(device, location, array) {
130
+ switch (array.length) {
131
+ case 1:
132
+ device.gl.vertexAttrib1fv(location, array);
133
+ break;
134
+ case 2:
135
+ device.gl.vertexAttrib2fv(location, array);
136
+ break;
137
+ case 3:
138
+ device.gl.vertexAttrib3fv(location, array);
139
+ break;
140
+ case 4:
141
+ device.gl.vertexAttrib4fv(location, array);
142
+ break;
143
+ default:
144
+ assert(false);
145
+ }
146
+ }
147
+ function setConstantIntArray(device, location, array) {
148
+ var _device$gl;
149
+ device.assertWebGL2();
150
+ (_device$gl = device.gl2) === null || _device$gl === void 0 ? void 0 : _device$gl.vertexAttribI4iv(location, array);
151
+ }
152
+ function setConstantUintArray(device, location, array) {
153
+ var _device$gl2;
154
+ device.assertWebGL2();
155
+ (_device$gl2 = device.gl2) === null || _device$gl2 === void 0 ? void 0 : _device$gl2.vertexAttribI4uiv(location, array);
156
+ }
157
+ function normalizeConstantArrayValue(arrayValue) {
158
+ if (Array.isArray(arrayValue)) {
159
+ return new Float32Array(arrayValue);
160
+ }
161
+ return arrayValue;
162
+ }
163
+ function compareConstantArrayValues(v1, v2) {
164
+ if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {
165
+ return false;
166
+ }
167
+ for (let i = 0; i < v1.length; ++i) {
168
+ if (v1[i] !== v2[i]) {
169
+ return false;
70
170
  }
71
- return this;
72
171
  }
172
+ return true;
73
173
  }
74
174
  //# sourceMappingURL=webgl-vertex-array-object.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-vertex-array-object.js","names":["assert","GL","getBrowser","WebGLResource","ERR_ELEMENTS","WEBGLVertexArrayObject","Symbol","toStringTag","constructor","device","props","_createHandle","gl2","createVertexArray","_deleteHandle","deleteVertexArray","handle","elements","_bindHandle","bindVertexArray","setElementBuffer","elementBuffer","arguments","length","undefined","opts","target","ELEMENT_ARRAY_BUFFER","bind","gl","bindBuffer","setBuffer","location","buffer","accessor","size","type","stride","offset","normalized","integer","divisor","Number","ARRAY_BUFFER","assertWebGL2","vertexAttribIPointer","vertexAttribPointer","enableVertexAttribArray","vertexAttribDivisor","enable","canDisableAttributeZero","isWebGL2","canDisableAttribute","disableVertexAttribArray"],"sources":["../../../src/adapter/objects/webgl-vertex-array-object.ts"],"sourcesContent":["import {assert, ResourceProps} from '@luma.gl/api';\nimport {GL} from '@luma.gl/constants';\nimport {getBrowser} from '@probe.gl/env';\n\nimport {WebGLDevice} from '../webgl-device';\nimport {WebGLResource} from './webgl-resource';\n\nimport {WEBGLBuffer} from '../resources/webgl-buffer';\n\nconst ERR_ELEMENTS = 'elements must be GL.ELEMENT_ARRAY_BUFFER';\n\n/**\n * VertexArrayObject properties\n */\nexport type VertexArrayObjectProps = ResourceProps & {\n};\n\n/** VertexArrayObject wrapper */\nexport class WEBGLVertexArrayObject extends WebGLResource<VertexArrayObjectProps> {\n override get [Symbol.toStringTag](): string {\n return 'BaseVertexArrayObject';\n }\n\n constructor(device: WebGLDevice, props?: VertexArrayObjectProps) {\n // @ts-expect-error\n super(device, props, {});\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 // 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.target === 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 return this;\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: any): this {\n // Check target\n if (buffer.target === GL.ELEMENT_ARRAY_BUFFER) {\n return this.setElementBuffer(buffer, accessor);\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 return this;\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): this {\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 return this;\n }\n}\n"],"mappings":"AAAA,SAAQA,MAAM,QAAsB,cAAc;AAClD,SAAQC,EAAE,QAAO,oBAAoB;AACrC,SAAQC,UAAU,QAAO,eAAe;AAAC,SA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AuB,IAAIlB,QAAQ,KAAK,CAAC;IAErE,IAAIiB,MAAM,IAAIG,mBAAmB,EAAE;MACjCpB,QAAQ,GAAGU,MAAM,CAACV,QAAQ,CAAC;MAC3B,IAAI,CAACJ,IAAI,CAAC,MACRqB,MAAM,GACF,IAAI,CAACpB,EAAE,CAACkB,uBAAuB,CAACf,QAAQ,CAAC,GACzC,IAAI,CAACH,EAAE,CAACwB,wBAAwB,CAACrB,QAAQ,CAC/C,CAAC;IACH;IACA,OAAO,IAAI;EACb;AACF"}
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","_defineProperty","Object","seal","destroy","buffer","_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","bufferValue","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/api';\nimport {Resource, assert, getScratchArray, fillArray} from '@luma.gl/api';\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';\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: any): 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,cAAc;AACzE,SAAQC,EAAE,QAAO,oBAAoB;AACrC,SAAQC,UAAU,QAAO,eAAe;AAAC,SAGjCC,aAAa;AAKrB,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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C,EAAE;MACnB,OAAO,KAAK;IACd;EACF;EACA,OAAO,IAAI;AACb"}
@@ -1,5 +1,6 @@
1
1
  import type { BufferProps } from '@luma.gl/api';
2
2
  import { Buffer } from '@luma.gl/api';
3
+ import { GL } from '@luma.gl/constants';
3
4
  import { WebGLDevice } from '../webgl-device';
4
5
  /** WebGL Buffer interface */
5
6
  export declare class WEBGLBuffer extends Buffer {
@@ -7,12 +8,20 @@ export declare class WEBGLBuffer extends Buffer {
7
8
  readonly gl: WebGLRenderingContext;
8
9
  readonly gl2: WebGL2RenderingContext | null;
9
10
  readonly handle: WebGLBuffer;
10
- readonly target: number;
11
+ /** Target in OpenGL defines the type of buffer */
12
+ readonly glTarget: GL.ARRAY_BUFFER | GL.ELEMENT_ARRAY_BUFFER | GL.UNIFORM_BUFFER;
13
+ /** Usage is a hint on how frequently the buffer will be updates */
14
+ readonly glUsage: GL.STATIC_DRAW | GL.DYNAMIC_DRAW;
15
+ /** Index type is needed when issuing draw calls, so we pre-compute it */
16
+ readonly glIndexType: GL.UNSIGNED_SHORT | GL.UNSIGNED_INT;
17
+ /** Number of bytes allocated on the GPU for this buffer */
11
18
  byteLength: number;
19
+ /** Number of bytes used */
12
20
  bytesUsed: number;
21
+ /** A partial CPU-side copy of the data in this buffer, for debugging purposes */
13
22
  debugData: ArrayBuffer | null;
14
- webglUsage: number;
15
23
  constructor(device: WebGLDevice, props?: BufferProps);
24
+ /** Allocate a new buffer and initialize to contents of typed array */
16
25
  _initWithData(data: any, byteOffset?: number, byteLength?: number): this;
17
26
  _initWithByteLength(byteLength: number): this;
18
27
  destroy(): void;
@@ -20,7 +29,7 @@ export declare class WEBGLBuffer extends Buffer {
20
29
  /** Read data from the buffer */
21
30
  readAsync(byteOffset?: number, byteLength?: number): Promise<ArrayBuffer>;
22
31
  _invalidateDebugData(): void;
23
- _getWriteTarget(): number;
24
- _getReadTarget(): number;
32
+ _getWriteTarget(): GL.ARRAY_BUFFER | GL.ELEMENT_ARRAY_BUFFER | GL.UNIFORM_BUFFER;
33
+ _getReadTarget(): GL.ARRAY_BUFFER | GL.ELEMENT_ARRAY_BUFFER | GL.UNIFORM_BUFFER;
25
34
  }
26
35
  //# sourceMappingURL=webgl-buffer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-buffer.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgl-buffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAC,MAAM,EAAS,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAI5C,6BAA6B;AAC7B,qBAAa,WAAY,SAAQ,MAAM;IACrC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,EAAE,EAAE,qBAAqB,CAAC;IACnC,QAAQ,CAAC,GAAG,EAAE,sBAAsB,GAAG,IAAI,CAAC;IAC5C,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,WAAW,GAAG,IAAI,CAAQ;IAErC,UAAU,EAAE,MAAM,CAAC;gBAKP,MAAM,EAAE,WAAW,EAAE,KAAK,GAAE,WAAgB;IAoCxD,aAAa,CAAC,IAAI,KAAA,EAAE,UAAU,GAAE,MAAU,EAAE,UAAU,GAAE,MAAqC,GAAG,IAAI;IAmBpG,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAwBpC,OAAO,IAAI,IAAI;IAWf,KAAK,CAAC,IAAI,EAAE,eAAe,EAAE,UAAU,GAAE,MAAU,GAAG,IAAI;IAqBnE,gCAAgC;IACjB,SAAS,CACtB,UAAU,GAAE,MAAU,EACtB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,WAAW,CA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AAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAwBpC,OAAO,IAAI,IAAI;IAWf,KAAK,CAAC,IAAI,EAAE,eAAe,EAAE,UAAU,GAAE,MAAU,GAAG,IAAI;IAqBnE,gCAAgC;IACjB,SAAS,CACtB,UAAU,GAAE,MAAU,EACtB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,WAAW,CAAC;IAmBvB,oBAAoB;IAIpB,eAAe;IAKf,cAAc;CAIf"}
@@ -10,11 +10,12 @@ export class WEBGLBuffer extends Buffer {
10
10
  _defineProperty(this, "gl", void 0);
11
11
  _defineProperty(this, "gl2", void 0);
12
12
  _defineProperty(this, "handle", void 0);
13
- _defineProperty(this, "target", void 0);
13
+ _defineProperty(this, "glTarget", void 0);
14
+ _defineProperty(this, "glUsage", void 0);
15
+ _defineProperty(this, "glIndexType", GL.UNSIGNED_SHORT);
14
16
  _defineProperty(this, "byteLength", void 0);
15
17
  _defineProperty(this, "bytesUsed", void 0);
16
18
  _defineProperty(this, "debugData", null);
17
- _defineProperty(this, "webglUsage", void 0);
18
19
  this.device = device;
19
20
  this.gl = this.device.gl;
20
21
  this.gl2 = this.device.gl2;
@@ -24,8 +25,9 @@ export class WEBGLBuffer extends Buffer {
24
25
  ...this.props,
25
26
  data: typeof this.props.data
26
27
  });
27
- this.target = this.props.target || getWebGLTarget(this.props.usage);
28
- this.webglUsage = this.props.webglUsage || getWebGLUsage(this.props.usage);
28
+ this.glTarget = getWebGLTarget(this.props.usage);
29
+ this.glUsage = getWebGLUsage(this.props.usage);
30
+ this.glIndexType = this.props.indexType === 'uint32' ? GL.UNSIGNED_INT : GL.UNSIGNED_SHORT;
29
31
  this.debugData = null;
30
32
  if (props.data) {
31
33
  this._initWithData(props.data, props.byteOffset, props.byteLength);
@@ -37,11 +39,11 @@ export class WEBGLBuffer extends Buffer {
37
39
  let byteOffset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
38
40
  let byteLength = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : data.byteLength + byteOffset;
39
41
  assert(ArrayBuffer.isView(data));
40
- const target = this._getWriteTarget();
41
- this.gl.bindBuffer(target, this.handle);
42
- this.gl.bufferData(target, byteLength, this.webglUsage);
43
- this.gl.bufferSubData(target, byteOffset, data);
44
- this.gl.bindBuffer(target, null);
42
+ const glTarget = this._getWriteTarget();
43
+ this.gl.bindBuffer(glTarget, this.handle);
44
+ this.gl.bufferData(glTarget, byteLength, this.glUsage);
45
+ this.gl.bufferSubData(glTarget, byteOffset, data);
46
+ this.gl.bindBuffer(glTarget, null);
45
47
  this.debugData = data.slice(0, DEBUG_DATA_LENGTH);
46
48
  this.bytesUsed = byteLength;
47
49
  this.byteLength = byteLength;
@@ -54,10 +56,10 @@ export class WEBGLBuffer extends Buffer {
54
56
  if (byteLength === 0) {
55
57
  data = new Float32Array(0);
56
58
  }
57
- const target = this._getWriteTarget();
58
- this.gl.bindBuffer(target, this.handle);
59
- this.gl.bufferData(target, data, this.webglUsage);
60
- this.gl.bindBuffer(target, null);
59
+ const glTarget = this._getWriteTarget();
60
+ this.gl.bindBuffer(glTarget, this.handle);
61
+ this.gl.bufferData(glTarget, data, this.glUsage);
62
+ this.gl.bindBuffer(glTarget, null);
61
63
  this.debugData = null;
62
64
  this.bytesUsed = byteLength;
63
65
  this.byteLength = byteLength;
@@ -76,15 +78,15 @@ export class WEBGLBuffer extends Buffer {
76
78
  let byteOffset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
77
79
  const srcOffset = 0;
78
80
  const byteLength = undefined;
79
- const target = this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.target;
80
- this.gl.bindBuffer(target, this.handle);
81
+ const glTarget = this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.glTarget;
82
+ this.gl.bindBuffer(glTarget, this.handle);
81
83
  if (srcOffset !== 0 || byteLength !== undefined) {
82
84
  this.device.assertWebGL2();
83
- this.gl2.bufferSubData(target, byteOffset, data, srcOffset, byteLength);
85
+ this.gl2.bufferSubData(glTarget, byteOffset, data, srcOffset, byteLength);
84
86
  } else {
85
- this.gl.bufferSubData(target, byteOffset, data);
87
+ this.gl.bufferSubData(glTarget, byteOffset, data);
86
88
  }
87
- this.gl.bindBuffer(target, null);
89
+ this.gl.bindBuffer(glTarget, null);
88
90
  }
89
91
  async readAsync() {
90
92
  let byteOffset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
@@ -101,10 +103,10 @@ export class WEBGLBuffer extends Buffer {
101
103
  this.debugData = null;
102
104
  }
103
105
  _getWriteTarget() {
104
- return this.target;
106
+ return this.glTarget;
105
107
  }
106
108
  _getReadTarget() {
107
- return this.target;
109
+ return this.glTarget;
108
110
  }
109
111
  }
110
112
  function getWebGLTarget(usage) {
@@ -129,6 +131,6 @@ function getWebGLUsage(usage) {
129
131
  if (usage & Buffer.UNIFORM) {
130
132
  return GL.DYNAMIC_DRAW;
131
133
  }
132
- return GL.DYNAMIC_DRAW;
134
+ return GL.STATIC_DRAW;
133
135
  }
134
136
  //# sourceMappingURL=webgl-buffer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-buffer.js","names":["Buffer","assert","GL","DEBUG_DATA_LENGTH","WEBGLBuffer","constructor","device","props","arguments","length","undefined","_defineProperty","gl","gl2","handle","createBuffer","setSpectorMetadata","data","target","getWebGLTarget","usage","webglUsage","getWebGLUsage","debugData","_initWithData","byteOffset","byteLength","_initWithByteLength","ArrayBuffer","isView","_getWriteTarget","bindBuffer","bufferData","bufferSubData","slice","bytesUsed","trackAllocatedMemory","Float32Array","destroy","destroyed","removeStats","trackDeallocatedMemory","deleteBuffer","write","srcOffset","isWebGL2","COPY_WRITE_BUFFER","assertWebGL2","readAsync","Uint8Array","dstOffset","COPY_READ_BUFFER","getBufferSubData","_invalidateDebugData","_getReadTarget","INDEX","ELEMENT_ARRAY_BUFFER","VERTEX","ARRAY_BUFFER","UNIFORM","UNIFORM_BUFFER","STATIC_DRAW","DYNAMIC_DRAW"],"sources":["../../../src/adapter/resources/webgl-buffer.ts"],"sourcesContent":["import type {BufferProps} from '@luma.gl/api';\nimport {Buffer, assert} from '@luma.gl/api';\nimport {GL} from '@luma.gl/constants';\nimport {WebGLDevice} from '../webgl-device';\n\nconst DEBUG_DATA_LENGTH = 10;\n\n/** WebGL Buffer interface */\nexport class WEBGLBuffer extends Buffer {\n readonly device: WebGLDevice;\n readonly gl: WebGLRenderingContext;\n readonly gl2: WebGL2RenderingContext | null;\n readonly handle: WebGLBuffer;\n readonly target: number;\n\n byteLength: number;\n bytesUsed: number;\n debugData: ArrayBuffer | null = null;\n\n webglUsage: number;\n\n // accessor: {};\n\n \n constructor(device: WebGLDevice, props: BufferProps = {}) {\n super(device, props);\n\n this.device = device;\n this.gl = this.device.gl;\n this.gl2 = this.device.gl2;\n\n const handle = typeof props === 'object' ? (props ).handle : undefined;\n this.handle = handle || this.gl.createBuffer();\n device.setSpectorMetadata(this.handle, {...this.props, data: typeof this.props.data});\n\n // In WebGL1, need to make sure we use GL.ELEMENT_ARRAY_BUFFER when initializing element buffers\n // otherwise buffer type will lock to generic (non-element) buffer\n // In WebGL2, we can use GL.COPY_READ_BUFFER which avoids locking the type here\n // @ts-expect-error Hack - Checking for subclass prop\n this.target = this.props.target || getWebGLTarget(this.props.usage);\n // @ts-expect-error Hack - Checking for subclass prop\n this.webglUsage = this.props.webglUsage || getWebGLUsage(this.props.usage);\n this.debugData = null;\n\n // Set data: (re)initializes the buffer\n if (props.data) {\n this._initWithData(props.data, props.byteOffset, props.byteLength);\n } else {\n this._initWithByteLength(props.byteLength || 0);\n }\n\n // Deprecated: Merge main props and accessor\n // this.accessor = {...props.accessor};\n\n // Object.seal(this);\n }\n\n // PRIVATE METHODS\n\n // Allocate a new buffer and initialize to contents of typed array\n _initWithData(data, byteOffset: number = 0, byteLength: number = data.byteLength + byteOffset): this {\n assert(ArrayBuffer.isView(data));\n\n const target = this._getWriteTarget();\n\n this.gl.bindBuffer(target, this.handle);\n this.gl.bufferData(target, byteLength, this.webglUsage);\n this.gl.bufferSubData(target, byteOffset, data);\n this.gl.bindBuffer(target, null);\n\n this.debugData = data.slice(0, DEBUG_DATA_LENGTH);\n this.bytesUsed = byteLength;\n this.byteLength = byteLength;\n this.trackAllocatedMemory(byteLength);\n\n return this;\n }\n\n // Allocate a GPU buffer of specified size.\n _initWithByteLength(byteLength: number): this {\n assert(byteLength >= 0);\n\n // Workaround needed for Safari (#291):\n // gl.bufferData with size equal to 0 crashes. Instead create zero sized array.\n let data = byteLength;\n if (byteLength === 0) {\n // @ts-expect-error\n data = new Float32Array(0);\n }\n\n const target = this._getWriteTarget();\n\n this.gl.bindBuffer(target, this.handle);\n this.gl.bufferData(target, data, this.webglUsage);\n this.gl.bindBuffer(target, null);\n\n this.debugData = null;\n this.bytesUsed = byteLength;\n this.byteLength = byteLength;\n\n return this;\n }\n\n override destroy(): void {\n if (!this.destroyed && this.handle) {\n this.removeStats();\n this.trackDeallocatedMemory();\n this.gl.deleteBuffer(this.handle);\n this.destroyed = true;\n // @ts-expect-error\n this.handle = null;\n }\n }\n\n override write(data: ArrayBufferView, byteOffset: number = 0): void {\n const srcOffset = 0;\n const byteLength = undefined; // data.byteLength;\n\n // Create the buffer - binding it here for the first time locks the type\n // In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type\n const target = this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.target;\n this.gl.bindBuffer(target, this.handle);\n // WebGL2: subData supports additional srcOffset and length parameters\n if (srcOffset !== 0 || byteLength !== undefined) {\n this.device.assertWebGL2();\n this.gl2.bufferSubData(target, byteOffset, data, srcOffset, byteLength);\n } else {\n this.gl.bufferSubData(target, byteOffset, data);\n }\n this.gl.bindBuffer(target, null);\n\n // TODO - update local `data` if offsets are right\n // this.debugData = data.slice(byteOffset, 40);\n }\n\n /** Read data from the buffer */\n override async readAsync(\n byteOffset: number = 0,\n byteLength?: number\n ): Promise<ArrayBuffer> {\n this.device.assertWebGL2();\n\n const data = new Uint8Array(byteLength);\n const dstOffset = 0;\n\n // Use GL.COPY_READ_BUFFER to avoid disturbing other targets and locking type\n this.gl.bindBuffer(GL.COPY_READ_BUFFER, this.handle);\n this.gl2.getBufferSubData(GL.COPY_READ_BUFFER, byteOffset, data, dstOffset, byteLength);\n this.gl.bindBuffer(GL.COPY_READ_BUFFER, null);\n\n // TODO - update local `data` if offsets are 0\n // this.debugData = null;\n\n return data;\n }\n\n // PROTECTED METHODS (INTENDED FOR USE BY OTHER FRAMEWORK CODE ONLY)\n\n _invalidateDebugData() {\n this.debugData = null;\n }\n\n _getWriteTarget() {\n return this.target;\n // return this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.target;\n }\n\n _getReadTarget() {\n return this.target;\n // return this.device.isWebGL2 ? GL.COPY_READ_BUFFER : this.target;\n }\n}\n\n// static MAP_READ = 0x01;\n// static MAP_WRITE = 0x02;\n// static COPY_SRC = 0x0004;\n// static COPY_DST = 0x0008;\n// static INDEX = 0x0010;\n// static VERTEX = 0x0020;\n// static UNIFORM = 0x0040;\n// static STORAGE = 0x0080;\n// static INDIRECT = 0x0100;\n// static QUERY_RESOLVE = 0x0200;\n\nfunction getWebGLTarget(usage: number): GL {\n if (usage & Buffer.INDEX) {\n return GL.ELEMENT_ARRAY_BUFFER;\n }\n if (usage & Buffer.VERTEX) {\n return GL.ARRAY_BUFFER;\n }\n if (usage & Buffer.UNIFORM) {\n return GL.UNIFORM_BUFFER;\n }\n\n // gl.COPY_READ_BUFFER: Buffer for copying from one buffer object to another.\n // gl.COPY_WRITE_BUFFER: Buffer for copying from one buffer object to another.\n // gl.TRANSFORM_FEEDBACK_BUFFER: Buffer for transform feedback operations.\n // gl.PIXEL_PACK_BUFFER: Buffer used for pixel transfer operations.\n // gl.PIXEL_UNPACK_BUFFER: Buffer used for pixel transfer operations.\n\n // Binding a buffer for the first time locks the type\n // In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type\n return GL.ARRAY_BUFFER;\n}\n\nfunction getWebGLUsage(usage: number): GL {\n if (usage & Buffer.INDEX) {\n return GL.STATIC_DRAW;\n }\n if (usage & Buffer.VERTEX) {\n return GL.STATIC_DRAW;\n }\n if (usage & Buffer.UNIFORM) {\n return GL.DYNAMIC_DRAW;\n }\n return GL.DYNAMIC_DRAW;\n}\n"],"mappings":";AACA,SAAQA,MAAM,EAAEC,MAAM,QAAO,cAAc;AAC3C,SAAQC,EAAE,QAAO,oBAAoB;AAGrC,MAAMC,iBAAiB,GAAG,EAAE;AAG5B,OAAO,MAAMC,WAAW,SAASJ,MAAM,CAAC;EAgBtCK,WAAWA,CAACC,MAAmB,EAA2B;IAAA,IAAzBC,KAAkB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IACtD,KAAK,CAACF,MAAM,EAAEC,KAAK,CAAC;IAACI,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA,oBARS,IAAI;IAAAA,eAAA;IAUlC,IAAI,CAACL,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACM,EAAE,GAAG,IAAI,CAACN,MAAM,CAACM,EAAE;IACxB,IAAI,CAACC,GAAG,GAAG,IAAI,CAACP,MAAM,CAACO,GAAG;IAE1B,MAAMC,MAAM,GAAG,OAAOP,KAAK,KAAK,QAAQ,GAAIA,KAAK,CAAGO,MAAM,GAAGJ,SAAS;IACtE,IAAI,CAACI,MAAM,GAAGA,MAAM,IAAI,IAAI,CAACF,EAAE,CAACG,YAAY,CAAC,CAAC;IAC9CT,MAAM,CAACU,kBAAkB,CAAC,IAAI,CAACF,MAAM,EAAE;MAAC,GAAG,IAAI,CAACP,KAAK;MAAEU,IAAI,EAAE,OAAO,IAAI,CAACV,KAAK,CAACU;IAAI,CAAC,CAAC;IAMrF,IAAI,CAACC,MAAM,GAAG,IAAI,CAACX,KAAK,CAACW,M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B,CAAClD,EAAE,CAACiD,gBAAgB,EAAE1B,UAAU,EAAER,IAAI,EAAEiC,SAAS,EAAExB,UAAU,CAAC;IACvF,IAAI,CAACd,EAAE,CAACmB,UAAU,CAAC7B,EAAE,CAACiD,gBAAgB,EAAE,IAAI,CAAC;IAK7C,OAAOlC,IAAI;EACb;EAIAoC,oBAAoBA,CAAA,EAAG;IACrB,IAAI,CAAC9B,SAAS,GAAG,IAAI;EACvB;EAEAO,eAAeA,CAAA,EAAG;IAChB,OAAO,IAAI,CAACZ,MAAM;EAEpB;EAEAoC,cAAcA,CAAA,EAAG;IACf,OAAO,IAAI,CAACpC,MAAM;EAEpB;AACF;AAaA,SAASC,cAAcA,CAACC,KAAa,EAAM;EACzC,IAAIA,KAAK,GAAGpB,MAAM,CAACuD,KAAK,EAAE;IACxB,OAAOrD,EAAE,CAACsD,oBAAoB;EAChC;EACA,IAAIpC,KAAK,GAAGpB,MAAM,CAACyD,MAAM,EAAE;IACzB,OAAOvD,EAAE,CAACwD,YAAY;EACxB;EACA,IAAItC,KAAK,GAAGpB,MAAM,CAAC2D,OAAO,EAAE;IAC1B,OAAOzD,EAAE,CAAC0D,cAAc;EAC1B;EAUA,OAAO1D,EAAE,CAACwD,YAAY;AACxB;AAEA,SAASpC,aAAaA,CAACF,KAAa,EAAM;EACxC,IAAIA,KAAK,GAAGpB,MAAM,CAACuD,KAAK,EAAE;IACxB,OAAOrD,EAAE,CAAC2D,WAAW;EACvB;EACA,IAAIzC,KAAK,GAAGpB,MAAM,CAACyD,MAAM,EAAE;IACzB,OAAOvD,EAAE,CAAC2D,WAAW;EACvB;EACA,IAAIzC,KAAK,GAAGpB,MAAM,CAAC2D,OAAO,EAAE;IAC1B,OAAOzD,EAAE,CAAC4D,YAAY;EACxB;EACA,OAAO5D,EAAE,CAAC4D,YAAY;AACxB"}
1
+ {"version":3,"file":"webgl-buffer.js","names":["Buffer","assert","GL","DEBUG_DATA_LENGTH","WEBGLBuffer","constructor","device","props","arguments","length","undefined","_defineProperty","UNSIGNED_SHORT","gl","gl2","handle","createBuffer","setSpectorMetadata","data","glTarget","getWebGLTarget","usage","glUsage","getWebGLUsage","glIndexType","indexType","UNSIGNED_INT","debugData","_initWithData","byteOffset","byteLength","_initWithByteLength","ArrayBuffer","isView","_getWriteTarget","bindBuffer","bufferData","bufferSubData","slice","bytesUsed","trackAllocatedMemory","Float32Array","destroy","destroyed","removeStats","trackDeallocatedMemory","deleteBuffer","write","srcOffset","isWebGL2","COPY_WRITE_BUFFER","assertWebGL2","readAsync","Uint8Array","dstOffset","COPY_READ_BUFFER","getBufferSubData","_invalidateDebugData","_getReadTarget","INDEX","ELEMENT_ARRAY_BUFFER","VERTEX","ARRAY_BUFFER","UNIFORM","UNIFORM_BUFFER","STATIC_DRAW","DYNAMIC_DRAW"],"sources":["../../../src/adapter/resources/webgl-buffer.ts"],"sourcesContent":["import type {BufferProps} from '@luma.gl/api';\nimport {Buffer, assert} from '@luma.gl/api';\nimport {GL} from '@luma.gl/constants';\nimport {WebGLDevice} from '../webgl-device';\n\nconst DEBUG_DATA_LENGTH = 10;\n\n/** WebGL Buffer interface */\nexport class WEBGLBuffer extends Buffer {\n readonly device: WebGLDevice;\n readonly gl: WebGLRenderingContext;\n readonly gl2: WebGL2RenderingContext | null;\n readonly handle: WebGLBuffer;\n\n /** Target in OpenGL defines the type of buffer */\n readonly glTarget: GL.ARRAY_BUFFER | GL.ELEMENT_ARRAY_BUFFER | GL.UNIFORM_BUFFER;\n /** Usage is a hint on how frequently the buffer will be updates */\n readonly glUsage: GL.STATIC_DRAW | GL.DYNAMIC_DRAW;\n /** Index type is needed when issuing draw calls, so we pre-compute it */\n readonly glIndexType: GL.UNSIGNED_SHORT | GL.UNSIGNED_INT = GL.UNSIGNED_SHORT;\n\n /** Number of bytes allocated on the GPU for this buffer */\n byteLength: number;\n /** Number of bytes used */\n bytesUsed: number;\n /** A partial CPU-side copy of the data in this buffer, for debugging purposes */\n debugData: ArrayBuffer | null = null;\n\n constructor(device: WebGLDevice, props: BufferProps = {}) {\n super(device, props);\n\n this.device = device;\n this.gl = this.device.gl;\n this.gl2 = this.device.gl2;\n\n const handle = typeof props === 'object' ? (props ).handle : undefined;\n this.handle = handle || this.gl.createBuffer();\n device.setSpectorMetadata(this.handle, {...this.props, data: typeof this.props.data});\n\n // - In WebGL1, need to make sure we use GL.ELEMENT_ARRAY_BUFFER when initializing element buffers\n // otherwise buffer type will lock to generic (non-element) buffer\n // - In WebGL2, we can use GL.COPY_READ_BUFFER which avoids locking the type here\n this.glTarget = getWebGLTarget(this.props.usage);\n this.glUsage = getWebGLUsage(this.props.usage);\n this.glIndexType = this.props.indexType === 'uint32' ? GL.UNSIGNED_INT : GL.UNSIGNED_SHORT;\n\n this.debugData = null;\n\n // Set data: (re)initializes the buffer\n if (props.data) {\n this._initWithData(props.data, props.byteOffset, props.byteLength);\n } else {\n this._initWithByteLength(props.byteLength || 0);\n }\n }\n\n // PRIVATE METHODS\n\n /** Allocate a new buffer and initialize to contents of typed array */\n _initWithData(data, byteOffset: number = 0, byteLength: number = data.byteLength + byteOffset): this {\n assert(ArrayBuffer.isView(data));\n\n const glTarget = this._getWriteTarget();\n this.gl.bindBuffer(glTarget, this.handle);\n this.gl.bufferData(glTarget, byteLength, this.glUsage);\n this.gl.bufferSubData(glTarget, byteOffset, data);\n this.gl.bindBuffer(glTarget, null);\n\n this.debugData = data.slice(0, DEBUG_DATA_LENGTH);\n this.bytesUsed = byteLength;\n this.byteLength = byteLength;\n this.trackAllocatedMemory(byteLength);\n\n return this;\n }\n\n // Allocate a GPU buffer of specified size.\n _initWithByteLength(byteLength: number): this {\n assert(byteLength >= 0);\n\n // Workaround needed for Safari (#291):\n // gl.bufferData with size equal to 0 crashes. Instead create zero sized array.\n let data = byteLength;\n if (byteLength === 0) {\n // @ts-expect-error\n data = new Float32Array(0);\n }\n\n const glTarget = this._getWriteTarget();\n\n this.gl.bindBuffer(glTarget, this.handle);\n this.gl.bufferData(glTarget, data, this.glUsage);\n this.gl.bindBuffer(glTarget, null);\n\n this.debugData = null;\n this.bytesUsed = byteLength;\n this.byteLength = byteLength;\n\n return this;\n }\n\n override destroy(): void {\n if (!this.destroyed && this.handle) {\n this.removeStats();\n this.trackDeallocatedMemory();\n this.gl.deleteBuffer(this.handle);\n this.destroyed = true;\n // @ts-expect-error\n this.handle = null;\n }\n }\n\n override write(data: ArrayBufferView, byteOffset: number = 0): void {\n const srcOffset = 0;\n const byteLength = undefined; // data.byteLength;\n\n // Create the buffer - binding it here for the first time locks the type\n // In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type\n const glTarget = this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.glTarget;\n this.gl.bindBuffer(glTarget, this.handle);\n // WebGL2: subData supports additional srcOffset and length parameters\n if (srcOffset !== 0 || byteLength !== undefined) {\n this.device.assertWebGL2();\n this.gl2.bufferSubData(glTarget, byteOffset, data, srcOffset, byteLength);\n } else {\n this.gl.bufferSubData(glTarget, byteOffset, data);\n }\n this.gl.bindBuffer(glTarget, null);\n\n // TODO - update local `data` if offsets are right\n // this.debugData = data.slice(byteOffset, 40);\n }\n\n /** Read data from the buffer */\n override async readAsync(\n byteOffset: number = 0,\n byteLength?: number\n ): Promise<ArrayBuffer> {\n this.device.assertWebGL2();\n\n const data = new Uint8Array(byteLength);\n const dstOffset = 0;\n\n // Use GL.COPY_READ_BUFFER to avoid disturbing other targets and locking type\n this.gl.bindBuffer(GL.COPY_READ_BUFFER, this.handle);\n this.gl2.getBufferSubData(GL.COPY_READ_BUFFER, byteOffset, data, dstOffset, byteLength);\n this.gl.bindBuffer(GL.COPY_READ_BUFFER, null);\n\n // TODO - update local `data` if offsets are 0\n // this.debugData = null;\n\n return data;\n }\n\n // PROTECTED METHODS (INTENDED FOR USE BY OTHER FRAMEWORK CODE ONLY)\n\n _invalidateDebugData() {\n this.debugData = null;\n }\n\n _getWriteTarget() {\n return this.glTarget;\n // return this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.glTarget;\n }\n\n _getReadTarget() {\n return this.glTarget;\n // return this.device.isWebGL2 ? GL.COPY_READ_BUFFER : this.glTarget;\n }\n}\n\n// static MAP_READ = 0x01;\n// static MAP_WRITE = 0x02;\n// static COPY_SRC = 0x0004;\n// static COPY_DST = 0x0008;\n// static INDEX = 0x0010;\n// static VERTEX = 0x0020;\n// static UNIFORM = 0x0040;\n// static STORAGE = 0x0080;\n// static INDIRECT = 0x0100;\n// static QUERY_RESOLVE = 0x0200;\n\nfunction getWebGLTarget(usage: number): GL.ARRAY_BUFFER | GL.ELEMENT_ARRAY_BUFFER | GL.UNIFORM_BUFFER {\n if (usage & Buffer.INDEX) {\n return GL.ELEMENT_ARRAY_BUFFER;\n }\n if (usage & Buffer.VERTEX) {\n return GL.ARRAY_BUFFER;\n }\n if (usage & Buffer.UNIFORM) {\n return GL.UNIFORM_BUFFER;\n }\n\n // gl.COPY_READ_BUFFER: Buffer for copying from one buffer object to another.\n // gl.COPY_WRITE_BUFFER: Buffer for copying from one buffer object to another.\n // gl.TRANSFORM_FEEDBACK_BUFFER: Buffer for transform feedback operations.\n // gl.PIXEL_PACK_BUFFER: Buffer used for pixel transfer operations.\n // gl.PIXEL_UNPACK_BUFFER: Buffer used for pixel transfer operations.\n\n // Binding a buffer for the first time locks the type\n // In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type\n return GL.ARRAY_BUFFER;\n}\n\n/** @todo usage is not passed correctly */\nfunction getWebGLUsage(usage: number): GL.STATIC_DRAW | GL.DYNAMIC_DRAW {\n if (usage & Buffer.INDEX) {\n return GL.STATIC_DRAW;\n }\n if (usage & Buffer.VERTEX) {\n return GL.STATIC_DRAW;\n }\n if (usage & Buffer.UNIFORM) {\n return GL.DYNAMIC_DRAW;\n }\n return GL.STATIC_DRAW;\n}\n"],"mappings":";AACA,SAAQA,MAAM,EAAEC,MAAM,QAAO,cAAc;AAC3C,SAAQC,EAAE,QAAO,oBAAoB;AAGrC,MAAMC,iBAAiB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AI,CAAC;IAK7C,OAAOrC,IAAI;EACb;EAIAuC,oBAAoBA,CAAA,EAAG;IACrB,IAAI,CAAC9B,SAAS,GAAG,IAAI;EACvB;EAEAO,eAAeA,CAAA,EAAG;IAChB,OAAO,IAAI,CAACf,QAAQ;EAEtB;EAEAuC,cAAcA,CAAA,EAAG;IACf,OAAO,IAAI,CAACvC,QAAQ;EAEtB;AACF;AAaA,SAASC,cAAcA,CAACC,KAAa,EAAiE;EACpG,IAAIA,KAAK,GAAGrB,MAAM,CAAC2D,KAAK,EAAE;IACxB,OAAOzD,EAAE,CAAC0D,oBAAoB;EAChC;EACA,IAAIvC,KAAK,GAAGrB,MAAM,CAAC6D,MAAM,EAAE;IACzB,OAAO3D,EAAE,CAAC4D,YAAY;EACxB;EACA,IAAIzC,KAAK,GAAGrB,MAAM,CAAC+D,OAAO,EAAE;IAC1B,OAAO7D,EAAE,CAAC8D,cAAc;EAC1B;EAUA,OAAO9D,EAAE,CAAC4D,YAAY;AACxB;AAGA,SAASvC,aAAaA,CAACF,KAAa,EAAoC;EACtE,IAAIA,KAAK,GAAGrB,MAAM,CAAC2D,KAAK,EAAE;IACxB,OAAOzD,EAAE,CAAC+D,WAAW;EACvB;EACA,IAAI5C,KAAK,GAAGrB,MAAM,CAAC6D,MAAM,EAAE;IACzB,OAAO3D,EAAE,CAAC+D,WAAW;EACvB;EACA,IAAI5C,KAAK,GAAGrB,MAAM,CAAC+D,OAAO,EAAE;IAC1B,OAAO7D,EAAE,CAACgE,YAAY;EACxB;EACA,OAAOhE,EAAE,CAAC+D,WAAW;AACvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-external-texture.js","names":[],"sources":["../../../src/adapter/resources/webgl-external-texture.ts"],"sourcesContent":["/*\nexport class WEBGLExternalTexture extends WEBGLTexture {\n readonly device: WebGLDevice;\n readonly gl: WebGLRenderingContext;\n readonly gl2: WebGL2RenderingContext | null;\n readonly handle: WebGLTexture;\n\n data;\n\n width: number = undefined;\n height: number = undefined;\n depth: number = undefined;\n\n format = undefined;\n type = undefined;\n dataFormat = undefined;\n border = undefined;\n mipmaps: boolean = undefined;\n\n textureUnit: number = undefined;\n\n sampler: WEBGLSampler;\n\n // Program.draw() checks the loaded flag of all textures to avoid\n // Textures that are still loading from promises\n // Set to true as soon as texture has been initialized with valid data\n loaded = false;\n _video;\n\n readonly target: GL;\n // target cannot be modified by bind:\n // textures are special because when you first bind them to a target,\n // they get special information. When you first bind a texture as a\n // GL_TEXTURE_2D, you are actually setting special state in the texture.\n // You are saying that this texture is a 2D texture.\n // And it will always be a 2D texture; this state cannot be changed ever.\n // If you have a texture that was first bound as a GL_TEXTURE_2D,\n // you must always bind it as a GL_TEXTURE_2D;\n // attempting to bind it as GL_TEXTURE_3D will give rise to an error\n // (while run-time).\n\n static isSupported(device: WebGLDevice, options?: TextureSupportOptions): boolean {\n const {format, linearFiltering} = options;\n let supported = true;\n if (format) {\n supported = supported && isFormatSupported(device.gl, format);\n supported = supported && (!linearFiltering || isTextureFormatFilterable(device.gl, format));\n }\n return supported;\n }\n\n // eslint-disable-next-line max-statements\n constructor(device: Device | WebGLRenderingContext, props: TextureProps) {\n super(WebGLDevice.attach(device), {id: uid('texture'), ...props});\n\n this.target = getWebGLTextureTarget(props);\n\n this.device = WebGLDevice.attach(device);\n this.gl = this.device.gl;\n this.gl2 = this.device.gl2;\n this.handle = this.props.handle || this.gl.createTexture();\n\n let data = props.data;\n\n const isVideo = typeof HTMLVideoElement !== 'undefined' && data instanceof HTMLVideoElement;\n // @ts-expect-error\n if (isVideo && data.readyState < HTMLVideoElement.HAVE_METADATA) {\n this._video = null; // Declare member before the object is sealed\n data.addEventListener('loadeddata', () => this.initialize(props));\n return this;\n }\n\n update(): this {\n if (this._video) {\n const {video, parameters, lastTime} = this._video;\n // @ts-expect-error\n if (lastTime === video.currentTime || video.readyState < HTMLVideoElement.HAVE_CURRENT_DATA) {\n return;\n }\n this.setSubImageData({\n data: video,\n parameters\n });\n if (this.mipmaps) {\n this.generateMipmap();\n }\n this._video.lastTime = video.currentTime;\n }\n }\n\n\n*/"],"mappings":""}
1
+ {"version":3,"file":"webgl-external-texture.js","names":[],"sources":["../../../src/adapter/resources/webgl-external-texture.ts"],"sourcesContent":["/*\nexport class WEBGLExternalTexture extends WEBGLTexture {\n readonly device: WebGLDevice;\n readonly gl: WebGLRenderingContext;\n readonly gl2: WebGL2RenderingContext | null;\n readonly handle: WebGLTexture;\n\n data;\n\n width: number = undefined;\n height: number = undefined;\n depth: number = undefined;\n\n format = undefined;\n type = undefined;\n dataFormat = undefined;\n border = undefined;\n mipmaps: boolean = undefined;\n\n textureUnit: number = undefined;\n\n sampler: WEBGLSampler;\n\n // Program.draw() checks the loaded flag of all textures to avoid\n // Textures that are still loading from promises\n // Set to true as soon as texture has been initialized with valid data\n loaded = false;\n _video;\n\n readonly target: GL;\n // target cannot be modified by bind:\n // textures are special because when you first bind them to a target,\n // they get special information. When you first bind a texture as a\n // GL_TEXTURE_2D, you are actually setting special state in the texture.\n // You are saying that this texture is a 2D texture.\n // And it will always be a 2D texture; this state cannot be changed ever.\n // If you have a texture that was first bound as a GL_TEXTURE_2D,\n // you must always bind it as a GL_TEXTURE_2D;\n // attempting to bind it as GL_TEXTURE_3D will give rise to an error\n // (while run-time).\n\n static isSupported(device: WebGLDevice, options?: TextureSupportOptions): boolean {\n const {format, linearFiltering} = options;\n let supported = true;\n if (format) {\n supported = supported && isFormatSupported(device.gl, format);\n supported = supported && (!linearFiltering || isTextureFormatFilterable(device.gl, format));\n }\n return supported;\n }\n\n // eslint-disable-next-line max-statements\n constructor(device: Device | WebGLRenderingContext, props: TextureProps) {\n super(WebGLDevice.attach(device), {id: uid('texture'), ...props});\n\n this.glTarget = getWebGLTextureTarget(props);\n\n this.device = WebGLDevice.attach(device);\n this.gl = this.device.gl;\n this.gl2 = this.device.gl2;\n this.handle = this.props.handle || this.gl.createTexture();\n\n let data = props.data;\n\n const isVideo = typeof HTMLVideoElement !== 'undefined' && data instanceof HTMLVideoElement;\n // @ts-expect-error\n if (isVideo && data.readyState < HTMLVideoElement.HAVE_METADATA) {\n this._video = null; // Declare member before the object is sealed\n data.addEventListener('loadeddata', () => this.initialize(props));\n return this;\n }\n\n update(): this {\n if (this._video) {\n const {video, parameters, lastTime} = this._video;\n // @ts-expect-error\n if (lastTime === video.currentTime || video.readyState < HTMLVideoElement.HAVE_CURRENT_DATA) {\n return;\n }\n this.setSubImageData({\n data: video,\n parameters\n });\n if (this.mipmaps) {\n this.generateMipmap();\n }\n this._video.lastTime = video.currentTime;\n }\n }\n\n\n*/"],"mappings":""}
@@ -1,20 +1,37 @@
1
- import type { RenderPipelineProps, RenderPass, Buffer, Binding, ShaderLayout } from '@luma.gl/api';
1
+ import type { RenderPipelineProps, RenderPass, Buffer, Binding, ShaderLayout, TypedArray, BufferMapping } from '@luma.gl/api';
2
2
  import { RenderPipeline } from '@luma.gl/api';
3
3
  import { WebGLDevice } from '../webgl-device';
4
+ import { WEBGLBuffer } from './webgl-buffer';
4
5
  import { WEBGLShader } from './webgl-shader';
5
6
  import { WEBGLVertexArrayObject } from '../objects/webgl-vertex-array-object';
6
7
  /** Creates a new render pipeline */
7
8
  export declare class WEBGLRenderPipeline extends RenderPipeline {
9
+ /** The WebGL device that created this render pipeline */
8
10
  device: WebGLDevice;
11
+ /** Handle to underlying WebGL program */
9
12
  handle: WebGLProgram;
13
+ /** vertex shader */
10
14
  vs: WEBGLShader;
15
+ /** fragment shader */
11
16
  fs: WEBGLShader;
17
+ /** The merged layout */
12
18
  layout: ShaderLayout;
13
- varyings: string[] | null;
14
- vertexArrayObject: WEBGLVertexArrayObject;
15
- _indexBuffer?: Buffer;
19
+ /** The layout extracted from shader by WebGL introspection APIs */
20
+ introspectedLayout: ShaderLayout;
21
+ /** Buffer map describing buffer interleaving etc */
22
+ bufferMap: BufferMapping[];
23
+ /** Uniforms set on this model */
16
24
  uniforms: Record<string, any>;
25
+ /** Bindings set on this model */
17
26
  bindings: Record<string, any>;
27
+ /** Any constant attributes */
28
+ constantAttributes: Record<string, TypedArray>;
29
+ /** Index buffer is stored separately */
30
+ _indexBuffer?: WEBGLBuffer;
31
+ /** WebGL varyings */
32
+ varyings: string[] | null;
33
+ /** Stores attribute bindings */
34
+ vertexArrayObject: WEBGLVertexArrayObject;
18
35
  _textureUniforms: Record<string, any>;
19
36
  _textureIndexCounter: number;
20
37
  _uniformCount: number;
@@ -24,7 +41,17 @@ export declare class WEBGLRenderPipeline extends RenderPipeline {
24
41
  setIndexBuffer(indexBuffer: Buffer): void;
25
42
  /** @todo needed for portable model */
26
43
  setAttributes(attributes: Record<string, Buffer>): void;
27
- /** @todo needed for portable model */
44
+ /**
45
+ * Constant attributes are only supported in WebGL, not in WebGPU
46
+ * Any attribute that is disabled in the current vertex array object
47
+ * is read from the context's global constant value for that attribute location.
48
+ * @param attributes
49
+ */
50
+ setConstantAttributes(attributes: Record<string, TypedArray>): void;
51
+ /**
52
+ * Bindings include: textures, samplers and uniform buffers
53
+ * @todo needed for portable model
54
+ */
28
55
  setBindings(bindings: Record<string, Binding>): void;
29
56
  setUniforms(uniforms: Record<string, any>): void;
30
57
  /** @todo needed for portable model
@@ -51,5 +78,11 @@ export declare class WEBGLRenderPipeline extends RenderPipeline {
51
78
  /** Apply any bindings */
52
79
  _applyBindings(): void;
53
80
  _applyUniforms(): void;
81
+ /**
82
+ * Constant attributes are only supported in WebGL, not in WebGPU
83
+ * Any attribute that is disabled in the current vertex array object
84
+ * is read from the context's global constant value for that attribute location.
85
+ */
86
+ _applyConstantAttributes(): void;
54
87
  }
55
88
  //# sourceMappingURL=webgl-render-pipeline.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-render-pipeline.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgl-render-pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,UAAU,EACV,MAAM,EACN,OAAO,EACP,YAAY,EAIb,MAAM,cAAc,CAAC;AACtB,OAAO,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GG;IACH,IAAI,CAAC,OAAO,EAAE;QACZ,UAAU,EAAE,UAAU,CAAC;QACvB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO;IA6EX,SAAS,CAAC,eAAe;IA0BzB;;;;OAIG;IACH,sBAAsB;IAkBtB,yBAAyB;IACzB,cAAc;IA6Dd,cAAc;CASf"}
1
+ {"version":3,"file":"webgl-render-pipeline.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgl-render-pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,UAAU,EACV,MAAM,EACN,OAAO,EACP,YAAY,EAIZ,UAAU,EACV,aAAa,EACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,cAAc,EAAgC,MAAM,cAAc,CAAC;AAS3E,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAAC,sBAAsB,EAAC,MAAM,sCAAsC,CAAC;AAK5E,oCAAoC;AACpC,qBAAa,mBAAoB,SAAQ,cAAc;IACrD,yDAAyD;IACzD,MAAM,EAAE,WAAW,CAAC;IACpB,yCAAyC;IACzC,MAAM,EAAE,YAAY,CAAC;IACrB,oBAAoB;IACpB,EAAE,EAAE,WAAW,CAAC;IAChB,sBAAsB;IACtB,EAAE,EAAE,WAAW,CAAC;IAChB,wBAAwB;IACxB,MAAM,EAAE,YAAY,CAAC;IACrB,mEAAmE;IACnE,kBAAkB,EAAE,YAAY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