@luma.gl/webgl 9.1.0-alpha.15 → 9.1.0-alpha.17
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/converters/sampler-parameters.js +6 -4
- package/dist/adapter/converters/texture-formats.d.ts +49 -11
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +150 -160
- package/dist/adapter/helpers/format-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/format-utils.js +6 -0
- package/dist/adapter/helpers/webgl-texture-utils.d.ts +34 -30
- package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.js +52 -256
- package/dist/adapter/resources/webgl-command-buffer.d.ts +59 -2
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +87 -31
- package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.js +3 -0
- package/dist/adapter/resources/webgl-external-texture.js +14 -0
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +1 -2
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +38 -20
- 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 +30 -16
- 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 +7 -5
- package/dist/adapter/resources/webgl-texture.d.ts +8 -14
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +119 -208
- 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 +8 -3
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +53 -22
- 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 +2 -3
- package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +6 -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 +40 -32
- package/dist/dist.dev.js +366 -400
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +341 -384
- package/dist/index.cjs.map +3 -3
- package/package.json +4 -4
- package/src/adapter/converters/device-parameters.ts +3 -3
- package/src/adapter/converters/sampler-parameters.ts +6 -4
- package/src/adapter/converters/texture-formats.ts +171 -177
- package/src/adapter/helpers/format-utils.ts +6 -0
- package/src/adapter/helpers/webgl-texture-utils.ts +99 -75
- package/src/adapter/resources/webgl-command-buffer.ts +124 -40
- package/src/adapter/resources/webgl-command-encoder.ts +6 -0
- package/src/adapter/resources/webgl-external-texture.ts +14 -0
- package/src/adapter/resources/webgl-framebuffer.ts +1 -2
- package/src/adapter/resources/webgl-render-pass.ts +44 -23
- package/src/adapter/resources/webgl-render-pipeline.ts +32 -16
- package/src/adapter/resources/webgl-shader.ts +8 -6
- package/src/adapter/resources/webgl-texture.ts +126 -235
- package/src/adapter/webgl-adapter.ts +4 -12
- package/src/adapter/webgl-device.ts +88 -48
- 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 +8 -31
- package/src/context/helpers/create-browser-context.ts +53 -63
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,39 @@ 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
|
+
let errorMessage = "";
|
|
724
|
+
const webglProps = {
|
|
725
|
+
preserveDrawingBuffer: true,
|
|
726
|
+
// failIfMajorPerformanceCaveat: true,
|
|
727
|
+
...webglContextAttributes
|
|
728
|
+
};
|
|
735
729
|
let gl = null;
|
|
736
|
-
gl ||= canvas.getContext("webgl2",
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
730
|
+
gl ||= canvas.getContext("webgl2", webglProps);
|
|
731
|
+
if (webglProps.failIfMajorPerformanceCaveat) {
|
|
732
|
+
errorMessage ||= "Only software GPU is available. Set `failIfMajorPerformanceCaveat: false` to allow.";
|
|
733
|
+
}
|
|
734
|
+
if (!gl && !webglContextAttributes.failIfMajorPerformanceCaveat) {
|
|
735
|
+
webglProps.failIfMajorPerformanceCaveat = false;
|
|
736
|
+
gl = canvas.getContext("webgl2", webglProps);
|
|
737
|
+
gl.luma ||= {};
|
|
738
|
+
gl.luma.softwareRenderer = true;
|
|
740
739
|
}
|
|
741
|
-
if (
|
|
742
|
-
|
|
743
|
-
|
|
740
|
+
if (!gl) {
|
|
741
|
+
gl = canvas.getContext("webgl", {});
|
|
742
|
+
if (gl) {
|
|
743
|
+
gl = null;
|
|
744
|
+
errorMessage ||= "Your browser only supports WebGL1";
|
|
745
|
+
}
|
|
744
746
|
}
|
|
745
|
-
if (
|
|
746
|
-
|
|
747
|
-
|
|
747
|
+
if (!gl) {
|
|
748
|
+
errorMessage ||= "Your browser does not support WebGL";
|
|
749
|
+
throw new Error(`Failed to create WebGL context: ${errorMessage}`);
|
|
748
750
|
}
|
|
751
|
+
const { onContextLost, onContextRestored } = props;
|
|
752
|
+
canvas.addEventListener("webglcontextlost", (event) => onContextLost(event), false);
|
|
753
|
+
canvas.addEventListener("webglcontextrestored", (event) => onContextRestored(event), false);
|
|
754
|
+
gl.luma ||= {};
|
|
749
755
|
return gl;
|
|
750
756
|
}
|
|
751
757
|
|
|
@@ -981,7 +987,7 @@ var TEXTURE_FORMATS = {
|
|
|
981
987
|
// 64-bit formats
|
|
982
988
|
"rg32uint": { gl: 33340, b: 8, c: 2, rb: true },
|
|
983
989
|
"rg32sint": { gl: 33339, b: 8, c: 2, rb: true },
|
|
984
|
-
"rg32float": { gl: 33328, b: 8, c: 2, render:
|
|
990
|
+
"rg32float": { gl: 33328, b: 8, c: 2, render: false, filter: float32_filterable, rb: true },
|
|
985
991
|
"rgba16uint": { gl: 36214, b: 8, c: 4, rb: true },
|
|
986
992
|
"rgba16sint": { gl: 36232, b: 8, c: 4, rb: true },
|
|
987
993
|
"rgba16float": { gl: 34842, b: 8, c: 4, render: float16_renderable, filter: float16_filterable },
|
|
@@ -1142,36 +1148,35 @@ function isTextureFormatSupported(gl, format, extensions) {
|
|
|
1142
1148
|
return true;
|
|
1143
1149
|
}
|
|
1144
1150
|
function isTextureFormatFilterable(gl, format, extensions) {
|
|
1145
|
-
|
|
1146
|
-
return false;
|
|
1147
|
-
}
|
|
1148
|
-
if (format.startsWith("depth") || format.startsWith("stencil")) {
|
|
1149
|
-
return false;
|
|
1150
|
-
}
|
|
1151
|
-
try {
|
|
1152
|
-
const decoded = (0, import_core.decodeTextureFormat)(format);
|
|
1153
|
-
if (decoded.signed) {
|
|
1154
|
-
return false;
|
|
1155
|
-
}
|
|
1156
|
-
} catch {
|
|
1157
|
-
return false;
|
|
1158
|
-
}
|
|
1159
|
-
if (format.endsWith("32float")) {
|
|
1160
|
-
return Boolean(getWebGLExtension(gl, "OES_texture_float_linear, extensions", extensions));
|
|
1161
|
-
}
|
|
1162
|
-
if (format.endsWith("16float")) {
|
|
1163
|
-
return Boolean(getWebGLExtension(gl, "OES_texture_half_float_linear, extensions", extensions));
|
|
1164
|
-
}
|
|
1165
|
-
return true;
|
|
1151
|
+
return getTextureFormatSupportWebGL(gl, format, extensions).filterable || false;
|
|
1166
1152
|
}
|
|
1167
1153
|
function isTextureFormatRenderable(gl, format, extensions) {
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1154
|
+
return getTextureFormatSupportWebGL(gl, format, extensions).renderable || false;
|
|
1155
|
+
}
|
|
1156
|
+
function getTextureFormatSupportWebGL(gl, format, extensions) {
|
|
1157
|
+
const formatInto = (0, import_core.decodeTextureFormat)(format);
|
|
1158
|
+
if (!formatInto) {
|
|
1159
|
+
return { supported: false };
|
|
1160
|
+
}
|
|
1161
|
+
const webglFormatInfo = TEXTURE_FORMATS[format];
|
|
1162
|
+
if (!webglFormatInfo) {
|
|
1163
|
+
return { supported: false };
|
|
1164
|
+
}
|
|
1165
|
+
let supported = webglFormatInfo.gl !== void 0;
|
|
1166
|
+
supported = supported && checkTextureFeature(gl, webglFormatInfo.f, extensions);
|
|
1167
|
+
const isDepthStencil = format.startsWith("depth") || format.startsWith("stencil");
|
|
1168
|
+
const isSigned = formatInto == null ? void 0 : formatInto.signed;
|
|
1169
|
+
const renderable = supported && !isSigned && webglFormatInfo.render && checkTextureFeature(gl, webglFormatInfo.render, extensions);
|
|
1170
|
+
const filterable = supported && !isDepthStencil && !isSigned && webglFormatInfo.filter && checkTextureFeature(gl, webglFormatInfo.filter, extensions);
|
|
1171
|
+
return {
|
|
1172
|
+
supported,
|
|
1173
|
+
renderable,
|
|
1174
|
+
filterable,
|
|
1175
|
+
blendable: false,
|
|
1176
|
+
// TODO,
|
|
1177
|
+
storable: false
|
|
1178
|
+
// TODO
|
|
1179
|
+
};
|
|
1175
1180
|
}
|
|
1176
1181
|
function getTextureFormatWebGL(format) {
|
|
1177
1182
|
var _a;
|
|
@@ -1449,7 +1454,7 @@ var WEBGLFramebuffer = class extends import_core4.Framebuffer {
|
|
|
1449
1454
|
const attachmentPoint = getDepthStencilAttachmentWebGL(this.depthStencilAttachment.props.format);
|
|
1450
1455
|
this._attachTextureView(attachmentPoint, this.depthStencilAttachment);
|
|
1451
1456
|
}
|
|
1452
|
-
if (this.props.
|
|
1457
|
+
if (this.device.props.debug) {
|
|
1453
1458
|
const status = this.gl.checkFramebufferStatus(36160);
|
|
1454
1459
|
if (status !== 36053) {
|
|
1455
1460
|
throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
|
|
@@ -1601,17 +1606,17 @@ var LOG_LEVEL = 1;
|
|
|
1601
1606
|
var spector = null;
|
|
1602
1607
|
var initialized = false;
|
|
1603
1608
|
var DEFAULT_SPECTOR_PROPS = {
|
|
1604
|
-
|
|
1609
|
+
debugSpectorJS: import_core6.log.get("debug-spectorjs"),
|
|
1605
1610
|
// https://github.com/BabylonJS/Spector.js#basic-usage
|
|
1606
1611
|
// https://forum.babylonjs.com/t/spectorcdn-is-temporarily-off/48241
|
|
1607
1612
|
// spectorUrl: 'https://spectorcdn.babylonjs.com/spector.bundle.js';
|
|
1608
|
-
|
|
1613
|
+
debugSpectorJSUrl: "https://cdn.jsdelivr.net/npm/spectorjs@0.9.30/dist/spector.bundle.js",
|
|
1609
1614
|
gl: void 0
|
|
1610
1615
|
};
|
|
1611
1616
|
async function loadSpectorJS(props) {
|
|
1612
1617
|
if (!globalThis.SPECTOR) {
|
|
1613
1618
|
try {
|
|
1614
|
-
await loadScript(props.
|
|
1619
|
+
await loadScript(props.debugSpectorJSUrl || DEFAULT_SPECTOR_PROPS.debugSpectorJSUrl);
|
|
1615
1620
|
} catch (error) {
|
|
1616
1621
|
import_core6.log.warn(String(error));
|
|
1617
1622
|
}
|
|
@@ -1620,13 +1625,13 @@ async function loadSpectorJS(props) {
|
|
|
1620
1625
|
function initializeSpectorJS(props) {
|
|
1621
1626
|
var _a;
|
|
1622
1627
|
props = { ...DEFAULT_SPECTOR_PROPS, ...props };
|
|
1623
|
-
if (!props.
|
|
1628
|
+
if (!props.debugSpectorJS) {
|
|
1624
1629
|
return null;
|
|
1625
1630
|
}
|
|
1626
1631
|
if (!spector && globalThis.SPECTOR && !((_a = globalThis.luma) == null ? void 0 : _a.spector)) {
|
|
1627
1632
|
import_core6.log.probe(LOG_LEVEL, "SPECTOR found and initialized. Start with `luma.spector.displayUI()`")();
|
|
1628
|
-
const { Spector } = globalThis.SPECTOR;
|
|
1629
|
-
spector = new
|
|
1633
|
+
const { Spector: SpectorJS } = globalThis.SPECTOR;
|
|
1634
|
+
spector = new SpectorJS();
|
|
1630
1635
|
if (globalThis.luma) {
|
|
1631
1636
|
globalThis.luma.spector = spector;
|
|
1632
1637
|
}
|
|
@@ -1675,7 +1680,7 @@ async function loadWebGLDeveloperTools() {
|
|
|
1675
1680
|
}
|
|
1676
1681
|
}
|
|
1677
1682
|
function makeDebugContext(gl, props = {}) {
|
|
1678
|
-
return props.
|
|
1683
|
+
return props.debugWebGL || props.traceWebGL ? getDebugContext(gl, props) : getRealContext(gl);
|
|
1679
1684
|
}
|
|
1680
1685
|
function getRealContext(gl) {
|
|
1681
1686
|
const data = getWebGLContextData(gl);
|
|
@@ -1720,32 +1725,19 @@ function onGLError(props, err, functionName, args) {
|
|
|
1720
1725
|
const message2 = `${errorMessage} in gl.${functionName}(${functionArgs})`;
|
|
1721
1726
|
import_core7.log.error(message2)();
|
|
1722
1727
|
debugger;
|
|
1723
|
-
if (props.throwOnError) {
|
|
1724
|
-
throw new Error(message2);
|
|
1725
|
-
}
|
|
1726
1728
|
}
|
|
1727
1729
|
function onValidateGLFunc(props, functionName, functionArgs) {
|
|
1728
1730
|
let functionString = "";
|
|
1729
1731
|
if (import_core7.log.level >= 1) {
|
|
1730
1732
|
functionString = getFunctionString(functionName, functionArgs);
|
|
1731
|
-
|
|
1732
|
-
|
|
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;
|
|
1733
|
+
if (props.traceWebGL) {
|
|
1734
|
+
import_core7.log.log(1, functionString)();
|
|
1738
1735
|
}
|
|
1739
1736
|
}
|
|
1740
1737
|
for (const arg of functionArgs) {
|
|
1741
1738
|
if (arg === void 0) {
|
|
1742
1739
|
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
|
-
}
|
|
1740
|
+
debugger;
|
|
1749
1741
|
}
|
|
1750
1742
|
}
|
|
1751
1743
|
}
|
|
@@ -1957,13 +1949,16 @@ var WEBGLShader = class extends import_core9.Shader {
|
|
|
1957
1949
|
this.destroyed = true;
|
|
1958
1950
|
}
|
|
1959
1951
|
}
|
|
1952
|
+
get asyncCompilationStatus() {
|
|
1953
|
+
return this._waitForCompilationComplete().then(() => this.compilationStatus);
|
|
1954
|
+
}
|
|
1960
1955
|
async getCompilationInfo() {
|
|
1961
1956
|
await this._waitForCompilationComplete();
|
|
1962
1957
|
return this.getCompilationInfoSync();
|
|
1963
1958
|
}
|
|
1964
1959
|
getCompilationInfoSync() {
|
|
1965
|
-
const
|
|
1966
|
-
return
|
|
1960
|
+
const shaderLog = this.device.gl.getShaderInfoLog(this.handle);
|
|
1961
|
+
return shaderLog ? parseShaderCompilerLog(shaderLog) : [];
|
|
1967
1962
|
}
|
|
1968
1963
|
getTranslatedSource() {
|
|
1969
1964
|
const extensions = this.device.getExtension("WEBGL_debug_shaders");
|
|
@@ -1973,13 +1968,12 @@ var WEBGLShader = class extends import_core9.Shader {
|
|
|
1973
1968
|
// PRIVATE METHODS
|
|
1974
1969
|
/** Compile a shader and get compilation status */
|
|
1975
1970
|
async _compile(source) {
|
|
1976
|
-
|
|
1977
|
-
${
|
|
1978
|
-
source = addGLSLVersion(source);
|
|
1971
|
+
source = source.startsWith("#version ") ? source : `#version 300 es
|
|
1972
|
+
${source}`;
|
|
1979
1973
|
const { gl } = this.device;
|
|
1980
1974
|
gl.shaderSource(this.handle, source);
|
|
1981
1975
|
gl.compileShader(this.handle);
|
|
1982
|
-
if (
|
|
1976
|
+
if (!this.device.props.debug) {
|
|
1983
1977
|
this.compilationStatus = "pending";
|
|
1984
1978
|
return;
|
|
1985
1979
|
}
|
|
@@ -2323,15 +2317,17 @@ function convertMaxFilterMode(maxFilter) {
|
|
|
2323
2317
|
return 9729;
|
|
2324
2318
|
}
|
|
2325
2319
|
}
|
|
2326
|
-
function convertMinFilterMode(minFilter, mipmapFilter) {
|
|
2320
|
+
function convertMinFilterMode(minFilter, mipmapFilter = "none") {
|
|
2327
2321
|
if (!mipmapFilter) {
|
|
2328
2322
|
return convertMaxFilterMode(minFilter);
|
|
2329
2323
|
}
|
|
2330
|
-
switch (
|
|
2324
|
+
switch (mipmapFilter) {
|
|
2325
|
+
case "none":
|
|
2326
|
+
return convertMaxFilterMode(minFilter);
|
|
2331
2327
|
case "nearest":
|
|
2332
|
-
return
|
|
2328
|
+
return minFilter === "nearest" ? 9984 : 9986;
|
|
2333
2329
|
case "linear":
|
|
2334
|
-
return
|
|
2330
|
+
return minFilter === "nearest" ? 9985 : 9987;
|
|
2335
2331
|
}
|
|
2336
2332
|
}
|
|
2337
2333
|
|
|
@@ -2485,14 +2481,20 @@ function glFormatToComponents(format) {
|
|
|
2485
2481
|
case 6406:
|
|
2486
2482
|
case 33326:
|
|
2487
2483
|
case 6403:
|
|
2484
|
+
case 36244:
|
|
2488
2485
|
return 1;
|
|
2486
|
+
case 33339:
|
|
2487
|
+
case 33340:
|
|
2489
2488
|
case 33328:
|
|
2489
|
+
case 33320:
|
|
2490
2490
|
case 33319:
|
|
2491
2491
|
return 2;
|
|
2492
2492
|
case 6407:
|
|
2493
|
+
case 36248:
|
|
2493
2494
|
case 34837:
|
|
2494
2495
|
return 3;
|
|
2495
2496
|
case 6408:
|
|
2497
|
+
case 36249:
|
|
2496
2498
|
case 34836:
|
|
2497
2499
|
return 4;
|
|
2498
2500
|
default:
|
|
@@ -2534,22 +2536,25 @@ function copyExternalImageToMipLevel(gl, handle, image, options) {
|
|
|
2534
2536
|
const { x = 0, y = 0, z = 0 } = options;
|
|
2535
2537
|
const { glFormat, glType } = options;
|
|
2536
2538
|
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2539
|
+
const glParameters = options.flipY ? { [37440]: true } : {};
|
|
2540
|
+
withGLParameters(gl, glParameters, () => {
|
|
2541
|
+
switch (dimension) {
|
|
2542
|
+
case "2d-array":
|
|
2543
|
+
case "3d":
|
|
2544
|
+
gl.bindTexture(glTarget, handle);
|
|
2545
|
+
gl.texSubImage3D(glTarget, mipLevel, x, y, z, width, height, depth, glFormat, glType, image);
|
|
2546
|
+
gl.bindTexture(glTarget, null);
|
|
2547
|
+
break;
|
|
2548
|
+
case "2d":
|
|
2549
|
+
case "cube":
|
|
2550
|
+
gl.bindTexture(glTarget, handle);
|
|
2551
|
+
gl.texSubImage2D(glTarget, mipLevel, x, y, width, height, glFormat, glType, image);
|
|
2552
|
+
gl.bindTexture(glTarget, null);
|
|
2553
|
+
break;
|
|
2554
|
+
default:
|
|
2555
|
+
throw new Error(dimension);
|
|
2556
|
+
}
|
|
2557
|
+
});
|
|
2553
2558
|
}
|
|
2554
2559
|
function copyCPUDataToMipLevel(gl, typedArray, options) {
|
|
2555
2560
|
const { dimension, width, height, depth = 0, mipLevel = 0, byteOffset = 0 } = options;
|
|
@@ -2598,15 +2603,15 @@ function getWebGLCubeFaceTarget(glTarget, dimension, level) {
|
|
|
2598
2603
|
return dimension === "cube" ? 34069 + level : glTarget;
|
|
2599
2604
|
}
|
|
2600
2605
|
function readPixelsToArray(source, options) {
|
|
2601
|
-
var _a
|
|
2606
|
+
var _a;
|
|
2602
2607
|
const {
|
|
2603
2608
|
sourceX = 0,
|
|
2604
2609
|
sourceY = 0,
|
|
2605
|
-
sourceAttachment =
|
|
2610
|
+
sourceAttachment = 0
|
|
2606
2611
|
// TODO - support gl.readBuffer
|
|
2607
2612
|
} = options || {};
|
|
2608
2613
|
let {
|
|
2609
|
-
target = null,
|
|
2614
|
+
target: target2 = null,
|
|
2610
2615
|
// following parameters are auto deduced if not provided
|
|
2611
2616
|
sourceWidth,
|
|
2612
2617
|
sourceHeight,
|
|
@@ -2616,31 +2621,36 @@ function readPixelsToArray(source, options) {
|
|
|
2616
2621
|
} = options || {};
|
|
2617
2622
|
const { framebuffer, deleteFramebuffer } = getFramebuffer(source);
|
|
2618
2623
|
const { gl, handle } = framebuffer;
|
|
2619
|
-
const attachment = sourceAttachment - 36064;
|
|
2620
2624
|
sourceWidth ||= framebuffer.width;
|
|
2621
2625
|
sourceHeight ||= framebuffer.height;
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2626
|
+
const texture = (_a = framebuffer.colorAttachments[sourceAttachment]) == null ? void 0 : _a.texture;
|
|
2627
|
+
if (!texture) {
|
|
2628
|
+
throw new Error(`Invalid framebuffer attachment ${sourceAttachment}`);
|
|
2629
|
+
}
|
|
2630
|
+
sourceDepth = (texture == null ? void 0 : texture.depth) || 1;
|
|
2631
|
+
sourceFormat ||= (texture == null ? void 0 : texture.glFormat) || 6408;
|
|
2632
|
+
sourceType ||= (texture == null ? void 0 : texture.glType) || 5121;
|
|
2633
|
+
target2 = getPixelArray(target2, sourceType, sourceFormat, sourceWidth, sourceHeight, sourceDepth);
|
|
2634
|
+
sourceType = sourceType || getGLTypeFromTypedArray(target2);
|
|
2627
2635
|
const prevHandle = gl.bindFramebuffer(36160, handle);
|
|
2628
|
-
gl.
|
|
2636
|
+
gl.readBuffer(36064 + sourceAttachment);
|
|
2637
|
+
gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target2);
|
|
2638
|
+
gl.readBuffer(36064);
|
|
2629
2639
|
gl.bindFramebuffer(36160, prevHandle || null);
|
|
2630
2640
|
if (deleteFramebuffer) {
|
|
2631
2641
|
framebuffer.destroy();
|
|
2632
2642
|
}
|
|
2633
|
-
return
|
|
2643
|
+
return target2;
|
|
2634
2644
|
}
|
|
2635
2645
|
function readPixelsToBuffer(source, options) {
|
|
2636
|
-
const { target, sourceX = 0, sourceY = 0, sourceFormat = 6408, targetByteOffset = 0 } = options || {};
|
|
2646
|
+
const { target: target2, sourceX = 0, sourceY = 0, sourceFormat = 6408, targetByteOffset = 0 } = options || {};
|
|
2637
2647
|
let { sourceWidth, sourceHeight, sourceType } = options || {};
|
|
2638
2648
|
const { framebuffer, deleteFramebuffer } = getFramebuffer(source);
|
|
2639
2649
|
sourceWidth = sourceWidth || framebuffer.width;
|
|
2640
2650
|
sourceHeight = sourceHeight || framebuffer.height;
|
|
2641
2651
|
const webglFramebuffer = framebuffer;
|
|
2642
2652
|
sourceType = sourceType || 5121;
|
|
2643
|
-
let webglBufferTarget =
|
|
2653
|
+
let webglBufferTarget = target2;
|
|
2644
2654
|
if (!webglBufferTarget) {
|
|
2645
2655
|
const components = glFormatToComponents(sourceFormat);
|
|
2646
2656
|
const byteCount = glTypeToBytes(sourceType);
|
|
@@ -2649,11 +2659,11 @@ function readPixelsToBuffer(source, options) {
|
|
|
2649
2659
|
}
|
|
2650
2660
|
const commandEncoder = source.device.createCommandEncoder();
|
|
2651
2661
|
commandEncoder.copyTextureToBuffer({
|
|
2652
|
-
source,
|
|
2662
|
+
sourceTexture: source,
|
|
2653
2663
|
width: sourceWidth,
|
|
2654
2664
|
height: sourceHeight,
|
|
2655
2665
|
origin: [sourceX, sourceY],
|
|
2656
|
-
|
|
2666
|
+
destinationBuffer: webglBufferTarget,
|
|
2657
2667
|
byteOffset: targetByteOffset
|
|
2658
2668
|
});
|
|
2659
2669
|
commandEncoder.destroy();
|
|
@@ -2679,38 +2689,19 @@ function toFramebuffer(texture, props) {
|
|
|
2679
2689
|
});
|
|
2680
2690
|
return framebuffer;
|
|
2681
2691
|
}
|
|
2682
|
-
function getPixelArray(pixelArray,
|
|
2692
|
+
function getPixelArray(pixelArray, glType, glFormat, width, height, depth) {
|
|
2683
2693
|
if (pixelArray) {
|
|
2684
2694
|
return pixelArray;
|
|
2685
2695
|
}
|
|
2686
|
-
|
|
2687
|
-
const ArrayType = getTypedArrayFromGLType(
|
|
2688
|
-
const components = glFormatToComponents(
|
|
2696
|
+
glType ||= 5121;
|
|
2697
|
+
const ArrayType = getTypedArrayFromGLType(glType, { clamped: false });
|
|
2698
|
+
const components = glFormatToComponents(glFormat);
|
|
2689
2699
|
return new ArrayType(width * height * components);
|
|
2690
2700
|
}
|
|
2691
2701
|
|
|
2692
2702
|
// dist/adapter/resources/webgl-texture.js
|
|
2693
|
-
function normalizeTextureData(data, options) {
|
|
2694
|
-
let lodArray;
|
|
2695
|
-
if (ArrayBuffer.isView(data)) {
|
|
2696
|
-
lodArray = [
|
|
2697
|
-
{
|
|
2698
|
-
// ts-expect-error does data really need to be Uint8ClampedArray?
|
|
2699
|
-
data,
|
|
2700
|
-
width: options.width,
|
|
2701
|
-
height: options.height
|
|
2702
|
-
// depth: options.depth
|
|
2703
|
-
}
|
|
2704
|
-
];
|
|
2705
|
-
} else if (!Array.isArray(data)) {
|
|
2706
|
-
lodArray = [data];
|
|
2707
|
-
} else {
|
|
2708
|
-
lodArray = data;
|
|
2709
|
-
}
|
|
2710
|
-
return lodArray;
|
|
2711
|
-
}
|
|
2712
2703
|
var WEBGLTexture = class extends import_core14.Texture {
|
|
2713
|
-
MAX_ATTRIBUTES;
|
|
2704
|
+
// readonly MAX_ATTRIBUTES: number;
|
|
2714
2705
|
device;
|
|
2715
2706
|
gl;
|
|
2716
2707
|
handle;
|
|
@@ -2718,8 +2709,12 @@ var WEBGLTexture = class extends import_core14.Texture {
|
|
|
2718
2709
|
// TODO - currently unused in WebGL. Create dummy sampler?
|
|
2719
2710
|
view = void 0;
|
|
2720
2711
|
// TODO - currently unused in WebGL. Create dummy view?
|
|
2721
|
-
mipmaps
|
|
2712
|
+
mipmaps;
|
|
2713
|
+
// Texture type
|
|
2714
|
+
/** Whether the internal format is compressed */
|
|
2715
|
+
compressed;
|
|
2722
2716
|
/**
|
|
2717
|
+
* The WebGL target corresponding to the texture type
|
|
2723
2718
|
* @note `target` cannot be modified by bind:
|
|
2724
2719
|
* textures are special because when you first bind them to a target,
|
|
2725
2720
|
* When you first bind a texture as a GL_TEXTURE_2D, you are saying that this texture is a 2D texture.
|
|
@@ -2728,122 +2723,79 @@ var WEBGLTexture = class extends import_core14.Texture {
|
|
|
2728
2723
|
* attempting to bind it as GL_TEXTURE_3D will give rise to a run-time error
|
|
2729
2724
|
*/
|
|
2730
2725
|
glTarget;
|
|
2731
|
-
// Texture type
|
|
2732
2726
|
/** The WebGL format - essentially channel structure */
|
|
2733
2727
|
glFormat;
|
|
2734
2728
|
/** The WebGL data format - the type of each channel */
|
|
2735
2729
|
glType;
|
|
2736
2730
|
/** The WebGL constant corresponding to the WebGPU style constant in format */
|
|
2737
2731
|
glInternalFormat;
|
|
2738
|
-
/** Whether the internal format is compressed */
|
|
2739
|
-
compressed;
|
|
2740
|
-
// data;
|
|
2741
|
-
// inherited props
|
|
2742
|
-
// dimension: ...
|
|
2743
|
-
// format: GLTextureTarget;
|
|
2744
|
-
// width: number = undefined;
|
|
2745
|
-
// height: number = undefined;
|
|
2746
|
-
// depth: number = undefined;
|
|
2747
2732
|
// state
|
|
2748
|
-
/** Texture binding slot */
|
|
2733
|
+
/** Texture binding slot - TODO - move to texture view? */
|
|
2749
2734
|
textureUnit = 0;
|
|
2750
|
-
/** For automatically updating video */
|
|
2751
|
-
_video = null;
|
|
2752
2735
|
constructor(device, props) {
|
|
2753
|
-
|
|
2754
|
-
|
|
2736
|
+
super(device, props);
|
|
2737
|
+
const propsWithData = { ...this.props };
|
|
2738
|
+
propsWithData.data = props.data;
|
|
2755
2739
|
this.device = device;
|
|
2756
2740
|
this.gl = this.device.gl;
|
|
2757
2741
|
this.glTarget = getWebGLTextureTarget(this.props.dimension);
|
|
2758
|
-
const
|
|
2759
|
-
this.glInternalFormat =
|
|
2760
|
-
this.glFormat =
|
|
2761
|
-
this.glType =
|
|
2762
|
-
this.compressed =
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
const video = props.data;
|
|
2766
|
-
this._video = null;
|
|
2767
|
-
video.addEventListener("loadeddata", () => this.initialize(props));
|
|
2768
|
-
}
|
|
2769
|
-
this.initialize({ ...this.props, data: props.data });
|
|
2742
|
+
const formatInfo = getTextureFormatWebGL(this.props.format);
|
|
2743
|
+
this.glInternalFormat = formatInfo.internalFormat;
|
|
2744
|
+
this.glFormat = formatInfo.format;
|
|
2745
|
+
this.glType = formatInfo.type;
|
|
2746
|
+
this.compressed = formatInfo.compressed;
|
|
2747
|
+
this.mipmaps = Boolean(this.props.mipmaps);
|
|
2748
|
+
this._initialize(propsWithData);
|
|
2770
2749
|
Object.seal(this);
|
|
2771
2750
|
}
|
|
2772
2751
|
/**
|
|
2773
2752
|
* Initialize texture with supplied props
|
|
2774
2753
|
*/
|
|
2775
2754
|
// eslint-disable-next-line max-statements
|
|
2776
|
-
|
|
2755
|
+
_initialize(propsWithData) {
|
|
2777
2756
|
this.handle = this.props.handle || this.gl.createTexture();
|
|
2778
|
-
this.device.setSpectorMetadata(this.handle, { ...this.props, data:
|
|
2779
|
-
|
|
2780
|
-
let { width, height } = props;
|
|
2757
|
+
this.device.setSpectorMetadata(this.handle, { ...this.props, data: propsWithData.data });
|
|
2758
|
+
let { width, height } = propsWithData;
|
|
2781
2759
|
if (!width || !height) {
|
|
2782
|
-
const textureSize = import_core14.Texture.getTextureDataSize(data);
|
|
2760
|
+
const textureSize = import_core14.Texture.getTextureDataSize(propsWithData.data);
|
|
2783
2761
|
width = (textureSize == null ? void 0 : textureSize.width) || 1;
|
|
2784
2762
|
height = (textureSize == null ? void 0 : textureSize.height) || 1;
|
|
2785
2763
|
}
|
|
2786
2764
|
this.width = width;
|
|
2787
2765
|
this.height = height;
|
|
2788
|
-
this.depth =
|
|
2789
|
-
this.setSampler(
|
|
2766
|
+
this.depth = propsWithData.depth;
|
|
2767
|
+
this.setSampler(propsWithData.sampler);
|
|
2790
2768
|
this.view = new WEBGLTextureView(this.device, { ...this.props, texture: this });
|
|
2791
2769
|
this.bind();
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
if (props.data) {
|
|
2796
|
-
switch (props.dimension) {
|
|
2770
|
+
initializeTextureStorage(this.gl, this.mipLevels, this);
|
|
2771
|
+
if (propsWithData.data) {
|
|
2772
|
+
switch (propsWithData.dimension) {
|
|
2797
2773
|
case "1d":
|
|
2798
|
-
this.setTexture1DData(
|
|
2774
|
+
this.setTexture1DData(propsWithData.data);
|
|
2799
2775
|
break;
|
|
2800
2776
|
case "2d":
|
|
2801
|
-
this.setTexture2DData(
|
|
2777
|
+
this.setTexture2DData(propsWithData.data);
|
|
2802
2778
|
break;
|
|
2803
2779
|
case "3d":
|
|
2804
|
-
this.setTexture3DData(
|
|
2780
|
+
this.setTexture3DData(propsWithData.data);
|
|
2805
2781
|
break;
|
|
2806
2782
|
case "cube":
|
|
2807
|
-
this.setTextureCubeData(
|
|
2783
|
+
this.setTextureCubeData(propsWithData.data);
|
|
2808
2784
|
break;
|
|
2809
2785
|
case "2d-array":
|
|
2810
|
-
this.setTextureArrayData(
|
|
2786
|
+
this.setTextureArrayData(propsWithData.data);
|
|
2811
2787
|
break;
|
|
2812
2788
|
case "cube-array":
|
|
2813
|
-
this.setTextureCubeArrayData(
|
|
2789
|
+
this.setTextureCubeArrayData(propsWithData.data);
|
|
2814
2790
|
break;
|
|
2815
2791
|
default:
|
|
2816
|
-
throw new Error(
|
|
2792
|
+
throw new Error(propsWithData.dimension);
|
|
2817
2793
|
}
|
|
2818
2794
|
}
|
|
2819
|
-
this.mipmaps = Boolean(props.mipmaps);
|
|
2820
2795
|
if (this.mipmaps) {
|
|
2821
2796
|
this.generateMipmap();
|
|
2822
2797
|
}
|
|
2823
2798
|
}
|
|
2824
|
-
/*
|
|
2825
|
-
initializeCube(props?: TextureProps): void {
|
|
2826
|
-
const {mipmaps = true} = props; // , parameters = {} as Record<GL, any>} = props;
|
|
2827
|
-
|
|
2828
|
-
// Store props for accessors
|
|
2829
|
-
// this.props = props;
|
|
2830
|
-
|
|
2831
|
-
// @ts-expect-error
|
|
2832
|
-
this.setCubeMapData(props).then(() => {
|
|
2833
|
-
// TODO - should genMipmap() be called on the cubemap or on the faces?
|
|
2834
|
-
// TODO - without generateMipmap() cube textures do not work at all!!! Why?
|
|
2835
|
-
if (mipmaps) {
|
|
2836
|
-
this.generateMipmap(props);
|
|
2837
|
-
}
|
|
2838
|
-
|
|
2839
|
-
this.setSampler(props.sampler);
|
|
2840
|
-
|
|
2841
|
-
// v8 compatibility?
|
|
2842
|
-
// const {parameters = {} as Record<GL, any>} = props;
|
|
2843
|
-
// this._setSamplerParameters(parameters);
|
|
2844
|
-
});
|
|
2845
|
-
}
|
|
2846
|
-
*/
|
|
2847
2799
|
destroy() {
|
|
2848
2800
|
if (this.handle) {
|
|
2849
2801
|
this.gl.deleteTexture(this.handle);
|
|
@@ -2852,9 +2804,6 @@ var WEBGLTexture = class extends import_core14.Texture {
|
|
|
2852
2804
|
this.destroyed = true;
|
|
2853
2805
|
}
|
|
2854
2806
|
}
|
|
2855
|
-
toString() {
|
|
2856
|
-
return `Texture(${this.id},${this.width}x${this.height})`;
|
|
2857
|
-
}
|
|
2858
2807
|
createView(props) {
|
|
2859
2808
|
return new WEBGLTextureView(this.device, { ...props, texture: this });
|
|
2860
2809
|
}
|
|
@@ -2870,33 +2819,33 @@ var WEBGLTexture = class extends import_core14.Texture {
|
|
|
2870
2819
|
const parameters = convertSamplerParametersToWebGL(samplerProps);
|
|
2871
2820
|
this._setSamplerParameters(parameters);
|
|
2872
2821
|
}
|
|
2873
|
-
/** Update external texture (video frame or canvas) */
|
|
2874
|
-
update() {
|
|
2875
|
-
import_core14.log.warn("Texture.update() not implemented");
|
|
2876
|
-
}
|
|
2877
2822
|
// Call to regenerate mipmaps after modifying texture(s)
|
|
2878
2823
|
generateMipmap(params = {}) {
|
|
2879
|
-
if (!this.props.
|
|
2880
|
-
|
|
2824
|
+
if (!this.device.isTextureFormatRenderable(this.props.format) || !this.device.isTextureFormatFilterable(this.props.format)) {
|
|
2825
|
+
import_core14.log.warn(`${this} is not renderable or filterable, may not be able to generate mipmaps`)();
|
|
2826
|
+
}
|
|
2827
|
+
try {
|
|
2828
|
+
this.gl.bindTexture(this.glTarget, this.handle);
|
|
2829
|
+
withGLParameters(this.gl, params, () => {
|
|
2830
|
+
this.gl.generateMipmap(this.glTarget);
|
|
2831
|
+
});
|
|
2832
|
+
} catch (error) {
|
|
2833
|
+
import_core14.log.warn(`Error generating mipmap for ${this}: ${error.message}`)();
|
|
2834
|
+
} finally {
|
|
2835
|
+
this.gl.bindTexture(this.glTarget, null);
|
|
2881
2836
|
}
|
|
2882
|
-
this.mipmaps = true;
|
|
2883
|
-
this.gl.bindTexture(this.glTarget, this.handle);
|
|
2884
|
-
withGLParameters(this.gl, params, () => {
|
|
2885
|
-
this.gl.generateMipmap(this.glTarget);
|
|
2886
|
-
});
|
|
2887
|
-
this.gl.bindTexture(this.glTarget, null);
|
|
2888
2837
|
}
|
|
2889
2838
|
// Image Data Setters
|
|
2890
2839
|
copyExternalImage(options) {
|
|
2891
2840
|
const size = import_core14.Texture.getExternalImageSize(options.image);
|
|
2892
2841
|
const opts = { ...import_core14.Texture.defaultCopyExternalImageOptions, ...size, ...options };
|
|
2893
|
-
const { image, depth, mipLevel, x, y, z } = opts;
|
|
2842
|
+
const { image, depth, mipLevel, x, y, z, flipY } = opts;
|
|
2894
2843
|
let { width, height } = opts;
|
|
2895
2844
|
const { dimension, glTarget, glFormat, glInternalFormat, glType } = this;
|
|
2896
2845
|
width = Math.min(width, size.width - x);
|
|
2897
2846
|
height = Math.min(height, size.height - y);
|
|
2898
2847
|
if (options.sourceX || options.sourceY) {
|
|
2899
|
-
throw new Error("WebGL does not
|
|
2848
|
+
throw new Error("WebGL does not support sourceX/sourceY)");
|
|
2900
2849
|
}
|
|
2901
2850
|
copyExternalImageToMipLevel(this.device.gl, this.handle, image, {
|
|
2902
2851
|
dimension,
|
|
@@ -2910,7 +2859,8 @@ var WEBGLTexture = class extends import_core14.Texture {
|
|
|
2910
2859
|
glFormat,
|
|
2911
2860
|
glInternalFormat,
|
|
2912
2861
|
glType,
|
|
2913
|
-
glTarget
|
|
2862
|
+
glTarget,
|
|
2863
|
+
flipY
|
|
2914
2864
|
});
|
|
2915
2865
|
return { width: opts.width, height: opts.height };
|
|
2916
2866
|
}
|
|
@@ -2920,7 +2870,7 @@ var WEBGLTexture = class extends import_core14.Texture {
|
|
|
2920
2870
|
/** Set a simple texture */
|
|
2921
2871
|
setTexture2DData(lodData, depth = 0) {
|
|
2922
2872
|
this.bind();
|
|
2923
|
-
const lodArray = normalizeTextureData(lodData, this);
|
|
2873
|
+
const lodArray = import_core14.Texture.normalizeTextureData(lodData, this);
|
|
2924
2874
|
if (lodArray.length > 1 && this.props.mipmaps !== false) {
|
|
2925
2875
|
import_core14.log.warn(`Texture ${this.id} mipmap and multiple LODs.`)();
|
|
2926
2876
|
}
|
|
@@ -2982,6 +2932,11 @@ var WEBGLTexture = class extends import_core14.Texture {
|
|
|
2982
2932
|
const faceDepth = import_core14.Texture.CubeFaces.indexOf(face);
|
|
2983
2933
|
this.setTexture2DData(lodData, faceDepth);
|
|
2984
2934
|
}
|
|
2935
|
+
// DEPRECATED METHODS
|
|
2936
|
+
/** Update external texture (video frame or canvas) @deprecated Use ExternalTexture */
|
|
2937
|
+
update() {
|
|
2938
|
+
throw new Error("Texture.update() not implemented. Use ExternalTexture");
|
|
2939
|
+
}
|
|
2985
2940
|
// INTERNAL METHODS
|
|
2986
2941
|
/** @todo update this method to accept LODs */
|
|
2987
2942
|
setImageDataForFace(options) {
|
|
@@ -3025,7 +2980,7 @@ var WEBGLTexture = class extends import_core14.Texture {
|
|
|
3025
2980
|
* Sets sampler parameters on texture
|
|
3026
2981
|
*/
|
|
3027
2982
|
_setSamplerParameters(parameters) {
|
|
3028
|
-
import_core14.log.log(1,
|
|
2983
|
+
import_core14.log.log(1, `${this.id} sampler parameters`, this.device.getGLKeys(parameters))();
|
|
3029
2984
|
this.gl.bindTexture(this.glTarget, this.handle);
|
|
3030
2985
|
for (const [pname, pvalue] of Object.entries(parameters)) {
|
|
3031
2986
|
const param = Number(pname);
|
|
@@ -3054,61 +3009,6 @@ var WEBGLTexture = class extends import_core14.Texture {
|
|
|
3054
3009
|
}
|
|
3055
3010
|
this.gl.bindTexture(this.glTarget, null);
|
|
3056
3011
|
}
|
|
3057
|
-
// CLASSIC
|
|
3058
|
-
/*
|
|
3059
|
-
setCubeMapData(options: {
|
|
3060
|
-
width: number;
|
|
3061
|
-
height: number;
|
|
3062
|
-
data: Record<GL, Texture2DData> | Record<TextureCubeFace, Texture2DData>;
|
|
3063
|
-
format?: any;
|
|
3064
|
-
type?: any;
|
|
3065
|
-
/** @deprecated Use .data *
|
|
3066
|
-
pixels: any;
|
|
3067
|
-
}): void {
|
|
3068
|
-
const {gl} = this;
|
|
3069
|
-
|
|
3070
|
-
const {width, height, pixels, data, format = GL.RGBA, type = GL.UNSIGNED_BYTE} = options;
|
|
3071
|
-
|
|
3072
|
-
// pixel data (imageDataMap) is an Object from Face to Image or Promise.
|
|
3073
|
-
// For example:
|
|
3074
|
-
// {
|
|
3075
|
-
// GL.TEXTURE_CUBE_MAP_POSITIVE_X : Image-or-Promise,
|
|
3076
|
-
// GL.TEXTURE_CUBE_MAP_NEGATIVE_X : Image-or-Promise,
|
|
3077
|
-
// ... }
|
|
3078
|
-
// To provide multiple level-of-details (LODs) this can be Face to Array
|
|
3079
|
-
// of Image or Promise, like this
|
|
3080
|
-
// {
|
|
3081
|
-
// GL.TEXTURE_CUBE_MAP_POSITIVE_X : [Image-or-Promise-LOD-0, Image-or-Promise-LOD-1],
|
|
3082
|
-
// GL.TEXTURE_CUBE_MAP_NEGATIVE_X : [Image-or-Promise-LOD-0, Image-or-Promise-LOD-1],
|
|
3083
|
-
// ... }
|
|
3084
|
-
|
|
3085
|
-
const imageDataMap = this._getImageDataMap(pixels || data);
|
|
3086
|
-
|
|
3087
|
-
const resolvedFaces = WEBGLTexture.FACES.map(face => {
|
|
3088
|
-
const facePixels = imageDataMap[face];
|
|
3089
|
-
return Array.isArray(facePixels) ? facePixels : [facePixels];
|
|
3090
|
-
});
|
|
3091
|
-
this.bind();
|
|
3092
|
-
|
|
3093
|
-
WEBGLTexture.FACES.forEach((face, index) => {
|
|
3094
|
-
if (resolvedFaces[index].length > 1 && this.props.mipmaps !== false) {
|
|
3095
|
-
// If the user provides multiple LODs, then automatic mipmap
|
|
3096
|
-
// generation generateMipmap() should be disabled to avoid overwritting them.
|
|
3097
|
-
log.warn(`${this.id} has mipmap and multiple LODs.`)();
|
|
3098
|
-
}
|
|
3099
|
-
resolvedFaces[index].forEach((image, lodLevel) => {
|
|
3100
|
-
// TODO: adjust width & height for LOD!
|
|
3101
|
-
if (width && height) {
|
|
3102
|
-
gl.texImage2D(face, lodLevel, format, width, height, 0 /* border*, format, type, image);
|
|
3103
|
-
} else {
|
|
3104
|
-
gl.texImage2D(face, lodLevel, format, format, type, image);
|
|
3105
|
-
}
|
|
3106
|
-
});
|
|
3107
|
-
});
|
|
3108
|
-
|
|
3109
|
-
this.unbind();
|
|
3110
|
-
}
|
|
3111
|
-
*/
|
|
3112
3012
|
// INTERNAL SETTERS
|
|
3113
3013
|
/**
|
|
3114
3014
|
* Copy a region of data from a CPU memory buffer into this texture.
|
|
@@ -3120,7 +3020,8 @@ var WEBGLTexture = class extends import_core14.Texture {
|
|
|
3120
3020
|
...this,
|
|
3121
3021
|
depth,
|
|
3122
3022
|
mipLevel,
|
|
3123
|
-
glTarget
|
|
3023
|
+
glTarget,
|
|
3024
|
+
flipY: this.props.flipY
|
|
3124
3025
|
});
|
|
3125
3026
|
return;
|
|
3126
3027
|
}
|
|
@@ -3162,10 +3063,6 @@ var WEBGLTexture = class extends import_core14.Texture {
|
|
|
3162
3063
|
// dist/adapter/resources/webgl-render-pass.js
|
|
3163
3064
|
var import_core15 = require("@luma.gl/core");
|
|
3164
3065
|
var import_constants17 = require("@luma.gl/constants");
|
|
3165
|
-
var GL_DEPTH_BUFFER_BIT = 256;
|
|
3166
|
-
var GL_STENCIL_BUFFER_BIT = 1024;
|
|
3167
|
-
var GL_COLOR_BUFFER_BIT = 16384;
|
|
3168
|
-
var GL_COLOR = 6144;
|
|
3169
3066
|
var COLOR_CHANNELS = [1, 2, 4, 8];
|
|
3170
3067
|
var WEBGLRenderPass = class extends import_core15.RenderPass {
|
|
3171
3068
|
device;
|
|
@@ -3187,6 +3084,12 @@ var WEBGLRenderPass = class extends import_core15.RenderPass {
|
|
|
3187
3084
|
}
|
|
3188
3085
|
this.device.pushState();
|
|
3189
3086
|
this.setParameters({ viewport, ...this.props.parameters });
|
|
3087
|
+
if (this.props.framebuffer) {
|
|
3088
|
+
const drawBuffers = this.props.framebuffer.colorAttachments.map((_, i) => 36064 + i);
|
|
3089
|
+
this.device.gl.drawBuffers(drawBuffers);
|
|
3090
|
+
} else {
|
|
3091
|
+
this.device.gl.drawBuffers([1029]);
|
|
3092
|
+
}
|
|
3190
3093
|
this.clear();
|
|
3191
3094
|
}
|
|
3192
3095
|
end() {
|
|
@@ -3250,19 +3153,30 @@ var WEBGLRenderPass = class extends import_core15.RenderPass {
|
|
|
3250
3153
|
* Optionally clears depth, color and stencil buffers based on parameters
|
|
3251
3154
|
*/
|
|
3252
3155
|
clear() {
|
|
3156
|
+
const DEFAULT_CLEAR_COLOR = [0, 0, 0, 1];
|
|
3157
|
+
const DEFAULT_CLEAR_DEPTH = 1;
|
|
3158
|
+
const DEFAULT_CLEAR_STENCIL = 0;
|
|
3253
3159
|
const glParameters = { ...this.glParameters };
|
|
3254
3160
|
let clearMask = 0;
|
|
3255
|
-
if (this.props.
|
|
3256
|
-
|
|
3257
|
-
|
|
3161
|
+
if (this.props.clearColors) {
|
|
3162
|
+
this.props.clearColors.forEach((color, drawBufferIndex) => {
|
|
3163
|
+
if (color) {
|
|
3164
|
+
this.clearColorBuffer(drawBufferIndex, color);
|
|
3165
|
+
}
|
|
3166
|
+
});
|
|
3167
|
+
}
|
|
3168
|
+
if (this.props.clearColor !== false && this.props.clearColors === void 0) {
|
|
3169
|
+
clearMask |= 16384;
|
|
3170
|
+
const clearColor = this.props.clearColor === true ? DEFAULT_CLEAR_COLOR : this.props.clearColor;
|
|
3171
|
+
glParameters.clearColor = clearColor;
|
|
3258
3172
|
}
|
|
3259
3173
|
if (this.props.clearDepth !== false) {
|
|
3260
|
-
clearMask |=
|
|
3261
|
-
glParameters.clearDepth = this.props.clearDepth;
|
|
3174
|
+
clearMask |= 256;
|
|
3175
|
+
glParameters.clearDepth = this.props.clearDepth === true ? DEFAULT_CLEAR_DEPTH : this.props.clearDepth;
|
|
3262
3176
|
}
|
|
3263
3177
|
if (this.props.clearStencil !== false) {
|
|
3264
|
-
clearMask |=
|
|
3265
|
-
glParameters.clearStencil = this.props.clearStencil;
|
|
3178
|
+
clearMask |= 1024;
|
|
3179
|
+
glParameters.clearStencil = this.props.clearStencil === true ? DEFAULT_CLEAR_STENCIL : this.props.clearStencil;
|
|
3266
3180
|
}
|
|
3267
3181
|
if (clearMask !== 0) {
|
|
3268
3182
|
withGLParameters(this.device.gl, glParameters, () => {
|
|
@@ -3276,16 +3190,22 @@ var WEBGLRenderPass = class extends import_core15.RenderPass {
|
|
|
3276
3190
|
clearColorBuffer(drawBuffer = 0, value = [0, 0, 0, 0]) {
|
|
3277
3191
|
withGLParameters(this.device.gl, { framebuffer: this.props.framebuffer }, () => {
|
|
3278
3192
|
switch (value.constructor) {
|
|
3193
|
+
case Int8Array:
|
|
3194
|
+
case Int16Array:
|
|
3279
3195
|
case Int32Array:
|
|
3280
|
-
this.device.gl.clearBufferiv(
|
|
3196
|
+
this.device.gl.clearBufferiv(6144, drawBuffer, value);
|
|
3281
3197
|
break;
|
|
3198
|
+
case Uint8Array:
|
|
3199
|
+
case Uint8ClampedArray:
|
|
3200
|
+
case Uint16Array:
|
|
3282
3201
|
case Uint32Array:
|
|
3283
|
-
this.device.gl.clearBufferuiv(
|
|
3202
|
+
this.device.gl.clearBufferuiv(6144, drawBuffer, value);
|
|
3284
3203
|
break;
|
|
3285
3204
|
case Float32Array:
|
|
3286
|
-
|
|
3287
|
-
this.device.gl.clearBufferfv(GL_COLOR, drawBuffer, value);
|
|
3205
|
+
this.device.gl.clearBufferfv(6144, drawBuffer, value);
|
|
3288
3206
|
break;
|
|
3207
|
+
default:
|
|
3208
|
+
throw new Error("clearColorBuffer: color must be typed array");
|
|
3289
3209
|
}
|
|
3290
3210
|
});
|
|
3291
3211
|
}
|
|
@@ -3781,9 +3701,9 @@ var WEBGLRenderPipeline = class extends import_core16.RenderPipeline {
|
|
|
3781
3701
|
*/
|
|
3782
3702
|
setBindings(bindings, options) {
|
|
3783
3703
|
for (const [name, value] of Object.entries(bindings)) {
|
|
3784
|
-
const binding = this.shaderLayout.bindings.find((
|
|
3704
|
+
const binding = this.shaderLayout.bindings.find((binding_) => binding_.name === name) || this.shaderLayout.bindings.find((binding_) => binding_.name === `${name}Uniforms`);
|
|
3785
3705
|
if (!binding) {
|
|
3786
|
-
const validBindings = this.shaderLayout.bindings.map((
|
|
3706
|
+
const validBindings = this.shaderLayout.bindings.map((binding_) => `"${binding_.name}"`).join(", ");
|
|
3787
3707
|
if (!(options == null ? void 0 : options.disableWarnings)) {
|
|
3788
3708
|
import_core16.log.warn(`No binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`, value)();
|
|
3789
3709
|
}
|
|
@@ -3908,21 +3828,34 @@ var WEBGLRenderPipeline = class extends import_core16.RenderPipeline {
|
|
|
3908
3828
|
this._reportLinkStatus(status);
|
|
3909
3829
|
}
|
|
3910
3830
|
/** Report link status. First, check for shader compilation failures if linking fails */
|
|
3911
|
-
_reportLinkStatus(status) {
|
|
3831
|
+
async _reportLinkStatus(status) {
|
|
3912
3832
|
var _a;
|
|
3913
3833
|
switch (status) {
|
|
3914
3834
|
case "success":
|
|
3915
3835
|
return;
|
|
3916
3836
|
default:
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3837
|
+
switch (this.vs.compilationStatus) {
|
|
3838
|
+
case "error":
|
|
3839
|
+
this.vs.debugShader();
|
|
3840
|
+
throw new Error(`Error during compilation of shader ${this.vs.id}`);
|
|
3841
|
+
case "pending":
|
|
3842
|
+
this.vs.asyncCompilationStatus.then(() => this.vs.debugShader());
|
|
3843
|
+
break;
|
|
3844
|
+
case "success":
|
|
3845
|
+
break;
|
|
3920
3846
|
}
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3847
|
+
switch ((_a = this.fs) == null ? void 0 : _a.compilationStatus) {
|
|
3848
|
+
case "error":
|
|
3849
|
+
this.fs.debugShader();
|
|
3850
|
+
throw new Error(`Error during compilation of shader ${this.fs.id}`);
|
|
3851
|
+
case "pending":
|
|
3852
|
+
this.fs.asyncCompilationStatus.then(() => this.fs.debugShader());
|
|
3853
|
+
break;
|
|
3854
|
+
case "success":
|
|
3855
|
+
break;
|
|
3924
3856
|
}
|
|
3925
|
-
|
|
3857
|
+
const linkErrorLog = this.device.gl.getProgramInfoLog(this.handle);
|
|
3858
|
+
throw new Error(`Error during ${status}: ${linkErrorLog}`);
|
|
3926
3859
|
}
|
|
3927
3860
|
}
|
|
3928
3861
|
/**
|
|
@@ -3976,11 +3909,6 @@ var WEBGLRenderPipeline = class extends import_core16.RenderPipeline {
|
|
|
3976
3909
|
texturesRenderable = false;
|
|
3977
3910
|
}
|
|
3978
3911
|
}
|
|
3979
|
-
for (const [, texture] of Object.entries(this.bindings)) {
|
|
3980
|
-
if (texture instanceof WEBGLTexture) {
|
|
3981
|
-
texture.update();
|
|
3982
|
-
}
|
|
3983
|
-
}
|
|
3984
3912
|
return texturesRenderable;
|
|
3985
3913
|
}
|
|
3986
3914
|
/** Apply any bindings (before each draw call) */
|
|
@@ -4107,13 +4035,15 @@ var WEBGLCommandBuffer = class extends import_core17.CommandBuffer {
|
|
|
4107
4035
|
case "copy-texture-to-texture":
|
|
4108
4036
|
_copyTextureToTexture(this.device, command.options);
|
|
4109
4037
|
break;
|
|
4038
|
+
default:
|
|
4039
|
+
throw new Error(command.name);
|
|
4110
4040
|
}
|
|
4111
4041
|
}
|
|
4112
4042
|
}
|
|
4113
4043
|
};
|
|
4114
4044
|
function _copyBufferToBuffer(device, options) {
|
|
4115
|
-
const source = options.
|
|
4116
|
-
const destination = options.
|
|
4045
|
+
const source = options.sourceBuffer;
|
|
4046
|
+
const destination = options.destinationBuffer;
|
|
4117
4047
|
device.gl.bindBuffer(36662, source.handle);
|
|
4118
4048
|
device.gl.bindBuffer(36663, destination.handle);
|
|
4119
4049
|
device.gl.copyBufferSubData(36662, 36663, options.sourceOffset ?? 0, options.destinationOffset ?? 0, options.size);
|
|
@@ -4126,20 +4056,20 @@ function _copyBufferToTexture(device, options) {
|
|
|
4126
4056
|
function _copyTextureToBuffer(device, options) {
|
|
4127
4057
|
const {
|
|
4128
4058
|
/** Texture to copy to/from. */
|
|
4129
|
-
|
|
4059
|
+
sourceTexture,
|
|
4130
4060
|
/** Mip-map level of the texture to copy to/from. (Default 0) */
|
|
4131
4061
|
mipLevel = 0,
|
|
4132
4062
|
/** Defines which aspects of the texture to copy to/from. */
|
|
4133
4063
|
aspect = "all",
|
|
4134
4064
|
/** Width to copy */
|
|
4135
|
-
width = options.
|
|
4065
|
+
width = options.sourceTexture.width,
|
|
4136
4066
|
/** Height to copy */
|
|
4137
|
-
height = options.
|
|
4067
|
+
height = options.sourceTexture.height,
|
|
4138
4068
|
depthOrArrayLayers = 0,
|
|
4139
4069
|
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
|
|
4140
4070
|
origin = [0, 0],
|
|
4141
4071
|
/** Destination buffer */
|
|
4142
|
-
|
|
4072
|
+
destinationBuffer,
|
|
4143
4073
|
/** Offset, in bytes, from the beginning of the buffer to the start of the image data (default 0) */
|
|
4144
4074
|
byteOffset = 0,
|
|
4145
4075
|
/**
|
|
@@ -4155,15 +4085,15 @@ function _copyTextureToBuffer(device, options) {
|
|
|
4155
4085
|
rowsPerImage
|
|
4156
4086
|
} = options;
|
|
4157
4087
|
if (aspect !== "all") {
|
|
4158
|
-
throw new Error("not supported");
|
|
4088
|
+
throw new Error("aspect not supported in WebGL");
|
|
4159
4089
|
}
|
|
4160
4090
|
if (mipLevel !== 0 || depthOrArrayLayers !== 0 || bytesPerRow || rowsPerImage) {
|
|
4161
4091
|
throw new Error("not implemented");
|
|
4162
4092
|
}
|
|
4163
|
-
const { framebuffer, destroyFramebuffer } = getFramebuffer2(
|
|
4093
|
+
const { framebuffer, destroyFramebuffer } = getFramebuffer2(sourceTexture);
|
|
4164
4094
|
let prevHandle;
|
|
4165
4095
|
try {
|
|
4166
|
-
const webglBuffer =
|
|
4096
|
+
const webglBuffer = destinationBuffer;
|
|
4167
4097
|
const sourceWidth = width || framebuffer.width;
|
|
4168
4098
|
const sourceHeight = height || framebuffer.height;
|
|
4169
4099
|
const sourceParams = getTextureFormatWebGL(framebuffer.colorAttachments[0].texture.props.format);
|
|
@@ -4185,7 +4115,7 @@ function _copyTextureToBuffer(device, options) {
|
|
|
4185
4115
|
function _copyTextureToTexture(device, options) {
|
|
4186
4116
|
const {
|
|
4187
4117
|
/** Texture to copy to/from. */
|
|
4188
|
-
|
|
4118
|
+
sourceTexture,
|
|
4189
4119
|
/** Mip-map level of the texture to copy to (Default 0) */
|
|
4190
4120
|
destinationMipLevel = 0,
|
|
4191
4121
|
/** Defines which aspects of the texture to copy to/from. */
|
|
@@ -4195,7 +4125,7 @@ function _copyTextureToTexture(device, options) {
|
|
|
4195
4125
|
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to. */
|
|
4196
4126
|
destinationOrigin = [0, 0],
|
|
4197
4127
|
/** Texture to copy to/from. */
|
|
4198
|
-
|
|
4128
|
+
destinationTexture
|
|
4199
4129
|
/** Mip-map level of the texture to copy to/from. (Default 0) */
|
|
4200
4130
|
// destinationMipLevel = options.mipLevel,
|
|
4201
4131
|
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
|
|
@@ -4204,18 +4134,18 @@ function _copyTextureToTexture(device, options) {
|
|
|
4204
4134
|
// destinationAspect = options.aspect,
|
|
4205
4135
|
} = options;
|
|
4206
4136
|
let {
|
|
4207
|
-
width = options.
|
|
4208
|
-
height = options.
|
|
4137
|
+
width = options.destinationTexture.width,
|
|
4138
|
+
height = options.destinationTexture.height
|
|
4209
4139
|
// depthOrArrayLayers = 0
|
|
4210
4140
|
} = options;
|
|
4211
|
-
const { framebuffer, destroyFramebuffer } = getFramebuffer2(
|
|
4141
|
+
const { framebuffer, destroyFramebuffer } = getFramebuffer2(sourceTexture);
|
|
4212
4142
|
const [sourceX, sourceY] = origin;
|
|
4213
4143
|
const [destinationX, destinationY, destinationZ] = destinationOrigin;
|
|
4214
4144
|
const prevHandle = device.gl.bindFramebuffer(36160, framebuffer.handle);
|
|
4215
4145
|
let texture = null;
|
|
4216
4146
|
let textureTarget;
|
|
4217
|
-
if (
|
|
4218
|
-
texture =
|
|
4147
|
+
if (destinationTexture instanceof WEBGLTexture) {
|
|
4148
|
+
texture = destinationTexture;
|
|
4219
4149
|
width = Number.isFinite(width) ? width : texture.width;
|
|
4220
4150
|
height = Number.isFinite(height) ? height : texture.height;
|
|
4221
4151
|
texture.bind(0);
|
|
@@ -4285,6 +4215,9 @@ var WEBGLCommandEncoder = class extends import_core18.CommandEncoder {
|
|
|
4285
4215
|
copyTextureToTexture(options) {
|
|
4286
4216
|
this.commandBuffer.commands.push({ name: "copy-texture-to-texture", options });
|
|
4287
4217
|
}
|
|
4218
|
+
// clearTexture(options: ClearTextureOptions): void {
|
|
4219
|
+
// this.commandBuffer.commands.push({name: 'copy-texture-to-texture', options});
|
|
4220
|
+
// }
|
|
4288
4221
|
pushDebugGroup(groupLabel) {
|
|
4289
4222
|
}
|
|
4290
4223
|
popDebugGroup() {
|
|
@@ -4302,19 +4235,19 @@ var import_env2 = require("@probe.gl/env");
|
|
|
4302
4235
|
|
|
4303
4236
|
// dist/utils/fill-array.js
|
|
4304
4237
|
function fillArray(options) {
|
|
4305
|
-
const { target, source, start = 0, count = 1 } = options;
|
|
4238
|
+
const { target: target2, source, start = 0, count = 1 } = options;
|
|
4306
4239
|
const length = source.length;
|
|
4307
4240
|
const total = count * length;
|
|
4308
4241
|
let copied = 0;
|
|
4309
4242
|
for (let i = start; copied < length; copied++) {
|
|
4310
|
-
|
|
4243
|
+
target2[i++] = source[copied];
|
|
4311
4244
|
}
|
|
4312
4245
|
while (copied < total) {
|
|
4313
4246
|
if (copied < total - copied) {
|
|
4314
|
-
|
|
4247
|
+
target2.copyWithin(start + copied, start, start + copied);
|
|
4315
4248
|
copied *= 2;
|
|
4316
4249
|
} else {
|
|
4317
|
-
|
|
4250
|
+
target2.copyWithin(start + copied, start, start + total - copied);
|
|
4318
4251
|
copied = total;
|
|
4319
4252
|
}
|
|
4320
4253
|
}
|
|
@@ -4730,11 +4663,11 @@ var WEBGLQuerySet = class extends import_core21.QuerySet {
|
|
|
4730
4663
|
* outstanding queries representing disjoint `begin()`/`end()` intervals.
|
|
4731
4664
|
* It is not possible to interleave or overlap `begin` and `end` calls.
|
|
4732
4665
|
*/
|
|
4733
|
-
_begin(
|
|
4666
|
+
_begin(target2) {
|
|
4734
4667
|
if (this._queryPending) {
|
|
4735
4668
|
return;
|
|
4736
4669
|
}
|
|
4737
|
-
this.target =
|
|
4670
|
+
this.target = target2;
|
|
4738
4671
|
this.device.gl.beginQuery(this.target, this.handle);
|
|
4739
4672
|
return;
|
|
4740
4673
|
}
|
|
@@ -4799,9 +4732,9 @@ var WEBGLQuerySet = class extends import_core21.QuerySet {
|
|
|
4799
4732
|
|
|
4800
4733
|
// dist/deprecated/clear.js
|
|
4801
4734
|
var import_core22 = require("@luma.gl/core");
|
|
4802
|
-
var
|
|
4803
|
-
var
|
|
4804
|
-
var
|
|
4735
|
+
var GL_DEPTH_BUFFER_BIT = 256;
|
|
4736
|
+
var GL_STENCIL_BUFFER_BIT = 1024;
|
|
4737
|
+
var GL_COLOR_BUFFER_BIT = 16384;
|
|
4805
4738
|
function clear(device, options) {
|
|
4806
4739
|
import_core22.log.warn("clear will be removed in next minor release");
|
|
4807
4740
|
const { framebuffer = null, color = null, depth = null, stencil = null } = options || {};
|
|
@@ -4811,19 +4744,19 @@ function clear(device, options) {
|
|
|
4811
4744
|
}
|
|
4812
4745
|
let clearFlags = 0;
|
|
4813
4746
|
if (color) {
|
|
4814
|
-
clearFlags |=
|
|
4747
|
+
clearFlags |= GL_COLOR_BUFFER_BIT;
|
|
4815
4748
|
if (color !== true) {
|
|
4816
4749
|
parameters.clearColor = color;
|
|
4817
4750
|
}
|
|
4818
4751
|
}
|
|
4819
4752
|
if (depth) {
|
|
4820
|
-
clearFlags |=
|
|
4753
|
+
clearFlags |= GL_DEPTH_BUFFER_BIT;
|
|
4821
4754
|
if (depth !== true) {
|
|
4822
4755
|
parameters.clearDepth = depth;
|
|
4823
4756
|
}
|
|
4824
4757
|
}
|
|
4825
4758
|
if (stencil) {
|
|
4826
|
-
clearFlags |=
|
|
4759
|
+
clearFlags |= GL_STENCIL_BUFFER_BIT;
|
|
4827
4760
|
if (depth !== true) {
|
|
4828
4761
|
parameters.clearStencil = depth;
|
|
4829
4762
|
}
|
|
@@ -4865,36 +4798,52 @@ var WebGLDevice = class extends import_core23.Device {
|
|
|
4865
4798
|
constructor(props) {
|
|
4866
4799
|
var _a, _b;
|
|
4867
4800
|
super({ ...props, id: props.id || uid("webgl-device") });
|
|
4868
|
-
|
|
4801
|
+
if (!props.createCanvasContext) {
|
|
4802
|
+
throw new Error("WebGLDevice requires props.createCanvasContext to be set");
|
|
4803
|
+
}
|
|
4804
|
+
const canvasContextProps = props.createCanvasContext === true ? {} : props.createCanvasContext;
|
|
4805
|
+
let device = (_b = (_a = canvasContextProps.canvas) == null ? void 0 : _a.gl) == null ? void 0 : _b.device;
|
|
4869
4806
|
if (device) {
|
|
4870
4807
|
throw new Error(`WebGL context already attached to device ${device.id}`);
|
|
4871
4808
|
}
|
|
4872
|
-
|
|
4873
|
-
this.canvasContext = new WebGLCanvasContext(this, { ...props, canvas });
|
|
4809
|
+
this.canvasContext = new WebGLCanvasContext(this, canvasContextProps);
|
|
4874
4810
|
this.lost = new Promise((resolve) => {
|
|
4875
4811
|
this._resolveContextLost = resolve;
|
|
4876
4812
|
});
|
|
4877
|
-
|
|
4878
|
-
|
|
4813
|
+
const webglContextAttributes = { ...props.webgl };
|
|
4814
|
+
if (canvasContextProps.alphaMode === "premultiplied") {
|
|
4815
|
+
webglContextAttributes.premultipliedAlpha = true;
|
|
4816
|
+
}
|
|
4817
|
+
if (props.powerPreference !== void 0) {
|
|
4818
|
+
webglContextAttributes.powerPreference = props.powerPreference;
|
|
4819
|
+
}
|
|
4820
|
+
const gl = createBrowserContext(this.canvasContext.canvas, {
|
|
4879
4821
|
onContextLost: (event) => {
|
|
4880
4822
|
var _a2;
|
|
4881
4823
|
return (_a2 = this._resolveContextLost) == null ? void 0 : _a2.call(this, {
|
|
4882
4824
|
reason: "destroyed",
|
|
4883
4825
|
message: "Entered sleep mode, or too many apps or browser tabs are using the GPU."
|
|
4884
4826
|
});
|
|
4885
|
-
}
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4827
|
+
},
|
|
4828
|
+
// eslint-disable-next-line no-console
|
|
4829
|
+
onContextRestored: (event) => console.log("WebGL context restored")
|
|
4830
|
+
}, webglContextAttributes);
|
|
4831
|
+
if (!gl) {
|
|
4889
4832
|
throw new Error("WebGL context creation failed");
|
|
4890
4833
|
}
|
|
4834
|
+
device = gl.device;
|
|
4835
|
+
if (device) {
|
|
4836
|
+
throw new Error(`WebGL context already attached to device ${device.id}`);
|
|
4837
|
+
}
|
|
4838
|
+
this.handle = gl;
|
|
4839
|
+
this.gl = gl;
|
|
4891
4840
|
this.spectorJS = initializeSpectorJS({ ...this.props, gl: this.handle });
|
|
4892
4841
|
this.gl.device = this;
|
|
4893
4842
|
this.gl._version = 2;
|
|
4894
4843
|
this.info = getDeviceInfo(this.gl, this._extensions);
|
|
4895
4844
|
this.limits = new WebGLDeviceLimits(this.gl);
|
|
4896
|
-
this.features = new WebGLDeviceFeatures(this.gl, this._extensions, this.props.
|
|
4897
|
-
if (this.props.
|
|
4845
|
+
this.features = new WebGLDeviceFeatures(this.gl, this._extensions, this.props._disabledFeatures);
|
|
4846
|
+
if (this.props._initializeFeatures) {
|
|
4898
4847
|
this.features.initializeFeatures();
|
|
4899
4848
|
}
|
|
4900
4849
|
this.canvasContext.resize();
|
|
@@ -4902,11 +4851,14 @@ var WebGLDevice = class extends import_core23.Device {
|
|
|
4902
4851
|
log: (...args) => import_core23.log.log(1, ...args)()
|
|
4903
4852
|
});
|
|
4904
4853
|
glState.trackState(this.gl, { copyState: false });
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4854
|
+
const debugWebGL = props.debugWebGL || props.debug;
|
|
4855
|
+
const traceWebGL = props.debugWebGL;
|
|
4856
|
+
if (debugWebGL) {
|
|
4857
|
+
this.gl = makeDebugContext(this.gl, { debugWebGL, traceWebGL });
|
|
4909
4858
|
import_core23.log.warn("WebGL debug mode activated. Performance reduced.")();
|
|
4859
|
+
if (props.debugWebGL) {
|
|
4860
|
+
import_core23.log.level = Math.max(import_core23.log.level, 1);
|
|
4861
|
+
}
|
|
4910
4862
|
}
|
|
4911
4863
|
}
|
|
4912
4864
|
/**
|
|
@@ -4932,7 +4884,7 @@ var WebGLDevice = class extends import_core23.Device {
|
|
|
4932
4884
|
throw new Error("WebGL only supports a single canvas");
|
|
4933
4885
|
}
|
|
4934
4886
|
createBuffer(props) {
|
|
4935
|
-
const newProps = this.
|
|
4887
|
+
const newProps = this._normalizeBufferProps(props);
|
|
4936
4888
|
return new WEBGLBuffer(this, newProps);
|
|
4937
4889
|
}
|
|
4938
4890
|
createTexture(props) {
|
|
@@ -5056,15 +5008,24 @@ var WebGLDevice = class extends import_core23.Device {
|
|
|
5056
5008
|
* Be aware that there are some duplicates especially for constants that are 0,
|
|
5057
5009
|
* so this isn't guaranteed to return the right key in all cases.
|
|
5058
5010
|
*/
|
|
5059
|
-
getGLKey(value,
|
|
5060
|
-
gl = gl || this.gl2 || this.gl;
|
|
5011
|
+
getGLKey(value, options) {
|
|
5061
5012
|
const number = Number(value);
|
|
5062
|
-
for (const key in gl) {
|
|
5063
|
-
if (gl[key] === number) {
|
|
5013
|
+
for (const key in this.gl) {
|
|
5014
|
+
if (this.gl[key] === number) {
|
|
5064
5015
|
return `GL.${key}`;
|
|
5065
5016
|
}
|
|
5066
5017
|
}
|
|
5067
|
-
return String(value);
|
|
5018
|
+
return (options == null ? void 0 : options.emptyIfUnknown) ? "" : String(value);
|
|
5019
|
+
}
|
|
5020
|
+
/**
|
|
5021
|
+
* Returns a map with any GL.<KEY> constants mapped to strings, both for keys and values
|
|
5022
|
+
*/
|
|
5023
|
+
getGLKeys(glParameters) {
|
|
5024
|
+
const opts = { emptyIfUnknown: true };
|
|
5025
|
+
return Object.entries(glParameters).reduce((keys, [key, value]) => {
|
|
5026
|
+
keys[`${key}:${this.getGLKey(key, opts)}`] = `${value}:${this.getGLKey(value, opts)}`;
|
|
5027
|
+
return keys;
|
|
5028
|
+
}, {});
|
|
5068
5029
|
}
|
|
5069
5030
|
/** Store constants */
|
|
5070
5031
|
_constants;
|
|
@@ -5276,27 +5237,23 @@ var WebGLAdapter = class extends import_core24.Adapter {
|
|
|
5276
5237
|
if (!isWebGL(gl)) {
|
|
5277
5238
|
throw new Error("Invalid WebGL2RenderingContext");
|
|
5278
5239
|
}
|
|
5279
|
-
return new WebGLDevice({ gl });
|
|
5240
|
+
return new WebGLDevice({ _handle: gl });
|
|
5280
5241
|
}
|
|
5281
5242
|
async create(props = {}) {
|
|
5282
5243
|
import_core24.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
|
|
5283
5244
|
const promises = [];
|
|
5284
|
-
if (props.debug) {
|
|
5245
|
+
if (props.debugWebGL || props.debug) {
|
|
5285
5246
|
promises.push(loadWebGLDeveloperTools());
|
|
5286
5247
|
}
|
|
5287
|
-
if (props.
|
|
5248
|
+
if (props.debugSpectorJS) {
|
|
5288
5249
|
promises.push(loadSpectorJS(props));
|
|
5289
5250
|
}
|
|
5290
|
-
if (typeof props.canvas === "string") {
|
|
5291
|
-
promises.push(import_core24.CanvasContext.pageLoaded);
|
|
5292
|
-
}
|
|
5293
5251
|
const results = await Promise.allSettled(promises);
|
|
5294
5252
|
for (const result of results) {
|
|
5295
5253
|
if (result.status === "rejected") {
|
|
5296
5254
|
import_core24.log.error(`Failed to initialize debug libraries ${result.reason}`)();
|
|
5297
5255
|
}
|
|
5298
5256
|
}
|
|
5299
|
-
import_core24.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
|
|
5300
5257
|
const device = new WebGLDevice(props);
|
|
5301
5258
|
const message2 = `Created ${device.type}${device.debug ? " debug" : ""} context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
|
|
5302
5259
|
import_core24.log.probe(LOG_LEVEL2, message2)();
|