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

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 (144) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  2. package/dist/adapter/converters/device-parameters.js +30 -12
  3. package/dist/adapter/converters/texture-formats.d.ts +22 -16
  4. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  5. package/dist/adapter/converters/texture-formats.js +39 -47
  6. package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
  7. package/dist/adapter/device-helpers/webgl-device-features.js +1 -2
  8. package/dist/adapter/device-helpers/webgl-device-limits.js +1 -1
  9. package/dist/adapter/helpers/webgl-texture-utils.d.ts +300 -0
  10. package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -0
  11. package/dist/adapter/helpers/webgl-texture-utils.js +370 -0
  12. package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
  13. package/dist/adapter/helpers/webgl-topology-utils.js +0 -4
  14. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  15. package/dist/adapter/resources/webgl-buffer.js +2 -2
  16. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  17. package/dist/adapter/resources/webgl-command-buffer.js +6 -9
  18. package/dist/adapter/resources/webgl-framebuffer.d.ts +32 -5
  19. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  20. package/dist/adapter/resources/webgl-framebuffer.js +42 -60
  21. package/dist/adapter/resources/webgl-render-pass.d.ts +3 -2
  22. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  23. package/dist/adapter/resources/webgl-render-pass.js +18 -7
  24. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  25. package/dist/adapter/resources/webgl-render-pipeline.js +46 -21
  26. package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
  27. package/dist/adapter/resources/webgl-shader.js +3 -3
  28. package/dist/adapter/resources/webgl-texture-view.d.ts +1 -1
  29. package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -1
  30. package/dist/adapter/resources/webgl-texture-view.js +1 -1
  31. package/dist/adapter/resources/webgl-texture.d.ts +76 -172
  32. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  33. package/dist/adapter/resources/webgl-texture.js +397 -511
  34. package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -2
  35. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  36. package/dist/adapter/resources/webgl-vertex-array.js +2 -2
  37. package/dist/adapter/webgl-adapter.d.ts +21 -0
  38. package/dist/adapter/webgl-adapter.d.ts.map +1 -0
  39. package/dist/adapter/webgl-adapter.js +91 -0
  40. package/dist/adapter/webgl-canvas-context.d.ts +3 -1
  41. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  42. package/dist/adapter/webgl-canvas-context.js +2 -0
  43. package/dist/adapter/webgl-device.d.ts +19 -30
  44. package/dist/adapter/webgl-device.d.ts.map +1 -1
  45. package/dist/adapter/webgl-device.js +35 -114
  46. package/dist/classic/accessor.d.ts +22 -1
  47. package/dist/classic/accessor.d.ts.map +1 -1
  48. package/dist/classic/accessor.js +1 -9
  49. package/dist/classic/clear.d.ts.map +1 -1
  50. package/dist/classic/clear.js +2 -5
  51. package/dist/classic/copy-and-blit.d.ts +3 -1
  52. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  53. package/dist/classic/copy-and-blit.js +21 -18
  54. package/dist/classic/format-utils.d.ts.map +1 -1
  55. package/dist/classic/format-utils.js +0 -3
  56. package/dist/classic/typed-array-utils.d.ts +1 -1
  57. package/dist/classic/typed-array-utils.d.ts.map +1 -1
  58. package/dist/context/debug/spector-types.d.ts +1108 -0
  59. package/dist/context/debug/spector-types.d.ts.map +1 -0
  60. package/dist/context/debug/spector-types.js +697 -0
  61. package/dist/context/debug/spector.d.ts +12 -8
  62. package/dist/context/debug/spector.d.ts.map +1 -1
  63. package/dist/context/debug/spector.js +25 -18
  64. package/dist/context/debug/webgl-developer-tools.d.ts +1 -1
  65. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  66. package/dist/context/debug/webgl-developer-tools.js +2 -5
  67. package/dist/context/parameters/webgl-parameter-tables.js +1 -1
  68. package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts +9 -0
  69. package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts.map +1 -0
  70. package/dist/context/polyfills/polyfill-webgl1-extensions.js +181 -0
  71. package/dist/context/state-tracker/webgl-state-tracker.d.ts +43 -0
  72. package/dist/context/state-tracker/webgl-state-tracker.d.ts.map +1 -0
  73. package/dist/context/state-tracker/{track-context-state.js → webgl-state-tracker.js} +46 -77
  74. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  75. package/dist/context/state-tracker/with-parameters.js +5 -4
  76. package/dist/dist.dev.js +1112 -1380
  77. package/dist/dist.min.js +2 -2
  78. package/dist/index.cjs +1122 -1284
  79. package/dist/index.cjs.map +4 -4
  80. package/dist/index.d.ts +3 -5
  81. package/dist/index.d.ts.map +1 -1
  82. package/dist/index.js +3 -5
  83. package/dist/utils/fill-array.d.ts +8 -0
  84. package/dist/utils/fill-array.d.ts.map +1 -0
  85. package/dist/utils/fill-array.js +26 -0
  86. package/dist/utils/load-script.d.ts +8 -0
  87. package/dist/utils/load-script.d.ts.map +1 -0
  88. package/dist/utils/load-script.js +26 -0
  89. package/dist/utils/split-uniforms-and-bindings.d.ts +9 -0
  90. package/dist/utils/split-uniforms-and-bindings.d.ts.map +1 -0
  91. package/dist/utils/split-uniforms-and-bindings.js +20 -0
  92. package/dist/utils/uid.d.ts +7 -0
  93. package/dist/utils/uid.d.ts.map +1 -0
  94. package/dist/utils/uid.js +14 -0
  95. package/package.json +6 -5
  96. package/src/adapter/converters/device-parameters.ts +31 -13
  97. package/src/adapter/converters/texture-formats.ts +51 -56
  98. package/src/adapter/device-helpers/webgl-device-features.ts +1 -2
  99. package/src/adapter/device-helpers/webgl-device-limits.ts +1 -1
  100. package/src/adapter/helpers/webgl-texture-utils.ts +484 -0
  101. package/src/adapter/helpers/webgl-topology-utils.ts +0 -4
  102. package/src/adapter/resources/webgl-buffer.ts +2 -2
  103. package/src/adapter/resources/webgl-command-buffer.ts +8 -10
  104. package/src/adapter/resources/webgl-framebuffer.ts +22 -56
  105. package/src/adapter/resources/webgl-render-pass.ts +21 -9
  106. package/src/adapter/resources/webgl-render-pipeline.ts +50 -24
  107. package/src/adapter/resources/webgl-shader.ts +4 -4
  108. package/src/adapter/resources/webgl-texture-view.ts +1 -3
  109. package/src/adapter/resources/webgl-texture.ts +445 -784
  110. package/src/adapter/resources/webgl-vertex-array.ts +8 -7
  111. package/src/adapter/webgl-adapter.ts +113 -0
  112. package/src/adapter/webgl-canvas-context.ts +4 -1
  113. package/src/adapter/webgl-device.ts +40 -151
  114. package/src/classic/accessor.ts +31 -11
  115. package/src/classic/clear.ts +3 -6
  116. package/src/classic/copy-and-blit.ts +32 -27
  117. package/src/classic/format-utils.ts +0 -3
  118. package/src/classic/typed-array-utils.ts +1 -1
  119. package/src/context/debug/spector-types.ts +1154 -0
  120. package/src/context/debug/spector.ts +40 -30
  121. package/src/context/debug/webgl-developer-tools.ts +3 -7
  122. package/src/context/parameters/webgl-parameter-tables.ts +3 -3
  123. package/src/context/polyfills/polyfill-webgl1-extensions.ts +202 -0
  124. package/src/context/state-tracker/{track-context-state.ts → webgl-state-tracker.ts} +57 -97
  125. package/src/context/state-tracker/with-parameters.ts +5 -4
  126. package/src/index.ts +5 -13
  127. package/src/utils/fill-array.ts +35 -0
  128. package/src/utils/load-script.ts +30 -0
  129. package/src/utils/split-uniforms-and-bindings.ts +31 -0
  130. package/src/utils/uid.ts +16 -0
  131. package/dist/adapter/objects/constants-to-keys.d.ts +0 -3
  132. package/dist/adapter/objects/constants-to-keys.d.ts.map +0 -1
  133. package/dist/adapter/objects/constants-to-keys.js +0 -22
  134. package/dist/adapter/objects/webgl-renderbuffer.d.ts +0 -43
  135. package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +0 -1
  136. package/dist/adapter/objects/webgl-renderbuffer.js +0 -95
  137. package/dist/adapter/objects/webgl-resource.d.ts +0 -32
  138. package/dist/adapter/objects/webgl-resource.d.ts.map +0 -1
  139. package/dist/adapter/objects/webgl-resource.js +0 -114
  140. package/dist/context/state-tracker/track-context-state.d.ts +0 -22
  141. package/dist/context/state-tracker/track-context-state.d.ts.map +0 -1
  142. package/src/adapter/objects/constants-to-keys.ts +0 -27
  143. package/src/adapter/objects/webgl-renderbuffer.ts +0 -132
  144. package/src/adapter/objects/webgl-resource.ts +0 -183
@@ -3,16 +3,13 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {FramebufferProps, TextureFormat} from '@luma.gl/core';
6
- import {Framebuffer, Texture, assert} from '@luma.gl/core';
6
+ import {Framebuffer, Texture} from '@luma.gl/core';
7
7
  import {GL} from '@luma.gl/constants';
8
8
  import {WebGLDevice} from '../webgl-device';
9
9
  import {WEBGLTexture} from './webgl-texture';
10
10
  import {WEBGLTextureView} from './webgl-texture-view';
11
11
  import {getDepthStencilAttachmentWebGL} from '../converters/texture-formats';
12
12
 
13
- // TODO - for now we don't see a usage for renderbuffers in WebGL 2.
14
- // import {WEBGLRenderbuffer} from '../objects/webgl-renderbuffer';
15
-
16
13
  export type Attachment = WEBGLTextureView | WEBGLTexture; // | WEBGLRenderbuffer;
17
14
 
18
15
  /** luma.gl Framebuffer, WebGL implementation */
@@ -21,9 +18,8 @@ export class WEBGLFramebuffer extends Framebuffer {
21
18
  gl: WebGL2RenderingContext;
22
19
  handle: WebGLFramebuffer;
23
20
 
24
- get texture() {
25
- return this.colorAttachments[0];
26
- }
21
+ colorAttachments: WEBGLTextureView[] = [];
22
+ depthStencilAttachment: WEBGLTextureView | null = null;
27
23
 
28
24
  constructor(device: WebGLDevice, props: FramebufferProps) {
29
25
  super(device, props);
@@ -52,17 +48,17 @@ export class WEBGLFramebuffer extends Framebuffer {
52
48
 
53
49
  // Walk the attachments
54
50
  for (let i = 0; i < this.colorAttachments.length; ++i) {
55
- const attachment = this.colorAttachments[i] as WEBGLTextureView;
51
+ const attachment = this.colorAttachments[i];
56
52
  const attachmentPoint = GL.COLOR_ATTACHMENT0 + i;
57
53
  if (attachment) {
58
- this._attachOne(attachmentPoint, attachment);
54
+ this._attachTexture(attachmentPoint, attachment);
59
55
  }
60
56
  }
61
57
 
62
58
  if (this.depthStencilAttachment) {
63
- this._attachOne(
59
+ this._attachTexture(
64
60
  getDepthStencilAttachmentWebGL(this.depthStencilAttachment.props.format),
65
- this.depthStencilAttachment as WEBGLTextureView
61
+ this.depthStencilAttachment
66
62
  );
67
63
  }
68
64
 
@@ -104,7 +100,7 @@ export class WEBGLFramebuffer extends Framebuffer {
104
100
 
105
101
  /**
106
102
  * Attachment resize is expected to be a noop if size is same
107
- */
103
+ *
108
104
  protected override resizeAttachments(width: number, height: number): this {
109
105
  // for default framebuffer, just update the stored size
110
106
  if (this.handle === null) {
@@ -124,72 +120,42 @@ export class WEBGLFramebuffer extends Framebuffer {
124
120
  // TODO Not clear that this is better than default destroy/create implementation
125
121
 
126
122
  for (const colorAttachment of this.colorAttachments) {
127
- (colorAttachment.texture as WEBGLTexture).resize({width, height});
123
+ colorAttachment.texture.clone({width, height});
128
124
  }
129
125
  if (this.depthStencilAttachment) {
130
- (this.depthStencilAttachment.texture as WEBGLTexture).resize({width, height});
126
+ this.depthStencilAttachment.texture.resize({width, height});
131
127
  }
132
128
  return this;
133
129
  }
130
+ */
134
131
 
135
132
  /** Attach one attachment */
136
- protected _attachOne(attachmentPoint: GL, attachment: Attachment): WEBGLTexture {
133
+ protected _attachTexture(attachmentPoint: GL, textureView: WEBGLTextureView): void {
137
134
  // if (attachment instanceof WEBGLRenderbuffer) {
138
135
  // this._attachWEBGLRenderbuffer(attachmentPoint, attachment);
139
136
  // return attachment;
140
137
  // }
141
- if (Array.isArray(attachment)) {
142
- const [texture, layer = 0, level = 0] = attachment;
143
- this._attachTexture(attachmentPoint, texture as unknown as WEBGLTexture, layer, level);
144
- return texture as unknown as WEBGLTexture;
145
- }
146
- if (attachment instanceof WEBGLTexture) {
147
- this._attachTexture(attachmentPoint, attachment, 0, 0);
148
- return attachment;
149
- }
150
- if (attachment instanceof WEBGLTextureView) {
151
- const textureView = attachment;
152
- this._attachTexture(
153
- attachmentPoint,
154
- textureView.texture,
155
- textureView.props.baseMipLevel,
156
- textureView.props.baseArrayLayer
157
- );
158
- return attachment.texture;
159
- }
160
- throw new Error('attach');
138
+ this._attachTextureView(attachmentPoint, textureView);
161
139
  }
162
140
 
163
- // TODO - we do not seem to need render buffers in WebGL 2
164
- // protected _attachWEBGLRenderbuffer(attachment: GL, renderbuffer: WEBGLRenderbuffer): void {
165
- // this.gl.framebufferRenderbuffer(
166
- // GL.FRAMEBUFFER,
167
- // attachment,
168
- // GL.RENDERBUFFER,
169
- // renderbuffer.handle
170
- // );
171
- // }
172
-
173
141
  /**
174
142
  * @param attachment
175
143
  * @param texture
176
144
  * @param layer = 0 - index into WEBGLTextureArray and Texture3D or face for `TextureCubeMap`
177
145
  * @param level = 0 - mipmapLevel
178
146
  */
179
- protected _attachTexture(
180
- attachment: GL,
181
- texture: WEBGLTexture,
182
- layer: number,
183
- level: number
184
- ): void {
147
+ protected _attachTextureView(attachment: GL, textureView: WEBGLTextureView): void {
185
148
  const {gl} = this.device;
149
+ const {texture} = textureView;
150
+ const level = textureView.props.baseMipLevel;
151
+ const layer = textureView.props.baseArrayLayer;
186
152
 
187
- gl.bindTexture(texture.target, texture.handle);
153
+ gl.bindTexture(texture.glTarget, texture.handle);
188
154
 
189
- switch (texture.target) {
155
+ switch (texture.glTarget) {
190
156
  case GL.TEXTURE_2D_ARRAY:
191
157
  case GL.TEXTURE_3D:
192
- gl.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.target, level, layer);
158
+ gl.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.handle, level, layer);
193
159
  break;
194
160
 
195
161
  case GL.TEXTURE_CUBE_MAP:
@@ -203,10 +169,10 @@ export class WEBGLFramebuffer extends Framebuffer {
203
169
  break;
204
170
 
205
171
  default:
206
- assert(false, 'Illegal texture type');
172
+ throw new Error('Illegal texture type');
207
173
  }
208
174
 
209
- gl.bindTexture(texture.target, null);
175
+ gl.bindTexture(texture.glTarget, null);
210
176
  }
211
177
  }
212
178
 
@@ -2,12 +2,12 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {RenderPass, RenderPassProps, NumberArray, RenderPassParameters} from '@luma.gl/core';
5
+ import {NumericArray} from '@math.gl/types';
6
+ import {RenderPass, RenderPassProps, RenderPassParameters} from '@luma.gl/core';
6
7
  import {WebGLDevice} from '../webgl-device';
7
8
  import {GL, GLParameters} from '@luma.gl/constants';
8
9
  import {withGLParameters} from '../../context/state-tracker/with-parameters';
9
10
  import {setGLParameters} from '../../context/parameters/unified-parameter-api';
10
- import {pushContextState, popContextState} from '../../context/state-tracker/track-context-state';
11
11
  import {WEBGLQuerySet} from './webgl-query-set';
12
12
 
13
13
  // Should collapse during minification
@@ -28,16 +28,30 @@ export class WEBGLRenderPass extends RenderPass {
28
28
  super(device, props);
29
29
  this.device = device;
30
30
 
31
+ // If no viewport is provided, apply reasonably defaults
32
+ let viewport;
33
+ if (!props?.parameters?.viewport) {
34
+ if (props?.framebuffer) {
35
+ // Set the viewport to the size of the framebuffer
36
+ const {width, height} = props.framebuffer;
37
+ viewport = [0, 0, width, height];
38
+ } else {
39
+ // Instead of using our own book-keeping, we can just read the values from the WebGL context
40
+ const [width, height] = device.getCanvasContext().getDrawingBufferSize();
41
+ viewport = [0, 0, width, height];
42
+ }
43
+ }
44
+
31
45
  // TODO - do parameters (scissorRect) affect the clear operation?
32
- pushContextState(this.device.gl);
33
- this.setParameters(this.props.parameters);
46
+ this.device.pushState();
47
+ this.setParameters({viewport, ...this.props.parameters});
34
48
 
35
49
  // Hack - for now WebGL draws in "immediate mode" (instead of queueing the operations)...
36
50
  this.clear();
37
51
  }
38
52
 
39
53
  end(): void {
40
- popContextState(this.device.gl);
54
+ this.device.popState();
41
55
  // should add commands to CommandEncoder.
42
56
  }
43
57
 
@@ -57,9 +71,7 @@ export class WEBGLRenderPass extends RenderPass {
57
71
  const glParameters: GLParameters = {...this.glParameters};
58
72
 
59
73
  // Framebuffers are specified using parameters in WebGL
60
- if (this.props.framebuffer) {
61
- glParameters.framebuffer = this.props.framebuffer;
62
- }
74
+ glParameters.framebuffer = this.props.framebuffer || null;
63
75
 
64
76
  if (this.props.depthReadOnly) {
65
77
  glParameters.depthMask = !this.props.depthReadOnly;
@@ -155,7 +167,7 @@ export class WEBGLRenderPass extends RenderPass {
155
167
  /**
156
168
  * WebGL2 - clear a specific color buffer
157
169
  */
158
- protected clearColorBuffer(drawBuffer: number = 0, value: NumberArray = [0, 0, 0, 0]) {
170
+ protected clearColorBuffer(drawBuffer: number = 0, value: NumericArray = [0, 0, 0, 0]) {
159
171
  withGLParameters(this.device.gl, {framebuffer: this.props.framebuffer}, () => {
160
172
  // Method selection per OpenGL ES 3 docs
161
173
  switch (value.constructor) {
@@ -5,14 +5,14 @@
5
5
  import type {RenderPipelineProps, RenderPipelineParameters, PrimitiveTopology} from '@luma.gl/core';
6
6
  import type {ShaderLayout, UniformValue, Binding} from '@luma.gl/core';
7
7
  import type {RenderPass, VertexArray} from '@luma.gl/core';
8
- import {RenderPipeline, cast, splitUniformsAndBindings, log} from '@luma.gl/core';
9
- import {mergeShaderLayout} from '@luma.gl/core';
10
- // import {mergeShaderLayout, getAttributeInfosFromLayouts} from '@luma.gl/core';
8
+ import {RenderPipeline, log} from '@luma.gl/core';
9
+ // import {getAttributeInfosFromLayouts} from '@luma.gl/core';
11
10
  import {GL} from '@luma.gl/constants';
12
11
 
13
12
  import {getShaderLayout} from '../helpers/get-shader-layout';
14
13
  import {withDeviceAndGLParameters} from '../converters/device-parameters';
15
14
  import {setUniform} from '../helpers/set-uniform';
15
+ import {splitUniformsAndBindings} from '../../utils/split-uniforms-and-bindings';
16
16
  // import {copyUniform, checkUniformValues} from '../../classes/uniforms';
17
17
 
18
18
  import {WebGLDevice} from '../webgl-device';
@@ -57,8 +57,8 @@ export class WEBGLRenderPipeline extends RenderPipeline {
57
57
  this.device.setSpectorMetadata(this.handle, {id: this.props.id});
58
58
 
59
59
  // Create shaders if needed
60
- this.vs = cast<WEBGLShader>(props.vs);
61
- this.fs = cast<WEBGLShader>(props.fs);
60
+ this.vs = props.vs as WEBGLShader;
61
+ this.fs = props.fs as WEBGLShader;
62
62
  // assert(this.vs.stage === 'vertex');
63
63
  // assert(this.fs.stage === 'fragment');
64
64
 
@@ -78,17 +78,6 @@ export class WEBGLRenderPipeline extends RenderPipeline {
78
78
 
79
79
  // Merge provided layout with introspected layout
80
80
  this.shaderLayout = mergeShaderLayout(this.introspectedLayout, props.shaderLayout);
81
-
82
- // WebGPU has more restrictive topology support than WebGL
83
- switch (this.props.topology) {
84
- case 'triangle-fan-webgl':
85
- case 'line-loop-webgl':
86
- log.warn(
87
- `Primitive topology ${this.props.topology} is deprecated and will be removed in v9.1`
88
- );
89
- break;
90
- default:
91
- }
92
81
  }
93
82
 
94
83
  override destroy(): void {
@@ -123,7 +112,8 @@ export class WEBGLRenderPipeline extends RenderPipeline {
123
112
  .join(', ');
124
113
  if (!options?.disableWarnings) {
125
114
  log.warn(
126
- `Unknown binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`
115
+ `No binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`,
116
+ value
127
117
  )();
128
118
  }
129
119
  continue; // eslint-disable-line no-continue
@@ -210,16 +200,18 @@ export class WEBGLRenderPipeline extends RenderPipeline {
210
200
  // Note: async textures set as uniforms might still be loading.
211
201
  // Now that all uniforms have been updated, check if any texture
212
202
  // in the uniforms is not yet initialized, then we don't draw
213
- if (!this._areTexturesRenderable() || vertexCount === 0) {
203
+ if (!this._areTexturesRenderable()) {
214
204
  log.info(2, `RenderPipeline:${this.id}.draw() aborted - textures not yet loaded`)();
205
+ // Note: false means that the app needs to redraw the pipeline again.
215
206
  return false;
216
207
  }
217
208
 
218
209
  // (isInstanced && instanceCount === 0)
219
- if (vertexCount === 0) {
220
- log.info(2, `RenderPipeline:${this.id}.draw() aborted - no vertices to draw`)();
221
- return true;
222
- }
210
+ // if (vertexCount === 0) {
211
+ // log.info(2, `RenderPipeline:${this.id}.draw() aborted - no vertices to draw`)();
212
+ // Note: false means that the app needs to redraw the pipeline again.
213
+ // return true;
214
+ // }
223
215
 
224
216
  this.device.gl.useProgram(this.handle);
225
217
 
@@ -390,10 +382,19 @@ export class WEBGLRenderPipeline extends RenderPipeline {
390
382
  _areTexturesRenderable() {
391
383
  let texturesRenderable = true;
392
384
 
385
+ for (const bindingInfo of this.shaderLayout.bindings) {
386
+ if (
387
+ !this.bindings[bindingInfo.name] &&
388
+ !this.bindings[bindingInfo.name.replace(/Uniforms$/, '')]
389
+ ) {
390
+ log.warn(`Binding ${bindingInfo.name} not found in ${this.id}`)();
391
+ texturesRenderable = false;
392
+ }
393
+ }
394
+
393
395
  for (const [, texture] of Object.entries(this.bindings)) {
394
396
  if (texture instanceof WEBGLTexture) {
395
397
  texture.update();
396
- texturesRenderable = texturesRenderable && texture.loaded;
397
398
  }
398
399
  }
399
400
 
@@ -474,7 +475,7 @@ export class WEBGLRenderPipeline extends RenderPipeline {
474
475
  }
475
476
 
476
477
  gl.activeTexture(GL.TEXTURE0 + textureUnit);
477
- gl.bindTexture(texture.target, texture.handle);
478
+ gl.bindTexture(texture.glTarget, texture.handle);
478
479
  // gl.bindSampler(textureUnit, sampler.handle);
479
480
  textureUnit += 1;
480
481
  break;
@@ -504,3 +505,28 @@ export class WEBGLRenderPipeline extends RenderPipeline {
504
505
  }
505
506
  }
506
507
  }
508
+
509
+ /**
510
+ * Merges an provided shader layout into a base shader layout
511
+ * In WebGL, this allows the auto generated shader layout to be overridden by the application
512
+ * Typically to change the format of the vertex attributes (from float32x4 to uint8x4 etc).
513
+ * @todo Drop this? Aren't all use cases covered by mergeBufferLayout()?
514
+ */
515
+ function mergeShaderLayout(baseLayout: ShaderLayout, overrideLayout: ShaderLayout): ShaderLayout {
516
+ // Deep clone the base layout
517
+ const mergedLayout: ShaderLayout = {
518
+ ...baseLayout,
519
+ attributes: baseLayout.attributes.map(attribute => ({...attribute}))
520
+ };
521
+ // Merge the attributes
522
+ for (const attribute of overrideLayout?.attributes || []) {
523
+ const baseAttribute = mergedLayout.attributes.find(attr => attr.name === attribute.name);
524
+ if (!baseAttribute) {
525
+ log.warn(`shader layout attribute ${attribute.name} not present in shader`);
526
+ } else {
527
+ baseAttribute.type = attribute.type || baseAttribute.type;
528
+ baseAttribute.stepMode = attribute.stepMode || baseAttribute.stepMode;
529
+ }
530
+ }
531
+ return mergedLayout;
532
+ }
@@ -44,15 +44,15 @@ export class WEBGLShader extends Shader {
44
44
  return this.getCompilationInfoSync();
45
45
  }
46
46
 
47
- override getCompilationInfoSync() {
47
+ override getCompilationInfoSync(): readonly CompilerMessage[] {
48
48
  const log = this.device.gl.getShaderInfoLog(this.handle);
49
- return parseShaderCompilerLog(log);
49
+ return log ? parseShaderCompilerLog(log) : [];
50
50
  }
51
51
 
52
52
  override getTranslatedSource(): string | null {
53
53
  const extensions = this.device.getExtension('WEBGL_debug_shaders');
54
54
  const ext = extensions.WEBGL_debug_shaders;
55
- return ext?.getTranslatedShaderSource(this.handle);
55
+ return ext?.getTranslatedShaderSource(this.handle) || null;
56
56
  }
57
57
 
58
58
  // PRIVATE METHODS
@@ -60,7 +60,7 @@ export class WEBGLShader extends Shader {
60
60
  /** Compile a shader and get compilation status */
61
61
  protected async _compile(source: string): Promise<void> {
62
62
  const addGLSLVersion = (source: string) =>
63
- source.startsWith('#version ') ? source : `#version 100\n${source}`;
63
+ source.startsWith('#version ') ? source : `#version 300 es\n${source}`;
64
64
  source = addGLSLVersion(source);
65
65
 
66
66
  const {gl} = this.device;
@@ -12,8 +12,7 @@ import {WEBGLTexture} from './webgl-texture';
12
12
  export class WEBGLTextureView extends TextureView {
13
13
  readonly device: WebGLDevice;
14
14
  readonly gl: WebGL2RenderingContext;
15
- readonly handle: WebGLTexture;
16
-
15
+ readonly handle: null; // Does not have a WebGL representation
17
16
  readonly texture: WEBGLTexture;
18
17
 
19
18
  constructor(device: Device, props: TextureViewProps & {texture: WEBGLTexture}) {
@@ -22,7 +21,6 @@ export class WEBGLTextureView extends TextureView {
22
21
  this.device = device as WebGLDevice;
23
22
  this.gl = this.device.gl;
24
23
  this.handle = null;
25
-
26
24
  this.texture = props.texture;
27
25
  }
28
26
  }