@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/index.cjs
CHANGED
|
@@ -2,7 +2,6 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
5
|
var __export = (target, all) => {
|
|
7
6
|
for (var name in all)
|
|
8
7
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16,10 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
15
|
return to;
|
|
17
16
|
};
|
|
18
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var __publicField = (obj, key, value) => {
|
|
20
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
23
18
|
|
|
24
19
|
// dist/index.js
|
|
25
20
|
var dist_exports = {};
|
|
@@ -37,20 +32,22 @@ __export(dist_exports, {
|
|
|
37
32
|
WEBGLVertexArray: () => WEBGLVertexArray,
|
|
38
33
|
WebGLCanvasContext: () => WebGLCanvasContext,
|
|
39
34
|
WebGLDevice: () => WebGLDevice,
|
|
35
|
+
WebGLStateTracker: () => WebGLStateTracker,
|
|
40
36
|
_TEXTURE_FORMATS: () => TEXTURE_FORMATS,
|
|
41
37
|
getGLParameters: () => getGLParameters,
|
|
42
38
|
getShaderLayout: () => getShaderLayout,
|
|
43
|
-
popContextState: () => popContextState,
|
|
44
|
-
pushContextState: () => pushContextState,
|
|
45
39
|
resetGLParameters: () => resetGLParameters,
|
|
46
40
|
setDeviceParameters: () => setDeviceParameters,
|
|
47
41
|
setGLParameters: () => setGLParameters,
|
|
48
|
-
|
|
42
|
+
webgl2Adapter: () => webgl2Adapter,
|
|
49
43
|
withDeviceParameters: () => withDeviceParameters,
|
|
50
44
|
withGLParameters: () => withGLParameters
|
|
51
45
|
});
|
|
52
46
|
module.exports = __toCommonJS(dist_exports);
|
|
53
47
|
|
|
48
|
+
// dist/adapter/webgl-adapter.js
|
|
49
|
+
var import_core23 = require("@luma.gl/core");
|
|
50
|
+
|
|
54
51
|
// dist/adapter/webgl-device.js
|
|
55
52
|
var import_core22 = require("@luma.gl/core");
|
|
56
53
|
|
|
@@ -594,24 +591,22 @@ function deepArrayEqual(x, y) {
|
|
|
594
591
|
return false;
|
|
595
592
|
}
|
|
596
593
|
|
|
597
|
-
// dist/context/state-tracker/
|
|
598
|
-
var
|
|
594
|
+
// dist/context/state-tracker/webgl-state-tracker.js
|
|
595
|
+
var WebGLStateTracker = class {
|
|
596
|
+
static get(gl) {
|
|
597
|
+
return gl.state;
|
|
598
|
+
}
|
|
599
599
|
gl;
|
|
600
600
|
program = null;
|
|
601
601
|
stateStack = [];
|
|
602
602
|
enable = true;
|
|
603
|
-
cache;
|
|
603
|
+
cache = null;
|
|
604
604
|
log;
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
// Copy cache from params (slow) or initialize from WebGL defaults (fast)
|
|
608
|
-
log: log9 = () => {
|
|
609
|
-
}
|
|
610
|
-
// Logging function, called when gl parameter change calls are actually issued
|
|
611
|
-
} = {}) {
|
|
605
|
+
initialized = false;
|
|
606
|
+
constructor(gl, props) {
|
|
612
607
|
this.gl = gl;
|
|
613
|
-
this.
|
|
614
|
-
|
|
608
|
+
this.log = (props == null ? void 0 : props.log) || (() => {
|
|
609
|
+
});
|
|
615
610
|
this._updateCache = this._updateCache.bind(this);
|
|
616
611
|
Object.seal(this);
|
|
617
612
|
}
|
|
@@ -623,6 +618,29 @@ var GLState = class {
|
|
|
623
618
|
setGLParameters(this.gl, oldValues);
|
|
624
619
|
this.stateStack.pop();
|
|
625
620
|
}
|
|
621
|
+
/**
|
|
622
|
+
* Initialize WebGL state caching on a context
|
|
623
|
+
* can be called multiple times to enable/disable
|
|
624
|
+
*
|
|
625
|
+
* @note After calling this function, context state will be cached
|
|
626
|
+
* .push() and .pop() will be available for saving,
|
|
627
|
+
* temporarily modifying, and then restoring state.
|
|
628
|
+
*/
|
|
629
|
+
trackState(gl, options) {
|
|
630
|
+
this.cache = options.copyState ? getGLParameters(gl) : Object.assign({}, GL_PARAMETER_DEFAULTS);
|
|
631
|
+
if (this.initialized) {
|
|
632
|
+
throw new Error("WebGLStateTracker");
|
|
633
|
+
}
|
|
634
|
+
this.initialized = true;
|
|
635
|
+
this.gl.state = this;
|
|
636
|
+
installProgramSpy(gl);
|
|
637
|
+
for (const key in GL_HOOKED_SETTERS) {
|
|
638
|
+
const setter = GL_HOOKED_SETTERS[key];
|
|
639
|
+
installSetterSpy(gl, key, setter);
|
|
640
|
+
}
|
|
641
|
+
installGetterOverride(gl, "getParameter");
|
|
642
|
+
installGetterOverride(gl, "isEnabled");
|
|
643
|
+
}
|
|
626
644
|
/**
|
|
627
645
|
// interceptor for context set functions - update our cache and our stack
|
|
628
646
|
// values (Object) - the key values for this setter
|
|
@@ -648,44 +666,13 @@ var GLState = class {
|
|
|
648
666
|
return { valueChanged, oldValue };
|
|
649
667
|
}
|
|
650
668
|
};
|
|
651
|
-
function getContextState(gl) {
|
|
652
|
-
return gl.state;
|
|
653
|
-
}
|
|
654
|
-
function trackContextState(gl, options) {
|
|
655
|
-
const { enable: enable2 = true, copyState } = options || {};
|
|
656
|
-
if (!gl.state) {
|
|
657
|
-
gl.state = new GLState(gl, { copyState });
|
|
658
|
-
installProgramSpy(gl);
|
|
659
|
-
for (const key in GL_HOOKED_SETTERS) {
|
|
660
|
-
const setter = GL_HOOKED_SETTERS[key];
|
|
661
|
-
installSetterSpy(gl, key, setter);
|
|
662
|
-
}
|
|
663
|
-
installGetterOverride(gl, "getParameter");
|
|
664
|
-
installGetterOverride(gl, "isEnabled");
|
|
665
|
-
}
|
|
666
|
-
const glState = getContextState(gl);
|
|
667
|
-
glState.enable = enable2;
|
|
668
|
-
return gl;
|
|
669
|
-
}
|
|
670
|
-
function pushContextState(gl) {
|
|
671
|
-
let glState = getContextState(gl);
|
|
672
|
-
if (!glState) {
|
|
673
|
-
trackContextState(gl, { copyState: false });
|
|
674
|
-
glState = getContextState(gl);
|
|
675
|
-
}
|
|
676
|
-
glState.push();
|
|
677
|
-
}
|
|
678
|
-
function popContextState(gl) {
|
|
679
|
-
const glState = getContextState(gl);
|
|
680
|
-
glState.pop();
|
|
681
|
-
}
|
|
682
669
|
function installGetterOverride(gl, functionName) {
|
|
683
670
|
const originalGetterFunc = gl[functionName].bind(gl);
|
|
684
671
|
gl[functionName] = function get(pname) {
|
|
685
672
|
if (pname === void 0 || NON_CACHE_PARAMETERS.has(pname)) {
|
|
686
673
|
return originalGetterFunc(pname);
|
|
687
674
|
}
|
|
688
|
-
const glState =
|
|
675
|
+
const glState = WebGLStateTracker.get(gl);
|
|
689
676
|
if (!(pname in glState.cache)) {
|
|
690
677
|
glState.cache[pname] = originalGetterFunc(pname);
|
|
691
678
|
}
|
|
@@ -708,7 +695,7 @@ function installSetterSpy(gl, functionName, setter) {
|
|
|
708
695
|
}
|
|
709
696
|
const originalSetterFunc = gl[functionName].bind(gl);
|
|
710
697
|
gl[functionName] = function set(...params) {
|
|
711
|
-
const glState =
|
|
698
|
+
const glState = WebGLStateTracker.get(gl);
|
|
712
699
|
const { valueChanged, oldValue } = setter(glState._updateCache, ...params);
|
|
713
700
|
if (valueChanged) {
|
|
714
701
|
originalSetterFunc(...params);
|
|
@@ -723,7 +710,7 @@ function installSetterSpy(gl, functionName, setter) {
|
|
|
723
710
|
function installProgramSpy(gl) {
|
|
724
711
|
const originalUseProgram = gl.useProgram.bind(gl);
|
|
725
712
|
gl.useProgram = function useProgramLuma(handle) {
|
|
726
|
-
const glState =
|
|
713
|
+
const glState = WebGLStateTracker.get(gl);
|
|
727
714
|
if (glState.program !== handle) {
|
|
728
715
|
originalUseProgram(handle);
|
|
729
716
|
glState.program = handle;
|
|
@@ -941,26 +928,6 @@ function checkTextureFeature(gl, feature, extensions) {
|
|
|
941
928
|
return textureExtensions.every((extension) => getWebGLExtension(gl, extension, extensions));
|
|
942
929
|
}
|
|
943
930
|
var TEXTURE_FORMATS = {
|
|
944
|
-
// Unsized formats that leave the precision up to the driver. TODO - Fix bpp constants
|
|
945
|
-
"rgb8unorm-unsized": {
|
|
946
|
-
gl: 6407,
|
|
947
|
-
b: 4,
|
|
948
|
-
c: 2,
|
|
949
|
-
bpp: 4,
|
|
950
|
-
dataFormat: 6407,
|
|
951
|
-
types: [5121, 33635]
|
|
952
|
-
},
|
|
953
|
-
"rgba8unorm-unsized": {
|
|
954
|
-
gl: 6408,
|
|
955
|
-
b: 4,
|
|
956
|
-
c: 2,
|
|
957
|
-
bpp: 4,
|
|
958
|
-
dataFormat: 6408,
|
|
959
|
-
types: [5121, 32819, 32820]
|
|
960
|
-
},
|
|
961
|
-
// 'r8unorm-unsized': {gl: GL.LUMINANCE, b: 4, c: 2, bpp: 4},
|
|
962
|
-
// 'rgb8unorm-srgb-unsized': {gl: GL.SRGB_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
|
|
963
|
-
// 'rgba8unorm-srgb-unsized': {gl: GL.SRGB_ALPHA_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
|
|
964
931
|
// 8-bit formats
|
|
965
932
|
"r8unorm": { gl: 33321, b: 1, c: 1, rb: true },
|
|
966
933
|
"r8snorm": { gl: 36756, b: 1, c: 1, render: snorm8_renderable },
|
|
@@ -1075,17 +1042,6 @@ var TEXTURE_FORMATS = {
|
|
|
1075
1042
|
dataFormat: 34041,
|
|
1076
1043
|
types: [34042]
|
|
1077
1044
|
},
|
|
1078
|
-
// "depth24unorm-stencil8" feature
|
|
1079
|
-
"depth24unorm-stencil8": {
|
|
1080
|
-
gl: 35056,
|
|
1081
|
-
b: 4,
|
|
1082
|
-
c: 2,
|
|
1083
|
-
p: 1,
|
|
1084
|
-
attachment: 33306,
|
|
1085
|
-
dataFormat: 34041,
|
|
1086
|
-
types: [34042],
|
|
1087
|
-
rb: true
|
|
1088
|
-
},
|
|
1089
1045
|
// "depth32float-stencil8" feature - TODO below is render buffer only?
|
|
1090
1046
|
"depth32float-stencil8": {
|
|
1091
1047
|
gl: 36013,
|
|
@@ -1175,6 +1131,10 @@ function isTextureFormatSupported(gl, format, extensions) {
|
|
|
1175
1131
|
if (info.gl === void 0) {
|
|
1176
1132
|
return false;
|
|
1177
1133
|
}
|
|
1134
|
+
const feature = info.f;
|
|
1135
|
+
if (feature) {
|
|
1136
|
+
return checkTextureFeature(gl, feature, extensions);
|
|
1137
|
+
}
|
|
1178
1138
|
const extension = info.x || info.gl2ext;
|
|
1179
1139
|
if (extension) {
|
|
1180
1140
|
return Boolean(getWebGLExtension(gl, extension, extensions));
|
|
@@ -1220,11 +1180,10 @@ function getTextureFormatWebGL(format) {
|
|
|
1220
1180
|
const decoded = (0, import_core.decodeTextureFormat)(format);
|
|
1221
1181
|
return {
|
|
1222
1182
|
internalFormat: webglFormat,
|
|
1223
|
-
format: (formatData == null ? void 0 : formatData.dataFormat) || getWebGLPixelDataFormat(decoded.
|
|
1183
|
+
format: (formatData == null ? void 0 : formatData.dataFormat) || getWebGLPixelDataFormat(decoded.channels, decoded.integer, decoded.normalized, webglFormat),
|
|
1224
1184
|
// depth formats don't have a type
|
|
1225
1185
|
type: decoded.dataType ? getGLFromVertexType(decoded.dataType) : ((_a = formatData == null ? void 0 : formatData.types) == null ? void 0 : _a[0]) || 5121,
|
|
1226
|
-
|
|
1227
|
-
compressed: decoded.compressed
|
|
1186
|
+
compressed: decoded.compressed || false
|
|
1228
1187
|
};
|
|
1229
1188
|
}
|
|
1230
1189
|
function getDepthStencilAttachmentWebGL(format) {
|
|
@@ -1234,11 +1193,11 @@ function getDepthStencilAttachmentWebGL(format) {
|
|
|
1234
1193
|
}
|
|
1235
1194
|
return info.attachment;
|
|
1236
1195
|
}
|
|
1237
|
-
function getWebGLPixelDataFormat(
|
|
1196
|
+
function getWebGLPixelDataFormat(channels, integer, normalized, format) {
|
|
1238
1197
|
if (format === 6408 || format === 6407) {
|
|
1239
1198
|
return format;
|
|
1240
1199
|
}
|
|
1241
|
-
switch (
|
|
1200
|
+
switch (channels) {
|
|
1242
1201
|
case "r":
|
|
1243
1202
|
return integer && !normalized ? 36244 : 6403;
|
|
1244
1203
|
case "rg":
|
|
@@ -1247,6 +1206,8 @@ function getWebGLPixelDataFormat(dataFormat, integer, normalized, format) {
|
|
|
1247
1206
|
return integer && !normalized ? 36248 : 6407;
|
|
1248
1207
|
case "rgba":
|
|
1249
1208
|
return integer && !normalized ? 36249 : 6408;
|
|
1209
|
+
case "bgra":
|
|
1210
|
+
throw new Error("bgra pixels not supported by WebGL");
|
|
1250
1211
|
default:
|
|
1251
1212
|
return 6408;
|
|
1252
1213
|
}
|
|
@@ -1268,7 +1229,6 @@ var WEBGL_FEATURES = {
|
|
|
1268
1229
|
// 'timestamp-query' // GPUQueryType "timestamp-query"
|
|
1269
1230
|
// "indirect-first-instance"
|
|
1270
1231
|
// Textures are handled by getTextureFeatures()
|
|
1271
|
-
// 'depth24unorm-stencil8' // GPUTextureFormat 'depth24unorm-stencil8'
|
|
1272
1232
|
// 'depth32float-stencil8' // GPUTextureFormat 'depth32float-stencil8'
|
|
1273
1233
|
// optional WebGL features
|
|
1274
1234
|
"timer-query-webgl": "EXT_disjoint_timer_query_webgl2",
|
|
@@ -1462,17 +1422,18 @@ function withGLParameters(gl, parameters, func) {
|
|
|
1462
1422
|
return func(gl);
|
|
1463
1423
|
}
|
|
1464
1424
|
const { nocatch = true } = parameters;
|
|
1465
|
-
|
|
1425
|
+
const webglState = WebGLStateTracker.get(gl);
|
|
1426
|
+
webglState.push();
|
|
1466
1427
|
setGLParameters(gl, parameters);
|
|
1467
1428
|
let value;
|
|
1468
1429
|
if (nocatch) {
|
|
1469
1430
|
value = func(gl);
|
|
1470
|
-
|
|
1431
|
+
webglState.pop();
|
|
1471
1432
|
} else {
|
|
1472
1433
|
try {
|
|
1473
1434
|
value = func(gl);
|
|
1474
1435
|
} finally {
|
|
1475
|
-
|
|
1436
|
+
webglState.pop();
|
|
1476
1437
|
}
|
|
1477
1438
|
}
|
|
1478
1439
|
return value;
|
|
@@ -1495,25 +1456,26 @@ function withDeviceAndGLParameters(device, parameters, glParameters, func) {
|
|
|
1495
1456
|
return func(device);
|
|
1496
1457
|
}
|
|
1497
1458
|
const webglDevice = device;
|
|
1498
|
-
|
|
1459
|
+
webglDevice.pushState();
|
|
1499
1460
|
try {
|
|
1500
1461
|
setDeviceParameters(device, parameters);
|
|
1501
1462
|
setGLParameters(webglDevice.gl, glParameters);
|
|
1502
1463
|
return func(device);
|
|
1503
1464
|
} finally {
|
|
1504
|
-
|
|
1465
|
+
webglDevice.popState();
|
|
1505
1466
|
}
|
|
1506
1467
|
}
|
|
1507
1468
|
function withDeviceParameters(device, parameters, func) {
|
|
1508
1469
|
if (isObjectEmpty3(parameters)) {
|
|
1509
1470
|
return func(device);
|
|
1510
1471
|
}
|
|
1511
|
-
|
|
1472
|
+
const webglDevice = device;
|
|
1473
|
+
webglDevice.pushState();
|
|
1512
1474
|
try {
|
|
1513
1475
|
setDeviceParameters(device, parameters);
|
|
1514
1476
|
return func(device);
|
|
1515
1477
|
} finally {
|
|
1516
|
-
|
|
1478
|
+
webglDevice.popState();
|
|
1517
1479
|
}
|
|
1518
1480
|
}
|
|
1519
1481
|
function setDeviceParameters(device, parameters) {
|
|
@@ -1632,8 +1594,16 @@ function setDeviceParameters(device, parameters) {
|
|
|
1632
1594
|
gl.stencilOpSeparate(1028, sfail, dpfail, dppass);
|
|
1633
1595
|
gl.stencilOpSeparate(1029, sfail, dpfail, dppass);
|
|
1634
1596
|
}
|
|
1597
|
+
switch (parameters.blend) {
|
|
1598
|
+
case true:
|
|
1599
|
+
gl.enable(3042);
|
|
1600
|
+
break;
|
|
1601
|
+
case false:
|
|
1602
|
+
gl.disable(3042);
|
|
1603
|
+
break;
|
|
1604
|
+
default:
|
|
1605
|
+
}
|
|
1635
1606
|
if (parameters.blendColorOperation || parameters.blendAlphaOperation) {
|
|
1636
|
-
gl.enable(3042);
|
|
1637
1607
|
const colorEquation = convertBlendOperationToEquation("blendColorOperation", parameters.blendColorOperation || "add");
|
|
1638
1608
|
const alphaEquation = convertBlendOperationToEquation("blendAlphaOperation", parameters.blendAlphaOperation || "add");
|
|
1639
1609
|
gl.blendEquationSeparate(colorEquation, alphaEquation);
|
|
@@ -1858,7 +1828,7 @@ function copyCPUImageToMipLevel(gl, image, options) {
|
|
|
1858
1828
|
const { dimension, width, height, depth = 0, level = 0 } = options;
|
|
1859
1829
|
const { x = 0, y = 0, z = 0 } = options;
|
|
1860
1830
|
const { glFormat, glType } = options;
|
|
1861
|
-
const glTarget =
|
|
1831
|
+
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
1862
1832
|
switch (dimension) {
|
|
1863
1833
|
case "2d-array":
|
|
1864
1834
|
case "3d":
|
|
@@ -1876,7 +1846,7 @@ function copyCPUDataToMipLevel(gl, typedArray, options) {
|
|
|
1876
1846
|
const { dimension, width, height, depth = 0, level = 0, byteOffset = 0 } = options;
|
|
1877
1847
|
const { x = 0, y = 0, z = 0 } = options;
|
|
1878
1848
|
const { glFormat, glType, compressed } = options;
|
|
1879
|
-
const glTarget =
|
|
1849
|
+
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
1880
1850
|
switch (dimension) {
|
|
1881
1851
|
case "2d-array":
|
|
1882
1852
|
case "3d":
|
|
@@ -1915,7 +1885,7 @@ function getWebGLTextureTarget(dimension) {
|
|
|
1915
1885
|
}
|
|
1916
1886
|
throw new Error(dimension);
|
|
1917
1887
|
}
|
|
1918
|
-
function
|
|
1888
|
+
function getWebGLCubeFaceTarget(glTarget, dimension, level) {
|
|
1919
1889
|
return dimension === "cube" ? 34069 + level : glTarget;
|
|
1920
1890
|
}
|
|
1921
1891
|
|
|
@@ -2120,7 +2090,7 @@ var WEBGLTexture = class extends import_core7.Texture {
|
|
|
2120
2090
|
throw new Error("setTexture1DData not supported in WebGL.");
|
|
2121
2091
|
}
|
|
2122
2092
|
/** Set a simple texture */
|
|
2123
|
-
setTexture2DData(lodData, depth = 0
|
|
2093
|
+
setTexture2DData(lodData, depth = 0) {
|
|
2124
2094
|
this.bind();
|
|
2125
2095
|
const lodArray = normalizeTextureData(lodData, this);
|
|
2126
2096
|
if (lodArray.length > 1 && this.props.mipmaps !== false) {
|
|
@@ -2141,7 +2111,9 @@ var WEBGLTexture = class extends import_core7.Texture {
|
|
|
2141
2111
|
throw new Error(this.id);
|
|
2142
2112
|
}
|
|
2143
2113
|
if (ArrayBuffer.isView(data)) {
|
|
2114
|
+
this.bind();
|
|
2144
2115
|
copyCPUDataToMipLevel(this.device.gl, data, this);
|
|
2116
|
+
this.unbind();
|
|
2145
2117
|
}
|
|
2146
2118
|
}
|
|
2147
2119
|
/**
|
|
@@ -2154,6 +2126,9 @@ var WEBGLTexture = class extends import_core7.Texture {
|
|
|
2154
2126
|
if (this.props.dimension !== "cube") {
|
|
2155
2127
|
throw new Error(this.id);
|
|
2156
2128
|
}
|
|
2129
|
+
for (const face of import_core7.Texture.CubeFaces) {
|
|
2130
|
+
this.setTextureCubeFaceData(data[face], face);
|
|
2131
|
+
}
|
|
2157
2132
|
}
|
|
2158
2133
|
/**
|
|
2159
2134
|
* Sets an entire texture array
|
|
@@ -2176,8 +2151,8 @@ var WEBGLTexture = class extends import_core7.Texture {
|
|
|
2176
2151
|
if (Array.isArray(lodData) && lodData.length > 1 && this.props.mipmaps !== false) {
|
|
2177
2152
|
import_core7.log.warn(`${this.id} has mipmap and multiple LODs.`)();
|
|
2178
2153
|
}
|
|
2179
|
-
|
|
2180
|
-
this.
|
|
2154
|
+
const faceDepth = import_core7.Texture.CubeFaces.indexOf(face);
|
|
2155
|
+
this.setTexture2DData(lodData, faceDepth);
|
|
2181
2156
|
}
|
|
2182
2157
|
// INTERNAL METHODS
|
|
2183
2158
|
/** @todo update this method to accept LODs */
|
|
@@ -2311,16 +2286,17 @@ var WEBGLTexture = class extends import_core7.Texture {
|
|
|
2311
2286
|
* Copy a region of data from a CPU memory buffer into this texture.
|
|
2312
2287
|
* @todo - GLUnpackParameters parameters
|
|
2313
2288
|
*/
|
|
2314
|
-
_setMipLevel(depth, level, textureData,
|
|
2289
|
+
_setMipLevel(depth, level, textureData, glTarget = this.glTarget) {
|
|
2315
2290
|
if (import_core7.Texture.isExternalImage(textureData)) {
|
|
2316
|
-
copyCPUImageToMipLevel(this.device.gl, textureData, { ...this, depth, level });
|
|
2291
|
+
copyCPUImageToMipLevel(this.device.gl, textureData, { ...this, depth, level, glTarget });
|
|
2317
2292
|
return;
|
|
2318
2293
|
}
|
|
2319
2294
|
if (this.isTextureLevelData(textureData)) {
|
|
2320
2295
|
copyCPUDataToMipLevel(this.device.gl, textureData.data, {
|
|
2321
2296
|
...this,
|
|
2322
2297
|
depth,
|
|
2323
|
-
level
|
|
2298
|
+
level,
|
|
2299
|
+
glTarget
|
|
2324
2300
|
});
|
|
2325
2301
|
return;
|
|
2326
2302
|
}
|
|
@@ -2453,7 +2429,7 @@ var WEBGLFramebuffer = class extends import_core8.Framebuffer {
|
|
|
2453
2429
|
switch (texture.glTarget) {
|
|
2454
2430
|
case 35866:
|
|
2455
2431
|
case 32879:
|
|
2456
|
-
gl.framebufferTextureLayer(36160, attachment, texture.
|
|
2432
|
+
gl.framebufferTextureLayer(36160, attachment, texture.handle, level, layer);
|
|
2457
2433
|
break;
|
|
2458
2434
|
case 34067:
|
|
2459
2435
|
const face = mapIndexToCubeMapFace(layer);
|
|
@@ -2566,30 +2542,36 @@ async function loadScript(scriptUrl, scriptId) {
|
|
|
2566
2542
|
}
|
|
2567
2543
|
|
|
2568
2544
|
// dist/context/debug/spector.js
|
|
2569
|
-
var DEFAULT_SPECTOR_PROPS = {
|
|
2570
|
-
spector: import_core10.log.get("spector") || import_core10.log.get("inspect")
|
|
2571
|
-
};
|
|
2572
|
-
var SPECTOR_CDN_URL = "https://spectorcdn.babylonjs.com/spector.bundle.js";
|
|
2573
2545
|
var LOG_LEVEL = 1;
|
|
2574
2546
|
var spector = null;
|
|
2575
2547
|
var initialized = false;
|
|
2548
|
+
var DEFAULT_SPECTOR_PROPS = {
|
|
2549
|
+
debugWithSpectorJS: import_core10.log.get("spector") || import_core10.log.get("spectorjs"),
|
|
2550
|
+
// https://github.com/BabylonJS/Spector.js#basic-usage
|
|
2551
|
+
// https://forum.babylonjs.com/t/spectorcdn-is-temporarily-off/48241
|
|
2552
|
+
// spectorUrl: 'https://spectorcdn.babylonjs.com/spector.bundle.js';
|
|
2553
|
+
spectorUrl: "https://cdn.jsdelivr.net/npm/spectorjs@0.9.30/dist/spector.bundle.js",
|
|
2554
|
+
gl: void 0
|
|
2555
|
+
};
|
|
2576
2556
|
async function loadSpectorJS(props) {
|
|
2577
2557
|
if (!globalThis.SPECTOR) {
|
|
2578
2558
|
try {
|
|
2579
|
-
await loadScript(
|
|
2559
|
+
await loadScript(props.spectorUrl || DEFAULT_SPECTOR_PROPS.spectorUrl);
|
|
2580
2560
|
} catch (error) {
|
|
2581
2561
|
import_core10.log.warn(String(error));
|
|
2582
2562
|
}
|
|
2583
2563
|
}
|
|
2584
2564
|
}
|
|
2585
2565
|
function initializeSpectorJS(props) {
|
|
2566
|
+
var _a;
|
|
2586
2567
|
props = { ...DEFAULT_SPECTOR_PROPS, ...props };
|
|
2587
|
-
if (!
|
|
2568
|
+
if (!props.debugWithSpectorJS) {
|
|
2588
2569
|
return null;
|
|
2589
2570
|
}
|
|
2590
|
-
if (!spector && globalThis.SPECTOR) {
|
|
2591
|
-
import_core10.log.probe(LOG_LEVEL, "SPECTOR found and initialized")();
|
|
2592
|
-
|
|
2571
|
+
if (!spector && globalThis.SPECTOR && !((_a = globalThis.luma) == null ? void 0 : _a.spector)) {
|
|
2572
|
+
import_core10.log.probe(LOG_LEVEL, "SPECTOR found and initialized. Start with `luma.spector.displayUI()`")();
|
|
2573
|
+
const { Spector } = globalThis.SPECTOR;
|
|
2574
|
+
spector = new Spector();
|
|
2593
2575
|
if (globalThis.luma) {
|
|
2594
2576
|
globalThis.luma.spector = spector;
|
|
2595
2577
|
}
|
|
@@ -2608,11 +2590,11 @@ function initializeSpectorJS(props) {
|
|
|
2608
2590
|
spector == null ? void 0 : spector.resultView.addCapture(capture);
|
|
2609
2591
|
});
|
|
2610
2592
|
}
|
|
2611
|
-
if (props
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2593
|
+
if (props.gl) {
|
|
2594
|
+
const gl = props.gl;
|
|
2595
|
+
const device = gl.device;
|
|
2596
|
+
spector == null ? void 0 : spector.startCapture(props.gl, 500);
|
|
2597
|
+
gl.device = device;
|
|
2616
2598
|
new Promise((resolve) => setTimeout(resolve, 2e3)).then((_) => {
|
|
2617
2599
|
import_core10.log.info("Spector capture stopped after 2 seconds")();
|
|
2618
2600
|
spector == null ? void 0 : spector.stopCapture();
|
|
@@ -2713,6 +2695,14 @@ function onValidateGLFunc(props, functionName, functionArgs) {
|
|
|
2713
2695
|
}
|
|
2714
2696
|
}
|
|
2715
2697
|
|
|
2698
|
+
// dist/utils/uid.js
|
|
2699
|
+
var uidCounters = {};
|
|
2700
|
+
function uid(id = "id") {
|
|
2701
|
+
uidCounters[id] = uidCounters[id] || 1;
|
|
2702
|
+
const count = uidCounters[id]++;
|
|
2703
|
+
return `${id}-${count}`;
|
|
2704
|
+
}
|
|
2705
|
+
|
|
2716
2706
|
// dist/adapter/resources/webgl-buffer.js
|
|
2717
2707
|
var import_core12 = require("@luma.gl/core");
|
|
2718
2708
|
var import_constants13 = require("@luma.gl/constants");
|
|
@@ -2917,8 +2907,8 @@ var WEBGLShader = class extends import_core13.Shader {
|
|
|
2917
2907
|
return this.getCompilationInfoSync();
|
|
2918
2908
|
}
|
|
2919
2909
|
getCompilationInfoSync() {
|
|
2920
|
-
const
|
|
2921
|
-
return
|
|
2910
|
+
const log10 = this.device.gl.getShaderInfoLog(this.handle);
|
|
2911
|
+
return log10 ? parseShaderCompilerLog(log10) : [];
|
|
2922
2912
|
}
|
|
2923
2913
|
getTranslatedSource() {
|
|
2924
2914
|
const extensions = this.device.getExtension("WEBGL_debug_shaders");
|
|
@@ -2928,7 +2918,7 @@ var WEBGLShader = class extends import_core13.Shader {
|
|
|
2928
2918
|
// PRIVATE METHODS
|
|
2929
2919
|
/** Compile a shader and get compilation status */
|
|
2930
2920
|
async _compile(source) {
|
|
2931
|
-
const addGLSLVersion = (source2) => source2.startsWith("#version ") ? source2 : `#version
|
|
2921
|
+
const addGLSLVersion = (source2) => source2.startsWith("#version ") ? source2 : `#version 300 es
|
|
2932
2922
|
${source2}`;
|
|
2933
2923
|
source = addGLSLVersion(source);
|
|
2934
2924
|
const { gl } = this.device;
|
|
@@ -2992,14 +2982,25 @@ var WEBGLRenderPass = class extends import_core14.RenderPass {
|
|
|
2992
2982
|
/** Parameters that should be applied before each draw call */
|
|
2993
2983
|
glParameters;
|
|
2994
2984
|
constructor(device, props) {
|
|
2985
|
+
var _a;
|
|
2995
2986
|
super(device, props);
|
|
2996
2987
|
this.device = device;
|
|
2997
|
-
|
|
2998
|
-
|
|
2988
|
+
let viewport;
|
|
2989
|
+
if (!((_a = props == null ? void 0 : props.parameters) == null ? void 0 : _a.viewport)) {
|
|
2990
|
+
if (props == null ? void 0 : props.framebuffer) {
|
|
2991
|
+
const { width, height } = props.framebuffer;
|
|
2992
|
+
viewport = [0, 0, width, height];
|
|
2993
|
+
} else {
|
|
2994
|
+
const [width, height] = device.getCanvasContext().getDrawingBufferSize();
|
|
2995
|
+
viewport = [0, 0, width, height];
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
this.device.pushState();
|
|
2999
|
+
this.setParameters({ viewport, ...this.props.parameters });
|
|
2999
3000
|
this.clear();
|
|
3000
3001
|
}
|
|
3001
3002
|
end() {
|
|
3002
|
-
|
|
3003
|
+
this.device.popState();
|
|
3003
3004
|
}
|
|
3004
3005
|
pushDebugGroup(groupLabel) {
|
|
3005
3006
|
}
|
|
@@ -3767,7 +3768,7 @@ var WEBGLRenderPipeline = class extends import_core15.RenderPipeline {
|
|
|
3767
3768
|
if (!binding) {
|
|
3768
3769
|
const validBindings = this.shaderLayout.bindings.map((binding2) => `"${binding2.name}"`).join(", ");
|
|
3769
3770
|
if (!(options == null ? void 0 : options.disableWarnings)) {
|
|
3770
|
-
import_core15.log.warn(`
|
|
3771
|
+
import_core15.log.warn(`No binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`, value)();
|
|
3771
3772
|
}
|
|
3772
3773
|
continue;
|
|
3773
3774
|
}
|
|
@@ -4821,11 +4822,10 @@ function glTypeToBytes(type) {
|
|
|
4821
4822
|
|
|
4822
4823
|
// dist/classic/copy-and-blit.js
|
|
4823
4824
|
function readPixelsToArray(source, options) {
|
|
4824
|
-
var _a, _b;
|
|
4825
|
+
var _a, _b, _c, _d, _e, _f;
|
|
4825
4826
|
const {
|
|
4826
4827
|
sourceX = 0,
|
|
4827
4828
|
sourceY = 0,
|
|
4828
|
-
sourceFormat = 6408,
|
|
4829
4829
|
sourceAttachment = 36064
|
|
4830
4830
|
// TODO - support gl.readBuffer
|
|
4831
4831
|
} = options || {};
|
|
@@ -4834,15 +4834,19 @@ function readPixelsToArray(source, options) {
|
|
|
4834
4834
|
// following parameters are auto deduced if not provided
|
|
4835
4835
|
sourceWidth,
|
|
4836
4836
|
sourceHeight,
|
|
4837
|
+
sourceDepth,
|
|
4838
|
+
sourceFormat,
|
|
4837
4839
|
sourceType
|
|
4838
4840
|
} = options || {};
|
|
4839
4841
|
const { framebuffer, deleteFramebuffer } = getFramebuffer2(source);
|
|
4840
4842
|
const { gl, handle } = framebuffer;
|
|
4841
|
-
sourceWidth = sourceWidth || framebuffer.width;
|
|
4842
|
-
sourceHeight = sourceHeight || framebuffer.height;
|
|
4843
4843
|
const attachment = sourceAttachment - 36064;
|
|
4844
|
-
|
|
4845
|
-
|
|
4844
|
+
sourceWidth ||= framebuffer.width;
|
|
4845
|
+
sourceHeight ||= framebuffer.height;
|
|
4846
|
+
sourceDepth = ((_b = (_a = framebuffer.colorAttachments[attachment]) == null ? void 0 : _a.texture) == null ? void 0 : _b.depth) || 1;
|
|
4847
|
+
sourceFormat ||= ((_d = (_c = framebuffer.colorAttachments[attachment]) == null ? void 0 : _c.texture) == null ? void 0 : _d.glFormat) || 6408;
|
|
4848
|
+
sourceType ||= ((_f = (_e = framebuffer.colorAttachments[attachment]) == null ? void 0 : _e.texture) == null ? void 0 : _f.glType) || 5121;
|
|
4849
|
+
target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight, sourceDepth);
|
|
4846
4850
|
sourceType = sourceType || getGLTypeFromTypedArray(target);
|
|
4847
4851
|
const prevHandle = gl.bindFramebuffer(36160, handle);
|
|
4848
4852
|
gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
|
|
@@ -4899,7 +4903,7 @@ function toFramebuffer(texture, props) {
|
|
|
4899
4903
|
});
|
|
4900
4904
|
return framebuffer;
|
|
4901
4905
|
}
|
|
4902
|
-
function getPixelArray(pixelArray, type, format, width, height) {
|
|
4906
|
+
function getPixelArray(pixelArray, type, format, width, height, depth) {
|
|
4903
4907
|
if (pixelArray) {
|
|
4904
4908
|
return pixelArray;
|
|
4905
4909
|
}
|
|
@@ -4945,8 +4949,10 @@ function clear(device, options) {
|
|
|
4945
4949
|
}
|
|
4946
4950
|
|
|
4947
4951
|
// dist/adapter/webgl-device.js
|
|
4948
|
-
var
|
|
4949
|
-
|
|
4952
|
+
var WebGLDevice = class extends import_core22.Device {
|
|
4953
|
+
//
|
|
4954
|
+
// Public `Device` API
|
|
4955
|
+
//
|
|
4950
4956
|
/** type of this device */
|
|
4951
4957
|
type = "webgl";
|
|
4952
4958
|
/** The underlying WebGL context */
|
|
@@ -4957,68 +4963,22 @@ var _WebGLDevice = class extends import_core22.Device {
|
|
|
4957
4963
|
canvasContext;
|
|
4958
4964
|
lost;
|
|
4959
4965
|
_resolveContextLost;
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
/**
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
}
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
* @param gl
|
|
4971
|
-
* @returns
|
|
4972
|
-
*/
|
|
4973
|
-
static attach(gl) {
|
|
4974
|
-
if (gl instanceof _WebGLDevice) {
|
|
4975
|
-
return gl;
|
|
4976
|
-
}
|
|
4977
|
-
if ((gl == null ? void 0 : gl.device) instanceof import_core22.Device) {
|
|
4978
|
-
return gl.device;
|
|
4979
|
-
}
|
|
4980
|
-
if (!isWebGL(gl)) {
|
|
4981
|
-
throw new Error("Invalid WebGL2RenderingContext");
|
|
4982
|
-
}
|
|
4983
|
-
return new _WebGLDevice({ gl });
|
|
4984
|
-
}
|
|
4985
|
-
static async create(props = {}) {
|
|
4986
|
-
var _a;
|
|
4987
|
-
import_core22.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
|
|
4988
|
-
const promises = [];
|
|
4989
|
-
if (props.debug) {
|
|
4990
|
-
promises.push(loadWebGLDeveloperTools());
|
|
4991
|
-
}
|
|
4992
|
-
if (props.spector) {
|
|
4993
|
-
promises.push(loadSpectorJS());
|
|
4994
|
-
}
|
|
4995
|
-
if (typeof props.canvas === "string") {
|
|
4996
|
-
promises.push(import_core22.CanvasContext.pageLoaded);
|
|
4997
|
-
}
|
|
4998
|
-
const results = await Promise.allSettled(promises);
|
|
4999
|
-
for (const result of results) {
|
|
5000
|
-
if (result.status === "rejected") {
|
|
5001
|
-
import_core22.log.error(`Failed to initialize debug libraries ${result.reason}`)();
|
|
5002
|
-
}
|
|
5003
|
-
}
|
|
5004
|
-
import_core22.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
|
|
5005
|
-
if ((_a = props.gl) == null ? void 0 : _a.device) {
|
|
5006
|
-
import_core22.log.warn("reattaching existing device")();
|
|
5007
|
-
return _WebGLDevice.attach(props.gl);
|
|
5008
|
-
}
|
|
5009
|
-
const device = new _WebGLDevice(props);
|
|
5010
|
-
const message2 = `Created ${device.type}${device.debug ? " debug" : ""} context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
|
|
5011
|
-
import_core22.log.probe(LOG_LEVEL2, message2)();
|
|
5012
|
-
import_core22.log.table(LOG_LEVEL2, device.info)();
|
|
5013
|
-
import_core22.log.groupEnd(LOG_LEVEL2)();
|
|
5014
|
-
return device;
|
|
5015
|
-
}
|
|
4966
|
+
/** WebGL2 context. */
|
|
4967
|
+
gl;
|
|
4968
|
+
debug = false;
|
|
4969
|
+
/** State used by luma.gl classes: TODO - move to canvasContext*/
|
|
4970
|
+
_canvasSizeInfo = { clientWidth: 0, clientHeight: 0, devicePixelRatio: 1 };
|
|
4971
|
+
/** State used by luma.gl classes - TODO - not used? */
|
|
4972
|
+
_extensions = {};
|
|
4973
|
+
_polyfilled = false;
|
|
4974
|
+
/** Instance of Spector.js (if initialized) */
|
|
4975
|
+
spectorJS;
|
|
5016
4976
|
//
|
|
5017
4977
|
// Public API
|
|
5018
4978
|
//
|
|
5019
4979
|
constructor(props) {
|
|
5020
4980
|
var _a, _b;
|
|
5021
|
-
super({ ...props, id: props.id || "webgl-device" });
|
|
4981
|
+
super({ ...props, id: props.id || uid("webgl-device") });
|
|
5022
4982
|
const device = (_a = props.gl) == null ? void 0 : _a.device;
|
|
5023
4983
|
if (device) {
|
|
5024
4984
|
throw new Error(`WebGL context already attached to device ${device.id}`);
|
|
@@ -5028,8 +4988,7 @@ var _WebGLDevice = class extends import_core22.Device {
|
|
|
5028
4988
|
this.lost = new Promise((resolve) => {
|
|
5029
4989
|
this._resolveContextLost = resolve;
|
|
5030
4990
|
});
|
|
5031
|
-
|
|
5032
|
-
gl ||= createBrowserContext(this.canvasContext.canvas, {
|
|
4991
|
+
this.handle = createBrowserContext(this.canvasContext.canvas, {
|
|
5033
4992
|
...props,
|
|
5034
4993
|
onContextLost: (event) => {
|
|
5035
4994
|
var _a2;
|
|
@@ -5039,11 +4998,11 @@ var _WebGLDevice = class extends import_core22.Device {
|
|
|
5039
4998
|
});
|
|
5040
4999
|
}
|
|
5041
5000
|
});
|
|
5042
|
-
|
|
5001
|
+
this.gl = this.handle;
|
|
5002
|
+
if (!this.handle) {
|
|
5043
5003
|
throw new Error("WebGL context creation failed");
|
|
5044
5004
|
}
|
|
5045
|
-
this.
|
|
5046
|
-
this.gl = gl;
|
|
5005
|
+
this.spectorJS = initializeSpectorJS({ ...this.props, gl: this.handle });
|
|
5047
5006
|
this.gl.device = this;
|
|
5048
5007
|
this.gl._version = 2;
|
|
5049
5008
|
this.info = getDeviceInfo(this.gl, this._extensions);
|
|
@@ -5053,21 +5012,16 @@ var _WebGLDevice = class extends import_core22.Device {
|
|
|
5053
5012
|
this.features.initializeFeatures();
|
|
5054
5013
|
}
|
|
5055
5014
|
this.canvasContext.resize();
|
|
5056
|
-
const
|
|
5057
|
-
trackContextState(this.gl, {
|
|
5058
|
-
enable: enable2,
|
|
5059
|
-
copyState,
|
|
5015
|
+
const glState = new WebGLStateTracker(this.gl, {
|
|
5060
5016
|
log: (...args) => import_core22.log.log(1, ...args)()
|
|
5061
5017
|
});
|
|
5018
|
+
glState.trackState(this.gl, { copyState: false });
|
|
5062
5019
|
if (props.debug) {
|
|
5063
5020
|
this.gl = makeDebugContext(this.gl, { ...props, throwOnError: true });
|
|
5064
5021
|
this.debug = true;
|
|
5065
5022
|
import_core22.log.level = Math.max(import_core22.log.level, 1);
|
|
5066
5023
|
import_core22.log.warn("WebGL debug mode activated. Performance reduced.")();
|
|
5067
5024
|
}
|
|
5068
|
-
if (props.spector) {
|
|
5069
|
-
this.spectorJS = initializeSpectorJS({ ...this.props, canvas: this.handle.canvas });
|
|
5070
|
-
}
|
|
5071
5025
|
}
|
|
5072
5026
|
/**
|
|
5073
5027
|
* Destroys the context
|
|
@@ -5078,9 +5032,6 @@ var _WebGLDevice = class extends import_core22.Device {
|
|
|
5078
5032
|
get isLost() {
|
|
5079
5033
|
return this.gl.isContextLost();
|
|
5080
5034
|
}
|
|
5081
|
-
getSize() {
|
|
5082
|
-
return [this.gl.drawingBufferWidth, this.gl.drawingBufferHeight];
|
|
5083
|
-
}
|
|
5084
5035
|
isTextureFormatSupported(format) {
|
|
5085
5036
|
return isTextureFormatSupported(this.gl, format, this._extensions);
|
|
5086
5037
|
}
|
|
@@ -5179,16 +5130,6 @@ var _WebGLDevice = class extends import_core22.Device {
|
|
|
5179
5130
|
//
|
|
5180
5131
|
// WebGL-only API (not part of `Device` API)
|
|
5181
5132
|
//
|
|
5182
|
-
/** WebGL2 context. */
|
|
5183
|
-
gl;
|
|
5184
|
-
debug = false;
|
|
5185
|
-
/** State used by luma.gl classes: TODO - move to canvasContext*/
|
|
5186
|
-
_canvasSizeInfo = { clientWidth: 0, clientHeight: 0, devicePixelRatio: 1 };
|
|
5187
|
-
/** State used by luma.gl classes - TODO - not used? */
|
|
5188
|
-
_extensions = {};
|
|
5189
|
-
_polyfilled = false;
|
|
5190
|
-
/** Instance of Spector.js (if initialized) */
|
|
5191
|
-
spectorJS;
|
|
5192
5133
|
/**
|
|
5193
5134
|
* Triggers device (or WebGL context) loss.
|
|
5194
5135
|
* @note primarily intended for testing how application reacts to device loss
|
|
@@ -5210,11 +5151,13 @@ var _WebGLDevice = class extends import_core22.Device {
|
|
|
5210
5151
|
}
|
|
5211
5152
|
/** Save current WebGL context state onto an internal stack */
|
|
5212
5153
|
pushState() {
|
|
5213
|
-
|
|
5154
|
+
const webglState = WebGLStateTracker.get(this.gl);
|
|
5155
|
+
webglState.push();
|
|
5214
5156
|
}
|
|
5215
5157
|
/** Restores previously saved context state */
|
|
5216
5158
|
popState() {
|
|
5217
|
-
|
|
5159
|
+
const webglState = WebGLStateTracker.get(this.gl);
|
|
5160
|
+
webglState.pop();
|
|
5218
5161
|
}
|
|
5219
5162
|
/**
|
|
5220
5163
|
* Storing data on a special field on WebGLObjects makes that data visible in SPECTOR chrome debug extension
|
|
@@ -5274,18 +5217,6 @@ var _WebGLDevice = class extends import_core22.Device {
|
|
|
5274
5217
|
return this._extensions;
|
|
5275
5218
|
}
|
|
5276
5219
|
};
|
|
5277
|
-
var WebGLDevice = _WebGLDevice;
|
|
5278
|
-
//
|
|
5279
|
-
// Public `Device` API
|
|
5280
|
-
//
|
|
5281
|
-
/** type of this device */
|
|
5282
|
-
__publicField(WebGLDevice, "type", "webgl");
|
|
5283
|
-
function isWebGL(gl) {
|
|
5284
|
-
if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
|
|
5285
|
-
return true;
|
|
5286
|
-
}
|
|
5287
|
-
return Boolean(gl && Number.isFinite(gl._version));
|
|
5288
|
-
}
|
|
5289
5220
|
function setConstantFloatArray(device, location, array) {
|
|
5290
5221
|
switch (array.length) {
|
|
5291
5222
|
case 1:
|
|
@@ -5320,4 +5251,180 @@ function compareConstantArrayValues2(v1, v2) {
|
|
|
5320
5251
|
}
|
|
5321
5252
|
return true;
|
|
5322
5253
|
}
|
|
5254
|
+
|
|
5255
|
+
// dist/context/polyfills/polyfill-webgl1-extensions.js
|
|
5256
|
+
var import_constants29 = require("@luma.gl/constants");
|
|
5257
|
+
var WEBGL1_STATIC_EXTENSIONS = {
|
|
5258
|
+
WEBGL_depth_texture: {
|
|
5259
|
+
UNSIGNED_INT_24_8_WEBGL: 34042
|
|
5260
|
+
},
|
|
5261
|
+
OES_element_index_uint: {},
|
|
5262
|
+
OES_texture_float: {},
|
|
5263
|
+
OES_texture_half_float: {
|
|
5264
|
+
// @ts-expect-error different numbers?
|
|
5265
|
+
HALF_FLOAT_OES: 5131
|
|
5266
|
+
},
|
|
5267
|
+
EXT_color_buffer_float: {},
|
|
5268
|
+
OES_standard_derivatives: {
|
|
5269
|
+
FRAGMENT_SHADER_DERIVATIVE_HINT_OES: 35723
|
|
5270
|
+
},
|
|
5271
|
+
EXT_frag_depth: {},
|
|
5272
|
+
EXT_blend_minmax: {
|
|
5273
|
+
MIN_EXT: 32775,
|
|
5274
|
+
MAX_EXT: 32776
|
|
5275
|
+
},
|
|
5276
|
+
EXT_shader_texture_lod: {}
|
|
5277
|
+
};
|
|
5278
|
+
var getWEBGL_draw_buffers = (gl) => ({
|
|
5279
|
+
drawBuffersWEBGL(buffers) {
|
|
5280
|
+
return gl.drawBuffers(buffers);
|
|
5281
|
+
},
|
|
5282
|
+
COLOR_ATTACHMENT0_WEBGL: 36064,
|
|
5283
|
+
COLOR_ATTACHMENT1_WEBGL: 36065,
|
|
5284
|
+
COLOR_ATTACHMENT2_WEBGL: 36066,
|
|
5285
|
+
COLOR_ATTACHMENT3_WEBGL: 36067
|
|
5286
|
+
});
|
|
5287
|
+
var getOES_vertex_array_object = (gl) => ({
|
|
5288
|
+
VERTEX_ARRAY_BINDING_OES: 34229,
|
|
5289
|
+
createVertexArrayOES() {
|
|
5290
|
+
return gl.createVertexArray();
|
|
5291
|
+
},
|
|
5292
|
+
deleteVertexArrayOES(vertexArray) {
|
|
5293
|
+
return gl.deleteVertexArray(vertexArray);
|
|
5294
|
+
},
|
|
5295
|
+
isVertexArrayOES(vertexArray) {
|
|
5296
|
+
return gl.isVertexArray(vertexArray);
|
|
5297
|
+
},
|
|
5298
|
+
bindVertexArrayOES(vertexArray) {
|
|
5299
|
+
return gl.bindVertexArray(vertexArray);
|
|
5300
|
+
}
|
|
5301
|
+
});
|
|
5302
|
+
var getANGLE_instanced_arrays = (gl) => ({
|
|
5303
|
+
VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE: 35070,
|
|
5304
|
+
drawArraysInstancedANGLE(...args) {
|
|
5305
|
+
return gl.drawArraysInstanced(...args);
|
|
5306
|
+
},
|
|
5307
|
+
drawElementsInstancedANGLE(...args) {
|
|
5308
|
+
return gl.drawElementsInstanced(...args);
|
|
5309
|
+
},
|
|
5310
|
+
vertexAttribDivisorANGLE(...args) {
|
|
5311
|
+
return gl.vertexAttribDivisor(...args);
|
|
5312
|
+
}
|
|
5313
|
+
});
|
|
5314
|
+
function enforceWebGL2(enforce = true) {
|
|
5315
|
+
const prototype = HTMLCanvasElement.prototype;
|
|
5316
|
+
if (!enforce && prototype.originalGetContext) {
|
|
5317
|
+
prototype.getContext = prototype.originalGetContext;
|
|
5318
|
+
prototype.originalGetContext = void 0;
|
|
5319
|
+
return;
|
|
5320
|
+
}
|
|
5321
|
+
prototype.originalGetContext = prototype.getContext;
|
|
5322
|
+
prototype.getContext = function(contextId, options) {
|
|
5323
|
+
if (contextId === "webgl" || contextId === "experimental-webgl") {
|
|
5324
|
+
const context = this.originalGetContext("webgl2", options);
|
|
5325
|
+
if (context instanceof HTMLElement) {
|
|
5326
|
+
polyfillWebGL1Extensions(context);
|
|
5327
|
+
}
|
|
5328
|
+
return context;
|
|
5329
|
+
}
|
|
5330
|
+
return this.originalGetContext(contextId, options);
|
|
5331
|
+
};
|
|
5332
|
+
}
|
|
5333
|
+
function polyfillWebGL1Extensions(gl) {
|
|
5334
|
+
gl.getExtension("EXT_color_buffer_float");
|
|
5335
|
+
const boundExtensions = {
|
|
5336
|
+
...WEBGL1_STATIC_EXTENSIONS,
|
|
5337
|
+
WEBGL_disjoint_timer_query: gl.getExtension("EXT_disjoint_timer_query_webgl2"),
|
|
5338
|
+
WEBGL_draw_buffers: getWEBGL_draw_buffers(gl),
|
|
5339
|
+
OES_vertex_array_object: getOES_vertex_array_object(gl),
|
|
5340
|
+
ANGLE_instanced_arrays: getANGLE_instanced_arrays(gl)
|
|
5341
|
+
};
|
|
5342
|
+
const originalGetExtension = gl.getExtension;
|
|
5343
|
+
gl.getExtension = function(extensionName) {
|
|
5344
|
+
const ext = originalGetExtension.call(gl, extensionName);
|
|
5345
|
+
if (ext) {
|
|
5346
|
+
return ext;
|
|
5347
|
+
}
|
|
5348
|
+
if (extensionName in boundExtensions) {
|
|
5349
|
+
return boundExtensions[extensionName];
|
|
5350
|
+
}
|
|
5351
|
+
return null;
|
|
5352
|
+
};
|
|
5353
|
+
const originalGetSupportedExtensions = gl.getSupportedExtensions;
|
|
5354
|
+
gl.getSupportedExtensions = function() {
|
|
5355
|
+
const extensions = originalGetSupportedExtensions.apply(gl) || [];
|
|
5356
|
+
return extensions == null ? void 0 : extensions.concat(Object.keys(boundExtensions));
|
|
5357
|
+
};
|
|
5358
|
+
}
|
|
5359
|
+
|
|
5360
|
+
// dist/adapter/webgl-adapter.js
|
|
5361
|
+
var LOG_LEVEL2 = 1;
|
|
5362
|
+
var WebGLAdapter = class extends import_core23.Adapter {
|
|
5363
|
+
/** type of device's created by this adapter */
|
|
5364
|
+
type = "webgl";
|
|
5365
|
+
constructor() {
|
|
5366
|
+
super();
|
|
5367
|
+
import_core23.Device.defaultProps = { ...import_core23.Device.defaultProps, ...DEFAULT_SPECTOR_PROPS };
|
|
5368
|
+
WebGLDevice.adapter = this;
|
|
5369
|
+
}
|
|
5370
|
+
/** Check if WebGL 2 is available */
|
|
5371
|
+
isSupported() {
|
|
5372
|
+
return typeof WebGL2RenderingContext !== "undefined";
|
|
5373
|
+
}
|
|
5374
|
+
/** Force any created WebGL contexts to be WebGL2 contexts, polyfilled with WebGL1 extensions */
|
|
5375
|
+
enforceWebGL2(enable2) {
|
|
5376
|
+
enforceWebGL2(enable2);
|
|
5377
|
+
}
|
|
5378
|
+
/**
|
|
5379
|
+
* Get a device instance from a GL context
|
|
5380
|
+
* Creates and instruments the device if not already created
|
|
5381
|
+
* @param gl
|
|
5382
|
+
* @returns
|
|
5383
|
+
*/
|
|
5384
|
+
async attach(gl) {
|
|
5385
|
+
if (gl instanceof WebGLDevice) {
|
|
5386
|
+
return gl;
|
|
5387
|
+
}
|
|
5388
|
+
if ((gl == null ? void 0 : gl.device) instanceof import_core23.Device) {
|
|
5389
|
+
return gl.device;
|
|
5390
|
+
}
|
|
5391
|
+
if (!isWebGL(gl)) {
|
|
5392
|
+
throw new Error("Invalid WebGL2RenderingContext");
|
|
5393
|
+
}
|
|
5394
|
+
return new WebGLDevice({ gl });
|
|
5395
|
+
}
|
|
5396
|
+
async create(props = {}) {
|
|
5397
|
+
import_core23.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
|
|
5398
|
+
const promises = [];
|
|
5399
|
+
if (props.debug) {
|
|
5400
|
+
promises.push(loadWebGLDeveloperTools());
|
|
5401
|
+
}
|
|
5402
|
+
if (props.debugWithSpectorJS) {
|
|
5403
|
+
promises.push(loadSpectorJS(props));
|
|
5404
|
+
}
|
|
5405
|
+
if (typeof props.canvas === "string") {
|
|
5406
|
+
promises.push(import_core23.CanvasContext.pageLoaded);
|
|
5407
|
+
}
|
|
5408
|
+
const results = await Promise.allSettled(promises);
|
|
5409
|
+
for (const result of results) {
|
|
5410
|
+
if (result.status === "rejected") {
|
|
5411
|
+
import_core23.log.error(`Failed to initialize debug libraries ${result.reason}`)();
|
|
5412
|
+
}
|
|
5413
|
+
}
|
|
5414
|
+
import_core23.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
|
|
5415
|
+
const device = new WebGLDevice(props);
|
|
5416
|
+
const message2 = `Created ${device.type}${device.debug ? " debug" : ""} context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
|
|
5417
|
+
import_core23.log.probe(LOG_LEVEL2, message2)();
|
|
5418
|
+
import_core23.log.table(LOG_LEVEL2, device.info)();
|
|
5419
|
+
import_core23.log.groupEnd(LOG_LEVEL2)();
|
|
5420
|
+
return device;
|
|
5421
|
+
}
|
|
5422
|
+
};
|
|
5423
|
+
function isWebGL(gl) {
|
|
5424
|
+
if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
|
|
5425
|
+
return true;
|
|
5426
|
+
}
|
|
5427
|
+
return Boolean(gl && Number.isFinite(gl._version));
|
|
5428
|
+
}
|
|
5429
|
+
var webgl2Adapter = new WebGLAdapter();
|
|
5323
5430
|
//# sourceMappingURL=index.cjs.map
|