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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts +9 -0
  2. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  3. package/dist/adapter/converters/device-parameters.js +15 -2
  4. package/dist/adapter/converters/device-parameters.js.map +1 -1
  5. package/dist/adapter/resources/webgl-command-buffer.js +0 -1
  6. package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
  7. package/dist/adapter/resources/webgl-render-pass.d.ts +2 -2
  8. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  9. package/dist/adapter/resources/webgl-render-pass.js +5 -3
  10. package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
  11. package/dist/adapter/resources/webgl-render-pipeline.d.ts +23 -28
  12. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  13. package/dist/adapter/resources/webgl-render-pipeline.js +41 -110
  14. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
  15. package/dist/adapter/resources/webgl-sampler.js.map +1 -1
  16. package/dist/adapter/resources/webgl-shader.js +3 -1
  17. package/dist/adapter/resources/webgl-shader.js.map +1 -1
  18. package/dist/adapter/resources/webgl-texture.js +5 -5
  19. package/dist/adapter/resources/webgl-texture.js.map +1 -1
  20. package/dist/adapter/resources/webgl-vertex-array.d.ts +67 -0
  21. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -0
  22. package/dist/adapter/resources/webgl-vertex-array.js +166 -0
  23. package/dist/adapter/resources/webgl-vertex-array.js.map +1 -0
  24. package/dist/adapter/webgl-device.d.ts +11 -1
  25. package/dist/adapter/webgl-device.d.ts.map +1 -1
  26. package/dist/adapter/webgl-device.js +66 -1
  27. package/dist/adapter/webgl-device.js.map +1 -1
  28. package/dist/classic/clear.js +3 -3
  29. package/dist/classic/clear.js.map +1 -1
  30. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  31. package/dist/classic/copy-and-blit.js +7 -9
  32. package/dist/classic/copy-and-blit.js.map +1 -1
  33. package/dist/context/context/create-browser-context.d.ts.map +1 -1
  34. package/dist/context/context/create-browser-context.js.map +1 -1
  35. package/dist/context/parameters/unified-parameter-api.d.ts +3 -3
  36. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  37. package/dist/context/parameters/unified-parameter-api.js +4 -4
  38. package/dist/context/parameters/unified-parameter-api.js.map +1 -1
  39. package/dist/context/state-tracker/track-context-state.js +3 -3
  40. package/dist/context/state-tracker/track-context-state.js.map +1 -1
  41. package/dist/context/state-tracker/with-parameters.d.ts +1 -1
  42. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  43. package/dist/context/state-tracker/with-parameters.js +3 -3
  44. package/dist/context/state-tracker/with-parameters.js.map +1 -1
  45. package/dist/dist.dev.js +1273 -1179
  46. package/dist/index.cjs +1026 -972
  47. package/dist/index.d.ts +5 -5
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +5 -5
  50. package/dist/index.js.map +1 -1
  51. package/dist.min.js +22 -22
  52. package/package.json +5 -5
  53. package/src/.DS_Store +0 -0
  54. package/src/adapter/.DS_Store +0 -0
  55. package/src/adapter/converters/device-parameters.ts +34 -2
  56. package/src/adapter/resources/webgl-command-buffer.ts +2 -2
  57. package/src/adapter/resources/webgl-render-pass.ts +8 -6
  58. package/src/adapter/resources/webgl-render-pipeline.ts +141 -174
  59. package/src/adapter/resources/webgl-sampler.ts +1 -1
  60. package/src/adapter/resources/webgl-shader.ts +1 -1
  61. package/src/adapter/resources/webgl-texture.ts +5 -5
  62. package/src/adapter/resources/webgl-vertex-array.ts +278 -0
  63. package/src/adapter/webgl-device.ts +137 -11
  64. package/src/classic/clear.ts +3 -3
  65. package/src/classic/copy-and-blit.ts +19 -15
  66. package/src/context/.DS_Store +0 -0
  67. package/src/context/context/create-browser-context.ts +12 -0
  68. package/src/context/parameters/unified-parameter-api.ts +4 -4
  69. package/src/context/state-tracker/track-context-state.ts +3 -3
  70. package/src/context/state-tracker/with-parameters.ts +3 -3
  71. package/src/index.ts +38 -16
  72. package/dist/adapter/objects/webgl-vertex-array-object.d.ts +0 -55
  73. package/dist/adapter/objects/webgl-vertex-array-object.d.ts.map +0 -1
  74. package/dist/adapter/objects/webgl-vertex-array-object.js +0 -173
  75. package/dist/adapter/objects/webgl-vertex-array-object.js.map +0 -1
  76. package/src/adapter/objects/webgl-vertex-array-object.ts +0 -276
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/webgl",
3
- "version": "9.0.0-alpha.35",
3
+ "version": "9.0.0-alpha.37",
4
4
  "description": "WebGL2 adapter for the luma.gl API",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -44,12 +44,12 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@babel/runtime": "^7.0.0",
47
- "@luma.gl/constants": "9.0.0-alpha.35",
48
- "@luma.gl/core": "9.0.0-alpha.35",
47
+ "@luma.gl/constants": "9.0.0-alpha.37",
48
+ "@luma.gl/core": "9.0.0-alpha.37",
49
49
  "@probe.gl/env": "^4.0.2"
50
50
  },
51
51
  "devDependencies": {
52
- "@luma.gl/test-utils": "9.0.0-alpha.35"
52
+ "@luma.gl/test-utils": "9.0.0-alpha.37"
53
53
  },
54
- "gitHead": "5b93557731aaf1b9fd0fc1d84b5a3c7c0717298a"
54
+ "gitHead": "705108c07db777553714bfdf5af77f75e5c54c35"
55
55
  }
package/src/.DS_Store ADDED
Binary file
Binary file
@@ -9,11 +9,43 @@ import {
9
9
  import {GL} from '@luma.gl/constants';
10
10
  import type {GLParameters} from '@luma.gl/constants';
11
11
  import {pushContextState, popContextState} from '../../context/state-tracker/track-context-state';
12
- import {setParameters} from '../../context/parameters/unified-parameter-api';
12
+ import {setGLParameters} from '../../context/parameters/unified-parameter-api';
13
13
  import {WebGLDevice} from '../webgl-device';
14
14
 
15
15
  /* eslint-disable no-unused-expressions */ // For expression ? gl.enable() : gl.disable()
16
16
 
17
+ /**
18
+ * Execute a function with a set of temporary WebGL parameter overrides
19
+ * - Saves current "global" WebGL context settings
20
+ * - Sets the supplies WebGL context parameters,
21
+ * - Executes supplied function
22
+ * - Restores parameters
23
+ * - Returns the return value of the supplied function
24
+ */
25
+ export function withDeviceAndGLParameters<T = unknown>(
26
+ device: Device,
27
+ parameters: Parameters,
28
+ glParameters: GLParameters,
29
+ func: (device?: Device) => T
30
+ ): T {
31
+ if (isObjectEmpty(parameters)) {
32
+ // Avoid setting state if no parameters provided. Just call and return
33
+ return func(device);
34
+ }
35
+
36
+ // Wrap in a try-catch to ensure that parameters are restored on exceptions
37
+ // @ts-expect-error
38
+ pushContextState(device.gl);
39
+ try {
40
+ setDeviceParameters(device, parameters);
41
+ setGLParameters(device, glParameters);
42
+ return func(device);
43
+ } finally {
44
+ // @ts-expect-error
45
+ popContextState(device.gl);
46
+ }
47
+ }
48
+
17
49
  /**
18
50
  * Execute a function with a set of temporary WebGL parameter overrides
19
51
  * - Saves current "global" WebGL context settings
@@ -37,7 +69,7 @@ export function withGLParameters<T = unknown>(
37
69
  // @ts-expect-error
38
70
  pushContextState(device.gl);
39
71
  try {
40
- setParameters(device, parameters);
72
+ setGLParameters(device, parameters);
41
73
  return func(device);
42
74
  } finally {
43
75
  // @ts-expect-error
@@ -333,8 +333,8 @@ function _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextur
333
333
  if (texture) {
334
334
  texture.unbind();
335
335
  }
336
- // @ts-expect-error
337
- device.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
336
+ // ts-expect-error
337
+ // device.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
338
338
  if (destroyFramebuffer) {
339
339
  framebuffer.destroy();
340
340
  }
@@ -1,10 +1,10 @@
1
- import {RenderPass, RenderPassProps, NumericArray, RenderPassParameters} from '@luma.gl/core';
1
+ import {RenderPass, RenderPassProps, NumberArray, RenderPassParameters} from '@luma.gl/core';
2
2
  import {WebGLDevice} from '../webgl-device';
3
3
  import {GL, GLParameters} from '@luma.gl/constants';
4
- import {withParameters} from '../../context/state-tracker/with-parameters';
4
+ import {withGLParameters} from '../../context/state-tracker/with-parameters';
5
+ import {setGLParameters} from '../../context/parameters/unified-parameter-api';
5
6
 
6
7
  // Should collapse during minification
7
-
8
8
  const GL_DEPTH_BUFFER_BIT = 0x00000100;
9
9
  const GL_STENCIL_BUFFER_BIT = 0x00000400;
10
10
  const GL_COLOR_BUFFER_BIT = 0x00004000;
@@ -89,6 +89,8 @@ export class WEBGLRenderPass extends RenderPass {
89
89
  }
90
90
 
91
91
  this.glParameters = glParameters;
92
+
93
+ setGLParameters(this.device, glParameters);
92
94
  }
93
95
 
94
96
  // Internal
@@ -116,7 +118,7 @@ export class WEBGLRenderPass extends RenderPass {
116
118
 
117
119
  if (clearMask !== 0) {
118
120
  // Temporarily set any clear "colors" and call clear
119
- withParameters(this.device, glParameters, () => {
121
+ withGLParameters(this.device, glParameters, () => {
120
122
  this.device.gl.clear(clearMask);
121
123
  });
122
124
 
@@ -130,8 +132,8 @@ export class WEBGLRenderPass extends RenderPass {
130
132
  /**
131
133
  * WebGL2 - clear a specific color buffer
132
134
  */
133
- protected clearColorBuffer(drawBuffer: number = 0, value: NumericArray = [0, 0, 0, 0]) {
134
- withParameters(this.device.gl2, {framebuffer: this.props.framebuffer}, () => {
135
+ protected clearColorBuffer(drawBuffer: number = 0, value: NumberArray = [0, 0, 0, 0]) {
136
+ withGLParameters(this.device.gl2, {framebuffer: this.props.framebuffer}, () => {
135
137
  // Method selection per OpenGL ES 3 docs
136
138
  switch (value.constructor) {
137
139
  case Int32Array:
@@ -1,21 +1,14 @@
1
1
  // luma.gl, MIT license
2
- import type {
3
- TypedArray,
4
- UniformValue,
5
- RenderPipelineProps,
6
- Binding,
7
- ShaderLayout,
8
- BufferLayout,
9
- PrimitiveTopology
10
- } from '@luma.gl/core';
11
- import type {RenderPass, Buffer} from '@luma.gl/core';
2
+ import type {UniformValue, RenderPipelineProps, Binding} from '@luma.gl/core';
3
+ import type {ShaderLayout, PrimitiveTopology} from '@luma.gl/core';
4
+ import type {RenderPass, VertexArray} from '@luma.gl/core';
12
5
  import {RenderPipeline, cast, log} from '@luma.gl/core';
13
- import {mergeShaderLayout, getAttributeInfosFromLayouts} from '@luma.gl/core';
6
+ import {mergeShaderLayout} from '@luma.gl/core';
7
+ // import {mergeShaderLayout, getAttributeInfosFromLayouts} from '@luma.gl/core';
14
8
  import {GL} from '@luma.gl/constants';
15
9
 
16
- import {getGLFromVertexType} from '../converters/vertex-formats';
17
10
  import {getShaderLayout} from '../helpers/get-shader-layout';
18
- import {withDeviceParameters, withGLParameters} from '../converters/device-parameters';
11
+ import {withDeviceAndGLParameters} from '../converters/device-parameters';
19
12
  import {setUniform} from '../helpers/set-uniform';
20
13
  // import {copyUniform, checkUniformValues} from '../../classes/uniforms';
21
14
 
@@ -23,7 +16,7 @@ import {WebGLDevice} from '../webgl-device';
23
16
  import {WEBGLBuffer} from './webgl-buffer';
24
17
  import {WEBGLShader} from './webgl-shader';
25
18
  import {WEBGLTexture} from './webgl-texture';
26
- import {WEBGLVertexArrayObject} from '../objects/webgl-vertex-array-object';
19
+ // import {WEBGLVertexArray} from './webgl-vertex-array';
27
20
  import {WEBGLRenderPass} from './webgl-render-pass';
28
21
 
29
22
  const LOG_PROGRAM_PERF_PRIORITY = 4;
@@ -40,25 +33,14 @@ export class WEBGLRenderPipeline extends RenderPipeline {
40
33
  fs: WEBGLShader;
41
34
  /** The layout extracted from shader by WebGL introspection APIs */
42
35
  introspectedLayout: ShaderLayout;
43
- /** The merged layout */
44
- shaderLayout: ShaderLayout;
45
- /** Buffer map describing buffer interleaving etc */
46
- bufferLayout: BufferLayout[];
47
36
 
48
37
  /** Uniforms set on this model */
49
- uniforms: Record<string, any> = {};
38
+ uniforms: Record<string, UniformValue> = {};
50
39
  /** Bindings set on this model */
51
- bindings: Record<string, any> = {};
52
- /** Any constant attributes */
53
- constantAttributes: Record<string, TypedArray> = {};
54
- /** Index buffer is stored separately */
55
- _indexBuffer?: WEBGLBuffer;
40
+ bindings: Record<string, Binding> = {};
56
41
  /** WebGL varyings */
57
42
  varyings: string[] | null = null;
58
43
 
59
- /** Stores attribute bindings */
60
- vertexArrayObject: WEBGLVertexArrayObject;
61
-
62
44
  _textureUniforms: Record<string, any> = {};
63
45
  _textureIndexCounter: number = 0;
64
46
  _uniformCount: number = 0;
@@ -91,9 +73,8 @@ export class WEBGLRenderPipeline extends RenderPipeline {
91
73
  // Merge provided layout with introspected layout
92
74
  this.shaderLayout = mergeShaderLayout(this.introspectedLayout, props.shaderLayout);
93
75
  // Merge layout with any buffer map overrides
94
- this.bufferLayout = props.bufferLayout || [];
76
+ // this.bufferLayout = props.bufferLayout || [];
95
77
  // this.shaderLayout = mergeBufferMap(this.shaderLayout, this.bufferLayout);
96
- this.vertexArrayObject = new WEBGLVertexArrayObject(this.device);
97
78
  }
98
79
 
99
80
  override destroy(): void {
@@ -104,86 +85,38 @@ export class WEBGLRenderPipeline extends RenderPipeline {
104
85
  }
105
86
  }
106
87
 
107
- setIndexBuffer(indexBuffer: Buffer): void {
108
- const webglBuffer = cast<WEBGLBuffer>(indexBuffer);
109
- this.vertexArrayObject.setElementBuffer(webglBuffer);
110
- this._indexBuffer = webglBuffer;
111
- }
112
-
113
- /** @todo needed for portable model */
114
- setAttributes(buffers: Record<string, Buffer>): void {
115
- const attributeInfos = getAttributeInfosFromLayouts(this.shaderLayout, this.bufferLayout);
116
-
117
- for (const [bufferName, buffer] of Object.entries(buffers)) {
118
- let set = false;
119
- for (const attributeInfo of Object.values(attributeInfos)) {
120
- if (attributeInfo.bufferName !== bufferName) {
121
- continue; // eslint-disable-line no-continue
122
- }
123
- const webglBuffer = cast<WEBGLBuffer>(buffer);
124
-
125
- const glType = getGLFromVertexType(attributeInfo.bufferDataType);
126
- // TODO remove when we have more confidence
127
- log.log(2, {
128
- setAttribute: attributeInfo.attributeName,
129
- toBuffer: bufferName,
130
- size: attributeInfo.bufferComponents,
131
- type: glType,
132
- stride: attributeInfo.byteStride,
133
- offset: attributeInfo.byteOffset,
134
- normalized: attributeInfo.normalized,
135
- // it is the shader attribute declaration, not the vertex memory format,
136
- // that determines if the data in the buffer will be treated as integers.
137
- // /
138
- // Also note that WebGL supports assigning non-normalized integer data to floating point attributes,
139
- // but as far as we can tell, WebGPU does not.
140
- integer: attributeInfo.integer,
141
- divisor: attributeInfo.stepMode === 'instance' ? 1 : 0
142
- })();
143
- this.vertexArrayObject.setBuffer(attributeInfo.location, webglBuffer, {
144
- size: attributeInfo.bufferComponents,
145
- type: glType,
146
- stride: attributeInfo.byteStride,
147
- offset: attributeInfo.byteOffset,
148
- normalized: attributeInfo.normalized,
149
- // it is the shader attribute declaration, not the vertex memory format,
150
- // that determines if the data in the buffer will be treated as integers.
151
- // /
152
- // Also note that WebGL supports assigning non-normalized integer data to floating point attributes,
153
- // but as far as we can tell, WebGPU does not.
154
- integer: attributeInfo.integer,
155
- divisor: attributeInfo.stepMode === 'instance' ? 1 : 0
156
- });
157
- set = true;
158
- }
159
- if (!set) {
160
- log.warn(
161
- `setAttributes(): Ignoring (buffer "${buffer.id}" for unknown attribute "${name}" in pipeline "${this.id}"`
162
- )();
163
- }
164
- }
165
- }
166
-
167
- /**
168
- * Constant attributes are only supported in WebGL, not in WebGPU
169
- * Any attribute that is disabled in the current vertex array object
170
- * is read from the context's global constant value for that attribute location.
171
- * @param attributes
172
- */
173
- setConstantAttributes(attributes: Record<string, TypedArray>): void {
174
- // TODO - there should be no advantage to setting these here vs in _applyConstantAttributes
175
- // for (const [name, value] of Object.entries(attributes)) {
176
- // const attributeInfo = getAttributeInfosFromLayouts(this.shaderLayout, this.bufferLayout, name);
177
- // if (!attributeInfo) {
178
- // log.warn(
179
- // `Ignoring constant value supplied for unknown attribute "${name}" in pipeline "${this.id}"`
180
- // )();
181
- // continue; // eslint-disable-line no-continue
182
- // }
183
- // this.vertexArrayObject.setConstant(attributeInfo.location, value);
184
- // }
185
- Object.assign(this.constantAttributes, attributes);
186
- }
88
+ // setIndexBuffer(indexBuffer: Buffer): void {
89
+ // const webglBuffer = cast<WEBGLBuffer>(indexBuffer);
90
+ // this.vertexArrayObject.setElementBuffer(webglBuffer);
91
+ // this._indexBuffer = indexBuffer;
92
+ // }
93
+
94
+ // /** @todo needed for portable model */
95
+ // setAttributes(attributes: Record<string, Buffer>): void {
96
+ // for (const [name, buffer] of Object.entries(attributes)) {
97
+ // const webglBuffer = cast<WEBGLBuffer>(buffer);
98
+ // const attribute = getAttributeLayout(this.layout, name);
99
+ // if (!attribute) {
100
+ // log.warn(
101
+ // `Ignoring buffer supplied for unknown attribute "${name}" in pipeline "${this.id}" (buffer "${buffer.id}")`
102
+ // )();
103
+ // continue;
104
+ // }
105
+ // const decoded = decodeVertexFormat(attribute.format);
106
+ // const {type: typeString, components: size, byteLength: stride, normalized, integer} = decoded;
107
+ // const divisor = attribute.stepMode === 'instance' ? 1 : 0;
108
+ // const type = getWebGLDataType(typeString);
109
+ // this.vertexArrayObject.setBuffer(attribute.location, webglBuffer, {
110
+ // size,
111
+ // type,
112
+ // stride,
113
+ // offset: 0,
114
+ // normalized,
115
+ // integer,
116
+ // divisor
117
+ // });
118
+ // }
119
+ // }
187
120
 
188
121
  /**
189
122
  * Bindings include: textures, samplers and uniform buffers
@@ -237,6 +170,8 @@ export class WEBGLRenderPipeline extends RenderPipeline {
237
170
  */
238
171
  draw(options: {
239
172
  renderPass: RenderPass;
173
+ /** vertex attributes */
174
+ vertexArray: VertexArray;
240
175
  vertexCount?: number;
241
176
  indexCount?: number;
242
177
  instanceCount?: number;
@@ -247,6 +182,7 @@ export class WEBGLRenderPipeline extends RenderPipeline {
247
182
  }): boolean {
248
183
  const {
249
184
  renderPass,
185
+ vertexArray,
250
186
  vertexCount,
251
187
  // indexCount,
252
188
  instanceCount,
@@ -256,71 +192,94 @@ export class WEBGLRenderPipeline extends RenderPipeline {
256
192
  // baseVertex
257
193
  } = options;
258
194
 
259
- const drawMode = getGLDrawMode(this.props.topology);
260
- const isIndexed: boolean = Boolean(this._indexBuffer);
261
- const indexType = this._indexBuffer?.glIndexType;
262
- const isInstanced: boolean = Number(options.instanceCount) > 0;
195
+ const glDrawMode = getGLDrawMode(this.props.topology);
196
+ const isIndexed: boolean = Boolean(vertexArray.indexBuffer);
197
+ const glIndexType = (vertexArray.indexBuffer as WEBGLBuffer)?.glIndexType;
198
+ const isInstanced: boolean = Number(instanceCount) > 0;
263
199
 
264
200
  // Avoid WebGL draw call when not rendering any data or values are incomplete
265
201
  // Note: async textures set as uniforms might still be loading.
266
202
  // Now that all uniforms have been updated, check if any texture
267
203
  // in the uniforms is not yet initialized, then we don't draw
268
- if (!this._areTexturesRenderable() || options.vertexCount === 0) {
204
+ if (!this._areTexturesRenderable() || vertexCount === 0) {
269
205
  // (isInstanced && instanceCount === 0)
270
206
  return false;
271
207
  }
272
208
 
273
209
  this.device.gl.useProgram(this.handle);
274
210
 
275
- this.vertexArrayObject.bind(() => {
276
- const primitiveMode = getGLPrimitive(this.props.topology);
277
- const transformFeedback: any = null;
278
- if (transformFeedback) {
279
- transformFeedback.begin(primitiveMode);
280
- }
211
+ // Note: Rebinds constant attributes before each draw call
212
+ vertexArray.bindBeforeRender(renderPass);
281
213
 
282
- // We have to apply bindings before every draw call since other draw calls will overwrite
283
- this._applyBindings();
284
- this._applyUniforms();
285
- this._applyConstantAttributes();
286
-
287
- const webglRenderPass = renderPass as WEBGLRenderPass;
288
-
289
- // TODO - double context push/pop
290
- withDeviceParameters(this.device, this.props.parameters, () => {
291
- withGLParameters(this.device, webglRenderPass.glParameters, () => {
292
- // TODO - Use polyfilled WebGL2RenderingContext instead of ANGLE extension
293
- if (isIndexed && isInstanced) {
294
- // ANGLE_instanced_arrays extension
295
- this.device.gl2?.drawElementsInstanced(
296
- drawMode,
297
- vertexCount || 0, // indexCount?
298
- indexType,
299
- firstVertex,
300
- instanceCount || 0
301
- );
302
- // } else if (isIndexed && this.device.isWebGL2 && !isNaN(start) && !isNaN(end)) {
303
- // this.device.gl2.drawRangeElements(drawMode, start, end, vertexCount, indexType, offset);
304
- } else if (isIndexed) {
305
- this.device.gl.drawElements(drawMode, vertexCount || 0, indexType, firstVertex); // indexCount?
306
- } else if (isInstanced) {
307
- this.device.gl2?.drawArraysInstanced(
308
- drawMode,
309
- firstVertex,
310
- vertexCount || 0,
311
- instanceCount || 0
312
- );
313
- } else {
314
- this.device.gl.drawArrays(drawMode, firstVertex, vertexCount || 0);
315
- }
316
- });
214
+ const primitiveMode = getGLPrimitive(this.props.topology);
215
+ const transformFeedback: any = null;
216
+ if (transformFeedback) {
217
+ transformFeedback.begin(primitiveMode);
218
+ }
219
+
220
+ // We have to apply bindings before every draw call since other draw calls will overwrite
221
+ this._applyBindings();
222
+ this._applyUniforms();
223
+
224
+ const webglRenderPass = renderPass as WEBGLRenderPass;
225
+ // // TODO - Use polyfilled WebGL2RenderingContext instead of ANGLE extension
226
+ // if (isIndexed && isInstanced) {
227
+ // // ANGLE_instanced_arrays extension
228
+ // this.device.gl2?.drawElementsInstanced(
229
+ // drawMode,
230
+ // vertexCount || 0, // indexCount?
231
+ // indexType,
232
+ // firstVertex,
233
+ // instanceCount || 0
234
+ // );
235
+ // // } else if (isIndexed && this.device.isWebGL2 && !isNaN(start) && !isNaN(end)) {
236
+ // // this.device.gl2.drawRangeElements(drawMode, start, end, vertexCount, indexType, offset);
237
+ // } else if (isIndexed) {
238
+ // this.device.gl.drawElements(drawMode, vertexCount || 0, indexType, firstVertex); // indexCount?
239
+ // } else if (isInstanced) {
240
+ // this.device.gl2?.drawArraysInstanced(
241
+ // drawMode,
242
+ // firstVertex,
243
+ // vertexCount || 0,
244
+ // instanceCount || 0
245
+ // );
246
+ // } else {
247
+ // this.device.gl.drawArrays(drawMode, firstVertex, vertexCount || 0);
248
+ // }
249
+ // });
250
+
251
+ withDeviceAndGLParameters(this.device, this.props.parameters, webglRenderPass.glParameters, () => {
252
+ if (isIndexed && isInstanced) {
253
+ // ANGLE_instanced_arrays extension
254
+ this.device.gl2?.drawElementsInstanced(
255
+ glDrawMode,
256
+ vertexCount || 0, // indexCount?
257
+ glIndexType,
258
+ firstVertex,
259
+ instanceCount || 0
260
+ );
261
+ // } else if (isIndexed && this.device.isWebGL2 && !isNaN(start) && !isNaN(end)) {
262
+ // this.device.gl2.drawRangeElements(glDrawMode, start, end, vertexCount, glIndexType, offset);
263
+ } else if (isIndexed) {
264
+ this.device.gl.drawElements(glDrawMode, vertexCount || 0, glIndexType, firstVertex); // indexCount?
265
+ } else if (isInstanced) {
266
+ this.device.gl2?.drawArraysInstanced(
267
+ glDrawMode,
268
+ firstVertex,
269
+ vertexCount || 0,
270
+ instanceCount || 0
271
+ );
272
+ } else {
273
+ this.device.gl.drawArrays(glDrawMode, firstVertex, vertexCount || 0);
274
+ }
317
275
 
318
- if (transformFeedback) {
319
- transformFeedback.end();
320
- }
321
- });
276
+ if (transformFeedback) {
277
+ transformFeedback.end();
278
+ }
322
279
  });
323
280
 
281
+ vertexArray.unbindAfterRender(renderPass);
282
+
324
283
  return true;
325
284
  }
326
285
 
@@ -337,17 +296,19 @@ export class WEBGLRenderPipeline extends RenderPipeline {
337
296
 
338
297
  // Avoid checking program linking error in production
339
298
  // @ts-expect-error
340
- if (gl.debug || log.level > 0) {
341
- const linked = gl.getProgramParameter(this.handle, gl.LINK_STATUS);
342
- if (!linked) {
343
- throw new Error(`Error linking: ${gl.getProgramInfoLog(this.handle)}`);
344
- }
299
+ if (!gl.debug && log.level === 0) {
300
+ // return;
301
+ }
345
302
 
346
- gl.validateProgram(this.handle);
347
- const validated = gl.getProgramParameter(this.handle, gl.VALIDATE_STATUS);
348
- if (!validated) {
349
- throw new Error(`Error validating: ${gl.getProgramInfoLog(this.handle)}`);
350
- }
303
+ const linked = gl.getProgramParameter(this.handle, gl.LINK_STATUS);
304
+ if (!linked) {
305
+ throw new Error(`Error linking: ${gl.getProgramInfoLog(this.handle)}`);
306
+ }
307
+
308
+ gl.validateProgram(this.handle);
309
+ const validated = gl.getProgramParameter(this.handle, gl.VALIDATE_STATUS);
310
+ if (!validated) {
311
+ throw new Error(`Error validating: ${gl.getProgramInfoLog(this.handle)}`);
351
312
  }
352
313
  }
353
314
 
@@ -368,7 +329,9 @@ export class WEBGLRenderPipeline extends RenderPipeline {
368
329
 
369
330
  for (const [, texture] of Object.entries(this.bindings)) {
370
331
  // texture.update();
332
+ // @ts-expect-error
371
333
  if (texture.loaded !== undefined) {
334
+ // @ts-expect-error
372
335
  texturesRenderable = texturesRenderable && texture.loaded;
373
336
  }
374
337
  }
@@ -381,10 +344,10 @@ export class WEBGLRenderPipeline extends RenderPipeline {
381
344
  * Any attribute that is disabled in the current vertex array object
382
345
  * is read from the context's global constant value for that attribute location.
383
346
  * @note Constant attributes are only supported in WebGL, not in WebGPU
384
- */
385
- _applyConstantAttributes(): void {
347
+ *
348
+ _applyConstantAttributes(vertexArray: WEBGLVertexArray): void {
386
349
  const attributeInfos = getAttributeInfosFromLayouts(this.shaderLayout, this.bufferLayout);
387
- for (const [name, value] of Object.entries(this.constantAttributes)) {
350
+ for (const [name, value] of Object.entries(this.)) {
388
351
  const attributeInfo = attributeInfos[name];
389
352
  if (!attributeInfo) {
390
353
  log.warn(
@@ -392,10 +355,11 @@ export class WEBGLRenderPipeline extends RenderPipeline {
392
355
  )();
393
356
  continue; // eslint-disable-line no-continue
394
357
  }
395
- this.vertexArrayObject.setConstant(attributeInfo.location, value);
396
- this.vertexArrayObject.enable(attributeInfo.location, false);
358
+ vertexArray.setConstant(attributeInfo.location, value);
359
+ vertexArray.enable(attributeInfo.location, false);
397
360
  }
398
361
  }
362
+ */
399
363
 
400
364
  /** Apply any bindings (before each draw call) */
401
365
  _applyBindings() {
@@ -429,8 +393,11 @@ export class WEBGLRenderPipeline extends RenderPipeline {
429
393
  gl2.bindBufferRange(
430
394
  GL.UNIFORM_BUFFER,
431
395
  uniformBufferIndex,
396
+ // @ts-expect-error
432
397
  value.buffer.handle,
398
+ // @ts-expect-error
433
399
  value.offset || 0,
400
+ // @ts-expect-error
434
401
  value.size || value.buffer.byteLength - value.offset
435
402
  );
436
403
  }
@@ -30,7 +30,7 @@ export class WEBGLSampler extends Sampler {
30
30
  override destroy(): void {
31
31
  if (this.handle) {
32
32
  this.device.gl2.deleteSampler(this.handle);
33
- // @ts-expect-error
33
+ // @ts-expect-error read-only/undefined
34
34
  this.handle = undefined;
35
35
  }
36
36
  }
@@ -60,7 +60,7 @@ export class WEBGLShader extends Shader {
60
60
  const shaderLog = gl.getShaderInfoLog(this.handle);
61
61
  const parsedLog = shaderLog ? parseShaderCompilerLog(shaderLog) : [];
62
62
  const messages = parsedLog.filter(message => message.type === 'error');
63
- const formattedLog = formatCompilerLog(messages, source);
63
+ const formattedLog = formatCompilerLog(messages, source, {showSourceCode: true});
64
64
  const shaderName: string = getShaderInfo(source).name;
65
65
  const shaderDescription = `${this.stage} shader ${shaderName}`;
66
66
  log.error(`GLSL compilation errors in ${shaderDescription}\n${formattedLog}`)();
@@ -15,7 +15,7 @@ import {
15
15
  } from '@luma.gl/core';
16
16
  import {Texture, cast, log, assert, isPowerOfTwo, loadImage} from '@luma.gl/core';
17
17
  import {GL, GLSamplerParameters} from '@luma.gl/constants';
18
- import {withParameters} from '../../context/state-tracker/with-parameters';
18
+ import {withGLParameters} from '../../context/state-tracker/with-parameters';
19
19
  import {
20
20
  convertTextureFormatToGL,
21
21
  getWebGLTextureParameters,
@@ -428,7 +428,7 @@ export class WEBGLTexture extends Texture<WEBGLTextureProps> {
428
428
  this.mipmaps = true;
429
429
 
430
430
  this.gl.bindTexture(this.target, this.handle);
431
- withParameters(this.gl, params, () => {
431
+ withGLParameters(this.gl, params, () => {
432
432
  this.gl.generateMipmap(this.target);
433
433
  });
434
434
  this.gl.bindTexture(this.target, null);
@@ -504,7 +504,7 @@ export class WEBGLTexture extends Texture<WEBGLTextureProps> {
504
504
 
505
505
  let gl2;
506
506
 
507
- withParameters(this.gl, parameters, () => {
507
+ withGLParameters(this.gl, parameters, () => {
508
508
  switch (dataType) {
509
509
  case 'null':
510
510
  gl.texImage2D(target, level, glFormat, width, height, 0 /* border*/, dataFormat, type, data);
@@ -644,7 +644,7 @@ export class WEBGLTexture extends Texture<WEBGLTextureProps> {
644
644
 
645
645
  this.gl.bindTexture(this.target, this.handle);
646
646
 
647
- withParameters(this.gl, parameters, () => {
647
+ withGLParameters(this.gl, parameters, () => {
648
648
  // TODO - x,y parameters
649
649
  if (compressed) {
650
650
  this.gl.compressedTexSubImage2D(target, level, x, y, width, height, glFormat, data);
@@ -904,7 +904,7 @@ export class WEBGLTexture extends Texture<WEBGLTextureProps> {
904
904
 
905
905
  const webglTextureFormat = getWebGLTextureParameters(format, this.device.isWebGL2);
906
906
 
907
- withParameters(this.gl, parameters, () => {
907
+ withGLParameters(this.gl, parameters, () => {
908
908
  if (ArrayBuffer.isView(data)) {
909
909
  // @ts-expect-error
910
910
  this.gl.texImage3D(