@luma.gl/webgl 9.0.17 → 9.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/device-parameters.js +30 -12
- package/dist/adapter/converters/texture-formats.d.ts +22 -16
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +39 -47
- package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-features.js +1 -2
- package/dist/adapter/device-helpers/webgl-device-limits.js +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.d.ts +300 -0
- package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -0
- package/dist/adapter/helpers/webgl-texture-utils.js +370 -0
- package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-topology-utils.js +0 -4
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +2 -2
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +6 -9
- package/dist/adapter/resources/webgl-framebuffer.d.ts +32 -5
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +42 -60
- package/dist/adapter/resources/webgl-render-pass.d.ts +3 -2
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +18 -7
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +46 -21
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +3 -3
- package/dist/adapter/resources/webgl-texture-view.d.ts +1 -1
- package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture-view.js +1 -1
- package/dist/adapter/resources/webgl-texture.d.ts +76 -172
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +397 -511
- package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -2
- package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-vertex-array.js +2 -2
- 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-canvas-context.d.ts +3 -1
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js +2 -0
- package/dist/adapter/webgl-device.d.ts +19 -30
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +35 -114
- package/dist/classic/accessor.d.ts +22 -1
- package/dist/classic/accessor.d.ts.map +1 -1
- package/dist/classic/accessor.js +1 -9
- package/dist/classic/clear.d.ts.map +1 -1
- package/dist/classic/clear.js +2 -5
- package/dist/classic/copy-and-blit.d.ts +3 -1
- package/dist/classic/copy-and-blit.d.ts.map +1 -1
- package/dist/classic/copy-and-blit.js +21 -18
- package/dist/classic/format-utils.d.ts.map +1 -1
- package/dist/classic/format-utils.js +0 -3
- package/dist/classic/typed-array-utils.d.ts +1 -1
- package/dist/classic/typed-array-utils.d.ts.map +1 -1
- 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 +25 -18
- package/dist/context/debug/webgl-developer-tools.d.ts +1 -1
- package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +2 -5
- package/dist/context/parameters/webgl-parameter-tables.js +1 -1
- 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} +46 -77
- 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 +1112 -1380
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +1122 -1284
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +3 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -5
- package/dist/utils/fill-array.d.ts +8 -0
- package/dist/utils/fill-array.d.ts.map +1 -0
- package/dist/utils/fill-array.js +26 -0
- package/dist/utils/load-script.d.ts +8 -0
- package/dist/utils/load-script.d.ts.map +1 -0
- package/dist/utils/load-script.js +26 -0
- package/dist/utils/split-uniforms-and-bindings.d.ts +9 -0
- package/dist/utils/split-uniforms-and-bindings.d.ts.map +1 -0
- package/dist/utils/split-uniforms-and-bindings.js +20 -0
- 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 +6 -5
- package/src/adapter/converters/device-parameters.ts +31 -13
- package/src/adapter/converters/texture-formats.ts +51 -56
- package/src/adapter/device-helpers/webgl-device-features.ts +1 -2
- package/src/adapter/device-helpers/webgl-device-limits.ts +1 -1
- package/src/adapter/helpers/webgl-texture-utils.ts +484 -0
- package/src/adapter/helpers/webgl-topology-utils.ts +0 -4
- package/src/adapter/resources/webgl-buffer.ts +2 -2
- package/src/adapter/resources/webgl-command-buffer.ts +8 -10
- package/src/adapter/resources/webgl-framebuffer.ts +22 -56
- package/src/adapter/resources/webgl-render-pass.ts +21 -9
- package/src/adapter/resources/webgl-render-pipeline.ts +50 -24
- package/src/adapter/resources/webgl-shader.ts +4 -4
- package/src/adapter/resources/webgl-texture-view.ts +1 -3
- package/src/adapter/resources/webgl-texture.ts +445 -784
- package/src/adapter/resources/webgl-vertex-array.ts +8 -7
- package/src/adapter/webgl-adapter.ts +113 -0
- package/src/adapter/webgl-canvas-context.ts +4 -1
- package/src/adapter/webgl-device.ts +40 -151
- package/src/classic/accessor.ts +31 -11
- package/src/classic/clear.ts +3 -6
- package/src/classic/copy-and-blit.ts +32 -27
- package/src/classic/format-utils.ts +0 -3
- package/src/classic/typed-array-utils.ts +1 -1
- package/src/context/debug/spector-types.ts +1154 -0
- package/src/context/debug/spector.ts +40 -30
- package/src/context/debug/webgl-developer-tools.ts +3 -7
- package/src/context/parameters/webgl-parameter-tables.ts +3 -3
- package/src/context/polyfills/polyfill-webgl1-extensions.ts +202 -0
- package/src/context/state-tracker/{track-context-state.ts → webgl-state-tracker.ts} +57 -97
- package/src/context/state-tracker/with-parameters.ts +5 -4
- package/src/index.ts +5 -13
- package/src/utils/fill-array.ts +35 -0
- package/src/utils/load-script.ts +30 -0
- package/src/utils/split-uniforms-and-bindings.ts +31 -0
- package/src/utils/uid.ts +16 -0
- package/dist/adapter/objects/constants-to-keys.d.ts +0 -3
- package/dist/adapter/objects/constants-to-keys.d.ts.map +0 -1
- package/dist/adapter/objects/constants-to-keys.js +0 -22
- package/dist/adapter/objects/webgl-renderbuffer.d.ts +0 -43
- package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +0 -1
- package/dist/adapter/objects/webgl-renderbuffer.js +0 -95
- package/dist/adapter/objects/webgl-resource.d.ts +0 -32
- package/dist/adapter/objects/webgl-resource.d.ts.map +0 -1
- package/dist/adapter/objects/webgl-resource.js +0 -114
- 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/src/adapter/objects/constants-to-keys.ts +0 -27
- package/src/adapter/objects/webgl-renderbuffer.ts +0 -132
- package/src/adapter/objects/webgl-resource.ts +0 -183
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 = {};
|
|
@@ -30,7 +25,6 @@ __export(dist_exports, {
|
|
|
30
25
|
WEBGLFramebuffer: () => WEBGLFramebuffer,
|
|
31
26
|
WEBGLRenderPass: () => WEBGLRenderPass,
|
|
32
27
|
WEBGLRenderPipeline: () => WEBGLRenderPipeline,
|
|
33
|
-
WEBGLResource: () => WebGLResource,
|
|
34
28
|
WEBGLSampler: () => WEBGLSampler,
|
|
35
29
|
WEBGLShader: () => WEBGLShader,
|
|
36
30
|
WEBGLTexture: () => WEBGLTexture,
|
|
@@ -38,28 +32,24 @@ __export(dist_exports, {
|
|
|
38
32
|
WEBGLVertexArray: () => WEBGLVertexArray,
|
|
39
33
|
WebGLCanvasContext: () => WebGLCanvasContext,
|
|
40
34
|
WebGLDevice: () => WebGLDevice,
|
|
41
|
-
|
|
35
|
+
WebGLStateTracker: () => WebGLStateTracker,
|
|
42
36
|
_TEXTURE_FORMATS: () => TEXTURE_FORMATS,
|
|
43
|
-
_WEBGLRenderbuffer: () => WEBGLRenderbuffer,
|
|
44
|
-
convertGLToTextureFormat: () => convertGLToTextureFormat,
|
|
45
37
|
getGLParameters: () => getGLParameters,
|
|
46
38
|
getShaderLayout: () => getShaderLayout,
|
|
47
|
-
popContextState: () => popContextState,
|
|
48
|
-
pushContextState: () => pushContextState,
|
|
49
39
|
resetGLParameters: () => resetGLParameters,
|
|
50
40
|
setDeviceParameters: () => setDeviceParameters,
|
|
51
41
|
setGLParameters: () => setGLParameters,
|
|
52
|
-
|
|
42
|
+
webgl2Adapter: () => webgl2Adapter,
|
|
53
43
|
withDeviceParameters: () => withDeviceParameters,
|
|
54
44
|
withGLParameters: () => withGLParameters
|
|
55
45
|
});
|
|
56
46
|
module.exports = __toCommonJS(dist_exports);
|
|
57
47
|
|
|
58
|
-
// dist/adapter/webgl-
|
|
59
|
-
var
|
|
48
|
+
// dist/adapter/webgl-adapter.js
|
|
49
|
+
var import_core23 = require("@luma.gl/core");
|
|
60
50
|
|
|
61
|
-
// dist/
|
|
62
|
-
var
|
|
51
|
+
// dist/adapter/webgl-device.js
|
|
52
|
+
var import_core22 = require("@luma.gl/core");
|
|
63
53
|
|
|
64
54
|
// dist/context/parameters/webgl-parameter-tables.js
|
|
65
55
|
var import_constants = require("@luma.gl/constants");
|
|
@@ -295,7 +285,7 @@ var GL_PARAMETER_SETTERS = {
|
|
|
295
285
|
lineWidth: (gl, value) => gl.lineWidth(value),
|
|
296
286
|
polygonOffsetFill: (gl, value) => value ? gl.enable(32823) : gl.disable(32823),
|
|
297
287
|
polygonOffset: (gl, value) => gl.polygonOffset(...value),
|
|
298
|
-
sampleCoverage: (gl, value) => gl.sampleCoverage(
|
|
288
|
+
sampleCoverage: (gl, value) => gl.sampleCoverage(value[0], value[1] || false),
|
|
299
289
|
scissorTest: (gl, value) => value ? gl.enable(3089) : gl.disable(3089),
|
|
300
290
|
scissor: (gl, value) => gl.scissor(...value),
|
|
301
291
|
stencilTest: (gl, value) => value ? gl.enable(2960) : gl.disable(2960),
|
|
@@ -601,24 +591,22 @@ function deepArrayEqual(x, y) {
|
|
|
601
591
|
return false;
|
|
602
592
|
}
|
|
603
593
|
|
|
604
|
-
// dist/context/state-tracker/
|
|
605
|
-
var
|
|
594
|
+
// dist/context/state-tracker/webgl-state-tracker.js
|
|
595
|
+
var WebGLStateTracker = class {
|
|
596
|
+
static get(gl) {
|
|
597
|
+
return gl.state;
|
|
598
|
+
}
|
|
606
599
|
gl;
|
|
607
600
|
program = null;
|
|
608
601
|
stateStack = [];
|
|
609
602
|
enable = true;
|
|
610
|
-
cache;
|
|
603
|
+
cache = null;
|
|
611
604
|
log;
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
// Copy cache from params (slow) or initialize from WebGL defaults (fast)
|
|
615
|
-
log: log9 = () => {
|
|
616
|
-
}
|
|
617
|
-
// Logging function, called when gl parameter change calls are actually issued
|
|
618
|
-
} = {}) {
|
|
605
|
+
initialized = false;
|
|
606
|
+
constructor(gl, props) {
|
|
619
607
|
this.gl = gl;
|
|
620
|
-
this.
|
|
621
|
-
|
|
608
|
+
this.log = (props == null ? void 0 : props.log) || (() => {
|
|
609
|
+
});
|
|
622
610
|
this._updateCache = this._updateCache.bind(this);
|
|
623
611
|
Object.seal(this);
|
|
624
612
|
}
|
|
@@ -626,11 +614,33 @@ var GLState = class {
|
|
|
626
614
|
this.stateStack.push({});
|
|
627
615
|
}
|
|
628
616
|
pop() {
|
|
629
|
-
(0, import_core.assert)(this.stateStack.length > 0);
|
|
630
617
|
const oldValues = this.stateStack[this.stateStack.length - 1];
|
|
631
618
|
setGLParameters(this.gl, oldValues);
|
|
632
619
|
this.stateStack.pop();
|
|
633
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
|
+
}
|
|
634
644
|
/**
|
|
635
645
|
// interceptor for context set functions - update our cache and our stack
|
|
636
646
|
// values (Object) - the key values for this setter
|
|
@@ -642,7 +652,6 @@ var GLState = class {
|
|
|
642
652
|
let oldValue;
|
|
643
653
|
const oldValues = this.stateStack.length > 0 ? this.stateStack[this.stateStack.length - 1] : null;
|
|
644
654
|
for (const key in values) {
|
|
645
|
-
(0, import_core.assert)(key !== void 0);
|
|
646
655
|
const value = values[key];
|
|
647
656
|
const cached = this.cache[key];
|
|
648
657
|
if (!deepArrayEqual(value, cached)) {
|
|
@@ -657,46 +666,13 @@ var GLState = class {
|
|
|
657
666
|
return { valueChanged, oldValue };
|
|
658
667
|
}
|
|
659
668
|
};
|
|
660
|
-
function getContextState(gl) {
|
|
661
|
-
return gl.state;
|
|
662
|
-
}
|
|
663
|
-
function trackContextState(gl, options) {
|
|
664
|
-
const { enable: enable2 = true, copyState } = options;
|
|
665
|
-
(0, import_core.assert)(copyState !== void 0);
|
|
666
|
-
if (!gl.state) {
|
|
667
|
-
gl.state = new GLState(gl, { copyState });
|
|
668
|
-
installProgramSpy(gl);
|
|
669
|
-
for (const key in GL_HOOKED_SETTERS) {
|
|
670
|
-
const setter = GL_HOOKED_SETTERS[key];
|
|
671
|
-
installSetterSpy(gl, key, setter);
|
|
672
|
-
}
|
|
673
|
-
installGetterOverride(gl, "getParameter");
|
|
674
|
-
installGetterOverride(gl, "isEnabled");
|
|
675
|
-
}
|
|
676
|
-
const glState = getContextState(gl);
|
|
677
|
-
glState.enable = enable2;
|
|
678
|
-
return gl;
|
|
679
|
-
}
|
|
680
|
-
function pushContextState(gl) {
|
|
681
|
-
let glState = getContextState(gl);
|
|
682
|
-
if (!glState) {
|
|
683
|
-
trackContextState(gl, { copyState: false });
|
|
684
|
-
glState = getContextState(gl);
|
|
685
|
-
}
|
|
686
|
-
glState.push();
|
|
687
|
-
}
|
|
688
|
-
function popContextState(gl) {
|
|
689
|
-
const glState = getContextState(gl);
|
|
690
|
-
(0, import_core.assert)(glState);
|
|
691
|
-
glState.pop();
|
|
692
|
-
}
|
|
693
669
|
function installGetterOverride(gl, functionName) {
|
|
694
670
|
const originalGetterFunc = gl[functionName].bind(gl);
|
|
695
671
|
gl[functionName] = function get(pname) {
|
|
696
672
|
if (pname === void 0 || NON_CACHE_PARAMETERS.has(pname)) {
|
|
697
673
|
return originalGetterFunc(pname);
|
|
698
674
|
}
|
|
699
|
-
const glState =
|
|
675
|
+
const glState = WebGLStateTracker.get(gl);
|
|
700
676
|
if (!(pname in glState.cache)) {
|
|
701
677
|
glState.cache[pname] = originalGetterFunc(pname);
|
|
702
678
|
}
|
|
@@ -719,7 +695,7 @@ function installSetterSpy(gl, functionName, setter) {
|
|
|
719
695
|
}
|
|
720
696
|
const originalSetterFunc = gl[functionName].bind(gl);
|
|
721
697
|
gl[functionName] = function set(...params) {
|
|
722
|
-
const glState =
|
|
698
|
+
const glState = WebGLStateTracker.get(gl);
|
|
723
699
|
const { valueChanged, oldValue } = setter(glState._updateCache, ...params);
|
|
724
700
|
if (valueChanged) {
|
|
725
701
|
originalSetterFunc(...params);
|
|
@@ -734,7 +710,7 @@ function installSetterSpy(gl, functionName, setter) {
|
|
|
734
710
|
function installProgramSpy(gl) {
|
|
735
711
|
const originalUseProgram = gl.useProgram.bind(gl);
|
|
736
712
|
gl.useProgram = function useProgramLuma(handle) {
|
|
737
|
-
const glState =
|
|
713
|
+
const glState = WebGLStateTracker.get(gl);
|
|
738
714
|
if (glState.program !== handle) {
|
|
739
715
|
originalUseProgram(handle);
|
|
740
716
|
glState.program = handle;
|
|
@@ -857,10 +833,10 @@ function identifyGPUType(vendor, renderer) {
|
|
|
857
833
|
}
|
|
858
834
|
|
|
859
835
|
// dist/adapter/device-helpers/webgl-device-features.js
|
|
860
|
-
var
|
|
836
|
+
var import_core2 = require("@luma.gl/core");
|
|
861
837
|
|
|
862
838
|
// dist/adapter/converters/texture-formats.js
|
|
863
|
-
var
|
|
839
|
+
var import_core = require("@luma.gl/core");
|
|
864
840
|
var import_constants4 = require("@luma.gl/constants");
|
|
865
841
|
|
|
866
842
|
// dist/adapter/converters/vertex-formats.js
|
|
@@ -952,26 +928,6 @@ function checkTextureFeature(gl, feature, extensions) {
|
|
|
952
928
|
return textureExtensions.every((extension) => getWebGLExtension(gl, extension, extensions));
|
|
953
929
|
}
|
|
954
930
|
var TEXTURE_FORMATS = {
|
|
955
|
-
// Unsized formats that leave the precision up to the driver. TODO - Fix bpp constants
|
|
956
|
-
"rgb8unorm-unsized": {
|
|
957
|
-
gl: 6407,
|
|
958
|
-
b: 4,
|
|
959
|
-
c: 2,
|
|
960
|
-
bpp: 4,
|
|
961
|
-
dataFormat: 6407,
|
|
962
|
-
types: [5121, 33635]
|
|
963
|
-
},
|
|
964
|
-
"rgba8unorm-unsized": {
|
|
965
|
-
gl: 6408,
|
|
966
|
-
b: 4,
|
|
967
|
-
c: 2,
|
|
968
|
-
bpp: 4,
|
|
969
|
-
dataFormat: 6408,
|
|
970
|
-
types: [5121, 32819, 32820]
|
|
971
|
-
},
|
|
972
|
-
// 'r8unorm-unsized': {gl: GL.LUMINANCE, b: 4, c: 2, bpp: 4},
|
|
973
|
-
// 'rgb8unorm-srgb-unsized': {gl: GL.SRGB_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
|
|
974
|
-
// 'rgba8unorm-srgb-unsized': {gl: GL.SRGB_ALPHA_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
|
|
975
931
|
// 8-bit formats
|
|
976
932
|
"r8unorm": { gl: 33321, b: 1, c: 1, rb: true },
|
|
977
933
|
"r8snorm": { gl: 36756, b: 1, c: 1, render: snorm8_renderable },
|
|
@@ -1005,7 +961,6 @@ var TEXTURE_FORMATS = {
|
|
|
1005
961
|
"bgra8unorm-srgb": { b: 4, c: 4 },
|
|
1006
962
|
"rg16uint": { gl: 33338, b: 4, c: 1, bpp: 4 },
|
|
1007
963
|
"rg16sint": { gl: 33337, b: 4, c: 2, bpp: 4 },
|
|
1008
|
-
// When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension
|
|
1009
964
|
"rg16float": { gl: 33327, bpp: 4, b: 4, c: 2, render: float16_renderable, filter: float16_filterable, rb: true },
|
|
1010
965
|
"rg16unorm-webgl": { gl: 33324, b: 2, c: 2, render: norm16_renderable },
|
|
1011
966
|
"rg16snorm-webgl": { gl: 36761, b: 2, c: 2, render: snorm16_renderable },
|
|
@@ -1087,17 +1042,6 @@ var TEXTURE_FORMATS = {
|
|
|
1087
1042
|
dataFormat: 34041,
|
|
1088
1043
|
types: [34042]
|
|
1089
1044
|
},
|
|
1090
|
-
// "depth24unorm-stencil8" feature
|
|
1091
|
-
"depth24unorm-stencil8": {
|
|
1092
|
-
gl: 35056,
|
|
1093
|
-
b: 4,
|
|
1094
|
-
c: 2,
|
|
1095
|
-
p: 1,
|
|
1096
|
-
attachment: 33306,
|
|
1097
|
-
dataFormat: 34041,
|
|
1098
|
-
types: [34042],
|
|
1099
|
-
rb: true
|
|
1100
|
-
},
|
|
1101
1045
|
// "depth32float-stencil8" feature - TODO below is render buffer only?
|
|
1102
1046
|
"depth32float-stencil8": {
|
|
1103
1047
|
gl: 36013,
|
|
@@ -1179,31 +1123,6 @@ var TEXTURE_FORMATS = {
|
|
|
1179
1123
|
"atc-rgba-unorm-webgl": { gl: 35986, f: texture_compression_atc_webgl },
|
|
1180
1124
|
"atc-rgbai-unorm-webgl": { gl: 34798, f: texture_compression_atc_webgl }
|
|
1181
1125
|
};
|
|
1182
|
-
var DATA_FORMAT_CHANNELS = {
|
|
1183
|
-
[6403]: 1,
|
|
1184
|
-
[36244]: 1,
|
|
1185
|
-
[33319]: 2,
|
|
1186
|
-
[33320]: 2,
|
|
1187
|
-
[6407]: 3,
|
|
1188
|
-
[36248]: 3,
|
|
1189
|
-
[6408]: 4,
|
|
1190
|
-
[36249]: 4,
|
|
1191
|
-
[6402]: 1,
|
|
1192
|
-
[34041]: 1,
|
|
1193
|
-
[6406]: 1,
|
|
1194
|
-
[6409]: 1,
|
|
1195
|
-
[6410]: 2
|
|
1196
|
-
};
|
|
1197
|
-
var TYPE_SIZES = {
|
|
1198
|
-
[5126]: 4,
|
|
1199
|
-
[5125]: 4,
|
|
1200
|
-
[5124]: 4,
|
|
1201
|
-
[5123]: 2,
|
|
1202
|
-
[5122]: 2,
|
|
1203
|
-
[5131]: 2,
|
|
1204
|
-
[5120]: 1,
|
|
1205
|
-
[5121]: 1
|
|
1206
|
-
};
|
|
1207
1126
|
function isTextureFormatSupported(gl, format, extensions) {
|
|
1208
1127
|
const info = TEXTURE_FORMATS[format];
|
|
1209
1128
|
if (!info) {
|
|
@@ -1212,34 +1131,16 @@ function isTextureFormatSupported(gl, format, extensions) {
|
|
|
1212
1131
|
if (info.gl === void 0) {
|
|
1213
1132
|
return false;
|
|
1214
1133
|
}
|
|
1134
|
+
const feature = info.f;
|
|
1135
|
+
if (feature) {
|
|
1136
|
+
return checkTextureFeature(gl, feature, extensions);
|
|
1137
|
+
}
|
|
1215
1138
|
const extension = info.x || info.gl2ext;
|
|
1216
1139
|
if (extension) {
|
|
1217
1140
|
return Boolean(getWebGLExtension(gl, extension, extensions));
|
|
1218
1141
|
}
|
|
1219
1142
|
return true;
|
|
1220
1143
|
}
|
|
1221
|
-
function isRenderbufferFormatSupported(gl, format, extensions) {
|
|
1222
|
-
var _a;
|
|
1223
|
-
return isTextureFormatSupported(gl, format, extensions) && ((_a = TEXTURE_FORMATS[format]) == null ? void 0 : _a.rb);
|
|
1224
|
-
}
|
|
1225
|
-
function convertGLToTextureFormat(format) {
|
|
1226
|
-
if (typeof format === "string") {
|
|
1227
|
-
return format;
|
|
1228
|
-
}
|
|
1229
|
-
const entry = Object.entries(TEXTURE_FORMATS).find(([, entry2]) => entry2.gl === format);
|
|
1230
|
-
if (!entry) {
|
|
1231
|
-
throw new Error(`Unknown texture format ${format}`);
|
|
1232
|
-
}
|
|
1233
|
-
return entry[0];
|
|
1234
|
-
}
|
|
1235
|
-
function convertTextureFormatToGL(format) {
|
|
1236
|
-
const formatInfo = TEXTURE_FORMATS[format];
|
|
1237
|
-
const webglFormat = formatInfo == null ? void 0 : formatInfo.gl;
|
|
1238
|
-
if (webglFormat === void 0) {
|
|
1239
|
-
throw new Error(`Unsupported texture format ${format}`);
|
|
1240
|
-
}
|
|
1241
|
-
return webglFormat;
|
|
1242
|
-
}
|
|
1243
1144
|
function isTextureFormatFilterable(gl, format, extensions) {
|
|
1244
1145
|
if (!isTextureFormatSupported(gl, format, extensions)) {
|
|
1245
1146
|
return false;
|
|
@@ -1248,7 +1149,7 @@ function isTextureFormatFilterable(gl, format, extensions) {
|
|
|
1248
1149
|
return false;
|
|
1249
1150
|
}
|
|
1250
1151
|
try {
|
|
1251
|
-
const decoded = (0,
|
|
1152
|
+
const decoded = (0, import_core.decodeTextureFormat)(format);
|
|
1252
1153
|
if (decoded.signed) {
|
|
1253
1154
|
return false;
|
|
1254
1155
|
}
|
|
@@ -1272,18 +1173,17 @@ function isTextureFormatRenderable(gl, format, extensions) {
|
|
|
1272
1173
|
}
|
|
1273
1174
|
return true;
|
|
1274
1175
|
}
|
|
1275
|
-
function
|
|
1176
|
+
function getTextureFormatWebGL(format) {
|
|
1276
1177
|
var _a;
|
|
1277
1178
|
const formatData = TEXTURE_FORMATS[format];
|
|
1278
1179
|
const webglFormat = convertTextureFormatToGL(format);
|
|
1279
|
-
const decoded = (0,
|
|
1180
|
+
const decoded = (0, import_core.decodeTextureFormat)(format);
|
|
1280
1181
|
return {
|
|
1281
|
-
|
|
1282
|
-
|
|
1182
|
+
internalFormat: webglFormat,
|
|
1183
|
+
format: (formatData == null ? void 0 : formatData.dataFormat) || getWebGLPixelDataFormat(decoded.channels, decoded.integer, decoded.normalized, webglFormat),
|
|
1283
1184
|
// depth formats don't have a type
|
|
1284
1185
|
type: decoded.dataType ? getGLFromVertexType(decoded.dataType) : ((_a = formatData == null ? void 0 : formatData.types) == null ? void 0 : _a[0]) || 5121,
|
|
1285
|
-
|
|
1286
|
-
compressed: decoded.compressed
|
|
1186
|
+
compressed: decoded.compressed || false
|
|
1287
1187
|
};
|
|
1288
1188
|
}
|
|
1289
1189
|
function getDepthStencilAttachmentWebGL(format) {
|
|
@@ -1293,17 +1193,11 @@ function getDepthStencilAttachmentWebGL(format) {
|
|
|
1293
1193
|
}
|
|
1294
1194
|
return info.attachment;
|
|
1295
1195
|
}
|
|
1296
|
-
function
|
|
1297
|
-
const params = getWebGLTextureParameters(format);
|
|
1298
|
-
const channels = DATA_FORMAT_CHANNELS[params.dataFormat] || 4;
|
|
1299
|
-
const channelSize = TYPE_SIZES[params.type] || 1;
|
|
1300
|
-
return channels * channelSize;
|
|
1301
|
-
}
|
|
1302
|
-
function getWebGLPixelDataFormat(dataFormat, integer, normalized, format) {
|
|
1196
|
+
function getWebGLPixelDataFormat(channels, integer, normalized, format) {
|
|
1303
1197
|
if (format === 6408 || format === 6407) {
|
|
1304
1198
|
return format;
|
|
1305
1199
|
}
|
|
1306
|
-
switch (
|
|
1200
|
+
switch (channels) {
|
|
1307
1201
|
case "r":
|
|
1308
1202
|
return integer && !normalized ? 36244 : 6403;
|
|
1309
1203
|
case "rg":
|
|
@@ -1312,10 +1206,20 @@ function getWebGLPixelDataFormat(dataFormat, integer, normalized, format) {
|
|
|
1312
1206
|
return integer && !normalized ? 36248 : 6407;
|
|
1313
1207
|
case "rgba":
|
|
1314
1208
|
return integer && !normalized ? 36249 : 6408;
|
|
1209
|
+
case "bgra":
|
|
1210
|
+
throw new Error("bgra pixels not supported by WebGL");
|
|
1315
1211
|
default:
|
|
1316
1212
|
return 6408;
|
|
1317
1213
|
}
|
|
1318
1214
|
}
|
|
1215
|
+
function convertTextureFormatToGL(format) {
|
|
1216
|
+
const formatInfo = TEXTURE_FORMATS[format];
|
|
1217
|
+
const webglFormat = formatInfo == null ? void 0 : formatInfo.gl;
|
|
1218
|
+
if (webglFormat === void 0) {
|
|
1219
|
+
throw new Error(`Unsupported texture format ${format}`);
|
|
1220
|
+
}
|
|
1221
|
+
return webglFormat;
|
|
1222
|
+
}
|
|
1319
1223
|
|
|
1320
1224
|
// dist/adapter/device-helpers/webgl-device-features.js
|
|
1321
1225
|
var WEBGL_FEATURES = {
|
|
@@ -1325,7 +1229,6 @@ var WEBGL_FEATURES = {
|
|
|
1325
1229
|
// 'timestamp-query' // GPUQueryType "timestamp-query"
|
|
1326
1230
|
// "indirect-first-instance"
|
|
1327
1231
|
// Textures are handled by getTextureFeatures()
|
|
1328
|
-
// 'depth24unorm-stencil8' // GPUTextureFormat 'depth24unorm-stencil8'
|
|
1329
1232
|
// 'depth32float-stencil8' // GPUTextureFormat 'depth32float-stencil8'
|
|
1330
1233
|
// optional WebGL features
|
|
1331
1234
|
"timer-query-webgl": "EXT_disjoint_timer_query_webgl2",
|
|
@@ -1337,7 +1240,7 @@ var WEBGL_FEATURES = {
|
|
|
1337
1240
|
"shader-conservative-depth-webgl": "EXT_conservative_depth"
|
|
1338
1241
|
// Textures are handled by getTextureFeatures()
|
|
1339
1242
|
};
|
|
1340
|
-
var WebGLDeviceFeatures = class extends
|
|
1243
|
+
var WebGLDeviceFeatures = class extends import_core2.DeviceFeatures {
|
|
1341
1244
|
gl;
|
|
1342
1245
|
extensions;
|
|
1343
1246
|
testedFeatures = /* @__PURE__ */ new Set();
|
|
@@ -1357,7 +1260,8 @@ var WebGLDeviceFeatures = class extends import_core3.DeviceFeatures {
|
|
|
1357
1260
|
return [];
|
|
1358
1261
|
}
|
|
1359
1262
|
has(feature) {
|
|
1360
|
-
|
|
1263
|
+
var _a;
|
|
1264
|
+
if ((_a = this.disabledFeatures) == null ? void 0 : _a[feature]) {
|
|
1361
1265
|
return false;
|
|
1362
1266
|
}
|
|
1363
1267
|
if (!this.testedFeatures.has(feature)) {
|
|
@@ -1391,9 +1295,9 @@ var WebGLDeviceFeatures = class extends import_core3.DeviceFeatures {
|
|
|
1391
1295
|
};
|
|
1392
1296
|
|
|
1393
1297
|
// dist/adapter/device-helpers/webgl-device-limits.js
|
|
1394
|
-
var
|
|
1298
|
+
var import_core3 = require("@luma.gl/core");
|
|
1395
1299
|
var import_constants5 = require("@luma.gl/constants");
|
|
1396
|
-
var WebGLDeviceLimits = class extends
|
|
1300
|
+
var WebGLDeviceLimits = class extends import_core3.DeviceLimits {
|
|
1397
1301
|
get maxTextureDimension1D() {
|
|
1398
1302
|
return 0;
|
|
1399
1303
|
}
|
|
@@ -1497,19 +1401,19 @@ var WebGLDeviceLimits = class extends import_core4.DeviceLimits {
|
|
|
1497
1401
|
if (this.limits[parameter] === void 0) {
|
|
1498
1402
|
this.limits[parameter] = this.gl.getParameter(parameter);
|
|
1499
1403
|
}
|
|
1500
|
-
return this.limits[parameter];
|
|
1404
|
+
return this.limits[parameter] || 0;
|
|
1501
1405
|
}
|
|
1502
1406
|
};
|
|
1503
1407
|
|
|
1504
1408
|
// dist/adapter/webgl-canvas-context.js
|
|
1505
|
-
var
|
|
1409
|
+
var import_core9 = require("@luma.gl/core");
|
|
1506
1410
|
|
|
1507
1411
|
// dist/adapter/resources/webgl-framebuffer.js
|
|
1508
|
-
var
|
|
1412
|
+
var import_core8 = require("@luma.gl/core");
|
|
1509
1413
|
var import_constants11 = require("@luma.gl/constants");
|
|
1510
1414
|
|
|
1511
1415
|
// dist/adapter/resources/webgl-texture.js
|
|
1512
|
-
var
|
|
1416
|
+
var import_core7 = require("@luma.gl/core");
|
|
1513
1417
|
var import_constants10 = require("@luma.gl/constants");
|
|
1514
1418
|
|
|
1515
1419
|
// dist/context/state-tracker/with-parameters.js
|
|
@@ -1518,17 +1422,18 @@ function withGLParameters(gl, parameters, func) {
|
|
|
1518
1422
|
return func(gl);
|
|
1519
1423
|
}
|
|
1520
1424
|
const { nocatch = true } = parameters;
|
|
1521
|
-
|
|
1425
|
+
const webglState = WebGLStateTracker.get(gl);
|
|
1426
|
+
webglState.push();
|
|
1522
1427
|
setGLParameters(gl, parameters);
|
|
1523
1428
|
let value;
|
|
1524
1429
|
if (nocatch) {
|
|
1525
1430
|
value = func(gl);
|
|
1526
|
-
|
|
1431
|
+
webglState.pop();
|
|
1527
1432
|
} else {
|
|
1528
1433
|
try {
|
|
1529
1434
|
value = func(gl);
|
|
1530
1435
|
} finally {
|
|
1531
|
-
|
|
1436
|
+
webglState.pop();
|
|
1532
1437
|
}
|
|
1533
1438
|
}
|
|
1534
1439
|
return value;
|
|
@@ -1544,32 +1449,33 @@ function isObjectEmpty2(object) {
|
|
|
1544
1449
|
var import_constants7 = require("@luma.gl/constants");
|
|
1545
1450
|
|
|
1546
1451
|
// dist/adapter/converters/device-parameters.js
|
|
1547
|
-
var
|
|
1452
|
+
var import_core4 = require("@luma.gl/core");
|
|
1548
1453
|
var import_constants6 = require("@luma.gl/constants");
|
|
1549
1454
|
function withDeviceAndGLParameters(device, parameters, glParameters, func) {
|
|
1550
|
-
if ((
|
|
1455
|
+
if (isObjectEmpty3(parameters)) {
|
|
1551
1456
|
return func(device);
|
|
1552
1457
|
}
|
|
1553
1458
|
const webglDevice = device;
|
|
1554
|
-
|
|
1459
|
+
webglDevice.pushState();
|
|
1555
1460
|
try {
|
|
1556
1461
|
setDeviceParameters(device, parameters);
|
|
1557
1462
|
setGLParameters(webglDevice.gl, glParameters);
|
|
1558
1463
|
return func(device);
|
|
1559
1464
|
} finally {
|
|
1560
|
-
|
|
1465
|
+
webglDevice.popState();
|
|
1561
1466
|
}
|
|
1562
1467
|
}
|
|
1563
1468
|
function withDeviceParameters(device, parameters, func) {
|
|
1564
|
-
if ((
|
|
1469
|
+
if (isObjectEmpty3(parameters)) {
|
|
1565
1470
|
return func(device);
|
|
1566
1471
|
}
|
|
1567
|
-
|
|
1472
|
+
const webglDevice = device;
|
|
1473
|
+
webglDevice.pushState();
|
|
1568
1474
|
try {
|
|
1569
1475
|
setDeviceParameters(device, parameters);
|
|
1570
1476
|
return func(device);
|
|
1571
1477
|
} finally {
|
|
1572
|
-
|
|
1478
|
+
webglDevice.popState();
|
|
1573
1479
|
}
|
|
1574
1480
|
}
|
|
1575
1481
|
function setDeviceParameters(device, parameters) {
|
|
@@ -1672,7 +1578,7 @@ function setDeviceParameters(device, parameters) {
|
|
|
1672
1578
|
gl.stencilMaskSeparate(1029, mask);
|
|
1673
1579
|
}
|
|
1674
1580
|
if (parameters.stencilReadMask) {
|
|
1675
|
-
|
|
1581
|
+
import_core4.log.warn("stencilReadMask not supported under WebGL");
|
|
1676
1582
|
}
|
|
1677
1583
|
if (parameters.stencilCompare) {
|
|
1678
1584
|
const mask = parameters.stencilReadMask || 4294967295;
|
|
@@ -1688,8 +1594,16 @@ function setDeviceParameters(device, parameters) {
|
|
|
1688
1594
|
gl.stencilOpSeparate(1028, sfail, dpfail, dppass);
|
|
1689
1595
|
gl.stencilOpSeparate(1029, sfail, dpfail, dppass);
|
|
1690
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
|
+
}
|
|
1691
1606
|
if (parameters.blendColorOperation || parameters.blendAlphaOperation) {
|
|
1692
|
-
gl.enable(3042);
|
|
1693
1607
|
const colorEquation = convertBlendOperationToEquation("blendColorOperation", parameters.blendColorOperation || "add");
|
|
1694
1608
|
const alphaEquation = convertBlendOperationToEquation("blendAlphaOperation", parameters.blendAlphaOperation || "add");
|
|
1695
1609
|
gl.blendEquationSeparate(colorEquation, alphaEquation);
|
|
@@ -1764,6 +1678,14 @@ function map(parameter, value, valueMap) {
|
|
|
1764
1678
|
function mapBoolean(parameter, value) {
|
|
1765
1679
|
return value;
|
|
1766
1680
|
}
|
|
1681
|
+
function isObjectEmpty3(obj) {
|
|
1682
|
+
let isEmpty = true;
|
|
1683
|
+
for (const key in obj) {
|
|
1684
|
+
isEmpty = false;
|
|
1685
|
+
break;
|
|
1686
|
+
}
|
|
1687
|
+
return isEmpty;
|
|
1688
|
+
}
|
|
1767
1689
|
|
|
1768
1690
|
// dist/adapter/converters/sampler-parameters.js
|
|
1769
1691
|
function convertSamplerParametersToWebGL(props) {
|
|
@@ -1830,136 +1752,10 @@ function convertMinFilterMode(minFilter, mipmapFilter) {
|
|
|
1830
1752
|
}
|
|
1831
1753
|
}
|
|
1832
1754
|
|
|
1833
|
-
// dist/adapter/resources/webgl-buffer.js
|
|
1834
|
-
var import_core6 = require("@luma.gl/core");
|
|
1835
|
-
var import_constants8 = require("@luma.gl/constants");
|
|
1836
|
-
var WEBGLBuffer = class extends import_core6.Buffer {
|
|
1837
|
-
device;
|
|
1838
|
-
gl;
|
|
1839
|
-
handle;
|
|
1840
|
-
/** Target in OpenGL defines the type of buffer */
|
|
1841
|
-
glTarget;
|
|
1842
|
-
/** Usage is a hint on how frequently the buffer will be updates */
|
|
1843
|
-
glUsage;
|
|
1844
|
-
/** Index type is needed when issuing draw calls, so we pre-compute it */
|
|
1845
|
-
glIndexType = 5123;
|
|
1846
|
-
/** Number of bytes allocated on the GPU for this buffer */
|
|
1847
|
-
byteLength;
|
|
1848
|
-
/** Number of bytes used */
|
|
1849
|
-
bytesUsed;
|
|
1850
|
-
constructor(device, props = {}) {
|
|
1851
|
-
super(device, props);
|
|
1852
|
-
this.device = device;
|
|
1853
|
-
this.gl = this.device.gl;
|
|
1854
|
-
const handle = typeof props === "object" ? props.handle : void 0;
|
|
1855
|
-
this.handle = handle || this.gl.createBuffer();
|
|
1856
|
-
device.setSpectorMetadata(this.handle, { ...this.props, data: typeof this.props.data });
|
|
1857
|
-
this.glTarget = getWebGLTarget(this.props.usage);
|
|
1858
|
-
this.glUsage = getWebGLUsage(this.props.usage);
|
|
1859
|
-
this.glIndexType = this.props.indexType === "uint32" ? 5125 : 5123;
|
|
1860
|
-
if (props.data) {
|
|
1861
|
-
this._initWithData(props.data, props.byteOffset, props.byteLength);
|
|
1862
|
-
} else {
|
|
1863
|
-
this._initWithByteLength(props.byteLength || 0);
|
|
1864
|
-
}
|
|
1865
|
-
}
|
|
1866
|
-
// PRIVATE METHODS
|
|
1867
|
-
/** Allocate a new buffer and initialize to contents of typed array */
|
|
1868
|
-
_initWithData(data, byteOffset = 0, byteLength = data.byteLength + byteOffset) {
|
|
1869
|
-
const glTarget = this.glTarget;
|
|
1870
|
-
this.gl.bindBuffer(glTarget, this.handle);
|
|
1871
|
-
this.gl.bufferData(glTarget, byteLength, this.glUsage);
|
|
1872
|
-
this.gl.bufferSubData(glTarget, byteOffset, data);
|
|
1873
|
-
this.gl.bindBuffer(glTarget, null);
|
|
1874
|
-
this.bytesUsed = byteLength;
|
|
1875
|
-
this.byteLength = byteLength;
|
|
1876
|
-
this._setDebugData(data, byteOffset, byteLength);
|
|
1877
|
-
this.trackAllocatedMemory(byteLength);
|
|
1878
|
-
}
|
|
1879
|
-
// Allocate a GPU buffer of specified size.
|
|
1880
|
-
_initWithByteLength(byteLength) {
|
|
1881
|
-
(0, import_core6.assert)(byteLength >= 0);
|
|
1882
|
-
let data = byteLength;
|
|
1883
|
-
if (byteLength === 0) {
|
|
1884
|
-
data = new Float32Array(0);
|
|
1885
|
-
}
|
|
1886
|
-
const glTarget = this.glTarget;
|
|
1887
|
-
this.gl.bindBuffer(glTarget, this.handle);
|
|
1888
|
-
this.gl.bufferData(glTarget, data, this.glUsage);
|
|
1889
|
-
this.gl.bindBuffer(glTarget, null);
|
|
1890
|
-
this.bytesUsed = byteLength;
|
|
1891
|
-
this.byteLength = byteLength;
|
|
1892
|
-
this._setDebugData(null, 0, byteLength);
|
|
1893
|
-
this.trackAllocatedMemory(byteLength);
|
|
1894
|
-
return this;
|
|
1895
|
-
}
|
|
1896
|
-
destroy() {
|
|
1897
|
-
if (!this.destroyed && this.handle) {
|
|
1898
|
-
this.removeStats();
|
|
1899
|
-
this.trackDeallocatedMemory();
|
|
1900
|
-
this.gl.deleteBuffer(this.handle);
|
|
1901
|
-
this.destroyed = true;
|
|
1902
|
-
this.handle = null;
|
|
1903
|
-
}
|
|
1904
|
-
}
|
|
1905
|
-
write(data, byteOffset = 0) {
|
|
1906
|
-
const srcOffset = 0;
|
|
1907
|
-
const byteLength = void 0;
|
|
1908
|
-
const glTarget = 36663;
|
|
1909
|
-
this.gl.bindBuffer(glTarget, this.handle);
|
|
1910
|
-
if (srcOffset !== 0 || byteLength !== void 0) {
|
|
1911
|
-
this.gl.bufferSubData(glTarget, byteOffset, data, srcOffset, byteLength);
|
|
1912
|
-
} else {
|
|
1913
|
-
this.gl.bufferSubData(glTarget, byteOffset, data);
|
|
1914
|
-
}
|
|
1915
|
-
this.gl.bindBuffer(glTarget, null);
|
|
1916
|
-
this._setDebugData(data, byteOffset, data.byteLength);
|
|
1917
|
-
}
|
|
1918
|
-
/** Asynchronously read data from the buffer */
|
|
1919
|
-
async readAsync(byteOffset = 0, byteLength) {
|
|
1920
|
-
return this.readSyncWebGL(byteOffset, byteLength);
|
|
1921
|
-
}
|
|
1922
|
-
/** Synchronously read data from the buffer. WebGL only. */
|
|
1923
|
-
readSyncWebGL(byteOffset = 0, byteLength) {
|
|
1924
|
-
byteLength = byteLength ?? this.byteLength - byteOffset;
|
|
1925
|
-
const data = new Uint8Array(byteLength);
|
|
1926
|
-
const dstOffset = 0;
|
|
1927
|
-
this.gl.bindBuffer(36662, this.handle);
|
|
1928
|
-
this.gl.getBufferSubData(36662, byteOffset, data, dstOffset, byteLength);
|
|
1929
|
-
this.gl.bindBuffer(36662, null);
|
|
1930
|
-
this._setDebugData(data, byteOffset, byteLength);
|
|
1931
|
-
return data;
|
|
1932
|
-
}
|
|
1933
|
-
};
|
|
1934
|
-
function getWebGLTarget(usage) {
|
|
1935
|
-
if (usage & import_core6.Buffer.INDEX) {
|
|
1936
|
-
return 34963;
|
|
1937
|
-
}
|
|
1938
|
-
if (usage & import_core6.Buffer.VERTEX) {
|
|
1939
|
-
return 34962;
|
|
1940
|
-
}
|
|
1941
|
-
if (usage & import_core6.Buffer.UNIFORM) {
|
|
1942
|
-
return 35345;
|
|
1943
|
-
}
|
|
1944
|
-
return 34962;
|
|
1945
|
-
}
|
|
1946
|
-
function getWebGLUsage(usage) {
|
|
1947
|
-
if (usage & import_core6.Buffer.INDEX) {
|
|
1948
|
-
return 35044;
|
|
1949
|
-
}
|
|
1950
|
-
if (usage & import_core6.Buffer.VERTEX) {
|
|
1951
|
-
return 35044;
|
|
1952
|
-
}
|
|
1953
|
-
if (usage & import_core6.Buffer.UNIFORM) {
|
|
1954
|
-
return 35048;
|
|
1955
|
-
}
|
|
1956
|
-
return 35044;
|
|
1957
|
-
}
|
|
1958
|
-
|
|
1959
1755
|
// dist/adapter/resources/webgl-sampler.js
|
|
1960
|
-
var
|
|
1961
|
-
var
|
|
1962
|
-
var WEBGLSampler = class extends
|
|
1756
|
+
var import_core5 = require("@luma.gl/core");
|
|
1757
|
+
var import_constants8 = require("@luma.gl/constants");
|
|
1758
|
+
var WEBGLSampler = class extends import_core5.Sampler {
|
|
1963
1759
|
device;
|
|
1964
1760
|
handle;
|
|
1965
1761
|
parameters;
|
|
@@ -1997,14 +1793,15 @@ var WEBGLSampler = class extends import_core7.Sampler {
|
|
|
1997
1793
|
};
|
|
1998
1794
|
|
|
1999
1795
|
// dist/adapter/resources/webgl-texture-view.js
|
|
2000
|
-
var
|
|
2001
|
-
var WEBGLTextureView = class extends
|
|
1796
|
+
var import_core6 = require("@luma.gl/core");
|
|
1797
|
+
var WEBGLTextureView = class extends import_core6.TextureView {
|
|
2002
1798
|
device;
|
|
2003
1799
|
gl;
|
|
2004
1800
|
handle;
|
|
1801
|
+
// Does not have a WebGL representation
|
|
2005
1802
|
texture;
|
|
2006
1803
|
constructor(device, props) {
|
|
2007
|
-
super(device, { ...
|
|
1804
|
+
super(device, { ...import_core6.Texture.defaultProps, ...props });
|
|
2008
1805
|
this.device = device;
|
|
2009
1806
|
this.gl = this.device.gl;
|
|
2010
1807
|
this.handle = null;
|
|
@@ -2012,164 +1809,253 @@ var WEBGLTextureView = class extends import_core8.TextureView {
|
|
|
2012
1809
|
}
|
|
2013
1810
|
};
|
|
2014
1811
|
|
|
2015
|
-
// dist/adapter/
|
|
2016
|
-
var
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
device;
|
|
2029
|
-
gl;
|
|
2030
|
-
handle;
|
|
2031
|
-
// (TODO - currently unused in WebGL, but WebGL 2 does support sampler objects) */
|
|
2032
|
-
sampler = void 0;
|
|
2033
|
-
view = void 0;
|
|
2034
|
-
// data;
|
|
2035
|
-
glFormat = void 0;
|
|
2036
|
-
type = void 0;
|
|
2037
|
-
dataFormat = void 0;
|
|
2038
|
-
mipmaps = void 0;
|
|
2039
|
-
/**
|
|
2040
|
-
* @note `target` cannot be modified by bind:
|
|
2041
|
-
* textures are special because when you first bind them to a target,
|
|
2042
|
-
* they get special information. When you first bind a texture as a
|
|
2043
|
-
* GL_TEXTURE_2D, you are saying that this texture is a 2D texture.
|
|
2044
|
-
* And it will always be a 2D texture; this state cannot be changed ever.
|
|
2045
|
-
* A texture that was first bound as a GL_TEXTURE_2D, must always be bound as a GL_TEXTURE_2D;
|
|
2046
|
-
* attempting to bind it as GL_TEXTURE_3D will give rise to a run-time error
|
|
2047
|
-
* */
|
|
2048
|
-
target;
|
|
2049
|
-
textureUnit = void 0;
|
|
2050
|
-
/**
|
|
2051
|
-
* Program.draw() checks the loaded flag of all textures to avoid
|
|
2052
|
-
* Textures that are still loading from promises
|
|
2053
|
-
* Set to true as soon as texture has been initialized with valid data
|
|
2054
|
-
*/
|
|
2055
|
-
loaded = false;
|
|
2056
|
-
_video;
|
|
2057
|
-
constructor(device, props) {
|
|
2058
|
-
var _a;
|
|
2059
|
-
super(device, { ...DEFAULT_WEBGL_TEXTURE_PROPS, format: "rgba8unorm", ...props });
|
|
2060
|
-
this.device = device;
|
|
2061
|
-
this.gl = this.device.gl;
|
|
2062
|
-
this.handle = this.props.handle || this.gl.createTexture();
|
|
2063
|
-
this.device.setSpectorMetadata(this.handle, { ...this.props, data: typeof this.props.data });
|
|
2064
|
-
this.glFormat = 6408;
|
|
2065
|
-
this.target = getWebGLTextureTarget(this.props);
|
|
2066
|
-
this.loaded = false;
|
|
2067
|
-
if (typeof ((_a = this.props) == null ? void 0 : _a.data) === "string") {
|
|
2068
|
-
Object.assign(this.props, { data: (0, import_core9.loadImage)(this.props.data) });
|
|
2069
|
-
}
|
|
2070
|
-
this.initialize(this.props);
|
|
2071
|
-
Object.seal(this);
|
|
1812
|
+
// dist/adapter/helpers/webgl-texture-utils.js
|
|
1813
|
+
var import_constants9 = require("@luma.gl/constants");
|
|
1814
|
+
function initializeTextureStorage(gl, levels, options) {
|
|
1815
|
+
const { dimension, width, height, depth = 0 } = options;
|
|
1816
|
+
const { glInternalFormat } = options;
|
|
1817
|
+
const glTarget = options.glTarget;
|
|
1818
|
+
switch (dimension) {
|
|
1819
|
+
case "2d-array":
|
|
1820
|
+
case "3d":
|
|
1821
|
+
gl.texStorage3D(glTarget, levels, glInternalFormat, width, height, depth);
|
|
1822
|
+
break;
|
|
1823
|
+
default:
|
|
1824
|
+
gl.texStorage2D(glTarget, levels, glInternalFormat, width, height);
|
|
2072
1825
|
}
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
1826
|
+
}
|
|
1827
|
+
function copyCPUImageToMipLevel(gl, image, options) {
|
|
1828
|
+
const { dimension, width, height, depth = 0, level = 0 } = options;
|
|
1829
|
+
const { x = 0, y = 0, z = 0 } = options;
|
|
1830
|
+
const { glFormat, glType } = options;
|
|
1831
|
+
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
1832
|
+
switch (dimension) {
|
|
1833
|
+
case "2d-array":
|
|
1834
|
+
case "3d":
|
|
1835
|
+
gl.texSubImage3D(glTarget, level, x, y, z, width, height, depth, glFormat, glType, image);
|
|
1836
|
+
break;
|
|
1837
|
+
case "2d":
|
|
1838
|
+
case "cube":
|
|
1839
|
+
gl.texSubImage2D(glTarget, level, x, y, width, height, glFormat, glType, image);
|
|
1840
|
+
break;
|
|
1841
|
+
default:
|
|
1842
|
+
throw new Error(dimension);
|
|
2080
1843
|
}
|
|
2081
|
-
|
|
2082
|
-
|
|
1844
|
+
}
|
|
1845
|
+
function copyCPUDataToMipLevel(gl, typedArray, options) {
|
|
1846
|
+
const { dimension, width, height, depth = 0, level = 0, byteOffset = 0 } = options;
|
|
1847
|
+
const { x = 0, y = 0, z = 0 } = options;
|
|
1848
|
+
const { glFormat, glType, compressed } = options;
|
|
1849
|
+
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
1850
|
+
switch (dimension) {
|
|
1851
|
+
case "2d-array":
|
|
1852
|
+
case "3d":
|
|
1853
|
+
if (compressed) {
|
|
1854
|
+
gl.compressedTexSubImage3D(glTarget, level, x, y, z, width, height, depth, glFormat, typedArray, byteOffset);
|
|
1855
|
+
} else {
|
|
1856
|
+
gl.texSubImage3D(glTarget, level, x, y, z, width, height, depth, glFormat, glType, typedArray, byteOffset);
|
|
1857
|
+
}
|
|
1858
|
+
break;
|
|
1859
|
+
case "2d":
|
|
1860
|
+
case "cube":
|
|
1861
|
+
if (compressed) {
|
|
1862
|
+
gl.compressedTexSubImage2D(glTarget, level, x, y, width, height, glFormat, typedArray, byteOffset);
|
|
1863
|
+
} else {
|
|
1864
|
+
gl.texSubImage2D(glTarget, level, x, y, width, height, glFormat, glType, typedArray, byteOffset);
|
|
1865
|
+
}
|
|
1866
|
+
break;
|
|
1867
|
+
default:
|
|
1868
|
+
throw new Error(dimension);
|
|
2083
1869
|
}
|
|
2084
|
-
|
|
2085
|
-
|
|
1870
|
+
}
|
|
1871
|
+
function getWebGLTextureTarget(dimension) {
|
|
1872
|
+
switch (dimension) {
|
|
1873
|
+
case "1d":
|
|
1874
|
+
break;
|
|
1875
|
+
case "2d":
|
|
1876
|
+
return 3553;
|
|
1877
|
+
case "3d":
|
|
1878
|
+
return 32879;
|
|
1879
|
+
case "cube":
|
|
1880
|
+
return 34067;
|
|
1881
|
+
case "2d-array":
|
|
1882
|
+
return 35866;
|
|
1883
|
+
case "cube-array":
|
|
1884
|
+
break;
|
|
2086
1885
|
}
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
1886
|
+
throw new Error(dimension);
|
|
1887
|
+
}
|
|
1888
|
+
function getWebGLCubeFaceTarget(glTarget, dimension, level) {
|
|
1889
|
+
return dimension === "cube" ? 34069 + level : glTarget;
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
// dist/adapter/resources/webgl-texture.js
|
|
1893
|
+
function normalizeTextureData(data, options) {
|
|
1894
|
+
let lodArray;
|
|
1895
|
+
if (ArrayBuffer.isView(data)) {
|
|
1896
|
+
lodArray = [
|
|
1897
|
+
{
|
|
1898
|
+
// ts-expect-error does data really need to be Uint8ClampedArray?
|
|
1899
|
+
data,
|
|
1900
|
+
width: options.width,
|
|
1901
|
+
height: options.height
|
|
1902
|
+
// depth: options.depth
|
|
1903
|
+
}
|
|
1904
|
+
];
|
|
1905
|
+
} else if (!Array.isArray(data)) {
|
|
1906
|
+
lodArray = [data];
|
|
1907
|
+
} else {
|
|
1908
|
+
lodArray = data;
|
|
1909
|
+
}
|
|
1910
|
+
return lodArray;
|
|
1911
|
+
}
|
|
1912
|
+
var WEBGLTexture = class extends import_core7.Texture {
|
|
1913
|
+
MAX_ATTRIBUTES;
|
|
1914
|
+
device;
|
|
1915
|
+
gl;
|
|
1916
|
+
handle;
|
|
1917
|
+
sampler = void 0;
|
|
1918
|
+
// TODO - currently unused in WebGL. Create dummy sampler?
|
|
1919
|
+
view = void 0;
|
|
1920
|
+
// TODO - currently unused in WebGL. Create dummy view?
|
|
1921
|
+
mipmaps = false;
|
|
1922
|
+
/**
|
|
1923
|
+
* @note `target` cannot be modified by bind:
|
|
1924
|
+
* textures are special because when you first bind them to a target,
|
|
1925
|
+
* When you first bind a texture as a GL_TEXTURE_2D, you are saying that this texture is a 2D texture.
|
|
1926
|
+
* And it will always be a 2D texture; this state cannot be changed ever.
|
|
1927
|
+
* A texture that was first bound as a GL_TEXTURE_2D, must always be bound as a GL_TEXTURE_2D;
|
|
1928
|
+
* attempting to bind it as GL_TEXTURE_3D will give rise to a run-time error
|
|
1929
|
+
*/
|
|
1930
|
+
glTarget;
|
|
1931
|
+
// Texture type
|
|
1932
|
+
/** The WebGL format - essentially channel structure */
|
|
1933
|
+
glFormat;
|
|
1934
|
+
/** The WebGL data format - the type of each channel */
|
|
1935
|
+
glType;
|
|
1936
|
+
/** The WebGL constant corresponding to the WebGPU style constant in format */
|
|
1937
|
+
glInternalFormat;
|
|
1938
|
+
/** Whether the internal format is compressed */
|
|
1939
|
+
compressed;
|
|
1940
|
+
// data;
|
|
1941
|
+
// inherited props
|
|
1942
|
+
// dimension: ...
|
|
1943
|
+
// format: GLTextureTarget;
|
|
1944
|
+
// width: number = undefined;
|
|
1945
|
+
// height: number = undefined;
|
|
1946
|
+
// depth: number = undefined;
|
|
1947
|
+
// state
|
|
1948
|
+
/** Texture binding slot */
|
|
1949
|
+
textureUnit = 0;
|
|
1950
|
+
/** For automatically updating video */
|
|
1951
|
+
_video = null;
|
|
1952
|
+
constructor(device, props) {
|
|
1953
|
+
super(device, { ...import_core7.Texture.defaultProps, ...props, data: void 0 });
|
|
1954
|
+
this.device = device;
|
|
1955
|
+
this.gl = this.device.gl;
|
|
1956
|
+
this.glTarget = getWebGLTextureTarget(this.props.dimension);
|
|
1957
|
+
const format = getTextureFormatWebGL(this.props.format);
|
|
1958
|
+
this.glInternalFormat = format.internalFormat;
|
|
1959
|
+
this.glFormat = format.format;
|
|
1960
|
+
this.glType = format.type;
|
|
1961
|
+
this.compressed = format.compressed;
|
|
1962
|
+
if (typeof HTMLVideoElement !== "undefined" && props.data instanceof HTMLVideoElement && // @ts-expect-error
|
|
1963
|
+
props.data.readyState < HTMLVideoElement.HAVE_METADATA) {
|
|
1964
|
+
const video = props.data;
|
|
2102
1965
|
this._video = null;
|
|
2103
|
-
|
|
2104
|
-
return this;
|
|
1966
|
+
video.addEventListener("loadeddata", () => this.initialize(props));
|
|
2105
1967
|
}
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
1968
|
+
this.initialize({ ...this.props, data: props.data });
|
|
1969
|
+
Object.seal(this);
|
|
1970
|
+
}
|
|
1971
|
+
/**
|
|
1972
|
+
* Initialize texture with supplied props
|
|
1973
|
+
*/
|
|
1974
|
+
// eslint-disable-next-line max-statements
|
|
1975
|
+
initialize(props = {}) {
|
|
1976
|
+
this.handle = this.props.handle || this.gl.createTexture();
|
|
1977
|
+
this.device.setSpectorMetadata(this.handle, { ...this.props, data: typeof this.props.data });
|
|
1978
|
+
const data = props.data;
|
|
1979
|
+
let { width, height } = props;
|
|
1980
|
+
if (!width || !height) {
|
|
1981
|
+
const textureSize = import_core7.Texture.getTextureDataSize(data);
|
|
1982
|
+
width = (textureSize == null ? void 0 : textureSize.width) || 1;
|
|
1983
|
+
height = (textureSize == null ? void 0 : textureSize.height) || 1;
|
|
2110
1984
|
}
|
|
2111
|
-
let { width, height, dataFormat, type, compressed = false } = props;
|
|
2112
|
-
const { depth = 0 } = props;
|
|
2113
|
-
const glFormat = convertTextureFormatToGL(props.format);
|
|
2114
|
-
({ width, height, compressed, dataFormat, type } = this._deduceParameters({
|
|
2115
|
-
format: props.format,
|
|
2116
|
-
type,
|
|
2117
|
-
dataFormat,
|
|
2118
|
-
compressed,
|
|
2119
|
-
data,
|
|
2120
|
-
width,
|
|
2121
|
-
height
|
|
2122
|
-
}));
|
|
2123
1985
|
this.width = width;
|
|
2124
1986
|
this.height = height;
|
|
2125
|
-
this.
|
|
2126
|
-
this.type = type;
|
|
2127
|
-
this.dataFormat = dataFormat;
|
|
2128
|
-
this.textureUnit = textureUnit;
|
|
2129
|
-
if (Number.isFinite(this.textureUnit)) {
|
|
2130
|
-
this.gl.activeTexture(33984 + this.textureUnit);
|
|
2131
|
-
this.gl.bindTexture(this.target, this.handle);
|
|
2132
|
-
}
|
|
2133
|
-
this.mipmaps = mipmaps;
|
|
2134
|
-
this.setImageData({
|
|
2135
|
-
data,
|
|
2136
|
-
width,
|
|
2137
|
-
height,
|
|
2138
|
-
depth,
|
|
2139
|
-
format: glFormat,
|
|
2140
|
-
type,
|
|
2141
|
-
dataFormat,
|
|
2142
|
-
// @ts-expect-error
|
|
2143
|
-
parameters: pixelStore,
|
|
2144
|
-
compressed
|
|
2145
|
-
});
|
|
1987
|
+
this.depth = props.depth;
|
|
2146
1988
|
this.setSampler(props.sampler);
|
|
2147
|
-
this.
|
|
2148
|
-
this.
|
|
2149
|
-
if (
|
|
1989
|
+
this.view = new WEBGLTextureView(this.device, { ...this.props, texture: this });
|
|
1990
|
+
this.bind();
|
|
1991
|
+
if (!this.props.data) {
|
|
1992
|
+
initializeTextureStorage(this.gl, this.mipLevels, this);
|
|
1993
|
+
}
|
|
1994
|
+
if (props.data) {
|
|
1995
|
+
switch (props.dimension) {
|
|
1996
|
+
case "1d":
|
|
1997
|
+
this.setTexture1DData(props.data);
|
|
1998
|
+
break;
|
|
1999
|
+
case "2d":
|
|
2000
|
+
this.setTexture2DData(props.data);
|
|
2001
|
+
break;
|
|
2002
|
+
case "3d":
|
|
2003
|
+
this.setTexture3DData(props.data);
|
|
2004
|
+
break;
|
|
2005
|
+
case "cube":
|
|
2006
|
+
this.setTextureCubeData(props.data);
|
|
2007
|
+
break;
|
|
2008
|
+
case "2d-array":
|
|
2009
|
+
this.setTextureArrayData(props.data);
|
|
2010
|
+
break;
|
|
2011
|
+
case "cube-array":
|
|
2012
|
+
this.setTextureCubeArrayData(props.data);
|
|
2013
|
+
break;
|
|
2014
|
+
default:
|
|
2015
|
+
throw new Error(props.dimension);
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
this.mipmaps = Boolean(props.mipmaps);
|
|
2019
|
+
if (this.mipmaps) {
|
|
2150
2020
|
this.generateMipmap();
|
|
2151
2021
|
}
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2022
|
+
}
|
|
2023
|
+
/*
|
|
2024
|
+
initializeCube(props?: TextureProps): void {
|
|
2025
|
+
const {mipmaps = true} = props; // , parameters = {} as Record<GL, any>} = props;
|
|
2026
|
+
|
|
2027
|
+
// Store props for accessors
|
|
2028
|
+
// this.props = props;
|
|
2029
|
+
|
|
2030
|
+
// @ts-expect-error
|
|
2031
|
+
this.setCubeMapData(props).then(() => {
|
|
2032
|
+
// TODO - should genMipmap() be called on the cubemap or on the faces?
|
|
2033
|
+
// TODO - without generateMipmap() cube textures do not work at all!!! Why?
|
|
2034
|
+
if (mipmaps) {
|
|
2035
|
+
this.generateMipmap(props);
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
this.setSampler(props.sampler);
|
|
2039
|
+
|
|
2040
|
+
// v8 compatibility?
|
|
2041
|
+
// const {parameters = {} as Record<GL, any>} = props;
|
|
2042
|
+
// this._setSamplerParameters(parameters);
|
|
2043
|
+
});
|
|
2044
|
+
}
|
|
2045
|
+
*/
|
|
2046
|
+
destroy() {
|
|
2047
|
+
if (this.handle) {
|
|
2048
|
+
this.gl.deleteTexture(this.handle);
|
|
2049
|
+
this.removeStats();
|
|
2050
|
+
this.trackDeallocatedMemory("Texture");
|
|
2051
|
+
this.destroyed = true;
|
|
2159
2052
|
}
|
|
2160
|
-
return this;
|
|
2161
2053
|
}
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
this.generateMipmap(props);
|
|
2168
|
-
}
|
|
2169
|
-
this.setSampler(props.sampler);
|
|
2170
|
-
this._setSamplerParameters(parameters);
|
|
2171
|
-
});
|
|
2172
|
-
return this;
|
|
2054
|
+
toString() {
|
|
2055
|
+
return `Texture(${this.id},${this.width}x${this.height})`;
|
|
2056
|
+
}
|
|
2057
|
+
createView(props) {
|
|
2058
|
+
return new WEBGLTextureView(this.device, { ...props, texture: this });
|
|
2173
2059
|
}
|
|
2174
2060
|
setSampler(sampler = {}) {
|
|
2175
2061
|
let samplerProps;
|
|
@@ -2182,300 +2068,102 @@ var _WEBGLTexture = class extends import_core9.Texture {
|
|
|
2182
2068
|
}
|
|
2183
2069
|
const parameters = convertSamplerParametersToWebGL(samplerProps);
|
|
2184
2070
|
this._setSamplerParameters(parameters);
|
|
2185
|
-
return this;
|
|
2186
|
-
}
|
|
2187
|
-
/**
|
|
2188
|
-
* If size has changed, reinitializes with current format
|
|
2189
|
-
* @note note clears image and mipmaps
|
|
2190
|
-
*/
|
|
2191
|
-
resize(options) {
|
|
2192
|
-
const { height, width, mipmaps = false } = options;
|
|
2193
|
-
if (width !== this.width || height !== this.height) {
|
|
2194
|
-
return this.initialize({
|
|
2195
|
-
width,
|
|
2196
|
-
height,
|
|
2197
|
-
format: this.format,
|
|
2198
|
-
type: this.type,
|
|
2199
|
-
dataFormat: this.dataFormat,
|
|
2200
|
-
mipmaps
|
|
2201
|
-
});
|
|
2202
|
-
}
|
|
2203
|
-
return this;
|
|
2204
2071
|
}
|
|
2205
|
-
/** Update external texture (video frame) */
|
|
2072
|
+
/** Update external texture (video frame or canvas) */
|
|
2206
2073
|
update() {
|
|
2207
|
-
|
|
2208
|
-
const { video, parameters, lastTime } = this._video;
|
|
2209
|
-
if (lastTime === video.currentTime || video.readyState < HTMLVideoElement.HAVE_CURRENT_DATA) {
|
|
2210
|
-
return;
|
|
2211
|
-
}
|
|
2212
|
-
this.setSubImageData({
|
|
2213
|
-
data: video,
|
|
2214
|
-
parameters
|
|
2215
|
-
});
|
|
2216
|
-
if (this.mipmaps) {
|
|
2217
|
-
this.generateMipmap();
|
|
2218
|
-
}
|
|
2219
|
-
this._video.lastTime = video.currentTime;
|
|
2220
|
-
}
|
|
2074
|
+
import_core7.log.warn("Texture.update() not implemented");
|
|
2221
2075
|
}
|
|
2222
2076
|
// Call to regenerate mipmaps after modifying texture(s)
|
|
2223
2077
|
generateMipmap(params = {}) {
|
|
2078
|
+
if (!this.props.data) {
|
|
2079
|
+
return;
|
|
2080
|
+
}
|
|
2224
2081
|
this.mipmaps = true;
|
|
2225
|
-
this.gl.bindTexture(this.
|
|
2082
|
+
this.gl.bindTexture(this.glTarget, this.handle);
|
|
2226
2083
|
withGLParameters(this.gl, params, () => {
|
|
2227
|
-
this.gl.generateMipmap(this.
|
|
2084
|
+
this.gl.generateMipmap(this.glTarget);
|
|
2228
2085
|
});
|
|
2229
|
-
this.gl.bindTexture(this.
|
|
2230
|
-
return this;
|
|
2086
|
+
this.gl.bindTexture(this.glTarget, null);
|
|
2231
2087
|
}
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
*/
|
|
2252
|
-
// eslint-disable-next-line max-statements, complexity
|
|
2253
|
-
setImageData(options) {
|
|
2254
|
-
if (this.props.dimension === "3d" || this.props.dimension === "2d-array") {
|
|
2255
|
-
return this.setImageData3D(options);
|
|
2256
|
-
}
|
|
2257
|
-
this.trackDeallocatedMemory("Texture");
|
|
2258
|
-
const { target = this.target, pixels = null, level = 0, glFormat = this.glFormat, offset = 0, parameters = {} } = options;
|
|
2259
|
-
let { data = null, type = this.type, width = this.width, height = this.height, dataFormat = this.dataFormat, compressed = false } = options;
|
|
2260
|
-
if (!data) {
|
|
2261
|
-
data = pixels;
|
|
2262
|
-
}
|
|
2263
|
-
({ type, dataFormat, compressed, width, height } = this._deduceParameters({
|
|
2264
|
-
format: this.props.format,
|
|
2265
|
-
type,
|
|
2266
|
-
dataFormat,
|
|
2267
|
-
compressed,
|
|
2268
|
-
data,
|
|
2269
|
-
width,
|
|
2270
|
-
height
|
|
2271
|
-
}));
|
|
2272
|
-
const { gl } = this;
|
|
2273
|
-
gl.bindTexture(this.target, this.handle);
|
|
2274
|
-
let dataType = null;
|
|
2275
|
-
({ data, dataType } = this._getDataType({ data, compressed }));
|
|
2276
|
-
withGLParameters(this.gl, parameters, () => {
|
|
2277
|
-
switch (dataType) {
|
|
2278
|
-
case "null":
|
|
2279
|
-
gl.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
|
|
2280
|
-
break;
|
|
2281
|
-
case "typed-array":
|
|
2282
|
-
gl.texImage2D(
|
|
2283
|
-
target,
|
|
2284
|
-
level,
|
|
2285
|
-
glFormat,
|
|
2286
|
-
width,
|
|
2287
|
-
height,
|
|
2288
|
-
0,
|
|
2289
|
-
// border (must be 0)
|
|
2290
|
-
dataFormat,
|
|
2291
|
-
type,
|
|
2292
|
-
data,
|
|
2293
|
-
offset
|
|
2294
|
-
);
|
|
2295
|
-
break;
|
|
2296
|
-
case "buffer":
|
|
2297
|
-
this.device.gl.bindBuffer(35052, data.handle || data);
|
|
2298
|
-
this.device.gl.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, offset);
|
|
2299
|
-
this.device.gl.bindBuffer(35052, null);
|
|
2300
|
-
break;
|
|
2301
|
-
case "browser-object":
|
|
2302
|
-
gl.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
|
|
2303
|
-
break;
|
|
2304
|
-
case "compressed":
|
|
2305
|
-
for (const [levelIndex, levelData] of data.entries()) {
|
|
2306
|
-
gl.compressedTexImage2D(target, levelIndex, levelData.format, levelData.width, levelData.height, 0, levelData.data);
|
|
2307
|
-
}
|
|
2308
|
-
break;
|
|
2309
|
-
default:
|
|
2310
|
-
(0, import_core9.assert)(false, "Unknown image data type");
|
|
2311
|
-
}
|
|
2312
|
-
});
|
|
2313
|
-
if (data && data.byteLength) {
|
|
2314
|
-
this.trackAllocatedMemory(data.byteLength, "Texture");
|
|
2315
|
-
} else {
|
|
2316
|
-
const bytesPerPixel = getTextureFormatBytesPerPixel(this.props.format);
|
|
2317
|
-
this.trackAllocatedMemory(this.width * this.height * bytesPerPixel, "Texture");
|
|
2088
|
+
// Image Data Setters
|
|
2089
|
+
copyExternalImage(options) {
|
|
2090
|
+
const size = import_core7.Texture.getExternalImageSize(options.image);
|
|
2091
|
+
const opts = { ...import_core7.Texture.defaultCopyExternalImageOptions, ...size, ...options };
|
|
2092
|
+
const { depth, mipLevel: lodLevel, image } = opts;
|
|
2093
|
+
this.bind();
|
|
2094
|
+
this._setMipLevel(depth, lodLevel, image);
|
|
2095
|
+
this.unbind();
|
|
2096
|
+
return { width: opts.width, height: opts.height };
|
|
2097
|
+
}
|
|
2098
|
+
setTexture1DData(data) {
|
|
2099
|
+
throw new Error("setTexture1DData not supported in WebGL.");
|
|
2100
|
+
}
|
|
2101
|
+
/** Set a simple texture */
|
|
2102
|
+
setTexture2DData(lodData, depth = 0) {
|
|
2103
|
+
this.bind();
|
|
2104
|
+
const lodArray = normalizeTextureData(lodData, this);
|
|
2105
|
+
if (lodArray.length > 1 && this.props.mipmaps !== false) {
|
|
2106
|
+
import_core7.log.warn(`Texture ${this.id} mipmap and multiple LODs.`)();
|
|
2318
2107
|
}
|
|
2319
|
-
|
|
2320
|
-
|
|
2108
|
+
for (let lodLevel = 0; lodLevel < lodArray.length; lodLevel++) {
|
|
2109
|
+
const imageData = lodArray[lodLevel];
|
|
2110
|
+
this._setMipLevel(depth, lodLevel, imageData);
|
|
2111
|
+
}
|
|
2112
|
+
this.unbind();
|
|
2321
2113
|
}
|
|
2322
2114
|
/**
|
|
2323
|
-
*
|
|
2324
|
-
*
|
|
2325
|
-
* Redefines an area of an existing texture
|
|
2115
|
+
* Sets a 3D texture
|
|
2116
|
+
* @param data
|
|
2326
2117
|
*/
|
|
2327
|
-
|
|
2328
|
-
(
|
|
2329
|
-
|
|
2330
|
-
type,
|
|
2331
|
-
dataFormat,
|
|
2332
|
-
compressed,
|
|
2333
|
-
data,
|
|
2334
|
-
width,
|
|
2335
|
-
height
|
|
2336
|
-
}));
|
|
2337
|
-
(0, import_core9.assert)(this.depth === 1, "texSubImage not supported for 3D textures");
|
|
2338
|
-
if (!data) {
|
|
2339
|
-
data = pixels;
|
|
2340
|
-
}
|
|
2341
|
-
if (data && data.data) {
|
|
2342
|
-
const ndarray = data;
|
|
2343
|
-
data = ndarray.data;
|
|
2344
|
-
width = ndarray.shape[0];
|
|
2345
|
-
height = ndarray.shape[1];
|
|
2118
|
+
setTexture3DData(data) {
|
|
2119
|
+
if (this.props.dimension !== "3d") {
|
|
2120
|
+
throw new Error(this.id);
|
|
2346
2121
|
}
|
|
2347
|
-
if (data
|
|
2348
|
-
|
|
2122
|
+
if (ArrayBuffer.isView(data)) {
|
|
2123
|
+
this.bind();
|
|
2124
|
+
copyCPUDataToMipLevel(this.device.gl, data, this);
|
|
2125
|
+
this.unbind();
|
|
2349
2126
|
}
|
|
2350
|
-
this.gl.bindTexture(this.target, this.handle);
|
|
2351
|
-
withGLParameters(this.gl, parameters, () => {
|
|
2352
|
-
if (compressed) {
|
|
2353
|
-
this.gl.compressedTexSubImage2D(target, level, x, y, width, height, glFormat, data);
|
|
2354
|
-
} else if (data === null) {
|
|
2355
|
-
this.gl.texSubImage2D(target, level, x, y, width, height, dataFormat, type, null);
|
|
2356
|
-
} else if (ArrayBuffer.isView(data)) {
|
|
2357
|
-
this.gl.texSubImage2D(target, level, x, y, width, height, dataFormat, type, data, offset);
|
|
2358
|
-
} else if (typeof WebGLBuffer !== "undefined" && data instanceof WebGLBuffer) {
|
|
2359
|
-
this.device.gl.bindBuffer(35052, data);
|
|
2360
|
-
this.device.gl.texSubImage2D(target, level, x, y, width, height, dataFormat, type, offset);
|
|
2361
|
-
this.device.gl.bindBuffer(35052, null);
|
|
2362
|
-
} else {
|
|
2363
|
-
this.device.gl.texSubImage2D(target, level, x, y, width, height, dataFormat, type, data);
|
|
2364
|
-
}
|
|
2365
|
-
});
|
|
2366
|
-
this.gl.bindTexture(this.target, null);
|
|
2367
2127
|
}
|
|
2368
2128
|
/**
|
|
2369
|
-
*
|
|
2370
|
-
*
|
|
2371
|
-
*
|
|
2372
|
-
*
|
|
2373
|
-
* Note that binding a texture into a Framebuffer's color buffer and
|
|
2374
|
-
* rendering can be faster.
|
|
2129
|
+
* Set a Texture Cube Data
|
|
2130
|
+
* @todo - could support TextureCubeArray with depth
|
|
2131
|
+
* @param data
|
|
2132
|
+
* @param index
|
|
2375
2133
|
*/
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
}
|
|
2380
|
-
getActiveUnit() {
|
|
2381
|
-
return this.gl.getParameter(34016) - 33984;
|
|
2382
|
-
}
|
|
2383
|
-
bind(textureUnit = this.textureUnit) {
|
|
2384
|
-
const { gl } = this;
|
|
2385
|
-
if (textureUnit !== void 0) {
|
|
2386
|
-
this.textureUnit = textureUnit;
|
|
2387
|
-
gl.activeTexture(33984 + textureUnit);
|
|
2134
|
+
setTextureCubeData(data, depth = 0) {
|
|
2135
|
+
if (this.props.dimension !== "cube") {
|
|
2136
|
+
throw new Error(this.id);
|
|
2388
2137
|
}
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
}
|
|
2392
|
-
unbind(textureUnit = this.textureUnit) {
|
|
2393
|
-
const { gl } = this;
|
|
2394
|
-
if (textureUnit !== void 0) {
|
|
2395
|
-
this.textureUnit = textureUnit;
|
|
2396
|
-
gl.activeTexture(33984 + textureUnit);
|
|
2138
|
+
for (const face of import_core7.Texture.CubeFaces) {
|
|
2139
|
+
this.setTextureCubeFaceData(data[face], face);
|
|
2397
2140
|
}
|
|
2398
|
-
gl.bindTexture(this.target, null);
|
|
2399
|
-
return textureUnit;
|
|
2400
2141
|
}
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
if (
|
|
2407
|
-
|
|
2408
|
-
}
|
|
2409
|
-
if (ArrayBuffer.isView(data)) {
|
|
2410
|
-
return { data, dataType: "typed-array" };
|
|
2411
|
-
}
|
|
2412
|
-
if (data instanceof WEBGLBuffer) {
|
|
2413
|
-
return { data: data.handle, dataType: "buffer" };
|
|
2414
|
-
}
|
|
2415
|
-
if (typeof WebGLBuffer !== "undefined" && data instanceof WebGLBuffer) {
|
|
2416
|
-
return { data, dataType: "buffer" };
|
|
2417
|
-
}
|
|
2418
|
-
return { data, dataType: "browser-object" };
|
|
2419
|
-
}
|
|
2420
|
-
// HELPER METHODS
|
|
2421
|
-
_deduceParameters(opts) {
|
|
2422
|
-
const { format, data } = opts;
|
|
2423
|
-
let { width, height, dataFormat, type, compressed } = opts;
|
|
2424
|
-
const parameters = getWebGLTextureParameters(format);
|
|
2425
|
-
dataFormat = dataFormat || parameters.dataFormat;
|
|
2426
|
-
type = type || parameters.type;
|
|
2427
|
-
compressed = compressed || parameters.compressed;
|
|
2428
|
-
({ width, height } = this._deduceImageSize(data, width, height));
|
|
2429
|
-
return { dataFormat, type, compressed, width, height, format, data };
|
|
2430
|
-
}
|
|
2431
|
-
// eslint-disable-next-line complexity
|
|
2432
|
-
_deduceImageSize(data, width, height) {
|
|
2433
|
-
let size;
|
|
2434
|
-
if (typeof ImageData !== "undefined" && data instanceof ImageData) {
|
|
2435
|
-
size = { width: data.width, height: data.height };
|
|
2436
|
-
} else if (typeof HTMLImageElement !== "undefined" && data instanceof HTMLImageElement) {
|
|
2437
|
-
size = { width: data.naturalWidth, height: data.naturalHeight };
|
|
2438
|
-
} else if (typeof HTMLCanvasElement !== "undefined" && data instanceof HTMLCanvasElement) {
|
|
2439
|
-
size = { width: data.width, height: data.height };
|
|
2440
|
-
} else if (typeof ImageBitmap !== "undefined" && data instanceof ImageBitmap) {
|
|
2441
|
-
size = { width: data.width, height: data.height };
|
|
2442
|
-
} else if (typeof HTMLVideoElement !== "undefined" && data instanceof HTMLVideoElement) {
|
|
2443
|
-
size = { width: data.videoWidth, height: data.videoHeight };
|
|
2444
|
-
} else if (!data) {
|
|
2445
|
-
size = { width: width >= 0 ? width : 1, height: height >= 0 ? height : 1 };
|
|
2446
|
-
} else {
|
|
2447
|
-
size = { width, height };
|
|
2142
|
+
/**
|
|
2143
|
+
* Sets an entire texture array
|
|
2144
|
+
* @param data
|
|
2145
|
+
*/
|
|
2146
|
+
setTextureArrayData(data) {
|
|
2147
|
+
if (this.props.dimension !== "2d-array") {
|
|
2148
|
+
throw new Error(this.id);
|
|
2448
2149
|
}
|
|
2449
|
-
|
|
2450
|
-
(0, import_core9.assert)(width === void 0 || size.width === width, "Deduced texture width does not match supplied width");
|
|
2451
|
-
(0, import_core9.assert)(height === void 0 || size.height === height, "Deduced texture height does not match supplied height");
|
|
2452
|
-
return size;
|
|
2150
|
+
throw new Error("setTextureArrayData not implemented.");
|
|
2453
2151
|
}
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
import_core9.log.warn(`${this.id} has mipmap and multiple LODs.`)();
|
|
2468
|
-
}
|
|
2469
|
-
resolvedFaces[index].forEach((image, lodLevel) => {
|
|
2470
|
-
if (width && height) {
|
|
2471
|
-
gl.texImage2D(face, lodLevel, format, width, height, 0, format, type, image);
|
|
2472
|
-
} else {
|
|
2473
|
-
gl.texImage2D(face, lodLevel, format, format, type, image);
|
|
2474
|
-
}
|
|
2475
|
-
});
|
|
2476
|
-
});
|
|
2477
|
-
this.unbind();
|
|
2152
|
+
/**
|
|
2153
|
+
* Sets an entire texture cube array
|
|
2154
|
+
* @param data
|
|
2155
|
+
*/
|
|
2156
|
+
setTextureCubeArrayData(data) {
|
|
2157
|
+
throw new Error("setTextureCubeArrayData not supported in WebGL2.");
|
|
2158
|
+
}
|
|
2159
|
+
setTextureCubeFaceData(lodData, face, depth = 0) {
|
|
2160
|
+
if (Array.isArray(lodData) && lodData.length > 1 && this.props.mipmaps !== false) {
|
|
2161
|
+
import_core7.log.warn(`${this.id} has mipmap and multiple LODs.`)();
|
|
2162
|
+
}
|
|
2163
|
+
const faceDepth = import_core7.Texture.CubeFaces.indexOf(face);
|
|
2164
|
+
this.setTexture2DData(lodData, faceDepth);
|
|
2478
2165
|
}
|
|
2166
|
+
// INTERNAL METHODS
|
|
2479
2167
|
/** @todo update this method to accept LODs */
|
|
2480
2168
|
setImageDataForFace(options) {
|
|
2481
2169
|
const {
|
|
@@ -2502,121 +2190,158 @@ var _WEBGLTexture = class extends import_core9.Texture {
|
|
|
2502
2190
|
} else {
|
|
2503
2191
|
gl.texImage2D(face, 0, format, format, type, imageData);
|
|
2504
2192
|
}
|
|
2505
|
-
return this;
|
|
2506
2193
|
}
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
type,
|
|
2514
|
-
// = GL.UNSIGNED_BYTE,
|
|
2515
|
-
width,
|
|
2516
|
-
height,
|
|
2517
|
-
depth = 1,
|
|
2518
|
-
offset = 0,
|
|
2519
|
-
data,
|
|
2520
|
-
parameters = {}
|
|
2521
|
-
} = options;
|
|
2522
|
-
this.trackDeallocatedMemory("Texture");
|
|
2523
|
-
this.gl.bindTexture(this.target, this.handle);
|
|
2524
|
-
const webglTextureFormat = getWebGLTextureParameters(format);
|
|
2525
|
-
withGLParameters(this.gl, parameters, () => {
|
|
2526
|
-
if (ArrayBuffer.isView(data)) {
|
|
2527
|
-
this.gl.texImage3D(
|
|
2528
|
-
this.target,
|
|
2529
|
-
level,
|
|
2530
|
-
webglTextureFormat.format,
|
|
2531
|
-
width,
|
|
2532
|
-
height,
|
|
2533
|
-
depth,
|
|
2534
|
-
0,
|
|
2535
|
-
webglTextureFormat.dataFormat,
|
|
2536
|
-
webglTextureFormat.type,
|
|
2537
|
-
// dataType: getWebGL,
|
|
2538
|
-
data
|
|
2539
|
-
);
|
|
2194
|
+
_getImageDataMap(faceData) {
|
|
2195
|
+
for (let i = 0; i < import_core7.Texture.CubeFaces.length; ++i) {
|
|
2196
|
+
const faceName = import_core7.Texture.CubeFaces[i];
|
|
2197
|
+
if (faceData[faceName]) {
|
|
2198
|
+
faceData[34069 + i] = faceData[faceName];
|
|
2199
|
+
delete faceData[faceName];
|
|
2540
2200
|
}
|
|
2541
|
-
if (data instanceof WEBGLBuffer) {
|
|
2542
|
-
this.gl.bindBuffer(35052, data.handle);
|
|
2543
|
-
this.gl.texImage3D(this.target, level, dataFormat, width, height, depth, 0, format, type, offset);
|
|
2544
|
-
}
|
|
2545
|
-
});
|
|
2546
|
-
if (data && data.byteLength) {
|
|
2547
|
-
this.trackAllocatedMemory(data.byteLength, "Texture");
|
|
2548
|
-
} else {
|
|
2549
|
-
const bytesPerPixel = getTextureFormatBytesPerPixel(this.props.format);
|
|
2550
|
-
this.trackAllocatedMemory(this.width * this.height * this.depth * bytesPerPixel, "Texture");
|
|
2551
2201
|
}
|
|
2552
|
-
|
|
2553
|
-
return this;
|
|
2202
|
+
return faceData;
|
|
2554
2203
|
}
|
|
2555
2204
|
// RESOURCE METHODS
|
|
2556
2205
|
/**
|
|
2557
2206
|
* Sets sampler parameters on texture
|
|
2558
2207
|
*/
|
|
2559
2208
|
_setSamplerParameters(parameters) {
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
}
|
|
2563
|
-
logParameters(parameters);
|
|
2564
|
-
this.gl.bindTexture(this.target, this.handle);
|
|
2209
|
+
import_core7.log.log(1, "texture sampler parameters", parameters)();
|
|
2210
|
+
this.gl.bindTexture(this.glTarget, this.handle);
|
|
2565
2211
|
for (const [pname, pvalue] of Object.entries(parameters)) {
|
|
2566
2212
|
const param = Number(pname);
|
|
2567
2213
|
const value = pvalue;
|
|
2568
2214
|
switch (param) {
|
|
2569
2215
|
case 33082:
|
|
2570
2216
|
case 33083:
|
|
2571
|
-
this.gl.texParameterf(this.
|
|
2217
|
+
this.gl.texParameterf(this.glTarget, param, value);
|
|
2218
|
+
break;
|
|
2219
|
+
case 10241:
|
|
2220
|
+
this.gl.texParameteri(this.glTarget, param, value);
|
|
2221
|
+
break;
|
|
2222
|
+
case 10242:
|
|
2223
|
+
case 10243:
|
|
2224
|
+
this.gl.texParameteri(this.glTarget, param, value);
|
|
2225
|
+
break;
|
|
2226
|
+
case 34046:
|
|
2227
|
+
if (this.device.features.has("texture-filterable-anisotropic-webgl")) {
|
|
2228
|
+
this.gl.texParameteri(this.glTarget, param, value);
|
|
2229
|
+
}
|
|
2572
2230
|
break;
|
|
2573
2231
|
default:
|
|
2574
|
-
this.gl.texParameteri(this.
|
|
2232
|
+
this.gl.texParameteri(this.glTarget, param, value);
|
|
2575
2233
|
break;
|
|
2576
2234
|
}
|
|
2577
2235
|
}
|
|
2578
|
-
this.gl.bindTexture(this.
|
|
2579
|
-
return;
|
|
2236
|
+
this.gl.bindTexture(this.glTarget, null);
|
|
2580
2237
|
}
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2238
|
+
// CLASSIC
|
|
2239
|
+
/*
|
|
2240
|
+
setCubeMapData(options: {
|
|
2241
|
+
width: number;
|
|
2242
|
+
height: number;
|
|
2243
|
+
data: Record<GL, Texture2DData> | Record<TextureCubeFace, Texture2DData>;
|
|
2244
|
+
format?: any;
|
|
2245
|
+
type?: any;
|
|
2246
|
+
/** @deprecated Use .data *
|
|
2247
|
+
pixels: any;
|
|
2248
|
+
}): void {
|
|
2249
|
+
const {gl} = this;
|
|
2250
|
+
|
|
2251
|
+
const {width, height, pixels, data, format = GL.RGBA, type = GL.UNSIGNED_BYTE} = options;
|
|
2252
|
+
|
|
2253
|
+
// pixel data (imageDataMap) is an Object from Face to Image or Promise.
|
|
2254
|
+
// For example:
|
|
2255
|
+
// {
|
|
2256
|
+
// GL.TEXTURE_CUBE_MAP_POSITIVE_X : Image-or-Promise,
|
|
2257
|
+
// GL.TEXTURE_CUBE_MAP_NEGATIVE_X : Image-or-Promise,
|
|
2258
|
+
// ... }
|
|
2259
|
+
// To provide multiple level-of-details (LODs) this can be Face to Array
|
|
2260
|
+
// of Image or Promise, like this
|
|
2261
|
+
// {
|
|
2262
|
+
// GL.TEXTURE_CUBE_MAP_POSITIVE_X : [Image-or-Promise-LOD-0, Image-or-Promise-LOD-1],
|
|
2263
|
+
// GL.TEXTURE_CUBE_MAP_NEGATIVE_X : [Image-or-Promise-LOD-0, Image-or-Promise-LOD-1],
|
|
2264
|
+
// ... }
|
|
2265
|
+
|
|
2266
|
+
const imageDataMap = this._getImageDataMap(pixels || data);
|
|
2267
|
+
|
|
2268
|
+
const resolvedFaces = WEBGLTexture.FACES.map(face => {
|
|
2269
|
+
const facePixels = imageDataMap[face];
|
|
2270
|
+
return Array.isArray(facePixels) ? facePixels : [facePixels];
|
|
2271
|
+
});
|
|
2272
|
+
this.bind();
|
|
2273
|
+
|
|
2274
|
+
WEBGLTexture.FACES.forEach((face, index) => {
|
|
2275
|
+
if (resolvedFaces[index].length > 1 && this.props.mipmaps !== false) {
|
|
2276
|
+
// If the user provides multiple LODs, then automatic mipmap
|
|
2277
|
+
// generation generateMipmap() should be disabled to avoid overwritting them.
|
|
2278
|
+
log.warn(`${this.id} has mipmap and multiple LODs.`)();
|
|
2279
|
+
}
|
|
2280
|
+
resolvedFaces[index].forEach((image, lodLevel) => {
|
|
2281
|
+
// TODO: adjust width & height for LOD!
|
|
2282
|
+
if (width && height) {
|
|
2283
|
+
gl.texImage2D(face, lodLevel, format, width, height, 0 /* border*, format, type, image);
|
|
2284
|
+
} else {
|
|
2285
|
+
gl.texImage2D(face, lodLevel, format, format, type, image);
|
|
2286
|
+
}
|
|
2287
|
+
});
|
|
2288
|
+
});
|
|
2289
|
+
|
|
2290
|
+
this.unbind();
|
|
2291
|
+
}
|
|
2292
|
+
*/
|
|
2293
|
+
// INTERNAL SETTERS
|
|
2294
|
+
/**
|
|
2295
|
+
* Copy a region of data from a CPU memory buffer into this texture.
|
|
2296
|
+
* @todo - GLUnpackParameters parameters
|
|
2297
|
+
*/
|
|
2298
|
+
_setMipLevel(depth, level, textureData, glTarget = this.glTarget) {
|
|
2299
|
+
if (import_core7.Texture.isExternalImage(textureData)) {
|
|
2300
|
+
copyCPUImageToMipLevel(this.device.gl, textureData, { ...this, depth, level, glTarget });
|
|
2301
|
+
return;
|
|
2302
|
+
}
|
|
2303
|
+
if (import_core7.Texture.isTextureLevelData(textureData)) {
|
|
2304
|
+
copyCPUDataToMipLevel(this.device.gl, textureData.data, {
|
|
2305
|
+
...this,
|
|
2306
|
+
depth,
|
|
2307
|
+
level,
|
|
2308
|
+
glTarget
|
|
2309
|
+
});
|
|
2310
|
+
return;
|
|
2311
|
+
}
|
|
2312
|
+
throw new Error("Texture: invalid image data");
|
|
2606
2313
|
}
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
}
|
|
2314
|
+
// HELPERS
|
|
2315
|
+
getActiveUnit() {
|
|
2316
|
+
return this.gl.getParameter(34016) - 33984;
|
|
2317
|
+
}
|
|
2318
|
+
bind(textureUnit) {
|
|
2319
|
+
const { gl } = this;
|
|
2320
|
+
if (textureUnit !== void 0) {
|
|
2321
|
+
this.textureUnit = textureUnit;
|
|
2322
|
+
gl.activeTexture(33984 + textureUnit);
|
|
2323
|
+
}
|
|
2324
|
+
gl.bindTexture(this.glTarget, this.handle);
|
|
2325
|
+
return textureUnit;
|
|
2326
|
+
}
|
|
2327
|
+
unbind(textureUnit) {
|
|
2328
|
+
const { gl } = this;
|
|
2329
|
+
if (textureUnit !== void 0) {
|
|
2330
|
+
this.textureUnit = textureUnit;
|
|
2331
|
+
gl.activeTexture(33984 + textureUnit);
|
|
2332
|
+
}
|
|
2333
|
+
gl.bindTexture(this.glTarget, null);
|
|
2334
|
+
return textureUnit;
|
|
2335
|
+
}
|
|
2336
|
+
};
|
|
2611
2337
|
|
|
2612
2338
|
// dist/adapter/resources/webgl-framebuffer.js
|
|
2613
|
-
var WEBGLFramebuffer = class extends
|
|
2339
|
+
var WEBGLFramebuffer = class extends import_core8.Framebuffer {
|
|
2614
2340
|
device;
|
|
2615
2341
|
gl;
|
|
2616
2342
|
handle;
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
}
|
|
2343
|
+
colorAttachments = [];
|
|
2344
|
+
depthStencilAttachment = null;
|
|
2620
2345
|
constructor(device, props) {
|
|
2621
2346
|
super(device, props);
|
|
2622
2347
|
const isDefaultFramebuffer = props.handle === null;
|
|
@@ -2631,11 +2356,11 @@ var WEBGLFramebuffer = class extends import_core10.Framebuffer {
|
|
|
2631
2356
|
const attachment = this.colorAttachments[i];
|
|
2632
2357
|
const attachmentPoint = 36064 + i;
|
|
2633
2358
|
if (attachment) {
|
|
2634
|
-
this.
|
|
2359
|
+
this._attachTexture(attachmentPoint, attachment);
|
|
2635
2360
|
}
|
|
2636
2361
|
}
|
|
2637
2362
|
if (this.depthStencilAttachment) {
|
|
2638
|
-
this.
|
|
2363
|
+
this._attachTexture(getDepthStencilAttachmentWebGL(this.depthStencilAttachment.props.format), this.depthStencilAttachment);
|
|
2639
2364
|
}
|
|
2640
2365
|
if (props.check !== false) {
|
|
2641
2366
|
const status = this.gl.checkFramebufferStatus(36160);
|
|
@@ -2665,68 +2390,55 @@ var WEBGLFramebuffer = class extends import_core10.Framebuffer {
|
|
|
2665
2390
|
});
|
|
2666
2391
|
}
|
|
2667
2392
|
/**
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
this.
|
|
2673
|
-
|
|
2393
|
+
* Attachment resize is expected to be a noop if size is same
|
|
2394
|
+
*
|
|
2395
|
+
protected override resizeAttachments(width: number, height: number): this {
|
|
2396
|
+
// for default framebuffer, just update the stored size
|
|
2397
|
+
if (this.handle === null) {
|
|
2398
|
+
// assert(width === undefined && height === undefined);
|
|
2399
|
+
this.width = this.gl.drawingBufferWidth;
|
|
2400
|
+
this.height = this.gl.drawingBufferHeight;
|
|
2401
|
+
return this;
|
|
2402
|
+
}
|
|
2403
|
+
|
|
2404
|
+
if (width === undefined) {
|
|
2405
|
+
width = this.gl.drawingBufferWidth;
|
|
2406
|
+
}
|
|
2407
|
+
if (height === undefined) {
|
|
2408
|
+
height = this.gl.drawingBufferHeight;
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
// TODO Not clear that this is better than default destroy/create implementation
|
|
2412
|
+
|
|
2413
|
+
for (const colorAttachment of this.colorAttachments) {
|
|
2414
|
+
colorAttachment.texture.clone({width, height});
|
|
2415
|
+
}
|
|
2416
|
+
if (this.depthStencilAttachment) {
|
|
2417
|
+
this.depthStencilAttachment.texture.resize({width, height});
|
|
2418
|
+
}
|
|
2674
2419
|
return this;
|
|
2675
2420
|
}
|
|
2676
|
-
|
|
2677
|
-
width = this.gl.drawingBufferWidth;
|
|
2678
|
-
}
|
|
2679
|
-
if (height === void 0) {
|
|
2680
|
-
height = this.gl.drawingBufferHeight;
|
|
2681
|
-
}
|
|
2682
|
-
for (const colorAttachment of this.colorAttachments) {
|
|
2683
|
-
colorAttachment.texture.resize({ width, height });
|
|
2684
|
-
}
|
|
2685
|
-
if (this.depthStencilAttachment) {
|
|
2686
|
-
this.depthStencilAttachment.texture.resize({ width, height });
|
|
2687
|
-
}
|
|
2688
|
-
return this;
|
|
2689
|
-
}
|
|
2421
|
+
*/
|
|
2690
2422
|
/** Attach one attachment */
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
this._attachTexture(attachmentPoint, texture, layer, level);
|
|
2695
|
-
return texture;
|
|
2696
|
-
}
|
|
2697
|
-
if (attachment instanceof WEBGLTexture) {
|
|
2698
|
-
this._attachTexture(attachmentPoint, attachment, 0, 0);
|
|
2699
|
-
return attachment;
|
|
2700
|
-
}
|
|
2701
|
-
if (attachment instanceof WEBGLTextureView) {
|
|
2702
|
-
const textureView = attachment;
|
|
2703
|
-
this._attachTexture(attachmentPoint, textureView.texture, textureView.props.baseMipLevel, textureView.props.baseArrayLayer);
|
|
2704
|
-
return attachment.texture;
|
|
2705
|
-
}
|
|
2706
|
-
throw new Error("attach");
|
|
2707
|
-
}
|
|
2708
|
-
// TODO - we do not seem to need render buffers in WebGL 2
|
|
2709
|
-
// protected _attachWEBGLRenderbuffer(attachment: GL, renderbuffer: WEBGLRenderbuffer): void {
|
|
2710
|
-
// this.gl.framebufferRenderbuffer(
|
|
2711
|
-
// GL.FRAMEBUFFER,
|
|
2712
|
-
// attachment,
|
|
2713
|
-
// GL.RENDERBUFFER,
|
|
2714
|
-
// renderbuffer.handle
|
|
2715
|
-
// );
|
|
2716
|
-
// }
|
|
2423
|
+
_attachTexture(attachmentPoint, textureView) {
|
|
2424
|
+
this._attachTextureView(attachmentPoint, textureView);
|
|
2425
|
+
}
|
|
2717
2426
|
/**
|
|
2718
2427
|
* @param attachment
|
|
2719
2428
|
* @param texture
|
|
2720
2429
|
* @param layer = 0 - index into WEBGLTextureArray and Texture3D or face for `TextureCubeMap`
|
|
2721
2430
|
* @param level = 0 - mipmapLevel
|
|
2722
2431
|
*/
|
|
2723
|
-
|
|
2432
|
+
_attachTextureView(attachment, textureView) {
|
|
2724
2433
|
const { gl } = this.device;
|
|
2725
|
-
|
|
2726
|
-
|
|
2434
|
+
const { texture } = textureView;
|
|
2435
|
+
const level = textureView.props.baseMipLevel;
|
|
2436
|
+
const layer = textureView.props.baseArrayLayer;
|
|
2437
|
+
gl.bindTexture(texture.glTarget, texture.handle);
|
|
2438
|
+
switch (texture.glTarget) {
|
|
2727
2439
|
case 35866:
|
|
2728
2440
|
case 32879:
|
|
2729
|
-
gl.framebufferTextureLayer(36160, attachment, texture.
|
|
2441
|
+
gl.framebufferTextureLayer(36160, attachment, texture.handle, level, layer);
|
|
2730
2442
|
break;
|
|
2731
2443
|
case 34067:
|
|
2732
2444
|
const face = mapIndexToCubeMapFace(layer);
|
|
@@ -2736,9 +2448,9 @@ var WEBGLFramebuffer = class extends import_core10.Framebuffer {
|
|
|
2736
2448
|
gl.framebufferTexture2D(36160, attachment, 3553, texture.handle, level);
|
|
2737
2449
|
break;
|
|
2738
2450
|
default:
|
|
2739
|
-
|
|
2451
|
+
throw new Error("Illegal texture type");
|
|
2740
2452
|
}
|
|
2741
|
-
gl.bindTexture(texture.
|
|
2453
|
+
gl.bindTexture(texture.glTarget, null);
|
|
2742
2454
|
}
|
|
2743
2455
|
};
|
|
2744
2456
|
function mapIndexToCubeMapFace(layer) {
|
|
@@ -2764,8 +2476,10 @@ function _getFrameBufferStatus(status) {
|
|
|
2764
2476
|
}
|
|
2765
2477
|
|
|
2766
2478
|
// dist/adapter/webgl-canvas-context.js
|
|
2767
|
-
var WebGLCanvasContext = class extends
|
|
2479
|
+
var WebGLCanvasContext = class extends import_core9.CanvasContext {
|
|
2768
2480
|
device;
|
|
2481
|
+
format = "rgba8unorm";
|
|
2482
|
+
depthStencilFormat = "depth24plus";
|
|
2769
2483
|
presentationSize;
|
|
2770
2484
|
_framebuffer = null;
|
|
2771
2485
|
constructor(device, props) {
|
|
@@ -2815,31 +2529,58 @@ var WebGLCanvasContext = class extends import_core11.CanvasContext {
|
|
|
2815
2529
|
};
|
|
2816
2530
|
|
|
2817
2531
|
// dist/context/debug/spector.js
|
|
2818
|
-
var
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2532
|
+
var import_core10 = require("@luma.gl/core");
|
|
2533
|
+
|
|
2534
|
+
// dist/utils/load-script.js
|
|
2535
|
+
async function loadScript(scriptUrl, scriptId) {
|
|
2536
|
+
const head = document.getElementsByTagName("head")[0];
|
|
2537
|
+
if (!head) {
|
|
2538
|
+
throw new Error("loadScript");
|
|
2539
|
+
}
|
|
2540
|
+
const script = document.createElement("script");
|
|
2541
|
+
script.setAttribute("type", "text/javascript");
|
|
2542
|
+
script.setAttribute("src", scriptUrl);
|
|
2543
|
+
if (scriptId) {
|
|
2544
|
+
script.id = scriptId;
|
|
2545
|
+
}
|
|
2546
|
+
return new Promise((resolve, reject) => {
|
|
2547
|
+
script.onload = resolve;
|
|
2548
|
+
script.onerror = (error) => reject(new Error(`Unable to load script '${scriptUrl}': ${error}`));
|
|
2549
|
+
head.appendChild(script);
|
|
2550
|
+
});
|
|
2551
|
+
}
|
|
2552
|
+
|
|
2553
|
+
// dist/context/debug/spector.js
|
|
2823
2554
|
var LOG_LEVEL = 1;
|
|
2824
2555
|
var spector = null;
|
|
2825
2556
|
var initialized = false;
|
|
2557
|
+
var DEFAULT_SPECTOR_PROPS = {
|
|
2558
|
+
debugWithSpectorJS: import_core10.log.get("spector") || import_core10.log.get("spectorjs"),
|
|
2559
|
+
// https://github.com/BabylonJS/Spector.js#basic-usage
|
|
2560
|
+
// https://forum.babylonjs.com/t/spectorcdn-is-temporarily-off/48241
|
|
2561
|
+
// spectorUrl: 'https://spectorcdn.babylonjs.com/spector.bundle.js';
|
|
2562
|
+
spectorUrl: "https://cdn.jsdelivr.net/npm/spectorjs@0.9.30/dist/spector.bundle.js",
|
|
2563
|
+
gl: void 0
|
|
2564
|
+
};
|
|
2826
2565
|
async function loadSpectorJS(props) {
|
|
2827
2566
|
if (!globalThis.SPECTOR) {
|
|
2828
2567
|
try {
|
|
2829
|
-
await (
|
|
2568
|
+
await loadScript(props.spectorUrl || DEFAULT_SPECTOR_PROPS.spectorUrl);
|
|
2830
2569
|
} catch (error) {
|
|
2831
|
-
|
|
2570
|
+
import_core10.log.warn(String(error));
|
|
2832
2571
|
}
|
|
2833
2572
|
}
|
|
2834
2573
|
}
|
|
2835
2574
|
function initializeSpectorJS(props) {
|
|
2575
|
+
var _a;
|
|
2836
2576
|
props = { ...DEFAULT_SPECTOR_PROPS, ...props };
|
|
2837
|
-
if (!
|
|
2577
|
+
if (!props.debugWithSpectorJS) {
|
|
2838
2578
|
return null;
|
|
2839
2579
|
}
|
|
2840
|
-
if (!spector && globalThis.SPECTOR) {
|
|
2841
|
-
|
|
2842
|
-
|
|
2580
|
+
if (!spector && globalThis.SPECTOR && !((_a = globalThis.luma) == null ? void 0 : _a.spector)) {
|
|
2581
|
+
import_core10.log.probe(LOG_LEVEL, "SPECTOR found and initialized. Start with `luma.spector.displayUI()`")();
|
|
2582
|
+
const { Spector } = globalThis.SPECTOR;
|
|
2583
|
+
spector = new Spector();
|
|
2843
2584
|
if (globalThis.luma) {
|
|
2844
2585
|
globalThis.luma.spector = spector;
|
|
2845
2586
|
}
|
|
@@ -2850,21 +2591,21 @@ function initializeSpectorJS(props) {
|
|
|
2850
2591
|
if (!initialized) {
|
|
2851
2592
|
initialized = true;
|
|
2852
2593
|
spector.spyCanvases();
|
|
2853
|
-
spector == null ? void 0 : spector.onCaptureStarted.add((capture) =>
|
|
2594
|
+
spector == null ? void 0 : spector.onCaptureStarted.add((capture) => import_core10.log.info("Spector capture started:", capture)());
|
|
2854
2595
|
spector == null ? void 0 : spector.onCapture.add((capture) => {
|
|
2855
|
-
|
|
2596
|
+
import_core10.log.info("Spector capture complete:", capture)();
|
|
2856
2597
|
spector == null ? void 0 : spector.getResultUI();
|
|
2857
2598
|
spector == null ? void 0 : spector.resultView.display();
|
|
2858
2599
|
spector == null ? void 0 : spector.resultView.addCapture(capture);
|
|
2859
2600
|
});
|
|
2860
2601
|
}
|
|
2861
|
-
if (props
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2602
|
+
if (props.gl) {
|
|
2603
|
+
const gl = props.gl;
|
|
2604
|
+
const device = gl.device;
|
|
2605
|
+
spector == null ? void 0 : spector.startCapture(props.gl, 500);
|
|
2606
|
+
gl.device = device;
|
|
2866
2607
|
new Promise((resolve) => setTimeout(resolve, 2e3)).then((_) => {
|
|
2867
|
-
|
|
2608
|
+
import_core10.log.info("Spector capture stopped after 2 seconds")();
|
|
2868
2609
|
spector == null ? void 0 : spector.stopCapture();
|
|
2869
2610
|
});
|
|
2870
2611
|
}
|
|
@@ -2872,7 +2613,7 @@ function initializeSpectorJS(props) {
|
|
|
2872
2613
|
}
|
|
2873
2614
|
|
|
2874
2615
|
// dist/context/debug/webgl-developer-tools.js
|
|
2875
|
-
var
|
|
2616
|
+
var import_core11 = require("@luma.gl/core");
|
|
2876
2617
|
var import_constants12 = require("@luma.gl/constants");
|
|
2877
2618
|
var import_env = require("@probe.gl/env");
|
|
2878
2619
|
var WEBGL_DEBUG_CDN_URL = "https://unpkg.com/webgl-debug@2.0.1/index.js";
|
|
@@ -2884,13 +2625,10 @@ async function loadWebGLDeveloperTools() {
|
|
|
2884
2625
|
if ((0, import_env.isBrowser)() && !globalThis.WebGLDebugUtils) {
|
|
2885
2626
|
globalThis.global = globalThis.global || globalThis;
|
|
2886
2627
|
globalThis.global.module = {};
|
|
2887
|
-
await
|
|
2628
|
+
await loadScript(WEBGL_DEBUG_CDN_URL);
|
|
2888
2629
|
}
|
|
2889
2630
|
}
|
|
2890
2631
|
function makeDebugContext(gl, props = {}) {
|
|
2891
|
-
if (!gl) {
|
|
2892
|
-
return null;
|
|
2893
|
-
}
|
|
2894
2632
|
return props.debug ? getDebugContext(gl, props) : getRealContext(gl);
|
|
2895
2633
|
}
|
|
2896
2634
|
function getRealContext(gl) {
|
|
@@ -2899,7 +2637,7 @@ function getRealContext(gl) {
|
|
|
2899
2637
|
}
|
|
2900
2638
|
function getDebugContext(gl, props) {
|
|
2901
2639
|
if (!globalThis.WebGLDebugUtils) {
|
|
2902
|
-
|
|
2640
|
+
import_core11.log.warn("webgl-debug not loaded")();
|
|
2903
2641
|
return gl;
|
|
2904
2642
|
}
|
|
2905
2643
|
const data = getWebGLContextData(gl);
|
|
@@ -2934,7 +2672,7 @@ function onGLError(props, err, functionName, args) {
|
|
|
2934
2672
|
const errorMessage = globalThis.WebGLDebugUtils.glEnumToString(err);
|
|
2935
2673
|
const functionArgs = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, args);
|
|
2936
2674
|
const message2 = `${errorMessage} in gl.${functionName}(${functionArgs})`;
|
|
2937
|
-
|
|
2675
|
+
import_core11.log.error(message2)();
|
|
2938
2676
|
debugger;
|
|
2939
2677
|
if (props.throwOnError) {
|
|
2940
2678
|
throw new Error(message2);
|
|
@@ -2942,9 +2680,9 @@ function onGLError(props, err, functionName, args) {
|
|
|
2942
2680
|
}
|
|
2943
2681
|
function onValidateGLFunc(props, functionName, functionArgs) {
|
|
2944
2682
|
let functionString = "";
|
|
2945
|
-
if (
|
|
2683
|
+
if (import_core11.log.level >= 1) {
|
|
2946
2684
|
functionString = getFunctionString(functionName, functionArgs);
|
|
2947
|
-
|
|
2685
|
+
import_core11.log.log(1, functionString)();
|
|
2948
2686
|
}
|
|
2949
2687
|
if (props.break && props.break.length > 0) {
|
|
2950
2688
|
functionString = functionString || getFunctionString(functionName, functionArgs);
|
|
@@ -2959,16 +2697,149 @@ function onValidateGLFunc(props, functionName, functionArgs) {
|
|
|
2959
2697
|
if (props.throwOnError) {
|
|
2960
2698
|
throw new Error(`Undefined argument: ${functionString}`);
|
|
2961
2699
|
} else {
|
|
2962
|
-
|
|
2700
|
+
import_core11.log.error(`Undefined argument: ${functionString}`)();
|
|
2963
2701
|
debugger;
|
|
2964
2702
|
}
|
|
2965
2703
|
}
|
|
2966
2704
|
}
|
|
2967
2705
|
}
|
|
2968
2706
|
|
|
2969
|
-
// dist/
|
|
2970
|
-
var
|
|
2707
|
+
// dist/utils/uid.js
|
|
2708
|
+
var uidCounters = {};
|
|
2709
|
+
function uid(id = "id") {
|
|
2710
|
+
uidCounters[id] = uidCounters[id] || 1;
|
|
2711
|
+
const count = uidCounters[id]++;
|
|
2712
|
+
return `${id}-${count}`;
|
|
2713
|
+
}
|
|
2714
|
+
|
|
2715
|
+
// dist/adapter/resources/webgl-buffer.js
|
|
2716
|
+
var import_core12 = require("@luma.gl/core");
|
|
2971
2717
|
var import_constants13 = require("@luma.gl/constants");
|
|
2718
|
+
var WEBGLBuffer = class extends import_core12.Buffer {
|
|
2719
|
+
device;
|
|
2720
|
+
gl;
|
|
2721
|
+
handle;
|
|
2722
|
+
/** Target in OpenGL defines the type of buffer */
|
|
2723
|
+
glTarget;
|
|
2724
|
+
/** Usage is a hint on how frequently the buffer will be updates */
|
|
2725
|
+
glUsage;
|
|
2726
|
+
/** Index type is needed when issuing draw calls, so we pre-compute it */
|
|
2727
|
+
glIndexType = 5123;
|
|
2728
|
+
/** Number of bytes allocated on the GPU for this buffer */
|
|
2729
|
+
byteLength;
|
|
2730
|
+
/** Number of bytes used */
|
|
2731
|
+
bytesUsed;
|
|
2732
|
+
constructor(device, props = {}) {
|
|
2733
|
+
super(device, props);
|
|
2734
|
+
this.device = device;
|
|
2735
|
+
this.gl = this.device.gl;
|
|
2736
|
+
const handle = typeof props === "object" ? props.handle : void 0;
|
|
2737
|
+
this.handle = handle || this.gl.createBuffer();
|
|
2738
|
+
device.setSpectorMetadata(this.handle, { ...this.props, data: typeof this.props.data });
|
|
2739
|
+
this.glTarget = getWebGLTarget(this.props.usage);
|
|
2740
|
+
this.glUsage = getWebGLUsage(this.props.usage);
|
|
2741
|
+
this.glIndexType = this.props.indexType === "uint32" ? 5125 : 5123;
|
|
2742
|
+
if (props.data) {
|
|
2743
|
+
this._initWithData(props.data, props.byteOffset, props.byteLength);
|
|
2744
|
+
} else {
|
|
2745
|
+
this._initWithByteLength(props.byteLength || 0);
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2748
|
+
// PRIVATE METHODS
|
|
2749
|
+
/** Allocate a new buffer and initialize to contents of typed array */
|
|
2750
|
+
_initWithData(data, byteOffset = 0, byteLength = data.byteLength + byteOffset) {
|
|
2751
|
+
const glTarget = this.glTarget;
|
|
2752
|
+
this.gl.bindBuffer(glTarget, this.handle);
|
|
2753
|
+
this.gl.bufferData(glTarget, byteLength, this.glUsage);
|
|
2754
|
+
this.gl.bufferSubData(glTarget, byteOffset, data);
|
|
2755
|
+
this.gl.bindBuffer(glTarget, null);
|
|
2756
|
+
this.bytesUsed = byteLength;
|
|
2757
|
+
this.byteLength = byteLength;
|
|
2758
|
+
this._setDebugData(data, byteOffset, byteLength);
|
|
2759
|
+
this.trackAllocatedMemory(byteLength);
|
|
2760
|
+
}
|
|
2761
|
+
// Allocate a GPU buffer of specified size.
|
|
2762
|
+
_initWithByteLength(byteLength) {
|
|
2763
|
+
let data = byteLength;
|
|
2764
|
+
if (byteLength === 0) {
|
|
2765
|
+
data = new Float32Array(0);
|
|
2766
|
+
}
|
|
2767
|
+
const glTarget = this.glTarget;
|
|
2768
|
+
this.gl.bindBuffer(glTarget, this.handle);
|
|
2769
|
+
this.gl.bufferData(glTarget, data, this.glUsage);
|
|
2770
|
+
this.gl.bindBuffer(glTarget, null);
|
|
2771
|
+
this.bytesUsed = byteLength;
|
|
2772
|
+
this.byteLength = byteLength;
|
|
2773
|
+
this._setDebugData(null, 0, byteLength);
|
|
2774
|
+
this.trackAllocatedMemory(byteLength);
|
|
2775
|
+
return this;
|
|
2776
|
+
}
|
|
2777
|
+
destroy() {
|
|
2778
|
+
if (!this.destroyed && this.handle) {
|
|
2779
|
+
this.removeStats();
|
|
2780
|
+
this.trackDeallocatedMemory();
|
|
2781
|
+
this.gl.deleteBuffer(this.handle);
|
|
2782
|
+
this.destroyed = true;
|
|
2783
|
+
this.handle = null;
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
write(data, byteOffset = 0) {
|
|
2787
|
+
const srcOffset = 0;
|
|
2788
|
+
const byteLength = void 0;
|
|
2789
|
+
const glTarget = 36663;
|
|
2790
|
+
this.gl.bindBuffer(glTarget, this.handle);
|
|
2791
|
+
if (srcOffset !== 0 || byteLength !== void 0) {
|
|
2792
|
+
this.gl.bufferSubData(glTarget, byteOffset, data, srcOffset, byteLength);
|
|
2793
|
+
} else {
|
|
2794
|
+
this.gl.bufferSubData(glTarget, byteOffset, data);
|
|
2795
|
+
}
|
|
2796
|
+
this.gl.bindBuffer(glTarget, null);
|
|
2797
|
+
this._setDebugData(data, byteOffset, data.byteLength);
|
|
2798
|
+
}
|
|
2799
|
+
/** Asynchronously read data from the buffer */
|
|
2800
|
+
async readAsync(byteOffset = 0, byteLength) {
|
|
2801
|
+
return this.readSyncWebGL(byteOffset, byteLength);
|
|
2802
|
+
}
|
|
2803
|
+
/** Synchronously read data from the buffer. WebGL only. */
|
|
2804
|
+
readSyncWebGL(byteOffset = 0, byteLength) {
|
|
2805
|
+
byteLength = byteLength ?? this.byteLength - byteOffset;
|
|
2806
|
+
const data = new Uint8Array(byteLength);
|
|
2807
|
+
const dstOffset = 0;
|
|
2808
|
+
this.gl.bindBuffer(36662, this.handle);
|
|
2809
|
+
this.gl.getBufferSubData(36662, byteOffset, data, dstOffset, byteLength);
|
|
2810
|
+
this.gl.bindBuffer(36662, null);
|
|
2811
|
+
this._setDebugData(data, byteOffset, byteLength);
|
|
2812
|
+
return data;
|
|
2813
|
+
}
|
|
2814
|
+
};
|
|
2815
|
+
function getWebGLTarget(usage) {
|
|
2816
|
+
if (usage & import_core12.Buffer.INDEX) {
|
|
2817
|
+
return 34963;
|
|
2818
|
+
}
|
|
2819
|
+
if (usage & import_core12.Buffer.VERTEX) {
|
|
2820
|
+
return 34962;
|
|
2821
|
+
}
|
|
2822
|
+
if (usage & import_core12.Buffer.UNIFORM) {
|
|
2823
|
+
return 35345;
|
|
2824
|
+
}
|
|
2825
|
+
return 34962;
|
|
2826
|
+
}
|
|
2827
|
+
function getWebGLUsage(usage) {
|
|
2828
|
+
if (usage & import_core12.Buffer.INDEX) {
|
|
2829
|
+
return 35044;
|
|
2830
|
+
}
|
|
2831
|
+
if (usage & import_core12.Buffer.VERTEX) {
|
|
2832
|
+
return 35044;
|
|
2833
|
+
}
|
|
2834
|
+
if (usage & import_core12.Buffer.UNIFORM) {
|
|
2835
|
+
return 35048;
|
|
2836
|
+
}
|
|
2837
|
+
return 35044;
|
|
2838
|
+
}
|
|
2839
|
+
|
|
2840
|
+
// dist/adapter/resources/webgl-shader.js
|
|
2841
|
+
var import_core13 = require("@luma.gl/core");
|
|
2842
|
+
var import_constants14 = require("@luma.gl/constants");
|
|
2972
2843
|
|
|
2973
2844
|
// dist/adapter/helpers/parse-shader-compiler-log.js
|
|
2974
2845
|
function parseShaderCompilerLog(errLog) {
|
|
@@ -3015,7 +2886,7 @@ function getMessageType(messageType) {
|
|
|
3015
2886
|
}
|
|
3016
2887
|
|
|
3017
2888
|
// dist/adapter/resources/webgl-shader.js
|
|
3018
|
-
var WEBGLShader = class extends
|
|
2889
|
+
var WEBGLShader = class extends import_core13.Shader {
|
|
3019
2890
|
device;
|
|
3020
2891
|
handle;
|
|
3021
2892
|
constructor(device, props) {
|
|
@@ -3045,24 +2916,24 @@ var WEBGLShader = class extends import_core14.Shader {
|
|
|
3045
2916
|
return this.getCompilationInfoSync();
|
|
3046
2917
|
}
|
|
3047
2918
|
getCompilationInfoSync() {
|
|
3048
|
-
const
|
|
3049
|
-
return parseShaderCompilerLog(
|
|
2919
|
+
const log10 = this.device.gl.getShaderInfoLog(this.handle);
|
|
2920
|
+
return log10 ? parseShaderCompilerLog(log10) : [];
|
|
3050
2921
|
}
|
|
3051
2922
|
getTranslatedSource() {
|
|
3052
2923
|
const extensions = this.device.getExtension("WEBGL_debug_shaders");
|
|
3053
2924
|
const ext = extensions.WEBGL_debug_shaders;
|
|
3054
|
-
return ext == null ? void 0 : ext.getTranslatedShaderSource(this.handle);
|
|
2925
|
+
return (ext == null ? void 0 : ext.getTranslatedShaderSource(this.handle)) || null;
|
|
3055
2926
|
}
|
|
3056
2927
|
// PRIVATE METHODS
|
|
3057
2928
|
/** Compile a shader and get compilation status */
|
|
3058
2929
|
async _compile(source) {
|
|
3059
|
-
const addGLSLVersion = (source2) => source2.startsWith("#version ") ? source2 : `#version
|
|
2930
|
+
const addGLSLVersion = (source2) => source2.startsWith("#version ") ? source2 : `#version 300 es
|
|
3060
2931
|
${source2}`;
|
|
3061
2932
|
source = addGLSLVersion(source);
|
|
3062
2933
|
const { gl } = this.device;
|
|
3063
2934
|
gl.shaderSource(this.handle, source);
|
|
3064
2935
|
gl.compileShader(this.handle);
|
|
3065
|
-
if (
|
|
2936
|
+
if (import_core13.log.level === 0) {
|
|
3066
2937
|
this.compilationStatus = "pending";
|
|
3067
2938
|
return;
|
|
3068
2939
|
}
|
|
@@ -3074,9 +2945,9 @@ ${source2}`;
|
|
|
3074
2945
|
}
|
|
3075
2946
|
return;
|
|
3076
2947
|
}
|
|
3077
|
-
|
|
2948
|
+
import_core13.log.once(1, "Shader compilation is asynchronous")();
|
|
3078
2949
|
await this._waitForCompilationComplete();
|
|
3079
|
-
|
|
2950
|
+
import_core13.log.info(2, `Shader ${this.id} - async compilation complete: ${this.compilationStatus}`)();
|
|
3080
2951
|
this._getCompilationStatus();
|
|
3081
2952
|
this.debugShader();
|
|
3082
2953
|
}
|
|
@@ -3108,26 +2979,37 @@ ${source2}`;
|
|
|
3108
2979
|
};
|
|
3109
2980
|
|
|
3110
2981
|
// dist/adapter/resources/webgl-render-pass.js
|
|
3111
|
-
var
|
|
3112
|
-
var
|
|
2982
|
+
var import_core14 = require("@luma.gl/core");
|
|
2983
|
+
var import_constants15 = require("@luma.gl/constants");
|
|
3113
2984
|
var GL_DEPTH_BUFFER_BIT = 256;
|
|
3114
2985
|
var GL_STENCIL_BUFFER_BIT = 1024;
|
|
3115
2986
|
var GL_COLOR_BUFFER_BIT = 16384;
|
|
3116
2987
|
var GL_COLOR = 6144;
|
|
3117
2988
|
var COLOR_CHANNELS = [1, 2, 4, 8];
|
|
3118
|
-
var WEBGLRenderPass = class extends
|
|
2989
|
+
var WEBGLRenderPass = class extends import_core14.RenderPass {
|
|
3119
2990
|
device;
|
|
3120
2991
|
/** Parameters that should be applied before each draw call */
|
|
3121
2992
|
glParameters;
|
|
3122
2993
|
constructor(device, props) {
|
|
2994
|
+
var _a;
|
|
3123
2995
|
super(device, props);
|
|
3124
2996
|
this.device = device;
|
|
3125
|
-
|
|
3126
|
-
|
|
2997
|
+
let viewport;
|
|
2998
|
+
if (!((_a = props == null ? void 0 : props.parameters) == null ? void 0 : _a.viewport)) {
|
|
2999
|
+
if (props == null ? void 0 : props.framebuffer) {
|
|
3000
|
+
const { width, height } = props.framebuffer;
|
|
3001
|
+
viewport = [0, 0, width, height];
|
|
3002
|
+
} else {
|
|
3003
|
+
const [width, height] = device.getCanvasContext().getDrawingBufferSize();
|
|
3004
|
+
viewport = [0, 0, width, height];
|
|
3005
|
+
}
|
|
3006
|
+
}
|
|
3007
|
+
this.device.pushState();
|
|
3008
|
+
this.setParameters({ viewport, ...this.props.parameters });
|
|
3127
3009
|
this.clear();
|
|
3128
3010
|
}
|
|
3129
3011
|
end() {
|
|
3130
|
-
|
|
3012
|
+
this.device.popState();
|
|
3131
3013
|
}
|
|
3132
3014
|
pushDebugGroup(groupLabel) {
|
|
3133
3015
|
}
|
|
@@ -3143,9 +3025,7 @@ var WEBGLRenderPass = class extends import_core15.RenderPass {
|
|
|
3143
3025
|
*/
|
|
3144
3026
|
setParameters(parameters = {}) {
|
|
3145
3027
|
const glParameters = { ...this.glParameters };
|
|
3146
|
-
|
|
3147
|
-
glParameters.framebuffer = this.props.framebuffer;
|
|
3148
|
-
}
|
|
3028
|
+
glParameters.framebuffer = this.props.framebuffer || null;
|
|
3149
3029
|
if (this.props.depthReadOnly) {
|
|
3150
3030
|
glParameters.depthMask = !this.props.depthReadOnly;
|
|
3151
3031
|
}
|
|
@@ -3231,19 +3111,17 @@ var WEBGLRenderPass = class extends import_core15.RenderPass {
|
|
|
3231
3111
|
};
|
|
3232
3112
|
|
|
3233
3113
|
// dist/adapter/resources/webgl-render-pipeline.js
|
|
3234
|
-
var
|
|
3235
|
-
var
|
|
3236
|
-
var import_constants21 = require("@luma.gl/constants");
|
|
3114
|
+
var import_core15 = require("@luma.gl/core");
|
|
3115
|
+
var import_constants22 = require("@luma.gl/constants");
|
|
3237
3116
|
|
|
3238
3117
|
// dist/adapter/helpers/get-shader-layout.js
|
|
3239
|
-
var
|
|
3118
|
+
var import_constants19 = require("@luma.gl/constants");
|
|
3240
3119
|
|
|
3241
3120
|
// dist/classic/accessor.js
|
|
3242
|
-
var
|
|
3243
|
-
var import_constants16 = require("@luma.gl/constants");
|
|
3121
|
+
var import_constants17 = require("@luma.gl/constants");
|
|
3244
3122
|
|
|
3245
3123
|
// dist/classic/typed-array-utils.js
|
|
3246
|
-
var
|
|
3124
|
+
var import_constants16 = require("@luma.gl/constants");
|
|
3247
3125
|
var ERR_TYPE_DEDUCTION = "Failed to deduce GL constant from typed array";
|
|
3248
3126
|
function getGLTypeFromTypedArray(arrayOrType) {
|
|
3249
3127
|
const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
|
|
@@ -3303,12 +3181,6 @@ var DEFAULT_ACCESSOR_VALUES = {
|
|
|
3303
3181
|
normalized: false,
|
|
3304
3182
|
integer: false
|
|
3305
3183
|
};
|
|
3306
|
-
var PROP_CHECKS = {
|
|
3307
|
-
deprecatedProps: {
|
|
3308
|
-
instanced: "divisor",
|
|
3309
|
-
isInstanced: "divisor"
|
|
3310
|
-
}
|
|
3311
|
-
};
|
|
3312
3184
|
var Accessor = class {
|
|
3313
3185
|
offset;
|
|
3314
3186
|
stride;
|
|
@@ -3324,7 +3196,6 @@ var Accessor = class {
|
|
|
3324
3196
|
return ArrayType.BYTES_PER_ELEMENT;
|
|
3325
3197
|
}
|
|
3326
3198
|
static getBytesPerVertex(accessor) {
|
|
3327
|
-
(0, import_core16.assert)(accessor.size);
|
|
3328
3199
|
const ArrayType = getTypedArrayFromGLType(accessor.type || 5126);
|
|
3329
3200
|
return ArrayType.BYTES_PER_ELEMENT * accessor.size;
|
|
3330
3201
|
}
|
|
@@ -3353,7 +3224,6 @@ var Accessor = class {
|
|
|
3353
3224
|
// PRIVATE
|
|
3354
3225
|
// eslint-disable-next-line complexity, max-statements
|
|
3355
3226
|
_assign(props = {}) {
|
|
3356
|
-
props = (0, import_core16.checkProps)("Accessor", props, PROP_CHECKS);
|
|
3357
3227
|
if (props.type !== void 0) {
|
|
3358
3228
|
this.type = props.type;
|
|
3359
3229
|
if (props.type === 5124 || props.type === 5125) {
|
|
@@ -3420,7 +3290,7 @@ var Accessor = class {
|
|
|
3420
3290
|
};
|
|
3421
3291
|
|
|
3422
3292
|
// dist/adapter/helpers/decode-webgl-types.js
|
|
3423
|
-
var
|
|
3293
|
+
var import_constants18 = require("@luma.gl/constants");
|
|
3424
3294
|
function isSamplerUniform(type) {
|
|
3425
3295
|
return SAMPLER_TYPES.includes(type);
|
|
3426
3296
|
}
|
|
@@ -3713,7 +3583,7 @@ function parseUniformName(name) {
|
|
|
3713
3583
|
}
|
|
3714
3584
|
|
|
3715
3585
|
// dist/adapter/helpers/set-uniform.js
|
|
3716
|
-
var
|
|
3586
|
+
var import_constants20 = require("@luma.gl/constants");
|
|
3717
3587
|
function setUniform(gl, location, type, value) {
|
|
3718
3588
|
const gl2 = gl;
|
|
3719
3589
|
let uniformValue = value;
|
|
@@ -3798,8 +3668,26 @@ function setUniform(gl, location, type, value) {
|
|
|
3798
3668
|
throw new Error("Illegal uniform");
|
|
3799
3669
|
}
|
|
3800
3670
|
|
|
3671
|
+
// dist/utils/split-uniforms-and-bindings.js
|
|
3672
|
+
var import_types = require("@math.gl/types");
|
|
3673
|
+
function isUniformValue(value) {
|
|
3674
|
+
return (0, import_types.isNumericArray)(value) !== null || typeof value === "number" || typeof value === "boolean";
|
|
3675
|
+
}
|
|
3676
|
+
function splitUniformsAndBindings(uniforms) {
|
|
3677
|
+
const result = { bindings: {}, uniforms: {} };
|
|
3678
|
+
Object.keys(uniforms).forEach((name) => {
|
|
3679
|
+
const uniform = uniforms[name];
|
|
3680
|
+
if (isUniformValue(uniform)) {
|
|
3681
|
+
result.uniforms[name] = uniform;
|
|
3682
|
+
} else {
|
|
3683
|
+
result.bindings[name] = uniform;
|
|
3684
|
+
}
|
|
3685
|
+
});
|
|
3686
|
+
return result;
|
|
3687
|
+
}
|
|
3688
|
+
|
|
3801
3689
|
// dist/adapter/helpers/webgl-topology-utils.js
|
|
3802
|
-
var
|
|
3690
|
+
var import_constants21 = require("@luma.gl/constants");
|
|
3803
3691
|
function getGLDrawMode(topology) {
|
|
3804
3692
|
switch (topology) {
|
|
3805
3693
|
case "point-list":
|
|
@@ -3808,14 +3696,10 @@ function getGLDrawMode(topology) {
|
|
|
3808
3696
|
return 1;
|
|
3809
3697
|
case "line-strip":
|
|
3810
3698
|
return 3;
|
|
3811
|
-
case "line-loop-webgl":
|
|
3812
|
-
return 2;
|
|
3813
3699
|
case "triangle-list":
|
|
3814
3700
|
return 4;
|
|
3815
3701
|
case "triangle-strip":
|
|
3816
3702
|
return 5;
|
|
3817
|
-
case "triangle-fan-webgl":
|
|
3818
|
-
return 6;
|
|
3819
3703
|
default:
|
|
3820
3704
|
throw new Error(topology);
|
|
3821
3705
|
}
|
|
@@ -3828,14 +3712,10 @@ function getGLPrimitive(topology) {
|
|
|
3828
3712
|
return 1;
|
|
3829
3713
|
case "line-strip":
|
|
3830
3714
|
return 1;
|
|
3831
|
-
case "line-loop-webgl":
|
|
3832
|
-
return 1;
|
|
3833
3715
|
case "triangle-list":
|
|
3834
3716
|
return 4;
|
|
3835
3717
|
case "triangle-strip":
|
|
3836
3718
|
return 4;
|
|
3837
|
-
case "triangle-fan-webgl":
|
|
3838
|
-
return 4;
|
|
3839
3719
|
default:
|
|
3840
3720
|
throw new Error(topology);
|
|
3841
3721
|
}
|
|
@@ -3843,7 +3723,7 @@ function getGLPrimitive(topology) {
|
|
|
3843
3723
|
|
|
3844
3724
|
// dist/adapter/resources/webgl-render-pipeline.js
|
|
3845
3725
|
var LOG_PROGRAM_PERF_PRIORITY = 4;
|
|
3846
|
-
var WEBGLRenderPipeline = class extends
|
|
3726
|
+
var WEBGLRenderPipeline = class extends import_core15.RenderPipeline {
|
|
3847
3727
|
/** The WebGL device that created this render pipeline */
|
|
3848
3728
|
device;
|
|
3849
3729
|
/** Handle to underlying WebGL program */
|
|
@@ -3868,25 +3748,18 @@ var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
|
|
|
3868
3748
|
this.device = device;
|
|
3869
3749
|
this.handle = this.props.handle || this.device.gl.createProgram();
|
|
3870
3750
|
this.device.setSpectorMetadata(this.handle, { id: this.props.id });
|
|
3871
|
-
this.vs =
|
|
3872
|
-
this.fs =
|
|
3751
|
+
this.vs = props.vs;
|
|
3752
|
+
this.fs = props.fs;
|
|
3873
3753
|
const { varyings, bufferMode = 35981 } = props;
|
|
3874
3754
|
if (varyings && varyings.length > 0) {
|
|
3875
3755
|
this.varyings = varyings;
|
|
3876
3756
|
this.device.gl.transformFeedbackVaryings(this.handle, varyings, bufferMode);
|
|
3877
3757
|
}
|
|
3878
3758
|
this._linkShaders();
|
|
3879
|
-
|
|
3759
|
+
import_core15.log.time(1, `RenderPipeline ${this.id} - shaderLayout introspection`)();
|
|
3880
3760
|
this.introspectedLayout = getShaderLayout(this.device.gl, this.handle);
|
|
3881
|
-
|
|
3882
|
-
this.shaderLayout =
|
|
3883
|
-
switch (this.props.topology) {
|
|
3884
|
-
case "triangle-fan-webgl":
|
|
3885
|
-
case "line-loop-webgl":
|
|
3886
|
-
import_core17.log.warn(`Primitive topology ${this.props.topology} is deprecated and will be removed in v9.1`);
|
|
3887
|
-
break;
|
|
3888
|
-
default:
|
|
3889
|
-
}
|
|
3761
|
+
import_core15.log.timeEnd(1, `RenderPipeline ${this.id} - shaderLayout introspection`)();
|
|
3762
|
+
this.shaderLayout = mergeShaderLayout(this.introspectedLayout, props.shaderLayout);
|
|
3890
3763
|
}
|
|
3891
3764
|
destroy() {
|
|
3892
3765
|
if (this.handle) {
|
|
@@ -3904,12 +3777,12 @@ var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
|
|
|
3904
3777
|
if (!binding) {
|
|
3905
3778
|
const validBindings = this.shaderLayout.bindings.map((binding2) => `"${binding2.name}"`).join(", ");
|
|
3906
3779
|
if (!(options == null ? void 0 : options.disableWarnings)) {
|
|
3907
|
-
|
|
3780
|
+
import_core15.log.warn(`No binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`, value)();
|
|
3908
3781
|
}
|
|
3909
3782
|
continue;
|
|
3910
3783
|
}
|
|
3911
3784
|
if (!value) {
|
|
3912
|
-
|
|
3785
|
+
import_core15.log.warn(`Unsetting binding "${name}" in render pipeline "${this.id}"`)();
|
|
3913
3786
|
}
|
|
3914
3787
|
switch (binding.type) {
|
|
3915
3788
|
case "uniform":
|
|
@@ -3923,7 +3796,7 @@ var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
|
|
|
3923
3796
|
}
|
|
3924
3797
|
break;
|
|
3925
3798
|
case "sampler":
|
|
3926
|
-
|
|
3799
|
+
import_core15.log.warn(`Ignoring sampler ${name}`)();
|
|
3927
3800
|
break;
|
|
3928
3801
|
default:
|
|
3929
3802
|
throw new Error(binding.type);
|
|
@@ -3956,17 +3829,13 @@ var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
|
|
|
3956
3829
|
const isIndexed = Boolean(vertexArray.indexBuffer);
|
|
3957
3830
|
const glIndexType = (_a = vertexArray.indexBuffer) == null ? void 0 : _a.glIndexType;
|
|
3958
3831
|
if (this.linkStatus !== "success") {
|
|
3959
|
-
|
|
3832
|
+
import_core15.log.info(2, `RenderPipeline:${this.id}.draw() aborted - waiting for shader linking`)();
|
|
3960
3833
|
return false;
|
|
3961
3834
|
}
|
|
3962
|
-
if (!this._areTexturesRenderable()
|
|
3963
|
-
|
|
3835
|
+
if (!this._areTexturesRenderable()) {
|
|
3836
|
+
import_core15.log.info(2, `RenderPipeline:${this.id}.draw() aborted - textures not yet loaded`)();
|
|
3964
3837
|
return false;
|
|
3965
3838
|
}
|
|
3966
|
-
if (vertexCount === 0) {
|
|
3967
|
-
import_core17.log.info(2, `RenderPipeline:${this.id}.draw() aborted - no vertices to draw`)();
|
|
3968
|
-
return true;
|
|
3969
|
-
}
|
|
3970
3839
|
this.device.gl.useProgram(this.handle);
|
|
3971
3840
|
vertexArray.bindBeforeRender(renderPass);
|
|
3972
3841
|
if (transformFeedback) {
|
|
@@ -4001,9 +3870,9 @@ var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
|
|
|
4001
3870
|
}
|
|
4002
3871
|
// DEPRECATED METHODS
|
|
4003
3872
|
setUniformsWebGL(uniforms) {
|
|
4004
|
-
const { bindings } =
|
|
3873
|
+
const { bindings } = splitUniformsAndBindings(uniforms);
|
|
4005
3874
|
Object.keys(bindings).forEach((name) => {
|
|
4006
|
-
|
|
3875
|
+
import_core15.log.warn(`Unsupported value "${JSON.stringify(bindings[name])}" used in setUniforms() for key ${name}. Use setBindings() instead?`)();
|
|
4007
3876
|
});
|
|
4008
3877
|
Object.assign(this.uniforms, uniforms);
|
|
4009
3878
|
}
|
|
@@ -4014,19 +3883,19 @@ var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
|
|
|
4014
3883
|
const { gl } = this.device;
|
|
4015
3884
|
gl.attachShader(this.handle, this.vs.handle);
|
|
4016
3885
|
gl.attachShader(this.handle, this.fs.handle);
|
|
4017
|
-
|
|
3886
|
+
import_core15.log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
|
|
4018
3887
|
gl.linkProgram(this.handle);
|
|
4019
|
-
|
|
4020
|
-
if (
|
|
3888
|
+
import_core15.log.timeEnd(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
|
|
3889
|
+
if (import_core15.log.level === 0) {
|
|
4021
3890
|
}
|
|
4022
3891
|
if (!this.device.features.has("compilation-status-async-webgl")) {
|
|
4023
3892
|
const status2 = this._getLinkStatus();
|
|
4024
3893
|
this._reportLinkStatus(status2);
|
|
4025
3894
|
return;
|
|
4026
3895
|
}
|
|
4027
|
-
|
|
3896
|
+
import_core15.log.once(1, "RenderPipeline linking is asynchronous")();
|
|
4028
3897
|
await this._waitForLinkComplete();
|
|
4029
|
-
|
|
3898
|
+
import_core15.log.info(2, `RenderPipeline ${this.id} - async linking complete: ${this.linkStatus}`)();
|
|
4030
3899
|
const status = this._getLinkStatus();
|
|
4031
3900
|
this._reportLinkStatus(status);
|
|
4032
3901
|
}
|
|
@@ -4093,10 +3962,15 @@ var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
|
|
|
4093
3962
|
*/
|
|
4094
3963
|
_areTexturesRenderable() {
|
|
4095
3964
|
let texturesRenderable = true;
|
|
3965
|
+
for (const bindingInfo of this.shaderLayout.bindings) {
|
|
3966
|
+
if (!this.bindings[bindingInfo.name] && !this.bindings[bindingInfo.name.replace(/Uniforms$/, "")]) {
|
|
3967
|
+
import_core15.log.warn(`Binding ${bindingInfo.name} not found in ${this.id}`)();
|
|
3968
|
+
texturesRenderable = false;
|
|
3969
|
+
}
|
|
3970
|
+
}
|
|
4096
3971
|
for (const [, texture] of Object.entries(this.bindings)) {
|
|
4097
3972
|
if (texture instanceof WEBGLTexture) {
|
|
4098
3973
|
texture.update();
|
|
4099
|
-
texturesRenderable = texturesRenderable && texture.loaded;
|
|
4100
3974
|
}
|
|
4101
3975
|
}
|
|
4102
3976
|
return texturesRenderable;
|
|
@@ -4149,13 +4023,13 @@ var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
|
|
|
4149
4023
|
} else if (value instanceof WEBGLTexture) {
|
|
4150
4024
|
texture = value;
|
|
4151
4025
|
} else if (value instanceof WEBGLFramebuffer && value.colorAttachments[0] instanceof WEBGLTextureView) {
|
|
4152
|
-
|
|
4026
|
+
import_core15.log.warn("Passing framebuffer in texture binding may be deprecated. Use fbo.colorAttachments[0] instead")();
|
|
4153
4027
|
texture = value.colorAttachments[0].texture;
|
|
4154
4028
|
} else {
|
|
4155
4029
|
throw new Error("No texture");
|
|
4156
4030
|
}
|
|
4157
4031
|
gl.activeTexture(33984 + textureUnit);
|
|
4158
|
-
gl.bindTexture(texture.
|
|
4032
|
+
gl.bindTexture(texture.glTarget, texture.handle);
|
|
4159
4033
|
textureUnit += 1;
|
|
4160
4034
|
break;
|
|
4161
4035
|
case "sampler":
|
|
@@ -4180,17 +4054,30 @@ var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
|
|
|
4180
4054
|
}
|
|
4181
4055
|
}
|
|
4182
4056
|
};
|
|
4057
|
+
function mergeShaderLayout(baseLayout, overrideLayout) {
|
|
4058
|
+
const mergedLayout = {
|
|
4059
|
+
...baseLayout,
|
|
4060
|
+
attributes: baseLayout.attributes.map((attribute) => ({ ...attribute }))
|
|
4061
|
+
};
|
|
4062
|
+
for (const attribute of (overrideLayout == null ? void 0 : overrideLayout.attributes) || []) {
|
|
4063
|
+
const baseAttribute = mergedLayout.attributes.find((attr) => attr.name === attribute.name);
|
|
4064
|
+
if (!baseAttribute) {
|
|
4065
|
+
import_core15.log.warn(`shader layout attribute ${attribute.name} not present in shader`);
|
|
4066
|
+
} else {
|
|
4067
|
+
baseAttribute.type = attribute.type || baseAttribute.type;
|
|
4068
|
+
baseAttribute.stepMode = attribute.stepMode || baseAttribute.stepMode;
|
|
4069
|
+
}
|
|
4070
|
+
}
|
|
4071
|
+
return mergedLayout;
|
|
4072
|
+
}
|
|
4183
4073
|
|
|
4184
4074
|
// dist/adapter/resources/webgl-command-encoder.js
|
|
4185
|
-
var
|
|
4075
|
+
var import_core17 = require("@luma.gl/core");
|
|
4186
4076
|
|
|
4187
4077
|
// dist/adapter/resources/webgl-command-buffer.js
|
|
4188
|
-
var
|
|
4189
|
-
var
|
|
4190
|
-
|
|
4191
|
-
return value;
|
|
4192
|
-
}
|
|
4193
|
-
var WEBGLCommandBuffer = class extends import_core19.CommandBuffer {
|
|
4078
|
+
var import_core16 = require("@luma.gl/core");
|
|
4079
|
+
var import_constants23 = require("@luma.gl/constants");
|
|
4080
|
+
var WEBGLCommandBuffer = class extends import_core16.CommandBuffer {
|
|
4194
4081
|
device;
|
|
4195
4082
|
commands = [];
|
|
4196
4083
|
constructor(device) {
|
|
@@ -4217,8 +4104,8 @@ var WEBGLCommandBuffer = class extends import_core19.CommandBuffer {
|
|
|
4217
4104
|
}
|
|
4218
4105
|
};
|
|
4219
4106
|
function _copyBufferToBuffer(device, options) {
|
|
4220
|
-
const source =
|
|
4221
|
-
const destination =
|
|
4107
|
+
const source = options.source;
|
|
4108
|
+
const destination = options.destination;
|
|
4222
4109
|
device.gl.bindBuffer(36662, source.handle);
|
|
4223
4110
|
device.gl.bindBuffer(36663, destination.handle);
|
|
4224
4111
|
device.gl.copyBufferSubData(36662, 36663, options.sourceOffset ?? 0, options.destinationOffset ?? 0, options.size);
|
|
@@ -4271,8 +4158,8 @@ function _copyTextureToBuffer(device, options) {
|
|
|
4271
4158
|
const webglBuffer = destination;
|
|
4272
4159
|
const sourceWidth = width || framebuffer.width;
|
|
4273
4160
|
const sourceHeight = height || framebuffer.height;
|
|
4274
|
-
const sourceParams =
|
|
4275
|
-
const sourceFormat = sourceParams.
|
|
4161
|
+
const sourceParams = getTextureFormatWebGL(framebuffer.colorAttachments[0].texture.props.format);
|
|
4162
|
+
const sourceFormat = sourceParams.format;
|
|
4276
4163
|
const sourceType = sourceParams.type;
|
|
4277
4164
|
device.gl.bindBuffer(35051, webglBuffer.handle);
|
|
4278
4165
|
prevHandle = device.gl.bindFramebuffer(36160, framebuffer.handle);
|
|
@@ -4324,7 +4211,7 @@ function _copyTextureToTexture(device, options) {
|
|
|
4324
4211
|
width = Number.isFinite(width) ? width : texture.width;
|
|
4325
4212
|
height = Number.isFinite(height) ? height : texture.height;
|
|
4326
4213
|
texture.bind(0);
|
|
4327
|
-
textureTarget = texture.
|
|
4214
|
+
textureTarget = texture.glTarget;
|
|
4328
4215
|
} else {
|
|
4329
4216
|
throw new Error("invalid destination");
|
|
4330
4217
|
}
|
|
@@ -4348,7 +4235,7 @@ function _copyTextureToTexture(device, options) {
|
|
|
4348
4235
|
}
|
|
4349
4236
|
}
|
|
4350
4237
|
function getFramebuffer(source) {
|
|
4351
|
-
if (source instanceof
|
|
4238
|
+
if (source instanceof import_core16.Texture) {
|
|
4352
4239
|
const { width, height, id } = source;
|
|
4353
4240
|
const framebuffer = source.device.createFramebuffer({
|
|
4354
4241
|
id: `framebuffer-for-${id}`,
|
|
@@ -4362,7 +4249,7 @@ function getFramebuffer(source) {
|
|
|
4362
4249
|
}
|
|
4363
4250
|
|
|
4364
4251
|
// dist/adapter/resources/webgl-command-encoder.js
|
|
4365
|
-
var WEBGLCommandEncoder = class extends
|
|
4252
|
+
var WEBGLCommandEncoder = class extends import_core17.CommandEncoder {
|
|
4366
4253
|
device;
|
|
4367
4254
|
commandBuffer;
|
|
4368
4255
|
constructor(device, props) {
|
|
@@ -4401,10 +4288,33 @@ var WEBGLCommandEncoder = class extends import_core20.CommandEncoder {
|
|
|
4401
4288
|
};
|
|
4402
4289
|
|
|
4403
4290
|
// dist/adapter/resources/webgl-vertex-array.js
|
|
4404
|
-
var
|
|
4405
|
-
var
|
|
4291
|
+
var import_core18 = require("@luma.gl/core");
|
|
4292
|
+
var import_constants24 = require("@luma.gl/constants");
|
|
4406
4293
|
var import_env2 = require("@probe.gl/env");
|
|
4407
|
-
|
|
4294
|
+
|
|
4295
|
+
// dist/utils/fill-array.js
|
|
4296
|
+
function fillArray(options) {
|
|
4297
|
+
const { target, source, start = 0, count = 1 } = options;
|
|
4298
|
+
const length = source.length;
|
|
4299
|
+
const total = count * length;
|
|
4300
|
+
let copied = 0;
|
|
4301
|
+
for (let i = start; copied < length; copied++) {
|
|
4302
|
+
target[i++] = source[copied];
|
|
4303
|
+
}
|
|
4304
|
+
while (copied < total) {
|
|
4305
|
+
if (copied < total - copied) {
|
|
4306
|
+
target.copyWithin(start + copied, start, start + copied);
|
|
4307
|
+
copied *= 2;
|
|
4308
|
+
} else {
|
|
4309
|
+
target.copyWithin(start + copied, start, start + total - copied);
|
|
4310
|
+
copied = total;
|
|
4311
|
+
}
|
|
4312
|
+
}
|
|
4313
|
+
return options.target;
|
|
4314
|
+
}
|
|
4315
|
+
|
|
4316
|
+
// dist/adapter/resources/webgl-vertex-array.js
|
|
4317
|
+
var WEBGLVertexArray = class extends import_core18.VertexArray {
|
|
4408
4318
|
get [Symbol.toStringTag]() {
|
|
4409
4319
|
return "VertexArray";
|
|
4410
4320
|
}
|
|
@@ -4571,8 +4481,8 @@ var WEBGLVertexArray = class extends import_core21.VertexArray {
|
|
|
4571
4481
|
this.buffer = this.buffer || this.device.createBuffer({ byteLength });
|
|
4572
4482
|
updateNeeded = updateNeeded || !compareConstantArrayValues(constantValue, this.bufferValue);
|
|
4573
4483
|
if (updateNeeded) {
|
|
4574
|
-
const typedArray = (0,
|
|
4575
|
-
|
|
4484
|
+
const typedArray = (0, import_core18.getScratchArray)(value.constructor, length);
|
|
4485
|
+
fillArray({ target: typedArray, source: constantValue, start: 0, count: length });
|
|
4576
4486
|
this.buffer.write(typedArray);
|
|
4577
4487
|
this.bufferValue = value;
|
|
4578
4488
|
}
|
|
@@ -4598,9 +4508,9 @@ function compareConstantArrayValues(v1, v2) {
|
|
|
4598
4508
|
}
|
|
4599
4509
|
|
|
4600
4510
|
// dist/adapter/resources/webgl-transform-feedback.js
|
|
4601
|
-
var
|
|
4602
|
-
var
|
|
4603
|
-
var WEBGLTransformFeedback = class extends
|
|
4511
|
+
var import_core19 = require("@luma.gl/core");
|
|
4512
|
+
var import_constants25 = require("@luma.gl/constants");
|
|
4513
|
+
var WEBGLTransformFeedback = class extends import_core19.TransformFeedback {
|
|
4604
4514
|
device;
|
|
4605
4515
|
gl;
|
|
4606
4516
|
handle;
|
|
@@ -4663,7 +4573,7 @@ var WEBGLTransformFeedback = class extends import_core22.TransformFeedback {
|
|
|
4663
4573
|
const { buffer, byteLength, byteOffset } = this._getBufferRange(bufferOrRange);
|
|
4664
4574
|
if (location < 0) {
|
|
4665
4575
|
this.unusedBuffers[locationOrName] = buffer;
|
|
4666
|
-
|
|
4576
|
+
import_core19.log.warn(`${this.id} unusedBuffers varying buffer ${locationOrName}`)();
|
|
4667
4577
|
return;
|
|
4668
4578
|
}
|
|
4669
4579
|
this.buffers[location] = { buffer, byteLength, byteOffset };
|
|
@@ -4750,9 +4660,9 @@ function isIndex(value) {
|
|
|
4750
4660
|
}
|
|
4751
4661
|
|
|
4752
4662
|
// dist/adapter/resources/webgl-query-set.js
|
|
4753
|
-
var
|
|
4754
|
-
var
|
|
4755
|
-
var WEBGLQuerySet = class extends
|
|
4663
|
+
var import_core20 = require("@luma.gl/core");
|
|
4664
|
+
var import_constants26 = require("@luma.gl/constants");
|
|
4665
|
+
var WEBGLQuerySet = class extends import_core20.QuerySet {
|
|
4756
4666
|
device;
|
|
4757
4667
|
handle;
|
|
4758
4668
|
target = null;
|
|
@@ -4880,12 +4790,11 @@ var WEBGLQuerySet = class extends import_core23.QuerySet {
|
|
|
4880
4790
|
};
|
|
4881
4791
|
|
|
4882
4792
|
// dist/classic/copy-and-blit.js
|
|
4883
|
-
var
|
|
4884
|
-
var
|
|
4793
|
+
var import_core21 = require("@luma.gl/core");
|
|
4794
|
+
var import_constants28 = require("@luma.gl/constants");
|
|
4885
4795
|
|
|
4886
4796
|
// dist/classic/format-utils.js
|
|
4887
|
-
var
|
|
4888
|
-
var import_constants26 = require("@luma.gl/constants");
|
|
4797
|
+
var import_constants27 = require("@luma.gl/constants");
|
|
4889
4798
|
function glFormatToComponents(format) {
|
|
4890
4799
|
switch (format) {
|
|
4891
4800
|
case 6406:
|
|
@@ -4902,7 +4811,6 @@ function glFormatToComponents(format) {
|
|
|
4902
4811
|
case 34836:
|
|
4903
4812
|
return 4;
|
|
4904
4813
|
default:
|
|
4905
|
-
(0, import_core24.assert)(false);
|
|
4906
4814
|
return 0;
|
|
4907
4815
|
}
|
|
4908
4816
|
}
|
|
@@ -4917,18 +4825,16 @@ function glTypeToBytes(type) {
|
|
|
4917
4825
|
case 5126:
|
|
4918
4826
|
return 4;
|
|
4919
4827
|
default:
|
|
4920
|
-
(0, import_core24.assert)(false);
|
|
4921
4828
|
return 0;
|
|
4922
4829
|
}
|
|
4923
4830
|
}
|
|
4924
4831
|
|
|
4925
4832
|
// dist/classic/copy-and-blit.js
|
|
4926
4833
|
function readPixelsToArray(source, options) {
|
|
4927
|
-
var _a, _b;
|
|
4834
|
+
var _a, _b, _c, _d, _e, _f;
|
|
4928
4835
|
const {
|
|
4929
4836
|
sourceX = 0,
|
|
4930
4837
|
sourceY = 0,
|
|
4931
|
-
sourceFormat = 6408,
|
|
4932
4838
|
sourceAttachment = 36064
|
|
4933
4839
|
// TODO - support gl.readBuffer
|
|
4934
4840
|
} = options || {};
|
|
@@ -4937,16 +4843,19 @@ function readPixelsToArray(source, options) {
|
|
|
4937
4843
|
// following parameters are auto deduced if not provided
|
|
4938
4844
|
sourceWidth,
|
|
4939
4845
|
sourceHeight,
|
|
4846
|
+
sourceDepth,
|
|
4847
|
+
sourceFormat,
|
|
4940
4848
|
sourceType
|
|
4941
4849
|
} = options || {};
|
|
4942
4850
|
const { framebuffer, deleteFramebuffer } = getFramebuffer2(source);
|
|
4943
|
-
(0, import_core25.assert)(framebuffer);
|
|
4944
4851
|
const { gl, handle } = framebuffer;
|
|
4945
|
-
sourceWidth = sourceWidth || framebuffer.width;
|
|
4946
|
-
sourceHeight = sourceHeight || framebuffer.height;
|
|
4947
4852
|
const attachment = sourceAttachment - 36064;
|
|
4948
|
-
|
|
4949
|
-
|
|
4853
|
+
sourceWidth ||= framebuffer.width;
|
|
4854
|
+
sourceHeight ||= framebuffer.height;
|
|
4855
|
+
sourceDepth = ((_b = (_a = framebuffer.colorAttachments[attachment]) == null ? void 0 : _a.texture) == null ? void 0 : _b.depth) || 1;
|
|
4856
|
+
sourceFormat ||= ((_d = (_c = framebuffer.colorAttachments[attachment]) == null ? void 0 : _c.texture) == null ? void 0 : _d.glFormat) || 6408;
|
|
4857
|
+
sourceType ||= ((_f = (_e = framebuffer.colorAttachments[attachment]) == null ? void 0 : _e.texture) == null ? void 0 : _f.glType) || 5121;
|
|
4858
|
+
target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight, sourceDepth);
|
|
4950
4859
|
sourceType = sourceType || getGLTypeFromTypedArray(target);
|
|
4951
4860
|
const prevHandle = gl.bindFramebuffer(36160, handle);
|
|
4952
4861
|
gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
|
|
@@ -4960,7 +4869,6 @@ function readPixelsToBuffer(source, options) {
|
|
|
4960
4869
|
const { target, sourceX = 0, sourceY = 0, sourceFormat = 6408, targetByteOffset = 0 } = options || {};
|
|
4961
4870
|
let { sourceWidth, sourceHeight, sourceType } = options || {};
|
|
4962
4871
|
const { framebuffer, deleteFramebuffer } = getFramebuffer2(source);
|
|
4963
|
-
(0, import_core25.assert)(framebuffer);
|
|
4964
4872
|
sourceWidth = sourceWidth || framebuffer.width;
|
|
4965
4873
|
sourceHeight = sourceHeight || framebuffer.height;
|
|
4966
4874
|
const webglFramebuffer = framebuffer;
|
|
@@ -4988,7 +4896,7 @@ function readPixelsToBuffer(source, options) {
|
|
|
4988
4896
|
return webglBufferTarget;
|
|
4989
4897
|
}
|
|
4990
4898
|
function getFramebuffer2(source) {
|
|
4991
|
-
if (!(source instanceof
|
|
4899
|
+
if (!(source instanceof import_core21.Framebuffer)) {
|
|
4992
4900
|
return { framebuffer: toFramebuffer(source), deleteFramebuffer: true };
|
|
4993
4901
|
}
|
|
4994
4902
|
return { framebuffer: source, deleteFramebuffer: false };
|
|
@@ -5004,7 +4912,7 @@ function toFramebuffer(texture, props) {
|
|
|
5004
4912
|
});
|
|
5005
4913
|
return framebuffer;
|
|
5006
4914
|
}
|
|
5007
|
-
function getPixelArray(pixelArray, type, format, width, height) {
|
|
4915
|
+
function getPixelArray(pixelArray, type, format, width, height, depth) {
|
|
5008
4916
|
if (pixelArray) {
|
|
5009
4917
|
return pixelArray;
|
|
5010
4918
|
}
|
|
@@ -5015,11 +4923,9 @@ function getPixelArray(pixelArray, type, format, width, height) {
|
|
|
5015
4923
|
}
|
|
5016
4924
|
|
|
5017
4925
|
// dist/classic/clear.js
|
|
5018
|
-
var import_core26 = require("@luma.gl/core");
|
|
5019
4926
|
var GL_DEPTH_BUFFER_BIT2 = 256;
|
|
5020
4927
|
var GL_STENCIL_BUFFER_BIT2 = 1024;
|
|
5021
4928
|
var GL_COLOR_BUFFER_BIT2 = 16384;
|
|
5022
|
-
var ERR_ARGUMENTS = "clear: bad arguments";
|
|
5023
4929
|
function clear(device, options) {
|
|
5024
4930
|
const { framebuffer = null, color = null, depth = null, stencil = null } = options || {};
|
|
5025
4931
|
const parameters = {};
|
|
@@ -5045,7 +4951,6 @@ function clear(device, options) {
|
|
|
5045
4951
|
parameters.clearStencil = depth;
|
|
5046
4952
|
}
|
|
5047
4953
|
}
|
|
5048
|
-
(0, import_core26.assert)(clearFlags !== 0, ERR_ARGUMENTS);
|
|
5049
4954
|
const gl = device.gl;
|
|
5050
4955
|
withGLParameters(gl, parameters, () => {
|
|
5051
4956
|
gl.clear(clearFlags);
|
|
@@ -5053,8 +4958,10 @@ function clear(device, options) {
|
|
|
5053
4958
|
}
|
|
5054
4959
|
|
|
5055
4960
|
// dist/adapter/webgl-device.js
|
|
5056
|
-
var
|
|
5057
|
-
|
|
4961
|
+
var WebGLDevice = class extends import_core22.Device {
|
|
4962
|
+
//
|
|
4963
|
+
// Public `Device` API
|
|
4964
|
+
//
|
|
5058
4965
|
/** type of this device */
|
|
5059
4966
|
type = "webgl";
|
|
5060
4967
|
/** The underlying WebGL context */
|
|
@@ -5065,68 +4972,22 @@ var _WebGLDevice = class extends import_core27.Device {
|
|
|
5065
4972
|
canvasContext;
|
|
5066
4973
|
lost;
|
|
5067
4974
|
_resolveContextLost;
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
/**
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
}
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
* @param gl
|
|
5079
|
-
* @returns
|
|
5080
|
-
*/
|
|
5081
|
-
static attach(gl) {
|
|
5082
|
-
if (gl instanceof _WebGLDevice) {
|
|
5083
|
-
return gl;
|
|
5084
|
-
}
|
|
5085
|
-
if ((gl == null ? void 0 : gl.device) instanceof import_core27.Device) {
|
|
5086
|
-
return gl.device;
|
|
5087
|
-
}
|
|
5088
|
-
if (!isWebGL(gl)) {
|
|
5089
|
-
throw new Error("Invalid WebGL2RenderingContext");
|
|
5090
|
-
}
|
|
5091
|
-
return new _WebGLDevice({ gl });
|
|
5092
|
-
}
|
|
5093
|
-
static async create(props = {}) {
|
|
5094
|
-
var _a;
|
|
5095
|
-
import_core27.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
|
|
5096
|
-
const promises = [];
|
|
5097
|
-
if (props.debug) {
|
|
5098
|
-
promises.push(loadWebGLDeveloperTools());
|
|
5099
|
-
}
|
|
5100
|
-
if (props.spector) {
|
|
5101
|
-
promises.push(loadSpectorJS());
|
|
5102
|
-
}
|
|
5103
|
-
if (typeof props.canvas === "string") {
|
|
5104
|
-
promises.push(import_core27.CanvasContext.pageLoaded);
|
|
5105
|
-
}
|
|
5106
|
-
const results = await Promise.allSettled(promises);
|
|
5107
|
-
for (const result of results) {
|
|
5108
|
-
if (result.status === "rejected") {
|
|
5109
|
-
import_core27.log.error(`Failed to initialize debug libraries ${result.reason}`)();
|
|
5110
|
-
}
|
|
5111
|
-
}
|
|
5112
|
-
import_core27.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
|
|
5113
|
-
if ((_a = props.gl) == null ? void 0 : _a.device) {
|
|
5114
|
-
import_core27.log.warn("reattaching existing device")();
|
|
5115
|
-
return _WebGLDevice.attach(props.gl);
|
|
5116
|
-
}
|
|
5117
|
-
const device = new _WebGLDevice(props);
|
|
5118
|
-
const message2 = `Created ${device.type}${device.debug ? " debug" : ""} context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
|
|
5119
|
-
import_core27.log.probe(LOG_LEVEL2, message2)();
|
|
5120
|
-
import_core27.log.table(LOG_LEVEL2, device.info)();
|
|
5121
|
-
import_core27.log.groupEnd(LOG_LEVEL2)();
|
|
5122
|
-
return device;
|
|
5123
|
-
}
|
|
4975
|
+
/** WebGL2 context. */
|
|
4976
|
+
gl;
|
|
4977
|
+
debug = false;
|
|
4978
|
+
/** State used by luma.gl classes: TODO - move to canvasContext*/
|
|
4979
|
+
_canvasSizeInfo = { clientWidth: 0, clientHeight: 0, devicePixelRatio: 1 };
|
|
4980
|
+
/** State used by luma.gl classes - TODO - not used? */
|
|
4981
|
+
_extensions = {};
|
|
4982
|
+
_polyfilled = false;
|
|
4983
|
+
/** Instance of Spector.js (if initialized) */
|
|
4984
|
+
spectorJS;
|
|
5124
4985
|
//
|
|
5125
4986
|
// Public API
|
|
5126
4987
|
//
|
|
5127
4988
|
constructor(props) {
|
|
5128
4989
|
var _a, _b;
|
|
5129
|
-
super({ ...props, id: props.id ||
|
|
4990
|
+
super({ ...props, id: props.id || uid("webgl-device") });
|
|
5130
4991
|
const device = (_a = props.gl) == null ? void 0 : _a.device;
|
|
5131
4992
|
if (device) {
|
|
5132
4993
|
throw new Error(`WebGL context already attached to device ${device.id}`);
|
|
@@ -5136,8 +4997,7 @@ var _WebGLDevice = class extends import_core27.Device {
|
|
|
5136
4997
|
this.lost = new Promise((resolve) => {
|
|
5137
4998
|
this._resolveContextLost = resolve;
|
|
5138
4999
|
});
|
|
5139
|
-
|
|
5140
|
-
gl ||= createBrowserContext(this.canvasContext.canvas, {
|
|
5000
|
+
this.handle = createBrowserContext(this.canvasContext.canvas, {
|
|
5141
5001
|
...props,
|
|
5142
5002
|
onContextLost: (event) => {
|
|
5143
5003
|
var _a2;
|
|
@@ -5147,16 +5007,13 @@ var _WebGLDevice = class extends import_core27.Device {
|
|
|
5147
5007
|
});
|
|
5148
5008
|
}
|
|
5149
5009
|
});
|
|
5150
|
-
|
|
5010
|
+
this.gl = this.handle;
|
|
5011
|
+
if (!this.handle) {
|
|
5151
5012
|
throw new Error("WebGL context creation failed");
|
|
5152
5013
|
}
|
|
5153
|
-
this.
|
|
5154
|
-
this.gl = gl;
|
|
5014
|
+
this.spectorJS = initializeSpectorJS({ ...this.props, gl: this.handle });
|
|
5155
5015
|
this.gl.device = this;
|
|
5156
5016
|
this.gl._version = 2;
|
|
5157
|
-
if (props.spector) {
|
|
5158
|
-
this.spectorJS = initializeSpectorJS({ ...this.props, canvas: this.handle.canvas });
|
|
5159
|
-
}
|
|
5160
5017
|
this.info = getDeviceInfo(this.gl, this._extensions);
|
|
5161
5018
|
this.limits = new WebGLDeviceLimits(this.gl);
|
|
5162
5019
|
this.features = new WebGLDeviceFeatures(this.gl, this._extensions, this.props.disabledFeatures);
|
|
@@ -5164,17 +5021,15 @@ var _WebGLDevice = class extends import_core27.Device {
|
|
|
5164
5021
|
this.features.initializeFeatures();
|
|
5165
5022
|
}
|
|
5166
5023
|
this.canvasContext.resize();
|
|
5167
|
-
const
|
|
5168
|
-
|
|
5169
|
-
enable: enable2,
|
|
5170
|
-
copyState,
|
|
5171
|
-
log: (...args) => import_core27.log.log(1, ...args)()
|
|
5024
|
+
const glState = new WebGLStateTracker(this.gl, {
|
|
5025
|
+
log: (...args) => import_core22.log.log(1, ...args)()
|
|
5172
5026
|
});
|
|
5027
|
+
glState.trackState(this.gl, { copyState: false });
|
|
5173
5028
|
if (props.debug) {
|
|
5174
5029
|
this.gl = makeDebugContext(this.gl, { ...props, throwOnError: true });
|
|
5175
5030
|
this.debug = true;
|
|
5176
|
-
|
|
5177
|
-
|
|
5031
|
+
import_core22.log.level = Math.max(import_core22.log.level, 1);
|
|
5032
|
+
import_core22.log.warn("WebGL debug mode activated. Performance reduced.")();
|
|
5178
5033
|
}
|
|
5179
5034
|
}
|
|
5180
5035
|
/**
|
|
@@ -5186,9 +5041,6 @@ var _WebGLDevice = class extends import_core27.Device {
|
|
|
5186
5041
|
get isLost() {
|
|
5187
5042
|
return this.gl.isContextLost();
|
|
5188
5043
|
}
|
|
5189
|
-
getSize() {
|
|
5190
|
-
return [this.gl.drawingBufferWidth, this.gl.drawingBufferHeight];
|
|
5191
|
-
}
|
|
5192
5044
|
isTextureFormatSupported(format) {
|
|
5193
5045
|
return isTextureFormatSupported(this.gl, format, this._extensions);
|
|
5194
5046
|
}
|
|
@@ -5206,6 +5058,7 @@ var _WebGLDevice = class extends import_core27.Device {
|
|
|
5206
5058
|
const newProps = this._getBufferProps(props);
|
|
5207
5059
|
return new WEBGLBuffer(this, newProps);
|
|
5208
5060
|
}
|
|
5061
|
+
// _createTexture(props: TextureProps): WEBGLTexture {
|
|
5209
5062
|
_createTexture(props) {
|
|
5210
5063
|
return new WEBGLTexture(this, props);
|
|
5211
5064
|
}
|
|
@@ -5243,7 +5096,7 @@ var _WebGLDevice = class extends import_core27.Device {
|
|
|
5243
5096
|
throw new Error("ComputePass not supported in WebGL");
|
|
5244
5097
|
}
|
|
5245
5098
|
renderPass = null;
|
|
5246
|
-
createCommandEncoder(props) {
|
|
5099
|
+
createCommandEncoder(props = {}) {
|
|
5247
5100
|
return new WEBGLCommandEncoder(this, props);
|
|
5248
5101
|
}
|
|
5249
5102
|
/**
|
|
@@ -5280,22 +5133,12 @@ var _WebGLDevice = class extends import_core27.Device {
|
|
|
5280
5133
|
clear(this, options);
|
|
5281
5134
|
}
|
|
5282
5135
|
resetWebGL() {
|
|
5283
|
-
|
|
5136
|
+
import_core22.log.warn("WebGLDevice.resetWebGL is deprecated, use only for debugging")();
|
|
5284
5137
|
resetGLParameters(this.gl);
|
|
5285
5138
|
}
|
|
5286
5139
|
//
|
|
5287
5140
|
// WebGL-only API (not part of `Device` API)
|
|
5288
5141
|
//
|
|
5289
|
-
/** WebGL2 context. */
|
|
5290
|
-
gl;
|
|
5291
|
-
debug = false;
|
|
5292
|
-
/** State used by luma.gl classes: TODO - move to canvasContext*/
|
|
5293
|
-
_canvasSizeInfo = { clientWidth: 0, clientHeight: 0, devicePixelRatio: 1 };
|
|
5294
|
-
/** State used by luma.gl classes - TODO - not used? */
|
|
5295
|
-
_extensions = {};
|
|
5296
|
-
_polyfilled = false;
|
|
5297
|
-
/** Instance of Spector.js (if initialized) */
|
|
5298
|
-
spectorJS;
|
|
5299
5142
|
/**
|
|
5300
5143
|
* Triggers device (or WebGL context) loss.
|
|
5301
5144
|
* @note primarily intended for testing how application reacts to device loss
|
|
@@ -5317,11 +5160,13 @@ var _WebGLDevice = class extends import_core27.Device {
|
|
|
5317
5160
|
}
|
|
5318
5161
|
/** Save current WebGL context state onto an internal stack */
|
|
5319
5162
|
pushState() {
|
|
5320
|
-
|
|
5163
|
+
const webglState = WebGLStateTracker.get(this.gl);
|
|
5164
|
+
webglState.push();
|
|
5321
5165
|
}
|
|
5322
5166
|
/** Restores previously saved context state */
|
|
5323
5167
|
popState() {
|
|
5324
|
-
|
|
5168
|
+
const webglState = WebGLStateTracker.get(this.gl);
|
|
5169
|
+
webglState.pop();
|
|
5325
5170
|
}
|
|
5326
5171
|
/**
|
|
5327
5172
|
* Storing data on a special field on WebGLObjects makes that data visible in SPECTOR chrome debug extension
|
|
@@ -5358,7 +5203,7 @@ var _WebGLDevice = class extends import_core27.Device {
|
|
|
5358
5203
|
this._constants = this._constants || new Array(maxVertexAttributes).fill(null);
|
|
5359
5204
|
const currentConstant = this._constants[location];
|
|
5360
5205
|
if (currentConstant && compareConstantArrayValues2(currentConstant, constant)) {
|
|
5361
|
-
|
|
5206
|
+
import_core22.log.info(1, `setConstantAttributeWebGL(${location}) could have been skipped, value unchanged`)();
|
|
5362
5207
|
}
|
|
5363
5208
|
this._constants[location] = constant;
|
|
5364
5209
|
switch (constant.constructor) {
|
|
@@ -5372,7 +5217,7 @@ var _WebGLDevice = class extends import_core27.Device {
|
|
|
5372
5217
|
setConstantUintArray(this, location, constant);
|
|
5373
5218
|
break;
|
|
5374
5219
|
default:
|
|
5375
|
-
|
|
5220
|
+
throw new Error("constant");
|
|
5376
5221
|
}
|
|
5377
5222
|
}
|
|
5378
5223
|
/** Ensure extensions are only requested once */
|
|
@@ -5381,18 +5226,6 @@ var _WebGLDevice = class extends import_core27.Device {
|
|
|
5381
5226
|
return this._extensions;
|
|
5382
5227
|
}
|
|
5383
5228
|
};
|
|
5384
|
-
var WebGLDevice = _WebGLDevice;
|
|
5385
|
-
//
|
|
5386
|
-
// Public `Device` API
|
|
5387
|
-
//
|
|
5388
|
-
/** type of this device */
|
|
5389
|
-
__publicField(WebGLDevice, "type", "webgl");
|
|
5390
|
-
function isWebGL(gl) {
|
|
5391
|
-
if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
|
|
5392
|
-
return true;
|
|
5393
|
-
}
|
|
5394
|
-
return Boolean(gl && Number.isFinite(gl._version));
|
|
5395
|
-
}
|
|
5396
5229
|
function setConstantFloatArray(device, location, array) {
|
|
5397
5230
|
switch (array.length) {
|
|
5398
5231
|
case 1:
|
|
@@ -5408,7 +5241,6 @@ function setConstantFloatArray(device, location, array) {
|
|
|
5408
5241
|
device.gl.vertexAttrib4fv(location, array);
|
|
5409
5242
|
break;
|
|
5410
5243
|
default:
|
|
5411
|
-
(0, import_core27.assert)(false);
|
|
5412
5244
|
}
|
|
5413
5245
|
}
|
|
5414
5246
|
function setConstantIntArray(device, location, array) {
|
|
@@ -5429,173 +5261,179 @@ function compareConstantArrayValues2(v1, v2) {
|
|
|
5429
5261
|
return true;
|
|
5430
5262
|
}
|
|
5431
5263
|
|
|
5432
|
-
// dist/
|
|
5433
|
-
var
|
|
5434
|
-
var
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
|
|
5264
|
+
// dist/context/polyfills/polyfill-webgl1-extensions.js
|
|
5265
|
+
var import_constants29 = require("@luma.gl/constants");
|
|
5266
|
+
var WEBGL1_STATIC_EXTENSIONS = {
|
|
5267
|
+
WEBGL_depth_texture: {
|
|
5268
|
+
UNSIGNED_INT_24_8_WEBGL: 34042
|
|
5269
|
+
},
|
|
5270
|
+
OES_element_index_uint: {},
|
|
5271
|
+
OES_texture_float: {},
|
|
5272
|
+
OES_texture_half_float: {
|
|
5273
|
+
// @ts-expect-error different numbers?
|
|
5274
|
+
HALF_FLOAT_OES: 5131
|
|
5275
|
+
},
|
|
5276
|
+
EXT_color_buffer_float: {},
|
|
5277
|
+
OES_standard_derivatives: {
|
|
5278
|
+
FRAGMENT_SHADER_DERIVATIVE_HINT_OES: 35723
|
|
5279
|
+
},
|
|
5280
|
+
EXT_frag_depth: {},
|
|
5281
|
+
EXT_blend_minmax: {
|
|
5282
|
+
MIN_EXT: 32775,
|
|
5283
|
+
MAX_EXT: 32776
|
|
5284
|
+
},
|
|
5285
|
+
EXT_shader_texture_lod: {}
|
|
5286
|
+
};
|
|
5287
|
+
var getWEBGL_draw_buffers = (gl) => ({
|
|
5288
|
+
drawBuffersWEBGL(buffers) {
|
|
5289
|
+
return gl.drawBuffers(buffers);
|
|
5290
|
+
},
|
|
5291
|
+
COLOR_ATTACHMENT0_WEBGL: 36064,
|
|
5292
|
+
COLOR_ATTACHMENT1_WEBGL: 36065,
|
|
5293
|
+
COLOR_ATTACHMENT2_WEBGL: 36066,
|
|
5294
|
+
COLOR_ATTACHMENT3_WEBGL: 36067
|
|
5295
|
+
});
|
|
5296
|
+
var getOES_vertex_array_object = (gl) => ({
|
|
5297
|
+
VERTEX_ARRAY_BINDING_OES: 34229,
|
|
5298
|
+
createVertexArrayOES() {
|
|
5299
|
+
return gl.createVertexArray();
|
|
5300
|
+
},
|
|
5301
|
+
deleteVertexArrayOES(vertexArray) {
|
|
5302
|
+
return gl.deleteVertexArray(vertexArray);
|
|
5303
|
+
},
|
|
5304
|
+
isVertexArrayOES(vertexArray) {
|
|
5305
|
+
return gl.isVertexArray(vertexArray);
|
|
5306
|
+
},
|
|
5307
|
+
bindVertexArrayOES(vertexArray) {
|
|
5308
|
+
return gl.bindVertexArray(vertexArray);
|
|
5456
5309
|
}
|
|
5457
|
-
|
|
5458
|
-
|
|
5310
|
+
});
|
|
5311
|
+
var getANGLE_instanced_arrays = (gl) => ({
|
|
5312
|
+
VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE: 35070,
|
|
5313
|
+
drawArraysInstancedANGLE(...args) {
|
|
5314
|
+
return gl.drawArraysInstanced(...args);
|
|
5315
|
+
},
|
|
5316
|
+
drawElementsInstancedANGLE(...args) {
|
|
5317
|
+
return gl.drawElementsInstanced(...args);
|
|
5318
|
+
},
|
|
5319
|
+
vertexAttribDivisorANGLE(...args) {
|
|
5320
|
+
return gl.vertexAttribDivisor(...args);
|
|
5459
5321
|
}
|
|
5460
|
-
|
|
5461
|
-
|
|
5322
|
+
});
|
|
5323
|
+
function enforceWebGL2(enforce = true) {
|
|
5324
|
+
const prototype = HTMLCanvasElement.prototype;
|
|
5325
|
+
if (!enforce && prototype.originalGetContext) {
|
|
5326
|
+
prototype.getContext = prototype.originalGetContext;
|
|
5327
|
+
prototype.originalGetContext = void 0;
|
|
5328
|
+
return;
|
|
5462
5329
|
}
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
if (
|
|
5466
|
-
this.
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
|
|
5330
|
+
prototype.originalGetContext = prototype.getContext;
|
|
5331
|
+
prototype.getContext = function(contextId, options) {
|
|
5332
|
+
if (contextId === "webgl" || contextId === "experimental-webgl") {
|
|
5333
|
+
const context = this.originalGetContext("webgl2", options);
|
|
5334
|
+
if (context instanceof HTMLElement) {
|
|
5335
|
+
polyfillWebGL1Extensions(context);
|
|
5336
|
+
}
|
|
5337
|
+
return context;
|
|
5471
5338
|
}
|
|
5472
|
-
return this;
|
|
5473
|
-
}
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5339
|
+
return this.originalGetContext(contextId, options);
|
|
5340
|
+
};
|
|
5341
|
+
}
|
|
5342
|
+
function polyfillWebGL1Extensions(gl) {
|
|
5343
|
+
gl.getExtension("EXT_color_buffer_float");
|
|
5344
|
+
const boundExtensions = {
|
|
5345
|
+
...WEBGL1_STATIC_EXTENSIONS,
|
|
5346
|
+
WEBGL_disjoint_timer_query: gl.getExtension("EXT_disjoint_timer_query_webgl2"),
|
|
5347
|
+
WEBGL_draw_buffers: getWEBGL_draw_buffers(gl),
|
|
5348
|
+
OES_vertex_array_object: getOES_vertex_array_object(gl),
|
|
5349
|
+
ANGLE_instanced_arrays: getANGLE_instanced_arrays(gl)
|
|
5350
|
+
};
|
|
5351
|
+
const originalGetExtension = gl.getExtension;
|
|
5352
|
+
gl.getExtension = function(extensionName) {
|
|
5353
|
+
const ext = originalGetExtension.call(gl, extensionName);
|
|
5354
|
+
if (ext) {
|
|
5355
|
+
return ext;
|
|
5478
5356
|
}
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
this._bindHandle(this.handle);
|
|
5482
|
-
this._bound = true;
|
|
5483
|
-
value = funcOrHandle();
|
|
5484
|
-
this._bound = false;
|
|
5485
|
-
this._bindHandle(null);
|
|
5486
|
-
} else {
|
|
5487
|
-
value = funcOrHandle();
|
|
5357
|
+
if (extensionName in boundExtensions) {
|
|
5358
|
+
return boundExtensions[extensionName];
|
|
5488
5359
|
}
|
|
5489
|
-
return
|
|
5490
|
-
}
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
}
|
|
5498
|
-
// PUBLIC VIRTUAL METHODS
|
|
5499
|
-
initialize(props) {
|
|
5500
|
-
}
|
|
5501
|
-
// PROTECTED METHODS - These must be overridden by subclass
|
|
5502
|
-
_createHandle() {
|
|
5503
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
5504
|
-
}
|
|
5505
|
-
_deleteHandle() {
|
|
5506
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
5507
|
-
}
|
|
5508
|
-
_bindHandle(handle) {
|
|
5509
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
5510
|
-
}
|
|
5511
|
-
_getOptsFromHandle() {
|
|
5512
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
5513
|
-
}
|
|
5514
|
-
_getParameter(pname, props) {
|
|
5515
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
5516
|
-
}
|
|
5517
|
-
_setParameter(pname, value) {
|
|
5518
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
5519
|
-
}
|
|
5520
|
-
};
|
|
5360
|
+
return null;
|
|
5361
|
+
};
|
|
5362
|
+
const originalGetSupportedExtensions = gl.getSupportedExtensions;
|
|
5363
|
+
gl.getSupportedExtensions = function() {
|
|
5364
|
+
const extensions = originalGetSupportedExtensions.apply(gl) || [];
|
|
5365
|
+
return extensions == null ? void 0 : extensions.concat(Object.keys(boundExtensions));
|
|
5366
|
+
};
|
|
5367
|
+
}
|
|
5521
5368
|
|
|
5522
|
-
// dist/adapter/
|
|
5523
|
-
var
|
|
5524
|
-
var
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
|
|
5531
|
-
}
|
|
5532
|
-
get height() {
|
|
5533
|
-
return this.props.height;
|
|
5534
|
-
}
|
|
5535
|
-
get format() {
|
|
5536
|
-
return this.props.format;
|
|
5537
|
-
}
|
|
5538
|
-
get samples() {
|
|
5539
|
-
return this.props.samples;
|
|
5369
|
+
// dist/adapter/webgl-adapter.js
|
|
5370
|
+
var LOG_LEVEL2 = 1;
|
|
5371
|
+
var WebGLAdapter = class extends import_core23.Adapter {
|
|
5372
|
+
/** type of device's created by this adapter */
|
|
5373
|
+
type = "webgl";
|
|
5374
|
+
constructor() {
|
|
5375
|
+
super();
|
|
5376
|
+
import_core23.Device.defaultProps = { ...import_core23.Device.defaultProps, ...DEFAULT_SPECTOR_PROPS };
|
|
5377
|
+
WebGLDevice.adapter = this;
|
|
5540
5378
|
}
|
|
5541
|
-
|
|
5542
|
-
|
|
5379
|
+
/** Check if WebGL 2 is available */
|
|
5380
|
+
isSupported() {
|
|
5381
|
+
return typeof WebGL2RenderingContext !== "undefined";
|
|
5543
5382
|
}
|
|
5544
|
-
/** WebGL
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
return isRenderbufferFormatSupported(device.gl, format, device._extensions);
|
|
5383
|
+
/** Force any created WebGL contexts to be WebGL2 contexts, polyfilled with WebGL1 extensions */
|
|
5384
|
+
enforceWebGL2(enable2) {
|
|
5385
|
+
enforceWebGL2(enable2);
|
|
5548
5386
|
}
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5387
|
+
/**
|
|
5388
|
+
* Get a device instance from a GL context
|
|
5389
|
+
* Creates and instruments the device if not already created
|
|
5390
|
+
* @param gl
|
|
5391
|
+
* @returns
|
|
5392
|
+
*/
|
|
5393
|
+
async attach(gl) {
|
|
5394
|
+
if (gl instanceof WebGLDevice) {
|
|
5395
|
+
return gl;
|
|
5552
5396
|
}
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
this._initialize(this.props);
|
|
5556
|
-
}
|
|
5557
|
-
resize(size) {
|
|
5558
|
-
if (size.width !== this.width || size.height !== this.height) {
|
|
5559
|
-
Object.assign(this.props, { ...size, format: this.format, samples: this.samples });
|
|
5560
|
-
this._initialize(this.props);
|
|
5397
|
+
if ((gl == null ? void 0 : gl.device) instanceof import_core23.Device) {
|
|
5398
|
+
return gl.device;
|
|
5561
5399
|
}
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
/** Creates and initializes a renderbuffer object's data store */
|
|
5565
|
-
_initialize(props) {
|
|
5566
|
-
const { format, width, height, samples } = props;
|
|
5567
|
-
(0, import_core29.assert)(format, "Needs format");
|
|
5568
|
-
this.trackDeallocatedMemory();
|
|
5569
|
-
this.gl.bindRenderbuffer(36161, this.handle);
|
|
5570
|
-
if (samples !== 0) {
|
|
5571
|
-
this.gl.renderbufferStorageMultisample(36161, samples, this.glFormat, width, height);
|
|
5572
|
-
} else {
|
|
5573
|
-
this.gl.renderbufferStorage(36161, this.glFormat, width, height);
|
|
5400
|
+
if (!isWebGL(gl)) {
|
|
5401
|
+
throw new Error("Invalid WebGL2RenderingContext");
|
|
5574
5402
|
}
|
|
5575
|
-
|
|
5576
|
-
this.trackAllocatedMemory(width * height * (samples || 1) * getTextureFormatBytesPerPixel(this.format));
|
|
5577
|
-
}
|
|
5578
|
-
// RESOURCE IMPLEMENTATION
|
|
5579
|
-
_createHandle() {
|
|
5580
|
-
return this.gl.createRenderbuffer();
|
|
5403
|
+
return new WebGLDevice({ gl });
|
|
5581
5404
|
}
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5405
|
+
async create(props = {}) {
|
|
5406
|
+
import_core23.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
|
|
5407
|
+
const promises = [];
|
|
5408
|
+
if (props.debug) {
|
|
5409
|
+
promises.push(loadWebGLDeveloperTools());
|
|
5410
|
+
}
|
|
5411
|
+
if (props.debugWithSpectorJS) {
|
|
5412
|
+
promises.push(loadSpectorJS(props));
|
|
5413
|
+
}
|
|
5414
|
+
if (typeof props.canvas === "string") {
|
|
5415
|
+
promises.push(import_core23.CanvasContext.pageLoaded);
|
|
5416
|
+
}
|
|
5417
|
+
const results = await Promise.allSettled(promises);
|
|
5418
|
+
for (const result of results) {
|
|
5419
|
+
if (result.status === "rejected") {
|
|
5420
|
+
import_core23.log.error(`Failed to initialize debug libraries ${result.reason}`)();
|
|
5421
|
+
}
|
|
5422
|
+
}
|
|
5423
|
+
import_core23.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
|
|
5424
|
+
const device = new WebGLDevice(props);
|
|
5425
|
+
const message2 = `Created ${device.type}${device.debug ? " debug" : ""} context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
|
|
5426
|
+
import_core23.log.probe(LOG_LEVEL2, message2)();
|
|
5427
|
+
import_core23.log.table(LOG_LEVEL2, device.info)();
|
|
5428
|
+
import_core23.log.groupEnd(LOG_LEVEL2)();
|
|
5429
|
+
return device;
|
|
5588
5430
|
}
|
|
5589
5431
|
};
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
width: 1,
|
|
5598
|
-
height: 1,
|
|
5599
|
-
samples: 0
|
|
5600
|
-
});
|
|
5432
|
+
function isWebGL(gl) {
|
|
5433
|
+
if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
|
|
5434
|
+
return true;
|
|
5435
|
+
}
|
|
5436
|
+
return Boolean(gl && Number.isFinite(gl._version));
|
|
5437
|
+
}
|
|
5438
|
+
var webgl2Adapter = new WebGLAdapter();
|
|
5601
5439
|
//# sourceMappingURL=index.cjs.map
|