@luma.gl/webgl 9.3.0-alpha.4 → 9.3.0-alpha.6
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/webgl-texture-table.d.ts +7 -1
- package/dist/adapter/converters/webgl-texture-table.d.ts.map +1 -1
- package/dist/adapter/converters/webgl-texture-table.js +121 -43
- package/dist/adapter/converters/webgl-texture-table.js.map +1 -1
- 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-features.js.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-info.js +5 -0
- package/dist/adapter/device-helpers/webgl-device-info.js.map +1 -1
- package/dist/adapter/helpers/get-shader-layout-from-glsl.js +16 -17
- package/dist/adapter/helpers/get-shader-layout-from-glsl.js.map +1 -1
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +19 -4
- package/dist/adapter/resources/webgl-buffer.js.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.d.ts +2 -2
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +2 -2
- package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.d.ts +5 -4
- package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.js +20 -7
- package/dist/adapter/resources/webgl-command-encoder.js.map +1 -1
- package/dist/adapter/resources/webgl-query-set.d.ts +29 -31
- package/dist/adapter/resources/webgl-query-set.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-query-set.js +193 -97
- package/dist/adapter/resources/webgl-query-set.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +12 -0
- package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +13 -19
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +35 -152
- package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
- package/dist/adapter/resources/webgl-shared-render-pipeline.d.ts +24 -0
- package/dist/adapter/resources/webgl-shared-render-pipeline.d.ts.map +1 -0
- package/dist/adapter/resources/webgl-shared-render-pipeline.js +152 -0
- package/dist/adapter/resources/webgl-shared-render-pipeline.js.map +1 -0
- package/dist/adapter/resources/webgl-texture.d.ts +23 -4
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +203 -100
- package/dist/adapter/resources/webgl-texture.js.map +1 -1
- package/dist/adapter/webgl-device.d.ts +4 -2
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +31 -3
- package/dist/adapter/webgl-device.js.map +1 -1
- package/dist/adapter/webgl-presentation-context.d.ts +21 -0
- package/dist/adapter/webgl-presentation-context.d.ts.map +1 -0
- package/dist/adapter/webgl-presentation-context.js +64 -0
- package/dist/adapter/webgl-presentation-context.js.map +1 -0
- package/dist/dist.dev.js +1332 -788
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +1247 -797
- package/dist/index.cjs.map +4 -4
- package/package.json +3 -3
- package/src/adapter/converters/webgl-texture-table.ts +159 -47
- package/src/adapter/device-helpers/webgl-device-features.ts +1 -2
- package/src/adapter/device-helpers/webgl-device-info.ts +6 -0
- package/src/adapter/helpers/get-shader-layout-from-glsl.ts +18 -19
- package/src/adapter/resources/webgl-buffer.ts +16 -4
- package/src/adapter/resources/webgl-command-buffer.ts +3 -2
- package/src/adapter/resources/webgl-command-encoder.ts +22 -7
- package/src/adapter/resources/webgl-query-set.ts +229 -102
- package/src/adapter/resources/webgl-render-pass.ts +13 -0
- package/src/adapter/resources/webgl-render-pipeline.ts +45 -179
- package/src/adapter/resources/webgl-shared-render-pipeline.ts +208 -0
- package/src/adapter/resources/webgl-texture.ts +326 -121
- package/src/adapter/webgl-device.ts +40 -4
- package/src/adapter/webgl-presentation-context.ts +93 -0
|
@@ -8,6 +8,8 @@ import type {
|
|
|
8
8
|
DeviceInfo,
|
|
9
9
|
DeviceTextureFormatCapabilities,
|
|
10
10
|
CanvasContextProps,
|
|
11
|
+
PresentationContextProps,
|
|
12
|
+
PresentationContext,
|
|
11
13
|
Buffer,
|
|
12
14
|
Texture,
|
|
13
15
|
Framebuffer,
|
|
@@ -23,6 +25,7 @@ import type {
|
|
|
23
25
|
FramebufferProps,
|
|
24
26
|
// RenderPipeline,
|
|
25
27
|
RenderPipelineProps,
|
|
28
|
+
SharedRenderPipeline,
|
|
26
29
|
ComputePipeline,
|
|
27
30
|
ComputePipelineProps,
|
|
28
31
|
// CommandEncoder,
|
|
@@ -41,6 +44,7 @@ import {getDeviceInfo} from './device-helpers/webgl-device-info';
|
|
|
41
44
|
import {WebGLDeviceFeatures} from './device-helpers/webgl-device-features';
|
|
42
45
|
import {WebGLDeviceLimits} from './device-helpers/webgl-device-limits';
|
|
43
46
|
import {WebGLCanvasContext} from './webgl-canvas-context';
|
|
47
|
+
import {WebGLPresentationContext} from './webgl-presentation-context';
|
|
44
48
|
import type {Spector} from '../context/debug/spector-types';
|
|
45
49
|
import {initializeSpectorJS} from '../context/debug/spector';
|
|
46
50
|
import {makeDebugContext} from '../context/debug/webgl-developer-tools';
|
|
@@ -53,6 +57,7 @@ import {WEBGLSampler} from './resources/webgl-sampler';
|
|
|
53
57
|
import {WEBGLTexture} from './resources/webgl-texture';
|
|
54
58
|
import {WEBGLFramebuffer} from './resources/webgl-framebuffer';
|
|
55
59
|
import {WEBGLRenderPipeline} from './resources/webgl-render-pipeline';
|
|
60
|
+
import {WEBGLSharedRenderPipeline} from './resources/webgl-shared-render-pipeline';
|
|
56
61
|
import {WEBGLCommandEncoder} from './resources/webgl-command-encoder';
|
|
57
62
|
import {WEBGLCommandBuffer} from './resources/webgl-command-buffer';
|
|
58
63
|
import {WEBGLVertexArray} from './resources/webgl-vertex-array';
|
|
@@ -255,6 +260,7 @@ export class WebGLDevice extends Device {
|
|
|
255
260
|
}
|
|
256
261
|
|
|
257
262
|
this.commandEncoder = new WEBGLCommandEncoder(this, {id: `${this}-command-encoder`});
|
|
263
|
+
this.canvasContext._startObservers();
|
|
258
264
|
}
|
|
259
265
|
|
|
260
266
|
/**
|
|
@@ -268,6 +274,7 @@ export class WebGLDevice extends Device {
|
|
|
268
274
|
* browser API for destroying WebGL contexts.
|
|
269
275
|
*/
|
|
270
276
|
destroy(): void {
|
|
277
|
+
this.commandEncoder?.destroy();
|
|
271
278
|
// Note that deck.gl (especially in React strict mode) depends on being able
|
|
272
279
|
// to asynchronously create a Device against the same canvas (i.e. WebGL context)
|
|
273
280
|
// multiple times and getting the same device back. Since deck.gl is not aware
|
|
@@ -290,6 +297,10 @@ export class WebGLDevice extends Device {
|
|
|
290
297
|
throw new Error('WebGL only supports a single canvas');
|
|
291
298
|
}
|
|
292
299
|
|
|
300
|
+
createPresentationContext(props?: PresentationContextProps): PresentationContext {
|
|
301
|
+
return new WebGLPresentationContext(this, props || {});
|
|
302
|
+
}
|
|
303
|
+
|
|
293
304
|
createBuffer(props: BufferProps | ArrayBuffer | ArrayBufferView): WEBGLBuffer {
|
|
294
305
|
const newProps = this._normalizeBufferProps(props);
|
|
295
306
|
return new WEBGLBuffer(this, newProps);
|
|
@@ -335,6 +346,13 @@ export class WebGLDevice extends Device {
|
|
|
335
346
|
return new WEBGLRenderPipeline(this, props);
|
|
336
347
|
}
|
|
337
348
|
|
|
349
|
+
override _createSharedRenderPipelineWebGL(props: RenderPipelineProps): SharedRenderPipeline {
|
|
350
|
+
return new WEBGLSharedRenderPipeline(
|
|
351
|
+
this,
|
|
352
|
+
props as RenderPipelineProps & {vs: WEBGLShader; fs: WEBGLShader}
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
|
|
338
356
|
createComputePipeline(props?: ComputePipelineProps): ComputePipeline {
|
|
339
357
|
throw new Error('ComputePipeline not supported in WebGL');
|
|
340
358
|
}
|
|
@@ -348,14 +366,32 @@ export class WebGLDevice extends Device {
|
|
|
348
366
|
* https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/commit
|
|
349
367
|
* Chrome's offscreen canvas does not require gl.commit
|
|
350
368
|
*/
|
|
351
|
-
submit(commandBuffer
|
|
369
|
+
submit(commandBuffer?: WEBGLCommandBuffer): void {
|
|
370
|
+
let submittedCommandEncoder: WEBGLCommandEncoder | null = null;
|
|
352
371
|
if (!commandBuffer) {
|
|
353
|
-
|
|
372
|
+
submittedCommandEncoder = this.commandEncoder;
|
|
373
|
+
commandBuffer = submittedCommandEncoder.finish();
|
|
354
374
|
this.commandEncoder.destroy();
|
|
355
|
-
this.commandEncoder = this.createCommandEncoder({
|
|
375
|
+
this.commandEncoder = this.createCommandEncoder({
|
|
376
|
+
id: submittedCommandEncoder.props.id,
|
|
377
|
+
timeProfilingQuerySet: submittedCommandEncoder.getTimeProfilingQuerySet()
|
|
378
|
+
});
|
|
356
379
|
}
|
|
357
380
|
|
|
358
|
-
|
|
381
|
+
try {
|
|
382
|
+
commandBuffer._executeCommands();
|
|
383
|
+
|
|
384
|
+
if (submittedCommandEncoder) {
|
|
385
|
+
submittedCommandEncoder
|
|
386
|
+
.resolveTimeProfilingQuerySet()
|
|
387
|
+
.then(() => {
|
|
388
|
+
this.commandEncoder._gpuTimeMs = submittedCommandEncoder._gpuTimeMs;
|
|
389
|
+
})
|
|
390
|
+
.catch(() => {});
|
|
391
|
+
}
|
|
392
|
+
} finally {
|
|
393
|
+
commandBuffer.destroy();
|
|
394
|
+
}
|
|
359
395
|
}
|
|
360
396
|
|
|
361
397
|
//
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {PresentationContextProps, TextureFormatDepthStencil, Framebuffer} from '@luma.gl/core';
|
|
6
|
+
import {PresentationContext} from '@luma.gl/core';
|
|
7
|
+
import type {WebGLDevice} from './webgl-device';
|
|
8
|
+
|
|
9
|
+
type PresentationCanvasRenderingContext2D =
|
|
10
|
+
| CanvasRenderingContext2D
|
|
11
|
+
| OffscreenCanvasRenderingContext2D;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Tracks a non-WebGL destination canvas while rendering into the device's default canvas context.
|
|
15
|
+
*/
|
|
16
|
+
export class WebGLPresentationContext extends PresentationContext {
|
|
17
|
+
readonly device: WebGLDevice;
|
|
18
|
+
readonly handle = null;
|
|
19
|
+
readonly context2d: PresentationCanvasRenderingContext2D;
|
|
20
|
+
|
|
21
|
+
get [Symbol.toStringTag](): string {
|
|
22
|
+
return 'WebGLPresentationContext';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
constructor(device: WebGLDevice, props: PresentationContextProps = {}) {
|
|
26
|
+
super(props);
|
|
27
|
+
this.device = device;
|
|
28
|
+
const contextLabel = `${this[Symbol.toStringTag]}(${this.id})`;
|
|
29
|
+
|
|
30
|
+
const defaultCanvasContext = this.device.getDefaultCanvasContext();
|
|
31
|
+
if (!defaultCanvasContext.offscreenCanvas) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`${contextLabel}: WebGL PresentationContext requires the default CanvasContext canvas to be an OffscreenCanvas`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const context2d = this.canvas.getContext('2d');
|
|
38
|
+
if (!context2d) {
|
|
39
|
+
throw new Error(`${contextLabel}: Failed to create 2d presentation context`);
|
|
40
|
+
}
|
|
41
|
+
this.context2d = context2d;
|
|
42
|
+
|
|
43
|
+
this._setAutoCreatedCanvasId(`${this.device.id}-presentation-canvas`);
|
|
44
|
+
this._configureDevice();
|
|
45
|
+
this._startObservers();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
present(): void {
|
|
49
|
+
this._resizeDrawingBufferIfNeeded();
|
|
50
|
+
this.device.submit();
|
|
51
|
+
|
|
52
|
+
const defaultCanvasContext = this.device.getDefaultCanvasContext();
|
|
53
|
+
const [sourceWidth, sourceHeight] = defaultCanvasContext.getDrawingBufferSize();
|
|
54
|
+
|
|
55
|
+
// Responsive layouts can transiently collapse presentation canvases to 0x0 during reflow.
|
|
56
|
+
// In that case WebGL has nothing meaningful to present, and drawImage() would throw when the
|
|
57
|
+
// offscreen source canvas has zero width or height.
|
|
58
|
+
if (
|
|
59
|
+
this.drawingBufferWidth === 0 ||
|
|
60
|
+
this.drawingBufferHeight === 0 ||
|
|
61
|
+
sourceWidth === 0 ||
|
|
62
|
+
sourceHeight === 0 ||
|
|
63
|
+
defaultCanvasContext.canvas.width === 0 ||
|
|
64
|
+
defaultCanvasContext.canvas.height === 0
|
|
65
|
+
) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (
|
|
70
|
+
sourceWidth !== this.drawingBufferWidth ||
|
|
71
|
+
sourceHeight !== this.drawingBufferHeight ||
|
|
72
|
+
defaultCanvasContext.canvas.width !== this.drawingBufferWidth ||
|
|
73
|
+
defaultCanvasContext.canvas.height !== this.drawingBufferHeight
|
|
74
|
+
) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`${this[Symbol.toStringTag]}(${this.id}): Default canvas context size ${sourceWidth}x${sourceHeight} does not match presentation size ${this.drawingBufferWidth}x${this.drawingBufferHeight}`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
this.context2d.clearRect(0, 0, this.drawingBufferWidth, this.drawingBufferHeight);
|
|
81
|
+
this.context2d.drawImage(defaultCanvasContext.canvas, 0, 0);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
protected override _configureDevice(): void {}
|
|
85
|
+
|
|
86
|
+
protected override _getCurrentFramebuffer(options?: {
|
|
87
|
+
depthStencilFormat?: TextureFormatDepthStencil | false;
|
|
88
|
+
}): Framebuffer {
|
|
89
|
+
const defaultCanvasContext = this.device.getDefaultCanvasContext();
|
|
90
|
+
defaultCanvasContext.setDrawingBufferSize(this.drawingBufferWidth, this.drawingBufferHeight);
|
|
91
|
+
return defaultCanvasContext.getCurrentFramebuffer(options);
|
|
92
|
+
}
|
|
93
|
+
}
|