@luma.gl/webgl 9.0.0-alpha.21 → 9.0.0-alpha.23
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 +1 -1
- package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/device-parameters.js +9 -9
- package/dist/adapter/converters/device-parameters.js.map +1 -1
- package/dist/adapter/converters/sampler-parameters.d.ts +1 -1
- package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/sampler-parameters.js +1 -1
- package/dist/adapter/converters/sampler-parameters.js.map +1 -1
- package/dist/adapter/converters/texture-formats.d.ts +27 -38
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +152 -114
- package/dist/adapter/converters/texture-formats.js.map +1 -1
- package/dist/adapter/helpers/attribute-utils.d.ts +1 -1
- package/dist/adapter/helpers/attribute-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/attribute-utils.js +1 -1
- package/dist/adapter/helpers/attribute-utils.js.map +1 -1
- package/dist/adapter/helpers/get-shader-info.d.ts.map +1 -1
- package/dist/adapter/helpers/get-shader-info.js.map +1 -1
- package/dist/adapter/helpers/uniforms.d.ts +7 -8
- package/dist/adapter/helpers/uniforms.d.ts.map +1 -1
- package/dist/adapter/helpers/uniforms.js +4 -4
- package/dist/adapter/helpers/uniforms.js.map +1 -1
- package/dist/adapter/objects/constants-to-keys.d.ts +0 -2
- package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
- package/dist/adapter/objects/constants-to-keys.js +0 -20
- package/dist/adapter/objects/constants-to-keys.js.map +1 -1
- package/dist/adapter/objects/webgl-renderbuffer.d.ts +11 -8
- package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-renderbuffer.js +29 -19
- package/dist/adapter/objects/webgl-renderbuffer.js.map +1 -1
- package/dist/adapter/objects/webgl-resource.d.ts +0 -1
- package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-resource.js +4 -7
- package/dist/adapter/objects/webgl-resource.js.map +1 -1
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +3 -2
- package/dist/adapter/resources/webgl-buffer.js.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.d.ts +8 -2
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +168 -25
- package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.d.ts +3 -2
- package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.js +6 -2
- package/dist/adapter/resources/webgl-command-encoder.js.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.d.ts +9 -12
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +29 -79
- package/dist/adapter/resources/webgl-framebuffer.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.d.ts +16 -1
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +80 -0
- package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +3 -4
- package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
- package/dist/adapter/resources/webgl-sampler.d.ts +1 -1
- package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-sampler.js +1 -1
- package/dist/adapter/resources/webgl-sampler.js.map +1 -1
- package/dist/adapter/resources/webgl-texture.d.ts +39 -19
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +32 -30
- package/dist/adapter/resources/webgl-texture.js.map +1 -1
- package/dist/adapter/webgl-canvas-context.d.ts +1 -2
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js.map +1 -1
- package/dist/adapter/webgl-device.d.ts +13 -6
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +20 -2
- package/dist/adapter/webgl-device.js.map +1 -1
- package/dist/classic/buffer.d.ts +0 -1
- package/dist/classic/buffer.d.ts.map +1 -1
- package/dist/classic/buffer.js +0 -6
- package/dist/classic/buffer.js.map +1 -1
- package/dist/classic/typed-array-utils.d.ts +15 -17
- package/dist/classic/typed-array-utils.d.ts.map +1 -1
- package/dist/classic/typed-array-utils.js +1 -1
- package/dist/classic/typed-array-utils.js.map +1 -1
- package/dist/context/context/create-browser-context.js.map +1 -1
- package/dist/context/parameters/unified-parameter-api.d.ts +1 -1
- package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
- package/dist/context/parameters/unified-parameter-api.js.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.d.ts +1 -2
- package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.js +1 -1
- package/dist/context/parameters/webgl-parameter-tables.js.map +1 -1
- package/dist/dist.dev.js +1102 -670
- package/dist/index.cjs +1085 -898
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist.min.js +22 -21
- package/package.json +7 -4
- package/src/adapter/converters/device-parameters.ts +46 -22
- package/src/adapter/converters/sampler-parameters.ts +1 -2
- package/src/adapter/converters/texture-formats.ts +242 -161
- package/src/adapter/helpers/attribute-utils.ts +1 -2
- package/src/adapter/helpers/get-shader-info.ts +3 -0
- package/src/adapter/helpers/uniforms.ts +9 -10
- package/src/adapter/objects/constants-to-keys.ts +0 -25
- package/src/adapter/objects/webgl-renderbuffer.ts +32 -29
- package/src/adapter/objects/webgl-resource.ts +4 -8
- package/src/adapter/resources/webgl-buffer.ts +4 -5
- package/src/adapter/resources/webgl-command-buffer.ts +328 -21
- package/src/adapter/resources/webgl-command-encoder.ts +7 -2
- package/src/adapter/resources/webgl-framebuffer.ts +63 -111
- package/src/adapter/resources/webgl-render-pass.ts +146 -2
- package/src/adapter/resources/webgl-render-pipeline.ts +6 -3
- package/src/adapter/resources/webgl-sampler.ts +1 -2
- package/src/adapter/resources/webgl-texture.ts +61 -43
- package/src/adapter/webgl-canvas-context.ts +2 -2
- package/src/adapter/webgl-device.ts +37 -8
- package/src/classic/buffer.ts +3 -3
- package/src/classic/typed-array-utils.ts +15 -26
- package/src/context/context/create-browser-context.ts +2 -2
- package/src/context/parameters/unified-parameter-api.ts +1 -1
- package/src/context/parameters/webgl-parameter-tables.ts +2 -2
- package/src/index.ts +5 -3
- package/dist/adapter/converters/renderbuffer-formats.d.ts +0 -16
- package/dist/adapter/converters/renderbuffer-formats.d.ts.map +0 -1
- package/dist/adapter/converters/renderbuffer-formats.js +0 -180
- package/dist/adapter/converters/renderbuffer-formats.js.map +0 -1
- package/dist/types/webgl.d.ts +0 -145
- package/dist/types/webgl.d.ts.map +0 -1
- package/dist/types/webgl.js +0 -2
- package/dist/types/webgl.js.map +0 -1
- package/src/.DS_Store +0 -0
- package/src/adapter/.DS_Store +0 -0
- package/src/adapter/converters/renderbuffer-formats.ts +0 -90
- package/src/context/.DS_Store +0 -0
- package/src/types/webgl.ts +0 -286
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// luma.gl, MIT license
|
|
2
2
|
|
|
3
|
-
import type {FramebufferProps,
|
|
4
|
-
import {Framebuffer, Texture,
|
|
3
|
+
import type {FramebufferProps, TextureFormat} from '@luma.gl/api';
|
|
4
|
+
import {Framebuffer, Texture, assert} from '@luma.gl/api';
|
|
5
5
|
import GL from '@luma.gl/constants';
|
|
6
6
|
import {WebGLDevice} from '../webgl-device';
|
|
7
7
|
import {WEBGLTexture} from './webgl-texture';
|
|
8
8
|
import {WEBGLRenderbuffer} from '../objects/webgl-renderbuffer';
|
|
9
|
-
import {
|
|
9
|
+
import {getDepthStencilAttachmentWebGL} from '../converters/texture-formats';
|
|
10
10
|
|
|
11
11
|
export type TextureAttachment = [Texture, number?, number?];
|
|
12
12
|
export type Attachment = WEBGLTexture | WEBGLRenderbuffer | TextureAttachment;
|
|
@@ -17,43 +17,49 @@ export class WEBGLFramebuffer extends Framebuffer {
|
|
|
17
17
|
gl: WebGLRenderingContext;
|
|
18
18
|
handle: WebGLFramebuffer;
|
|
19
19
|
|
|
20
|
-
get texture() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
protected _ownResources: (WEBGLTexture | WEBGLRenderbuffer)[] = [];
|
|
20
|
+
get texture() {
|
|
21
|
+
return this.colorAttachments[0];
|
|
22
|
+
}
|
|
24
23
|
|
|
25
24
|
constructor(device: WebGLDevice, props: FramebufferProps) {
|
|
26
25
|
super(device, props);
|
|
26
|
+
|
|
27
|
+
// WebGL default framebuffer handle is null
|
|
28
|
+
const isDefaultFramebuffer = props.handle === null;
|
|
29
|
+
|
|
27
30
|
this.device = device;
|
|
28
31
|
this.gl = device.gl;
|
|
29
|
-
this.handle =
|
|
32
|
+
this.handle =
|
|
33
|
+
this.props.handle || isDefaultFramebuffer ? this.props.handle : this.gl.createFramebuffer();
|
|
30
34
|
|
|
31
|
-
if (
|
|
35
|
+
if (!isDefaultFramebuffer) {
|
|
36
|
+
// default framebuffer handle is null, so we can't set spector metadata...
|
|
32
37
|
device.setSpectorMetadata(this.handle, {id: this.props.id, props: this.props});
|
|
33
|
-
}
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this.depthStencilAttachment = this._createDepthStencilAttachment();
|
|
39
|
+
// Auto create textures for attachments if needed
|
|
40
|
+
this.autoCreateAttachmentTextures();
|
|
38
41
|
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
/** Attach from a map of attachments */
|
|
43
|
+
this.gl.bindFramebuffer(GL.FRAMEBUFFER, this.handle);
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
// Walk the attachments
|
|
46
|
+
for (let i = 0; i < this.colorAttachments.length; ++i) {
|
|
47
|
+
const attachment = this.colorAttachments[i];
|
|
48
|
+
const attachmentPoint = GL.COLOR_ATTACHMENT0 + i;
|
|
49
|
+
if (attachment) {
|
|
50
|
+
this._attachOne(attachmentPoint, attachment as WEBGLTexture);
|
|
51
|
+
}
|
|
48
52
|
}
|
|
49
|
-
}
|
|
50
53
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
if (this.depthStencilAttachment) {
|
|
55
|
+
this._attachOne(
|
|
56
|
+
getDepthStencilAttachmentWebGL(this.depthStencilAttachment.format),
|
|
57
|
+
this.depthStencilAttachment as WEBGLTexture
|
|
58
|
+
);
|
|
59
|
+
}
|
|
54
60
|
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
this.gl.bindFramebuffer(GL.FRAMEBUFFER, null);
|
|
62
|
+
}
|
|
57
63
|
|
|
58
64
|
// @ts-expect-error
|
|
59
65
|
if (props.check !== false) {
|
|
@@ -61,14 +67,12 @@ export class WEBGLFramebuffer extends Framebuffer {
|
|
|
61
67
|
}
|
|
62
68
|
}
|
|
63
69
|
|
|
70
|
+
/** destroys any auto created resources etc. */
|
|
64
71
|
override destroy(): void {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
resource.destroy();
|
|
68
|
-
}
|
|
72
|
+
super.destroy(); // destroys owned resources etc.
|
|
73
|
+
if (!this.destroyed && this.handle !== null) {
|
|
69
74
|
this.gl.deleteFramebuffer(this.handle);
|
|
70
75
|
// this.handle = null;
|
|
71
|
-
this.destroyed = true;
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
78
|
|
|
@@ -77,92 +81,31 @@ export class WEBGLFramebuffer extends Framebuffer {
|
|
|
77
81
|
/** Check the status */
|
|
78
82
|
protected _checkStatus(): void {
|
|
79
83
|
const {gl} = this;
|
|
80
|
-
|
|
84
|
+
// TODO - should we really rely on this trick?
|
|
85
|
+
const prevHandle = gl.bindFramebuffer(GL.FRAMEBUFFER, this.handle) as unknown as WebGLFramebuffer;
|
|
81
86
|
const status = gl.checkFramebufferStatus(GL.FRAMEBUFFER);
|
|
82
|
-
// @ts-expect-error
|
|
83
87
|
gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
|
|
84
88
|
if (status !== gl.FRAMEBUFFER_COMPLETE) {
|
|
85
89
|
throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
|
|
86
90
|
}
|
|
87
91
|
}
|
|
88
92
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return undefined;
|
|
93
|
-
}
|
|
94
|
-
if (colorAttachment instanceof WEBGLTexture) {
|
|
95
|
-
return colorAttachment;
|
|
96
|
-
}
|
|
97
|
-
// if (typeof colorAttachment === 'default') {
|
|
98
|
-
// return this._createColorAttachment('rgba8unorm', this.width, this.height);
|
|
99
|
-
// }
|
|
100
|
-
// @ts-expect-error
|
|
101
|
-
return this._createColorAttachment(colorAttachment, this.width, this.height);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/** Create a color attachment */
|
|
106
|
-
protected _createColorAttachment(format: ColorTextureFormat, width: number, height: number): WEBGLTexture {
|
|
107
|
-
const texture = this.device._createTexture({
|
|
108
|
-
id: `${this.id}-color`,
|
|
109
|
-
data: null, // reserves texture memory, but texels are undefined
|
|
110
|
-
format,
|
|
111
|
-
// type: GL.UNSIGNED_BYTE,
|
|
112
|
-
width,
|
|
113
|
-
height,
|
|
114
|
-
// Note: Mipmapping can be disabled by texture resource when we resize the texture
|
|
115
|
-
// to a non-power-of-two dimenstion (NPOT texture) under WebGL1. To have consistant
|
|
116
|
-
// behavior we always disable mipmaps.
|
|
117
|
-
mipmaps: false,
|
|
118
|
-
// Set MIN and MAG filtering parameters so mipmaps are not used in sampling.
|
|
119
|
-
// Use LINEAR so subpixel algos like fxaa work.
|
|
120
|
-
// Set WRAP modes that support NPOT textures too.
|
|
121
|
-
sampler: {
|
|
122
|
-
minFilter: 'linear',
|
|
123
|
-
magFilter: 'linear',
|
|
124
|
-
addressModeU: 'clamp-to-edge',
|
|
125
|
-
addressModeV: 'clamp-to-edge'
|
|
126
|
-
},
|
|
127
|
-
// parameters: {
|
|
128
|
-
// [GL.TEXTURE_MIN_FILTER]: GL.LINEAR,
|
|
129
|
-
// [GL.TEXTURE_MAG_FILTER]: GL.LINEAR,
|
|
130
|
-
// [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
|
|
131
|
-
// [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE
|
|
132
|
-
// }
|
|
133
|
-
}) ;
|
|
134
|
-
this._ownResources.push(texture);
|
|
135
|
-
return texture;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/** Create a depth stencil attachment GL.DEPTH24_STENCIL8 */
|
|
139
|
-
protected _createDepthStencilAttachment(): WEBGLRenderbuffer | WEBGLTexture {
|
|
140
|
-
if (!this.props.depthStencilAttachment) {
|
|
141
|
-
return undefined;
|
|
142
|
-
}
|
|
143
|
-
if (this.props.depthStencilAttachment instanceof WEBGLRenderbuffer) {
|
|
144
|
-
return this.props.depthStencilAttachment;
|
|
145
|
-
}
|
|
146
|
-
if (this.props.depthStencilAttachment instanceof Texture) {
|
|
147
|
-
return this.props.depthStencilAttachment as unknown as WEBGLTexture;
|
|
148
|
-
}
|
|
149
|
-
const format = this.props.depthStencilAttachment;
|
|
150
|
-
const webglFormat = getWebGLTextureFormat(this.gl, format);
|
|
151
|
-
|
|
152
|
-
const texture = new WEBGLRenderbuffer(this.device, {
|
|
93
|
+
/** In WebGL we must use renderbuffers for depth/stencil attachments (unless we have extensions) */
|
|
94
|
+
protected override createDepthStencilTexture(format: TextureFormat): Texture {
|
|
95
|
+
return new WEBGLRenderbuffer(this.device, {
|
|
153
96
|
id: `${this.id}-depth-stencil`, // TODO misleading if not depth and stencil?
|
|
154
|
-
format
|
|
97
|
+
format,
|
|
155
98
|
// dataFormat: GL.DEPTH_STENCIL,
|
|
156
99
|
// type: GL.UNSIGNED_INT_24_8,
|
|
157
100
|
width: this.width,
|
|
158
101
|
height: this.height
|
|
159
|
-
});
|
|
160
|
-
this._ownResources.push(texture);
|
|
161
|
-
return texture;
|
|
102
|
+
}) as unknown as WEBGLTexture;
|
|
162
103
|
}
|
|
163
104
|
|
|
164
|
-
/**
|
|
165
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Attachment resize is expected to be a noop if size is same
|
|
107
|
+
*/
|
|
108
|
+
protected override resizeAttachments(width: number, height: number): this {
|
|
166
109
|
// for default framebuffer, just update the stored size
|
|
167
110
|
if (this.handle === null) {
|
|
168
111
|
// assert(width === undefined && height === undefined);
|
|
@@ -170,6 +113,7 @@ export class WEBGLFramebuffer extends Framebuffer {
|
|
|
170
113
|
this.height = this.gl.drawingBufferHeight;
|
|
171
114
|
return this;
|
|
172
115
|
}
|
|
116
|
+
|
|
173
117
|
if (width === undefined) {
|
|
174
118
|
width = this.gl.drawingBufferWidth;
|
|
175
119
|
}
|
|
@@ -177,19 +121,22 @@ export class WEBGLFramebuffer extends Framebuffer {
|
|
|
177
121
|
height = this.gl.drawingBufferHeight;
|
|
178
122
|
}
|
|
179
123
|
|
|
180
|
-
|
|
181
|
-
log.log(2, `Resizing framebuffer ${this.id} to ${width}x${height}`)();
|
|
182
|
-
}
|
|
124
|
+
// TODO Not clear that this is better than default destroy/create implementation
|
|
183
125
|
|
|
184
126
|
for (const colorAttachment of this.colorAttachments) {
|
|
185
|
-
colorAttachment.resize({width, height});
|
|
127
|
+
(colorAttachment as WEBGLTexture).resize({width, height});
|
|
128
|
+
}
|
|
129
|
+
if (this.depthStencilAttachment) {
|
|
130
|
+
(this.depthStencilAttachment as WEBGLTexture).resize({width, height});
|
|
186
131
|
}
|
|
187
|
-
this.depthStencilAttachment?.resize({width, height});
|
|
188
132
|
return this;
|
|
189
133
|
}
|
|
190
134
|
|
|
191
135
|
/** Attach one attachment */
|
|
192
|
-
protected _attachOne(
|
|
136
|
+
protected _attachOne(
|
|
137
|
+
attachmentPoint: GL,
|
|
138
|
+
attachment: Attachment
|
|
139
|
+
): WEBGLTexture | WEBGLRenderbuffer {
|
|
193
140
|
if (attachment instanceof WEBGLRenderbuffer) {
|
|
194
141
|
this._attachWEBGLRenderbuffer(attachmentPoint, attachment);
|
|
195
142
|
return attachment;
|
|
@@ -219,7 +166,12 @@ export class WEBGLFramebuffer extends Framebuffer {
|
|
|
219
166
|
* @param layer = 0 - index into WEBGLTextureArray and Texture3D or face for `TextureCubeMap`
|
|
220
167
|
* @param level = 0 - mipmapLevel (must be 0 in WebGL1)
|
|
221
168
|
*/
|
|
222
|
-
protected _attachTexture(
|
|
169
|
+
protected _attachTexture(
|
|
170
|
+
attachment: GL,
|
|
171
|
+
texture: WEBGLTexture,
|
|
172
|
+
layer: number,
|
|
173
|
+
level: number
|
|
174
|
+
): void {
|
|
223
175
|
const {gl, gl2} = this.device;
|
|
224
176
|
gl.bindTexture(texture.target, texture.handle);
|
|
225
177
|
|
|
@@ -1,15 +1,36 @@
|
|
|
1
|
-
import {RenderPass, RenderPassProps} from '@luma.gl/api';
|
|
1
|
+
import {RenderPass, RenderPassProps, NumericArray, RenderPassParameters} from '@luma.gl/api';
|
|
2
2
|
import {WebGLDevice} from '../webgl-device';
|
|
3
|
+
import {GL, GLParameters} from '@luma.gl/constants';
|
|
4
|
+
import {withParameters} from '../../context/state-tracker/with-parameters';
|
|
5
|
+
|
|
6
|
+
// Should collapse during minification
|
|
7
|
+
|
|
8
|
+
const GL_DEPTH_BUFFER_BIT = 0x00000100;
|
|
9
|
+
const GL_STENCIL_BUFFER_BIT = 0x00000400;
|
|
10
|
+
const GL_COLOR_BUFFER_BIT = 0x00004000;
|
|
11
|
+
|
|
12
|
+
const GL_COLOR = 0x1800;
|
|
3
13
|
|
|
4
14
|
export class WEBGLRenderPass extends RenderPass {
|
|
5
15
|
readonly device: WebGLDevice;
|
|
6
16
|
|
|
17
|
+
/** Parameters that should be applied before each draw call */
|
|
18
|
+
glParameters: GLParameters;
|
|
19
|
+
|
|
7
20
|
constructor(device: WebGLDevice, props: RenderPassProps) {
|
|
8
21
|
super(device, props);
|
|
9
22
|
this.device = device;
|
|
23
|
+
|
|
24
|
+
// TODO - do parameters (scissorRect) affect the clear operation?
|
|
25
|
+
this.setParameters(this.props.parameters);
|
|
26
|
+
|
|
27
|
+
// Hack - for now WebGL draws in "immediate mode" (instead of queueing the operations)...
|
|
28
|
+
this.clear();
|
|
10
29
|
}
|
|
11
30
|
|
|
12
|
-
end(): void {
|
|
31
|
+
end(): void {
|
|
32
|
+
// should add commands to CommandEncoder.
|
|
33
|
+
}
|
|
13
34
|
|
|
14
35
|
pushDebugGroup(groupLabel: string): void {}
|
|
15
36
|
popDebugGroup(): void {}
|
|
@@ -21,4 +42,127 @@ export class WEBGLRenderPass extends RenderPass {
|
|
|
21
42
|
// endOcclusionQuery(): void;
|
|
22
43
|
|
|
23
44
|
// executeBundles(bundles: Iterable<GPURenderBundle>): void;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Maps RenderPass parameters to GL parameters
|
|
48
|
+
*/
|
|
49
|
+
setParameters(parameters: RenderPassParameters = {}): void {
|
|
50
|
+
const glParameters: GLParameters = {};
|
|
51
|
+
|
|
52
|
+
// Framebuffers are specified using parameters in WebGL
|
|
53
|
+
if (this.props.framebuffer) {
|
|
54
|
+
glParameters.framebuffer = this.props.framebuffer;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (this.props.depthReadOnly) {
|
|
58
|
+
glParameters.depthMask = !this.props.depthReadOnly;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
glParameters.stencilMask = this.props.stencilReadOnly ? 0 : 1;
|
|
62
|
+
|
|
63
|
+
glParameters[GL.RASTERIZER_DISCARD] = this.props.discard;
|
|
64
|
+
|
|
65
|
+
// Map the four renderpass parameters to WebGL parameters
|
|
66
|
+
if (parameters.viewport) {
|
|
67
|
+
glParameters.viewport = parameters.viewport;
|
|
68
|
+
glParameters.depthRange = [parameters.viewport[4], parameters.viewport[5]];
|
|
69
|
+
}
|
|
70
|
+
glParameters.scissorTest = Boolean(parameters.scissorRect);
|
|
71
|
+
if (parameters.scissorRect) {
|
|
72
|
+
glParameters.scissor = parameters.scissorRect;
|
|
73
|
+
}
|
|
74
|
+
if (parameters.blendConstant) {
|
|
75
|
+
glParameters.blendColor = parameters.blendConstant;
|
|
76
|
+
}
|
|
77
|
+
if (parameters.stencilReference) {
|
|
78
|
+
// eslint-disable-next-line no-console
|
|
79
|
+
console.warn('RenderPassParameters.stencilReference not yet implemented in WebGL');
|
|
80
|
+
// parameters.stencilFunc = [func, ref, mask];
|
|
81
|
+
// Does this work?
|
|
82
|
+
parameters[GL.STENCIL_REF] = parameters.stencilReference;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
this.glParameters = glParameters;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Internal
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Optionally clears depth, color and stencil buffers based on parameters
|
|
92
|
+
*/
|
|
93
|
+
protected clear(): void {
|
|
94
|
+
const glParameters: GLParameters = {...this.glParameters};
|
|
95
|
+
|
|
96
|
+
let clearMask = 0;
|
|
97
|
+
|
|
98
|
+
if (this.props.clearColor !== false) {
|
|
99
|
+
clearMask |= GL_COLOR_BUFFER_BIT;
|
|
100
|
+
glParameters.clearColor = this.props.clearColor;
|
|
101
|
+
}
|
|
102
|
+
if (this.props.clearDepth !== false) {
|
|
103
|
+
clearMask |= GL_DEPTH_BUFFER_BIT;
|
|
104
|
+
glParameters.clearDepth = this.props.clearDepth;
|
|
105
|
+
}
|
|
106
|
+
if (this.props.clearStencil !== false) {
|
|
107
|
+
clearMask |= GL_STENCIL_BUFFER_BIT;
|
|
108
|
+
glParameters.clearStencil = this.props.clearStencil;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (clearMask !== 0) {
|
|
112
|
+
// Temporarily set any clear "colors" and call clear
|
|
113
|
+
withParameters(this.device, glParameters, () => {
|
|
114
|
+
this.device.gl.clear(clearMask);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// TODO - clear multiple color attachments
|
|
118
|
+
// for (attachment of this.framebuffer.colorAttachments) {
|
|
119
|
+
// this.clearColorBuffer
|
|
120
|
+
// }
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* WebGL2 - clear a specific color buffer
|
|
126
|
+
*/
|
|
127
|
+
protected clearColorBuffer(drawBuffer: number = 0, value: NumericArray = [0, 0, 0, 0]) {
|
|
128
|
+
withParameters(this.device.gl2, {framebuffer: this.props.framebuffer}, () => {
|
|
129
|
+
// Method selection per OpenGL ES 3 docs
|
|
130
|
+
switch (value.constructor) {
|
|
131
|
+
case Int32Array:
|
|
132
|
+
this.device.gl2.clearBufferiv(GL_COLOR, drawBuffer, value);
|
|
133
|
+
break;
|
|
134
|
+
case Uint32Array:
|
|
135
|
+
this.device.gl2.clearBufferuiv(GL_COLOR, drawBuffer, value);
|
|
136
|
+
break;
|
|
137
|
+
case Float32Array:
|
|
138
|
+
default:
|
|
139
|
+
this.device.gl2.clearBufferfv(GL_COLOR, drawBuffer, value);
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// clearDepthStencil() {
|
|
146
|
+
// const GL_DEPTH = 0x1801;
|
|
147
|
+
// const GL_STENCIL = 0x1802;
|
|
148
|
+
// const GL_DEPTH_STENCIL = 0x84f9;
|
|
149
|
+
|
|
150
|
+
// case GL_DEPTH:
|
|
151
|
+
// this.device.gl2.clearBufferfv(GL_DEPTH, 0, [value]);
|
|
152
|
+
// break;
|
|
153
|
+
|
|
154
|
+
// case GL_STENCIL:
|
|
155
|
+
// this.device.gl2.clearBufferiv(GL_STENCIL, 0, [value]);
|
|
156
|
+
// break;
|
|
157
|
+
|
|
158
|
+
// case GL_DEPTH_STENCIL:
|
|
159
|
+
// const [depth, stencil] = value;
|
|
160
|
+
// this.device.gl2.clearBufferfi(GL_DEPTH_STENCIL, 0, depth, stencil);
|
|
161
|
+
// break;
|
|
162
|
+
|
|
163
|
+
// default:
|
|
164
|
+
// assert(false, ERR_ARGUMENTS);
|
|
165
|
+
// }
|
|
166
|
+
// });
|
|
24
167
|
}
|
|
168
|
+
|
|
@@ -22,6 +22,7 @@ import {WEBGLBuffer} from './webgl-buffer';
|
|
|
22
22
|
import {WEBGLShader} from './webgl-shader';
|
|
23
23
|
import {WEBGLTexture} from './webgl-texture';
|
|
24
24
|
import {WEBGLVertexArrayObject} from '../objects/webgl-vertex-array-object';
|
|
25
|
+
import {WEBGLRenderPass} from './webgl-render-pass';
|
|
25
26
|
|
|
26
27
|
const LOG_PROGRAM_PERF_PRIORITY = 4;
|
|
27
28
|
|
|
@@ -159,7 +160,7 @@ export class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
159
160
|
* This function unifies those ways into a single call using common parameters with sane defaults
|
|
160
161
|
*/
|
|
161
162
|
draw(options: {
|
|
162
|
-
renderPass
|
|
163
|
+
renderPass: RenderPass;
|
|
163
164
|
vertexCount?: number;
|
|
164
165
|
indexCount?: number;
|
|
165
166
|
instanceCount?: number;
|
|
@@ -169,7 +170,7 @@ export class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
169
170
|
baseVertex?: number;
|
|
170
171
|
}): boolean {
|
|
171
172
|
const {
|
|
172
|
-
renderPass
|
|
173
|
+
renderPass,
|
|
173
174
|
vertexCount,
|
|
174
175
|
// indexCount,
|
|
175
176
|
instanceCount,
|
|
@@ -206,9 +207,11 @@ export class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
206
207
|
this._applyBindings();
|
|
207
208
|
this._applyUniforms();
|
|
208
209
|
|
|
210
|
+
const webglRenderPass = renderPass as WEBGLRenderPass;
|
|
211
|
+
|
|
209
212
|
// TODO - double context push/pop
|
|
210
213
|
withDeviceParameters(this.device, this.props.parameters, () => {
|
|
211
|
-
withGLParameters(this.device,
|
|
214
|
+
withGLParameters(this.device, webglRenderPass.glParameters, () => {
|
|
212
215
|
// TODO - Use polyfilled WebGL2RenderingContext instead of ANGLE extension
|
|
213
216
|
if (isIndexed && isInstanced) {
|
|
214
217
|
// ANGLE_instanced_arrays extension
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// luma.gl, MIT license
|
|
2
2
|
|
|
3
3
|
import {Sampler, SamplerProps} from '@luma.gl/api';
|
|
4
|
-
import GL from '@luma.gl/constants';
|
|
5
|
-
import type {GLSamplerParameters} from '../../types/webgl';
|
|
4
|
+
import {GL, GLSamplerParameters} from '@luma.gl/constants';
|
|
6
5
|
import {convertSamplerParametersToWebGL} from '../converters/sampler-parameters';
|
|
7
6
|
import type {WebGLDevice} from '../webgl-device';
|
|
8
7
|
|