@luma.gl/webgl 9.0.11 → 9.1.0-alpha.1
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/LICENSE +34 -0
- package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/device-parameters.js +12 -1
- 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 +31 -32
- package/dist/adapter/device-helpers/webgl-device-features.js +1 -1
- 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 +368 -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 +1 -3
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +45 -20
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +2 -2
- 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 +58 -172
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +402 -510
- 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-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 +4 -3
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +6 -5
- 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 +2 -1
- package/dist/classic/copy-and-blit.d.ts.map +1 -1
- package/dist/classic/copy-and-blit.js +11 -9
- 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.d.ts.map +1 -1
- package/dist/context/debug/spector.js +2 -1
- 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/state-tracker/track-context-state.d.ts.map +1 -1
- package/dist/context/state-tracker/track-context-state.js +5 -6
- package/dist/dist.dev.js +870 -1261
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +859 -1137
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -3
- 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/package.json +6 -5
- package/src/adapter/converters/device-parameters.ts +13 -1
- package/src/adapter/converters/texture-formats.ts +45 -42
- package/src/adapter/device-helpers/webgl-device-features.ts +1 -1
- package/src/adapter/device-helpers/webgl-device-limits.ts +1 -1
- package/src/adapter/helpers/webgl-texture-utils.ts +481 -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 +4 -5
- package/src/adapter/resources/webgl-render-pipeline.ts +48 -23
- package/src/adapter/resources/webgl-shader.ts +3 -3
- package/src/adapter/resources/webgl-texture-view.ts +1 -3
- package/src/adapter/resources/webgl-texture.ts +432 -784
- package/src/adapter/resources/webgl-vertex-array.ts +8 -7
- package/src/adapter/webgl-canvas-context.ts +4 -1
- package/src/adapter/webgl-device.ts +10 -18
- package/src/classic/accessor.ts +31 -11
- package/src/classic/clear.ts +3 -6
- package/src/classic/copy-and-blit.ts +19 -19
- package/src/classic/format-utils.ts +0 -3
- package/src/classic/typed-array-utils.ts +1 -1
- package/src/context/debug/spector.ts +2 -1
- package/src/context/debug/webgl-developer-tools.ts +3 -7
- package/src/context/parameters/webgl-parameter-tables.ts +3 -3
- package/src/context/state-tracker/track-context-state.ts +5 -6
- package/src/index.ts +0 -6
- 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/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/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.glTarget, 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,7 +2,8 @@
|
|
|
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';
|
|
@@ -57,9 +58,7 @@ export class WEBGLRenderPass extends RenderPass {
|
|
|
57
58
|
const glParameters: GLParameters = {...this.glParameters};
|
|
58
59
|
|
|
59
60
|
// Framebuffers are specified using parameters in WebGL
|
|
60
|
-
|
|
61
|
-
glParameters.framebuffer = this.props.framebuffer;
|
|
62
|
-
}
|
|
61
|
+
glParameters.framebuffer = this.props.framebuffer || null;
|
|
63
62
|
|
|
64
63
|
if (this.props.depthReadOnly) {
|
|
65
64
|
glParameters.depthMask = !this.props.depthReadOnly;
|
|
@@ -155,7 +154,7 @@ export class WEBGLRenderPass extends RenderPass {
|
|
|
155
154
|
/**
|
|
156
155
|
* WebGL2 - clear a specific color buffer
|
|
157
156
|
*/
|
|
158
|
-
protected clearColorBuffer(drawBuffer: number = 0, value:
|
|
157
|
+
protected clearColorBuffer(drawBuffer: number = 0, value: NumericArray = [0, 0, 0, 0]) {
|
|
159
158
|
withGLParameters(this.device.gl, {framebuffer: this.props.framebuffer}, () => {
|
|
160
159
|
// Method selection per OpenGL ES 3 docs
|
|
161
160
|
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 {
|
|
@@ -210,16 +199,18 @@ export class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
210
199
|
// Note: async textures set as uniforms might still be loading.
|
|
211
200
|
// Now that all uniforms have been updated, check if any texture
|
|
212
201
|
// in the uniforms is not yet initialized, then we don't draw
|
|
213
|
-
if (!this._areTexturesRenderable()
|
|
202
|
+
if (!this._areTexturesRenderable()) {
|
|
214
203
|
log.info(2, `RenderPipeline:${this.id}.draw() aborted - textures not yet loaded`)();
|
|
204
|
+
// Note: false means that the app needs to redraw the pipeline again.
|
|
215
205
|
return false;
|
|
216
206
|
}
|
|
217
207
|
|
|
218
208
|
// (isInstanced && instanceCount === 0)
|
|
219
|
-
if (vertexCount === 0) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
209
|
+
// if (vertexCount === 0) {
|
|
210
|
+
// log.info(2, `RenderPipeline:${this.id}.draw() aborted - no vertices to draw`)();
|
|
211
|
+
// Note: false means that the app needs to redraw the pipeline again.
|
|
212
|
+
// return true;
|
|
213
|
+
// }
|
|
223
214
|
|
|
224
215
|
this.device.gl.useProgram(this.handle);
|
|
225
216
|
|
|
@@ -390,10 +381,19 @@ export class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
390
381
|
_areTexturesRenderable() {
|
|
391
382
|
let texturesRenderable = true;
|
|
392
383
|
|
|
384
|
+
for (const bindingInfo of this.shaderLayout.bindings) {
|
|
385
|
+
if (
|
|
386
|
+
!this.bindings[bindingInfo.name] &&
|
|
387
|
+
!this.bindings[bindingInfo.name.replace(/Uniforms$/, '')]
|
|
388
|
+
) {
|
|
389
|
+
log.warn(`Binding ${bindingInfo.name} not found in ${this.id}`)();
|
|
390
|
+
texturesRenderable = false;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
393
394
|
for (const [, texture] of Object.entries(this.bindings)) {
|
|
394
395
|
if (texture instanceof WEBGLTexture) {
|
|
395
396
|
texture.update();
|
|
396
|
-
texturesRenderable = texturesRenderable && texture.loaded;
|
|
397
397
|
}
|
|
398
398
|
}
|
|
399
399
|
|
|
@@ -474,7 +474,7 @@ export class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
474
474
|
}
|
|
475
475
|
|
|
476
476
|
gl.activeTexture(GL.TEXTURE0 + textureUnit);
|
|
477
|
-
gl.bindTexture(texture.
|
|
477
|
+
gl.bindTexture(texture.glTarget, texture.handle);
|
|
478
478
|
// gl.bindSampler(textureUnit, sampler.handle);
|
|
479
479
|
textureUnit += 1;
|
|
480
480
|
break;
|
|
@@ -504,3 +504,28 @@ export class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
504
504
|
}
|
|
505
505
|
}
|
|
506
506
|
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Merges an provided shader layout into a base shader layout
|
|
510
|
+
* In WebGL, this allows the auto generated shader layout to be overridden by the application
|
|
511
|
+
* Typically to change the format of the vertex attributes (from float32x4 to uint8x4 etc).
|
|
512
|
+
* @todo Drop this? Aren't all use cases covered by mergeBufferLayout()?
|
|
513
|
+
*/
|
|
514
|
+
function mergeShaderLayout(baseLayout: ShaderLayout, overrideLayout: ShaderLayout): ShaderLayout {
|
|
515
|
+
// Deep clone the base layout
|
|
516
|
+
const mergedLayout: ShaderLayout = {
|
|
517
|
+
...baseLayout,
|
|
518
|
+
attributes: baseLayout.attributes.map(attribute => ({...attribute}))
|
|
519
|
+
};
|
|
520
|
+
// Merge the attributes
|
|
521
|
+
for (const attribute of overrideLayout?.attributes || []) {
|
|
522
|
+
const baseAttribute = mergedLayout.attributes.find(attr => attr.name === attribute.name);
|
|
523
|
+
if (!baseAttribute) {
|
|
524
|
+
log.warn(`shader layout attribute ${attribute.name} not present in shader`);
|
|
525
|
+
} else {
|
|
526
|
+
baseAttribute.type = attribute.type || baseAttribute.type;
|
|
527
|
+
baseAttribute.stepMode = attribute.stepMode || baseAttribute.stepMode;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
return mergedLayout;
|
|
531
|
+
}
|
|
@@ -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
|
|
@@ -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
|
}
|