@luma.gl/webgl 9.0.0-beta.5 → 9.0.0-beta.7
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 +128 -71
- package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/sampler-parameters.js +20 -19
- package/dist/adapter/converters/shader-formats.d.ts.map +1 -1
- package/dist/adapter/converters/shader-formats.js +40 -20
- package/dist/adapter/converters/texture-formats.d.ts +16 -11
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +224 -205
- package/dist/adapter/converters/vertex-formats.d.ts.map +1 -1
- package/dist/adapter/converters/vertex-formats.js +22 -21
- package/dist/adapter/device-helpers/webgl-device-features.d.ts +19 -5
- package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-features.js +89 -43
- package/dist/adapter/device-helpers/webgl-device-info.d.ts +2 -1
- package/dist/adapter/device-helpers/webgl-device-info.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-info.js +22 -19
- package/dist/adapter/device-helpers/webgl-device-limits.d.ts +33 -48
- package/dist/adapter/device-helpers/webgl-device-limits.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-limits.js +42 -87
- package/dist/adapter/helpers/decode-webgl-types.d.ts.map +1 -1
- package/dist/adapter/helpers/decode-webgl-types.js +47 -46
- package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
- package/dist/adapter/helpers/get-shader-layout.js +35 -34
- package/dist/adapter/helpers/parse-shader-compiler-log.d.ts.map +1 -1
- package/dist/adapter/helpers/parse-shader-compiler-log.js +3 -2
- package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
- package/dist/adapter/helpers/set-uniform.js +42 -41
- package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-topology-utils.js +40 -39
- package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
- package/dist/adapter/objects/constants-to-keys.js +2 -1
- package/dist/adapter/objects/webgl-renderbuffer.d.ts +2 -2
- package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-renderbuffer.js +30 -17
- package/dist/adapter/objects/webgl-resource.d.ts +2 -24
- package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-resource.js +6 -101
- package/dist/adapter/resources/webgl-buffer.d.ts +1 -1
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +16 -15
- package/dist/adapter/resources/webgl-command-buffer.d.ts +1 -1
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +32 -31
- package/dist/adapter/resources/webgl-command-encoder.d.ts +8 -3
- package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.js +4 -2
- package/dist/adapter/resources/webgl-external-texture.js +6 -5
- package/dist/adapter/resources/webgl-framebuffer.d.ts +6 -10
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +60 -53
- package/dist/adapter/resources/webgl-query-set.d.ts +44 -0
- package/dist/adapter/resources/webgl-query-set.d.ts.map +1 -0
- package/dist/adapter/resources/webgl-query-set.js +136 -0
- package/dist/adapter/resources/webgl-render-pass.d.ts +3 -1
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +20 -12
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +4 -5
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +52 -61
- 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 +5 -4
- package/dist/adapter/resources/webgl-shader.d.ts +3 -2
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +15 -9
- package/dist/adapter/resources/webgl-texture-view.d.ts +14 -0
- package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -0
- package/dist/adapter/resources/webgl-texture-view.js +18 -0
- package/dist/adapter/resources/webgl-texture.d.ts +6 -4
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +39 -32
- package/dist/adapter/resources/webgl-transform-feedback.d.ts +1 -1
- package/dist/adapter/resources/webgl-transform-feedback.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-transform-feedback.js +10 -10
- package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -3
- package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-vertex-array.js +10 -9
- package/dist/adapter/webgl-canvas-context.d.ts +2 -2
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js +3 -2
- package/dist/adapter/webgl-device.d.ts +35 -30
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +110 -109
- package/dist/classic/accessor.d.ts.map +1 -1
- package/dist/classic/accessor.js +8 -7
- package/dist/classic/clear.d.ts.map +1 -1
- package/dist/classic/clear.js +5 -4
- package/dist/classic/copy-and-blit.d.ts +1 -1
- package/dist/classic/copy-and-blit.d.ts.map +1 -1
- package/dist/classic/copy-and-blit.js +19 -19
- package/dist/classic/format-utils.d.ts.map +1 -1
- package/dist/classic/format-utils.js +16 -15
- package/dist/classic/typed-array-utils.d.ts.map +1 -1
- package/dist/classic/typed-array-utils.js +20 -19
- 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.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +7 -6
- package/dist/context/{context → helpers}/create-browser-context.d.ts.map +1 -1
- package/dist/context/{context → helpers}/create-browser-context.js +2 -1
- package/dist/context/{context/context-data.d.ts → helpers/webgl-context-data.d.ts} +2 -3
- package/dist/context/helpers/webgl-context-data.d.ts.map +1 -0
- package/dist/context/helpers/webgl-context-data.js +21 -0
- package/dist/context/helpers/webgl-extensions.d.ts +4 -0
- package/dist/context/helpers/webgl-extensions.d.ts.map +1 -0
- package/dist/context/helpers/webgl-extensions.js +10 -0
- package/dist/context/parameters/unified-parameter-api.d.ts +3 -4
- package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
- package/dist/context/parameters/unified-parameter-api.js +7 -11
- package/dist/context/parameters/webgl-parameter-tables.d.ts +12 -13
- package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.js +302 -295
- package/dist/context/state-tracker/deep-array-equal.d.ts.map +1 -1
- package/dist/context/state-tracker/deep-array-equal.js +2 -1
- package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
- package/dist/context/state-tracker/track-context-state.js +5 -4
- package/dist/context/state-tracker/with-parameters.d.ts +2 -3
- package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
- package/dist/context/state-tracker/with-parameters.js +6 -8
- package/dist/dist.dev.js +1635 -1387
- package/dist/index.cjs +1766 -1534
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +25 -25
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -23
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -1
- package/dist.min.js +6 -6
- package/package.json +4 -4
- package/src/adapter/converters/device-parameters.ts +114 -27
- package/src/adapter/converters/sampler-parameters.ts +12 -3
- package/src/adapter/converters/shader-formats.ts +47 -22
- package/src/adapter/converters/texture-formats.ts +138 -114
- package/src/adapter/converters/vertex-formats.ts +3 -3
- package/src/adapter/device-helpers/webgl-device-features.ts +102 -50
- package/src/adapter/device-helpers/webgl-device-info.ts +28 -19
- package/src/adapter/device-helpers/webgl-device-limits.ts +46 -150
- package/src/adapter/helpers/decode-webgl-types.ts +13 -7
- package/src/adapter/helpers/get-shader-layout.ts +4 -3
- package/src/adapter/helpers/parse-shader-compiler-log.ts +10 -6
- package/src/adapter/helpers/set-uniform.ts +2 -1
- package/src/adapter/helpers/webgl-topology-utils.ts +10 -3
- package/src/adapter/objects/constants-to-keys.ts +2 -1
- package/src/adapter/objects/webgl-renderbuffer.ts +36 -14
- package/src/adapter/objects/webgl-resource.ts +7 -125
- package/src/adapter/resources/webgl-buffer.ts +4 -3
- package/src/adapter/resources/webgl-command-buffer.ts +5 -5
- package/src/adapter/resources/webgl-command-encoder.ts +14 -11
- package/src/adapter/resources/webgl-external-texture.ts +6 -5
- package/src/adapter/resources/webgl-framebuffer.ts +61 -53
- package/src/adapter/resources/webgl-query-set.ts +171 -0
- package/src/adapter/resources/webgl-render-pass.ts +20 -11
- package/src/adapter/resources/webgl-render-pipeline.ts +54 -54
- package/src/adapter/resources/webgl-sampler.ts +2 -1
- package/src/adapter/resources/webgl-shader.ts +12 -5
- package/src/adapter/resources/webgl-texture-view.ts +28 -0
- package/src/adapter/resources/webgl-texture.ts +14 -3
- package/src/adapter/resources/webgl-transform-feedback.ts +2 -7
- package/src/adapter/resources/webgl-vertex-array.ts +4 -3
- package/src/adapter/webgl-canvas-context.ts +6 -4
- package/src/adapter/webgl-device.ts +116 -107
- package/src/classic/accessor.ts +5 -4
- package/src/classic/clear.ts +14 -8
- package/src/classic/copy-and-blit.ts +11 -4
- package/src/classic/format-utils.ts +2 -1
- package/src/classic/typed-array-utils.ts +3 -7
- package/src/context/debug/spector.ts +9 -6
- package/src/context/debug/webgl-developer-tools.ts +27 -14
- package/src/context/{context → helpers}/create-browser-context.ts +3 -2
- package/src/context/helpers/webgl-context-data.ts +31 -0
- package/src/context/helpers/webgl-extensions.ts +17 -0
- package/src/context/parameters/unified-parameter-api.ts +6 -17
- package/src/context/parameters/webgl-parameter-tables.ts +69 -32
- package/src/context/state-tracker/deep-array-equal.ts +2 -1
- package/src/context/state-tracker/track-context-state.ts +11 -6
- package/src/context/state-tracker/with-parameters.ts +8 -8
- package/src/index.ts +7 -6
- package/src/types.ts +2 -1
- package/dist/adapter/device-helpers/device-features.d.ts +0 -6
- package/dist/adapter/device-helpers/device-features.d.ts.map +0 -1
- package/dist/adapter/device-helpers/device-features.js +0 -65
- package/dist/adapter/device-helpers/device-limits.d.ts +0 -50
- package/dist/adapter/device-helpers/device-limits.d.ts.map +0 -1
- package/dist/adapter/device-helpers/device-limits.js +0 -92
- package/dist/adapter/device-helpers/get-device-info.d.ts +0 -4
- package/dist/adapter/device-helpers/get-device-info.d.ts.map +0 -1
- package/dist/adapter/device-helpers/get-device-info.js +0 -87
- package/dist/context/context/context-data.d.ts.map +0 -1
- package/dist/context/context/context-data.js +0 -33
- package/src/context/context/context-data.ts +0 -44
- /package/dist/context/{context → helpers}/create-browser-context.d.ts +0 -0
|
@@ -1,58 +1,57 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
import { Device, CanvasContext, log, uid, assert } from '@luma.gl/core';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import { readPixelsToArray, readPixelsToBuffer } from
|
|
25
|
-
import { setGLParameters, getGLParameters } from
|
|
26
|
-
import { withGLParameters } from
|
|
27
|
-
import { clear } from
|
|
5
|
+
import { popContextState, pushContextState, trackContextState } from "../context/state-tracker/track-context-state.js";
|
|
6
|
+
import { createBrowserContext } from "../context/helpers/create-browser-context.js";
|
|
7
|
+
import { getDeviceInfo } from "./device-helpers/webgl-device-info.js";
|
|
8
|
+
import { WebGLDeviceFeatures } from "./device-helpers/webgl-device-features.js";
|
|
9
|
+
import { WebGLDeviceLimits } from "./device-helpers/webgl-device-limits.js";
|
|
10
|
+
import { WebGLCanvasContext } from "./webgl-canvas-context.js";
|
|
11
|
+
import { loadSpectorJS, initializeSpectorJS } from "../context/debug/spector.js";
|
|
12
|
+
import { loadWebGLDeveloperTools, makeDebugContext } from "../context/debug/webgl-developer-tools.js";
|
|
13
|
+
import { isTextureFormatSupported, isTextureFormatRenderable, isTextureFormatFilterable } from "./converters/texture-formats.js";
|
|
14
|
+
import { WEBGLBuffer } from "./resources/webgl-buffer.js";
|
|
15
|
+
import { WEBGLShader } from "./resources/webgl-shader.js";
|
|
16
|
+
import { WEBGLSampler } from "./resources/webgl-sampler.js";
|
|
17
|
+
import { WEBGLTexture } from "./resources/webgl-texture.js";
|
|
18
|
+
import { WEBGLFramebuffer } from "./resources/webgl-framebuffer.js";
|
|
19
|
+
import { WEBGLRenderPass } from "./resources/webgl-render-pass.js";
|
|
20
|
+
import { WEBGLRenderPipeline } from "./resources/webgl-render-pipeline.js";
|
|
21
|
+
import { WEBGLCommandEncoder } from "./resources/webgl-command-encoder.js";
|
|
22
|
+
import { WEBGLVertexArray } from "./resources/webgl-vertex-array.js";
|
|
23
|
+
import { WEBGLTransformFeedback } from "./resources/webgl-transform-feedback.js";
|
|
24
|
+
import { WEBGLQuerySet } from "./resources/webgl-query-set.js";
|
|
25
|
+
import { readPixelsToArray, readPixelsToBuffer } from "../classic/copy-and-blit.js";
|
|
26
|
+
import { setGLParameters, getGLParameters } from "../context/parameters/unified-parameter-api.js";
|
|
27
|
+
import { withGLParameters } from "../context/state-tracker/with-parameters.js";
|
|
28
|
+
import { clear } from "../classic/clear.js";
|
|
29
|
+
import { getWebGLExtension } from "../context/helpers/webgl-extensions.js";
|
|
28
30
|
const LOG_LEVEL = 1;
|
|
29
31
|
/** WebGPU style Device API for a WebGL context */
|
|
30
32
|
export class WebGLDevice extends Device {
|
|
31
33
|
//
|
|
32
34
|
// Public `Device` API
|
|
33
35
|
//
|
|
36
|
+
/** type of this device */
|
|
34
37
|
static type = 'webgl';
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
/** type of this device */
|
|
39
|
+
type = 'webgl';
|
|
40
|
+
/** The underlying WebGL context */
|
|
41
|
+
handle;
|
|
42
|
+
features;
|
|
43
|
+
limits;
|
|
38
44
|
info;
|
|
39
45
|
canvasContext;
|
|
40
|
-
handle;
|
|
41
|
-
get features() {
|
|
42
|
-
this._features = this._features || getDeviceFeatures(this.gl);
|
|
43
|
-
return this._features;
|
|
44
|
-
}
|
|
45
|
-
get limits() {
|
|
46
|
-
this._limits = this._limits || getDeviceLimits(this.gl);
|
|
47
|
-
return this._limits;
|
|
48
|
-
}
|
|
49
46
|
lost;
|
|
50
47
|
_resolveContextLost;
|
|
51
|
-
_features;
|
|
52
|
-
_limits;
|
|
53
48
|
//
|
|
54
49
|
// Static methods, expected to be present by `luma.createDevice()`
|
|
55
50
|
//
|
|
51
|
+
/** Check if WebGL 2 is available */
|
|
52
|
+
static isSupported() {
|
|
53
|
+
return typeof WebGL2RenderingContext !== 'undefined';
|
|
54
|
+
}
|
|
56
55
|
/**
|
|
57
56
|
* Get a device instance from a GL context
|
|
58
57
|
* Creates and instruments the device if not already created
|
|
@@ -75,29 +74,37 @@ export class WebGLDevice extends Device {
|
|
|
75
74
|
}
|
|
76
75
|
static async create(props = {}) {
|
|
77
76
|
log.groupCollapsed(LOG_LEVEL, 'WebGLDevice created')();
|
|
78
|
-
|
|
79
|
-
// to avoid setting page onload callback unless necessary
|
|
80
|
-
if (typeof props.canvas === 'string') {
|
|
81
|
-
await CanvasContext.pageLoaded;
|
|
82
|
-
}
|
|
77
|
+
const promises = [];
|
|
83
78
|
// Load webgl and spector debug scripts from CDN if requested
|
|
84
|
-
if (
|
|
85
|
-
|
|
79
|
+
if (props.debug) {
|
|
80
|
+
promises.push(loadWebGLDeveloperTools());
|
|
81
|
+
}
|
|
82
|
+
if (props.spector) {
|
|
83
|
+
promises.push(loadSpectorJS());
|
|
84
|
+
}
|
|
85
|
+
// Wait for page to load: if canvas is a string we need to query the DOM for the canvas element.
|
|
86
|
+
// We only wait when props.canvas is string to avoids setting the global page onload callback unless necessary.
|
|
87
|
+
if (typeof props.canvas === 'string') {
|
|
88
|
+
promises.push(CanvasContext.pageLoaded);
|
|
86
89
|
}
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
// Wait for all the loads to settle before creating the context.
|
|
91
|
+
// The Device.create() functions are async, so in contrast to the constructor, we can `await` here.
|
|
92
|
+
const results = await Promise.allSettled(promises);
|
|
93
|
+
for (const result of results) {
|
|
94
|
+
if (result.status === 'rejected') {
|
|
95
|
+
log.error(`Failed to initialize debug libraries ${result.reason}`)();
|
|
96
|
+
}
|
|
91
97
|
}
|
|
92
98
|
log.probe(LOG_LEVEL + 1, 'DOM is loaded')();
|
|
93
99
|
// @ts-expect-error
|
|
94
|
-
if (props.gl
|
|
100
|
+
if (props.gl?.device) {
|
|
101
|
+
log.warn('reattaching existing device')();
|
|
95
102
|
return WebGLDevice.attach(props.gl);
|
|
96
103
|
}
|
|
97
104
|
const device = new WebGLDevice(props);
|
|
98
105
|
// Log some debug info about the newly created context
|
|
99
106
|
const message = `\
|
|
100
|
-
Created ${device.
|
|
107
|
+
Created ${device.type}${device.debug ? ' debug' : ''} context: \
|
|
101
108
|
${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
|
|
102
109
|
log.probe(LOG_LEVEL, message)();
|
|
103
110
|
log.table(LOG_LEVEL, device.info)();
|
|
@@ -116,33 +123,34 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
116
123
|
throw new Error(`WebGL context already attached to device ${device.id}`);
|
|
117
124
|
}
|
|
118
125
|
// Create and instrument context
|
|
119
|
-
const canvas = props.canvas || props.
|
|
126
|
+
const canvas = props.gl?.canvas || props.canvas;
|
|
120
127
|
this.canvasContext = new WebGLCanvasContext(this, { ...props, canvas });
|
|
121
128
|
this.lost = new Promise(resolve => {
|
|
122
129
|
this._resolveContextLost = resolve;
|
|
123
130
|
});
|
|
124
|
-
const onContextLost = (event) => this._resolveContextLost?.({
|
|
125
|
-
reason: 'destroyed',
|
|
126
|
-
message: 'Computer entered sleep mode, or too many apps or browser tabs are using the GPU.'
|
|
127
|
-
});
|
|
128
131
|
let gl = props.gl || null;
|
|
129
|
-
gl
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
gl ||= createBrowserContext(this.canvasContext.canvas, {
|
|
133
|
+
...props,
|
|
134
|
+
onContextLost: (event) => this._resolveContextLost?.({
|
|
135
|
+
reason: 'destroyed',
|
|
136
|
+
message: 'Entered sleep mode, or too many apps or browser tabs are using the GPU.'
|
|
137
|
+
})
|
|
138
|
+
});
|
|
134
139
|
if (!gl) {
|
|
135
140
|
throw new Error('WebGL context creation failed');
|
|
136
141
|
}
|
|
137
142
|
this.handle = gl;
|
|
138
|
-
this.gl =
|
|
139
|
-
this.
|
|
143
|
+
this.gl = gl;
|
|
144
|
+
this.gl.device = this; // Update GL context: Link webgl context back to device
|
|
145
|
+
this.gl._version = 2; // Update GL context: Store WebGL version field on gl context (HACK to identify debug contexts)
|
|
140
146
|
// luma Device fields
|
|
141
|
-
this.info = getDeviceInfo(this.gl);
|
|
142
|
-
|
|
143
|
-
this.
|
|
144
|
-
|
|
145
|
-
|
|
147
|
+
this.info = getDeviceInfo(this.gl, this._extensions);
|
|
148
|
+
this.limits = new WebGLDeviceLimits(this.gl);
|
|
149
|
+
this.features = new WebGLDeviceFeatures(this.gl, this._extensions, this.props.disabledFeatures);
|
|
150
|
+
if (this.props.initalizeFeatures) {
|
|
151
|
+
this.features.initializeFeatures();
|
|
152
|
+
}
|
|
153
|
+
this.canvasContext.resize();
|
|
146
154
|
// Install context state tracking
|
|
147
155
|
// @ts-expect-error - hidden parameters
|
|
148
156
|
const { enable = true, copyState = false } = props;
|
|
@@ -152,24 +160,21 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
152
160
|
log: (...args) => log.log(1, ...args)()
|
|
153
161
|
});
|
|
154
162
|
// DEBUG contexts: Add debug instrumentation to the context, force log level to at least 1
|
|
155
|
-
if (
|
|
163
|
+
if (props.debug) {
|
|
156
164
|
this.gl = makeDebugContext(this.gl, { ...props, throwOnError: true });
|
|
157
165
|
this.debug = true;
|
|
158
166
|
log.level = Math.max(log.level, 1);
|
|
159
167
|
log.warn('WebGL debug mode activated. Performance reduced.')();
|
|
160
168
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const canvas = this.handle.canvas || props.canvas;
|
|
164
|
-
this.spector = initializeSpectorJS({ ...this.props, canvas });
|
|
169
|
+
if (props.spector) {
|
|
170
|
+
this.spectorJS = initializeSpectorJS({ ...this.props, canvas: this.handle.canvas });
|
|
165
171
|
}
|
|
166
172
|
}
|
|
167
173
|
/**
|
|
168
174
|
* Destroys the context
|
|
169
|
-
* @note Has no effect for browser contexts, there is no browser API for destroying contexts
|
|
175
|
+
* @note Has no effect for WebGL browser contexts, there is no browser API for destroying contexts
|
|
170
176
|
*/
|
|
171
|
-
destroy() {
|
|
172
|
-
}
|
|
177
|
+
destroy() { }
|
|
173
178
|
get isLost() {
|
|
174
179
|
return this.gl.isContextLost();
|
|
175
180
|
}
|
|
@@ -177,13 +182,13 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
177
182
|
return [this.gl.drawingBufferWidth, this.gl.drawingBufferHeight];
|
|
178
183
|
}
|
|
179
184
|
isTextureFormatSupported(format) {
|
|
180
|
-
return isTextureFormatSupported(this.gl, format);
|
|
185
|
+
return isTextureFormatSupported(this.gl, format, this._extensions);
|
|
181
186
|
}
|
|
182
187
|
isTextureFormatFilterable(format) {
|
|
183
|
-
return isTextureFormatFilterable(this.gl, format);
|
|
188
|
+
return isTextureFormatFilterable(this.gl, format, this._extensions);
|
|
184
189
|
}
|
|
185
190
|
isTextureFormatRenderable(format) {
|
|
186
|
-
return isTextureFormatRenderable(this.gl, format);
|
|
191
|
+
return isTextureFormatRenderable(this.gl, format, this._extensions);
|
|
187
192
|
}
|
|
188
193
|
// IMPLEMENTATION OF ABSTRACT DEVICE
|
|
189
194
|
createCanvasContext(props) {
|
|
@@ -208,12 +213,18 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
208
213
|
createFramebuffer(props) {
|
|
209
214
|
return new WEBGLFramebuffer(this, props);
|
|
210
215
|
}
|
|
211
|
-
createRenderPipeline(props) {
|
|
212
|
-
return new WEBGLRenderPipeline(this, props);
|
|
213
|
-
}
|
|
214
216
|
createVertexArray(props) {
|
|
215
217
|
return new WEBGLVertexArray(this, props);
|
|
216
218
|
}
|
|
219
|
+
createTransformFeedback(props) {
|
|
220
|
+
return new WEBGLTransformFeedback(this, props);
|
|
221
|
+
}
|
|
222
|
+
createQuerySet(props) {
|
|
223
|
+
return new WEBGLQuerySet(this, props);
|
|
224
|
+
}
|
|
225
|
+
createRenderPipeline(props) {
|
|
226
|
+
return new WEBGLRenderPipeline(this, props);
|
|
227
|
+
}
|
|
217
228
|
beginRenderPass(props) {
|
|
218
229
|
return new WEBGLRenderPass(this, props);
|
|
219
230
|
}
|
|
@@ -223,18 +234,7 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
223
234
|
beginComputePass(props) {
|
|
224
235
|
throw new Error('ComputePass not supported in WebGL');
|
|
225
236
|
}
|
|
226
|
-
createTransformFeedback(props) {
|
|
227
|
-
return new WEBGLTransformFeedback(this, props);
|
|
228
|
-
}
|
|
229
237
|
renderPass = null;
|
|
230
|
-
getDefaultRenderPass() {
|
|
231
|
-
this.renderPass =
|
|
232
|
-
this.renderPass ||
|
|
233
|
-
this.beginRenderPass({
|
|
234
|
-
framebuffer: this.canvasContext.getCurrentFramebuffer()
|
|
235
|
-
});
|
|
236
|
-
return this.renderPass;
|
|
237
|
-
}
|
|
238
238
|
createCommandEncoder(props) {
|
|
239
239
|
return new WEBGLCommandEncoder(this, props);
|
|
240
240
|
}
|
|
@@ -250,7 +250,7 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
250
250
|
}
|
|
251
251
|
//
|
|
252
252
|
// TEMPORARY HACKS - will be removed in v9.1
|
|
253
|
-
//
|
|
253
|
+
//
|
|
254
254
|
/** @deprecated - should use command encoder */
|
|
255
255
|
readPixelsToArrayWebGL(source, options) {
|
|
256
256
|
return readPixelsToArray(source, options);
|
|
@@ -260,13 +260,13 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
260
260
|
return readPixelsToBuffer(source, options);
|
|
261
261
|
}
|
|
262
262
|
setParametersWebGL(parameters) {
|
|
263
|
-
setGLParameters(this, parameters);
|
|
263
|
+
setGLParameters(this.gl, parameters);
|
|
264
264
|
}
|
|
265
265
|
getParametersWebGL(parameters) {
|
|
266
|
-
return getGLParameters(this, parameters);
|
|
266
|
+
return getGLParameters(this.gl, parameters);
|
|
267
267
|
}
|
|
268
268
|
withParametersWebGL(parameters, func) {
|
|
269
|
-
withGLParameters(this, parameters, func);
|
|
269
|
+
withGLParameters(this.gl, parameters, func);
|
|
270
270
|
}
|
|
271
271
|
clearWebGL(options) {
|
|
272
272
|
clear(this, options);
|
|
@@ -283,20 +283,15 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
283
283
|
_extensions = {};
|
|
284
284
|
_polyfilled = false;
|
|
285
285
|
/** Instance of Spector.js (if initialized) */
|
|
286
|
-
|
|
287
|
-
_webglLimits;
|
|
288
|
-
/** Return WebGL specific limits */
|
|
289
|
-
get webglLimits() {
|
|
290
|
-
this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);
|
|
291
|
-
return this._webglLimits;
|
|
292
|
-
}
|
|
286
|
+
spectorJS;
|
|
293
287
|
/**
|
|
294
288
|
* Triggers device (or WebGL context) loss.
|
|
295
289
|
* @note primarily intended for testing how application reacts to device loss
|
|
296
290
|
*/
|
|
297
291
|
loseDevice() {
|
|
298
292
|
let deviceLossTriggered = false;
|
|
299
|
-
const
|
|
293
|
+
const extensions = this.getExtension('WEBGL_lose_context');
|
|
294
|
+
const ext = extensions.WEBGL_lose_context;
|
|
300
295
|
if (ext) {
|
|
301
296
|
deviceLossTriggered = true;
|
|
302
297
|
ext.loseContext();
|
|
@@ -351,11 +346,12 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
351
346
|
* so they need to be updated before every render
|
|
352
347
|
* @todo - remember/cache values to avoid setting them unnecessarily?
|
|
353
348
|
*/
|
|
354
|
-
|
|
355
|
-
|
|
349
|
+
setConstantAttributeWebGL(location, constant) {
|
|
350
|
+
const maxVertexAttributes = this.limits.maxVertexAttributes;
|
|
351
|
+
this._constants = this._constants || new Array(maxVertexAttributes).fill(null);
|
|
356
352
|
const currentConstant = this._constants[location];
|
|
357
353
|
if (currentConstant && compareConstantArrayValues(currentConstant, constant)) {
|
|
358
|
-
log.info(1, `
|
|
354
|
+
log.info(1, `setConstantAttributeWebGL(${location}) could have been skipped, value unchanged`)();
|
|
359
355
|
}
|
|
360
356
|
this._constants[location] = constant;
|
|
361
357
|
switch (constant.constructor) {
|
|
@@ -372,6 +368,11 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
372
368
|
assert(false);
|
|
373
369
|
}
|
|
374
370
|
}
|
|
371
|
+
/** Ensure extensions are only requested once */
|
|
372
|
+
getExtension(name) {
|
|
373
|
+
getWebGLExtension(this.gl, name, this._extensions);
|
|
374
|
+
return this._extensions;
|
|
375
|
+
}
|
|
375
376
|
}
|
|
376
377
|
/** Check if supplied parameter is a WebGL2RenderingContext */
|
|
377
378
|
function isWebGL(gl) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accessor.d.ts","sourceRoot":"","sources":["../../src/classic/accessor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"accessor.d.ts","sourceRoot":"","sources":["../../src/classic/accessor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAqB,MAAM,EAAE,cAAc,EAAC,MAAM,eAAe,CAAC;AACzE,OAAO,EAAC,EAAE,EAAC,MAAM,oBAAoB,CAAC;AAGtC,QAAA,MAAM,uBAAuB;;;;;;;;CAQ5B,CAAC;AASF,qBAAa,QAAS,YAAW,cAAc;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc,GAAG,MAAM;IAOtE,MAAM,CAAC,iBAAiB,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM;IAY1D,MAAM,CAAC,OAAO,CAAC,GAAG,SAAS,EAAE,cAAc,EAAE,GAAG,QAAQ;gBAI5C,GAAG,SAAS,EAAE,cAAc,EAAE;IAK1C,QAAQ,IAAI,MAAM;IAOlB,IAAI,iBAAiB,IAAI,MAAM,CAE9B;IAED,IAAI,gBAAgB,IAAI,MAAM,CAE7B;IAKD,OAAO,CAAC,KAAK,GAAE,cAAmB,GAAG,IAAI;CA6E1C;AAGD,OAAO,EAAC,uBAAuB,EAAC,CAAC"}
|
package/dist/classic/accessor.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
import { assert, checkProps } from '@luma.gl/core';
|
|
4
5
|
import { GL } from '@luma.gl/constants';
|
|
5
|
-
import { getTypedArrayFromGLType } from
|
|
6
|
+
import { getTypedArrayFromGLType } from "./typed-array-utils.js";
|
|
6
7
|
const DEFAULT_ACCESSOR_VALUES = {
|
|
7
8
|
offset: 0,
|
|
8
9
|
stride: 0,
|
|
9
|
-
type:
|
|
10
|
+
type: 5126,
|
|
10
11
|
size: 1,
|
|
11
12
|
divisor: 0,
|
|
12
13
|
normalized: false,
|
|
@@ -31,14 +32,14 @@ export class Accessor {
|
|
|
31
32
|
static getBytesPerElement(accessor) {
|
|
32
33
|
// TODO: using `FLOAT` when type is not specified,
|
|
33
34
|
// ensure this assumption is valid or force API to specify type.
|
|
34
|
-
const ArrayType = getTypedArrayFromGLType(accessor.type ||
|
|
35
|
+
const ArrayType = getTypedArrayFromGLType(accessor.type || 5126);
|
|
35
36
|
return ArrayType.BYTES_PER_ELEMENT;
|
|
36
37
|
}
|
|
37
38
|
static getBytesPerVertex(accessor) {
|
|
38
39
|
assert(accessor.size);
|
|
39
40
|
// TODO: using `FLOAT` when type is not specified,
|
|
40
41
|
// ensure this assumption is valid or force API to specify type.
|
|
41
|
-
const ArrayType = getTypedArrayFromGLType(accessor.type ||
|
|
42
|
+
const ArrayType = getTypedArrayFromGLType(accessor.type || 5126);
|
|
42
43
|
return ArrayType.BYTES_PER_ELEMENT * accessor.size;
|
|
43
44
|
}
|
|
44
45
|
// Combines (merges) a list of accessors. On top of default values
|
|
@@ -49,7 +50,7 @@ export class Accessor {
|
|
|
49
50
|
return new Accessor(...[DEFAULT_ACCESSOR_VALUES, ...accessors]); // Default values
|
|
50
51
|
}
|
|
51
52
|
constructor(...accessors) {
|
|
52
|
-
accessors.forEach(
|
|
53
|
+
accessors.forEach(accessor => this._assign(accessor)); // Merge in sequence
|
|
53
54
|
Object.freeze(this);
|
|
54
55
|
}
|
|
55
56
|
toString() {
|
|
@@ -70,7 +71,7 @@ export class Accessor {
|
|
|
70
71
|
if (props.type !== undefined) {
|
|
71
72
|
this.type = props.type;
|
|
72
73
|
// Auto-deduce integer type?
|
|
73
|
-
if (props.type ===
|
|
74
|
+
if (props.type === 5124 || props.type === 5125) {
|
|
74
75
|
this.integer = true;
|
|
75
76
|
}
|
|
76
77
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clear.d.ts","sourceRoot":"","sources":["../../src/classic/clear.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clear.d.ts","sourceRoot":"","sources":["../../src/classic/clear.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAE,WAAW,EAAS,MAAM,eAAe,CAAC;AAiB1D;;;GAGG;AACH,wBAAgB,KAAK,CACnB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IAAC,WAAW,CAAC,EAAE,WAAW,CAAC;IAAC,KAAK,CAAC,EAAE,GAAG,CAAC;IAAC,KAAK,CAAC,EAAE,GAAG,CAAC;IAAC,OAAO,CAAC,EAAE,GAAG,CAAA;CAAC,GAC7E,IAAI,CAsCN;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IAAC,WAAW,CAAC,EAAE,WAAW,CAAC;IAAC,MAAM,CAAC,EAAE,GAAG,CAAC;IAAC,UAAU,CAAC,EAAE,GAAG,CAAC;IAAC,KAAK,CAAC,EAAE,GAAG,CAAA;CAAC,QA2CnF"}
|
package/dist/classic/clear.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
import { assert } from '@luma.gl/core';
|
|
4
|
-
import { withGLParameters } from
|
|
5
|
+
import { withGLParameters } from "../context/state-tracker/with-parameters.js";
|
|
5
6
|
// Should collapse during minification
|
|
6
7
|
const GL_DEPTH_BUFFER_BIT = 0x00000100;
|
|
7
8
|
const GL_STENCIL_BUFFER_BIT = 0x00000400;
|
|
@@ -43,8 +44,8 @@ export function clear(device, options) {
|
|
|
43
44
|
}
|
|
44
45
|
assert(clearFlags !== 0, ERR_ARGUMENTS);
|
|
45
46
|
// Temporarily set any clear "colors" and call clear
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
const gl = device.gl;
|
|
48
|
+
withGLParameters(gl, parameters, () => {
|
|
48
49
|
gl.clear(clearFlags);
|
|
49
50
|
});
|
|
50
51
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Buffer, Texture, Framebuffer, FramebufferProps } from '@luma.gl/core';
|
|
2
2
|
import { GL } from '@luma.gl/constants';
|
|
3
|
-
import { WEBGLBuffer } from
|
|
3
|
+
import { WEBGLBuffer } from "../adapter/resources/webgl-buffer.js";
|
|
4
4
|
/**
|
|
5
5
|
* Copies data from a type or a Texture object into ArrayBuffer object.
|
|
6
6
|
* App can provide targetPixelArray or have it auto allocated by this method
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copy-and-blit.d.ts","sourceRoot":"","sources":["../../src/classic/copy-and-blit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"copy-and-blit.d.ts","sourceRoot":"","sources":["../../src/classic/copy-and-blit.ts"],"names":[],"mappings":"AAIA,OAAO,EAAS,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAC,MAAM,eAAe,CAAC;AACrF,OAAO,EAAC,EAAE,EAAC,MAAM,oBAAoB,CAAC;AAMtC,OAAO,EAAC,WAAW,EAAC,6CAA0C;AAE9D;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,WAAW,GAAG,OAAO,EAC7B,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,YAAY,CAAC;IAEjD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACA,UAAU,GAAG,WAAW,GAAG,YAAY,CAiDzC;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,WAAW,GAAG,OAAO,EAC7B,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACA,WAAW,CA+Cb;AAED;;;GAGG;AAEH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,WAAW,GAAG,OAAO,EAC7B,MAAM,EAAE,OAAO,GAAG,EAAE,EACpB,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GACA,OAAO,CA+FT;AAYD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,gBAAgB,GAAG,WAAW,CAUrF"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
import { assert, Texture, Framebuffer } from '@luma.gl/core';
|
|
4
5
|
import { GL } from '@luma.gl/constants';
|
|
5
|
-
import { getGLTypeFromTypedArray, getTypedArrayFromGLType } from
|
|
6
|
-
import { glFormatToComponents, glTypeToBytes } from
|
|
6
|
+
import { getGLTypeFromTypedArray, getTypedArrayFromGLType } from "./typed-array-utils.js";
|
|
7
|
+
import { glFormatToComponents, glTypeToBytes } from "./format-utils.js";
|
|
7
8
|
/**
|
|
8
9
|
* Copies data from a type or a Texture object into ArrayBuffer object.
|
|
9
10
|
* App can provide targetPixelArray or have it auto allocated by this method
|
|
@@ -16,7 +17,7 @@ import { glFormatToComponents, glTypeToBytes } from './format-utils';
|
|
|
16
17
|
* @returns pixel array,
|
|
17
18
|
*/
|
|
18
19
|
export function readPixelsToArray(source, options) {
|
|
19
|
-
const { sourceX = 0, sourceY = 0, sourceFormat =
|
|
20
|
+
const { sourceX = 0, sourceY = 0, sourceFormat = 6408, sourceAttachment = 36064 // TODO - support gl.readBuffer
|
|
20
21
|
} = options || {};
|
|
21
22
|
let { target = null,
|
|
22
23
|
// following parameters are auto deduced if not provided
|
|
@@ -30,21 +31,20 @@ export function readPixelsToArray(source, options) {
|
|
|
30
31
|
// if (sourceAttachment === GL.COLOR_ATTACHMENT0 && handle === null) {
|
|
31
32
|
// sourceAttachment = GL.FRONT;
|
|
32
33
|
// }
|
|
33
|
-
const attachment = sourceAttachment -
|
|
34
|
+
const attachment = sourceAttachment - 36064;
|
|
34
35
|
// assert(attachments[sourceAttachment]);
|
|
35
36
|
// Deduce the type from color attachment if not provided.
|
|
36
37
|
sourceType =
|
|
37
38
|
sourceType ||
|
|
38
|
-
framebuffer.colorAttachments[attachment]?.type ||
|
|
39
|
-
GL.UNSIGNED_BYTE;
|
|
39
|
+
framebuffer.colorAttachments[attachment]?.texture?.type || 5121;
|
|
40
40
|
// Deduce type and allocated pixelArray if needed
|
|
41
41
|
target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
|
|
42
42
|
// Pixel array available, if necessary, deduce type from it.
|
|
43
43
|
sourceType = sourceType || getGLTypeFromTypedArray(target);
|
|
44
|
-
const prevHandle = gl.bindFramebuffer(
|
|
44
|
+
const prevHandle = gl.bindFramebuffer(36160, handle);
|
|
45
45
|
gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
|
|
46
46
|
// @ts-expect-error
|
|
47
|
-
gl.bindFramebuffer(
|
|
47
|
+
gl.bindFramebuffer(36160, prevHandle || null);
|
|
48
48
|
if (deleteFramebuffer) {
|
|
49
49
|
framebuffer.destroy();
|
|
50
50
|
}
|
|
@@ -58,7 +58,7 @@ export function readPixelsToArray(source, options) {
|
|
|
58
58
|
* @param options
|
|
59
59
|
*/
|
|
60
60
|
export function readPixelsToBuffer(source, options) {
|
|
61
|
-
const { target, sourceX = 0, sourceY = 0, sourceFormat =
|
|
61
|
+
const { target, sourceX = 0, sourceY = 0, sourceFormat = 6408, targetByteOffset = 0 } = options || {};
|
|
62
62
|
// following parameters are auto deduced if not provided
|
|
63
63
|
let { sourceWidth, sourceHeight, sourceType } = options || {};
|
|
64
64
|
const { framebuffer, deleteFramebuffer } = getFramebuffer(source);
|
|
@@ -68,7 +68,7 @@ export function readPixelsToBuffer(source, options) {
|
|
|
68
68
|
// Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature
|
|
69
69
|
const webglFramebuffer = framebuffer;
|
|
70
70
|
// deduce type if not available.
|
|
71
|
-
sourceType = sourceType ||
|
|
71
|
+
sourceType = sourceType || 5121;
|
|
72
72
|
let webglBufferTarget = target;
|
|
73
73
|
if (!webglBufferTarget) {
|
|
74
74
|
// Create new buffer with enough size
|
|
@@ -101,7 +101,7 @@ export function readPixelsToBuffer(source, options) {
|
|
|
101
101
|
export function copyToTexture(source, target, options) {
|
|
102
102
|
const { sourceX = 0, sourceY = 0,
|
|
103
103
|
// attachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer
|
|
104
|
-
targetMipmaplevel = 0, targetInternalFormat =
|
|
104
|
+
targetMipmaplevel = 0, targetInternalFormat = 6408 } = options || {};
|
|
105
105
|
let { targetX, targetY, targetZ, width, // defaults to target width
|
|
106
106
|
height // defaults to target height
|
|
107
107
|
} = options || {};
|
|
@@ -115,7 +115,7 @@ export function copyToTexture(source, target, options) {
|
|
|
115
115
|
targetX = targetX || 0;
|
|
116
116
|
targetY = targetY || 0;
|
|
117
117
|
targetZ = targetZ || 0;
|
|
118
|
-
const prevHandle = device.gl.bindFramebuffer(
|
|
118
|
+
const prevHandle = device.gl.bindFramebuffer(36160, handle);
|
|
119
119
|
// TODO - support gl.readBuffer (WebGL2 only)
|
|
120
120
|
// const prevBuffer = gl.readBuffer(attachment);
|
|
121
121
|
assert(target);
|
|
@@ -136,12 +136,12 @@ export function copyToTexture(source, target, options) {
|
|
|
136
136
|
}
|
|
137
137
|
else {
|
|
138
138
|
switch (textureTarget) {
|
|
139
|
-
case
|
|
140
|
-
case
|
|
139
|
+
case 3553:
|
|
140
|
+
case 34067:
|
|
141
141
|
device.gl.copyTexSubImage2D(textureTarget, targetMipmaplevel, targetX, targetY, sourceX, sourceY, width, height);
|
|
142
142
|
break;
|
|
143
|
-
case
|
|
144
|
-
case
|
|
143
|
+
case 35866:
|
|
144
|
+
case 32879:
|
|
145
145
|
device.gl.copyTexSubImage3D(textureTarget, targetMipmaplevel, targetX, targetY, targetZ, sourceX, sourceY, width, height);
|
|
146
146
|
break;
|
|
147
147
|
default:
|
|
@@ -151,7 +151,7 @@ export function copyToTexture(source, target, options) {
|
|
|
151
151
|
texture.unbind();
|
|
152
152
|
}
|
|
153
153
|
// @ts-expect-error
|
|
154
|
-
device.gl.bindFramebuffer(
|
|
154
|
+
device.gl.bindFramebuffer(36160, prevHandle || null);
|
|
155
155
|
if (deleteFramebuffer) {
|
|
156
156
|
framebuffer.destroy();
|
|
157
157
|
}
|
|
@@ -183,7 +183,7 @@ function getPixelArray(pixelArray, type, format, width, height) {
|
|
|
183
183
|
return pixelArray;
|
|
184
184
|
}
|
|
185
185
|
// Allocate pixel array if not already available, using supplied type
|
|
186
|
-
type = type ||
|
|
186
|
+
type = type || 5121;
|
|
187
187
|
const ArrayType = getTypedArrayFromGLType(type, { clamped: false });
|
|
188
188
|
const components = glFormatToComponents(format);
|
|
189
189
|
// TODO - check for composite type (components = 1).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-utils.d.ts","sourceRoot":"","sources":["../../src/classic/format-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"format-utils.d.ts","sourceRoot":"","sources":["../../src/classic/format-utils.ts"],"names":[],"mappings":"AAQA,wBAAgB,oBAAoB,CAAC,MAAM,KAAA,qBAoB1C;AAGD,wBAAgB,aAAa,CAAC,IAAI,KAAA,iBAejC"}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
import { assert } from '@luma.gl/core';
|
|
4
5
|
import { GL } from '@luma.gl/constants';
|
|
5
6
|
// Returns number of components in a specific readPixels WebGL format
|
|
6
7
|
export function glFormatToComponents(format) {
|
|
7
8
|
switch (format) {
|
|
8
|
-
case
|
|
9
|
-
case
|
|
10
|
-
case
|
|
9
|
+
case 6406:
|
|
10
|
+
case 33326:
|
|
11
|
+
case 6403:
|
|
11
12
|
return 1;
|
|
12
|
-
case
|
|
13
|
-
case
|
|
13
|
+
case 33328:
|
|
14
|
+
case 33319:
|
|
14
15
|
return 2;
|
|
15
|
-
case
|
|
16
|
-
case
|
|
16
|
+
case 6407:
|
|
17
|
+
case 34837:
|
|
17
18
|
return 3;
|
|
18
|
-
case
|
|
19
|
-
case
|
|
19
|
+
case 6408:
|
|
20
|
+
case 34836:
|
|
20
21
|
return 4;
|
|
21
22
|
// TODO: Add support for additional WebGL2 formats
|
|
22
23
|
default:
|
|
@@ -27,13 +28,13 @@ export function glFormatToComponents(format) {
|
|
|
27
28
|
// Return byte count for given readPixels WebGL type
|
|
28
29
|
export function glTypeToBytes(type) {
|
|
29
30
|
switch (type) {
|
|
30
|
-
case
|
|
31
|
+
case 5121:
|
|
31
32
|
return 1;
|
|
32
|
-
case
|
|
33
|
-
case
|
|
34
|
-
case
|
|
33
|
+
case 33635:
|
|
34
|
+
case 32819:
|
|
35
|
+
case 32820:
|
|
35
36
|
return 2;
|
|
36
|
-
case
|
|
37
|
+
case 5126:
|
|
37
38
|
return 4;
|
|
38
39
|
// TODO: Add support for additional WebGL2 types
|
|
39
40
|
default:
|