@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.
- package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/device-parameters.js +30 -12
- package/dist/adapter/converters/texture-formats.d.ts +22 -16
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +39 -47
- package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-features.js +1 -2
- package/dist/adapter/device-helpers/webgl-device-limits.js +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.d.ts +300 -0
- package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -0
- package/dist/adapter/helpers/webgl-texture-utils.js +370 -0
- package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-topology-utils.js +0 -4
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +2 -2
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +6 -9
- package/dist/adapter/resources/webgl-framebuffer.d.ts +32 -5
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +42 -60
- package/dist/adapter/resources/webgl-render-pass.d.ts +3 -2
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +18 -7
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +46 -21
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +3 -3
- package/dist/adapter/resources/webgl-texture-view.d.ts +1 -1
- package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture-view.js +1 -1
- package/dist/adapter/resources/webgl-texture.d.ts +76 -172
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +397 -511
- package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -2
- package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-vertex-array.js +2 -2
- package/dist/adapter/webgl-adapter.d.ts +21 -0
- package/dist/adapter/webgl-adapter.d.ts.map +1 -0
- package/dist/adapter/webgl-adapter.js +91 -0
- package/dist/adapter/webgl-canvas-context.d.ts +3 -1
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js +2 -0
- package/dist/adapter/webgl-device.d.ts +19 -30
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +35 -114
- package/dist/classic/accessor.d.ts +22 -1
- package/dist/classic/accessor.d.ts.map +1 -1
- package/dist/classic/accessor.js +1 -9
- package/dist/classic/clear.d.ts.map +1 -1
- package/dist/classic/clear.js +2 -5
- package/dist/classic/copy-and-blit.d.ts +3 -1
- package/dist/classic/copy-and-blit.d.ts.map +1 -1
- package/dist/classic/copy-and-blit.js +21 -18
- package/dist/classic/format-utils.d.ts.map +1 -1
- package/dist/classic/format-utils.js +0 -3
- package/dist/classic/typed-array-utils.d.ts +1 -1
- package/dist/classic/typed-array-utils.d.ts.map +1 -1
- package/dist/context/debug/spector-types.d.ts +1108 -0
- package/dist/context/debug/spector-types.d.ts.map +1 -0
- package/dist/context/debug/spector-types.js +697 -0
- package/dist/context/debug/spector.d.ts +12 -8
- package/dist/context/debug/spector.d.ts.map +1 -1
- package/dist/context/debug/spector.js +25 -18
- package/dist/context/debug/webgl-developer-tools.d.ts +1 -1
- package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +2 -5
- package/dist/context/parameters/webgl-parameter-tables.js +1 -1
- package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts +9 -0
- package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts.map +1 -0
- package/dist/context/polyfills/polyfill-webgl1-extensions.js +181 -0
- package/dist/context/state-tracker/webgl-state-tracker.d.ts +43 -0
- package/dist/context/state-tracker/webgl-state-tracker.d.ts.map +1 -0
- package/dist/context/state-tracker/{track-context-state.js → webgl-state-tracker.js} +46 -77
- package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
- package/dist/context/state-tracker/with-parameters.js +5 -4
- package/dist/dist.dev.js +1112 -1380
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +1122 -1284
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +3 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -5
- package/dist/utils/fill-array.d.ts +8 -0
- package/dist/utils/fill-array.d.ts.map +1 -0
- package/dist/utils/fill-array.js +26 -0
- package/dist/utils/load-script.d.ts +8 -0
- package/dist/utils/load-script.d.ts.map +1 -0
- package/dist/utils/load-script.js +26 -0
- package/dist/utils/split-uniforms-and-bindings.d.ts +9 -0
- package/dist/utils/split-uniforms-and-bindings.d.ts.map +1 -0
- package/dist/utils/split-uniforms-and-bindings.js +20 -0
- package/dist/utils/uid.d.ts +7 -0
- package/dist/utils/uid.d.ts.map +1 -0
- package/dist/utils/uid.js +14 -0
- package/package.json +6 -5
- package/src/adapter/converters/device-parameters.ts +31 -13
- package/src/adapter/converters/texture-formats.ts +51 -56
- package/src/adapter/device-helpers/webgl-device-features.ts +1 -2
- package/src/adapter/device-helpers/webgl-device-limits.ts +1 -1
- package/src/adapter/helpers/webgl-texture-utils.ts +484 -0
- package/src/adapter/helpers/webgl-topology-utils.ts +0 -4
- package/src/adapter/resources/webgl-buffer.ts +2 -2
- package/src/adapter/resources/webgl-command-buffer.ts +8 -10
- package/src/adapter/resources/webgl-framebuffer.ts +22 -56
- package/src/adapter/resources/webgl-render-pass.ts +21 -9
- package/src/adapter/resources/webgl-render-pipeline.ts +50 -24
- package/src/adapter/resources/webgl-shader.ts +4 -4
- package/src/adapter/resources/webgl-texture-view.ts +1 -3
- package/src/adapter/resources/webgl-texture.ts +445 -784
- package/src/adapter/resources/webgl-vertex-array.ts +8 -7
- package/src/adapter/webgl-adapter.ts +113 -0
- package/src/adapter/webgl-canvas-context.ts +4 -1
- package/src/adapter/webgl-device.ts +40 -151
- package/src/classic/accessor.ts +31 -11
- package/src/classic/clear.ts +3 -6
- package/src/classic/copy-and-blit.ts +32 -27
- package/src/classic/format-utils.ts +0 -3
- package/src/classic/typed-array-utils.ts +1 -1
- package/src/context/debug/spector-types.ts +1154 -0
- package/src/context/debug/spector.ts +40 -30
- package/src/context/debug/webgl-developer-tools.ts +3 -7
- package/src/context/parameters/webgl-parameter-tables.ts +3 -3
- package/src/context/polyfills/polyfill-webgl1-extensions.ts +202 -0
- package/src/context/state-tracker/{track-context-state.ts → webgl-state-tracker.ts} +57 -97
- package/src/context/state-tracker/with-parameters.ts +5 -4
- package/src/index.ts +5 -13
- package/src/utils/fill-array.ts +35 -0
- package/src/utils/load-script.ts +30 -0
- package/src/utils/split-uniforms-and-bindings.ts +31 -0
- package/src/utils/uid.ts +16 -0
- package/dist/adapter/objects/constants-to-keys.d.ts +0 -3
- package/dist/adapter/objects/constants-to-keys.d.ts.map +0 -1
- package/dist/adapter/objects/constants-to-keys.js +0 -22
- package/dist/adapter/objects/webgl-renderbuffer.d.ts +0 -43
- package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +0 -1
- package/dist/adapter/objects/webgl-renderbuffer.js +0 -95
- package/dist/adapter/objects/webgl-resource.d.ts +0 -32
- package/dist/adapter/objects/webgl-resource.d.ts.map +0 -1
- package/dist/adapter/objects/webgl-resource.js +0 -114
- package/dist/context/state-tracker/track-context-state.d.ts +0 -22
- package/dist/context/state-tracker/track-context-state.d.ts.map +0 -1
- package/src/adapter/objects/constants-to-keys.ts +0 -27
- package/src/adapter/objects/webgl-renderbuffer.ts +0 -132
- 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
|
|
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
|
-
|
|
25
|
-
|
|
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]
|
|
51
|
+
const attachment = this.colorAttachments[i];
|
|
56
52
|
const attachmentPoint = GL.COLOR_ATTACHMENT0 + i;
|
|
57
53
|
if (attachment) {
|
|
58
|
-
this.
|
|
54
|
+
this._attachTexture(attachmentPoint, attachment);
|
|
59
55
|
}
|
|
60
56
|
}
|
|
61
57
|
|
|
62
58
|
if (this.depthStencilAttachment) {
|
|
63
|
-
this.
|
|
59
|
+
this._attachTexture(
|
|
64
60
|
getDepthStencilAttachmentWebGL(this.depthStencilAttachment.props.format),
|
|
65
|
-
this.depthStencilAttachment
|
|
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
|
-
|
|
123
|
+
colorAttachment.texture.clone({width, height});
|
|
128
124
|
}
|
|
129
125
|
if (this.depthStencilAttachment) {
|
|
130
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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.
|
|
153
|
+
gl.bindTexture(texture.glTarget, texture.handle);
|
|
188
154
|
|
|
189
|
-
switch (texture.
|
|
155
|
+
switch (texture.glTarget) {
|
|
190
156
|
case GL.TEXTURE_2D_ARRAY:
|
|
191
157
|
case GL.TEXTURE_3D:
|
|
192
|
-
gl.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.
|
|
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
|
-
|
|
172
|
+
throw new Error('Illegal texture type');
|
|
207
173
|
}
|
|
208
174
|
|
|
209
|
-
gl.bindTexture(texture.
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
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,
|
|
9
|
-
import {
|
|
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 =
|
|
61
|
-
this.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
|
-
`
|
|
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()
|
|
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
|
-
|
|
221
|
-
|
|
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.
|
|
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
|
|
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:
|
|
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
|
}
|