@luma.gl/webgl 9.1.0-alpha.15 → 9.1.0-alpha.16
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 +3 -3
- package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.d.ts +24 -22
- package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.js +6 -224
- package/dist/adapter/resources/webgl-command-buffer.js +15 -15
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +24 -11
- package/dist/adapter/resources/webgl-shader.d.ts +1 -0
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +6 -4
- package/dist/adapter/webgl-adapter.d.ts.map +1 -1
- package/dist/adapter/webgl-adapter.js +4 -10
- package/dist/adapter/webgl-device.d.ts +1 -2
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +33 -14
- package/dist/context/debug/spector-types.js +1 -1
- package/dist/context/debug/spector.d.ts +5 -5
- package/dist/context/debug/spector.d.ts.map +1 -1
- package/dist/context/debug/spector.js +6 -6
- package/dist/context/debug/webgl-developer-tools.d.ts +1 -3
- package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +4 -19
- package/dist/context/helpers/create-browser-context.d.ts +6 -22
- package/dist/context/helpers/create-browser-context.d.ts.map +1 -1
- package/dist/context/helpers/create-browser-context.js +26 -32
- package/dist/dist.dev.js +147 -135
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +129 -123
- package/dist/index.cjs.map +3 -3
- package/package.json +3 -3
- package/src/adapter/converters/device-parameters.ts +3 -3
- package/src/adapter/helpers/webgl-texture-utils.ts +33 -30
- package/src/adapter/resources/webgl-command-buffer.ts +16 -16
- package/src/adapter/resources/webgl-render-pipeline.ts +26 -11
- package/src/adapter/resources/webgl-shader.ts +7 -5
- package/src/adapter/webgl-adapter.ts +4 -12
- package/src/adapter/webgl-device.ts +67 -40
- package/src/context/debug/spector-types.ts +1 -1
- package/src/context/debug/spector.ts +11 -11
- package/src/context/debug/webgl-developer-tools.ts +5 -31
- package/src/context/helpers/create-browser-context.ts +39 -64
package/dist/index.cjs
CHANGED
|
@@ -2,9 +2,9 @@ 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 __export = (
|
|
5
|
+
var __export = (target2, all) => {
|
|
6
6
|
for (var name in all)
|
|
7
|
-
__defProp(
|
|
7
|
+
__defProp(target2, name, { get: all[name], enumerable: true });
|
|
8
8
|
};
|
|
9
9
|
var __copyProps = (to, from, except, desc) => {
|
|
10
10
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -137,8 +137,8 @@ var enable = (gl, value, key) => value ? gl.enable(key) : gl.disable(key);
|
|
|
137
137
|
var hint = (gl, value, key) => gl.hint(key, value);
|
|
138
138
|
var pixelStorei = (gl, value, key) => gl.pixelStorei(key, value);
|
|
139
139
|
var bindFramebuffer = (gl, value, key) => {
|
|
140
|
-
const
|
|
141
|
-
return gl.bindFramebuffer(
|
|
140
|
+
const target2 = key === 36006 ? 36009 : 36008;
|
|
141
|
+
return gl.bindFramebuffer(target2, value);
|
|
142
142
|
};
|
|
143
143
|
var bindBuffer = (gl, value, key) => {
|
|
144
144
|
const bindingMap = {
|
|
@@ -340,17 +340,17 @@ var GL_HOOKED_SETTERS = {
|
|
|
340
340
|
useProgram: (update, value) => update({
|
|
341
341
|
[35725]: value
|
|
342
342
|
}),
|
|
343
|
-
bindRenderbuffer: (update,
|
|
343
|
+
bindRenderbuffer: (update, target2, value) => update({
|
|
344
344
|
[36007]: value
|
|
345
345
|
}),
|
|
346
|
-
bindTransformFeedback: (update,
|
|
346
|
+
bindTransformFeedback: (update, target2, value) => update({
|
|
347
347
|
[36389]: value
|
|
348
348
|
}),
|
|
349
349
|
bindVertexArray: (update, value) => update({
|
|
350
350
|
[34229]: value
|
|
351
351
|
}),
|
|
352
|
-
bindFramebuffer: (update,
|
|
353
|
-
switch (
|
|
352
|
+
bindFramebuffer: (update, target2, framebuffer) => {
|
|
353
|
+
switch (target2) {
|
|
354
354
|
case 36160:
|
|
355
355
|
return update({
|
|
356
356
|
[36006]: framebuffer,
|
|
@@ -364,14 +364,14 @@ var GL_HOOKED_SETTERS = {
|
|
|
364
364
|
return null;
|
|
365
365
|
}
|
|
366
366
|
},
|
|
367
|
-
bindBuffer: (update,
|
|
367
|
+
bindBuffer: (update, target2, buffer) => {
|
|
368
368
|
const pname = {
|
|
369
369
|
[34962]: [34964],
|
|
370
370
|
[36662]: [36662],
|
|
371
371
|
[36663]: [36663],
|
|
372
372
|
[35051]: [35053],
|
|
373
373
|
[35052]: [35055]
|
|
374
|
-
}[
|
|
374
|
+
}[target2];
|
|
375
375
|
if (pname) {
|
|
376
376
|
return update({ [pname]: buffer });
|
|
377
377
|
}
|
|
@@ -719,33 +719,27 @@ function installProgramSpy(gl) {
|
|
|
719
719
|
}
|
|
720
720
|
|
|
721
721
|
// dist/context/helpers/create-browser-context.js
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
};
|
|
730
|
-
function createBrowserContext(canvas, props) {
|
|
731
|
-
props = { ...DEFAULT_CONTEXT_PROPS, ...props };
|
|
732
|
-
let errorMessage = null;
|
|
733
|
-
const onCreateError = (error) => errorMessage = error.statusMessage || errorMessage;
|
|
734
|
-
canvas.addEventListener("webglcontextcreationerror", onCreateError, false);
|
|
722
|
+
function createBrowserContext(canvas, props, webglContextAttributes) {
|
|
723
|
+
const errorMessage = null;
|
|
724
|
+
const webglProps = {
|
|
725
|
+
preserveDrawingBuffer: true,
|
|
726
|
+
// failIfMajorPerformanceCaveat: true,
|
|
727
|
+
...webglContextAttributes
|
|
728
|
+
};
|
|
735
729
|
let gl = null;
|
|
736
|
-
gl ||= canvas.getContext("webgl2",
|
|
737
|
-
|
|
730
|
+
gl ||= canvas.getContext("webgl2", webglProps);
|
|
731
|
+
if (!gl && !webglContextAttributes.failIfMajorPerformanceCaveat) {
|
|
732
|
+
webglProps.failIfMajorPerformanceCaveat = false;
|
|
733
|
+
gl = canvas.getContext("webgl", webglProps);
|
|
734
|
+
gl.luma ||= {};
|
|
735
|
+
gl.luma.softwareRenderer = true;
|
|
736
|
+
}
|
|
738
737
|
if (!gl) {
|
|
739
738
|
throw new Error(`Failed to create WebGL context: ${errorMessage || "Unknown error"}`);
|
|
740
739
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
}
|
|
745
|
-
if (props.onContextRestored) {
|
|
746
|
-
const { onContextRestored } = props;
|
|
747
|
-
canvas.addEventListener("webglcontextrestored", (event) => onContextRestored(event), false);
|
|
748
|
-
}
|
|
740
|
+
const { onContextLost, onContextRestored } = props;
|
|
741
|
+
canvas.addEventListener("webglcontextlost", (event) => onContextLost(event), false);
|
|
742
|
+
canvas.addEventListener("webglcontextrestored", (event) => onContextRestored(event), false);
|
|
749
743
|
return gl;
|
|
750
744
|
}
|
|
751
745
|
|
|
@@ -1601,17 +1595,17 @@ var LOG_LEVEL = 1;
|
|
|
1601
1595
|
var spector = null;
|
|
1602
1596
|
var initialized = false;
|
|
1603
1597
|
var DEFAULT_SPECTOR_PROPS = {
|
|
1604
|
-
|
|
1598
|
+
debugSpectorJS: import_core6.log.get("debug-spectorjs"),
|
|
1605
1599
|
// https://github.com/BabylonJS/Spector.js#basic-usage
|
|
1606
1600
|
// https://forum.babylonjs.com/t/spectorcdn-is-temporarily-off/48241
|
|
1607
1601
|
// spectorUrl: 'https://spectorcdn.babylonjs.com/spector.bundle.js';
|
|
1608
|
-
|
|
1602
|
+
debugSpectorJSUrl: "https://cdn.jsdelivr.net/npm/spectorjs@0.9.30/dist/spector.bundle.js",
|
|
1609
1603
|
gl: void 0
|
|
1610
1604
|
};
|
|
1611
1605
|
async function loadSpectorJS(props) {
|
|
1612
1606
|
if (!globalThis.SPECTOR) {
|
|
1613
1607
|
try {
|
|
1614
|
-
await loadScript(props.
|
|
1608
|
+
await loadScript(props.debugSpectorJSUrl || DEFAULT_SPECTOR_PROPS.debugSpectorJSUrl);
|
|
1615
1609
|
} catch (error) {
|
|
1616
1610
|
import_core6.log.warn(String(error));
|
|
1617
1611
|
}
|
|
@@ -1620,13 +1614,13 @@ async function loadSpectorJS(props) {
|
|
|
1620
1614
|
function initializeSpectorJS(props) {
|
|
1621
1615
|
var _a;
|
|
1622
1616
|
props = { ...DEFAULT_SPECTOR_PROPS, ...props };
|
|
1623
|
-
if (!props.
|
|
1617
|
+
if (!props.debugSpectorJS) {
|
|
1624
1618
|
return null;
|
|
1625
1619
|
}
|
|
1626
1620
|
if (!spector && globalThis.SPECTOR && !((_a = globalThis.luma) == null ? void 0 : _a.spector)) {
|
|
1627
1621
|
import_core6.log.probe(LOG_LEVEL, "SPECTOR found and initialized. Start with `luma.spector.displayUI()`")();
|
|
1628
|
-
const { Spector } = globalThis.SPECTOR;
|
|
1629
|
-
spector = new
|
|
1622
|
+
const { Spector: SpectorJS } = globalThis.SPECTOR;
|
|
1623
|
+
spector = new SpectorJS();
|
|
1630
1624
|
if (globalThis.luma) {
|
|
1631
1625
|
globalThis.luma.spector = spector;
|
|
1632
1626
|
}
|
|
@@ -1675,7 +1669,7 @@ async function loadWebGLDeveloperTools() {
|
|
|
1675
1669
|
}
|
|
1676
1670
|
}
|
|
1677
1671
|
function makeDebugContext(gl, props = {}) {
|
|
1678
|
-
return props.
|
|
1672
|
+
return props.debugWebGL ? getDebugContext(gl, props) : getRealContext(gl);
|
|
1679
1673
|
}
|
|
1680
1674
|
function getRealContext(gl) {
|
|
1681
1675
|
const data = getWebGLContextData(gl);
|
|
@@ -1720,9 +1714,6 @@ function onGLError(props, err, functionName, args) {
|
|
|
1720
1714
|
const message2 = `${errorMessage} in gl.${functionName}(${functionArgs})`;
|
|
1721
1715
|
import_core7.log.error(message2)();
|
|
1722
1716
|
debugger;
|
|
1723
|
-
if (props.throwOnError) {
|
|
1724
|
-
throw new Error(message2);
|
|
1725
|
-
}
|
|
1726
1717
|
}
|
|
1727
1718
|
function onValidateGLFunc(props, functionName, functionArgs) {
|
|
1728
1719
|
let functionString = "";
|
|
@@ -1730,22 +1721,10 @@ function onValidateGLFunc(props, functionName, functionArgs) {
|
|
|
1730
1721
|
functionString = getFunctionString(functionName, functionArgs);
|
|
1731
1722
|
import_core7.log.log(1, functionString)();
|
|
1732
1723
|
}
|
|
1733
|
-
if (props.break && props.break.length > 0) {
|
|
1734
|
-
functionString = functionString || getFunctionString(functionName, functionArgs);
|
|
1735
|
-
const isBreakpoint = props.break.every((breakOn) => functionString.indexOf(breakOn) !== -1);
|
|
1736
|
-
if (isBreakpoint) {
|
|
1737
|
-
debugger;
|
|
1738
|
-
}
|
|
1739
|
-
}
|
|
1740
1724
|
for (const arg of functionArgs) {
|
|
1741
1725
|
if (arg === void 0) {
|
|
1742
1726
|
functionString = functionString || getFunctionString(functionName, functionArgs);
|
|
1743
|
-
|
|
1744
|
-
throw new Error(`Undefined argument: ${functionString}`);
|
|
1745
|
-
} else {
|
|
1746
|
-
import_core7.log.error(`Undefined argument: ${functionString}`)();
|
|
1747
|
-
debugger;
|
|
1748
|
-
}
|
|
1727
|
+
debugger;
|
|
1749
1728
|
}
|
|
1750
1729
|
}
|
|
1751
1730
|
}
|
|
@@ -1957,13 +1936,16 @@ var WEBGLShader = class extends import_core9.Shader {
|
|
|
1957
1936
|
this.destroyed = true;
|
|
1958
1937
|
}
|
|
1959
1938
|
}
|
|
1939
|
+
get asyncCompilationStatus() {
|
|
1940
|
+
return this._waitForCompilationComplete().then(() => this.compilationStatus);
|
|
1941
|
+
}
|
|
1960
1942
|
async getCompilationInfo() {
|
|
1961
1943
|
await this._waitForCompilationComplete();
|
|
1962
1944
|
return this.getCompilationInfoSync();
|
|
1963
1945
|
}
|
|
1964
1946
|
getCompilationInfoSync() {
|
|
1965
|
-
const
|
|
1966
|
-
return
|
|
1947
|
+
const shaderLog = this.device.gl.getShaderInfoLog(this.handle);
|
|
1948
|
+
return shaderLog ? parseShaderCompilerLog(shaderLog) : [];
|
|
1967
1949
|
}
|
|
1968
1950
|
getTranslatedSource() {
|
|
1969
1951
|
const extensions = this.device.getExtension("WEBGL_debug_shaders");
|
|
@@ -1973,9 +1955,8 @@ var WEBGLShader = class extends import_core9.Shader {
|
|
|
1973
1955
|
// PRIVATE METHODS
|
|
1974
1956
|
/** Compile a shader and get compilation status */
|
|
1975
1957
|
async _compile(source) {
|
|
1976
|
-
|
|
1977
|
-
${
|
|
1978
|
-
source = addGLSLVersion(source);
|
|
1958
|
+
source = source.startsWith("#version ") ? source : `#version 300 es
|
|
1959
|
+
${source}`;
|
|
1979
1960
|
const { gl } = this.device;
|
|
1980
1961
|
gl.shaderSource(this.handle, source);
|
|
1981
1962
|
gl.compileShader(this.handle);
|
|
@@ -2606,7 +2587,7 @@ function readPixelsToArray(source, options) {
|
|
|
2606
2587
|
// TODO - support gl.readBuffer
|
|
2607
2588
|
} = options || {};
|
|
2608
2589
|
let {
|
|
2609
|
-
target = null,
|
|
2590
|
+
target: target2 = null,
|
|
2610
2591
|
// following parameters are auto deduced if not provided
|
|
2611
2592
|
sourceWidth,
|
|
2612
2593
|
sourceHeight,
|
|
@@ -2622,25 +2603,25 @@ function readPixelsToArray(source, options) {
|
|
|
2622
2603
|
sourceDepth = ((_b = (_a = framebuffer.colorAttachments[attachment]) == null ? void 0 : _a.texture) == null ? void 0 : _b.depth) || 1;
|
|
2623
2604
|
sourceFormat ||= ((_d = (_c = framebuffer.colorAttachments[attachment]) == null ? void 0 : _c.texture) == null ? void 0 : _d.glFormat) || 6408;
|
|
2624
2605
|
sourceType ||= ((_f = (_e = framebuffer.colorAttachments[attachment]) == null ? void 0 : _e.texture) == null ? void 0 : _f.glType) || 5121;
|
|
2625
|
-
|
|
2626
|
-
sourceType = sourceType || getGLTypeFromTypedArray(
|
|
2606
|
+
target2 = getPixelArray(target2, sourceType, sourceFormat, sourceWidth, sourceHeight, sourceDepth);
|
|
2607
|
+
sourceType = sourceType || getGLTypeFromTypedArray(target2);
|
|
2627
2608
|
const prevHandle = gl.bindFramebuffer(36160, handle);
|
|
2628
|
-
gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType,
|
|
2609
|
+
gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target2);
|
|
2629
2610
|
gl.bindFramebuffer(36160, prevHandle || null);
|
|
2630
2611
|
if (deleteFramebuffer) {
|
|
2631
2612
|
framebuffer.destroy();
|
|
2632
2613
|
}
|
|
2633
|
-
return
|
|
2614
|
+
return target2;
|
|
2634
2615
|
}
|
|
2635
2616
|
function readPixelsToBuffer(source, options) {
|
|
2636
|
-
const { target, sourceX = 0, sourceY = 0, sourceFormat = 6408, targetByteOffset = 0 } = options || {};
|
|
2617
|
+
const { target: target2, sourceX = 0, sourceY = 0, sourceFormat = 6408, targetByteOffset = 0 } = options || {};
|
|
2637
2618
|
let { sourceWidth, sourceHeight, sourceType } = options || {};
|
|
2638
2619
|
const { framebuffer, deleteFramebuffer } = getFramebuffer(source);
|
|
2639
2620
|
sourceWidth = sourceWidth || framebuffer.width;
|
|
2640
2621
|
sourceHeight = sourceHeight || framebuffer.height;
|
|
2641
2622
|
const webglFramebuffer = framebuffer;
|
|
2642
2623
|
sourceType = sourceType || 5121;
|
|
2643
|
-
let webglBufferTarget =
|
|
2624
|
+
let webglBufferTarget = target2;
|
|
2644
2625
|
if (!webglBufferTarget) {
|
|
2645
2626
|
const components = glFormatToComponents(sourceFormat);
|
|
2646
2627
|
const byteCount = glTypeToBytes(sourceType);
|
|
@@ -2649,11 +2630,11 @@ function readPixelsToBuffer(source, options) {
|
|
|
2649
2630
|
}
|
|
2650
2631
|
const commandEncoder = source.device.createCommandEncoder();
|
|
2651
2632
|
commandEncoder.copyTextureToBuffer({
|
|
2652
|
-
source,
|
|
2633
|
+
sourceTexture: source,
|
|
2653
2634
|
width: sourceWidth,
|
|
2654
2635
|
height: sourceHeight,
|
|
2655
2636
|
origin: [sourceX, sourceY],
|
|
2656
|
-
|
|
2637
|
+
destinationBuffer: webglBufferTarget,
|
|
2657
2638
|
byteOffset: targetByteOffset
|
|
2658
2639
|
});
|
|
2659
2640
|
commandEncoder.destroy();
|
|
@@ -3781,9 +3762,9 @@ var WEBGLRenderPipeline = class extends import_core16.RenderPipeline {
|
|
|
3781
3762
|
*/
|
|
3782
3763
|
setBindings(bindings, options) {
|
|
3783
3764
|
for (const [name, value] of Object.entries(bindings)) {
|
|
3784
|
-
const binding = this.shaderLayout.bindings.find((
|
|
3765
|
+
const binding = this.shaderLayout.bindings.find((binding_) => binding_.name === name) || this.shaderLayout.bindings.find((binding_) => binding_.name === `${name}Uniforms`);
|
|
3785
3766
|
if (!binding) {
|
|
3786
|
-
const validBindings = this.shaderLayout.bindings.map((
|
|
3767
|
+
const validBindings = this.shaderLayout.bindings.map((binding_) => `"${binding_.name}"`).join(", ");
|
|
3787
3768
|
if (!(options == null ? void 0 : options.disableWarnings)) {
|
|
3788
3769
|
import_core16.log.warn(`No binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`, value)();
|
|
3789
3770
|
}
|
|
@@ -3908,21 +3889,34 @@ var WEBGLRenderPipeline = class extends import_core16.RenderPipeline {
|
|
|
3908
3889
|
this._reportLinkStatus(status);
|
|
3909
3890
|
}
|
|
3910
3891
|
/** Report link status. First, check for shader compilation failures if linking fails */
|
|
3911
|
-
_reportLinkStatus(status) {
|
|
3892
|
+
async _reportLinkStatus(status) {
|
|
3912
3893
|
var _a;
|
|
3913
3894
|
switch (status) {
|
|
3914
3895
|
case "success":
|
|
3915
3896
|
return;
|
|
3916
3897
|
default:
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3898
|
+
switch (this.vs.compilationStatus) {
|
|
3899
|
+
case "error":
|
|
3900
|
+
this.vs.debugShader();
|
|
3901
|
+
throw new Error(`Error during compilation of shader ${this.vs.id}`);
|
|
3902
|
+
case "pending":
|
|
3903
|
+
this.vs.asyncCompilationStatus.then(() => this.vs.debugShader());
|
|
3904
|
+
break;
|
|
3905
|
+
case "success":
|
|
3906
|
+
break;
|
|
3920
3907
|
}
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3908
|
+
switch ((_a = this.fs) == null ? void 0 : _a.compilationStatus) {
|
|
3909
|
+
case "error":
|
|
3910
|
+
this.fs.debugShader();
|
|
3911
|
+
throw new Error(`Error during compilation of shader ${this.fs.id}`);
|
|
3912
|
+
case "pending":
|
|
3913
|
+
this.fs.asyncCompilationStatus.then(() => this.fs.debugShader());
|
|
3914
|
+
break;
|
|
3915
|
+
case "success":
|
|
3916
|
+
break;
|
|
3924
3917
|
}
|
|
3925
|
-
|
|
3918
|
+
const linkErrorLog = this.device.gl.getProgramInfoLog(this.handle);
|
|
3919
|
+
throw new Error(`Error during ${status}: ${linkErrorLog}`);
|
|
3926
3920
|
}
|
|
3927
3921
|
}
|
|
3928
3922
|
/**
|
|
@@ -4112,8 +4106,8 @@ var WEBGLCommandBuffer = class extends import_core17.CommandBuffer {
|
|
|
4112
4106
|
}
|
|
4113
4107
|
};
|
|
4114
4108
|
function _copyBufferToBuffer(device, options) {
|
|
4115
|
-
const source = options.
|
|
4116
|
-
const destination = options.
|
|
4109
|
+
const source = options.sourceBuffer;
|
|
4110
|
+
const destination = options.destinationBuffer;
|
|
4117
4111
|
device.gl.bindBuffer(36662, source.handle);
|
|
4118
4112
|
device.gl.bindBuffer(36663, destination.handle);
|
|
4119
4113
|
device.gl.copyBufferSubData(36662, 36663, options.sourceOffset ?? 0, options.destinationOffset ?? 0, options.size);
|
|
@@ -4126,20 +4120,20 @@ function _copyBufferToTexture(device, options) {
|
|
|
4126
4120
|
function _copyTextureToBuffer(device, options) {
|
|
4127
4121
|
const {
|
|
4128
4122
|
/** Texture to copy to/from. */
|
|
4129
|
-
|
|
4123
|
+
sourceTexture,
|
|
4130
4124
|
/** Mip-map level of the texture to copy to/from. (Default 0) */
|
|
4131
4125
|
mipLevel = 0,
|
|
4132
4126
|
/** Defines which aspects of the texture to copy to/from. */
|
|
4133
4127
|
aspect = "all",
|
|
4134
4128
|
/** Width to copy */
|
|
4135
|
-
width = options.
|
|
4129
|
+
width = options.sourceTexture.width,
|
|
4136
4130
|
/** Height to copy */
|
|
4137
|
-
height = options.
|
|
4131
|
+
height = options.sourceTexture.height,
|
|
4138
4132
|
depthOrArrayLayers = 0,
|
|
4139
4133
|
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
|
|
4140
4134
|
origin = [0, 0],
|
|
4141
4135
|
/** Destination buffer */
|
|
4142
|
-
|
|
4136
|
+
destinationBuffer,
|
|
4143
4137
|
/** Offset, in bytes, from the beginning of the buffer to the start of the image data (default 0) */
|
|
4144
4138
|
byteOffset = 0,
|
|
4145
4139
|
/**
|
|
@@ -4155,15 +4149,15 @@ function _copyTextureToBuffer(device, options) {
|
|
|
4155
4149
|
rowsPerImage
|
|
4156
4150
|
} = options;
|
|
4157
4151
|
if (aspect !== "all") {
|
|
4158
|
-
throw new Error("not supported");
|
|
4152
|
+
throw new Error("aspect not supported in WebGL");
|
|
4159
4153
|
}
|
|
4160
4154
|
if (mipLevel !== 0 || depthOrArrayLayers !== 0 || bytesPerRow || rowsPerImage) {
|
|
4161
4155
|
throw new Error("not implemented");
|
|
4162
4156
|
}
|
|
4163
|
-
const { framebuffer, destroyFramebuffer } = getFramebuffer2(
|
|
4157
|
+
const { framebuffer, destroyFramebuffer } = getFramebuffer2(sourceTexture);
|
|
4164
4158
|
let prevHandle;
|
|
4165
4159
|
try {
|
|
4166
|
-
const webglBuffer =
|
|
4160
|
+
const webglBuffer = destinationBuffer;
|
|
4167
4161
|
const sourceWidth = width || framebuffer.width;
|
|
4168
4162
|
const sourceHeight = height || framebuffer.height;
|
|
4169
4163
|
const sourceParams = getTextureFormatWebGL(framebuffer.colorAttachments[0].texture.props.format);
|
|
@@ -4185,7 +4179,7 @@ function _copyTextureToBuffer(device, options) {
|
|
|
4185
4179
|
function _copyTextureToTexture(device, options) {
|
|
4186
4180
|
const {
|
|
4187
4181
|
/** Texture to copy to/from. */
|
|
4188
|
-
|
|
4182
|
+
sourceTexture,
|
|
4189
4183
|
/** Mip-map level of the texture to copy to (Default 0) */
|
|
4190
4184
|
destinationMipLevel = 0,
|
|
4191
4185
|
/** Defines which aspects of the texture to copy to/from. */
|
|
@@ -4195,7 +4189,7 @@ function _copyTextureToTexture(device, options) {
|
|
|
4195
4189
|
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to. */
|
|
4196
4190
|
destinationOrigin = [0, 0],
|
|
4197
4191
|
/** Texture to copy to/from. */
|
|
4198
|
-
|
|
4192
|
+
destinationTexture
|
|
4199
4193
|
/** Mip-map level of the texture to copy to/from. (Default 0) */
|
|
4200
4194
|
// destinationMipLevel = options.mipLevel,
|
|
4201
4195
|
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
|
|
@@ -4204,18 +4198,18 @@ function _copyTextureToTexture(device, options) {
|
|
|
4204
4198
|
// destinationAspect = options.aspect,
|
|
4205
4199
|
} = options;
|
|
4206
4200
|
let {
|
|
4207
|
-
width = options.
|
|
4208
|
-
height = options.
|
|
4201
|
+
width = options.destinationTexture.width,
|
|
4202
|
+
height = options.destinationTexture.height
|
|
4209
4203
|
// depthOrArrayLayers = 0
|
|
4210
4204
|
} = options;
|
|
4211
|
-
const { framebuffer, destroyFramebuffer } = getFramebuffer2(
|
|
4205
|
+
const { framebuffer, destroyFramebuffer } = getFramebuffer2(sourceTexture);
|
|
4212
4206
|
const [sourceX, sourceY] = origin;
|
|
4213
4207
|
const [destinationX, destinationY, destinationZ] = destinationOrigin;
|
|
4214
4208
|
const prevHandle = device.gl.bindFramebuffer(36160, framebuffer.handle);
|
|
4215
4209
|
let texture = null;
|
|
4216
4210
|
let textureTarget;
|
|
4217
|
-
if (
|
|
4218
|
-
texture =
|
|
4211
|
+
if (destinationTexture instanceof WEBGLTexture) {
|
|
4212
|
+
texture = destinationTexture;
|
|
4219
4213
|
width = Number.isFinite(width) ? width : texture.width;
|
|
4220
4214
|
height = Number.isFinite(height) ? height : texture.height;
|
|
4221
4215
|
texture.bind(0);
|
|
@@ -4302,19 +4296,19 @@ var import_env2 = require("@probe.gl/env");
|
|
|
4302
4296
|
|
|
4303
4297
|
// dist/utils/fill-array.js
|
|
4304
4298
|
function fillArray(options) {
|
|
4305
|
-
const { target, source, start = 0, count = 1 } = options;
|
|
4299
|
+
const { target: target2, source, start = 0, count = 1 } = options;
|
|
4306
4300
|
const length = source.length;
|
|
4307
4301
|
const total = count * length;
|
|
4308
4302
|
let copied = 0;
|
|
4309
4303
|
for (let i = start; copied < length; copied++) {
|
|
4310
|
-
|
|
4304
|
+
target2[i++] = source[copied];
|
|
4311
4305
|
}
|
|
4312
4306
|
while (copied < total) {
|
|
4313
4307
|
if (copied < total - copied) {
|
|
4314
|
-
|
|
4308
|
+
target2.copyWithin(start + copied, start, start + copied);
|
|
4315
4309
|
copied *= 2;
|
|
4316
4310
|
} else {
|
|
4317
|
-
|
|
4311
|
+
target2.copyWithin(start + copied, start, start + total - copied);
|
|
4318
4312
|
copied = total;
|
|
4319
4313
|
}
|
|
4320
4314
|
}
|
|
@@ -4730,11 +4724,11 @@ var WEBGLQuerySet = class extends import_core21.QuerySet {
|
|
|
4730
4724
|
* outstanding queries representing disjoint `begin()`/`end()` intervals.
|
|
4731
4725
|
* It is not possible to interleave or overlap `begin` and `end` calls.
|
|
4732
4726
|
*/
|
|
4733
|
-
_begin(
|
|
4727
|
+
_begin(target2) {
|
|
4734
4728
|
if (this._queryPending) {
|
|
4735
4729
|
return;
|
|
4736
4730
|
}
|
|
4737
|
-
this.target =
|
|
4731
|
+
this.target = target2;
|
|
4738
4732
|
this.device.gl.beginQuery(this.target, this.handle);
|
|
4739
4733
|
return;
|
|
4740
4734
|
}
|
|
@@ -4865,36 +4859,52 @@ var WebGLDevice = class extends import_core23.Device {
|
|
|
4865
4859
|
constructor(props) {
|
|
4866
4860
|
var _a, _b;
|
|
4867
4861
|
super({ ...props, id: props.id || uid("webgl-device") });
|
|
4868
|
-
|
|
4862
|
+
if (!props.createCanvasContext) {
|
|
4863
|
+
throw new Error("WebGLDevice requires props.createCanvasContext to be set");
|
|
4864
|
+
}
|
|
4865
|
+
const canvasContextProps = props.createCanvasContext === true ? {} : props.createCanvasContext;
|
|
4866
|
+
let device = (_b = (_a = canvasContextProps.canvas) == null ? void 0 : _a.gl) == null ? void 0 : _b.device;
|
|
4869
4867
|
if (device) {
|
|
4870
4868
|
throw new Error(`WebGL context already attached to device ${device.id}`);
|
|
4871
4869
|
}
|
|
4872
|
-
|
|
4873
|
-
this.canvasContext = new WebGLCanvasContext(this, { ...props, canvas });
|
|
4870
|
+
this.canvasContext = new WebGLCanvasContext(this, canvasContextProps);
|
|
4874
4871
|
this.lost = new Promise((resolve) => {
|
|
4875
4872
|
this._resolveContextLost = resolve;
|
|
4876
4873
|
});
|
|
4877
|
-
|
|
4878
|
-
|
|
4874
|
+
const webglContextAttributes = { ...props.webgl };
|
|
4875
|
+
if (canvasContextProps.alphaMode === "premultiplied") {
|
|
4876
|
+
webglContextAttributes.premultipliedAlpha = true;
|
|
4877
|
+
}
|
|
4878
|
+
if (props.powerPreference !== void 0) {
|
|
4879
|
+
webglContextAttributes.powerPreference = props.powerPreference;
|
|
4880
|
+
}
|
|
4881
|
+
const gl = createBrowserContext(this.canvasContext.canvas, {
|
|
4879
4882
|
onContextLost: (event) => {
|
|
4880
4883
|
var _a2;
|
|
4881
4884
|
return (_a2 = this._resolveContextLost) == null ? void 0 : _a2.call(this, {
|
|
4882
4885
|
reason: "destroyed",
|
|
4883
4886
|
message: "Entered sleep mode, or too many apps or browser tabs are using the GPU."
|
|
4884
4887
|
});
|
|
4885
|
-
}
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4888
|
+
},
|
|
4889
|
+
// eslint-disable-next-line no-console
|
|
4890
|
+
onContextRestored: (event) => console.log("WebGL context restored")
|
|
4891
|
+
}, webglContextAttributes);
|
|
4892
|
+
if (!gl) {
|
|
4889
4893
|
throw new Error("WebGL context creation failed");
|
|
4890
4894
|
}
|
|
4895
|
+
device = gl.device;
|
|
4896
|
+
if (device) {
|
|
4897
|
+
throw new Error(`WebGL context already attached to device ${device.id}`);
|
|
4898
|
+
}
|
|
4899
|
+
this.handle = gl;
|
|
4900
|
+
this.gl = gl;
|
|
4891
4901
|
this.spectorJS = initializeSpectorJS({ ...this.props, gl: this.handle });
|
|
4892
4902
|
this.gl.device = this;
|
|
4893
4903
|
this.gl._version = 2;
|
|
4894
4904
|
this.info = getDeviceInfo(this.gl, this._extensions);
|
|
4895
4905
|
this.limits = new WebGLDeviceLimits(this.gl);
|
|
4896
|
-
this.features = new WebGLDeviceFeatures(this.gl, this._extensions, this.props.
|
|
4897
|
-
if (this.props.
|
|
4906
|
+
this.features = new WebGLDeviceFeatures(this.gl, this._extensions, this.props._disabledFeatures);
|
|
4907
|
+
if (this.props._initializeFeatures) {
|
|
4898
4908
|
this.features.initializeFeatures();
|
|
4899
4909
|
}
|
|
4900
4910
|
this.canvasContext.resize();
|
|
@@ -4902,8 +4912,8 @@ var WebGLDevice = class extends import_core23.Device {
|
|
|
4902
4912
|
log: (...args) => import_core23.log.log(1, ...args)()
|
|
4903
4913
|
});
|
|
4904
4914
|
glState.trackState(this.gl, { copyState: false });
|
|
4905
|
-
if (props.
|
|
4906
|
-
this.gl = makeDebugContext(this.gl, { ...props
|
|
4915
|
+
if (props.debugWebGL) {
|
|
4916
|
+
this.gl = makeDebugContext(this.gl, { ...props });
|
|
4907
4917
|
this.debug = true;
|
|
4908
4918
|
import_core23.log.level = Math.max(import_core23.log.level, 1);
|
|
4909
4919
|
import_core23.log.warn("WebGL debug mode activated. Performance reduced.")();
|
|
@@ -4932,7 +4942,7 @@ var WebGLDevice = class extends import_core23.Device {
|
|
|
4932
4942
|
throw new Error("WebGL only supports a single canvas");
|
|
4933
4943
|
}
|
|
4934
4944
|
createBuffer(props) {
|
|
4935
|
-
const newProps = this.
|
|
4945
|
+
const newProps = this._normalizeBufferProps(props);
|
|
4936
4946
|
return new WEBGLBuffer(this, newProps);
|
|
4937
4947
|
}
|
|
4938
4948
|
createTexture(props) {
|
|
@@ -5276,27 +5286,23 @@ var WebGLAdapter = class extends import_core24.Adapter {
|
|
|
5276
5286
|
if (!isWebGL(gl)) {
|
|
5277
5287
|
throw new Error("Invalid WebGL2RenderingContext");
|
|
5278
5288
|
}
|
|
5279
|
-
return new WebGLDevice({ gl });
|
|
5289
|
+
return new WebGLDevice({ _handle: gl });
|
|
5280
5290
|
}
|
|
5281
5291
|
async create(props = {}) {
|
|
5282
5292
|
import_core24.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
|
|
5283
5293
|
const promises = [];
|
|
5284
|
-
if (props.
|
|
5294
|
+
if (props.debugWebGL) {
|
|
5285
5295
|
promises.push(loadWebGLDeveloperTools());
|
|
5286
5296
|
}
|
|
5287
|
-
if (props.
|
|
5297
|
+
if (props.debugSpectorJS) {
|
|
5288
5298
|
promises.push(loadSpectorJS(props));
|
|
5289
5299
|
}
|
|
5290
|
-
if (typeof props.canvas === "string") {
|
|
5291
|
-
promises.push(import_core24.CanvasContext.pageLoaded);
|
|
5292
|
-
}
|
|
5293
5300
|
const results = await Promise.allSettled(promises);
|
|
5294
5301
|
for (const result of results) {
|
|
5295
5302
|
if (result.status === "rejected") {
|
|
5296
5303
|
import_core24.log.error(`Failed to initialize debug libraries ${result.reason}`)();
|
|
5297
5304
|
}
|
|
5298
5305
|
}
|
|
5299
|
-
import_core24.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
|
|
5300
5306
|
const device = new WebGLDevice(props);
|
|
5301
5307
|
const message2 = `Created ${device.type}${device.debug ? " debug" : ""} context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
|
|
5302
5308
|
import_core24.log.probe(LOG_LEVEL2, message2)();
|