@luma.gl/webgl 9.1.0-alpha.1 → 9.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/device-parameters.js +18 -11
- package/dist/adapter/converters/texture-formats.d.ts +1 -1
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +9 -16
- package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-features.js +0 -1
- package/dist/adapter/helpers/webgl-texture-utils.d.ts +4 -4
- package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.js +11 -9
- package/dist/adapter/resources/webgl-framebuffer.js +1 -1
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +17 -4
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +1 -1
- package/dist/adapter/resources/webgl-shader.js +1 -1
- package/dist/adapter/resources/webgl-texture.d.ts +21 -3
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +23 -29
- package/dist/adapter/resources/webgl-transform-feedback.js +1 -1
- package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-vertex-array.js +3 -0
- package/dist/adapter/webgl-adapter.d.ts +21 -0
- package/dist/adapter/webgl-adapter.d.ts.map +1 -0
- package/dist/adapter/webgl-adapter.js +91 -0
- package/dist/adapter/webgl-device.d.ts +15 -27
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +32 -112
- package/dist/classic/copy-and-blit.d.ts +1 -0
- package/dist/classic/copy-and-blit.d.ts.map +1 -1
- package/dist/classic/copy-and-blit.js +11 -10
- package/dist/context/debug/spector-types.d.ts +1108 -0
- package/dist/context/debug/spector-types.d.ts.map +1 -0
- package/dist/context/debug/spector-types.js +697 -0
- package/dist/context/debug/spector.d.ts +12 -8
- package/dist/context/debug/spector.d.ts.map +1 -1
- package/dist/context/debug/spector.js +23 -17
- package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts +9 -0
- package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts.map +1 -0
- package/dist/context/polyfills/polyfill-webgl1-extensions.js +181 -0
- package/dist/context/state-tracker/webgl-state-tracker.d.ts +43 -0
- package/dist/context/state-tracker/webgl-state-tracker.d.ts.map +1 -0
- package/dist/context/state-tracker/{track-context-state.js → webgl-state-tracker.js} +44 -74
- package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
- package/dist/context/state-tracker/with-parameters.js +5 -4
- package/dist/dist.dev.js +352 -236
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +355 -238
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/utils/split-uniforms-and-bindings.d.ts +1 -1
- package/dist/utils/split-uniforms-and-bindings.d.ts.map +1 -1
- package/dist/utils/uid.d.ts +7 -0
- package/dist/utils/uid.d.ts.map +1 -0
- package/dist/utils/uid.js +14 -0
- package/package.json +3 -3
- package/src/adapter/converters/device-parameters.ts +18 -12
- package/src/adapter/converters/texture-formats.ts +12 -20
- package/src/adapter/device-helpers/webgl-device-features.ts +0 -1
- package/src/adapter/helpers/webgl-texture-utils.ts +12 -9
- package/src/adapter/resources/webgl-framebuffer.ts +1 -1
- package/src/adapter/resources/webgl-render-pass.ts +17 -4
- package/src/adapter/resources/webgl-render-pipeline.ts +2 -1
- package/src/adapter/resources/webgl-shader.ts +1 -1
- package/src/adapter/resources/webgl-texture.ts +42 -29
- package/src/adapter/resources/webgl-transform-feedback.ts +1 -1
- package/src/adapter/resources/webgl-vertex-array.ts +3 -0
- package/src/adapter/webgl-adapter.ts +113 -0
- package/src/adapter/webgl-device.ts +32 -135
- package/src/classic/copy-and-blit.ts +14 -9
- package/src/context/debug/spector-types.ts +1154 -0
- package/src/context/debug/spector.ts +38 -29
- package/src/context/polyfills/polyfill-webgl1-extensions.ts +202 -0
- package/src/context/state-tracker/{track-context-state.ts → webgl-state-tracker.ts} +55 -94
- package/src/context/state-tracker/with-parameters.ts +5 -4
- package/src/index.ts +5 -7
- package/src/utils/split-uniforms-and-bindings.ts +3 -3
- package/src/utils/uid.ts +16 -0
- package/dist/context/state-tracker/track-context-state.d.ts +0 -22
- package/dist/context/state-tracker/track-context-state.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export type { WebGLDeviceLimits } from "./adapter/device-helpers/webgl-device-limits.js";
|
|
2
|
+
export { webgl2Adapter } from "./adapter/webgl-adapter.js";
|
|
3
|
+
export type { WebGLAdapter } from "./adapter/webgl-adapter.js";
|
|
2
4
|
export { WebGLDevice } from "./adapter/webgl-device.js";
|
|
3
5
|
export { WebGLCanvasContext } from "./adapter/webgl-canvas-context.js";
|
|
4
6
|
export { WEBGLBuffer } from "./adapter/resources/webgl-buffer.js";
|
|
@@ -15,8 +17,8 @@ export { Accessor } from "./classic/accessor.js";
|
|
|
15
17
|
export type { AccessorObject } from "./types.js";
|
|
16
18
|
export { setDeviceParameters, withDeviceParameters } from "./adapter/converters/device-parameters.js";
|
|
17
19
|
export { getShaderLayout } from "./adapter/helpers/get-shader-layout.js";
|
|
20
|
+
export { WebGLStateTracker } from "./context/state-tracker/webgl-state-tracker.js";
|
|
18
21
|
export { TEXTURE_FORMATS as _TEXTURE_FORMATS } from "./adapter/converters/texture-formats.js";
|
|
19
|
-
export { trackContextState, pushContextState, popContextState } from "./context/state-tracker/track-context-state.js";
|
|
20
22
|
export { resetGLParameters, setGLParameters, getGLParameters } from "./context/parameters/unified-parameter-api.js";
|
|
21
23
|
export { withGLParameters } from "./context/state-tracker/with-parameters.js";
|
|
22
24
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,YAAY,EAAC,iBAAiB,EAAC,wDAAqD;AAGpF,OAAO,EAAC,WAAW,EAAC,kCAA+B;AACnD,OAAO,EAAC,kBAAkB,EAAC,0CAAuC;AAGlE,OAAO,EAAC,WAAW,EAAC,4CAAyC;AAC7D,OAAO,EAAC,YAAY,EAAC,6CAA0C;AAE/D,OAAO,EAAC,WAAW,EAAC,4CAAyC;AAC7D,OAAO,EAAC,YAAY,EAAC,6CAA0C;AAC/D,OAAO,EAAC,gBAAgB,EAAC,iDAA8C;AAEvE,OAAO,EAAC,mBAAmB,EAAC,qDAAkD;AAE9E,OAAO,EAAC,mBAAmB,EAAC,qDAAkD;AAC9E,OAAO,EAAC,eAAe,EAAC,iDAA8C;AAEtE,OAAO,EAAC,gBAAgB,EAAC,kDAA+C;AAGxE,OAAO,EAAC,sBAAsB,EAAC,wDAAqD;AAGpF,OAAO,EAAC,QAAQ,EAAC,8BAA2B;AAC5C,YAAY,EAAC,cAAc,EAAC,mBAAgB;AAI5C,OAAO,EAAC,mBAAmB,EAAE,oBAAoB,EAAC,kDAA+C;AAGjG,OAAO,EAAC,eAAe,EAAC,+CAA4C;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,YAAY,EAAC,iBAAiB,EAAC,wDAAqD;AAGpF,OAAO,EAAC,aAAa,EAAC,mCAAgC;AACtD,YAAY,EAAC,YAAY,EAAC,mCAAgC;AAG1D,OAAO,EAAC,WAAW,EAAC,kCAA+B;AACnD,OAAO,EAAC,kBAAkB,EAAC,0CAAuC;AAGlE,OAAO,EAAC,WAAW,EAAC,4CAAyC;AAC7D,OAAO,EAAC,YAAY,EAAC,6CAA0C;AAE/D,OAAO,EAAC,WAAW,EAAC,4CAAyC;AAC7D,OAAO,EAAC,YAAY,EAAC,6CAA0C;AAC/D,OAAO,EAAC,gBAAgB,EAAC,iDAA8C;AAEvE,OAAO,EAAC,mBAAmB,EAAC,qDAAkD;AAE9E,OAAO,EAAC,mBAAmB,EAAC,qDAAkD;AAC9E,OAAO,EAAC,eAAe,EAAC,iDAA8C;AAEtE,OAAO,EAAC,gBAAgB,EAAC,kDAA+C;AAGxE,OAAO,EAAC,sBAAsB,EAAC,wDAAqD;AAGpF,OAAO,EAAC,QAAQ,EAAC,8BAA2B;AAC5C,YAAY,EAAC,cAAc,EAAC,mBAAgB;AAI5C,OAAO,EAAC,mBAAmB,EAAE,oBAAoB,EAAC,kDAA+C;AAGjG,OAAO,EAAC,eAAe,EAAC,+CAA4C;AACpE,OAAO,EAAC,iBAAiB,EAAC,uDAAoD;AAG9E,OAAO,EAAC,eAAe,IAAI,gBAAgB,EAAC,gDAA6C;AAGzF,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,eAAe,EAChB,sDAAmD;AAEpD,OAAO,EAAC,gBAAgB,EAAC,mDAAgD"}
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
// WebGL adapter classes
|
|
5
|
+
export { webgl2Adapter } from "./adapter/webgl-adapter.js";
|
|
6
|
+
// WebGL Device classes
|
|
5
7
|
export { WebGLDevice } from "./adapter/webgl-device.js";
|
|
6
8
|
export { WebGLCanvasContext } from "./adapter/webgl-canvas-context.js";
|
|
7
9
|
// WebGL Resource classes
|
|
@@ -25,10 +27,9 @@ export { Accessor } from "./classic/accessor.js";
|
|
|
25
27
|
export { setDeviceParameters, withDeviceParameters } from "./adapter/converters/device-parameters.js";
|
|
26
28
|
// HELPERS - EXPERIMENTAL
|
|
27
29
|
export { getShaderLayout } from "./adapter/helpers/get-shader-layout.js";
|
|
30
|
+
export { WebGLStateTracker } from "./context/state-tracker/webgl-state-tracker.js";
|
|
28
31
|
// TEST EXPORTS
|
|
29
32
|
export { TEXTURE_FORMATS as _TEXTURE_FORMATS } from "./adapter/converters/texture-formats.js";
|
|
30
33
|
// DEPRECATED TEST EXPORTS
|
|
31
|
-
// State tracking
|
|
32
|
-
export { trackContextState, pushContextState, popContextState } from "./context/state-tracker/track-context-state.js";
|
|
33
34
|
export { resetGLParameters, setGLParameters, getGLParameters } from "./context/parameters/unified-parameter-api.js";
|
|
34
35
|
export { withGLParameters } from "./context/state-tracker/with-parameters.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { UniformValue, Binding } from '@luma.gl/core';
|
|
2
|
-
export declare function isUniformValue(value: unknown):
|
|
2
|
+
export declare function isUniformValue(value: unknown): value is UniformValue;
|
|
3
3
|
type UniformsAndBindings = {
|
|
4
4
|
bindings: Record<string, Binding>;
|
|
5
5
|
uniforms: Record<string, UniformValue>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"split-uniforms-and-bindings.d.ts","sourceRoot":"","sources":["../../src/utils/split-uniforms-and-bindings.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,YAAY,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAGzD,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"split-uniforms-and-bindings.d.ts","sourceRoot":"","sources":["../../src/utils/split-uniforms-and-bindings.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,YAAY,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAGzD,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEpE;AAED,KAAK,mBAAmB,GAAG;IACzB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACxC,CAAC;AAEF,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,CAAC,GAC/C,mBAAmB,CAYrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uid.d.ts","sourceRoot":"","sources":["../../src/utils/uid.ts"],"names":[],"mappings":"AAMA;;;;IAII;AACJ,wBAAgB,GAAG,CAAC,EAAE,GAAE,MAAa,GAAG,MAAM,CAI7C"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
const uidCounters = {};
|
|
5
|
+
/**
|
|
6
|
+
* Returns a UID.
|
|
7
|
+
* @param id= - Identifier base name
|
|
8
|
+
* @return uid
|
|
9
|
+
**/
|
|
10
|
+
export function uid(id = 'id') {
|
|
11
|
+
uidCounters[id] = uidCounters[id] || 1;
|
|
12
|
+
const count = uidCounters[id]++;
|
|
13
|
+
return `${id}-${count}`;
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/webgl",
|
|
3
|
-
"version": "9.1.0-alpha.
|
|
3
|
+
"version": "9.1.0-alpha.10",
|
|
4
4
|
"description": "WebGL2 adapter for the luma.gl core API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"@luma.gl/core": "^9.0.0-beta"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@luma.gl/constants": "9.1.0-alpha.
|
|
46
|
+
"@luma.gl/constants": "9.1.0-alpha.10",
|
|
47
47
|
"@math.gl/types": "^4.0.0",
|
|
48
48
|
"@probe.gl/env": "^4.0.8"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "f419cdc284e87b553df60af49d2888ac7dbbf288"
|
|
51
51
|
}
|
|
@@ -14,7 +14,6 @@ import type {
|
|
|
14
14
|
GLProvokingVertex,
|
|
15
15
|
GLStencilOp
|
|
16
16
|
} from '@luma.gl/constants';
|
|
17
|
-
import {pushContextState, popContextState} from '../../context/state-tracker/track-context-state';
|
|
18
17
|
import {setGLParameters} from '../../context/parameters/unified-parameter-api';
|
|
19
18
|
import {WebGLDevice} from '../webgl-device';
|
|
20
19
|
|
|
@@ -41,13 +40,13 @@ export function withDeviceAndGLParameters<T = unknown>(
|
|
|
41
40
|
|
|
42
41
|
// Wrap in a try-catch to ensure that parameters are restored on exceptions
|
|
43
42
|
const webglDevice = device as WebGLDevice;
|
|
44
|
-
|
|
43
|
+
webglDevice.pushState();
|
|
45
44
|
try {
|
|
46
45
|
setDeviceParameters(device, parameters);
|
|
47
46
|
setGLParameters(webglDevice.gl, glParameters);
|
|
48
47
|
return func(device);
|
|
49
48
|
} finally {
|
|
50
|
-
|
|
49
|
+
webglDevice.popState();
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
|
|
@@ -72,12 +71,12 @@ export function withGLParameters<T = unknown>(
|
|
|
72
71
|
|
|
73
72
|
// Wrap in a try-catch to ensure that parameters are restored on exceptions
|
|
74
73
|
const webglDevice = device as WebGLDevice;
|
|
75
|
-
|
|
74
|
+
webglDevice.pushState();
|
|
76
75
|
try {
|
|
77
76
|
setGLParameters(webglDevice.gl, parameters);
|
|
78
77
|
return func(device);
|
|
79
78
|
} finally {
|
|
80
|
-
|
|
79
|
+
webglDevice.popState();
|
|
81
80
|
}
|
|
82
81
|
}
|
|
83
82
|
|
|
@@ -99,15 +98,14 @@ export function withDeviceParameters<T = unknown>(
|
|
|
99
98
|
return func(device);
|
|
100
99
|
}
|
|
101
100
|
|
|
102
|
-
// Wrap in a try-catch to ensure that parameters are restored on exceptions
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
// Wrap in a try-catch to ensure that parameters are restored on exceptions'
|
|
102
|
+
const webglDevice = device as WebGLDevice;
|
|
103
|
+
webglDevice.pushState();
|
|
105
104
|
try {
|
|
106
105
|
setDeviceParameters(device, parameters);
|
|
107
106
|
return func(device);
|
|
108
107
|
} finally {
|
|
109
|
-
|
|
110
|
-
popContextState(device.gl);
|
|
108
|
+
webglDevice.popState();
|
|
111
109
|
}
|
|
112
110
|
}
|
|
113
111
|
|
|
@@ -280,10 +278,18 @@ export function setDeviceParameters(device: Device, parameters: Parameters) {
|
|
|
280
278
|
// },
|
|
281
279
|
|
|
282
280
|
// COLOR STATE
|
|
281
|
+
switch (parameters.blend) {
|
|
282
|
+
case true:
|
|
283
|
+
gl.enable(GL.BLEND);
|
|
284
|
+
break;
|
|
285
|
+
case false:
|
|
286
|
+
gl.disable(GL.BLEND);
|
|
287
|
+
break;
|
|
288
|
+
default:
|
|
289
|
+
// leave WebGL blend state unchanged if `parameters.blend` is not set
|
|
290
|
+
}
|
|
283
291
|
|
|
284
292
|
if (parameters.blendColorOperation || parameters.blendAlphaOperation) {
|
|
285
|
-
gl.enable(GL.BLEND);
|
|
286
|
-
|
|
287
293
|
const colorEquation = convertBlendOperationToEquation(
|
|
288
294
|
'blendColorOperation',
|
|
289
295
|
parameters.blendColorOperation || 'add'
|
|
@@ -141,15 +141,6 @@ type Format = {
|
|
|
141
141
|
*/
|
|
142
142
|
// prettier-ignore
|
|
143
143
|
export const TEXTURE_FORMATS: Record<TextureFormat, Format> = {
|
|
144
|
-
// Unsized formats that leave the precision up to the driver. TODO - Fix bpp constants
|
|
145
|
-
'rgb8unorm-unsized': {gl: GL.RGB, b: 4, c: 2, bpp: 4,
|
|
146
|
-
dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_6_5]},
|
|
147
|
-
'rgba8unorm-unsized': {gl: GL.RGBA, b: 4, c: 2, bpp: 4,
|
|
148
|
-
dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_4_4_4_4, GL.UNSIGNED_SHORT_5_5_5_1]},
|
|
149
|
-
// 'r8unorm-unsized': {gl: GL.LUMINANCE, b: 4, c: 2, bpp: 4},
|
|
150
|
-
// 'rgb8unorm-srgb-unsized': {gl: GL.SRGB_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
|
|
151
|
-
// 'rgba8unorm-srgb-unsized': {gl: GL.SRGB_ALPHA_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
|
|
152
|
-
|
|
153
144
|
// 8-bit formats
|
|
154
145
|
'r8unorm': {gl: GL.R8, b: 1, c: 1, rb: true},
|
|
155
146
|
'r8snorm': {gl: GL.R8_SNORM, b: 1, c: 1, render: snorm8_renderable},
|
|
@@ -239,9 +230,6 @@ export const TEXTURE_FORMATS: Record<TextureFormat, Format> = {
|
|
|
239
230
|
// The depth component of the "depth24plus" and "depth24plus-stencil8" formats may be implemented as either a 24-bit depth value or a "depth32float" value.
|
|
240
231
|
'depth24plus-stencil8': {gl: GL.DEPTH24_STENCIL8, b: 4, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT, rb: true, depthTexture: true,
|
|
241
232
|
dataFormat: GL.DEPTH_STENCIL, types: [GL.UNSIGNED_INT_24_8]},
|
|
242
|
-
// "depth24unorm-stencil8" feature
|
|
243
|
-
'depth24unorm-stencil8': {gl: GL.DEPTH24_STENCIL8, b: 4, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT,
|
|
244
|
-
dataFormat: GL.DEPTH_STENCIL, types: [GL.UNSIGNED_INT_24_8], rb: true},
|
|
245
233
|
// "depth32float-stencil8" feature - TODO below is render buffer only?
|
|
246
234
|
'depth32float-stencil8': {gl: GL.DEPTH32F_STENCIL8, b: 5, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT,
|
|
247
235
|
dataFormat: GL.DEPTH_STENCIL, types: [GL.FLOAT_32_UNSIGNED_INT_24_8_REV], rb: true},
|
|
@@ -469,6 +457,10 @@ export function isTextureFormatSupported(
|
|
|
469
457
|
if (info.gl === undefined) {
|
|
470
458
|
return false;
|
|
471
459
|
}
|
|
460
|
+
const feature = info.f;
|
|
461
|
+
if (feature) {
|
|
462
|
+
return checkTextureFeature(gl, feature, extensions);
|
|
463
|
+
}
|
|
472
464
|
// Check extensions
|
|
473
465
|
const extension = info.x || info.gl2ext;
|
|
474
466
|
if (extension) {
|
|
@@ -509,7 +501,7 @@ export function getTextureFormatSupport(
|
|
|
509
501
|
|
|
510
502
|
// Support Check that we have a GL constant
|
|
511
503
|
let supported = info.gl === undefined;
|
|
512
|
-
supported = supported && checkTextureFeature(gl, info.f
|
|
504
|
+
supported = supported && checkTextureFeature(gl, info.f, extensions);
|
|
513
505
|
|
|
514
506
|
// Filtering
|
|
515
507
|
// const filterable = info.filter
|
|
@@ -521,8 +513,8 @@ export function getTextureFormatSupport(
|
|
|
521
513
|
|
|
522
514
|
return {
|
|
523
515
|
supported,
|
|
524
|
-
renderable: supported && checkTextureFeature(gl, info.render
|
|
525
|
-
filterable: supported && checkTextureFeature(gl, info.filter
|
|
516
|
+
renderable: supported && checkTextureFeature(gl, info.render, extensions),
|
|
517
|
+
filterable: supported && checkTextureFeature(gl, info.filter, extensions),
|
|
526
518
|
blendable: false, // tod,
|
|
527
519
|
storable: false
|
|
528
520
|
};
|
|
@@ -586,13 +578,12 @@ export function getTextureFormatWebGL(format: TextureFormat): {
|
|
|
586
578
|
internalFormat: webglFormat,
|
|
587
579
|
format:
|
|
588
580
|
formatData?.dataFormat ||
|
|
589
|
-
getWebGLPixelDataFormat(decoded.
|
|
581
|
+
getWebGLPixelDataFormat(decoded.channels, decoded.integer, decoded.normalized, webglFormat),
|
|
590
582
|
// depth formats don't have a type
|
|
591
583
|
type: decoded.dataType
|
|
592
584
|
? getGLFromVertexType(decoded.dataType)
|
|
593
585
|
: formatData?.types?.[0] || GL.UNSIGNED_BYTE,
|
|
594
|
-
|
|
595
|
-
compressed: decoded.compressed
|
|
586
|
+
compressed: decoded.compressed || false
|
|
596
587
|
};
|
|
597
588
|
}
|
|
598
589
|
|
|
@@ -619,7 +610,7 @@ export function getTextureFormatBytesPerPixel(format: TextureFormat): number {
|
|
|
619
610
|
// DATA TYPE HELPERS
|
|
620
611
|
|
|
621
612
|
export function getWebGLPixelDataFormat(
|
|
622
|
-
|
|
613
|
+
channels: 'r' | 'rg' | 'rgb' | 'rgba' | 'bgra',
|
|
623
614
|
integer: boolean,
|
|
624
615
|
normalized: boolean,
|
|
625
616
|
format: GL
|
|
@@ -629,11 +620,12 @@ export function getWebGLPixelDataFormat(
|
|
|
629
620
|
return format;
|
|
630
621
|
}
|
|
631
622
|
// prettier-ignore
|
|
632
|
-
switch (
|
|
623
|
+
switch (channels) {
|
|
633
624
|
case 'r': return integer && !normalized ? GL.RED_INTEGER : GL.RED;
|
|
634
625
|
case 'rg': return integer && !normalized ? GL.RG_INTEGER : GL.RG;
|
|
635
626
|
case 'rgb': return integer && !normalized ? GL.RGB_INTEGER : GL.RGB;
|
|
636
627
|
case 'rgba': return integer && !normalized ? GL.RGBA_INTEGER : GL.RGBA;
|
|
628
|
+
case 'bgra': throw new Error('bgra pixels not supported by WebGL');
|
|
637
629
|
default: return GL.RGBA;
|
|
638
630
|
}
|
|
639
631
|
}
|
|
@@ -21,7 +21,6 @@ const WEBGL_FEATURES: Partial<Record<DeviceFeature, boolean | string>> = {
|
|
|
21
21
|
// 'timestamp-query' // GPUQueryType "timestamp-query"
|
|
22
22
|
// "indirect-first-instance"
|
|
23
23
|
// Textures are handled by getTextureFeatures()
|
|
24
|
-
// 'depth24unorm-stencil8' // GPUTextureFormat 'depth24unorm-stencil8'
|
|
25
24
|
// 'depth32float-stencil8' // GPUTextureFormat 'depth32float-stencil8'
|
|
26
25
|
|
|
27
26
|
// optional WebGL features
|
|
@@ -97,7 +97,7 @@ export function initializeTextureStorage(
|
|
|
97
97
|
): void {
|
|
98
98
|
const {dimension, width, height, depth = 0} = options;
|
|
99
99
|
const {glInternalFormat} = options;
|
|
100
|
-
const glTarget = options.glTarget; //
|
|
100
|
+
const glTarget = options.glTarget; // getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
101
101
|
switch (dimension) {
|
|
102
102
|
case '2d-array':
|
|
103
103
|
case '3d':
|
|
@@ -120,7 +120,7 @@ export function copyCPUImageToMipLevel(
|
|
|
120
120
|
const {dimension, width, height, depth = 0, level = 0} = options;
|
|
121
121
|
const {x = 0, y = 0, z = 0} = options;
|
|
122
122
|
const {glFormat, glType} = options;
|
|
123
|
-
const glTarget =
|
|
123
|
+
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
124
124
|
|
|
125
125
|
// width = size.width,
|
|
126
126
|
// height = size.height
|
|
@@ -154,7 +154,9 @@ export function copyCPUDataToMipLevel(
|
|
|
154
154
|
const {dimension, width, height, depth = 0, level = 0, byteOffset = 0} = options;
|
|
155
155
|
const {x = 0, y = 0, z = 0} = options;
|
|
156
156
|
const {glFormat, glType, compressed} = options;
|
|
157
|
-
const glTarget =
|
|
157
|
+
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
158
|
+
|
|
159
|
+
// gl.bindTexture(glTarget, null);
|
|
158
160
|
|
|
159
161
|
switch (dimension) {
|
|
160
162
|
case '2d-array':
|
|
@@ -196,7 +198,7 @@ export function copyGPUBufferToMipLevel(
|
|
|
196
198
|
const {dimension, width, height, depth = 0, level = 0, byteOffset = 0} = options;
|
|
197
199
|
const {x = 0, y = 0, z = 0} = options;
|
|
198
200
|
const {glFormat, glType, compressed} = options;
|
|
199
|
-
const glTarget =
|
|
201
|
+
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
200
202
|
|
|
201
203
|
gl.bindBuffer(GL.PIXEL_UNPACK_BUFFER, webglBuffer);
|
|
202
204
|
|
|
@@ -250,9 +252,10 @@ export function getWebGLTextureTarget(
|
|
|
250
252
|
|
|
251
253
|
/**
|
|
252
254
|
* In WebGL, cube maps specify faces by overriding target instead of using the depth parameter.
|
|
255
|
+
* @note We still bind the texture using GL.TEXTURE_CUBE_MAP, but we need to use the face-specific target when setting mip levels.
|
|
253
256
|
* @returns glTarget unchanged, if dimension !== 'cube'.
|
|
254
257
|
*/
|
|
255
|
-
function
|
|
258
|
+
function getWebGLCubeFaceTarget(
|
|
256
259
|
glTarget: GLTextureTarget,
|
|
257
260
|
dimension: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d',
|
|
258
261
|
level: number
|
|
@@ -269,7 +272,7 @@ function getCubeTargetWebGL(
|
|
|
269
272
|
export function clearMipLevel(gl: WebGL2RenderingContext, options: WebGLSetTextureOptions): void {
|
|
270
273
|
const {dimension, width, height, depth = 0, level = 0} = options;
|
|
271
274
|
const {glInternalFormat, glFormat, glType, compressed} = options;
|
|
272
|
-
const glTarget =
|
|
275
|
+
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
273
276
|
|
|
274
277
|
switch (dimension) {
|
|
275
278
|
case '2d-array':
|
|
@@ -312,7 +315,7 @@ export function setMipLevelFromExternalImage(
|
|
|
312
315
|
const {dimension, width, height, depth = 0, level = 0} = options;
|
|
313
316
|
const {glInternalFormat, glType} = options;
|
|
314
317
|
|
|
315
|
-
const glTarget =
|
|
318
|
+
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
316
319
|
|
|
317
320
|
// TODO - we can't change texture width (due to WebGPU limitations) -
|
|
318
321
|
// and the width/heigh of an external image is implicit, so why do we need to extract it?
|
|
@@ -363,7 +366,7 @@ export function setMipLevelFromTypedArray(
|
|
|
363
366
|
const {dimension, width, height, depth = 0, level = 0, offset = 0} = options;
|
|
364
367
|
const {glInternalFormat, glFormat, glType, compressed} = options;
|
|
365
368
|
|
|
366
|
-
const glTarget =
|
|
369
|
+
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
367
370
|
|
|
368
371
|
withGLParameters(gl, parameters, () => {
|
|
369
372
|
switch (dimension) {
|
|
@@ -442,7 +445,7 @@ export function setMipLevelFromGPUBuffer(
|
|
|
442
445
|
): void {
|
|
443
446
|
const {dimension, width, height, depth = 0, level = 0, byteOffset = 0} = options;
|
|
444
447
|
const {glInternalFormat, glFormat, glType, compressed} = options;
|
|
445
|
-
const glTarget =
|
|
448
|
+
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
446
449
|
|
|
447
450
|
const webglBuffer = buffer as WEBGLBuffer;
|
|
448
451
|
const imageSize = buffer.byteLength;
|
|
@@ -155,7 +155,7 @@ export class WEBGLFramebuffer extends Framebuffer {
|
|
|
155
155
|
switch (texture.glTarget) {
|
|
156
156
|
case GL.TEXTURE_2D_ARRAY:
|
|
157
157
|
case GL.TEXTURE_3D:
|
|
158
|
-
gl.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.
|
|
158
|
+
gl.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.handle, level, layer);
|
|
159
159
|
break;
|
|
160
160
|
|
|
161
161
|
case GL.TEXTURE_CUBE_MAP:
|
|
@@ -8,7 +8,6 @@ import {WebGLDevice} from '../webgl-device';
|
|
|
8
8
|
import {GL, GLParameters} from '@luma.gl/constants';
|
|
9
9
|
import {withGLParameters} from '../../context/state-tracker/with-parameters';
|
|
10
10
|
import {setGLParameters} from '../../context/parameters/unified-parameter-api';
|
|
11
|
-
import {pushContextState, popContextState} from '../../context/state-tracker/track-context-state';
|
|
12
11
|
import {WEBGLQuerySet} from './webgl-query-set';
|
|
13
12
|
|
|
14
13
|
// Should collapse during minification
|
|
@@ -29,16 +28,30 @@ export class WEBGLRenderPass extends RenderPass {
|
|
|
29
28
|
super(device, props);
|
|
30
29
|
this.device = device;
|
|
31
30
|
|
|
31
|
+
// If no viewport is provided, apply reasonably defaults
|
|
32
|
+
let viewport;
|
|
33
|
+
if (!props?.parameters?.viewport) {
|
|
34
|
+
if (props?.framebuffer) {
|
|
35
|
+
// Set the viewport to the size of the framebuffer
|
|
36
|
+
const {width, height} = props.framebuffer;
|
|
37
|
+
viewport = [0, 0, width, height];
|
|
38
|
+
} else {
|
|
39
|
+
// Instead of using our own book-keeping, we can just read the values from the WebGL context
|
|
40
|
+
const [width, height] = device.getCanvasContext().getDrawingBufferSize();
|
|
41
|
+
viewport = [0, 0, width, height];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
32
45
|
// TODO - do parameters (scissorRect) affect the clear operation?
|
|
33
|
-
|
|
34
|
-
this.setParameters(this.props.parameters);
|
|
46
|
+
this.device.pushState();
|
|
47
|
+
this.setParameters({viewport, ...this.props.parameters});
|
|
35
48
|
|
|
36
49
|
// Hack - for now WebGL draws in "immediate mode" (instead of queueing the operations)...
|
|
37
50
|
this.clear();
|
|
38
51
|
}
|
|
39
52
|
|
|
40
53
|
end(): void {
|
|
41
|
-
|
|
54
|
+
this.device.popState();
|
|
42
55
|
// should add commands to CommandEncoder.
|
|
43
56
|
}
|
|
44
57
|
|
|
@@ -112,7 +112,8 @@ export class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
112
112
|
.join(', ');
|
|
113
113
|
if (!options?.disableWarnings) {
|
|
114
114
|
log.warn(
|
|
115
|
-
`
|
|
115
|
+
`No binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`,
|
|
116
|
+
value
|
|
116
117
|
)();
|
|
117
118
|
}
|
|
118
119
|
continue; // eslint-disable-line no-continue
|
|
@@ -60,7 +60,7 @@ export class WEBGLShader extends Shader {
|
|
|
60
60
|
/** Compile a shader and get compilation status */
|
|
61
61
|
protected async _compile(source: string): Promise<void> {
|
|
62
62
|
const addGLSLVersion = (source: string) =>
|
|
63
|
-
source.startsWith('#version ') ? source : `#version
|
|
63
|
+
source.startsWith('#version ') ? source : `#version 300 es\n${source}`;
|
|
64
64
|
source = addGLSLVersion(source);
|
|
65
65
|
|
|
66
66
|
const {gl} = this.device;
|
|
@@ -192,7 +192,7 @@ export class WEBGLTexture extends Texture {
|
|
|
192
192
|
let {width, height} = props;
|
|
193
193
|
|
|
194
194
|
if (!width || !height) {
|
|
195
|
-
const textureSize =
|
|
195
|
+
const textureSize = Texture.getTextureDataSize(data);
|
|
196
196
|
width = textureSize?.width || 1;
|
|
197
197
|
height = textureSize?.height || 1;
|
|
198
198
|
}
|
|
@@ -333,13 +333,36 @@ export class WEBGLTexture extends Texture {
|
|
|
333
333
|
}
|
|
334
334
|
|
|
335
335
|
// Image Data Setters
|
|
336
|
+
copyExternalImage(options: {
|
|
337
|
+
image: ExternalImage;
|
|
338
|
+
sourceX?: number;
|
|
339
|
+
sourceY?: number;
|
|
340
|
+
width?: number;
|
|
341
|
+
height?: number;
|
|
342
|
+
depth?: number;
|
|
343
|
+
mipLevel?: number;
|
|
344
|
+
x?: number;
|
|
345
|
+
y?: number;
|
|
346
|
+
z?: number;
|
|
347
|
+
aspect?: 'all' | 'stencil-only' | 'depth-only';
|
|
348
|
+
colorSpace?: 'srgb';
|
|
349
|
+
premultipliedAlpha?: boolean;
|
|
350
|
+
}): {width: number; height: number} {
|
|
351
|
+
const size = Texture.getExternalImageSize(options.image);
|
|
352
|
+
const opts = {...Texture.defaultCopyExternalImageOptions, ...size, ...options};
|
|
353
|
+
const {depth, mipLevel: lodLevel, image} = opts;
|
|
354
|
+
this.bind();
|
|
355
|
+
this._setMipLevel(depth, lodLevel, image);
|
|
356
|
+
this.unbind();
|
|
357
|
+
return {width: opts.width, height: opts.height};
|
|
358
|
+
}
|
|
336
359
|
|
|
337
360
|
setTexture1DData(data: Texture1DData): void {
|
|
338
361
|
throw new Error('setTexture1DData not supported in WebGL.');
|
|
339
362
|
}
|
|
340
363
|
|
|
341
364
|
/** Set a simple texture */
|
|
342
|
-
setTexture2DData(lodData: Texture2DData, depth = 0
|
|
365
|
+
setTexture2DData(lodData: Texture2DData, depth = 0): void {
|
|
343
366
|
this.bind();
|
|
344
367
|
|
|
345
368
|
const lodArray = normalizeTextureData(lodData, this);
|
|
@@ -367,7 +390,9 @@ export class WEBGLTexture extends Texture {
|
|
|
367
390
|
throw new Error(this.id);
|
|
368
391
|
}
|
|
369
392
|
if (ArrayBuffer.isView(data)) {
|
|
393
|
+
this.bind();
|
|
370
394
|
copyCPUDataToMipLevel(this.device.gl, data, this);
|
|
395
|
+
this.unbind();
|
|
371
396
|
}
|
|
372
397
|
}
|
|
373
398
|
|
|
@@ -381,9 +406,9 @@ export class WEBGLTexture extends Texture {
|
|
|
381
406
|
if (this.props.dimension !== 'cube') {
|
|
382
407
|
throw new Error(this.id);
|
|
383
408
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
409
|
+
for (const face of Texture.CubeFaces) {
|
|
410
|
+
this.setTextureCubeFaceData(data[face], face);
|
|
411
|
+
}
|
|
387
412
|
}
|
|
388
413
|
|
|
389
414
|
/**
|
|
@@ -414,27 +439,9 @@ export class WEBGLTexture extends Texture {
|
|
|
414
439
|
log.warn(`${this.id} has mipmap and multiple LODs.`)();
|
|
415
440
|
}
|
|
416
441
|
|
|
417
|
-
|
|
418
|
-
// const glType = GL.UNSIGNED_BYTE;
|
|
419
|
-
// const {width, height, format = GL.RGBA, type = GL.UNSIGNED_BYTE} = this;
|
|
420
|
-
// const {width, height, format = GL.RGBA, type = GL.UNSIGNED_BYTE} = this;
|
|
442
|
+
const faceDepth = Texture.CubeFaces.indexOf(face);
|
|
421
443
|
|
|
422
|
-
this.
|
|
423
|
-
// for (let lodLevel = 0; lodLevel < lodData.length; lodLevel++) {
|
|
424
|
-
// const imageData = lodData[lodLevel];
|
|
425
|
-
// if (imageData instanceof ArrayBuffer) {
|
|
426
|
-
// // const imageData = image instanceof ArrayBuffer ? new ImageData(new Uint8ClampedArray(image), this.width) : image;
|
|
427
|
-
// this.device.gl.texImage2D?.(
|
|
428
|
-
// glFace,
|
|
429
|
-
// lodLevel,
|
|
430
|
-
// this.glInternalFormat,
|
|
431
|
-
// this.glInternalFormat,
|
|
432
|
-
// glType,
|
|
433
|
-
// imageData
|
|
434
|
-
// );
|
|
435
|
-
// }
|
|
436
|
-
// }
|
|
437
|
-
this.unbind();
|
|
444
|
+
this.setTexture2DData(lodData, faceDepth);
|
|
438
445
|
}
|
|
439
446
|
|
|
440
447
|
// INTERNAL METHODS
|
|
@@ -592,23 +599,29 @@ export class WEBGLTexture extends Texture {
|
|
|
592
599
|
* Copy a region of data from a CPU memory buffer into this texture.
|
|
593
600
|
* @todo - GLUnpackParameters parameters
|
|
594
601
|
*/
|
|
595
|
-
protected _setMipLevel(
|
|
602
|
+
protected _setMipLevel(
|
|
603
|
+
depth: number,
|
|
604
|
+
level: number,
|
|
605
|
+
textureData: Texture2DData,
|
|
606
|
+
glTarget: GL = this.glTarget
|
|
607
|
+
) {
|
|
596
608
|
// if (!textureData) {
|
|
597
609
|
// clearMipLevel(this.device.gl, {...this, depth, level});
|
|
598
610
|
// return;
|
|
599
611
|
// }
|
|
600
612
|
|
|
601
613
|
if (Texture.isExternalImage(textureData)) {
|
|
602
|
-
copyCPUImageToMipLevel(this.device.gl, textureData, {...this, depth, level});
|
|
614
|
+
copyCPUImageToMipLevel(this.device.gl, textureData, {...this, depth, level, glTarget});
|
|
603
615
|
return;
|
|
604
616
|
}
|
|
605
617
|
|
|
606
618
|
// @ts-expect-error
|
|
607
|
-
if (
|
|
619
|
+
if (Texture.isTextureLevelData(textureData)) {
|
|
608
620
|
copyCPUDataToMipLevel(this.device.gl, textureData.data, {
|
|
609
621
|
...this,
|
|
610
622
|
depth,
|
|
611
|
-
level
|
|
623
|
+
level,
|
|
624
|
+
glTarget
|
|
612
625
|
});
|
|
613
626
|
return;
|
|
614
627
|
}
|
|
@@ -56,7 +56,7 @@ export class WEBGLTransformFeedback extends TransformFeedback {
|
|
|
56
56
|
|
|
57
57
|
end(): void {
|
|
58
58
|
this.gl.endTransformFeedback();
|
|
59
|
-
if (
|
|
59
|
+
if (this.bindOnUse) {
|
|
60
60
|
this._unbindBuffers();
|
|
61
61
|
}
|
|
62
62
|
this.gl.bindTransformFeedback(GL.TRANSFORM_FEEDBACK, null);
|
|
@@ -97,6 +97,9 @@ export class WEBGLVertexArray extends VertexArray {
|
|
|
97
97
|
// Attaches ARRAY_BUFFER with specified buffer format to location
|
|
98
98
|
this.device.gl.vertexAttribPointer(location, size, type, normalized, stride, offset);
|
|
99
99
|
}
|
|
100
|
+
// Clear binding - keeping it may cause [.WebGL-0x12804417100]
|
|
101
|
+
// GL_INVALID_OPERATION: A transform feedback buffer that would be written to is also bound to a non-transform-feedback target
|
|
102
|
+
this.device.gl.bindBuffer(GL.ARRAY_BUFFER, null);
|
|
100
103
|
|
|
101
104
|
// Mark as non-constant
|
|
102
105
|
this.device.gl.enableVertexAttribArray(location);
|