@luma.gl/webgl 9.1.0-alpha.2 → 9.1.0-alpha.9
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 +2 -2
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +12 -27
- 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 +339 -233
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +342 -235
- 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/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 +17 -27
- 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/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/dist.dev.js
CHANGED
|
@@ -11,7 +11,6 @@ var __exports__ = (() => {
|
|
|
11
11
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
12
12
|
var __getProtoOf = Object.getPrototypeOf;
|
|
13
13
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
15
14
|
var __commonJS = (cb, mod) => function __require() {
|
|
16
15
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
17
16
|
};
|
|
@@ -37,10 +36,6 @@ var __exports__ = (() => {
|
|
|
37
36
|
mod
|
|
38
37
|
));
|
|
39
38
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
40
|
-
var __publicField = (obj, key, value) => {
|
|
41
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
42
|
-
return value;
|
|
43
|
-
};
|
|
44
39
|
|
|
45
40
|
// external-global-plugin:@luma.gl/core
|
|
46
41
|
var require_core = __commonJS({
|
|
@@ -65,20 +60,22 @@ var __exports__ = (() => {
|
|
|
65
60
|
WEBGLVertexArray: () => WEBGLVertexArray,
|
|
66
61
|
WebGLCanvasContext: () => WebGLCanvasContext,
|
|
67
62
|
WebGLDevice: () => WebGLDevice,
|
|
63
|
+
WebGLStateTracker: () => WebGLStateTracker,
|
|
68
64
|
_TEXTURE_FORMATS: () => TEXTURE_FORMATS,
|
|
69
65
|
getGLParameters: () => getGLParameters,
|
|
70
66
|
getShaderLayout: () => getShaderLayout,
|
|
71
|
-
popContextState: () => popContextState,
|
|
72
|
-
pushContextState: () => pushContextState,
|
|
73
67
|
resetGLParameters: () => resetGLParameters,
|
|
74
68
|
setDeviceParameters: () => setDeviceParameters,
|
|
75
69
|
setGLParameters: () => setGLParameters,
|
|
76
|
-
|
|
70
|
+
webgl2Adapter: () => webgl2Adapter,
|
|
77
71
|
withDeviceParameters: () => withDeviceParameters,
|
|
78
72
|
withGLParameters: () => withGLParameters
|
|
79
73
|
});
|
|
80
74
|
__reExport(bundle_exports, __toESM(require_core(), 1));
|
|
81
75
|
|
|
76
|
+
// src/adapter/webgl-adapter.ts
|
|
77
|
+
var import_core23 = __toESM(require_core(), 1);
|
|
78
|
+
|
|
82
79
|
// src/adapter/webgl-device.ts
|
|
83
80
|
var import_core22 = __toESM(require_core(), 1);
|
|
84
81
|
|
|
@@ -1309,24 +1306,22 @@ var __exports__ = (() => {
|
|
|
1309
1306
|
return false;
|
|
1310
1307
|
}
|
|
1311
1308
|
|
|
1312
|
-
// src/context/state-tracker/
|
|
1313
|
-
var
|
|
1309
|
+
// src/context/state-tracker/webgl-state-tracker.ts
|
|
1310
|
+
var WebGLStateTracker = class {
|
|
1311
|
+
static get(gl) {
|
|
1312
|
+
return gl.state;
|
|
1313
|
+
}
|
|
1314
1314
|
gl;
|
|
1315
1315
|
program = null;
|
|
1316
1316
|
stateStack = [];
|
|
1317
1317
|
enable = true;
|
|
1318
|
-
cache;
|
|
1318
|
+
cache = null;
|
|
1319
1319
|
log;
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
// Copy cache from params (slow) or initialize from WebGL defaults (fast)
|
|
1323
|
-
log: log9 = () => {
|
|
1324
|
-
}
|
|
1325
|
-
// Logging function, called when gl parameter change calls are actually issued
|
|
1326
|
-
} = {}) {
|
|
1320
|
+
initialized = false;
|
|
1321
|
+
constructor(gl, props) {
|
|
1327
1322
|
this.gl = gl;
|
|
1328
|
-
this.
|
|
1329
|
-
|
|
1323
|
+
this.log = props?.log || (() => {
|
|
1324
|
+
});
|
|
1330
1325
|
this._updateCache = this._updateCache.bind(this);
|
|
1331
1326
|
Object.seal(this);
|
|
1332
1327
|
}
|
|
@@ -1338,6 +1333,29 @@ var __exports__ = (() => {
|
|
|
1338
1333
|
setGLParameters(this.gl, oldValues);
|
|
1339
1334
|
this.stateStack.pop();
|
|
1340
1335
|
}
|
|
1336
|
+
/**
|
|
1337
|
+
* Initialize WebGL state caching on a context
|
|
1338
|
+
* can be called multiple times to enable/disable
|
|
1339
|
+
*
|
|
1340
|
+
* @note After calling this function, context state will be cached
|
|
1341
|
+
* .push() and .pop() will be available for saving,
|
|
1342
|
+
* temporarily modifying, and then restoring state.
|
|
1343
|
+
*/
|
|
1344
|
+
trackState(gl, options) {
|
|
1345
|
+
this.cache = options.copyState ? getGLParameters(gl) : Object.assign({}, GL_PARAMETER_DEFAULTS);
|
|
1346
|
+
if (this.initialized) {
|
|
1347
|
+
throw new Error("WebGLStateTracker");
|
|
1348
|
+
}
|
|
1349
|
+
this.initialized = true;
|
|
1350
|
+
this.gl.state = this;
|
|
1351
|
+
installProgramSpy(gl);
|
|
1352
|
+
for (const key in GL_HOOKED_SETTERS) {
|
|
1353
|
+
const setter = GL_HOOKED_SETTERS[key];
|
|
1354
|
+
installSetterSpy(gl, key, setter);
|
|
1355
|
+
}
|
|
1356
|
+
installGetterOverride(gl, "getParameter");
|
|
1357
|
+
installGetterOverride(gl, "isEnabled");
|
|
1358
|
+
}
|
|
1341
1359
|
/**
|
|
1342
1360
|
// interceptor for context set functions - update our cache and our stack
|
|
1343
1361
|
// values (Object) - the key values for this setter
|
|
@@ -1363,44 +1381,13 @@ var __exports__ = (() => {
|
|
|
1363
1381
|
return { valueChanged, oldValue };
|
|
1364
1382
|
}
|
|
1365
1383
|
};
|
|
1366
|
-
function getContextState(gl) {
|
|
1367
|
-
return gl.state;
|
|
1368
|
-
}
|
|
1369
|
-
function trackContextState(gl, options) {
|
|
1370
|
-
const { enable: enable2 = true, copyState } = options || {};
|
|
1371
|
-
if (!gl.state) {
|
|
1372
|
-
gl.state = new GLState(gl, { copyState });
|
|
1373
|
-
installProgramSpy(gl);
|
|
1374
|
-
for (const key in GL_HOOKED_SETTERS) {
|
|
1375
|
-
const setter = GL_HOOKED_SETTERS[key];
|
|
1376
|
-
installSetterSpy(gl, key, setter);
|
|
1377
|
-
}
|
|
1378
|
-
installGetterOverride(gl, "getParameter");
|
|
1379
|
-
installGetterOverride(gl, "isEnabled");
|
|
1380
|
-
}
|
|
1381
|
-
const glState = getContextState(gl);
|
|
1382
|
-
glState.enable = enable2;
|
|
1383
|
-
return gl;
|
|
1384
|
-
}
|
|
1385
|
-
function pushContextState(gl) {
|
|
1386
|
-
let glState = getContextState(gl);
|
|
1387
|
-
if (!glState) {
|
|
1388
|
-
trackContextState(gl, { copyState: false });
|
|
1389
|
-
glState = getContextState(gl);
|
|
1390
|
-
}
|
|
1391
|
-
glState.push();
|
|
1392
|
-
}
|
|
1393
|
-
function popContextState(gl) {
|
|
1394
|
-
const glState = getContextState(gl);
|
|
1395
|
-
glState.pop();
|
|
1396
|
-
}
|
|
1397
1384
|
function installGetterOverride(gl, functionName) {
|
|
1398
1385
|
const originalGetterFunc = gl[functionName].bind(gl);
|
|
1399
1386
|
gl[functionName] = function get(pname) {
|
|
1400
1387
|
if (pname === void 0 || NON_CACHE_PARAMETERS.has(pname)) {
|
|
1401
1388
|
return originalGetterFunc(pname);
|
|
1402
1389
|
}
|
|
1403
|
-
const glState =
|
|
1390
|
+
const glState = WebGLStateTracker.get(gl);
|
|
1404
1391
|
if (!(pname in glState.cache)) {
|
|
1405
1392
|
glState.cache[pname] = originalGetterFunc(pname);
|
|
1406
1393
|
}
|
|
@@ -1423,7 +1410,7 @@ var __exports__ = (() => {
|
|
|
1423
1410
|
}
|
|
1424
1411
|
const originalSetterFunc = gl[functionName].bind(gl);
|
|
1425
1412
|
gl[functionName] = function set(...params) {
|
|
1426
|
-
const glState =
|
|
1413
|
+
const glState = WebGLStateTracker.get(gl);
|
|
1427
1414
|
const { valueChanged, oldValue } = setter(glState._updateCache, ...params);
|
|
1428
1415
|
if (valueChanged) {
|
|
1429
1416
|
originalSetterFunc(...params);
|
|
@@ -1438,7 +1425,7 @@ var __exports__ = (() => {
|
|
|
1438
1425
|
function installProgramSpy(gl) {
|
|
1439
1426
|
const originalUseProgram = gl.useProgram.bind(gl);
|
|
1440
1427
|
gl.useProgram = function useProgramLuma(handle) {
|
|
1441
|
-
const glState =
|
|
1428
|
+
const glState = WebGLStateTracker.get(gl);
|
|
1442
1429
|
if (glState.program !== handle) {
|
|
1443
1430
|
originalUseProgram(handle);
|
|
1444
1431
|
glState.program = handle;
|
|
@@ -1655,26 +1642,6 @@ var __exports__ = (() => {
|
|
|
1655
1642
|
return textureExtensions.every((extension) => getWebGLExtension(gl, extension, extensions));
|
|
1656
1643
|
}
|
|
1657
1644
|
var TEXTURE_FORMATS = {
|
|
1658
|
-
// Unsized formats that leave the precision up to the driver. TODO - Fix bpp constants
|
|
1659
|
-
"rgb8unorm-unsized": {
|
|
1660
|
-
gl: 6407 /* RGB */,
|
|
1661
|
-
b: 4,
|
|
1662
|
-
c: 2,
|
|
1663
|
-
bpp: 4,
|
|
1664
|
-
dataFormat: 6407 /* RGB */,
|
|
1665
|
-
types: [5121 /* UNSIGNED_BYTE */, 33635 /* UNSIGNED_SHORT_5_6_5 */]
|
|
1666
|
-
},
|
|
1667
|
-
"rgba8unorm-unsized": {
|
|
1668
|
-
gl: 6408 /* RGBA */,
|
|
1669
|
-
b: 4,
|
|
1670
|
-
c: 2,
|
|
1671
|
-
bpp: 4,
|
|
1672
|
-
dataFormat: 6408 /* RGBA */,
|
|
1673
|
-
types: [5121 /* UNSIGNED_BYTE */, 32819 /* UNSIGNED_SHORT_4_4_4_4 */, 32820 /* UNSIGNED_SHORT_5_5_5_1 */]
|
|
1674
|
-
},
|
|
1675
|
-
// 'r8unorm-unsized': {gl: GL.LUMINANCE, b: 4, c: 2, bpp: 4},
|
|
1676
|
-
// 'rgb8unorm-srgb-unsized': {gl: GL.SRGB_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
|
|
1677
|
-
// 'rgba8unorm-srgb-unsized': {gl: GL.SRGB_ALPHA_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
|
|
1678
1645
|
// 8-bit formats
|
|
1679
1646
|
"r8unorm": { gl: 33321 /* R8 */, b: 1, c: 1, rb: true },
|
|
1680
1647
|
"r8snorm": { gl: 36756 /* R8_SNORM */, b: 1, c: 1, render: snorm8_renderable },
|
|
@@ -1789,17 +1756,6 @@ var __exports__ = (() => {
|
|
|
1789
1756
|
dataFormat: 34041 /* DEPTH_STENCIL */,
|
|
1790
1757
|
types: [34042 /* UNSIGNED_INT_24_8 */]
|
|
1791
1758
|
},
|
|
1792
|
-
// "depth24unorm-stencil8" feature
|
|
1793
|
-
"depth24unorm-stencil8": {
|
|
1794
|
-
gl: 35056 /* DEPTH24_STENCIL8 */,
|
|
1795
|
-
b: 4,
|
|
1796
|
-
c: 2,
|
|
1797
|
-
p: 1,
|
|
1798
|
-
attachment: 33306 /* DEPTH_STENCIL_ATTACHMENT */,
|
|
1799
|
-
dataFormat: 34041 /* DEPTH_STENCIL */,
|
|
1800
|
-
types: [34042 /* UNSIGNED_INT_24_8 */],
|
|
1801
|
-
rb: true
|
|
1802
|
-
},
|
|
1803
1759
|
// "depth32float-stencil8" feature - TODO below is render buffer only?
|
|
1804
1760
|
"depth32float-stencil8": {
|
|
1805
1761
|
gl: 36013 /* DEPTH32F_STENCIL8 */,
|
|
@@ -1914,6 +1870,10 @@ var __exports__ = (() => {
|
|
|
1914
1870
|
if (info.gl === void 0) {
|
|
1915
1871
|
return false;
|
|
1916
1872
|
}
|
|
1873
|
+
const feature = info.f;
|
|
1874
|
+
if (feature) {
|
|
1875
|
+
return checkTextureFeature(gl, feature, extensions);
|
|
1876
|
+
}
|
|
1917
1877
|
const extension = info.x || info.gl2ext;
|
|
1918
1878
|
if (extension) {
|
|
1919
1879
|
return Boolean(getWebGLExtension(gl, extension, extensions));
|
|
@@ -1958,11 +1918,10 @@ var __exports__ = (() => {
|
|
|
1958
1918
|
const decoded = (0, import_core.decodeTextureFormat)(format);
|
|
1959
1919
|
return {
|
|
1960
1920
|
internalFormat: webglFormat,
|
|
1961
|
-
format: formatData?.dataFormat || getWebGLPixelDataFormat(decoded.
|
|
1921
|
+
format: formatData?.dataFormat || getWebGLPixelDataFormat(decoded.channels, decoded.integer, decoded.normalized, webglFormat),
|
|
1962
1922
|
// depth formats don't have a type
|
|
1963
1923
|
type: decoded.dataType ? getGLFromVertexType(decoded.dataType) : formatData?.types?.[0] || 5121 /* UNSIGNED_BYTE */,
|
|
1964
|
-
|
|
1965
|
-
compressed: decoded.compressed
|
|
1924
|
+
compressed: decoded.compressed || false
|
|
1966
1925
|
};
|
|
1967
1926
|
}
|
|
1968
1927
|
function getDepthStencilAttachmentWebGL(format) {
|
|
@@ -1972,11 +1931,11 @@ var __exports__ = (() => {
|
|
|
1972
1931
|
}
|
|
1973
1932
|
return info.attachment;
|
|
1974
1933
|
}
|
|
1975
|
-
function getWebGLPixelDataFormat(
|
|
1934
|
+
function getWebGLPixelDataFormat(channels, integer, normalized, format) {
|
|
1976
1935
|
if (format === 6408 /* RGBA */ || format === 6407 /* RGB */) {
|
|
1977
1936
|
return format;
|
|
1978
1937
|
}
|
|
1979
|
-
switch (
|
|
1938
|
+
switch (channels) {
|
|
1980
1939
|
case "r":
|
|
1981
1940
|
return integer && !normalized ? 36244 /* RED_INTEGER */ : 6403 /* RED */;
|
|
1982
1941
|
case "rg":
|
|
@@ -1985,6 +1944,8 @@ var __exports__ = (() => {
|
|
|
1985
1944
|
return integer && !normalized ? 36248 /* RGB_INTEGER */ : 6407 /* RGB */;
|
|
1986
1945
|
case "rgba":
|
|
1987
1946
|
return integer && !normalized ? 36249 /* RGBA_INTEGER */ : 6408 /* RGBA */;
|
|
1947
|
+
case "bgra":
|
|
1948
|
+
throw new Error("bgra pixels not supported by WebGL");
|
|
1988
1949
|
default:
|
|
1989
1950
|
return 6408 /* RGBA */;
|
|
1990
1951
|
}
|
|
@@ -2006,7 +1967,6 @@ var __exports__ = (() => {
|
|
|
2006
1967
|
// 'timestamp-query' // GPUQueryType "timestamp-query"
|
|
2007
1968
|
// "indirect-first-instance"
|
|
2008
1969
|
// Textures are handled by getTextureFeatures()
|
|
2009
|
-
// 'depth24unorm-stencil8' // GPUTextureFormat 'depth24unorm-stencil8'
|
|
2010
1970
|
// 'depth32float-stencil8' // GPUTextureFormat 'depth32float-stencil8'
|
|
2011
1971
|
// optional WebGL features
|
|
2012
1972
|
"timer-query-webgl": "EXT_disjoint_timer_query_webgl2",
|
|
@@ -2196,17 +2156,18 @@ var __exports__ = (() => {
|
|
|
2196
2156
|
return func(gl);
|
|
2197
2157
|
}
|
|
2198
2158
|
const { nocatch = true } = parameters;
|
|
2199
|
-
|
|
2159
|
+
const webglState = WebGLStateTracker.get(gl);
|
|
2160
|
+
webglState.push();
|
|
2200
2161
|
setGLParameters(gl, parameters);
|
|
2201
2162
|
let value;
|
|
2202
2163
|
if (nocatch) {
|
|
2203
2164
|
value = func(gl);
|
|
2204
|
-
|
|
2165
|
+
webglState.pop();
|
|
2205
2166
|
} else {
|
|
2206
2167
|
try {
|
|
2207
2168
|
value = func(gl);
|
|
2208
2169
|
} finally {
|
|
2209
|
-
|
|
2170
|
+
webglState.pop();
|
|
2210
2171
|
}
|
|
2211
2172
|
}
|
|
2212
2173
|
return value;
|
|
@@ -2225,25 +2186,26 @@ var __exports__ = (() => {
|
|
|
2225
2186
|
return func(device);
|
|
2226
2187
|
}
|
|
2227
2188
|
const webglDevice = device;
|
|
2228
|
-
|
|
2189
|
+
webglDevice.pushState();
|
|
2229
2190
|
try {
|
|
2230
2191
|
setDeviceParameters(device, parameters);
|
|
2231
2192
|
setGLParameters(webglDevice.gl, glParameters);
|
|
2232
2193
|
return func(device);
|
|
2233
2194
|
} finally {
|
|
2234
|
-
|
|
2195
|
+
webglDevice.popState();
|
|
2235
2196
|
}
|
|
2236
2197
|
}
|
|
2237
2198
|
function withDeviceParameters(device, parameters, func) {
|
|
2238
2199
|
if (isObjectEmpty3(parameters)) {
|
|
2239
2200
|
return func(device);
|
|
2240
2201
|
}
|
|
2241
|
-
|
|
2202
|
+
const webglDevice = device;
|
|
2203
|
+
webglDevice.pushState();
|
|
2242
2204
|
try {
|
|
2243
2205
|
setDeviceParameters(device, parameters);
|
|
2244
2206
|
return func(device);
|
|
2245
2207
|
} finally {
|
|
2246
|
-
|
|
2208
|
+
webglDevice.popState();
|
|
2247
2209
|
}
|
|
2248
2210
|
}
|
|
2249
2211
|
function setDeviceParameters(device, parameters) {
|
|
@@ -2371,8 +2333,16 @@ var __exports__ = (() => {
|
|
|
2371
2333
|
gl.stencilOpSeparate(1028 /* FRONT */, sfail, dpfail, dppass);
|
|
2372
2334
|
gl.stencilOpSeparate(1029 /* BACK */, sfail, dpfail, dppass);
|
|
2373
2335
|
}
|
|
2336
|
+
switch (parameters.blend) {
|
|
2337
|
+
case true:
|
|
2338
|
+
gl.enable(3042 /* BLEND */);
|
|
2339
|
+
break;
|
|
2340
|
+
case false:
|
|
2341
|
+
gl.disable(3042 /* BLEND */);
|
|
2342
|
+
break;
|
|
2343
|
+
default:
|
|
2344
|
+
}
|
|
2374
2345
|
if (parameters.blendColorOperation || parameters.blendAlphaOperation) {
|
|
2375
|
-
gl.enable(3042 /* BLEND */);
|
|
2376
2346
|
const colorEquation = convertBlendOperationToEquation(
|
|
2377
2347
|
"blendColorOperation",
|
|
2378
2348
|
parameters.blendColorOperation || "add"
|
|
@@ -2616,7 +2586,7 @@ var __exports__ = (() => {
|
|
|
2616
2586
|
const { dimension, width, height, depth = 0, level = 0 } = options;
|
|
2617
2587
|
const { x = 0, y = 0, z = 0 } = options;
|
|
2618
2588
|
const { glFormat, glType } = options;
|
|
2619
|
-
const glTarget =
|
|
2589
|
+
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
2620
2590
|
switch (dimension) {
|
|
2621
2591
|
case "2d-array":
|
|
2622
2592
|
case "3d":
|
|
@@ -2634,7 +2604,7 @@ var __exports__ = (() => {
|
|
|
2634
2604
|
const { dimension, width, height, depth = 0, level = 0, byteOffset = 0 } = options;
|
|
2635
2605
|
const { x = 0, y = 0, z = 0 } = options;
|
|
2636
2606
|
const { glFormat, glType, compressed } = options;
|
|
2637
|
-
const glTarget =
|
|
2607
|
+
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
2638
2608
|
switch (dimension) {
|
|
2639
2609
|
case "2d-array":
|
|
2640
2610
|
case "3d":
|
|
@@ -2673,7 +2643,7 @@ var __exports__ = (() => {
|
|
|
2673
2643
|
}
|
|
2674
2644
|
throw new Error(dimension);
|
|
2675
2645
|
}
|
|
2676
|
-
function
|
|
2646
|
+
function getWebGLCubeFaceTarget(glTarget, dimension, level) {
|
|
2677
2647
|
return dimension === "cube" ? 34069 /* TEXTURE_CUBE_MAP_POSITIVE_X */ + level : glTarget;
|
|
2678
2648
|
}
|
|
2679
2649
|
|
|
@@ -2878,7 +2848,7 @@ var __exports__ = (() => {
|
|
|
2878
2848
|
throw new Error("setTexture1DData not supported in WebGL.");
|
|
2879
2849
|
}
|
|
2880
2850
|
/** Set a simple texture */
|
|
2881
|
-
setTexture2DData(lodData, depth = 0
|
|
2851
|
+
setTexture2DData(lodData, depth = 0) {
|
|
2882
2852
|
this.bind();
|
|
2883
2853
|
const lodArray = normalizeTextureData(lodData, this);
|
|
2884
2854
|
if (lodArray.length > 1 && this.props.mipmaps !== false) {
|
|
@@ -2899,7 +2869,9 @@ var __exports__ = (() => {
|
|
|
2899
2869
|
throw new Error(this.id);
|
|
2900
2870
|
}
|
|
2901
2871
|
if (ArrayBuffer.isView(data)) {
|
|
2872
|
+
this.bind();
|
|
2902
2873
|
copyCPUDataToMipLevel(this.device.gl, data, this);
|
|
2874
|
+
this.unbind();
|
|
2903
2875
|
}
|
|
2904
2876
|
}
|
|
2905
2877
|
/**
|
|
@@ -2912,6 +2884,9 @@ var __exports__ = (() => {
|
|
|
2912
2884
|
if (this.props.dimension !== "cube") {
|
|
2913
2885
|
throw new Error(this.id);
|
|
2914
2886
|
}
|
|
2887
|
+
for (const face of import_core7.Texture.CubeFaces) {
|
|
2888
|
+
this.setTextureCubeFaceData(data[face], face);
|
|
2889
|
+
}
|
|
2915
2890
|
}
|
|
2916
2891
|
/**
|
|
2917
2892
|
* Sets an entire texture array
|
|
@@ -2934,8 +2909,8 @@ var __exports__ = (() => {
|
|
|
2934
2909
|
if (Array.isArray(lodData) && lodData.length > 1 && this.props.mipmaps !== false) {
|
|
2935
2910
|
import_core7.log.warn(`${this.id} has mipmap and multiple LODs.`)();
|
|
2936
2911
|
}
|
|
2937
|
-
|
|
2938
|
-
this.
|
|
2912
|
+
const faceDepth = import_core7.Texture.CubeFaces.indexOf(face);
|
|
2913
|
+
this.setTexture2DData(lodData, faceDepth);
|
|
2939
2914
|
}
|
|
2940
2915
|
// INTERNAL METHODS
|
|
2941
2916
|
/** @todo update this method to accept LODs */
|
|
@@ -3073,16 +3048,17 @@ var __exports__ = (() => {
|
|
|
3073
3048
|
* Copy a region of data from a CPU memory buffer into this texture.
|
|
3074
3049
|
* @todo - GLUnpackParameters parameters
|
|
3075
3050
|
*/
|
|
3076
|
-
_setMipLevel(depth, level, textureData,
|
|
3051
|
+
_setMipLevel(depth, level, textureData, glTarget = this.glTarget) {
|
|
3077
3052
|
if (import_core7.Texture.isExternalImage(textureData)) {
|
|
3078
|
-
copyCPUImageToMipLevel(this.device.gl, textureData, { ...this, depth, level });
|
|
3053
|
+
copyCPUImageToMipLevel(this.device.gl, textureData, { ...this, depth, level, glTarget });
|
|
3079
3054
|
return;
|
|
3080
3055
|
}
|
|
3081
3056
|
if (this.isTextureLevelData(textureData)) {
|
|
3082
3057
|
copyCPUDataToMipLevel(this.device.gl, textureData.data, {
|
|
3083
3058
|
...this,
|
|
3084
3059
|
depth,
|
|
3085
|
-
level
|
|
3060
|
+
level,
|
|
3061
|
+
glTarget
|
|
3086
3062
|
});
|
|
3087
3063
|
return;
|
|
3088
3064
|
}
|
|
@@ -3221,7 +3197,7 @@ var __exports__ = (() => {
|
|
|
3221
3197
|
switch (texture.glTarget) {
|
|
3222
3198
|
case 35866 /* TEXTURE_2D_ARRAY */:
|
|
3223
3199
|
case 32879 /* TEXTURE_3D */:
|
|
3224
|
-
gl.framebufferTextureLayer(36160 /* FRAMEBUFFER */, attachment, texture.
|
|
3200
|
+
gl.framebufferTextureLayer(36160 /* FRAMEBUFFER */, attachment, texture.handle, level, layer);
|
|
3225
3201
|
break;
|
|
3226
3202
|
case 34067 /* TEXTURE_CUBE_MAP */:
|
|
3227
3203
|
const face = mapIndexToCubeMapFace(layer);
|
|
@@ -3334,17 +3310,21 @@ var __exports__ = (() => {
|
|
|
3334
3310
|
}
|
|
3335
3311
|
|
|
3336
3312
|
// src/context/debug/spector.ts
|
|
3337
|
-
var DEFAULT_SPECTOR_PROPS = {
|
|
3338
|
-
spector: import_core10.log.get("spector") || import_core10.log.get("inspect")
|
|
3339
|
-
};
|
|
3340
|
-
var SPECTOR_CDN_URL = "https://spectorcdn.babylonjs.com/spector.bundle.js";
|
|
3341
3313
|
var LOG_LEVEL = 1;
|
|
3342
3314
|
var spector = null;
|
|
3343
3315
|
var initialized = false;
|
|
3316
|
+
var DEFAULT_SPECTOR_PROPS = {
|
|
3317
|
+
debugWithSpectorJS: import_core10.log.get("spector") || import_core10.log.get("spectorjs"),
|
|
3318
|
+
// https://github.com/BabylonJS/Spector.js#basic-usage
|
|
3319
|
+
// https://forum.babylonjs.com/t/spectorcdn-is-temporarily-off/48241
|
|
3320
|
+
// spectorUrl: 'https://spectorcdn.babylonjs.com/spector.bundle.js';
|
|
3321
|
+
spectorUrl: "https://cdn.jsdelivr.net/npm/spectorjs@0.9.30/dist/spector.bundle.js",
|
|
3322
|
+
gl: void 0
|
|
3323
|
+
};
|
|
3344
3324
|
async function loadSpectorJS(props) {
|
|
3345
3325
|
if (!globalThis.SPECTOR) {
|
|
3346
3326
|
try {
|
|
3347
|
-
await loadScript(
|
|
3327
|
+
await loadScript(props.spectorUrl || DEFAULT_SPECTOR_PROPS.spectorUrl);
|
|
3348
3328
|
} catch (error) {
|
|
3349
3329
|
import_core10.log.warn(String(error));
|
|
3350
3330
|
}
|
|
@@ -3352,12 +3332,13 @@ var __exports__ = (() => {
|
|
|
3352
3332
|
}
|
|
3353
3333
|
function initializeSpectorJS(props) {
|
|
3354
3334
|
props = { ...DEFAULT_SPECTOR_PROPS, ...props };
|
|
3355
|
-
if (!props
|
|
3335
|
+
if (!props.debugWithSpectorJS) {
|
|
3356
3336
|
return null;
|
|
3357
3337
|
}
|
|
3358
|
-
if (!spector && globalThis.SPECTOR) {
|
|
3359
|
-
import_core10.log.probe(LOG_LEVEL, "SPECTOR found and initialized")();
|
|
3360
|
-
|
|
3338
|
+
if (!spector && globalThis.SPECTOR && !globalThis.luma?.spector) {
|
|
3339
|
+
import_core10.log.probe(LOG_LEVEL, "SPECTOR found and initialized. Start with `luma.spector.displayUI()`")();
|
|
3340
|
+
const { Spector } = globalThis.SPECTOR;
|
|
3341
|
+
spector = new Spector();
|
|
3361
3342
|
if (globalThis.luma) {
|
|
3362
3343
|
globalThis.luma.spector = spector;
|
|
3363
3344
|
}
|
|
@@ -3378,11 +3359,11 @@ var __exports__ = (() => {
|
|
|
3378
3359
|
spector?.resultView.addCapture(capture);
|
|
3379
3360
|
});
|
|
3380
3361
|
}
|
|
3381
|
-
if (props
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3362
|
+
if (props.gl) {
|
|
3363
|
+
const gl = props.gl;
|
|
3364
|
+
const device = gl.device;
|
|
3365
|
+
spector?.startCapture(props.gl, 500);
|
|
3366
|
+
gl.device = device;
|
|
3386
3367
|
new Promise((resolve) => setTimeout(resolve, 2e3)).then((_) => {
|
|
3387
3368
|
import_core10.log.info("Spector capture stopped after 2 seconds")();
|
|
3388
3369
|
spector?.stopCapture();
|
|
@@ -3541,6 +3522,14 @@ var __exports__ = (() => {
|
|
|
3541
3522
|
}
|
|
3542
3523
|
}
|
|
3543
3524
|
|
|
3525
|
+
// src/utils/uid.ts
|
|
3526
|
+
var uidCounters = {};
|
|
3527
|
+
function uid(id = "id") {
|
|
3528
|
+
uidCounters[id] = uidCounters[id] || 1;
|
|
3529
|
+
const count = uidCounters[id]++;
|
|
3530
|
+
return `${id}-${count}`;
|
|
3531
|
+
}
|
|
3532
|
+
|
|
3544
3533
|
// src/adapter/resources/webgl-buffer.ts
|
|
3545
3534
|
var import_core12 = __toESM(require_core(), 1);
|
|
3546
3535
|
var WEBGLBuffer = class extends import_core12.Buffer {
|
|
@@ -3743,8 +3732,8 @@ var __exports__ = (() => {
|
|
|
3743
3732
|
return this.getCompilationInfoSync();
|
|
3744
3733
|
}
|
|
3745
3734
|
getCompilationInfoSync() {
|
|
3746
|
-
const
|
|
3747
|
-
return
|
|
3735
|
+
const log10 = this.device.gl.getShaderInfoLog(this.handle);
|
|
3736
|
+
return log10 ? parseShaderCompilerLog(log10) : [];
|
|
3748
3737
|
}
|
|
3749
3738
|
getTranslatedSource() {
|
|
3750
3739
|
const extensions = this.device.getExtension("WEBGL_debug_shaders");
|
|
@@ -3754,7 +3743,7 @@ var __exports__ = (() => {
|
|
|
3754
3743
|
// PRIVATE METHODS
|
|
3755
3744
|
/** Compile a shader and get compilation status */
|
|
3756
3745
|
async _compile(source) {
|
|
3757
|
-
const addGLSLVersion = (source2) => source2.startsWith("#version ") ? source2 : `#version
|
|
3746
|
+
const addGLSLVersion = (source2) => source2.startsWith("#version ") ? source2 : `#version 300 es
|
|
3758
3747
|
${source2}`;
|
|
3759
3748
|
source = addGLSLVersion(source);
|
|
3760
3749
|
const { gl } = this.device;
|
|
@@ -3819,12 +3808,22 @@ ${source2}`;
|
|
|
3819
3808
|
constructor(device, props) {
|
|
3820
3809
|
super(device, props);
|
|
3821
3810
|
this.device = device;
|
|
3822
|
-
|
|
3823
|
-
|
|
3811
|
+
let viewport;
|
|
3812
|
+
if (!props?.parameters?.viewport) {
|
|
3813
|
+
if (props?.framebuffer) {
|
|
3814
|
+
const { width, height } = props.framebuffer;
|
|
3815
|
+
viewport = [0, 0, width, height];
|
|
3816
|
+
} else {
|
|
3817
|
+
const [width, height] = device.getCanvasContext().getDrawingBufferSize();
|
|
3818
|
+
viewport = [0, 0, width, height];
|
|
3819
|
+
}
|
|
3820
|
+
}
|
|
3821
|
+
this.device.pushState();
|
|
3822
|
+
this.setParameters({ viewport, ...this.props.parameters });
|
|
3824
3823
|
this.clear();
|
|
3825
3824
|
}
|
|
3826
3825
|
end() {
|
|
3827
|
-
|
|
3826
|
+
this.device.popState();
|
|
3828
3827
|
}
|
|
3829
3828
|
pushDebugGroup(groupLabel) {
|
|
3830
3829
|
}
|
|
@@ -4612,7 +4611,8 @@ ${source2}`;
|
|
|
4612
4611
|
const validBindings = this.shaderLayout.bindings.map((binding2) => `"${binding2.name}"`).join(", ");
|
|
4613
4612
|
if (!options?.disableWarnings) {
|
|
4614
4613
|
import_core15.log.warn(
|
|
4615
|
-
`
|
|
4614
|
+
`No binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`,
|
|
4615
|
+
value
|
|
4616
4616
|
)();
|
|
4617
4617
|
}
|
|
4618
4618
|
continue;
|
|
@@ -5716,7 +5716,6 @@ ${source2}`;
|
|
|
5716
5716
|
const {
|
|
5717
5717
|
sourceX = 0,
|
|
5718
5718
|
sourceY = 0,
|
|
5719
|
-
sourceFormat = 6408 /* RGBA */,
|
|
5720
5719
|
sourceAttachment = 36064 /* COLOR_ATTACHMENT0 */
|
|
5721
5720
|
// TODO - support gl.readBuffer
|
|
5722
5721
|
} = options || {};
|
|
@@ -5725,15 +5724,19 @@ ${source2}`;
|
|
|
5725
5724
|
// following parameters are auto deduced if not provided
|
|
5726
5725
|
sourceWidth,
|
|
5727
5726
|
sourceHeight,
|
|
5727
|
+
sourceDepth,
|
|
5728
|
+
sourceFormat,
|
|
5728
5729
|
sourceType
|
|
5729
5730
|
} = options || {};
|
|
5730
5731
|
const { framebuffer, deleteFramebuffer } = getFramebuffer2(source);
|
|
5731
5732
|
const { gl, handle } = framebuffer;
|
|
5732
|
-
sourceWidth = sourceWidth || framebuffer.width;
|
|
5733
|
-
sourceHeight = sourceHeight || framebuffer.height;
|
|
5734
5733
|
const attachment = sourceAttachment - 36064 /* COLOR_ATTACHMENT0 */;
|
|
5735
|
-
|
|
5736
|
-
|
|
5734
|
+
sourceWidth ||= framebuffer.width;
|
|
5735
|
+
sourceHeight ||= framebuffer.height;
|
|
5736
|
+
sourceDepth = framebuffer.colorAttachments[attachment]?.texture?.depth || 1;
|
|
5737
|
+
sourceFormat ||= framebuffer.colorAttachments[attachment]?.texture?.glFormat || 6408 /* RGBA */;
|
|
5738
|
+
sourceType ||= framebuffer.colorAttachments[attachment]?.texture?.glType || 5121 /* UNSIGNED_BYTE */;
|
|
5739
|
+
target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight, sourceDepth);
|
|
5737
5740
|
sourceType = sourceType || getGLTypeFromTypedArray(target);
|
|
5738
5741
|
const prevHandle = gl.bindFramebuffer(36160 /* FRAMEBUFFER */, handle);
|
|
5739
5742
|
gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
|
|
@@ -5796,7 +5799,7 @@ ${source2}`;
|
|
|
5796
5799
|
});
|
|
5797
5800
|
return framebuffer;
|
|
5798
5801
|
}
|
|
5799
|
-
function getPixelArray(pixelArray, type, format, width, height) {
|
|
5802
|
+
function getPixelArray(pixelArray, type, format, width, height, depth) {
|
|
5800
5803
|
if (pixelArray) {
|
|
5801
5804
|
return pixelArray;
|
|
5802
5805
|
}
|
|
@@ -5842,8 +5845,10 @@ ${source2}`;
|
|
|
5842
5845
|
}
|
|
5843
5846
|
|
|
5844
5847
|
// src/adapter/webgl-device.ts
|
|
5845
|
-
var
|
|
5846
|
-
|
|
5848
|
+
var WebGLDevice = class extends import_core22.Device {
|
|
5849
|
+
//
|
|
5850
|
+
// Public `Device` API
|
|
5851
|
+
//
|
|
5847
5852
|
/** type of this device */
|
|
5848
5853
|
type = "webgl";
|
|
5849
5854
|
/** The underlying WebGL context */
|
|
@@ -5854,66 +5859,21 @@ ${source2}`;
|
|
|
5854
5859
|
canvasContext;
|
|
5855
5860
|
lost;
|
|
5856
5861
|
_resolveContextLost;
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5860
|
-
/**
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
}
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
* @param gl
|
|
5868
|
-
* @returns
|
|
5869
|
-
*/
|
|
5870
|
-
static attach(gl) {
|
|
5871
|
-
if (gl instanceof _WebGLDevice) {
|
|
5872
|
-
return gl;
|
|
5873
|
-
}
|
|
5874
|
-
if (gl?.device instanceof import_core22.Device) {
|
|
5875
|
-
return gl.device;
|
|
5876
|
-
}
|
|
5877
|
-
if (!isWebGL(gl)) {
|
|
5878
|
-
throw new Error("Invalid WebGL2RenderingContext");
|
|
5879
|
-
}
|
|
5880
|
-
return new _WebGLDevice({ gl });
|
|
5881
|
-
}
|
|
5882
|
-
static async create(props = {}) {
|
|
5883
|
-
import_core22.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
|
|
5884
|
-
const promises = [];
|
|
5885
|
-
if (props.debug) {
|
|
5886
|
-
promises.push(loadWebGLDeveloperTools());
|
|
5887
|
-
}
|
|
5888
|
-
if (props.spector) {
|
|
5889
|
-
promises.push(loadSpectorJS());
|
|
5890
|
-
}
|
|
5891
|
-
if (typeof props.canvas === "string") {
|
|
5892
|
-
promises.push(import_core22.CanvasContext.pageLoaded);
|
|
5893
|
-
}
|
|
5894
|
-
const results = await Promise.allSettled(promises);
|
|
5895
|
-
for (const result of results) {
|
|
5896
|
-
if (result.status === "rejected") {
|
|
5897
|
-
import_core22.log.error(`Failed to initialize debug libraries ${result.reason}`)();
|
|
5898
|
-
}
|
|
5899
|
-
}
|
|
5900
|
-
import_core22.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
|
|
5901
|
-
if (props.gl?.device) {
|
|
5902
|
-
import_core22.log.warn("reattaching existing device")();
|
|
5903
|
-
return _WebGLDevice.attach(props.gl);
|
|
5904
|
-
}
|
|
5905
|
-
const device = new _WebGLDevice(props);
|
|
5906
|
-
const message2 = `Created ${device.type}${device.debug ? " debug" : ""} context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
|
|
5907
|
-
import_core22.log.probe(LOG_LEVEL2, message2)();
|
|
5908
|
-
import_core22.log.table(LOG_LEVEL2, device.info)();
|
|
5909
|
-
import_core22.log.groupEnd(LOG_LEVEL2)();
|
|
5910
|
-
return device;
|
|
5911
|
-
}
|
|
5862
|
+
/** WebGL2 context. */
|
|
5863
|
+
gl;
|
|
5864
|
+
debug = false;
|
|
5865
|
+
/** State used by luma.gl classes: TODO - move to canvasContext*/
|
|
5866
|
+
_canvasSizeInfo = { clientWidth: 0, clientHeight: 0, devicePixelRatio: 1 };
|
|
5867
|
+
/** State used by luma.gl classes - TODO - not used? */
|
|
5868
|
+
_extensions = {};
|
|
5869
|
+
_polyfilled = false;
|
|
5870
|
+
/** Instance of Spector.js (if initialized) */
|
|
5871
|
+
spectorJS;
|
|
5912
5872
|
//
|
|
5913
5873
|
// Public API
|
|
5914
5874
|
//
|
|
5915
5875
|
constructor(props) {
|
|
5916
|
-
super({ ...props, id: props.id || "webgl-device" });
|
|
5876
|
+
super({ ...props, id: props.id || uid("webgl-device") });
|
|
5917
5877
|
const device = props.gl?.device;
|
|
5918
5878
|
if (device) {
|
|
5919
5879
|
throw new Error(`WebGL context already attached to device ${device.id}`);
|
|
@@ -5923,19 +5883,18 @@ ${source2}`;
|
|
|
5923
5883
|
this.lost = new Promise((resolve) => {
|
|
5924
5884
|
this._resolveContextLost = resolve;
|
|
5925
5885
|
});
|
|
5926
|
-
|
|
5927
|
-
gl ||= createBrowserContext(this.canvasContext.canvas, {
|
|
5886
|
+
this.handle = createBrowserContext(this.canvasContext.canvas, {
|
|
5928
5887
|
...props,
|
|
5929
5888
|
onContextLost: (event) => this._resolveContextLost?.({
|
|
5930
5889
|
reason: "destroyed",
|
|
5931
5890
|
message: "Entered sleep mode, or too many apps or browser tabs are using the GPU."
|
|
5932
5891
|
})
|
|
5933
5892
|
});
|
|
5934
|
-
|
|
5893
|
+
this.gl = this.handle;
|
|
5894
|
+
if (!this.handle) {
|
|
5935
5895
|
throw new Error("WebGL context creation failed");
|
|
5936
5896
|
}
|
|
5937
|
-
this.
|
|
5938
|
-
this.gl = gl;
|
|
5897
|
+
this.spectorJS = initializeSpectorJS({ ...this.props, gl: this.handle });
|
|
5939
5898
|
this.gl.device = this;
|
|
5940
5899
|
this.gl._version = 2;
|
|
5941
5900
|
this.info = getDeviceInfo(this.gl, this._extensions);
|
|
@@ -5945,21 +5904,16 @@ ${source2}`;
|
|
|
5945
5904
|
this.features.initializeFeatures();
|
|
5946
5905
|
}
|
|
5947
5906
|
this.canvasContext.resize();
|
|
5948
|
-
const
|
|
5949
|
-
trackContextState(this.gl, {
|
|
5950
|
-
enable: enable2,
|
|
5951
|
-
copyState,
|
|
5907
|
+
const glState = new WebGLStateTracker(this.gl, {
|
|
5952
5908
|
log: (...args) => import_core22.log.log(1, ...args)()
|
|
5953
5909
|
});
|
|
5910
|
+
glState.trackState(this.gl, { copyState: false });
|
|
5954
5911
|
if (props.debug) {
|
|
5955
5912
|
this.gl = makeDebugContext(this.gl, { ...props, throwOnError: true });
|
|
5956
5913
|
this.debug = true;
|
|
5957
5914
|
import_core22.log.level = Math.max(import_core22.log.level, 1);
|
|
5958
5915
|
import_core22.log.warn("WebGL debug mode activated. Performance reduced.")();
|
|
5959
5916
|
}
|
|
5960
|
-
if (props.spector) {
|
|
5961
|
-
this.spectorJS = initializeSpectorJS({ ...this.props, canvas: this.handle.canvas });
|
|
5962
|
-
}
|
|
5963
5917
|
}
|
|
5964
5918
|
/**
|
|
5965
5919
|
* Destroys the context
|
|
@@ -5970,9 +5924,6 @@ ${source2}`;
|
|
|
5970
5924
|
get isLost() {
|
|
5971
5925
|
return this.gl.isContextLost();
|
|
5972
5926
|
}
|
|
5973
|
-
getSize() {
|
|
5974
|
-
return [this.gl.drawingBufferWidth, this.gl.drawingBufferHeight];
|
|
5975
|
-
}
|
|
5976
5927
|
isTextureFormatSupported(format) {
|
|
5977
5928
|
return isTextureFormatSupported(this.gl, format, this._extensions);
|
|
5978
5929
|
}
|
|
@@ -6070,16 +6021,6 @@ ${source2}`;
|
|
|
6070
6021
|
//
|
|
6071
6022
|
// WebGL-only API (not part of `Device` API)
|
|
6072
6023
|
//
|
|
6073
|
-
/** WebGL2 context. */
|
|
6074
|
-
gl;
|
|
6075
|
-
debug = false;
|
|
6076
|
-
/** State used by luma.gl classes: TODO - move to canvasContext*/
|
|
6077
|
-
_canvasSizeInfo = { clientWidth: 0, clientHeight: 0, devicePixelRatio: 1 };
|
|
6078
|
-
/** State used by luma.gl classes - TODO - not used? */
|
|
6079
|
-
_extensions = {};
|
|
6080
|
-
_polyfilled = false;
|
|
6081
|
-
/** Instance of Spector.js (if initialized) */
|
|
6082
|
-
spectorJS;
|
|
6083
6024
|
/**
|
|
6084
6025
|
* Triggers device (or WebGL context) loss.
|
|
6085
6026
|
* @note primarily intended for testing how application reacts to device loss
|
|
@@ -6100,11 +6041,13 @@ ${source2}`;
|
|
|
6100
6041
|
}
|
|
6101
6042
|
/** Save current WebGL context state onto an internal stack */
|
|
6102
6043
|
pushState() {
|
|
6103
|
-
|
|
6044
|
+
const webglState = WebGLStateTracker.get(this.gl);
|
|
6045
|
+
webglState.push();
|
|
6104
6046
|
}
|
|
6105
6047
|
/** Restores previously saved context state */
|
|
6106
6048
|
popState() {
|
|
6107
|
-
|
|
6049
|
+
const webglState = WebGLStateTracker.get(this.gl);
|
|
6050
|
+
webglState.pop();
|
|
6108
6051
|
}
|
|
6109
6052
|
/**
|
|
6110
6053
|
* Storing data on a special field on WebGLObjects makes that data visible in SPECTOR chrome debug extension
|
|
@@ -6167,18 +6110,6 @@ ${source2}`;
|
|
|
6167
6110
|
return this._extensions;
|
|
6168
6111
|
}
|
|
6169
6112
|
};
|
|
6170
|
-
var WebGLDevice = _WebGLDevice;
|
|
6171
|
-
//
|
|
6172
|
-
// Public `Device` API
|
|
6173
|
-
//
|
|
6174
|
-
/** type of this device */
|
|
6175
|
-
__publicField(WebGLDevice, "type", "webgl");
|
|
6176
|
-
function isWebGL(gl) {
|
|
6177
|
-
if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
|
|
6178
|
-
return true;
|
|
6179
|
-
}
|
|
6180
|
-
return Boolean(gl && Number.isFinite(gl._version));
|
|
6181
|
-
}
|
|
6182
6113
|
function setConstantFloatArray(device, location, array) {
|
|
6183
6114
|
switch (array.length) {
|
|
6184
6115
|
case 1:
|
|
@@ -6213,6 +6144,181 @@ ${source2}`;
|
|
|
6213
6144
|
}
|
|
6214
6145
|
return true;
|
|
6215
6146
|
}
|
|
6147
|
+
|
|
6148
|
+
// src/context/polyfills/polyfill-webgl1-extensions.ts
|
|
6149
|
+
var WEBGL1_STATIC_EXTENSIONS = {
|
|
6150
|
+
WEBGL_depth_texture: {
|
|
6151
|
+
UNSIGNED_INT_24_8_WEBGL: 34042 /* UNSIGNED_INT_24_8 */
|
|
6152
|
+
},
|
|
6153
|
+
OES_element_index_uint: {},
|
|
6154
|
+
OES_texture_float: {},
|
|
6155
|
+
OES_texture_half_float: {
|
|
6156
|
+
// @ts-expect-error different numbers?
|
|
6157
|
+
HALF_FLOAT_OES: 5131 /* HALF_FLOAT */
|
|
6158
|
+
},
|
|
6159
|
+
EXT_color_buffer_float: {},
|
|
6160
|
+
OES_standard_derivatives: {
|
|
6161
|
+
FRAGMENT_SHADER_DERIVATIVE_HINT_OES: 35723 /* FRAGMENT_SHADER_DERIVATIVE_HINT */
|
|
6162
|
+
},
|
|
6163
|
+
EXT_frag_depth: {},
|
|
6164
|
+
EXT_blend_minmax: {
|
|
6165
|
+
MIN_EXT: 32775 /* MIN */,
|
|
6166
|
+
MAX_EXT: 32776 /* MAX */
|
|
6167
|
+
},
|
|
6168
|
+
EXT_shader_texture_lod: {}
|
|
6169
|
+
};
|
|
6170
|
+
var getWEBGL_draw_buffers = (gl) => ({
|
|
6171
|
+
drawBuffersWEBGL(buffers) {
|
|
6172
|
+
return gl.drawBuffers(buffers);
|
|
6173
|
+
},
|
|
6174
|
+
COLOR_ATTACHMENT0_WEBGL: 36064 /* COLOR_ATTACHMENT0 */,
|
|
6175
|
+
COLOR_ATTACHMENT1_WEBGL: 36065 /* COLOR_ATTACHMENT1 */,
|
|
6176
|
+
COLOR_ATTACHMENT2_WEBGL: 36066 /* COLOR_ATTACHMENT2 */,
|
|
6177
|
+
COLOR_ATTACHMENT3_WEBGL: 36067 /* COLOR_ATTACHMENT3 */
|
|
6178
|
+
});
|
|
6179
|
+
var getOES_vertex_array_object = (gl) => ({
|
|
6180
|
+
VERTEX_ARRAY_BINDING_OES: 34229 /* VERTEX_ARRAY_BINDING */,
|
|
6181
|
+
createVertexArrayOES() {
|
|
6182
|
+
return gl.createVertexArray();
|
|
6183
|
+
},
|
|
6184
|
+
deleteVertexArrayOES(vertexArray) {
|
|
6185
|
+
return gl.deleteVertexArray(vertexArray);
|
|
6186
|
+
},
|
|
6187
|
+
isVertexArrayOES(vertexArray) {
|
|
6188
|
+
return gl.isVertexArray(vertexArray);
|
|
6189
|
+
},
|
|
6190
|
+
bindVertexArrayOES(vertexArray) {
|
|
6191
|
+
return gl.bindVertexArray(vertexArray);
|
|
6192
|
+
}
|
|
6193
|
+
});
|
|
6194
|
+
var getANGLE_instanced_arrays = (gl) => ({
|
|
6195
|
+
VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE: 35070,
|
|
6196
|
+
drawArraysInstancedANGLE(...args) {
|
|
6197
|
+
return gl.drawArraysInstanced(...args);
|
|
6198
|
+
},
|
|
6199
|
+
drawElementsInstancedANGLE(...args) {
|
|
6200
|
+
return gl.drawElementsInstanced(...args);
|
|
6201
|
+
},
|
|
6202
|
+
vertexAttribDivisorANGLE(...args) {
|
|
6203
|
+
return gl.vertexAttribDivisor(...args);
|
|
6204
|
+
}
|
|
6205
|
+
});
|
|
6206
|
+
function enforceWebGL2(enforce = true) {
|
|
6207
|
+
const prototype = HTMLCanvasElement.prototype;
|
|
6208
|
+
if (!enforce && prototype.originalGetContext) {
|
|
6209
|
+
prototype.getContext = prototype.originalGetContext;
|
|
6210
|
+
prototype.originalGetContext = void 0;
|
|
6211
|
+
return;
|
|
6212
|
+
}
|
|
6213
|
+
prototype.originalGetContext = prototype.getContext;
|
|
6214
|
+
prototype.getContext = function(contextId, options) {
|
|
6215
|
+
if (contextId === "webgl" || contextId === "experimental-webgl") {
|
|
6216
|
+
const context = this.originalGetContext("webgl2", options);
|
|
6217
|
+
if (context instanceof HTMLElement) {
|
|
6218
|
+
polyfillWebGL1Extensions(context);
|
|
6219
|
+
}
|
|
6220
|
+
return context;
|
|
6221
|
+
}
|
|
6222
|
+
return this.originalGetContext(contextId, options);
|
|
6223
|
+
};
|
|
6224
|
+
}
|
|
6225
|
+
function polyfillWebGL1Extensions(gl) {
|
|
6226
|
+
gl.getExtension("EXT_color_buffer_float");
|
|
6227
|
+
const boundExtensions = {
|
|
6228
|
+
...WEBGL1_STATIC_EXTENSIONS,
|
|
6229
|
+
WEBGL_disjoint_timer_query: gl.getExtension("EXT_disjoint_timer_query_webgl2"),
|
|
6230
|
+
WEBGL_draw_buffers: getWEBGL_draw_buffers(gl),
|
|
6231
|
+
OES_vertex_array_object: getOES_vertex_array_object(gl),
|
|
6232
|
+
ANGLE_instanced_arrays: getANGLE_instanced_arrays(gl)
|
|
6233
|
+
};
|
|
6234
|
+
const originalGetExtension = gl.getExtension;
|
|
6235
|
+
gl.getExtension = function(extensionName) {
|
|
6236
|
+
const ext = originalGetExtension.call(gl, extensionName);
|
|
6237
|
+
if (ext) {
|
|
6238
|
+
return ext;
|
|
6239
|
+
}
|
|
6240
|
+
if (extensionName in boundExtensions) {
|
|
6241
|
+
return boundExtensions[extensionName];
|
|
6242
|
+
}
|
|
6243
|
+
return null;
|
|
6244
|
+
};
|
|
6245
|
+
const originalGetSupportedExtensions = gl.getSupportedExtensions;
|
|
6246
|
+
gl.getSupportedExtensions = function() {
|
|
6247
|
+
const extensions = originalGetSupportedExtensions.apply(gl) || [];
|
|
6248
|
+
return extensions?.concat(Object.keys(boundExtensions));
|
|
6249
|
+
};
|
|
6250
|
+
}
|
|
6251
|
+
|
|
6252
|
+
// src/adapter/webgl-adapter.ts
|
|
6253
|
+
var LOG_LEVEL2 = 1;
|
|
6254
|
+
var WebGLAdapter = class extends import_core23.Adapter {
|
|
6255
|
+
/** type of device's created by this adapter */
|
|
6256
|
+
type = "webgl";
|
|
6257
|
+
constructor() {
|
|
6258
|
+
super();
|
|
6259
|
+
import_core23.Device.defaultProps = { ...import_core23.Device.defaultProps, ...DEFAULT_SPECTOR_PROPS };
|
|
6260
|
+
WebGLDevice.adapter = this;
|
|
6261
|
+
}
|
|
6262
|
+
/** Check if WebGL 2 is available */
|
|
6263
|
+
isSupported() {
|
|
6264
|
+
return typeof WebGL2RenderingContext !== "undefined";
|
|
6265
|
+
}
|
|
6266
|
+
/** Force any created WebGL contexts to be WebGL2 contexts, polyfilled with WebGL1 extensions */
|
|
6267
|
+
enforceWebGL2(enable2) {
|
|
6268
|
+
enforceWebGL2(enable2);
|
|
6269
|
+
}
|
|
6270
|
+
/**
|
|
6271
|
+
* Get a device instance from a GL context
|
|
6272
|
+
* Creates and instruments the device if not already created
|
|
6273
|
+
* @param gl
|
|
6274
|
+
* @returns
|
|
6275
|
+
*/
|
|
6276
|
+
async attach(gl) {
|
|
6277
|
+
if (gl instanceof WebGLDevice) {
|
|
6278
|
+
return gl;
|
|
6279
|
+
}
|
|
6280
|
+
if (gl?.device instanceof import_core23.Device) {
|
|
6281
|
+
return gl.device;
|
|
6282
|
+
}
|
|
6283
|
+
if (!isWebGL(gl)) {
|
|
6284
|
+
throw new Error("Invalid WebGL2RenderingContext");
|
|
6285
|
+
}
|
|
6286
|
+
return new WebGLDevice({ gl });
|
|
6287
|
+
}
|
|
6288
|
+
async create(props = {}) {
|
|
6289
|
+
import_core23.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
|
|
6290
|
+
const promises = [];
|
|
6291
|
+
if (props.debug) {
|
|
6292
|
+
promises.push(loadWebGLDeveloperTools());
|
|
6293
|
+
}
|
|
6294
|
+
if (props.debugWithSpectorJS) {
|
|
6295
|
+
promises.push(loadSpectorJS(props));
|
|
6296
|
+
}
|
|
6297
|
+
if (typeof props.canvas === "string") {
|
|
6298
|
+
promises.push(import_core23.CanvasContext.pageLoaded);
|
|
6299
|
+
}
|
|
6300
|
+
const results = await Promise.allSettled(promises);
|
|
6301
|
+
for (const result of results) {
|
|
6302
|
+
if (result.status === "rejected") {
|
|
6303
|
+
import_core23.log.error(`Failed to initialize debug libraries ${result.reason}`)();
|
|
6304
|
+
}
|
|
6305
|
+
}
|
|
6306
|
+
import_core23.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
|
|
6307
|
+
const device = new WebGLDevice(props);
|
|
6308
|
+
const message2 = `Created ${device.type}${device.debug ? " debug" : ""} context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
|
|
6309
|
+
import_core23.log.probe(LOG_LEVEL2, message2)();
|
|
6310
|
+
import_core23.log.table(LOG_LEVEL2, device.info)();
|
|
6311
|
+
import_core23.log.groupEnd(LOG_LEVEL2)();
|
|
6312
|
+
return device;
|
|
6313
|
+
}
|
|
6314
|
+
};
|
|
6315
|
+
function isWebGL(gl) {
|
|
6316
|
+
if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
|
|
6317
|
+
return true;
|
|
6318
|
+
}
|
|
6319
|
+
return Boolean(gl && Number.isFinite(gl._version));
|
|
6320
|
+
}
|
|
6321
|
+
var webgl2Adapter = new WebGLAdapter();
|
|
6216
6322
|
return __toCommonJS(bundle_exports);
|
|
6217
6323
|
})();
|
|
6218
6324
|
return __exports__;
|