@luma.gl/webgl 9.0.11 → 9.1.0-alpha.2
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/LICENSE +34 -0
- package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/device-parameters.js +12 -1
- package/dist/adapter/converters/texture-formats.d.ts +22 -16
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +31 -32
- package/dist/adapter/device-helpers/webgl-device-features.js +1 -1
- package/dist/adapter/device-helpers/webgl-device-limits.js +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.d.ts +300 -0
- package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -0
- package/dist/adapter/helpers/webgl-texture-utils.js +368 -0
- package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-topology-utils.js +0 -4
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +2 -2
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +6 -9
- package/dist/adapter/resources/webgl-framebuffer.d.ts +32 -5
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +42 -60
- package/dist/adapter/resources/webgl-render-pass.d.ts +3 -2
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +1 -3
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +45 -20
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +2 -2
- package/dist/adapter/resources/webgl-texture-view.d.ts +1 -1
- package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture-view.js +1 -1
- package/dist/adapter/resources/webgl-texture.d.ts +58 -172
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +402 -510
- package/dist/adapter/resources/webgl-transform-feedback.js +1 -1
- package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -2
- package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-vertex-array.js +5 -2
- package/dist/adapter/webgl-canvas-context.d.ts +3 -1
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js +2 -0
- package/dist/adapter/webgl-device.d.ts +4 -3
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +6 -5
- package/dist/classic/accessor.d.ts +22 -1
- package/dist/classic/accessor.d.ts.map +1 -1
- package/dist/classic/accessor.js +1 -9
- package/dist/classic/clear.d.ts.map +1 -1
- package/dist/classic/clear.js +2 -5
- package/dist/classic/copy-and-blit.d.ts +2 -1
- package/dist/classic/copy-and-blit.d.ts.map +1 -1
- package/dist/classic/copy-and-blit.js +11 -9
- package/dist/classic/format-utils.d.ts.map +1 -1
- package/dist/classic/format-utils.js +0 -3
- package/dist/classic/typed-array-utils.d.ts +1 -1
- package/dist/classic/typed-array-utils.d.ts.map +1 -1
- package/dist/context/debug/spector.d.ts.map +1 -1
- package/dist/context/debug/spector.js +2 -1
- package/dist/context/debug/webgl-developer-tools.d.ts +1 -1
- package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +2 -5
- package/dist/context/parameters/webgl-parameter-tables.js +1 -1
- package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
- package/dist/context/state-tracker/track-context-state.js +5 -6
- package/dist/dist.dev.js +872 -1262
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +861 -1138
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -3
- package/dist/utils/fill-array.d.ts +8 -0
- package/dist/utils/fill-array.d.ts.map +1 -0
- package/dist/utils/fill-array.js +26 -0
- package/dist/utils/load-script.d.ts +8 -0
- package/dist/utils/load-script.d.ts.map +1 -0
- package/dist/utils/load-script.js +26 -0
- package/dist/utils/split-uniforms-and-bindings.d.ts +9 -0
- package/dist/utils/split-uniforms-and-bindings.d.ts.map +1 -0
- package/dist/utils/split-uniforms-and-bindings.js +20 -0
- package/package.json +6 -5
- package/src/adapter/converters/device-parameters.ts +13 -1
- package/src/adapter/converters/texture-formats.ts +45 -42
- package/src/adapter/device-helpers/webgl-device-features.ts +1 -1
- package/src/adapter/device-helpers/webgl-device-limits.ts +1 -1
- package/src/adapter/helpers/webgl-texture-utils.ts +481 -0
- package/src/adapter/helpers/webgl-topology-utils.ts +0 -4
- package/src/adapter/resources/webgl-buffer.ts +2 -2
- package/src/adapter/resources/webgl-command-buffer.ts +8 -10
- package/src/adapter/resources/webgl-framebuffer.ts +22 -56
- package/src/adapter/resources/webgl-render-pass.ts +4 -5
- package/src/adapter/resources/webgl-render-pipeline.ts +48 -23
- package/src/adapter/resources/webgl-shader.ts +3 -3
- package/src/adapter/resources/webgl-texture-view.ts +1 -3
- package/src/adapter/resources/webgl-texture.ts +432 -784
- package/src/adapter/resources/webgl-transform-feedback.ts +1 -1
- package/src/adapter/resources/webgl-vertex-array.ts +11 -7
- package/src/adapter/webgl-canvas-context.ts +4 -1
- package/src/adapter/webgl-device.ts +10 -18
- package/src/classic/accessor.ts +31 -11
- package/src/classic/clear.ts +3 -6
- package/src/classic/copy-and-blit.ts +19 -19
- package/src/classic/format-utils.ts +0 -3
- package/src/classic/typed-array-utils.ts +1 -1
- package/src/context/debug/spector.ts +2 -1
- package/src/context/debug/webgl-developer-tools.ts +3 -7
- package/src/context/parameters/webgl-parameter-tables.ts +3 -3
- package/src/context/state-tracker/track-context-state.ts +5 -6
- package/src/index.ts +0 -6
- package/src/utils/fill-array.ts +35 -0
- package/src/utils/load-script.ts +30 -0
- package/src/utils/split-uniforms-and-bindings.ts +31 -0
- package/dist/adapter/objects/constants-to-keys.d.ts +0 -3
- package/dist/adapter/objects/constants-to-keys.d.ts.map +0 -1
- package/dist/adapter/objects/constants-to-keys.js +0 -22
- package/dist/adapter/objects/webgl-renderbuffer.d.ts +0 -43
- package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +0 -1
- package/dist/adapter/objects/webgl-renderbuffer.js +0 -95
- package/dist/adapter/objects/webgl-resource.d.ts +0 -32
- package/dist/adapter/objects/webgl-resource.d.ts.map +0 -1
- package/dist/adapter/objects/webgl-resource.js +0 -114
- package/src/adapter/objects/constants-to-keys.ts +0 -27
- package/src/adapter/objects/webgl-renderbuffer.ts +0 -132
- package/src/adapter/objects/webgl-resource.ts +0 -183
package/dist/dist.dev.js
CHANGED
|
@@ -58,7 +58,6 @@ var __exports__ = (() => {
|
|
|
58
58
|
WEBGLFramebuffer: () => WEBGLFramebuffer,
|
|
59
59
|
WEBGLRenderPass: () => WEBGLRenderPass,
|
|
60
60
|
WEBGLRenderPipeline: () => WEBGLRenderPipeline,
|
|
61
|
-
WEBGLResource: () => WebGLResource,
|
|
62
61
|
WEBGLSampler: () => WEBGLSampler,
|
|
63
62
|
WEBGLShader: () => WEBGLShader,
|
|
64
63
|
WEBGLTexture: () => WEBGLTexture,
|
|
@@ -66,10 +65,7 @@ var __exports__ = (() => {
|
|
|
66
65
|
WEBGLVertexArray: () => WEBGLVertexArray,
|
|
67
66
|
WebGLCanvasContext: () => WebGLCanvasContext,
|
|
68
67
|
WebGLDevice: () => WebGLDevice,
|
|
69
|
-
WebGLResource: () => WebGLResource,
|
|
70
68
|
_TEXTURE_FORMATS: () => TEXTURE_FORMATS,
|
|
71
|
-
_WEBGLRenderbuffer: () => WEBGLRenderbuffer,
|
|
72
|
-
convertGLToTextureFormat: () => convertGLToTextureFormat,
|
|
73
69
|
getGLParameters: () => getGLParameters,
|
|
74
70
|
getShaderLayout: () => getShaderLayout,
|
|
75
71
|
popContextState: () => popContextState,
|
|
@@ -84,10 +80,7 @@ var __exports__ = (() => {
|
|
|
84
80
|
__reExport(bundle_exports, __toESM(require_core(), 1));
|
|
85
81
|
|
|
86
82
|
// src/adapter/webgl-device.ts
|
|
87
|
-
var
|
|
88
|
-
|
|
89
|
-
// src/context/state-tracker/track-context-state.ts
|
|
90
|
-
var import_core = __toESM(require_core(), 1);
|
|
83
|
+
var import_core22 = __toESM(require_core(), 1);
|
|
91
84
|
|
|
92
85
|
// ../constants/src/webgl-constants.ts
|
|
93
86
|
var GLEnum = /* @__PURE__ */ ((GLEnum2) => {
|
|
@@ -970,7 +963,7 @@ var __exports__ = (() => {
|
|
|
970
963
|
lineWidth: (gl, value) => gl.lineWidth(value),
|
|
971
964
|
polygonOffsetFill: (gl, value) => value ? gl.enable(32823 /* POLYGON_OFFSET_FILL */) : gl.disable(32823 /* POLYGON_OFFSET_FILL */),
|
|
972
965
|
polygonOffset: (gl, value) => gl.polygonOffset(...value),
|
|
973
|
-
sampleCoverage: (gl, value) => gl.sampleCoverage(
|
|
966
|
+
sampleCoverage: (gl, value) => gl.sampleCoverage(value[0], value[1] || false),
|
|
974
967
|
scissorTest: (gl, value) => value ? gl.enable(3089 /* SCISSOR_TEST */) : gl.disable(3089 /* SCISSOR_TEST */),
|
|
975
968
|
scissor: (gl, value) => gl.scissor(...value),
|
|
976
969
|
stencilTest: (gl, value) => value ? gl.enable(2960 /* STENCIL_TEST */) : gl.disable(2960 /* STENCIL_TEST */),
|
|
@@ -1341,7 +1334,6 @@ var __exports__ = (() => {
|
|
|
1341
1334
|
this.stateStack.push({});
|
|
1342
1335
|
}
|
|
1343
1336
|
pop() {
|
|
1344
|
-
(0, import_core.assert)(this.stateStack.length > 0);
|
|
1345
1337
|
const oldValues = this.stateStack[this.stateStack.length - 1];
|
|
1346
1338
|
setGLParameters(this.gl, oldValues);
|
|
1347
1339
|
this.stateStack.pop();
|
|
@@ -1357,7 +1349,6 @@ var __exports__ = (() => {
|
|
|
1357
1349
|
let oldValue;
|
|
1358
1350
|
const oldValues = this.stateStack.length > 0 ? this.stateStack[this.stateStack.length - 1] : null;
|
|
1359
1351
|
for (const key in values) {
|
|
1360
|
-
(0, import_core.assert)(key !== void 0);
|
|
1361
1352
|
const value = values[key];
|
|
1362
1353
|
const cached = this.cache[key];
|
|
1363
1354
|
if (!deepArrayEqual(value, cached)) {
|
|
@@ -1376,8 +1367,7 @@ var __exports__ = (() => {
|
|
|
1376
1367
|
return gl.state;
|
|
1377
1368
|
}
|
|
1378
1369
|
function trackContextState(gl, options) {
|
|
1379
|
-
const { enable: enable2 = true, copyState } = options;
|
|
1380
|
-
(0, import_core.assert)(copyState !== void 0);
|
|
1370
|
+
const { enable: enable2 = true, copyState } = options || {};
|
|
1381
1371
|
if (!gl.state) {
|
|
1382
1372
|
gl.state = new GLState(gl, { copyState });
|
|
1383
1373
|
installProgramSpy(gl);
|
|
@@ -1402,7 +1392,6 @@ var __exports__ = (() => {
|
|
|
1402
1392
|
}
|
|
1403
1393
|
function popContextState(gl) {
|
|
1404
1394
|
const glState = getContextState(gl);
|
|
1405
|
-
(0, import_core.assert)(glState);
|
|
1406
1395
|
glState.pop();
|
|
1407
1396
|
}
|
|
1408
1397
|
function installGetterOverride(gl, functionName) {
|
|
@@ -1573,10 +1562,10 @@ var __exports__ = (() => {
|
|
|
1573
1562
|
}
|
|
1574
1563
|
|
|
1575
1564
|
// src/adapter/device-helpers/webgl-device-features.ts
|
|
1576
|
-
var
|
|
1565
|
+
var import_core2 = __toESM(require_core(), 1);
|
|
1577
1566
|
|
|
1578
1567
|
// src/adapter/converters/texture-formats.ts
|
|
1579
|
-
var
|
|
1568
|
+
var import_core = __toESM(require_core(), 1);
|
|
1580
1569
|
|
|
1581
1570
|
// src/adapter/converters/vertex-formats.ts
|
|
1582
1571
|
function getGLFromVertexType(dataType) {
|
|
@@ -1719,7 +1708,6 @@ var __exports__ = (() => {
|
|
|
1719
1708
|
"bgra8unorm-srgb": { b: 4, c: 4 },
|
|
1720
1709
|
"rg16uint": { gl: 33338 /* RG16UI */, b: 4, c: 1, bpp: 4 },
|
|
1721
1710
|
"rg16sint": { gl: 33337 /* RG16I */, b: 4, c: 2, bpp: 4 },
|
|
1722
|
-
// When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension
|
|
1723
1711
|
"rg16float": { gl: 33327 /* RG16F */, bpp: 4, b: 4, c: 2, render: float16_renderable, filter: float16_filterable, rb: true },
|
|
1724
1712
|
"rg16unorm-webgl": { gl: 33324 /* RG16_EXT */, b: 2, c: 2, render: norm16_renderable },
|
|
1725
1713
|
"rg16snorm-webgl": { gl: 36761 /* RG16_SNORM_EXT */, b: 2, c: 2, render: snorm16_renderable },
|
|
@@ -1932,27 +1920,6 @@ var __exports__ = (() => {
|
|
|
1932
1920
|
}
|
|
1933
1921
|
return true;
|
|
1934
1922
|
}
|
|
1935
|
-
function isRenderbufferFormatSupported(gl, format, extensions) {
|
|
1936
|
-
return isTextureFormatSupported(gl, format, extensions) && TEXTURE_FORMATS[format]?.rb;
|
|
1937
|
-
}
|
|
1938
|
-
function convertGLToTextureFormat(format) {
|
|
1939
|
-
if (typeof format === "string") {
|
|
1940
|
-
return format;
|
|
1941
|
-
}
|
|
1942
|
-
const entry = Object.entries(TEXTURE_FORMATS).find(([, entry2]) => entry2.gl === format);
|
|
1943
|
-
if (!entry) {
|
|
1944
|
-
throw new Error(`Unknown texture format ${format}`);
|
|
1945
|
-
}
|
|
1946
|
-
return entry[0];
|
|
1947
|
-
}
|
|
1948
|
-
function convertTextureFormatToGL(format) {
|
|
1949
|
-
const formatInfo = TEXTURE_FORMATS[format];
|
|
1950
|
-
const webglFormat = formatInfo?.gl;
|
|
1951
|
-
if (webglFormat === void 0) {
|
|
1952
|
-
throw new Error(`Unsupported texture format ${format}`);
|
|
1953
|
-
}
|
|
1954
|
-
return webglFormat;
|
|
1955
|
-
}
|
|
1956
1923
|
function isTextureFormatFilterable(gl, format, extensions) {
|
|
1957
1924
|
if (!isTextureFormatSupported(gl, format, extensions)) {
|
|
1958
1925
|
return false;
|
|
@@ -1961,7 +1928,7 @@ var __exports__ = (() => {
|
|
|
1961
1928
|
return false;
|
|
1962
1929
|
}
|
|
1963
1930
|
try {
|
|
1964
|
-
const decoded = (0,
|
|
1931
|
+
const decoded = (0, import_core.decodeTextureFormat)(format);
|
|
1965
1932
|
if (decoded.signed) {
|
|
1966
1933
|
return false;
|
|
1967
1934
|
}
|
|
@@ -1985,13 +1952,13 @@ var __exports__ = (() => {
|
|
|
1985
1952
|
}
|
|
1986
1953
|
return true;
|
|
1987
1954
|
}
|
|
1988
|
-
function
|
|
1955
|
+
function getTextureFormatWebGL(format) {
|
|
1989
1956
|
const formatData = TEXTURE_FORMATS[format];
|
|
1990
1957
|
const webglFormat = convertTextureFormatToGL(format);
|
|
1991
|
-
const decoded = (0,
|
|
1958
|
+
const decoded = (0, import_core.decodeTextureFormat)(format);
|
|
1992
1959
|
return {
|
|
1993
|
-
|
|
1994
|
-
|
|
1960
|
+
internalFormat: webglFormat,
|
|
1961
|
+
format: formatData?.dataFormat || getWebGLPixelDataFormat(decoded.format, decoded.integer, decoded.normalized, webglFormat),
|
|
1995
1962
|
// depth formats don't have a type
|
|
1996
1963
|
type: decoded.dataType ? getGLFromVertexType(decoded.dataType) : formatData?.types?.[0] || 5121 /* UNSIGNED_BYTE */,
|
|
1997
1964
|
// @ts-expect-error
|
|
@@ -2005,12 +1972,6 @@ var __exports__ = (() => {
|
|
|
2005
1972
|
}
|
|
2006
1973
|
return info.attachment;
|
|
2007
1974
|
}
|
|
2008
|
-
function getTextureFormatBytesPerPixel(format) {
|
|
2009
|
-
const params = getWebGLTextureParameters(format);
|
|
2010
|
-
const channels = DATA_FORMAT_CHANNELS[params.dataFormat] || 4;
|
|
2011
|
-
const channelSize = TYPE_SIZES[params.type] || 1;
|
|
2012
|
-
return channels * channelSize;
|
|
2013
|
-
}
|
|
2014
1975
|
function getWebGLPixelDataFormat(dataFormat, integer, normalized, format) {
|
|
2015
1976
|
if (format === 6408 /* RGBA */ || format === 6407 /* RGB */) {
|
|
2016
1977
|
return format;
|
|
@@ -2028,6 +1989,14 @@ var __exports__ = (() => {
|
|
|
2028
1989
|
return 6408 /* RGBA */;
|
|
2029
1990
|
}
|
|
2030
1991
|
}
|
|
1992
|
+
function convertTextureFormatToGL(format) {
|
|
1993
|
+
const formatInfo = TEXTURE_FORMATS[format];
|
|
1994
|
+
const webglFormat = formatInfo?.gl;
|
|
1995
|
+
if (webglFormat === void 0) {
|
|
1996
|
+
throw new Error(`Unsupported texture format ${format}`);
|
|
1997
|
+
}
|
|
1998
|
+
return webglFormat;
|
|
1999
|
+
}
|
|
2031
2000
|
|
|
2032
2001
|
// src/adapter/device-helpers/webgl-device-features.ts
|
|
2033
2002
|
var WEBGL_FEATURES = {
|
|
@@ -2049,7 +2018,7 @@ var __exports__ = (() => {
|
|
|
2049
2018
|
"shader-conservative-depth-webgl": "EXT_conservative_depth"
|
|
2050
2019
|
// Textures are handled by getTextureFeatures()
|
|
2051
2020
|
};
|
|
2052
|
-
var WebGLDeviceFeatures = class extends
|
|
2021
|
+
var WebGLDeviceFeatures = class extends import_core2.DeviceFeatures {
|
|
2053
2022
|
gl;
|
|
2054
2023
|
extensions;
|
|
2055
2024
|
testedFeatures = /* @__PURE__ */ new Set();
|
|
@@ -2069,7 +2038,7 @@ var __exports__ = (() => {
|
|
|
2069
2038
|
return [];
|
|
2070
2039
|
}
|
|
2071
2040
|
has(feature) {
|
|
2072
|
-
if (this.disabledFeatures[feature]) {
|
|
2041
|
+
if (this.disabledFeatures?.[feature]) {
|
|
2073
2042
|
return false;
|
|
2074
2043
|
}
|
|
2075
2044
|
if (!this.testedFeatures.has(feature)) {
|
|
@@ -2103,8 +2072,8 @@ var __exports__ = (() => {
|
|
|
2103
2072
|
};
|
|
2104
2073
|
|
|
2105
2074
|
// src/adapter/device-helpers/webgl-device-limits.ts
|
|
2106
|
-
var
|
|
2107
|
-
var WebGLDeviceLimits = class extends
|
|
2075
|
+
var import_core3 = __toESM(require_core(), 1);
|
|
2076
|
+
var WebGLDeviceLimits = class extends import_core3.DeviceLimits {
|
|
2108
2077
|
get maxTextureDimension1D() {
|
|
2109
2078
|
return 0;
|
|
2110
2079
|
}
|
|
@@ -2208,18 +2177,18 @@ var __exports__ = (() => {
|
|
|
2208
2177
|
if (this.limits[parameter] === void 0) {
|
|
2209
2178
|
this.limits[parameter] = this.gl.getParameter(parameter);
|
|
2210
2179
|
}
|
|
2211
|
-
return this.limits[parameter];
|
|
2180
|
+
return this.limits[parameter] || 0;
|
|
2212
2181
|
}
|
|
2213
2182
|
};
|
|
2214
2183
|
|
|
2215
2184
|
// src/adapter/webgl-canvas-context.ts
|
|
2216
|
-
var
|
|
2185
|
+
var import_core9 = __toESM(require_core(), 1);
|
|
2217
2186
|
|
|
2218
2187
|
// src/adapter/resources/webgl-framebuffer.ts
|
|
2219
|
-
var
|
|
2188
|
+
var import_core8 = __toESM(require_core(), 1);
|
|
2220
2189
|
|
|
2221
2190
|
// src/adapter/resources/webgl-texture.ts
|
|
2222
|
-
var
|
|
2191
|
+
var import_core7 = __toESM(require_core(), 1);
|
|
2223
2192
|
|
|
2224
2193
|
// src/context/state-tracker/with-parameters.ts
|
|
2225
2194
|
function withGLParameters(gl, parameters, func) {
|
|
@@ -2250,9 +2219,9 @@ var __exports__ = (() => {
|
|
|
2250
2219
|
}
|
|
2251
2220
|
|
|
2252
2221
|
// src/adapter/converters/device-parameters.ts
|
|
2253
|
-
var
|
|
2222
|
+
var import_core4 = __toESM(require_core(), 1);
|
|
2254
2223
|
function withDeviceAndGLParameters(device, parameters, glParameters, func) {
|
|
2255
|
-
if ((
|
|
2224
|
+
if (isObjectEmpty3(parameters)) {
|
|
2256
2225
|
return func(device);
|
|
2257
2226
|
}
|
|
2258
2227
|
const webglDevice = device;
|
|
@@ -2266,7 +2235,7 @@ var __exports__ = (() => {
|
|
|
2266
2235
|
}
|
|
2267
2236
|
}
|
|
2268
2237
|
function withDeviceParameters(device, parameters, func) {
|
|
2269
|
-
if ((
|
|
2238
|
+
if (isObjectEmpty3(parameters)) {
|
|
2270
2239
|
return func(device);
|
|
2271
2240
|
}
|
|
2272
2241
|
pushContextState(device.gl);
|
|
@@ -2383,7 +2352,7 @@ var __exports__ = (() => {
|
|
|
2383
2352
|
gl.stencilMaskSeparate(1029 /* BACK */, mask);
|
|
2384
2353
|
}
|
|
2385
2354
|
if (parameters.stencilReadMask) {
|
|
2386
|
-
|
|
2355
|
+
import_core4.log.warn("stencilReadMask not supported under WebGL");
|
|
2387
2356
|
}
|
|
2388
2357
|
if (parameters.stencilCompare) {
|
|
2389
2358
|
const mask = parameters.stencilReadMask || 4294967295;
|
|
@@ -2496,6 +2465,14 @@ var __exports__ = (() => {
|
|
|
2496
2465
|
function mapBoolean(parameter, value) {
|
|
2497
2466
|
return value;
|
|
2498
2467
|
}
|
|
2468
|
+
function isObjectEmpty3(obj) {
|
|
2469
|
+
let isEmpty = true;
|
|
2470
|
+
for (const key in obj) {
|
|
2471
|
+
isEmpty = false;
|
|
2472
|
+
break;
|
|
2473
|
+
}
|
|
2474
|
+
return isEmpty;
|
|
2475
|
+
}
|
|
2499
2476
|
|
|
2500
2477
|
// src/adapter/converters/sampler-parameters.ts
|
|
2501
2478
|
function convertSamplerParametersToWebGL(props) {
|
|
@@ -2565,134 +2542,9 @@ var __exports__ = (() => {
|
|
|
2565
2542
|
}
|
|
2566
2543
|
}
|
|
2567
2544
|
|
|
2568
|
-
// src/adapter/resources/webgl-buffer.ts
|
|
2569
|
-
var import_core6 = __toESM(require_core(), 1);
|
|
2570
|
-
var WEBGLBuffer = class extends import_core6.Buffer {
|
|
2571
|
-
device;
|
|
2572
|
-
gl;
|
|
2573
|
-
handle;
|
|
2574
|
-
/** Target in OpenGL defines the type of buffer */
|
|
2575
|
-
glTarget;
|
|
2576
|
-
/** Usage is a hint on how frequently the buffer will be updates */
|
|
2577
|
-
glUsage;
|
|
2578
|
-
/** Index type is needed when issuing draw calls, so we pre-compute it */
|
|
2579
|
-
glIndexType = 5123 /* UNSIGNED_SHORT */;
|
|
2580
|
-
/** Number of bytes allocated on the GPU for this buffer */
|
|
2581
|
-
byteLength;
|
|
2582
|
-
/** Number of bytes used */
|
|
2583
|
-
bytesUsed;
|
|
2584
|
-
constructor(device, props = {}) {
|
|
2585
|
-
super(device, props);
|
|
2586
|
-
this.device = device;
|
|
2587
|
-
this.gl = this.device.gl;
|
|
2588
|
-
const handle = typeof props === "object" ? props.handle : void 0;
|
|
2589
|
-
this.handle = handle || this.gl.createBuffer();
|
|
2590
|
-
device.setSpectorMetadata(this.handle, { ...this.props, data: typeof this.props.data });
|
|
2591
|
-
this.glTarget = getWebGLTarget(this.props.usage);
|
|
2592
|
-
this.glUsage = getWebGLUsage(this.props.usage);
|
|
2593
|
-
this.glIndexType = this.props.indexType === "uint32" ? 5125 /* UNSIGNED_INT */ : 5123 /* UNSIGNED_SHORT */;
|
|
2594
|
-
if (props.data) {
|
|
2595
|
-
this._initWithData(props.data, props.byteOffset, props.byteLength);
|
|
2596
|
-
} else {
|
|
2597
|
-
this._initWithByteLength(props.byteLength || 0);
|
|
2598
|
-
}
|
|
2599
|
-
}
|
|
2600
|
-
// PRIVATE METHODS
|
|
2601
|
-
/** Allocate a new buffer and initialize to contents of typed array */
|
|
2602
|
-
_initWithData(data, byteOffset = 0, byteLength = data.byteLength + byteOffset) {
|
|
2603
|
-
const glTarget = this.glTarget;
|
|
2604
|
-
this.gl.bindBuffer(glTarget, this.handle);
|
|
2605
|
-
this.gl.bufferData(glTarget, byteLength, this.glUsage);
|
|
2606
|
-
this.gl.bufferSubData(glTarget, byteOffset, data);
|
|
2607
|
-
this.gl.bindBuffer(glTarget, null);
|
|
2608
|
-
this.bytesUsed = byteLength;
|
|
2609
|
-
this.byteLength = byteLength;
|
|
2610
|
-
this._setDebugData(data, byteOffset, byteLength);
|
|
2611
|
-
this.trackAllocatedMemory(byteLength);
|
|
2612
|
-
}
|
|
2613
|
-
// Allocate a GPU buffer of specified size.
|
|
2614
|
-
_initWithByteLength(byteLength) {
|
|
2615
|
-
(0, import_core6.assert)(byteLength >= 0);
|
|
2616
|
-
let data = byteLength;
|
|
2617
|
-
if (byteLength === 0) {
|
|
2618
|
-
data = new Float32Array(0);
|
|
2619
|
-
}
|
|
2620
|
-
const glTarget = this.glTarget;
|
|
2621
|
-
this.gl.bindBuffer(glTarget, this.handle);
|
|
2622
|
-
this.gl.bufferData(glTarget, data, this.glUsage);
|
|
2623
|
-
this.gl.bindBuffer(glTarget, null);
|
|
2624
|
-
this.bytesUsed = byteLength;
|
|
2625
|
-
this.byteLength = byteLength;
|
|
2626
|
-
this._setDebugData(null, 0, byteLength);
|
|
2627
|
-
this.trackAllocatedMemory(byteLength);
|
|
2628
|
-
return this;
|
|
2629
|
-
}
|
|
2630
|
-
destroy() {
|
|
2631
|
-
if (!this.destroyed && this.handle) {
|
|
2632
|
-
this.removeStats();
|
|
2633
|
-
this.trackDeallocatedMemory();
|
|
2634
|
-
this.gl.deleteBuffer(this.handle);
|
|
2635
|
-
this.destroyed = true;
|
|
2636
|
-
this.handle = null;
|
|
2637
|
-
}
|
|
2638
|
-
}
|
|
2639
|
-
write(data, byteOffset = 0) {
|
|
2640
|
-
const srcOffset = 0;
|
|
2641
|
-
const byteLength = void 0;
|
|
2642
|
-
const glTarget = 36663 /* COPY_WRITE_BUFFER */;
|
|
2643
|
-
this.gl.bindBuffer(glTarget, this.handle);
|
|
2644
|
-
if (srcOffset !== 0 || byteLength !== void 0) {
|
|
2645
|
-
this.gl.bufferSubData(glTarget, byteOffset, data, srcOffset, byteLength);
|
|
2646
|
-
} else {
|
|
2647
|
-
this.gl.bufferSubData(glTarget, byteOffset, data);
|
|
2648
|
-
}
|
|
2649
|
-
this.gl.bindBuffer(glTarget, null);
|
|
2650
|
-
this._setDebugData(data, byteOffset, data.byteLength);
|
|
2651
|
-
}
|
|
2652
|
-
/** Asynchronously read data from the buffer */
|
|
2653
|
-
async readAsync(byteOffset = 0, byteLength) {
|
|
2654
|
-
return this.readSyncWebGL(byteOffset, byteLength);
|
|
2655
|
-
}
|
|
2656
|
-
/** Synchronously read data from the buffer. WebGL only. */
|
|
2657
|
-
readSyncWebGL(byteOffset = 0, byteLength) {
|
|
2658
|
-
byteLength = byteLength ?? this.byteLength - byteOffset;
|
|
2659
|
-
const data = new Uint8Array(byteLength);
|
|
2660
|
-
const dstOffset = 0;
|
|
2661
|
-
this.gl.bindBuffer(36662 /* COPY_READ_BUFFER */, this.handle);
|
|
2662
|
-
this.gl.getBufferSubData(36662 /* COPY_READ_BUFFER */, byteOffset, data, dstOffset, byteLength);
|
|
2663
|
-
this.gl.bindBuffer(36662 /* COPY_READ_BUFFER */, null);
|
|
2664
|
-
this._setDebugData(data, byteOffset, byteLength);
|
|
2665
|
-
return data;
|
|
2666
|
-
}
|
|
2667
|
-
};
|
|
2668
|
-
function getWebGLTarget(usage) {
|
|
2669
|
-
if (usage & import_core6.Buffer.INDEX) {
|
|
2670
|
-
return 34963 /* ELEMENT_ARRAY_BUFFER */;
|
|
2671
|
-
}
|
|
2672
|
-
if (usage & import_core6.Buffer.VERTEX) {
|
|
2673
|
-
return 34962 /* ARRAY_BUFFER */;
|
|
2674
|
-
}
|
|
2675
|
-
if (usage & import_core6.Buffer.UNIFORM) {
|
|
2676
|
-
return 35345 /* UNIFORM_BUFFER */;
|
|
2677
|
-
}
|
|
2678
|
-
return 34962 /* ARRAY_BUFFER */;
|
|
2679
|
-
}
|
|
2680
|
-
function getWebGLUsage(usage) {
|
|
2681
|
-
if (usage & import_core6.Buffer.INDEX) {
|
|
2682
|
-
return 35044 /* STATIC_DRAW */;
|
|
2683
|
-
}
|
|
2684
|
-
if (usage & import_core6.Buffer.VERTEX) {
|
|
2685
|
-
return 35044 /* STATIC_DRAW */;
|
|
2686
|
-
}
|
|
2687
|
-
if (usage & import_core6.Buffer.UNIFORM) {
|
|
2688
|
-
return 35048 /* DYNAMIC_DRAW */;
|
|
2689
|
-
}
|
|
2690
|
-
return 35044 /* STATIC_DRAW */;
|
|
2691
|
-
}
|
|
2692
|
-
|
|
2693
2545
|
// src/adapter/resources/webgl-sampler.ts
|
|
2694
|
-
var
|
|
2695
|
-
var WEBGLSampler = class extends
|
|
2546
|
+
var import_core5 = __toESM(require_core(), 1);
|
|
2547
|
+
var WEBGLSampler = class extends import_core5.Sampler {
|
|
2696
2548
|
device;
|
|
2697
2549
|
handle;
|
|
2698
2550
|
parameters;
|
|
@@ -2730,14 +2582,15 @@ var __exports__ = (() => {
|
|
|
2730
2582
|
};
|
|
2731
2583
|
|
|
2732
2584
|
// src/adapter/resources/webgl-texture-view.ts
|
|
2733
|
-
var
|
|
2734
|
-
var WEBGLTextureView = class extends
|
|
2585
|
+
var import_core6 = __toESM(require_core(), 1);
|
|
2586
|
+
var WEBGLTextureView = class extends import_core6.TextureView {
|
|
2735
2587
|
device;
|
|
2736
2588
|
gl;
|
|
2737
2589
|
handle;
|
|
2590
|
+
// Does not have a WebGL representation
|
|
2738
2591
|
texture;
|
|
2739
2592
|
constructor(device, props) {
|
|
2740
|
-
super(device, { ...
|
|
2593
|
+
super(device, { ...import_core6.Texture.defaultProps, ...props });
|
|
2741
2594
|
this.device = device;
|
|
2742
2595
|
this.gl = this.device.gl;
|
|
2743
2596
|
this.handle = null;
|
|
@@ -2745,63 +2598,239 @@ var __exports__ = (() => {
|
|
|
2745
2598
|
}
|
|
2746
2599
|
};
|
|
2747
2600
|
|
|
2601
|
+
// src/adapter/helpers/webgl-texture-utils.ts
|
|
2602
|
+
function initializeTextureStorage(gl, levels, options) {
|
|
2603
|
+
const { dimension, width, height, depth = 0 } = options;
|
|
2604
|
+
const { glInternalFormat } = options;
|
|
2605
|
+
const glTarget = options.glTarget;
|
|
2606
|
+
switch (dimension) {
|
|
2607
|
+
case "2d-array":
|
|
2608
|
+
case "3d":
|
|
2609
|
+
gl.texStorage3D(glTarget, levels, glInternalFormat, width, height, depth);
|
|
2610
|
+
break;
|
|
2611
|
+
default:
|
|
2612
|
+
gl.texStorage2D(glTarget, levels, glInternalFormat, width, height);
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
function copyCPUImageToMipLevel(gl, image, options) {
|
|
2616
|
+
const { dimension, width, height, depth = 0, level = 0 } = options;
|
|
2617
|
+
const { x = 0, y = 0, z = 0 } = options;
|
|
2618
|
+
const { glFormat, glType } = options;
|
|
2619
|
+
const glTarget = getCubeTargetWebGL(options.glTarget, dimension, depth);
|
|
2620
|
+
switch (dimension) {
|
|
2621
|
+
case "2d-array":
|
|
2622
|
+
case "3d":
|
|
2623
|
+
gl.texSubImage3D(glTarget, level, x, y, z, width, height, depth, glFormat, glType, image);
|
|
2624
|
+
break;
|
|
2625
|
+
case "2d":
|
|
2626
|
+
case "cube":
|
|
2627
|
+
gl.texSubImage2D(glTarget, level, x, y, width, height, glFormat, glType, image);
|
|
2628
|
+
break;
|
|
2629
|
+
default:
|
|
2630
|
+
throw new Error(dimension);
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
function copyCPUDataToMipLevel(gl, typedArray, options) {
|
|
2634
|
+
const { dimension, width, height, depth = 0, level = 0, byteOffset = 0 } = options;
|
|
2635
|
+
const { x = 0, y = 0, z = 0 } = options;
|
|
2636
|
+
const { glFormat, glType, compressed } = options;
|
|
2637
|
+
const glTarget = getCubeTargetWebGL(options.glTarget, dimension, depth);
|
|
2638
|
+
switch (dimension) {
|
|
2639
|
+
case "2d-array":
|
|
2640
|
+
case "3d":
|
|
2641
|
+
if (compressed) {
|
|
2642
|
+
gl.compressedTexSubImage3D(glTarget, level, x, y, z, width, height, depth, glFormat, typedArray, byteOffset);
|
|
2643
|
+
} else {
|
|
2644
|
+
gl.texSubImage3D(glTarget, level, x, y, z, width, height, depth, glFormat, glType, typedArray, byteOffset);
|
|
2645
|
+
}
|
|
2646
|
+
break;
|
|
2647
|
+
case "2d":
|
|
2648
|
+
case "cube":
|
|
2649
|
+
if (compressed) {
|
|
2650
|
+
gl.compressedTexSubImage2D(glTarget, level, x, y, width, height, glFormat, typedArray, byteOffset);
|
|
2651
|
+
} else {
|
|
2652
|
+
gl.texSubImage2D(glTarget, level, x, y, width, height, glFormat, glType, typedArray, byteOffset);
|
|
2653
|
+
}
|
|
2654
|
+
break;
|
|
2655
|
+
default:
|
|
2656
|
+
throw new Error(dimension);
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2659
|
+
function getWebGLTextureTarget(dimension) {
|
|
2660
|
+
switch (dimension) {
|
|
2661
|
+
case "1d":
|
|
2662
|
+
break;
|
|
2663
|
+
case "2d":
|
|
2664
|
+
return 3553 /* TEXTURE_2D */;
|
|
2665
|
+
case "3d":
|
|
2666
|
+
return 32879 /* TEXTURE_3D */;
|
|
2667
|
+
case "cube":
|
|
2668
|
+
return 34067 /* TEXTURE_CUBE_MAP */;
|
|
2669
|
+
case "2d-array":
|
|
2670
|
+
return 35866 /* TEXTURE_2D_ARRAY */;
|
|
2671
|
+
case "cube-array":
|
|
2672
|
+
break;
|
|
2673
|
+
}
|
|
2674
|
+
throw new Error(dimension);
|
|
2675
|
+
}
|
|
2676
|
+
function getCubeTargetWebGL(glTarget, dimension, level) {
|
|
2677
|
+
return dimension === "cube" ? 34069 /* TEXTURE_CUBE_MAP_POSITIVE_X */ + level : glTarget;
|
|
2678
|
+
}
|
|
2679
|
+
|
|
2748
2680
|
// src/adapter/resources/webgl-texture.ts
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2681
|
+
function normalizeTextureData(data, options) {
|
|
2682
|
+
let lodArray;
|
|
2683
|
+
if (ArrayBuffer.isView(data)) {
|
|
2684
|
+
lodArray = [
|
|
2685
|
+
{
|
|
2686
|
+
// ts-expect-error does data really need to be Uint8ClampedArray?
|
|
2687
|
+
data,
|
|
2688
|
+
width: options.width,
|
|
2689
|
+
height: options.height
|
|
2690
|
+
// depth: options.depth
|
|
2691
|
+
}
|
|
2692
|
+
];
|
|
2693
|
+
} else if (!Array.isArray(data)) {
|
|
2694
|
+
lodArray = [data];
|
|
2695
|
+
} else {
|
|
2696
|
+
lodArray = data;
|
|
2697
|
+
}
|
|
2698
|
+
return lodArray;
|
|
2699
|
+
}
|
|
2700
|
+
var WEBGLTexture = class extends import_core7.Texture {
|
|
2760
2701
|
MAX_ATTRIBUTES;
|
|
2761
2702
|
device;
|
|
2762
2703
|
gl;
|
|
2763
2704
|
handle;
|
|
2764
|
-
// (TODO - currently unused in WebGL, but WebGL 2 does support sampler objects) */
|
|
2765
2705
|
sampler = void 0;
|
|
2706
|
+
// TODO - currently unused in WebGL. Create dummy sampler?
|
|
2766
2707
|
view = void 0;
|
|
2767
|
-
//
|
|
2768
|
-
|
|
2769
|
-
type = void 0;
|
|
2770
|
-
dataFormat = void 0;
|
|
2771
|
-
mipmaps = void 0;
|
|
2708
|
+
// TODO - currently unused in WebGL. Create dummy view?
|
|
2709
|
+
mipmaps = false;
|
|
2772
2710
|
/**
|
|
2773
2711
|
* @note `target` cannot be modified by bind:
|
|
2774
2712
|
* textures are special because when you first bind them to a target,
|
|
2775
|
-
*
|
|
2776
|
-
* GL_TEXTURE_2D, you are saying that this texture is a 2D texture.
|
|
2713
|
+
* When you first bind a texture as a GL_TEXTURE_2D, you are saying that this texture is a 2D texture.
|
|
2777
2714
|
* And it will always be a 2D texture; this state cannot be changed ever.
|
|
2778
2715
|
* A texture that was first bound as a GL_TEXTURE_2D, must always be bound as a GL_TEXTURE_2D;
|
|
2779
2716
|
* attempting to bind it as GL_TEXTURE_3D will give rise to a run-time error
|
|
2780
|
-
* */
|
|
2781
|
-
target;
|
|
2782
|
-
textureUnit = void 0;
|
|
2783
|
-
/**
|
|
2784
|
-
* Program.draw() checks the loaded flag of all textures to avoid
|
|
2785
|
-
* Textures that are still loading from promises
|
|
2786
|
-
* Set to true as soon as texture has been initialized with valid data
|
|
2787
2717
|
*/
|
|
2788
|
-
|
|
2789
|
-
|
|
2718
|
+
glTarget;
|
|
2719
|
+
// Texture type
|
|
2720
|
+
/** The WebGL format - essentially channel structure */
|
|
2721
|
+
glFormat;
|
|
2722
|
+
/** The WebGL data format - the type of each channel */
|
|
2723
|
+
glType;
|
|
2724
|
+
/** The WebGL constant corresponding to the WebGPU style constant in format */
|
|
2725
|
+
glInternalFormat;
|
|
2726
|
+
/** Whether the internal format is compressed */
|
|
2727
|
+
compressed;
|
|
2728
|
+
// data;
|
|
2729
|
+
// inherited props
|
|
2730
|
+
// dimension: ...
|
|
2731
|
+
// format: GLTextureTarget;
|
|
2732
|
+
// width: number = undefined;
|
|
2733
|
+
// height: number = undefined;
|
|
2734
|
+
// depth: number = undefined;
|
|
2735
|
+
// state
|
|
2736
|
+
/** Texture binding slot */
|
|
2737
|
+
textureUnit = 0;
|
|
2738
|
+
/** For automatically updating video */
|
|
2739
|
+
_video = null;
|
|
2790
2740
|
constructor(device, props) {
|
|
2791
|
-
super(device, { ...
|
|
2741
|
+
super(device, { ...import_core7.Texture.defaultProps, ...props, data: void 0 });
|
|
2792
2742
|
this.device = device;
|
|
2793
2743
|
this.gl = this.device.gl;
|
|
2744
|
+
this.glTarget = getWebGLTextureTarget(this.props.dimension);
|
|
2745
|
+
const format = getTextureFormatWebGL(this.props.format);
|
|
2746
|
+
this.glInternalFormat = format.internalFormat;
|
|
2747
|
+
this.glFormat = format.format;
|
|
2748
|
+
this.glType = format.type;
|
|
2749
|
+
this.compressed = format.compressed;
|
|
2750
|
+
if (typeof HTMLVideoElement !== "undefined" && props.data instanceof HTMLVideoElement && // @ts-expect-error
|
|
2751
|
+
props.data.readyState < HTMLVideoElement.HAVE_METADATA) {
|
|
2752
|
+
const video = props.data;
|
|
2753
|
+
this._video = null;
|
|
2754
|
+
video.addEventListener("loadeddata", () => this.initialize(props));
|
|
2755
|
+
}
|
|
2756
|
+
this.initialize({ ...this.props, data: props.data });
|
|
2757
|
+
Object.seal(this);
|
|
2758
|
+
}
|
|
2759
|
+
/**
|
|
2760
|
+
* Initialize texture with supplied props
|
|
2761
|
+
*/
|
|
2762
|
+
// eslint-disable-next-line max-statements
|
|
2763
|
+
initialize(props = {}) {
|
|
2794
2764
|
this.handle = this.props.handle || this.gl.createTexture();
|
|
2795
2765
|
this.device.setSpectorMetadata(this.handle, { ...this.props, data: typeof this.props.data });
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2766
|
+
const data = props.data;
|
|
2767
|
+
let { width, height } = props;
|
|
2768
|
+
if (!width || !height) {
|
|
2769
|
+
const textureSize = this.getTextureDataSize(data);
|
|
2770
|
+
width = textureSize?.width || 1;
|
|
2771
|
+
height = textureSize?.height || 1;
|
|
2772
|
+
}
|
|
2773
|
+
this.width = width;
|
|
2774
|
+
this.height = height;
|
|
2775
|
+
this.depth = props.depth;
|
|
2776
|
+
this.setSampler(props.sampler);
|
|
2777
|
+
this.view = new WEBGLTextureView(this.device, { ...this.props, texture: this });
|
|
2778
|
+
this.bind();
|
|
2779
|
+
if (!this.props.data) {
|
|
2780
|
+
initializeTextureStorage(this.gl, this.mipLevels, this);
|
|
2781
|
+
}
|
|
2782
|
+
if (props.data) {
|
|
2783
|
+
switch (props.dimension) {
|
|
2784
|
+
case "1d":
|
|
2785
|
+
this.setTexture1DData(props.data);
|
|
2786
|
+
break;
|
|
2787
|
+
case "2d":
|
|
2788
|
+
this.setTexture2DData(props.data);
|
|
2789
|
+
break;
|
|
2790
|
+
case "3d":
|
|
2791
|
+
this.setTexture3DData(props.data);
|
|
2792
|
+
break;
|
|
2793
|
+
case "cube":
|
|
2794
|
+
this.setTextureCubeData(props.data);
|
|
2795
|
+
break;
|
|
2796
|
+
case "2d-array":
|
|
2797
|
+
this.setTextureArrayData(props.data);
|
|
2798
|
+
break;
|
|
2799
|
+
case "cube-array":
|
|
2800
|
+
this.setTextureCubeArrayData(props.data);
|
|
2801
|
+
break;
|
|
2802
|
+
default:
|
|
2803
|
+
throw new Error(props.dimension);
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2806
|
+
this.mipmaps = Boolean(props.mipmaps);
|
|
2807
|
+
if (this.mipmaps) {
|
|
2808
|
+
this.generateMipmap();
|
|
2801
2809
|
}
|
|
2802
|
-
this.initialize(this.props);
|
|
2803
|
-
Object.seal(this);
|
|
2804
2810
|
}
|
|
2811
|
+
/*
|
|
2812
|
+
initializeCube(props?: TextureProps): void {
|
|
2813
|
+
const {mipmaps = true} = props; // , parameters = {} as Record<GL, any>} = props;
|
|
2814
|
+
|
|
2815
|
+
// Store props for accessors
|
|
2816
|
+
// this.props = props;
|
|
2817
|
+
|
|
2818
|
+
// @ts-expect-error
|
|
2819
|
+
this.setCubeMapData(props).then(() => {
|
|
2820
|
+
// TODO - should genMipmap() be called on the cubemap or on the faces?
|
|
2821
|
+
// TODO - without generateMipmap() cube textures do not work at all!!! Why?
|
|
2822
|
+
if (mipmaps) {
|
|
2823
|
+
this.generateMipmap(props);
|
|
2824
|
+
}
|
|
2825
|
+
|
|
2826
|
+
this.setSampler(props.sampler);
|
|
2827
|
+
|
|
2828
|
+
// v8 compatibility?
|
|
2829
|
+
// const {parameters = {} as Record<GL, any>} = props;
|
|
2830
|
+
// this._setSamplerParameters(parameters);
|
|
2831
|
+
});
|
|
2832
|
+
}
|
|
2833
|
+
*/
|
|
2805
2834
|
destroy() {
|
|
2806
2835
|
if (this.handle) {
|
|
2807
2836
|
this.gl.deleteTexture(this.handle);
|
|
@@ -2816,97 +2845,6 @@ var __exports__ = (() => {
|
|
|
2816
2845
|
createView(props) {
|
|
2817
2846
|
return new WEBGLTextureView(this.device, { ...props, texture: this });
|
|
2818
2847
|
}
|
|
2819
|
-
// eslint-disable-next-line max-statements
|
|
2820
|
-
initialize(props = {}) {
|
|
2821
|
-
if (this.props.dimension === "cube") {
|
|
2822
|
-
return this.initializeCube(props);
|
|
2823
|
-
}
|
|
2824
|
-
let data = props.data;
|
|
2825
|
-
if (data instanceof Promise) {
|
|
2826
|
-
data.then(
|
|
2827
|
-
(resolvedImageData) => this.initialize(
|
|
2828
|
-
Object.assign({}, props, {
|
|
2829
|
-
pixels: resolvedImageData,
|
|
2830
|
-
data: resolvedImageData
|
|
2831
|
-
})
|
|
2832
|
-
)
|
|
2833
|
-
);
|
|
2834
|
-
return this;
|
|
2835
|
-
}
|
|
2836
|
-
const isVideo = typeof HTMLVideoElement !== "undefined" && data instanceof HTMLVideoElement;
|
|
2837
|
-
if (isVideo && data.readyState < HTMLVideoElement.HAVE_METADATA) {
|
|
2838
|
-
this._video = null;
|
|
2839
|
-
data.addEventListener("loadeddata", () => this.initialize(props));
|
|
2840
|
-
return this;
|
|
2841
|
-
}
|
|
2842
|
-
const { parameters = {} } = props;
|
|
2843
|
-
const { pixels = null, pixelStore = {}, textureUnit = void 0, mipmaps = true } = props;
|
|
2844
|
-
if (!data) {
|
|
2845
|
-
data = pixels;
|
|
2846
|
-
}
|
|
2847
|
-
let { width, height, dataFormat, type, compressed = false } = props;
|
|
2848
|
-
const { depth = 0 } = props;
|
|
2849
|
-
const glFormat = convertTextureFormatToGL(props.format);
|
|
2850
|
-
({ width, height, compressed, dataFormat, type } = this._deduceParameters({
|
|
2851
|
-
format: props.format,
|
|
2852
|
-
type,
|
|
2853
|
-
dataFormat,
|
|
2854
|
-
compressed,
|
|
2855
|
-
data,
|
|
2856
|
-
width,
|
|
2857
|
-
height
|
|
2858
|
-
}));
|
|
2859
|
-
this.width = width;
|
|
2860
|
-
this.height = height;
|
|
2861
|
-
this.glFormat = glFormat;
|
|
2862
|
-
this.type = type;
|
|
2863
|
-
this.dataFormat = dataFormat;
|
|
2864
|
-
this.textureUnit = textureUnit;
|
|
2865
|
-
if (Number.isFinite(this.textureUnit)) {
|
|
2866
|
-
this.gl.activeTexture(33984 /* TEXTURE0 */ + this.textureUnit);
|
|
2867
|
-
this.gl.bindTexture(this.target, this.handle);
|
|
2868
|
-
}
|
|
2869
|
-
this.mipmaps = mipmaps;
|
|
2870
|
-
this.setImageData({
|
|
2871
|
-
data,
|
|
2872
|
-
width,
|
|
2873
|
-
height,
|
|
2874
|
-
depth,
|
|
2875
|
-
format: glFormat,
|
|
2876
|
-
type,
|
|
2877
|
-
dataFormat,
|
|
2878
|
-
// @ts-expect-error
|
|
2879
|
-
parameters: pixelStore,
|
|
2880
|
-
compressed
|
|
2881
|
-
});
|
|
2882
|
-
this.setSampler(props.sampler);
|
|
2883
|
-
this._setSamplerParameters(parameters);
|
|
2884
|
-
this.view = this.createView({ ...this.props, mipLevelCount: 1, arrayLayerCount: 1 });
|
|
2885
|
-
if (mipmaps && this.device.isTextureFormatFilterable(props.format)) {
|
|
2886
|
-
this.generateMipmap();
|
|
2887
|
-
}
|
|
2888
|
-
if (isVideo) {
|
|
2889
|
-
this._video = {
|
|
2890
|
-
video: data,
|
|
2891
|
-
parameters,
|
|
2892
|
-
// @ts-expect-error
|
|
2893
|
-
lastTime: data.readyState >= HTMLVideoElement.HAVE_CURRENT_DATA ? data.currentTime : -1
|
|
2894
|
-
};
|
|
2895
|
-
}
|
|
2896
|
-
return this;
|
|
2897
|
-
}
|
|
2898
|
-
initializeCube(props) {
|
|
2899
|
-
const { mipmaps = true, parameters = {} } = props;
|
|
2900
|
-
this.setCubeMapImageData(props).then(() => {
|
|
2901
|
-
this.loaded = true;
|
|
2902
|
-
if (mipmaps) {
|
|
2903
|
-
this.generateMipmap(props);
|
|
2904
|
-
}
|
|
2905
|
-
this.setSampler(props.sampler);
|
|
2906
|
-
this._setSamplerParameters(parameters);
|
|
2907
|
-
});
|
|
2908
|
-
return this;
|
|
2909
|
-
}
|
|
2910
2848
|
setSampler(sampler = {}) {
|
|
2911
2849
|
let samplerProps;
|
|
2912
2850
|
if (sampler instanceof WEBGLSampler) {
|
|
@@ -2918,377 +2856,88 @@ var __exports__ = (() => {
|
|
|
2918
2856
|
}
|
|
2919
2857
|
const parameters = convertSamplerParametersToWebGL(samplerProps);
|
|
2920
2858
|
this._setSamplerParameters(parameters);
|
|
2921
|
-
return this;
|
|
2922
|
-
}
|
|
2923
|
-
/**
|
|
2924
|
-
* If size has changed, reinitializes with current format
|
|
2925
|
-
* @note note clears image and mipmaps
|
|
2926
|
-
*/
|
|
2927
|
-
resize(options) {
|
|
2928
|
-
const { height, width, mipmaps = false } = options;
|
|
2929
|
-
if (width !== this.width || height !== this.height) {
|
|
2930
|
-
return this.initialize({
|
|
2931
|
-
width,
|
|
2932
|
-
height,
|
|
2933
|
-
format: this.format,
|
|
2934
|
-
type: this.type,
|
|
2935
|
-
dataFormat: this.dataFormat,
|
|
2936
|
-
mipmaps
|
|
2937
|
-
});
|
|
2938
|
-
}
|
|
2939
|
-
return this;
|
|
2940
2859
|
}
|
|
2941
|
-
/** Update external texture (video frame) */
|
|
2860
|
+
/** Update external texture (video frame or canvas) */
|
|
2942
2861
|
update() {
|
|
2943
|
-
|
|
2944
|
-
const { video, parameters, lastTime } = this._video;
|
|
2945
|
-
if (lastTime === video.currentTime || video.readyState < HTMLVideoElement.HAVE_CURRENT_DATA) {
|
|
2946
|
-
return;
|
|
2947
|
-
}
|
|
2948
|
-
this.setSubImageData({
|
|
2949
|
-
data: video,
|
|
2950
|
-
parameters
|
|
2951
|
-
});
|
|
2952
|
-
if (this.mipmaps) {
|
|
2953
|
-
this.generateMipmap();
|
|
2954
|
-
}
|
|
2955
|
-
this._video.lastTime = video.currentTime;
|
|
2956
|
-
}
|
|
2862
|
+
import_core7.log.warn("Texture.update() not implemented");
|
|
2957
2863
|
}
|
|
2958
2864
|
// Call to regenerate mipmaps after modifying texture(s)
|
|
2959
2865
|
generateMipmap(params = {}) {
|
|
2866
|
+
if (!this.props.data) {
|
|
2867
|
+
return;
|
|
2868
|
+
}
|
|
2960
2869
|
this.mipmaps = true;
|
|
2961
|
-
this.gl.bindTexture(this.
|
|
2870
|
+
this.gl.bindTexture(this.glTarget, this.handle);
|
|
2962
2871
|
withGLParameters(this.gl, params, () => {
|
|
2963
|
-
this.gl.generateMipmap(this.
|
|
2872
|
+
this.gl.generateMipmap(this.glTarget);
|
|
2964
2873
|
});
|
|
2965
|
-
this.gl.bindTexture(this.
|
|
2966
|
-
return this;
|
|
2874
|
+
this.gl.bindTexture(this.glTarget, null);
|
|
2967
2875
|
}
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
* @param width -
|
|
2979
|
-
* @param height -
|
|
2980
|
-
* @param mipMapLevel -
|
|
2981
|
-
* @param {GLenum} format - format of image data.
|
|
2982
|
-
* @param {GLenum} type
|
|
2983
|
-
* - format of array (autodetect from type) or
|
|
2984
|
-
* - (WEBGL2) format of buffer
|
|
2985
|
-
* @param {Number} offset - (WEBGL2) offset from start of buffer
|
|
2986
|
-
* @parameters - temporary settings to be applied, can be used to supply pixel store settings.
|
|
2987
|
-
*/
|
|
2988
|
-
// eslint-disable-next-line max-statements, complexity
|
|
2989
|
-
setImageData(options) {
|
|
2990
|
-
if (this.props.dimension === "3d" || this.props.dimension === "2d-array") {
|
|
2991
|
-
return this.setImageData3D(options);
|
|
2876
|
+
// Image Data Setters
|
|
2877
|
+
setTexture1DData(data) {
|
|
2878
|
+
throw new Error("setTexture1DData not supported in WebGL.");
|
|
2879
|
+
}
|
|
2880
|
+
/** Set a simple texture */
|
|
2881
|
+
setTexture2DData(lodData, depth = 0, glTarget = this.glTarget) {
|
|
2882
|
+
this.bind();
|
|
2883
|
+
const lodArray = normalizeTextureData(lodData, this);
|
|
2884
|
+
if (lodArray.length > 1 && this.props.mipmaps !== false) {
|
|
2885
|
+
import_core7.log.warn(`Texture ${this.id} mipmap and multiple LODs.`)();
|
|
2992
2886
|
}
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
pixels = null,
|
|
2997
|
-
level = 0,
|
|
2998
|
-
glFormat = this.glFormat,
|
|
2999
|
-
offset = 0,
|
|
3000
|
-
parameters = {}
|
|
3001
|
-
} = options;
|
|
3002
|
-
let {
|
|
3003
|
-
data = null,
|
|
3004
|
-
type = this.type,
|
|
3005
|
-
width = this.width,
|
|
3006
|
-
height = this.height,
|
|
3007
|
-
dataFormat = this.dataFormat,
|
|
3008
|
-
compressed = false
|
|
3009
|
-
} = options;
|
|
3010
|
-
if (!data) {
|
|
3011
|
-
data = pixels;
|
|
2887
|
+
for (let lodLevel = 0; lodLevel < lodArray.length; lodLevel++) {
|
|
2888
|
+
const imageData = lodArray[lodLevel];
|
|
2889
|
+
this._setMipLevel(depth, lodLevel, imageData);
|
|
3012
2890
|
}
|
|
3013
|
-
|
|
3014
|
-
format: this.props.format,
|
|
3015
|
-
type,
|
|
3016
|
-
dataFormat,
|
|
3017
|
-
compressed,
|
|
3018
|
-
data,
|
|
3019
|
-
width,
|
|
3020
|
-
height
|
|
3021
|
-
}));
|
|
3022
|
-
const { gl } = this;
|
|
3023
|
-
gl.bindTexture(this.target, this.handle);
|
|
3024
|
-
let dataType = null;
|
|
3025
|
-
({ data, dataType } = this._getDataType({ data, compressed }));
|
|
3026
|
-
withGLParameters(this.gl, parameters, () => {
|
|
3027
|
-
switch (dataType) {
|
|
3028
|
-
case "null":
|
|
3029
|
-
gl.texImage2D(
|
|
3030
|
-
target,
|
|
3031
|
-
level,
|
|
3032
|
-
glFormat,
|
|
3033
|
-
width,
|
|
3034
|
-
height,
|
|
3035
|
-
0,
|
|
3036
|
-
dataFormat,
|
|
3037
|
-
type,
|
|
3038
|
-
data
|
|
3039
|
-
);
|
|
3040
|
-
break;
|
|
3041
|
-
case "typed-array":
|
|
3042
|
-
gl.texImage2D(
|
|
3043
|
-
target,
|
|
3044
|
-
level,
|
|
3045
|
-
glFormat,
|
|
3046
|
-
width,
|
|
3047
|
-
height,
|
|
3048
|
-
0,
|
|
3049
|
-
// border (must be 0)
|
|
3050
|
-
dataFormat,
|
|
3051
|
-
type,
|
|
3052
|
-
data,
|
|
3053
|
-
offset
|
|
3054
|
-
);
|
|
3055
|
-
break;
|
|
3056
|
-
case "buffer":
|
|
3057
|
-
this.device.gl.bindBuffer(35052 /* PIXEL_UNPACK_BUFFER */, data.handle || data);
|
|
3058
|
-
this.device.gl.texImage2D(
|
|
3059
|
-
target,
|
|
3060
|
-
level,
|
|
3061
|
-
glFormat,
|
|
3062
|
-
width,
|
|
3063
|
-
height,
|
|
3064
|
-
0,
|
|
3065
|
-
dataFormat,
|
|
3066
|
-
type,
|
|
3067
|
-
offset
|
|
3068
|
-
);
|
|
3069
|
-
this.device.gl.bindBuffer(35052 /* PIXEL_UNPACK_BUFFER */, null);
|
|
3070
|
-
break;
|
|
3071
|
-
case "browser-object":
|
|
3072
|
-
gl.texImage2D(
|
|
3073
|
-
target,
|
|
3074
|
-
level,
|
|
3075
|
-
glFormat,
|
|
3076
|
-
width,
|
|
3077
|
-
height,
|
|
3078
|
-
0,
|
|
3079
|
-
dataFormat,
|
|
3080
|
-
type,
|
|
3081
|
-
data
|
|
3082
|
-
);
|
|
3083
|
-
break;
|
|
3084
|
-
case "compressed":
|
|
3085
|
-
for (const [levelIndex, levelData] of data.entries()) {
|
|
3086
|
-
gl.compressedTexImage2D(
|
|
3087
|
-
target,
|
|
3088
|
-
levelIndex,
|
|
3089
|
-
levelData.format,
|
|
3090
|
-
levelData.width,
|
|
3091
|
-
levelData.height,
|
|
3092
|
-
0,
|
|
3093
|
-
levelData.data
|
|
3094
|
-
);
|
|
3095
|
-
}
|
|
3096
|
-
break;
|
|
3097
|
-
default:
|
|
3098
|
-
(0, import_core9.assert)(false, "Unknown image data type");
|
|
3099
|
-
}
|
|
3100
|
-
});
|
|
3101
|
-
if (data && data.byteLength) {
|
|
3102
|
-
this.trackAllocatedMemory(data.byteLength, "Texture");
|
|
3103
|
-
} else {
|
|
3104
|
-
const bytesPerPixel = getTextureFormatBytesPerPixel(this.props.format);
|
|
3105
|
-
this.trackAllocatedMemory(this.width * this.height * bytesPerPixel, "Texture");
|
|
3106
|
-
}
|
|
3107
|
-
this.loaded = true;
|
|
3108
|
-
return this;
|
|
2891
|
+
this.unbind();
|
|
3109
2892
|
}
|
|
3110
2893
|
/**
|
|
3111
|
-
*
|
|
3112
|
-
*
|
|
3113
|
-
* Redefines an area of an existing texture
|
|
2894
|
+
* Sets a 3D texture
|
|
2895
|
+
* @param data
|
|
3114
2896
|
*/
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
data = null,
|
|
3119
|
-
x = 0,
|
|
3120
|
-
y = 0,
|
|
3121
|
-
width = this.width,
|
|
3122
|
-
height = this.height,
|
|
3123
|
-
level = 0,
|
|
3124
|
-
glFormat = this.glFormat,
|
|
3125
|
-
type = this.type,
|
|
3126
|
-
dataFormat = this.dataFormat,
|
|
3127
|
-
compressed = false,
|
|
3128
|
-
offset = 0,
|
|
3129
|
-
parameters = {}
|
|
3130
|
-
}) {
|
|
3131
|
-
({ type, dataFormat, compressed, width, height } = this._deduceParameters({
|
|
3132
|
-
format: this.props.format,
|
|
3133
|
-
type,
|
|
3134
|
-
dataFormat,
|
|
3135
|
-
compressed,
|
|
3136
|
-
data,
|
|
3137
|
-
width,
|
|
3138
|
-
height
|
|
3139
|
-
}));
|
|
3140
|
-
(0, import_core9.assert)(this.depth === 1, "texSubImage not supported for 3D textures");
|
|
3141
|
-
if (!data) {
|
|
3142
|
-
data = pixels;
|
|
3143
|
-
}
|
|
3144
|
-
if (data && data.data) {
|
|
3145
|
-
const ndarray = data;
|
|
3146
|
-
data = ndarray.data;
|
|
3147
|
-
width = ndarray.shape[0];
|
|
3148
|
-
height = ndarray.shape[1];
|
|
2897
|
+
setTexture3DData(data) {
|
|
2898
|
+
if (this.props.dimension !== "3d") {
|
|
2899
|
+
throw new Error(this.id);
|
|
3149
2900
|
}
|
|
3150
|
-
if (data
|
|
3151
|
-
data
|
|
2901
|
+
if (ArrayBuffer.isView(data)) {
|
|
2902
|
+
copyCPUDataToMipLevel(this.device.gl, data, this);
|
|
3152
2903
|
}
|
|
3153
|
-
this.gl.bindTexture(this.target, this.handle);
|
|
3154
|
-
withGLParameters(this.gl, parameters, () => {
|
|
3155
|
-
if (compressed) {
|
|
3156
|
-
this.gl.compressedTexSubImage2D(target, level, x, y, width, height, glFormat, data);
|
|
3157
|
-
} else if (data === null) {
|
|
3158
|
-
this.gl.texSubImage2D(target, level, x, y, width, height, dataFormat, type, null);
|
|
3159
|
-
} else if (ArrayBuffer.isView(data)) {
|
|
3160
|
-
this.gl.texSubImage2D(target, level, x, y, width, height, dataFormat, type, data, offset);
|
|
3161
|
-
} else if (typeof WebGLBuffer !== "undefined" && data instanceof WebGLBuffer) {
|
|
3162
|
-
this.device.gl.bindBuffer(35052 /* PIXEL_UNPACK_BUFFER */, data);
|
|
3163
|
-
this.device.gl.texSubImage2D(target, level, x, y, width, height, dataFormat, type, offset);
|
|
3164
|
-
this.device.gl.bindBuffer(35052 /* PIXEL_UNPACK_BUFFER */, null);
|
|
3165
|
-
} else {
|
|
3166
|
-
this.device.gl.texSubImage2D(target, level, x, y, width, height, dataFormat, type, data);
|
|
3167
|
-
}
|
|
3168
|
-
});
|
|
3169
|
-
this.gl.bindTexture(this.target, null);
|
|
3170
2904
|
}
|
|
3171
2905
|
/**
|
|
3172
|
-
*
|
|
3173
|
-
*
|
|
3174
|
-
*
|
|
3175
|
-
*
|
|
3176
|
-
* Note that binding a texture into a Framebuffer's color buffer and
|
|
3177
|
-
* rendering can be faster.
|
|
2906
|
+
* Set a Texture Cube Data
|
|
2907
|
+
* @todo - could support TextureCubeArray with depth
|
|
2908
|
+
* @param data
|
|
2909
|
+
* @param index
|
|
3178
2910
|
*/
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
)();
|
|
3183
|
-
return null;
|
|
3184
|
-
}
|
|
3185
|
-
getActiveUnit() {
|
|
3186
|
-
return this.gl.getParameter(34016 /* ACTIVE_TEXTURE */) - 33984 /* TEXTURE0 */;
|
|
3187
|
-
}
|
|
3188
|
-
bind(textureUnit = this.textureUnit) {
|
|
3189
|
-
const { gl } = this;
|
|
3190
|
-
if (textureUnit !== void 0) {
|
|
3191
|
-
this.textureUnit = textureUnit;
|
|
3192
|
-
gl.activeTexture(gl.TEXTURE0 + textureUnit);
|
|
2911
|
+
setTextureCubeData(data, depth = 0) {
|
|
2912
|
+
if (this.props.dimension !== "cube") {
|
|
2913
|
+
throw new Error(this.id);
|
|
3193
2914
|
}
|
|
3194
|
-
gl.bindTexture(this.target, this.handle);
|
|
3195
|
-
return textureUnit;
|
|
3196
2915
|
}
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
2916
|
+
/**
|
|
2917
|
+
* Sets an entire texture array
|
|
2918
|
+
* @param data
|
|
2919
|
+
*/
|
|
2920
|
+
setTextureArrayData(data) {
|
|
2921
|
+
if (this.props.dimension !== "2d-array") {
|
|
2922
|
+
throw new Error(this.id);
|
|
3202
2923
|
}
|
|
3203
|
-
|
|
3204
|
-
return textureUnit;
|
|
2924
|
+
throw new Error("setTextureArrayData not implemented.");
|
|
3205
2925
|
}
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
return { data, dataType: "null" };
|
|
3213
|
-
}
|
|
3214
|
-
if (ArrayBuffer.isView(data)) {
|
|
3215
|
-
return { data, dataType: "typed-array" };
|
|
3216
|
-
}
|
|
3217
|
-
if (data instanceof WEBGLBuffer) {
|
|
3218
|
-
return { data: data.handle, dataType: "buffer" };
|
|
3219
|
-
}
|
|
3220
|
-
if (typeof WebGLBuffer !== "undefined" && data instanceof WebGLBuffer) {
|
|
3221
|
-
return { data, dataType: "buffer" };
|
|
3222
|
-
}
|
|
3223
|
-
return { data, dataType: "browser-object" };
|
|
3224
|
-
}
|
|
3225
|
-
// HELPER METHODS
|
|
3226
|
-
_deduceParameters(opts) {
|
|
3227
|
-
const { format, data } = opts;
|
|
3228
|
-
let { width, height, dataFormat, type, compressed } = opts;
|
|
3229
|
-
const parameters = getWebGLTextureParameters(format);
|
|
3230
|
-
dataFormat = dataFormat || parameters.dataFormat;
|
|
3231
|
-
type = type || parameters.type;
|
|
3232
|
-
compressed = compressed || parameters.compressed;
|
|
3233
|
-
({ width, height } = this._deduceImageSize(data, width, height));
|
|
3234
|
-
return { dataFormat, type, compressed, width, height, format, data };
|
|
3235
|
-
}
|
|
3236
|
-
// eslint-disable-next-line complexity
|
|
3237
|
-
_deduceImageSize(data, width, height) {
|
|
3238
|
-
let size;
|
|
3239
|
-
if (typeof ImageData !== "undefined" && data instanceof ImageData) {
|
|
3240
|
-
size = { width: data.width, height: data.height };
|
|
3241
|
-
} else if (typeof HTMLImageElement !== "undefined" && data instanceof HTMLImageElement) {
|
|
3242
|
-
size = { width: data.naturalWidth, height: data.naturalHeight };
|
|
3243
|
-
} else if (typeof HTMLCanvasElement !== "undefined" && data instanceof HTMLCanvasElement) {
|
|
3244
|
-
size = { width: data.width, height: data.height };
|
|
3245
|
-
} else if (typeof ImageBitmap !== "undefined" && data instanceof ImageBitmap) {
|
|
3246
|
-
size = { width: data.width, height: data.height };
|
|
3247
|
-
} else if (typeof HTMLVideoElement !== "undefined" && data instanceof HTMLVideoElement) {
|
|
3248
|
-
size = { width: data.videoWidth, height: data.videoHeight };
|
|
3249
|
-
} else if (!data) {
|
|
3250
|
-
size = { width: width >= 0 ? width : 1, height: height >= 0 ? height : 1 };
|
|
3251
|
-
} else {
|
|
3252
|
-
size = { width, height };
|
|
3253
|
-
}
|
|
3254
|
-
(0, import_core9.assert)(size, "Could not deduced texture size");
|
|
3255
|
-
(0, import_core9.assert)(
|
|
3256
|
-
width === void 0 || size.width === width,
|
|
3257
|
-
"Deduced texture width does not match supplied width"
|
|
3258
|
-
);
|
|
3259
|
-
(0, import_core9.assert)(
|
|
3260
|
-
height === void 0 || size.height === height,
|
|
3261
|
-
"Deduced texture height does not match supplied height"
|
|
3262
|
-
);
|
|
3263
|
-
return size;
|
|
2926
|
+
/**
|
|
2927
|
+
* Sets an entire texture cube array
|
|
2928
|
+
* @param data
|
|
2929
|
+
*/
|
|
2930
|
+
setTextureCubeArrayData(data) {
|
|
2931
|
+
throw new Error("setTextureCubeArrayData not supported in WebGL2.");
|
|
3264
2932
|
}
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
const { width, height, pixels, data, format = 6408 /* RGBA */, type = 5121 /* UNSIGNED_BYTE */ } = options;
|
|
3270
|
-
const imageDataMap = pixels || data;
|
|
3271
|
-
const resolvedFaces = await Promise.all(
|
|
3272
|
-
_WEBGLTexture.FACES.map((face) => {
|
|
3273
|
-
const facePixels = imageDataMap[face];
|
|
3274
|
-
return Promise.all(Array.isArray(facePixels) ? facePixels : [facePixels]);
|
|
3275
|
-
})
|
|
3276
|
-
);
|
|
2933
|
+
setTextureCubeFaceData(lodData, face, depth = 0) {
|
|
2934
|
+
if (Array.isArray(lodData) && lodData.length > 1 && this.props.mipmaps !== false) {
|
|
2935
|
+
import_core7.log.warn(`${this.id} has mipmap and multiple LODs.`)();
|
|
2936
|
+
}
|
|
3277
2937
|
this.bind();
|
|
3278
|
-
_WEBGLTexture.FACES.forEach((face, index) => {
|
|
3279
|
-
if (resolvedFaces[index].length > 1 && this.props.mipmaps !== false) {
|
|
3280
|
-
import_core9.log.warn(`${this.id} has mipmap and multiple LODs.`)();
|
|
3281
|
-
}
|
|
3282
|
-
resolvedFaces[index].forEach((image, lodLevel) => {
|
|
3283
|
-
if (width && height) {
|
|
3284
|
-
gl.texImage2D(face, lodLevel, format, width, height, 0, format, type, image);
|
|
3285
|
-
} else {
|
|
3286
|
-
gl.texImage2D(face, lodLevel, format, format, type, image);
|
|
3287
|
-
}
|
|
3288
|
-
});
|
|
3289
|
-
});
|
|
3290
2938
|
this.unbind();
|
|
3291
2939
|
}
|
|
2940
|
+
// INTERNAL METHODS
|
|
3292
2941
|
/** @todo update this method to accept LODs */
|
|
3293
2942
|
setImageDataForFace(options) {
|
|
3294
2943
|
const {
|
|
@@ -3319,132 +2968,157 @@ var __exports__ = (() => {
|
|
|
3319
2968
|
} else {
|
|
3320
2969
|
gl.texImage2D(face, 0, format, format, type, imageData);
|
|
3321
2970
|
}
|
|
3322
|
-
return this;
|
|
3323
2971
|
}
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
type,
|
|
3331
|
-
// = GL.UNSIGNED_BYTE,
|
|
3332
|
-
width,
|
|
3333
|
-
height,
|
|
3334
|
-
depth = 1,
|
|
3335
|
-
offset = 0,
|
|
3336
|
-
data,
|
|
3337
|
-
parameters = {}
|
|
3338
|
-
} = options;
|
|
3339
|
-
this.trackDeallocatedMemory("Texture");
|
|
3340
|
-
this.gl.bindTexture(this.target, this.handle);
|
|
3341
|
-
const webglTextureFormat = getWebGLTextureParameters(format);
|
|
3342
|
-
withGLParameters(this.gl, parameters, () => {
|
|
3343
|
-
if (ArrayBuffer.isView(data)) {
|
|
3344
|
-
this.gl.texImage3D(
|
|
3345
|
-
this.target,
|
|
3346
|
-
level,
|
|
3347
|
-
webglTextureFormat.format,
|
|
3348
|
-
width,
|
|
3349
|
-
height,
|
|
3350
|
-
depth,
|
|
3351
|
-
0,
|
|
3352
|
-
webglTextureFormat.dataFormat,
|
|
3353
|
-
webglTextureFormat.type,
|
|
3354
|
-
// dataType: getWebGL,
|
|
3355
|
-
data
|
|
3356
|
-
);
|
|
2972
|
+
_getImageDataMap(faceData) {
|
|
2973
|
+
for (let i = 0; i < import_core7.Texture.CubeFaces.length; ++i) {
|
|
2974
|
+
const faceName = import_core7.Texture.CubeFaces[i];
|
|
2975
|
+
if (faceData[faceName]) {
|
|
2976
|
+
faceData[34069 /* TEXTURE_CUBE_MAP_POSITIVE_X */ + i] = faceData[faceName];
|
|
2977
|
+
delete faceData[faceName];
|
|
3357
2978
|
}
|
|
3358
|
-
if (data instanceof WEBGLBuffer) {
|
|
3359
|
-
this.gl.bindBuffer(35052 /* PIXEL_UNPACK_BUFFER */, data.handle);
|
|
3360
|
-
this.gl.texImage3D(
|
|
3361
|
-
this.target,
|
|
3362
|
-
level,
|
|
3363
|
-
dataFormat,
|
|
3364
|
-
width,
|
|
3365
|
-
height,
|
|
3366
|
-
depth,
|
|
3367
|
-
0,
|
|
3368
|
-
format,
|
|
3369
|
-
type,
|
|
3370
|
-
offset
|
|
3371
|
-
);
|
|
3372
|
-
}
|
|
3373
|
-
});
|
|
3374
|
-
if (data && data.byteLength) {
|
|
3375
|
-
this.trackAllocatedMemory(data.byteLength, "Texture");
|
|
3376
|
-
} else {
|
|
3377
|
-
const bytesPerPixel = getTextureFormatBytesPerPixel(this.props.format);
|
|
3378
|
-
this.trackAllocatedMemory(this.width * this.height * this.depth * bytesPerPixel, "Texture");
|
|
3379
2979
|
}
|
|
3380
|
-
|
|
3381
|
-
return this;
|
|
2980
|
+
return faceData;
|
|
3382
2981
|
}
|
|
3383
2982
|
// RESOURCE METHODS
|
|
3384
2983
|
/**
|
|
3385
2984
|
* Sets sampler parameters on texture
|
|
3386
2985
|
*/
|
|
3387
2986
|
_setSamplerParameters(parameters) {
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
}
|
|
3391
|
-
logParameters(parameters);
|
|
3392
|
-
this.gl.bindTexture(this.target, this.handle);
|
|
2987
|
+
import_core7.log.log(1, "texture sampler parameters", parameters)();
|
|
2988
|
+
this.gl.bindTexture(this.glTarget, this.handle);
|
|
3393
2989
|
for (const [pname, pvalue] of Object.entries(parameters)) {
|
|
3394
2990
|
const param = Number(pname);
|
|
3395
2991
|
const value = pvalue;
|
|
3396
2992
|
switch (param) {
|
|
3397
2993
|
case 33082 /* TEXTURE_MIN_LOD */:
|
|
3398
2994
|
case 33083 /* TEXTURE_MAX_LOD */:
|
|
3399
|
-
this.gl.texParameterf(this.
|
|
2995
|
+
this.gl.texParameterf(this.glTarget, param, value);
|
|
2996
|
+
break;
|
|
2997
|
+
case 10241 /* TEXTURE_MIN_FILTER */:
|
|
2998
|
+
this.gl.texParameteri(this.glTarget, param, value);
|
|
2999
|
+
break;
|
|
3000
|
+
case 10242 /* TEXTURE_WRAP_S */:
|
|
3001
|
+
case 10243 /* TEXTURE_WRAP_T */:
|
|
3002
|
+
this.gl.texParameteri(this.glTarget, param, value);
|
|
3003
|
+
break;
|
|
3004
|
+
case 34046 /* TEXTURE_MAX_ANISOTROPY_EXT */:
|
|
3005
|
+
if (this.device.features.has("texture-filterable-anisotropic-webgl")) {
|
|
3006
|
+
this.gl.texParameteri(this.glTarget, param, value);
|
|
3007
|
+
}
|
|
3400
3008
|
break;
|
|
3401
3009
|
default:
|
|
3402
|
-
this.gl.texParameteri(this.
|
|
3010
|
+
this.gl.texParameteri(this.glTarget, param, value);
|
|
3403
3011
|
break;
|
|
3404
3012
|
}
|
|
3405
3013
|
}
|
|
3406
|
-
this.gl.bindTexture(this.
|
|
3407
|
-
return;
|
|
3014
|
+
this.gl.bindTexture(this.glTarget, null);
|
|
3408
3015
|
}
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3016
|
+
// CLASSIC
|
|
3017
|
+
/*
|
|
3018
|
+
setCubeMapData(options: {
|
|
3019
|
+
width: number;
|
|
3020
|
+
height: number;
|
|
3021
|
+
data: Record<GL, Texture2DData> | Record<TextureCubeFace, Texture2DData>;
|
|
3022
|
+
format?: any;
|
|
3023
|
+
type?: any;
|
|
3024
|
+
/** @deprecated Use .data *
|
|
3025
|
+
pixels: any;
|
|
3026
|
+
}): void {
|
|
3027
|
+
const {gl} = this;
|
|
3028
|
+
|
|
3029
|
+
const {width, height, pixels, data, format = GL.RGBA, type = GL.UNSIGNED_BYTE} = options;
|
|
3030
|
+
|
|
3031
|
+
// pixel data (imageDataMap) is an Object from Face to Image or Promise.
|
|
3032
|
+
// For example:
|
|
3033
|
+
// {
|
|
3034
|
+
// GL.TEXTURE_CUBE_MAP_POSITIVE_X : Image-or-Promise,
|
|
3035
|
+
// GL.TEXTURE_CUBE_MAP_NEGATIVE_X : Image-or-Promise,
|
|
3036
|
+
// ... }
|
|
3037
|
+
// To provide multiple level-of-details (LODs) this can be Face to Array
|
|
3038
|
+
// of Image or Promise, like this
|
|
3039
|
+
// {
|
|
3040
|
+
// GL.TEXTURE_CUBE_MAP_POSITIVE_X : [Image-or-Promise-LOD-0, Image-or-Promise-LOD-1],
|
|
3041
|
+
// GL.TEXTURE_CUBE_MAP_NEGATIVE_X : [Image-or-Promise-LOD-0, Image-or-Promise-LOD-1],
|
|
3042
|
+
// ... }
|
|
3043
|
+
|
|
3044
|
+
const imageDataMap = this._getImageDataMap(pixels || data);
|
|
3045
|
+
|
|
3046
|
+
const resolvedFaces = WEBGLTexture.FACES.map(face => {
|
|
3047
|
+
const facePixels = imageDataMap[face];
|
|
3048
|
+
return Array.isArray(facePixels) ? facePixels : [facePixels];
|
|
3049
|
+
});
|
|
3050
|
+
this.bind();
|
|
3051
|
+
|
|
3052
|
+
WEBGLTexture.FACES.forEach((face, index) => {
|
|
3053
|
+
if (resolvedFaces[index].length > 1 && this.props.mipmaps !== false) {
|
|
3054
|
+
// If the user provides multiple LODs, then automatic mipmap
|
|
3055
|
+
// generation generateMipmap() should be disabled to avoid overwritting them.
|
|
3056
|
+
log.warn(`${this.id} has mipmap and multiple LODs.`)();
|
|
3057
|
+
}
|
|
3058
|
+
resolvedFaces[index].forEach((image, lodLevel) => {
|
|
3059
|
+
// TODO: adjust width & height for LOD!
|
|
3060
|
+
if (width && height) {
|
|
3061
|
+
gl.texImage2D(face, lodLevel, format, width, height, 0 /* border*, format, type, image);
|
|
3062
|
+
} else {
|
|
3063
|
+
gl.texImage2D(face, lodLevel, format, format, type, image);
|
|
3064
|
+
}
|
|
3065
|
+
});
|
|
3066
|
+
});
|
|
3067
|
+
|
|
3068
|
+
this.unbind();
|
|
3069
|
+
}
|
|
3070
|
+
*/
|
|
3071
|
+
// INTERNAL SETTERS
|
|
3072
|
+
/**
|
|
3073
|
+
* Copy a region of data from a CPU memory buffer into this texture.
|
|
3074
|
+
* @todo - GLUnpackParameters parameters
|
|
3075
|
+
*/
|
|
3076
|
+
_setMipLevel(depth, level, textureData, offset = 0) {
|
|
3077
|
+
if (import_core7.Texture.isExternalImage(textureData)) {
|
|
3078
|
+
copyCPUImageToMipLevel(this.device.gl, textureData, { ...this, depth, level });
|
|
3079
|
+
return;
|
|
3080
|
+
}
|
|
3081
|
+
if (this.isTextureLevelData(textureData)) {
|
|
3082
|
+
copyCPUDataToMipLevel(this.device.gl, textureData.data, {
|
|
3083
|
+
...this,
|
|
3084
|
+
depth,
|
|
3085
|
+
level
|
|
3086
|
+
});
|
|
3087
|
+
return;
|
|
3088
|
+
}
|
|
3089
|
+
throw new Error("Texture: invalid image data");
|
|
3434
3090
|
}
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3091
|
+
// HELPERS
|
|
3092
|
+
getActiveUnit() {
|
|
3093
|
+
return this.gl.getParameter(34016 /* ACTIVE_TEXTURE */) - 33984 /* TEXTURE0 */;
|
|
3094
|
+
}
|
|
3095
|
+
bind(textureUnit) {
|
|
3096
|
+
const { gl } = this;
|
|
3097
|
+
if (textureUnit !== void 0) {
|
|
3098
|
+
this.textureUnit = textureUnit;
|
|
3099
|
+
gl.activeTexture(gl.TEXTURE0 + textureUnit);
|
|
3100
|
+
}
|
|
3101
|
+
gl.bindTexture(this.glTarget, this.handle);
|
|
3102
|
+
return textureUnit;
|
|
3103
|
+
}
|
|
3104
|
+
unbind(textureUnit) {
|
|
3105
|
+
const { gl } = this;
|
|
3106
|
+
if (textureUnit !== void 0) {
|
|
3107
|
+
this.textureUnit = textureUnit;
|
|
3108
|
+
gl.activeTexture(gl.TEXTURE0 + textureUnit);
|
|
3109
|
+
}
|
|
3110
|
+
gl.bindTexture(this.glTarget, null);
|
|
3111
|
+
return textureUnit;
|
|
3112
|
+
}
|
|
3113
|
+
};
|
|
3439
3114
|
|
|
3440
3115
|
// src/adapter/resources/webgl-framebuffer.ts
|
|
3441
|
-
var WEBGLFramebuffer = class extends
|
|
3116
|
+
var WEBGLFramebuffer = class extends import_core8.Framebuffer {
|
|
3442
3117
|
device;
|
|
3443
3118
|
gl;
|
|
3444
3119
|
handle;
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
}
|
|
3120
|
+
colorAttachments = [];
|
|
3121
|
+
depthStencilAttachment = null;
|
|
3448
3122
|
constructor(device, props) {
|
|
3449
3123
|
super(device, props);
|
|
3450
3124
|
const isDefaultFramebuffer = props.handle === null;
|
|
@@ -3462,11 +3136,11 @@ var __exports__ = (() => {
|
|
|
3462
3136
|
const attachment = this.colorAttachments[i];
|
|
3463
3137
|
const attachmentPoint = 36064 /* COLOR_ATTACHMENT0 */ + i;
|
|
3464
3138
|
if (attachment) {
|
|
3465
|
-
this.
|
|
3139
|
+
this._attachTexture(attachmentPoint, attachment);
|
|
3466
3140
|
}
|
|
3467
3141
|
}
|
|
3468
3142
|
if (this.depthStencilAttachment) {
|
|
3469
|
-
this.
|
|
3143
|
+
this._attachTexture(
|
|
3470
3144
|
getDepthStencilAttachmentWebGL(this.depthStencilAttachment.props.format),
|
|
3471
3145
|
this.depthStencilAttachment
|
|
3472
3146
|
);
|
|
@@ -3499,73 +3173,55 @@ var __exports__ = (() => {
|
|
|
3499
3173
|
});
|
|
3500
3174
|
}
|
|
3501
3175
|
/**
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
this.
|
|
3507
|
-
|
|
3176
|
+
* Attachment resize is expected to be a noop if size is same
|
|
3177
|
+
*
|
|
3178
|
+
protected override resizeAttachments(width: number, height: number): this {
|
|
3179
|
+
// for default framebuffer, just update the stored size
|
|
3180
|
+
if (this.handle === null) {
|
|
3181
|
+
// assert(width === undefined && height === undefined);
|
|
3182
|
+
this.width = this.gl.drawingBufferWidth;
|
|
3183
|
+
this.height = this.gl.drawingBufferHeight;
|
|
3184
|
+
return this;
|
|
3185
|
+
}
|
|
3186
|
+
|
|
3187
|
+
if (width === undefined) {
|
|
3188
|
+
width = this.gl.drawingBufferWidth;
|
|
3189
|
+
}
|
|
3190
|
+
if (height === undefined) {
|
|
3191
|
+
height = this.gl.drawingBufferHeight;
|
|
3192
|
+
}
|
|
3193
|
+
|
|
3194
|
+
// TODO Not clear that this is better than default destroy/create implementation
|
|
3195
|
+
|
|
3196
|
+
for (const colorAttachment of this.colorAttachments) {
|
|
3197
|
+
colorAttachment.texture.clone({width, height});
|
|
3198
|
+
}
|
|
3199
|
+
if (this.depthStencilAttachment) {
|
|
3200
|
+
this.depthStencilAttachment.texture.resize({width, height});
|
|
3201
|
+
}
|
|
3508
3202
|
return this;
|
|
3509
3203
|
}
|
|
3510
|
-
|
|
3511
|
-
width = this.gl.drawingBufferWidth;
|
|
3512
|
-
}
|
|
3513
|
-
if (height === void 0) {
|
|
3514
|
-
height = this.gl.drawingBufferHeight;
|
|
3515
|
-
}
|
|
3516
|
-
for (const colorAttachment of this.colorAttachments) {
|
|
3517
|
-
colorAttachment.texture.resize({ width, height });
|
|
3518
|
-
}
|
|
3519
|
-
if (this.depthStencilAttachment) {
|
|
3520
|
-
this.depthStencilAttachment.texture.resize({ width, height });
|
|
3521
|
-
}
|
|
3522
|
-
return this;
|
|
3523
|
-
}
|
|
3204
|
+
*/
|
|
3524
3205
|
/** Attach one attachment */
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
this._attachTexture(attachmentPoint, texture, layer, level);
|
|
3529
|
-
return texture;
|
|
3530
|
-
}
|
|
3531
|
-
if (attachment instanceof WEBGLTexture) {
|
|
3532
|
-
this._attachTexture(attachmentPoint, attachment, 0, 0);
|
|
3533
|
-
return attachment;
|
|
3534
|
-
}
|
|
3535
|
-
if (attachment instanceof WEBGLTextureView) {
|
|
3536
|
-
const textureView = attachment;
|
|
3537
|
-
this._attachTexture(
|
|
3538
|
-
attachmentPoint,
|
|
3539
|
-
textureView.texture,
|
|
3540
|
-
textureView.props.baseMipLevel,
|
|
3541
|
-
textureView.props.baseArrayLayer
|
|
3542
|
-
);
|
|
3543
|
-
return attachment.texture;
|
|
3544
|
-
}
|
|
3545
|
-
throw new Error("attach");
|
|
3546
|
-
}
|
|
3547
|
-
// TODO - we do not seem to need render buffers in WebGL 2
|
|
3548
|
-
// protected _attachWEBGLRenderbuffer(attachment: GL, renderbuffer: WEBGLRenderbuffer): void {
|
|
3549
|
-
// this.gl.framebufferRenderbuffer(
|
|
3550
|
-
// GL.FRAMEBUFFER,
|
|
3551
|
-
// attachment,
|
|
3552
|
-
// GL.RENDERBUFFER,
|
|
3553
|
-
// renderbuffer.handle
|
|
3554
|
-
// );
|
|
3555
|
-
// }
|
|
3206
|
+
_attachTexture(attachmentPoint, textureView) {
|
|
3207
|
+
this._attachTextureView(attachmentPoint, textureView);
|
|
3208
|
+
}
|
|
3556
3209
|
/**
|
|
3557
3210
|
* @param attachment
|
|
3558
3211
|
* @param texture
|
|
3559
3212
|
* @param layer = 0 - index into WEBGLTextureArray and Texture3D or face for `TextureCubeMap`
|
|
3560
3213
|
* @param level = 0 - mipmapLevel
|
|
3561
3214
|
*/
|
|
3562
|
-
|
|
3215
|
+
_attachTextureView(attachment, textureView) {
|
|
3563
3216
|
const { gl } = this.device;
|
|
3564
|
-
|
|
3565
|
-
|
|
3217
|
+
const { texture } = textureView;
|
|
3218
|
+
const level = textureView.props.baseMipLevel;
|
|
3219
|
+
const layer = textureView.props.baseArrayLayer;
|
|
3220
|
+
gl.bindTexture(texture.glTarget, texture.handle);
|
|
3221
|
+
switch (texture.glTarget) {
|
|
3566
3222
|
case 35866 /* TEXTURE_2D_ARRAY */:
|
|
3567
3223
|
case 32879 /* TEXTURE_3D */:
|
|
3568
|
-
gl.framebufferTextureLayer(36160 /* FRAMEBUFFER */, attachment, texture.
|
|
3224
|
+
gl.framebufferTextureLayer(36160 /* FRAMEBUFFER */, attachment, texture.glTarget, level, layer);
|
|
3569
3225
|
break;
|
|
3570
3226
|
case 34067 /* TEXTURE_CUBE_MAP */:
|
|
3571
3227
|
const face = mapIndexToCubeMapFace(layer);
|
|
@@ -3575,9 +3231,9 @@ var __exports__ = (() => {
|
|
|
3575
3231
|
gl.framebufferTexture2D(36160 /* FRAMEBUFFER */, attachment, 3553 /* TEXTURE_2D */, texture.handle, level);
|
|
3576
3232
|
break;
|
|
3577
3233
|
default:
|
|
3578
|
-
|
|
3234
|
+
throw new Error("Illegal texture type");
|
|
3579
3235
|
}
|
|
3580
|
-
gl.bindTexture(texture.
|
|
3236
|
+
gl.bindTexture(texture.glTarget, null);
|
|
3581
3237
|
}
|
|
3582
3238
|
};
|
|
3583
3239
|
function mapIndexToCubeMapFace(layer) {
|
|
@@ -3603,8 +3259,10 @@ var __exports__ = (() => {
|
|
|
3603
3259
|
}
|
|
3604
3260
|
|
|
3605
3261
|
// src/adapter/webgl-canvas-context.ts
|
|
3606
|
-
var WebGLCanvasContext = class extends
|
|
3262
|
+
var WebGLCanvasContext = class extends import_core9.CanvasContext {
|
|
3607
3263
|
device;
|
|
3264
|
+
format = "rgba8unorm";
|
|
3265
|
+
depthStencilFormat = "depth24plus";
|
|
3608
3266
|
presentationSize;
|
|
3609
3267
|
_framebuffer = null;
|
|
3610
3268
|
constructor(device, props) {
|
|
@@ -3654,9 +3312,30 @@ var __exports__ = (() => {
|
|
|
3654
3312
|
};
|
|
3655
3313
|
|
|
3656
3314
|
// src/context/debug/spector.ts
|
|
3657
|
-
var
|
|
3315
|
+
var import_core10 = __toESM(require_core(), 1);
|
|
3316
|
+
|
|
3317
|
+
// src/utils/load-script.ts
|
|
3318
|
+
async function loadScript(scriptUrl, scriptId) {
|
|
3319
|
+
const head = document.getElementsByTagName("head")[0];
|
|
3320
|
+
if (!head) {
|
|
3321
|
+
throw new Error("loadScript");
|
|
3322
|
+
}
|
|
3323
|
+
const script = document.createElement("script");
|
|
3324
|
+
script.setAttribute("type", "text/javascript");
|
|
3325
|
+
script.setAttribute("src", scriptUrl);
|
|
3326
|
+
if (scriptId) {
|
|
3327
|
+
script.id = scriptId;
|
|
3328
|
+
}
|
|
3329
|
+
return new Promise((resolve, reject) => {
|
|
3330
|
+
script.onload = resolve;
|
|
3331
|
+
script.onerror = (error) => reject(new Error(`Unable to load script '${scriptUrl}': ${error}`));
|
|
3332
|
+
head.appendChild(script);
|
|
3333
|
+
});
|
|
3334
|
+
}
|
|
3335
|
+
|
|
3336
|
+
// src/context/debug/spector.ts
|
|
3658
3337
|
var DEFAULT_SPECTOR_PROPS = {
|
|
3659
|
-
spector:
|
|
3338
|
+
spector: import_core10.log.get("spector") || import_core10.log.get("inspect")
|
|
3660
3339
|
};
|
|
3661
3340
|
var SPECTOR_CDN_URL = "https://spectorcdn.babylonjs.com/spector.bundle.js";
|
|
3662
3341
|
var LOG_LEVEL = 1;
|
|
@@ -3665,9 +3344,9 @@ var __exports__ = (() => {
|
|
|
3665
3344
|
async function loadSpectorJS(props) {
|
|
3666
3345
|
if (!globalThis.SPECTOR) {
|
|
3667
3346
|
try {
|
|
3668
|
-
await
|
|
3347
|
+
await loadScript(SPECTOR_CDN_URL);
|
|
3669
3348
|
} catch (error) {
|
|
3670
|
-
|
|
3349
|
+
import_core10.log.warn(String(error));
|
|
3671
3350
|
}
|
|
3672
3351
|
}
|
|
3673
3352
|
}
|
|
@@ -3677,7 +3356,7 @@ var __exports__ = (() => {
|
|
|
3677
3356
|
return null;
|
|
3678
3357
|
}
|
|
3679
3358
|
if (!spector && globalThis.SPECTOR) {
|
|
3680
|
-
|
|
3359
|
+
import_core10.log.probe(LOG_LEVEL, "SPECTOR found and initialized")();
|
|
3681
3360
|
spector = new globalThis.SPECTOR.Spector();
|
|
3682
3361
|
if (globalThis.luma) {
|
|
3683
3362
|
globalThis.luma.spector = spector;
|
|
@@ -3690,10 +3369,10 @@ var __exports__ = (() => {
|
|
|
3690
3369
|
initialized = true;
|
|
3691
3370
|
spector.spyCanvases();
|
|
3692
3371
|
spector?.onCaptureStarted.add(
|
|
3693
|
-
(capture) =>
|
|
3372
|
+
(capture) => import_core10.log.info("Spector capture started:", capture)()
|
|
3694
3373
|
);
|
|
3695
3374
|
spector?.onCapture.add((capture) => {
|
|
3696
|
-
|
|
3375
|
+
import_core10.log.info("Spector capture complete:", capture)();
|
|
3697
3376
|
spector?.getResultUI();
|
|
3698
3377
|
spector?.resultView.display();
|
|
3699
3378
|
spector?.resultView.addCapture(capture);
|
|
@@ -3705,7 +3384,7 @@ var __exports__ = (() => {
|
|
|
3705
3384
|
}
|
|
3706
3385
|
spector?.startCapture(props?.canvas, 500);
|
|
3707
3386
|
new Promise((resolve) => setTimeout(resolve, 2e3)).then((_) => {
|
|
3708
|
-
|
|
3387
|
+
import_core10.log.info("Spector capture stopped after 2 seconds")();
|
|
3709
3388
|
spector?.stopCapture();
|
|
3710
3389
|
});
|
|
3711
3390
|
}
|
|
@@ -3713,40 +3392,37 @@ var __exports__ = (() => {
|
|
|
3713
3392
|
}
|
|
3714
3393
|
|
|
3715
3394
|
// src/context/debug/webgl-developer-tools.ts
|
|
3716
|
-
var
|
|
3395
|
+
var import_core11 = __toESM(require_core(), 1);
|
|
3396
|
+
|
|
3397
|
+
// ../../node_modules/@probe.gl/env/dist/lib/globals.js
|
|
3398
|
+
var document_ = globalThis.document || {};
|
|
3399
|
+
var process_ = globalThis.process || {};
|
|
3400
|
+
var console_ = globalThis.console;
|
|
3401
|
+
var navigator_ = globalThis.navigator || {};
|
|
3717
3402
|
|
|
3718
3403
|
// ../../node_modules/@probe.gl/env/dist/lib/is-electron.js
|
|
3719
3404
|
function isElectron(mockUserAgent) {
|
|
3720
|
-
if (typeof window !== "undefined" &&
|
|
3405
|
+
if (typeof window !== "undefined" && window.process?.type === "renderer") {
|
|
3721
3406
|
return true;
|
|
3722
3407
|
}
|
|
3723
|
-
if (typeof process !== "undefined" &&
|
|
3408
|
+
if (typeof process !== "undefined" && Boolean(process.versions?.["electron"])) {
|
|
3724
3409
|
return true;
|
|
3725
3410
|
}
|
|
3726
|
-
const realUserAgent = typeof navigator
|
|
3411
|
+
const realUserAgent = typeof navigator !== "undefined" && navigator.userAgent;
|
|
3727
3412
|
const userAgent = mockUserAgent || realUserAgent;
|
|
3728
|
-
|
|
3729
|
-
return true;
|
|
3730
|
-
}
|
|
3731
|
-
return false;
|
|
3413
|
+
return Boolean(userAgent && userAgent.indexOf("Electron") >= 0);
|
|
3732
3414
|
}
|
|
3733
3415
|
|
|
3734
3416
|
// ../../node_modules/@probe.gl/env/dist/lib/is-browser.js
|
|
3735
3417
|
function isBrowser() {
|
|
3736
|
-
const isNode =
|
|
3418
|
+
const isNode = (
|
|
3419
|
+
// @ts-expect-error
|
|
3420
|
+
typeof process === "object" && String(process) === "[object process]" && !process?.browser
|
|
3421
|
+
);
|
|
3737
3422
|
return !isNode || isElectron();
|
|
3738
3423
|
}
|
|
3739
3424
|
|
|
3740
|
-
// ../../node_modules/@probe.gl/env/dist/lib/globals.js
|
|
3741
|
-
var self_ = globalThis.self || globalThis.window || globalThis.global;
|
|
3742
|
-
var window_ = globalThis.window || globalThis.self || globalThis.global;
|
|
3743
|
-
var document_ = globalThis.document || {};
|
|
3744
|
-
var process_ = globalThis.process || {};
|
|
3745
|
-
var console_ = globalThis.console;
|
|
3746
|
-
var navigator_ = globalThis.navigator || {};
|
|
3747
|
-
|
|
3748
3425
|
// ../../node_modules/@probe.gl/env/dist/lib/get-browser.js
|
|
3749
|
-
var window2 = globalThis;
|
|
3750
3426
|
function getBrowser(mockUserAgent) {
|
|
3751
3427
|
if (!mockUserAgent && !isBrowser()) {
|
|
3752
3428
|
return "Node";
|
|
@@ -3758,18 +3434,13 @@ var __exports__ = (() => {
|
|
|
3758
3434
|
if (userAgent.indexOf("Edge") > -1) {
|
|
3759
3435
|
return "Edge";
|
|
3760
3436
|
}
|
|
3761
|
-
|
|
3762
|
-
const isTrident = userAgent.indexOf("Trident/") !== -1;
|
|
3763
|
-
if (isMSIE || isTrident) {
|
|
3764
|
-
return "IE";
|
|
3765
|
-
}
|
|
3766
|
-
if (window2.chrome) {
|
|
3437
|
+
if (globalThis.chrome) {
|
|
3767
3438
|
return "Chrome";
|
|
3768
3439
|
}
|
|
3769
|
-
if (
|
|
3440
|
+
if (globalThis.safari) {
|
|
3770
3441
|
return "Safari";
|
|
3771
3442
|
}
|
|
3772
|
-
if (
|
|
3443
|
+
if (globalThis.mozInnerScreenX) {
|
|
3773
3444
|
return "Firefox";
|
|
3774
3445
|
}
|
|
3775
3446
|
return "Unknown";
|
|
@@ -3785,96 +3456,217 @@ var __exports__ = (() => {
|
|
|
3785
3456
|
if (isBrowser() && !globalThis.WebGLDebugUtils) {
|
|
3786
3457
|
globalThis.global = globalThis.global || globalThis;
|
|
3787
3458
|
globalThis.global.module = {};
|
|
3788
|
-
await
|
|
3459
|
+
await loadScript(WEBGL_DEBUG_CDN_URL);
|
|
3460
|
+
}
|
|
3461
|
+
}
|
|
3462
|
+
function makeDebugContext(gl, props = {}) {
|
|
3463
|
+
return props.debug ? getDebugContext(gl, props) : getRealContext(gl);
|
|
3464
|
+
}
|
|
3465
|
+
function getRealContext(gl) {
|
|
3466
|
+
const data = getWebGLContextData(gl);
|
|
3467
|
+
return data.realContext ? data.realContext : gl;
|
|
3468
|
+
}
|
|
3469
|
+
function getDebugContext(gl, props) {
|
|
3470
|
+
if (!globalThis.WebGLDebugUtils) {
|
|
3471
|
+
import_core11.log.warn("webgl-debug not loaded")();
|
|
3472
|
+
return gl;
|
|
3473
|
+
}
|
|
3474
|
+
const data = getWebGLContextData(gl);
|
|
3475
|
+
if (data.debugContext) {
|
|
3476
|
+
return data.debugContext;
|
|
3477
|
+
}
|
|
3478
|
+
globalThis.WebGLDebugUtils.init({ ...GLEnum, ...gl });
|
|
3479
|
+
const glDebug = globalThis.WebGLDebugUtils.makeDebugContext(
|
|
3480
|
+
gl,
|
|
3481
|
+
onGLError.bind(null, props),
|
|
3482
|
+
onValidateGLFunc.bind(null, props)
|
|
3483
|
+
);
|
|
3484
|
+
for (const key in GLEnum) {
|
|
3485
|
+
if (!(key in glDebug) && typeof GLEnum[key] === "number") {
|
|
3486
|
+
glDebug[key] = GLEnum[key];
|
|
3487
|
+
}
|
|
3488
|
+
}
|
|
3489
|
+
class WebGLDebugContext {
|
|
3490
|
+
}
|
|
3491
|
+
Object.setPrototypeOf(glDebug, Object.getPrototypeOf(gl));
|
|
3492
|
+
Object.setPrototypeOf(WebGLDebugContext, glDebug);
|
|
3493
|
+
const debugContext = Object.create(WebGLDebugContext);
|
|
3494
|
+
data.realContext = gl;
|
|
3495
|
+
data.debugContext = debugContext;
|
|
3496
|
+
debugContext.debug = true;
|
|
3497
|
+
return debugContext;
|
|
3498
|
+
}
|
|
3499
|
+
function getFunctionString(functionName, functionArgs) {
|
|
3500
|
+
functionArgs = Array.from(functionArgs).map((arg) => arg === void 0 ? "undefined" : arg);
|
|
3501
|
+
let args = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, functionArgs);
|
|
3502
|
+
args = `${args.slice(0, 100)}${args.length > 100 ? "..." : ""}`;
|
|
3503
|
+
return `gl.${functionName}(${args})`;
|
|
3504
|
+
}
|
|
3505
|
+
function onGLError(props, err, functionName, args) {
|
|
3506
|
+
args = Array.from(args).map((arg) => arg === void 0 ? "undefined" : arg);
|
|
3507
|
+
const errorMessage = globalThis.WebGLDebugUtils.glEnumToString(err);
|
|
3508
|
+
const functionArgs = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, args);
|
|
3509
|
+
const message2 = `${errorMessage} in gl.${functionName}(${functionArgs})`;
|
|
3510
|
+
import_core11.log.error(message2)();
|
|
3511
|
+
debugger;
|
|
3512
|
+
if (props.throwOnError) {
|
|
3513
|
+
throw new Error(message2);
|
|
3514
|
+
}
|
|
3515
|
+
}
|
|
3516
|
+
function onValidateGLFunc(props, functionName, functionArgs) {
|
|
3517
|
+
let functionString = "";
|
|
3518
|
+
if (import_core11.log.level >= 1) {
|
|
3519
|
+
functionString = getFunctionString(functionName, functionArgs);
|
|
3520
|
+
import_core11.log.log(1, functionString)();
|
|
3521
|
+
}
|
|
3522
|
+
if (props.break && props.break.length > 0) {
|
|
3523
|
+
functionString = functionString || getFunctionString(functionName, functionArgs);
|
|
3524
|
+
const isBreakpoint = props.break.every(
|
|
3525
|
+
(breakOn) => functionString.indexOf(breakOn) !== -1
|
|
3526
|
+
);
|
|
3527
|
+
if (isBreakpoint) {
|
|
3528
|
+
debugger;
|
|
3529
|
+
}
|
|
3530
|
+
}
|
|
3531
|
+
for (const arg of functionArgs) {
|
|
3532
|
+
if (arg === void 0) {
|
|
3533
|
+
functionString = functionString || getFunctionString(functionName, functionArgs);
|
|
3534
|
+
if (props.throwOnError) {
|
|
3535
|
+
throw new Error(`Undefined argument: ${functionString}`);
|
|
3536
|
+
} else {
|
|
3537
|
+
import_core11.log.error(`Undefined argument: ${functionString}`)();
|
|
3538
|
+
debugger;
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3541
|
+
}
|
|
3542
|
+
}
|
|
3543
|
+
|
|
3544
|
+
// src/adapter/resources/webgl-buffer.ts
|
|
3545
|
+
var import_core12 = __toESM(require_core(), 1);
|
|
3546
|
+
var WEBGLBuffer = class extends import_core12.Buffer {
|
|
3547
|
+
device;
|
|
3548
|
+
gl;
|
|
3549
|
+
handle;
|
|
3550
|
+
/** Target in OpenGL defines the type of buffer */
|
|
3551
|
+
glTarget;
|
|
3552
|
+
/** Usage is a hint on how frequently the buffer will be updates */
|
|
3553
|
+
glUsage;
|
|
3554
|
+
/** Index type is needed when issuing draw calls, so we pre-compute it */
|
|
3555
|
+
glIndexType = 5123 /* UNSIGNED_SHORT */;
|
|
3556
|
+
/** Number of bytes allocated on the GPU for this buffer */
|
|
3557
|
+
byteLength;
|
|
3558
|
+
/** Number of bytes used */
|
|
3559
|
+
bytesUsed;
|
|
3560
|
+
constructor(device, props = {}) {
|
|
3561
|
+
super(device, props);
|
|
3562
|
+
this.device = device;
|
|
3563
|
+
this.gl = this.device.gl;
|
|
3564
|
+
const handle = typeof props === "object" ? props.handle : void 0;
|
|
3565
|
+
this.handle = handle || this.gl.createBuffer();
|
|
3566
|
+
device.setSpectorMetadata(this.handle, { ...this.props, data: typeof this.props.data });
|
|
3567
|
+
this.glTarget = getWebGLTarget(this.props.usage);
|
|
3568
|
+
this.glUsage = getWebGLUsage(this.props.usage);
|
|
3569
|
+
this.glIndexType = this.props.indexType === "uint32" ? 5125 /* UNSIGNED_INT */ : 5123 /* UNSIGNED_SHORT */;
|
|
3570
|
+
if (props.data) {
|
|
3571
|
+
this._initWithData(props.data, props.byteOffset, props.byteLength);
|
|
3572
|
+
} else {
|
|
3573
|
+
this._initWithByteLength(props.byteLength || 0);
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
// PRIVATE METHODS
|
|
3577
|
+
/** Allocate a new buffer and initialize to contents of typed array */
|
|
3578
|
+
_initWithData(data, byteOffset = 0, byteLength = data.byteLength + byteOffset) {
|
|
3579
|
+
const glTarget = this.glTarget;
|
|
3580
|
+
this.gl.bindBuffer(glTarget, this.handle);
|
|
3581
|
+
this.gl.bufferData(glTarget, byteLength, this.glUsage);
|
|
3582
|
+
this.gl.bufferSubData(glTarget, byteOffset, data);
|
|
3583
|
+
this.gl.bindBuffer(glTarget, null);
|
|
3584
|
+
this.bytesUsed = byteLength;
|
|
3585
|
+
this.byteLength = byteLength;
|
|
3586
|
+
this._setDebugData(data, byteOffset, byteLength);
|
|
3587
|
+
this.trackAllocatedMemory(byteLength);
|
|
3588
|
+
}
|
|
3589
|
+
// Allocate a GPU buffer of specified size.
|
|
3590
|
+
_initWithByteLength(byteLength) {
|
|
3591
|
+
let data = byteLength;
|
|
3592
|
+
if (byteLength === 0) {
|
|
3593
|
+
data = new Float32Array(0);
|
|
3594
|
+
}
|
|
3595
|
+
const glTarget = this.glTarget;
|
|
3596
|
+
this.gl.bindBuffer(glTarget, this.handle);
|
|
3597
|
+
this.gl.bufferData(glTarget, data, this.glUsage);
|
|
3598
|
+
this.gl.bindBuffer(glTarget, null);
|
|
3599
|
+
this.bytesUsed = byteLength;
|
|
3600
|
+
this.byteLength = byteLength;
|
|
3601
|
+
this._setDebugData(null, 0, byteLength);
|
|
3602
|
+
this.trackAllocatedMemory(byteLength);
|
|
3603
|
+
return this;
|
|
3604
|
+
}
|
|
3605
|
+
destroy() {
|
|
3606
|
+
if (!this.destroyed && this.handle) {
|
|
3607
|
+
this.removeStats();
|
|
3608
|
+
this.trackDeallocatedMemory();
|
|
3609
|
+
this.gl.deleteBuffer(this.handle);
|
|
3610
|
+
this.destroyed = true;
|
|
3611
|
+
this.handle = null;
|
|
3612
|
+
}
|
|
3789
3613
|
}
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3614
|
+
write(data, byteOffset = 0) {
|
|
3615
|
+
const srcOffset = 0;
|
|
3616
|
+
const byteLength = void 0;
|
|
3617
|
+
const glTarget = 36663 /* COPY_WRITE_BUFFER */;
|
|
3618
|
+
this.gl.bindBuffer(glTarget, this.handle);
|
|
3619
|
+
if (srcOffset !== 0 || byteLength !== void 0) {
|
|
3620
|
+
this.gl.bufferSubData(glTarget, byteOffset, data, srcOffset, byteLength);
|
|
3621
|
+
} else {
|
|
3622
|
+
this.gl.bufferSubData(glTarget, byteOffset, data);
|
|
3623
|
+
}
|
|
3624
|
+
this.gl.bindBuffer(glTarget, null);
|
|
3625
|
+
this._setDebugData(data, byteOffset, data.byteLength);
|
|
3794
3626
|
}
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
const data = getWebGLContextData(gl);
|
|
3799
|
-
return data.realContext ? data.realContext : gl;
|
|
3800
|
-
}
|
|
3801
|
-
function getDebugContext(gl, props) {
|
|
3802
|
-
if (!globalThis.WebGLDebugUtils) {
|
|
3803
|
-
import_core13.log.warn("webgl-debug not loaded")();
|
|
3804
|
-
return gl;
|
|
3627
|
+
/** Asynchronously read data from the buffer */
|
|
3628
|
+
async readAsync(byteOffset = 0, byteLength) {
|
|
3629
|
+
return this.readSyncWebGL(byteOffset, byteLength);
|
|
3805
3630
|
}
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3631
|
+
/** Synchronously read data from the buffer. WebGL only. */
|
|
3632
|
+
readSyncWebGL(byteOffset = 0, byteLength) {
|
|
3633
|
+
byteLength = byteLength ?? this.byteLength - byteOffset;
|
|
3634
|
+
const data = new Uint8Array(byteLength);
|
|
3635
|
+
const dstOffset = 0;
|
|
3636
|
+
this.gl.bindBuffer(36662 /* COPY_READ_BUFFER */, this.handle);
|
|
3637
|
+
this.gl.getBufferSubData(36662 /* COPY_READ_BUFFER */, byteOffset, data, dstOffset, byteLength);
|
|
3638
|
+
this.gl.bindBuffer(36662 /* COPY_READ_BUFFER */, null);
|
|
3639
|
+
this._setDebugData(data, byteOffset, byteLength);
|
|
3640
|
+
return data;
|
|
3809
3641
|
}
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
onValidateGLFunc.bind(null, props)
|
|
3815
|
-
);
|
|
3816
|
-
for (const key in GLEnum) {
|
|
3817
|
-
if (!(key in glDebug) && typeof GLEnum[key] === "number") {
|
|
3818
|
-
glDebug[key] = GLEnum[key];
|
|
3819
|
-
}
|
|
3642
|
+
};
|
|
3643
|
+
function getWebGLTarget(usage) {
|
|
3644
|
+
if (usage & import_core12.Buffer.INDEX) {
|
|
3645
|
+
return 34963 /* ELEMENT_ARRAY_BUFFER */;
|
|
3820
3646
|
}
|
|
3821
|
-
|
|
3647
|
+
if (usage & import_core12.Buffer.VERTEX) {
|
|
3648
|
+
return 34962 /* ARRAY_BUFFER */;
|
|
3822
3649
|
}
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
const debugContext = Object.create(WebGLDebugContext);
|
|
3826
|
-
data.realContext = gl;
|
|
3827
|
-
data.debugContext = debugContext;
|
|
3828
|
-
debugContext.debug = true;
|
|
3829
|
-
return debugContext;
|
|
3830
|
-
}
|
|
3831
|
-
function getFunctionString(functionName, functionArgs) {
|
|
3832
|
-
functionArgs = Array.from(functionArgs).map((arg) => arg === void 0 ? "undefined" : arg);
|
|
3833
|
-
let args = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, functionArgs);
|
|
3834
|
-
args = `${args.slice(0, 100)}${args.length > 100 ? "..." : ""}`;
|
|
3835
|
-
return `gl.${functionName}(${args})`;
|
|
3836
|
-
}
|
|
3837
|
-
function onGLError(props, err, functionName, args) {
|
|
3838
|
-
args = Array.from(args).map((arg) => arg === void 0 ? "undefined" : arg);
|
|
3839
|
-
const errorMessage = globalThis.WebGLDebugUtils.glEnumToString(err);
|
|
3840
|
-
const functionArgs = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, args);
|
|
3841
|
-
const message2 = `${errorMessage} in gl.${functionName}(${functionArgs})`;
|
|
3842
|
-
import_core13.log.error(message2)();
|
|
3843
|
-
debugger;
|
|
3844
|
-
if (props.throwOnError) {
|
|
3845
|
-
throw new Error(message2);
|
|
3650
|
+
if (usage & import_core12.Buffer.UNIFORM) {
|
|
3651
|
+
return 35345 /* UNIFORM_BUFFER */;
|
|
3846
3652
|
}
|
|
3653
|
+
return 34962 /* ARRAY_BUFFER */;
|
|
3847
3654
|
}
|
|
3848
|
-
function
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
functionString = getFunctionString(functionName, functionArgs);
|
|
3852
|
-
import_core13.log.log(1, functionString)();
|
|
3655
|
+
function getWebGLUsage(usage) {
|
|
3656
|
+
if (usage & import_core12.Buffer.INDEX) {
|
|
3657
|
+
return 35044 /* STATIC_DRAW */;
|
|
3853
3658
|
}
|
|
3854
|
-
if (
|
|
3855
|
-
|
|
3856
|
-
const isBreakpoint = props.break.every(
|
|
3857
|
-
(breakOn) => functionString.indexOf(breakOn) !== -1
|
|
3858
|
-
);
|
|
3859
|
-
if (isBreakpoint) {
|
|
3860
|
-
debugger;
|
|
3861
|
-
}
|
|
3659
|
+
if (usage & import_core12.Buffer.VERTEX) {
|
|
3660
|
+
return 35044 /* STATIC_DRAW */;
|
|
3862
3661
|
}
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
functionString = functionString || getFunctionString(functionName, functionArgs);
|
|
3866
|
-
if (props.throwOnError) {
|
|
3867
|
-
throw new Error(`Undefined argument: ${functionString}`);
|
|
3868
|
-
} else {
|
|
3869
|
-
import_core13.log.error(`Undefined argument: ${functionString}`)();
|
|
3870
|
-
debugger;
|
|
3871
|
-
}
|
|
3872
|
-
}
|
|
3662
|
+
if (usage & import_core12.Buffer.UNIFORM) {
|
|
3663
|
+
return 35048 /* DYNAMIC_DRAW */;
|
|
3873
3664
|
}
|
|
3665
|
+
return 35044 /* STATIC_DRAW */;
|
|
3874
3666
|
}
|
|
3875
3667
|
|
|
3876
3668
|
// src/adapter/resources/webgl-shader.ts
|
|
3877
|
-
var
|
|
3669
|
+
var import_core13 = __toESM(require_core(), 1);
|
|
3878
3670
|
|
|
3879
3671
|
// src/adapter/helpers/parse-shader-compiler-log.ts
|
|
3880
3672
|
function parseShaderCompilerLog(errLog) {
|
|
@@ -3921,7 +3713,7 @@ var __exports__ = (() => {
|
|
|
3921
3713
|
}
|
|
3922
3714
|
|
|
3923
3715
|
// src/adapter/resources/webgl-shader.ts
|
|
3924
|
-
var WEBGLShader = class extends
|
|
3716
|
+
var WEBGLShader = class extends import_core13.Shader {
|
|
3925
3717
|
device;
|
|
3926
3718
|
handle;
|
|
3927
3719
|
constructor(device, props) {
|
|
@@ -3952,12 +3744,12 @@ var __exports__ = (() => {
|
|
|
3952
3744
|
}
|
|
3953
3745
|
getCompilationInfoSync() {
|
|
3954
3746
|
const log9 = this.device.gl.getShaderInfoLog(this.handle);
|
|
3955
|
-
return parseShaderCompilerLog(log9);
|
|
3747
|
+
return log9 ? parseShaderCompilerLog(log9) : [];
|
|
3956
3748
|
}
|
|
3957
3749
|
getTranslatedSource() {
|
|
3958
3750
|
const extensions = this.device.getExtension("WEBGL_debug_shaders");
|
|
3959
3751
|
const ext = extensions.WEBGL_debug_shaders;
|
|
3960
|
-
return ext?.getTranslatedShaderSource(this.handle);
|
|
3752
|
+
return ext?.getTranslatedShaderSource(this.handle) || null;
|
|
3961
3753
|
}
|
|
3962
3754
|
// PRIVATE METHODS
|
|
3963
3755
|
/** Compile a shader and get compilation status */
|
|
@@ -3968,7 +3760,7 @@ ${source2}`;
|
|
|
3968
3760
|
const { gl } = this.device;
|
|
3969
3761
|
gl.shaderSource(this.handle, source);
|
|
3970
3762
|
gl.compileShader(this.handle);
|
|
3971
|
-
if (
|
|
3763
|
+
if (import_core13.log.level === 0) {
|
|
3972
3764
|
this.compilationStatus = "pending";
|
|
3973
3765
|
return;
|
|
3974
3766
|
}
|
|
@@ -3980,9 +3772,9 @@ ${source2}`;
|
|
|
3980
3772
|
}
|
|
3981
3773
|
return;
|
|
3982
3774
|
}
|
|
3983
|
-
|
|
3775
|
+
import_core13.log.once(1, "Shader compilation is asynchronous")();
|
|
3984
3776
|
await this._waitForCompilationComplete();
|
|
3985
|
-
|
|
3777
|
+
import_core13.log.info(2, `Shader ${this.id} - async compilation complete: ${this.compilationStatus}`)();
|
|
3986
3778
|
this._getCompilationStatus();
|
|
3987
3779
|
this.debugShader();
|
|
3988
3780
|
}
|
|
@@ -4014,13 +3806,13 @@ ${source2}`;
|
|
|
4014
3806
|
};
|
|
4015
3807
|
|
|
4016
3808
|
// src/adapter/resources/webgl-render-pass.ts
|
|
4017
|
-
var
|
|
3809
|
+
var import_core14 = __toESM(require_core(), 1);
|
|
4018
3810
|
var GL_DEPTH_BUFFER_BIT = 256;
|
|
4019
3811
|
var GL_STENCIL_BUFFER_BIT = 1024;
|
|
4020
3812
|
var GL_COLOR_BUFFER_BIT = 16384;
|
|
4021
3813
|
var GL_COLOR = 6144;
|
|
4022
3814
|
var COLOR_CHANNELS = [1, 2, 4, 8];
|
|
4023
|
-
var WEBGLRenderPass = class extends
|
|
3815
|
+
var WEBGLRenderPass = class extends import_core14.RenderPass {
|
|
4024
3816
|
device;
|
|
4025
3817
|
/** Parameters that should be applied before each draw call */
|
|
4026
3818
|
glParameters;
|
|
@@ -4048,9 +3840,7 @@ ${source2}`;
|
|
|
4048
3840
|
*/
|
|
4049
3841
|
setParameters(parameters = {}) {
|
|
4050
3842
|
const glParameters = { ...this.glParameters };
|
|
4051
|
-
|
|
4052
|
-
glParameters.framebuffer = this.props.framebuffer;
|
|
4053
|
-
}
|
|
3843
|
+
glParameters.framebuffer = this.props.framebuffer || null;
|
|
4054
3844
|
if (this.props.depthReadOnly) {
|
|
4055
3845
|
glParameters.depthMask = !this.props.depthReadOnly;
|
|
4056
3846
|
}
|
|
@@ -4156,11 +3946,7 @@ ${source2}`;
|
|
|
4156
3946
|
};
|
|
4157
3947
|
|
|
4158
3948
|
// src/adapter/resources/webgl-render-pipeline.ts
|
|
4159
|
-
var
|
|
4160
|
-
var import_core18 = __toESM(require_core(), 1);
|
|
4161
|
-
|
|
4162
|
-
// src/classic/accessor.ts
|
|
4163
|
-
var import_core16 = __toESM(require_core(), 1);
|
|
3949
|
+
var import_core15 = __toESM(require_core(), 1);
|
|
4164
3950
|
|
|
4165
3951
|
// src/classic/typed-array-utils.ts
|
|
4166
3952
|
var ERR_TYPE_DEDUCTION = "Failed to deduce GL constant from typed array";
|
|
@@ -4222,12 +4008,6 @@ ${source2}`;
|
|
|
4222
4008
|
normalized: false,
|
|
4223
4009
|
integer: false
|
|
4224
4010
|
};
|
|
4225
|
-
var PROP_CHECKS = {
|
|
4226
|
-
deprecatedProps: {
|
|
4227
|
-
instanced: "divisor",
|
|
4228
|
-
isInstanced: "divisor"
|
|
4229
|
-
}
|
|
4230
|
-
};
|
|
4231
4011
|
var Accessor = class {
|
|
4232
4012
|
offset;
|
|
4233
4013
|
stride;
|
|
@@ -4243,7 +4023,6 @@ ${source2}`;
|
|
|
4243
4023
|
return ArrayType.BYTES_PER_ELEMENT;
|
|
4244
4024
|
}
|
|
4245
4025
|
static getBytesPerVertex(accessor) {
|
|
4246
|
-
(0, import_core16.assert)(accessor.size);
|
|
4247
4026
|
const ArrayType = getTypedArrayFromGLType(accessor.type || 5126 /* FLOAT */);
|
|
4248
4027
|
return ArrayType.BYTES_PER_ELEMENT * accessor.size;
|
|
4249
4028
|
}
|
|
@@ -4272,7 +4051,6 @@ ${source2}`;
|
|
|
4272
4051
|
// PRIVATE
|
|
4273
4052
|
// eslint-disable-next-line complexity, max-statements
|
|
4274
4053
|
_assign(props = {}) {
|
|
4275
|
-
props = (0, import_core16.checkProps)("Accessor", props, PROP_CHECKS);
|
|
4276
4054
|
if (props.type !== void 0) {
|
|
4277
4055
|
this.type = props.type;
|
|
4278
4056
|
if (props.type === 5124 /* INT */ || props.type === 5125 /* UNSIGNED_INT */) {
|
|
@@ -4715,6 +4493,34 @@ ${source2}`;
|
|
|
4715
4493
|
throw new Error("Illegal uniform");
|
|
4716
4494
|
}
|
|
4717
4495
|
|
|
4496
|
+
// ../../node_modules/@math.gl/types/dist/is-array.js
|
|
4497
|
+
function isTypedArray(value) {
|
|
4498
|
+
return ArrayBuffer.isView(value) && !(value instanceof DataView) ? value : null;
|
|
4499
|
+
}
|
|
4500
|
+
function isNumericArray(value) {
|
|
4501
|
+
if (Array.isArray(value)) {
|
|
4502
|
+
return value.length === 0 || typeof value[0] === "number" ? value : null;
|
|
4503
|
+
}
|
|
4504
|
+
return isTypedArray(value);
|
|
4505
|
+
}
|
|
4506
|
+
|
|
4507
|
+
// src/utils/split-uniforms-and-bindings.ts
|
|
4508
|
+
function isUniformValue(value) {
|
|
4509
|
+
return isNumericArray(value) !== null || typeof value === "number" || typeof value === "boolean";
|
|
4510
|
+
}
|
|
4511
|
+
function splitUniformsAndBindings(uniforms) {
|
|
4512
|
+
const result = { bindings: {}, uniforms: {} };
|
|
4513
|
+
Object.keys(uniforms).forEach((name) => {
|
|
4514
|
+
const uniform = uniforms[name];
|
|
4515
|
+
if (isUniformValue(uniform)) {
|
|
4516
|
+
result.uniforms[name] = uniform;
|
|
4517
|
+
} else {
|
|
4518
|
+
result.bindings[name] = uniform;
|
|
4519
|
+
}
|
|
4520
|
+
});
|
|
4521
|
+
return result;
|
|
4522
|
+
}
|
|
4523
|
+
|
|
4718
4524
|
// src/adapter/helpers/webgl-topology-utils.ts
|
|
4719
4525
|
function getGLDrawMode(topology) {
|
|
4720
4526
|
switch (topology) {
|
|
@@ -4724,14 +4530,10 @@ ${source2}`;
|
|
|
4724
4530
|
return 1 /* LINES */;
|
|
4725
4531
|
case "line-strip":
|
|
4726
4532
|
return 3 /* LINE_STRIP */;
|
|
4727
|
-
case "line-loop-webgl":
|
|
4728
|
-
return 2 /* LINE_LOOP */;
|
|
4729
4533
|
case "triangle-list":
|
|
4730
4534
|
return 4 /* TRIANGLES */;
|
|
4731
4535
|
case "triangle-strip":
|
|
4732
4536
|
return 5 /* TRIANGLE_STRIP */;
|
|
4733
|
-
case "triangle-fan-webgl":
|
|
4734
|
-
return 6 /* TRIANGLE_FAN */;
|
|
4735
4537
|
default:
|
|
4736
4538
|
throw new Error(topology);
|
|
4737
4539
|
}
|
|
@@ -4744,14 +4546,10 @@ ${source2}`;
|
|
|
4744
4546
|
return 1 /* LINES */;
|
|
4745
4547
|
case "line-strip":
|
|
4746
4548
|
return 1 /* LINES */;
|
|
4747
|
-
case "line-loop-webgl":
|
|
4748
|
-
return 1 /* LINES */;
|
|
4749
4549
|
case "triangle-list":
|
|
4750
4550
|
return 4 /* TRIANGLES */;
|
|
4751
4551
|
case "triangle-strip":
|
|
4752
4552
|
return 4 /* TRIANGLES */;
|
|
4753
|
-
case "triangle-fan-webgl":
|
|
4754
|
-
return 4 /* TRIANGLES */;
|
|
4755
4553
|
default:
|
|
4756
4554
|
throw new Error(topology);
|
|
4757
4555
|
}
|
|
@@ -4759,7 +4557,7 @@ ${source2}`;
|
|
|
4759
4557
|
|
|
4760
4558
|
// src/adapter/resources/webgl-render-pipeline.ts
|
|
4761
4559
|
var LOG_PROGRAM_PERF_PRIORITY = 4;
|
|
4762
|
-
var WEBGLRenderPipeline = class extends
|
|
4560
|
+
var WEBGLRenderPipeline = class extends import_core15.RenderPipeline {
|
|
4763
4561
|
/** The WebGL device that created this render pipeline */
|
|
4764
4562
|
device;
|
|
4765
4563
|
/** Handle to underlying WebGL program */
|
|
@@ -4784,27 +4582,18 @@ ${source2}`;
|
|
|
4784
4582
|
this.device = device;
|
|
4785
4583
|
this.handle = this.props.handle || this.device.gl.createProgram();
|
|
4786
4584
|
this.device.setSpectorMetadata(this.handle, { id: this.props.id });
|
|
4787
|
-
this.vs =
|
|
4788
|
-
this.fs =
|
|
4585
|
+
this.vs = props.vs;
|
|
4586
|
+
this.fs = props.fs;
|
|
4789
4587
|
const { varyings, bufferMode = 35981 /* SEPARATE_ATTRIBS */ } = props;
|
|
4790
4588
|
if (varyings && varyings.length > 0) {
|
|
4791
4589
|
this.varyings = varyings;
|
|
4792
4590
|
this.device.gl.transformFeedbackVaryings(this.handle, varyings, bufferMode);
|
|
4793
4591
|
}
|
|
4794
4592
|
this._linkShaders();
|
|
4795
|
-
|
|
4593
|
+
import_core15.log.time(1, `RenderPipeline ${this.id} - shaderLayout introspection`)();
|
|
4796
4594
|
this.introspectedLayout = getShaderLayout(this.device.gl, this.handle);
|
|
4797
|
-
|
|
4798
|
-
this.shaderLayout =
|
|
4799
|
-
switch (this.props.topology) {
|
|
4800
|
-
case "triangle-fan-webgl":
|
|
4801
|
-
case "line-loop-webgl":
|
|
4802
|
-
import_core17.log.warn(
|
|
4803
|
-
`Primitive topology ${this.props.topology} is deprecated and will be removed in v9.1`
|
|
4804
|
-
);
|
|
4805
|
-
break;
|
|
4806
|
-
default:
|
|
4807
|
-
}
|
|
4595
|
+
import_core15.log.timeEnd(1, `RenderPipeline ${this.id} - shaderLayout introspection`)();
|
|
4596
|
+
this.shaderLayout = mergeShaderLayout(this.introspectedLayout, props.shaderLayout);
|
|
4808
4597
|
}
|
|
4809
4598
|
destroy() {
|
|
4810
4599
|
if (this.handle) {
|
|
@@ -4822,14 +4611,14 @@ ${source2}`;
|
|
|
4822
4611
|
if (!binding) {
|
|
4823
4612
|
const validBindings = this.shaderLayout.bindings.map((binding2) => `"${binding2.name}"`).join(", ");
|
|
4824
4613
|
if (!options?.disableWarnings) {
|
|
4825
|
-
|
|
4614
|
+
import_core15.log.warn(
|
|
4826
4615
|
`Unknown binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`
|
|
4827
4616
|
)();
|
|
4828
4617
|
}
|
|
4829
4618
|
continue;
|
|
4830
4619
|
}
|
|
4831
4620
|
if (!value) {
|
|
4832
|
-
|
|
4621
|
+
import_core15.log.warn(`Unsetting binding "${name}" in render pipeline "${this.id}"`)();
|
|
4833
4622
|
}
|
|
4834
4623
|
switch (binding.type) {
|
|
4835
4624
|
case "uniform":
|
|
@@ -4843,7 +4632,7 @@ ${source2}`;
|
|
|
4843
4632
|
}
|
|
4844
4633
|
break;
|
|
4845
4634
|
case "sampler":
|
|
4846
|
-
|
|
4635
|
+
import_core15.log.warn(`Ignoring sampler ${name}`)();
|
|
4847
4636
|
break;
|
|
4848
4637
|
default:
|
|
4849
4638
|
throw new Error(binding.type);
|
|
@@ -4875,17 +4664,13 @@ ${source2}`;
|
|
|
4875
4664
|
const isIndexed = Boolean(vertexArray.indexBuffer);
|
|
4876
4665
|
const glIndexType = vertexArray.indexBuffer?.glIndexType;
|
|
4877
4666
|
if (this.linkStatus !== "success") {
|
|
4878
|
-
|
|
4667
|
+
import_core15.log.info(2, `RenderPipeline:${this.id}.draw() aborted - waiting for shader linking`)();
|
|
4879
4668
|
return false;
|
|
4880
4669
|
}
|
|
4881
|
-
if (!this._areTexturesRenderable()
|
|
4882
|
-
|
|
4670
|
+
if (!this._areTexturesRenderable()) {
|
|
4671
|
+
import_core15.log.info(2, `RenderPipeline:${this.id}.draw() aborted - textures not yet loaded`)();
|
|
4883
4672
|
return false;
|
|
4884
4673
|
}
|
|
4885
|
-
if (vertexCount === 0) {
|
|
4886
|
-
import_core17.log.info(2, `RenderPipeline:${this.id}.draw() aborted - no vertices to draw`)();
|
|
4887
|
-
return true;
|
|
4888
|
-
}
|
|
4889
4674
|
this.device.gl.useProgram(this.handle);
|
|
4890
4675
|
vertexArray.bindBeforeRender(renderPass);
|
|
4891
4676
|
if (transformFeedback) {
|
|
@@ -4925,9 +4710,9 @@ ${source2}`;
|
|
|
4925
4710
|
}
|
|
4926
4711
|
// DEPRECATED METHODS
|
|
4927
4712
|
setUniformsWebGL(uniforms) {
|
|
4928
|
-
const { bindings } =
|
|
4713
|
+
const { bindings } = splitUniformsAndBindings(uniforms);
|
|
4929
4714
|
Object.keys(bindings).forEach((name) => {
|
|
4930
|
-
|
|
4715
|
+
import_core15.log.warn(
|
|
4931
4716
|
`Unsupported value "${JSON.stringify(
|
|
4932
4717
|
bindings[name]
|
|
4933
4718
|
)}" used in setUniforms() for key ${name}. Use setBindings() instead?`
|
|
@@ -4942,19 +4727,19 @@ ${source2}`;
|
|
|
4942
4727
|
const { gl } = this.device;
|
|
4943
4728
|
gl.attachShader(this.handle, this.vs.handle);
|
|
4944
4729
|
gl.attachShader(this.handle, this.fs.handle);
|
|
4945
|
-
|
|
4730
|
+
import_core15.log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
|
|
4946
4731
|
gl.linkProgram(this.handle);
|
|
4947
|
-
|
|
4948
|
-
if (
|
|
4732
|
+
import_core15.log.timeEnd(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
|
|
4733
|
+
if (import_core15.log.level === 0) {
|
|
4949
4734
|
}
|
|
4950
4735
|
if (!this.device.features.has("compilation-status-async-webgl")) {
|
|
4951
4736
|
const status2 = this._getLinkStatus();
|
|
4952
4737
|
this._reportLinkStatus(status2);
|
|
4953
4738
|
return;
|
|
4954
4739
|
}
|
|
4955
|
-
|
|
4740
|
+
import_core15.log.once(1, "RenderPipeline linking is asynchronous")();
|
|
4956
4741
|
await this._waitForLinkComplete();
|
|
4957
|
-
|
|
4742
|
+
import_core15.log.info(2, `RenderPipeline ${this.id} - async linking complete: ${this.linkStatus}`)();
|
|
4958
4743
|
const status = this._getLinkStatus();
|
|
4959
4744
|
this._reportLinkStatus(status);
|
|
4960
4745
|
}
|
|
@@ -5020,10 +4805,15 @@ ${source2}`;
|
|
|
5020
4805
|
*/
|
|
5021
4806
|
_areTexturesRenderable() {
|
|
5022
4807
|
let texturesRenderable = true;
|
|
4808
|
+
for (const bindingInfo of this.shaderLayout.bindings) {
|
|
4809
|
+
if (!this.bindings[bindingInfo.name] && !this.bindings[bindingInfo.name.replace(/Uniforms$/, "")]) {
|
|
4810
|
+
import_core15.log.warn(`Binding ${bindingInfo.name} not found in ${this.id}`)();
|
|
4811
|
+
texturesRenderable = false;
|
|
4812
|
+
}
|
|
4813
|
+
}
|
|
5023
4814
|
for (const [, texture] of Object.entries(this.bindings)) {
|
|
5024
4815
|
if (texture instanceof WEBGLTexture) {
|
|
5025
4816
|
texture.update();
|
|
5026
|
-
texturesRenderable = texturesRenderable && texture.loaded;
|
|
5027
4817
|
}
|
|
5028
4818
|
}
|
|
5029
4819
|
return texturesRenderable;
|
|
@@ -5076,7 +4866,7 @@ ${source2}`;
|
|
|
5076
4866
|
} else if (value instanceof WEBGLTexture) {
|
|
5077
4867
|
texture = value;
|
|
5078
4868
|
} else if (value instanceof WEBGLFramebuffer && value.colorAttachments[0] instanceof WEBGLTextureView) {
|
|
5079
|
-
|
|
4869
|
+
import_core15.log.warn(
|
|
5080
4870
|
"Passing framebuffer in texture binding may be deprecated. Use fbo.colorAttachments[0] instead"
|
|
5081
4871
|
)();
|
|
5082
4872
|
texture = value.colorAttachments[0].texture;
|
|
@@ -5084,7 +4874,7 @@ ${source2}`;
|
|
|
5084
4874
|
throw new Error("No texture");
|
|
5085
4875
|
}
|
|
5086
4876
|
gl.activeTexture(33984 /* TEXTURE0 */ + textureUnit);
|
|
5087
|
-
gl.bindTexture(texture.
|
|
4877
|
+
gl.bindTexture(texture.glTarget, texture.handle);
|
|
5088
4878
|
textureUnit += 1;
|
|
5089
4879
|
break;
|
|
5090
4880
|
case "sampler":
|
|
@@ -5109,16 +4899,29 @@ ${source2}`;
|
|
|
5109
4899
|
}
|
|
5110
4900
|
}
|
|
5111
4901
|
};
|
|
4902
|
+
function mergeShaderLayout(baseLayout, overrideLayout) {
|
|
4903
|
+
const mergedLayout = {
|
|
4904
|
+
...baseLayout,
|
|
4905
|
+
attributes: baseLayout.attributes.map((attribute) => ({ ...attribute }))
|
|
4906
|
+
};
|
|
4907
|
+
for (const attribute of overrideLayout?.attributes || []) {
|
|
4908
|
+
const baseAttribute = mergedLayout.attributes.find((attr) => attr.name === attribute.name);
|
|
4909
|
+
if (!baseAttribute) {
|
|
4910
|
+
import_core15.log.warn(`shader layout attribute ${attribute.name} not present in shader`);
|
|
4911
|
+
} else {
|
|
4912
|
+
baseAttribute.type = attribute.type || baseAttribute.type;
|
|
4913
|
+
baseAttribute.stepMode = attribute.stepMode || baseAttribute.stepMode;
|
|
4914
|
+
}
|
|
4915
|
+
}
|
|
4916
|
+
return mergedLayout;
|
|
4917
|
+
}
|
|
5112
4918
|
|
|
5113
4919
|
// src/adapter/resources/webgl-command-encoder.ts
|
|
5114
|
-
var
|
|
4920
|
+
var import_core17 = __toESM(require_core(), 1);
|
|
5115
4921
|
|
|
5116
4922
|
// src/adapter/resources/webgl-command-buffer.ts
|
|
5117
|
-
var
|
|
5118
|
-
|
|
5119
|
-
return value;
|
|
5120
|
-
}
|
|
5121
|
-
var WEBGLCommandBuffer = class extends import_core19.CommandBuffer {
|
|
4923
|
+
var import_core16 = __toESM(require_core(), 1);
|
|
4924
|
+
var WEBGLCommandBuffer = class extends import_core16.CommandBuffer {
|
|
5122
4925
|
device;
|
|
5123
4926
|
commands = [];
|
|
5124
4927
|
constructor(device) {
|
|
@@ -5145,8 +4948,8 @@ ${source2}`;
|
|
|
5145
4948
|
}
|
|
5146
4949
|
};
|
|
5147
4950
|
function _copyBufferToBuffer(device, options) {
|
|
5148
|
-
const source =
|
|
5149
|
-
const destination =
|
|
4951
|
+
const source = options.source;
|
|
4952
|
+
const destination = options.destination;
|
|
5150
4953
|
device.gl.bindBuffer(36662 /* COPY_READ_BUFFER */, source.handle);
|
|
5151
4954
|
device.gl.bindBuffer(36663 /* COPY_WRITE_BUFFER */, destination.handle);
|
|
5152
4955
|
device.gl.copyBufferSubData(
|
|
@@ -5205,8 +5008,10 @@ ${source2}`;
|
|
|
5205
5008
|
const webglBuffer = destination;
|
|
5206
5009
|
const sourceWidth = width || framebuffer.width;
|
|
5207
5010
|
const sourceHeight = height || framebuffer.height;
|
|
5208
|
-
const sourceParams =
|
|
5209
|
-
|
|
5011
|
+
const sourceParams = getTextureFormatWebGL(
|
|
5012
|
+
framebuffer.colorAttachments[0].texture.props.format
|
|
5013
|
+
);
|
|
5014
|
+
const sourceFormat = sourceParams.format;
|
|
5210
5015
|
const sourceType = sourceParams.type;
|
|
5211
5016
|
device.gl.bindBuffer(35051 /* PIXEL_PACK_BUFFER */, webglBuffer.handle);
|
|
5212
5017
|
prevHandle = device.gl.bindFramebuffer(36160 /* FRAMEBUFFER */, framebuffer.handle);
|
|
@@ -5269,7 +5074,7 @@ ${source2}`;
|
|
|
5269
5074
|
width = Number.isFinite(width) ? width : texture.width;
|
|
5270
5075
|
height = Number.isFinite(height) ? height : texture.height;
|
|
5271
5076
|
texture.bind(0);
|
|
5272
|
-
textureTarget = texture.
|
|
5077
|
+
textureTarget = texture.glTarget;
|
|
5273
5078
|
} else {
|
|
5274
5079
|
throw new Error("invalid destination");
|
|
5275
5080
|
}
|
|
@@ -5312,7 +5117,7 @@ ${source2}`;
|
|
|
5312
5117
|
}
|
|
5313
5118
|
}
|
|
5314
5119
|
function getFramebuffer(source) {
|
|
5315
|
-
if (source instanceof
|
|
5120
|
+
if (source instanceof import_core16.Texture) {
|
|
5316
5121
|
const { width, height, id } = source;
|
|
5317
5122
|
const framebuffer = source.device.createFramebuffer({
|
|
5318
5123
|
id: `framebuffer-for-${id}`,
|
|
@@ -5326,7 +5131,7 @@ ${source2}`;
|
|
|
5326
5131
|
}
|
|
5327
5132
|
|
|
5328
5133
|
// src/adapter/resources/webgl-command-encoder.ts
|
|
5329
|
-
var WEBGLCommandEncoder = class extends
|
|
5134
|
+
var WEBGLCommandEncoder = class extends import_core17.CommandEncoder {
|
|
5330
5135
|
device;
|
|
5331
5136
|
commandBuffer;
|
|
5332
5137
|
constructor(device, props) {
|
|
@@ -5365,8 +5170,31 @@ ${source2}`;
|
|
|
5365
5170
|
};
|
|
5366
5171
|
|
|
5367
5172
|
// src/adapter/resources/webgl-vertex-array.ts
|
|
5368
|
-
var
|
|
5369
|
-
|
|
5173
|
+
var import_core18 = __toESM(require_core(), 1);
|
|
5174
|
+
|
|
5175
|
+
// src/utils/fill-array.ts
|
|
5176
|
+
function fillArray(options) {
|
|
5177
|
+
const { target, source, start = 0, count = 1 } = options;
|
|
5178
|
+
const length = source.length;
|
|
5179
|
+
const total = count * length;
|
|
5180
|
+
let copied = 0;
|
|
5181
|
+
for (let i = start; copied < length; copied++) {
|
|
5182
|
+
target[i++] = source[copied];
|
|
5183
|
+
}
|
|
5184
|
+
while (copied < total) {
|
|
5185
|
+
if (copied < total - copied) {
|
|
5186
|
+
target.copyWithin(start + copied, start, start + copied);
|
|
5187
|
+
copied *= 2;
|
|
5188
|
+
} else {
|
|
5189
|
+
target.copyWithin(start + copied, start, start + total - copied);
|
|
5190
|
+
copied = total;
|
|
5191
|
+
}
|
|
5192
|
+
}
|
|
5193
|
+
return options.target;
|
|
5194
|
+
}
|
|
5195
|
+
|
|
5196
|
+
// src/adapter/resources/webgl-vertex-array.ts
|
|
5197
|
+
var WEBGLVertexArray = class extends import_core18.VertexArray {
|
|
5370
5198
|
get [Symbol.toStringTag]() {
|
|
5371
5199
|
return "VertexArray";
|
|
5372
5200
|
}
|
|
@@ -5425,6 +5253,7 @@ ${source2}`;
|
|
|
5425
5253
|
} else {
|
|
5426
5254
|
this.device.gl.vertexAttribPointer(location, size, type, normalized, stride, offset);
|
|
5427
5255
|
}
|
|
5256
|
+
this.device.gl.bindBuffer(34962 /* ARRAY_BUFFER */, null);
|
|
5428
5257
|
this.device.gl.enableVertexAttribArray(location);
|
|
5429
5258
|
this.device.gl.vertexAttribDivisor(location, divisor || 0);
|
|
5430
5259
|
this.attributes[location] = buffer;
|
|
@@ -5533,8 +5362,8 @@ ${source2}`;
|
|
|
5533
5362
|
this.buffer = this.buffer || this.device.createBuffer({ byteLength });
|
|
5534
5363
|
updateNeeded = updateNeeded || !compareConstantArrayValues(constantValue, this.bufferValue);
|
|
5535
5364
|
if (updateNeeded) {
|
|
5536
|
-
const typedArray = (0,
|
|
5537
|
-
|
|
5365
|
+
const typedArray = (0, import_core18.getScratchArray)(value.constructor, length);
|
|
5366
|
+
fillArray({ target: typedArray, source: constantValue, start: 0, count: length });
|
|
5538
5367
|
this.buffer.write(typedArray);
|
|
5539
5368
|
this.bufferValue = value;
|
|
5540
5369
|
}
|
|
@@ -5560,8 +5389,8 @@ ${source2}`;
|
|
|
5560
5389
|
}
|
|
5561
5390
|
|
|
5562
5391
|
// src/adapter/resources/webgl-transform-feedback.ts
|
|
5563
|
-
var
|
|
5564
|
-
var WEBGLTransformFeedback = class extends
|
|
5392
|
+
var import_core19 = __toESM(require_core(), 1);
|
|
5393
|
+
var WEBGLTransformFeedback = class extends import_core19.TransformFeedback {
|
|
5565
5394
|
device;
|
|
5566
5395
|
gl;
|
|
5567
5396
|
handle;
|
|
@@ -5604,7 +5433,7 @@ ${source2}`;
|
|
|
5604
5433
|
}
|
|
5605
5434
|
end() {
|
|
5606
5435
|
this.gl.endTransformFeedback();
|
|
5607
|
-
if (
|
|
5436
|
+
if (this.bindOnUse) {
|
|
5608
5437
|
this._unbindBuffers();
|
|
5609
5438
|
}
|
|
5610
5439
|
this.gl.bindTransformFeedback(36386 /* TRANSFORM_FEEDBACK */, null);
|
|
@@ -5624,7 +5453,7 @@ ${source2}`;
|
|
|
5624
5453
|
const { buffer, byteLength, byteOffset } = this._getBufferRange(bufferOrRange);
|
|
5625
5454
|
if (location < 0) {
|
|
5626
5455
|
this.unusedBuffers[locationOrName] = buffer;
|
|
5627
|
-
|
|
5456
|
+
import_core19.log.warn(`${this.id} unusedBuffers varying buffer ${locationOrName}`)();
|
|
5628
5457
|
return;
|
|
5629
5458
|
}
|
|
5630
5459
|
this.buffers[location] = { buffer, byteLength, byteOffset };
|
|
@@ -5711,8 +5540,8 @@ ${source2}`;
|
|
|
5711
5540
|
}
|
|
5712
5541
|
|
|
5713
5542
|
// src/adapter/resources/webgl-query-set.ts
|
|
5714
|
-
var
|
|
5715
|
-
var WEBGLQuerySet = class extends
|
|
5543
|
+
var import_core20 = __toESM(require_core(), 1);
|
|
5544
|
+
var WEBGLQuerySet = class extends import_core20.QuerySet {
|
|
5716
5545
|
device;
|
|
5717
5546
|
handle;
|
|
5718
5547
|
target = null;
|
|
@@ -5845,10 +5674,9 @@ ${source2}`;
|
|
|
5845
5674
|
};
|
|
5846
5675
|
|
|
5847
5676
|
// src/classic/copy-and-blit.ts
|
|
5848
|
-
var
|
|
5677
|
+
var import_core21 = __toESM(require_core(), 1);
|
|
5849
5678
|
|
|
5850
5679
|
// src/classic/format-utils.ts
|
|
5851
|
-
var import_core24 = __toESM(require_core(), 1);
|
|
5852
5680
|
function glFormatToComponents(format) {
|
|
5853
5681
|
switch (format) {
|
|
5854
5682
|
case 6406 /* ALPHA */:
|
|
@@ -5865,7 +5693,6 @@ ${source2}`;
|
|
|
5865
5693
|
case 34836 /* RGBA32F */:
|
|
5866
5694
|
return 4;
|
|
5867
5695
|
default:
|
|
5868
|
-
(0, import_core24.assert)(false);
|
|
5869
5696
|
return 0;
|
|
5870
5697
|
}
|
|
5871
5698
|
}
|
|
@@ -5880,7 +5707,6 @@ ${source2}`;
|
|
|
5880
5707
|
case 5126 /* FLOAT */:
|
|
5881
5708
|
return 4;
|
|
5882
5709
|
default:
|
|
5883
|
-
(0, import_core24.assert)(false);
|
|
5884
5710
|
return 0;
|
|
5885
5711
|
}
|
|
5886
5712
|
}
|
|
@@ -5902,12 +5728,11 @@ ${source2}`;
|
|
|
5902
5728
|
sourceType
|
|
5903
5729
|
} = options || {};
|
|
5904
5730
|
const { framebuffer, deleteFramebuffer } = getFramebuffer2(source);
|
|
5905
|
-
(0, import_core25.assert)(framebuffer);
|
|
5906
5731
|
const { gl, handle } = framebuffer;
|
|
5907
5732
|
sourceWidth = sourceWidth || framebuffer.width;
|
|
5908
5733
|
sourceHeight = sourceHeight || framebuffer.height;
|
|
5909
5734
|
const attachment = sourceAttachment - 36064 /* COLOR_ATTACHMENT0 */;
|
|
5910
|
-
sourceType = sourceType || framebuffer.colorAttachments[attachment]?.texture?.
|
|
5735
|
+
sourceType = sourceType || framebuffer.colorAttachments[attachment]?.texture?.glType || 5121 /* UNSIGNED_BYTE */;
|
|
5911
5736
|
target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
|
|
5912
5737
|
sourceType = sourceType || getGLTypeFromTypedArray(target);
|
|
5913
5738
|
const prevHandle = gl.bindFramebuffer(36160 /* FRAMEBUFFER */, handle);
|
|
@@ -5928,7 +5753,6 @@ ${source2}`;
|
|
|
5928
5753
|
} = options || {};
|
|
5929
5754
|
let { sourceWidth, sourceHeight, sourceType } = options || {};
|
|
5930
5755
|
const { framebuffer, deleteFramebuffer } = getFramebuffer2(source);
|
|
5931
|
-
(0, import_core25.assert)(framebuffer);
|
|
5932
5756
|
sourceWidth = sourceWidth || framebuffer.width;
|
|
5933
5757
|
sourceHeight = sourceHeight || framebuffer.height;
|
|
5934
5758
|
const webglFramebuffer = framebuffer;
|
|
@@ -5956,7 +5780,7 @@ ${source2}`;
|
|
|
5956
5780
|
return webglBufferTarget;
|
|
5957
5781
|
}
|
|
5958
5782
|
function getFramebuffer2(source) {
|
|
5959
|
-
if (!(source instanceof
|
|
5783
|
+
if (!(source instanceof import_core21.Framebuffer)) {
|
|
5960
5784
|
return { framebuffer: toFramebuffer(source), deleteFramebuffer: true };
|
|
5961
5785
|
}
|
|
5962
5786
|
return { framebuffer: source, deleteFramebuffer: false };
|
|
@@ -5983,11 +5807,9 @@ ${source2}`;
|
|
|
5983
5807
|
}
|
|
5984
5808
|
|
|
5985
5809
|
// src/classic/clear.ts
|
|
5986
|
-
var import_core26 = __toESM(require_core(), 1);
|
|
5987
5810
|
var GL_DEPTH_BUFFER_BIT2 = 256;
|
|
5988
5811
|
var GL_STENCIL_BUFFER_BIT2 = 1024;
|
|
5989
5812
|
var GL_COLOR_BUFFER_BIT2 = 16384;
|
|
5990
|
-
var ERR_ARGUMENTS = "clear: bad arguments";
|
|
5991
5813
|
function clear(device, options) {
|
|
5992
5814
|
const { framebuffer = null, color = null, depth = null, stencil = null } = options || {};
|
|
5993
5815
|
const parameters = {};
|
|
@@ -6013,7 +5835,6 @@ ${source2}`;
|
|
|
6013
5835
|
parameters.clearStencil = depth;
|
|
6014
5836
|
}
|
|
6015
5837
|
}
|
|
6016
|
-
(0, import_core26.assert)(clearFlags !== 0, ERR_ARGUMENTS);
|
|
6017
5838
|
const gl = device.gl;
|
|
6018
5839
|
withGLParameters(gl, parameters, () => {
|
|
6019
5840
|
gl.clear(clearFlags);
|
|
@@ -6022,7 +5843,7 @@ ${source2}`;
|
|
|
6022
5843
|
|
|
6023
5844
|
// src/adapter/webgl-device.ts
|
|
6024
5845
|
var LOG_LEVEL2 = 1;
|
|
6025
|
-
var _WebGLDevice = class extends
|
|
5846
|
+
var _WebGLDevice = class extends import_core22.Device {
|
|
6026
5847
|
/** type of this device */
|
|
6027
5848
|
type = "webgl";
|
|
6028
5849
|
/** The underlying WebGL context */
|
|
@@ -6050,7 +5871,7 @@ ${source2}`;
|
|
|
6050
5871
|
if (gl instanceof _WebGLDevice) {
|
|
6051
5872
|
return gl;
|
|
6052
5873
|
}
|
|
6053
|
-
if (gl?.device instanceof
|
|
5874
|
+
if (gl?.device instanceof import_core22.Device) {
|
|
6054
5875
|
return gl.device;
|
|
6055
5876
|
}
|
|
6056
5877
|
if (!isWebGL(gl)) {
|
|
@@ -6059,7 +5880,7 @@ ${source2}`;
|
|
|
6059
5880
|
return new _WebGLDevice({ gl });
|
|
6060
5881
|
}
|
|
6061
5882
|
static async create(props = {}) {
|
|
6062
|
-
|
|
5883
|
+
import_core22.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
|
|
6063
5884
|
const promises = [];
|
|
6064
5885
|
if (props.debug) {
|
|
6065
5886
|
promises.push(loadWebGLDeveloperTools());
|
|
@@ -6068,31 +5889,31 @@ ${source2}`;
|
|
|
6068
5889
|
promises.push(loadSpectorJS());
|
|
6069
5890
|
}
|
|
6070
5891
|
if (typeof props.canvas === "string") {
|
|
6071
|
-
promises.push(
|
|
5892
|
+
promises.push(import_core22.CanvasContext.pageLoaded);
|
|
6072
5893
|
}
|
|
6073
5894
|
const results = await Promise.allSettled(promises);
|
|
6074
5895
|
for (const result of results) {
|
|
6075
5896
|
if (result.status === "rejected") {
|
|
6076
|
-
|
|
5897
|
+
import_core22.log.error(`Failed to initialize debug libraries ${result.reason}`)();
|
|
6077
5898
|
}
|
|
6078
5899
|
}
|
|
6079
|
-
|
|
5900
|
+
import_core22.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
|
|
6080
5901
|
if (props.gl?.device) {
|
|
6081
|
-
|
|
5902
|
+
import_core22.log.warn("reattaching existing device")();
|
|
6082
5903
|
return _WebGLDevice.attach(props.gl);
|
|
6083
5904
|
}
|
|
6084
5905
|
const device = new _WebGLDevice(props);
|
|
6085
5906
|
const message2 = `Created ${device.type}${device.debug ? " debug" : ""} context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
|
|
5907
|
+
import_core22.log.probe(LOG_LEVEL2, message2)();
|
|
5908
|
+
import_core22.log.table(LOG_LEVEL2, device.info)();
|
|
5909
|
+
import_core22.log.groupEnd(LOG_LEVEL2)();
|
|
6089
5910
|
return device;
|
|
6090
5911
|
}
|
|
6091
5912
|
//
|
|
6092
5913
|
// Public API
|
|
6093
5914
|
//
|
|
6094
5915
|
constructor(props) {
|
|
6095
|
-
super({ ...props, id: props.id ||
|
|
5916
|
+
super({ ...props, id: props.id || "webgl-device" });
|
|
6096
5917
|
const device = props.gl?.device;
|
|
6097
5918
|
if (device) {
|
|
6098
5919
|
throw new Error(`WebGL context already attached to device ${device.id}`);
|
|
@@ -6128,13 +5949,13 @@ ${source2}`;
|
|
|
6128
5949
|
trackContextState(this.gl, {
|
|
6129
5950
|
enable: enable2,
|
|
6130
5951
|
copyState,
|
|
6131
|
-
log: (...args) =>
|
|
5952
|
+
log: (...args) => import_core22.log.log(1, ...args)()
|
|
6132
5953
|
});
|
|
6133
5954
|
if (props.debug) {
|
|
6134
5955
|
this.gl = makeDebugContext(this.gl, { ...props, throwOnError: true });
|
|
6135
5956
|
this.debug = true;
|
|
6136
|
-
|
|
6137
|
-
|
|
5957
|
+
import_core22.log.level = Math.max(import_core22.log.level, 1);
|
|
5958
|
+
import_core22.log.warn("WebGL debug mode activated. Performance reduced.")();
|
|
6138
5959
|
}
|
|
6139
5960
|
if (props.spector) {
|
|
6140
5961
|
this.spectorJS = initializeSpectorJS({ ...this.props, canvas: this.handle.canvas });
|
|
@@ -6169,6 +5990,7 @@ ${source2}`;
|
|
|
6169
5990
|
const newProps = this._getBufferProps(props);
|
|
6170
5991
|
return new WEBGLBuffer(this, newProps);
|
|
6171
5992
|
}
|
|
5993
|
+
// _createTexture(props: TextureProps): WEBGLTexture {
|
|
6172
5994
|
_createTexture(props) {
|
|
6173
5995
|
return new WEBGLTexture(this, props);
|
|
6174
5996
|
}
|
|
@@ -6206,7 +6028,7 @@ ${source2}`;
|
|
|
6206
6028
|
throw new Error("ComputePass not supported in WebGL");
|
|
6207
6029
|
}
|
|
6208
6030
|
renderPass = null;
|
|
6209
|
-
createCommandEncoder(props) {
|
|
6031
|
+
createCommandEncoder(props = {}) {
|
|
6210
6032
|
return new WEBGLCommandEncoder(this, props);
|
|
6211
6033
|
}
|
|
6212
6034
|
/**
|
|
@@ -6242,7 +6064,7 @@ ${source2}`;
|
|
|
6242
6064
|
clear(this, options);
|
|
6243
6065
|
}
|
|
6244
6066
|
resetWebGL() {
|
|
6245
|
-
|
|
6067
|
+
import_core22.log.warn("WebGLDevice.resetWebGL is deprecated, use only for debugging")();
|
|
6246
6068
|
resetGLParameters(this.gl);
|
|
6247
6069
|
}
|
|
6248
6070
|
//
|
|
@@ -6319,7 +6141,7 @@ ${source2}`;
|
|
|
6319
6141
|
this._constants = this._constants || new Array(maxVertexAttributes).fill(null);
|
|
6320
6142
|
const currentConstant = this._constants[location];
|
|
6321
6143
|
if (currentConstant && compareConstantArrayValues2(currentConstant, constant)) {
|
|
6322
|
-
|
|
6144
|
+
import_core22.log.info(
|
|
6323
6145
|
1,
|
|
6324
6146
|
`setConstantAttributeWebGL(${location}) could have been skipped, value unchanged`
|
|
6325
6147
|
)();
|
|
@@ -6336,7 +6158,7 @@ ${source2}`;
|
|
|
6336
6158
|
setConstantUintArray(this, location, constant);
|
|
6337
6159
|
break;
|
|
6338
6160
|
default:
|
|
6339
|
-
|
|
6161
|
+
throw new Error("constant");
|
|
6340
6162
|
}
|
|
6341
6163
|
}
|
|
6342
6164
|
/** Ensure extensions are only requested once */
|
|
@@ -6372,7 +6194,6 @@ ${source2}`;
|
|
|
6372
6194
|
device.gl.vertexAttrib4fv(location, array);
|
|
6373
6195
|
break;
|
|
6374
6196
|
default:
|
|
6375
|
-
(0, import_core27.assert)(false);
|
|
6376
6197
|
}
|
|
6377
6198
|
}
|
|
6378
6199
|
function setConstantIntArray(device, location, array) {
|
|
@@ -6392,217 +6213,6 @@ ${source2}`;
|
|
|
6392
6213
|
}
|
|
6393
6214
|
return true;
|
|
6394
6215
|
}
|
|
6395
|
-
|
|
6396
|
-
// src/adapter/objects/webgl-resource.ts
|
|
6397
|
-
var import_core28 = __toESM(require_core(), 1);
|
|
6398
|
-
var ERR_RESOURCE_METHOD_UNDEFINED = "Resource subclass must define virtual methods";
|
|
6399
|
-
var WebGLResource = class extends import_core28.Resource {
|
|
6400
|
-
device;
|
|
6401
|
-
gl;
|
|
6402
|
-
gl2;
|
|
6403
|
-
_handle;
|
|
6404
|
-
_bound = false;
|
|
6405
|
-
// Only meaningful for resources that allocate GPU memory
|
|
6406
|
-
byteLength = 0;
|
|
6407
|
-
constructor(device, props, defaultProps) {
|
|
6408
|
-
super(device, props, defaultProps);
|
|
6409
|
-
this.device = device;
|
|
6410
|
-
const gl = this.device.gl;
|
|
6411
|
-
const { id } = props || {};
|
|
6412
|
-
this.gl = gl;
|
|
6413
|
-
this.gl2 = gl;
|
|
6414
|
-
this.id = id || (0, import_core28.uid)(this.constructor.name);
|
|
6415
|
-
this._handle = props?.handle;
|
|
6416
|
-
if (this._handle === void 0) {
|
|
6417
|
-
this._handle = this._createHandle();
|
|
6418
|
-
}
|
|
6419
|
-
this.byteLength = 0;
|
|
6420
|
-
}
|
|
6421
|
-
toString() {
|
|
6422
|
-
return `${this.constructor.name}(${this.id})`;
|
|
6423
|
-
}
|
|
6424
|
-
get handle() {
|
|
6425
|
-
return this._handle;
|
|
6426
|
-
}
|
|
6427
|
-
delete({ deleteChildren = false } = {}) {
|
|
6428
|
-
const children = this._handle && this._deleteHandle(this._handle);
|
|
6429
|
-
if (this._handle) {
|
|
6430
|
-
this.removeStats();
|
|
6431
|
-
}
|
|
6432
|
-
this._handle = null;
|
|
6433
|
-
if (children && deleteChildren) {
|
|
6434
|
-
children.filter(Boolean).forEach((child) => child.destroy());
|
|
6435
|
-
}
|
|
6436
|
-
return this;
|
|
6437
|
-
}
|
|
6438
|
-
bind(funcOrHandle = this.handle) {
|
|
6439
|
-
if (typeof funcOrHandle !== "function") {
|
|
6440
|
-
this._bindHandle(funcOrHandle);
|
|
6441
|
-
return this;
|
|
6442
|
-
}
|
|
6443
|
-
let value;
|
|
6444
|
-
if (!this._bound) {
|
|
6445
|
-
this._bindHandle(this.handle);
|
|
6446
|
-
this._bound = true;
|
|
6447
|
-
value = funcOrHandle();
|
|
6448
|
-
this._bound = false;
|
|
6449
|
-
this._bindHandle(null);
|
|
6450
|
-
} else {
|
|
6451
|
-
value = funcOrHandle();
|
|
6452
|
-
}
|
|
6453
|
-
return value;
|
|
6454
|
-
}
|
|
6455
|
-
unbind() {
|
|
6456
|
-
this.bind(null);
|
|
6457
|
-
}
|
|
6458
|
-
// Install stubs for removed methods
|
|
6459
|
-
stubRemovedMethods(className, version, methodNames) {
|
|
6460
|
-
return (0, import_core28.stubRemovedMethods)(this, className, version, methodNames);
|
|
6461
|
-
}
|
|
6462
|
-
// PUBLIC VIRTUAL METHODS
|
|
6463
|
-
initialize(props) {
|
|
6464
|
-
}
|
|
6465
|
-
// PROTECTED METHODS - These must be overridden by subclass
|
|
6466
|
-
_createHandle() {
|
|
6467
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
6468
|
-
}
|
|
6469
|
-
_deleteHandle() {
|
|
6470
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
6471
|
-
}
|
|
6472
|
-
_bindHandle(handle) {
|
|
6473
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
6474
|
-
}
|
|
6475
|
-
_getOptsFromHandle() {
|
|
6476
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
6477
|
-
}
|
|
6478
|
-
_getParameter(pname, props) {
|
|
6479
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
6480
|
-
}
|
|
6481
|
-
_setParameter(pname, value) {
|
|
6482
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
6483
|
-
}
|
|
6484
|
-
// PRIVATE METHODS
|
|
6485
|
-
/*
|
|
6486
|
-
_addStats() {
|
|
6487
|
-
const name = this.constructor.name;
|
|
6488
|
-
const stats = lumaStats.get('Resource Counts');
|
|
6489
|
-
|
|
6490
|
-
stats.get('Resources Created').incrementCount();
|
|
6491
|
-
stats.get(`${name}s Created`).incrementCount();
|
|
6492
|
-
stats.get(`${name}s Active`).incrementCount();
|
|
6493
|
-
}
|
|
6494
|
-
|
|
6495
|
-
_removeStats() {
|
|
6496
|
-
const name = this.constructor.name;
|
|
6497
|
-
const stats = lumaStats.get('Resource Counts');
|
|
6498
|
-
|
|
6499
|
-
stats.get(`${name}s Active`).decrementCount();
|
|
6500
|
-
}
|
|
6501
|
-
|
|
6502
|
-
trackAllocatedMemory(bytes, name = this.constructor.name) {
|
|
6503
|
-
const stats = lumaStats.get('Memory Usage');
|
|
6504
|
-
|
|
6505
|
-
stats.get('GPU Memory').addCount(bytes);
|
|
6506
|
-
stats.get(`${name} Memory`).addCount(bytes);
|
|
6507
|
-
this.byteLength = bytes;
|
|
6508
|
-
}
|
|
6509
|
-
|
|
6510
|
-
trackDeallocatedMemory(name = this.constructor.name) {
|
|
6511
|
-
const stats = lumaStats.get('Memory Usage');
|
|
6512
|
-
|
|
6513
|
-
stats.get('GPU Memory').subtractCount(this.byteLength);
|
|
6514
|
-
stats.get(`${name} Memory`).subtractCount(this.byteLength);
|
|
6515
|
-
this.byteLength = 0;
|
|
6516
|
-
}
|
|
6517
|
-
*/
|
|
6518
|
-
};
|
|
6519
|
-
|
|
6520
|
-
// src/adapter/objects/webgl-renderbuffer.ts
|
|
6521
|
-
var import_core29 = __toESM(require_core(), 1);
|
|
6522
|
-
var _WEBGLRenderbuffer = class extends WebGLResource {
|
|
6523
|
-
get [Symbol.toStringTag]() {
|
|
6524
|
-
return "Renderbuffer";
|
|
6525
|
-
}
|
|
6526
|
-
get width() {
|
|
6527
|
-
return this.props.width;
|
|
6528
|
-
}
|
|
6529
|
-
get height() {
|
|
6530
|
-
return this.props.height;
|
|
6531
|
-
}
|
|
6532
|
-
get format() {
|
|
6533
|
-
return this.props.format;
|
|
6534
|
-
}
|
|
6535
|
-
get samples() {
|
|
6536
|
-
return this.props.samples;
|
|
6537
|
-
}
|
|
6538
|
-
get attachment() {
|
|
6539
|
-
return;
|
|
6540
|
-
}
|
|
6541
|
-
/** WebGL format constant */
|
|
6542
|
-
glFormat;
|
|
6543
|
-
static isTextureFormatSupported(device, format) {
|
|
6544
|
-
return isRenderbufferFormatSupported(device.gl, format, device._extensions);
|
|
6545
|
-
}
|
|
6546
|
-
constructor(device, props) {
|
|
6547
|
-
if (typeof props.format === "number") {
|
|
6548
|
-
throw new Error("Renderbuffer");
|
|
6549
|
-
}
|
|
6550
|
-
super(device, props, _WEBGLRenderbuffer.defaultProps);
|
|
6551
|
-
this.glFormat = convertTextureFormatToGL(this.props.format);
|
|
6552
|
-
this._initialize(this.props);
|
|
6553
|
-
}
|
|
6554
|
-
resize(size) {
|
|
6555
|
-
if (size.width !== this.width || size.height !== this.height) {
|
|
6556
|
-
Object.assign(this.props, { ...size, format: this.format, samples: this.samples });
|
|
6557
|
-
this._initialize(this.props);
|
|
6558
|
-
}
|
|
6559
|
-
}
|
|
6560
|
-
// PRIVATE METHODS
|
|
6561
|
-
/** Creates and initializes a renderbuffer object's data store */
|
|
6562
|
-
_initialize(props) {
|
|
6563
|
-
const { format, width, height, samples } = props;
|
|
6564
|
-
(0, import_core29.assert)(format, "Needs format");
|
|
6565
|
-
this.trackDeallocatedMemory();
|
|
6566
|
-
this.gl.bindRenderbuffer(36161 /* RENDERBUFFER */, this.handle);
|
|
6567
|
-
if (samples !== 0) {
|
|
6568
|
-
this.gl.renderbufferStorageMultisample(
|
|
6569
|
-
36161 /* RENDERBUFFER */,
|
|
6570
|
-
samples,
|
|
6571
|
-
this.glFormat,
|
|
6572
|
-
width,
|
|
6573
|
-
height
|
|
6574
|
-
);
|
|
6575
|
-
} else {
|
|
6576
|
-
this.gl.renderbufferStorage(36161 /* RENDERBUFFER */, this.glFormat, width, height);
|
|
6577
|
-
}
|
|
6578
|
-
this.gl.bindRenderbuffer(36161 /* RENDERBUFFER */, null);
|
|
6579
|
-
this.trackAllocatedMemory(
|
|
6580
|
-
width * height * (samples || 1) * getTextureFormatBytesPerPixel(this.format)
|
|
6581
|
-
);
|
|
6582
|
-
}
|
|
6583
|
-
// RESOURCE IMPLEMENTATION
|
|
6584
|
-
_createHandle() {
|
|
6585
|
-
return this.gl.createRenderbuffer();
|
|
6586
|
-
}
|
|
6587
|
-
_deleteHandle() {
|
|
6588
|
-
this.gl.deleteRenderbuffer(this.handle);
|
|
6589
|
-
this.trackDeallocatedMemory();
|
|
6590
|
-
}
|
|
6591
|
-
_bindHandle(handle) {
|
|
6592
|
-
this.gl.bindRenderbuffer(36161 /* RENDERBUFFER */, handle);
|
|
6593
|
-
}
|
|
6594
|
-
};
|
|
6595
|
-
var WEBGLRenderbuffer = _WEBGLRenderbuffer;
|
|
6596
|
-
__publicField(WEBGLRenderbuffer, "defaultProps", {
|
|
6597
|
-
id: void 0,
|
|
6598
|
-
handle: void 0,
|
|
6599
|
-
userData: void 0,
|
|
6600
|
-
format: void 0,
|
|
6601
|
-
// 'depth16unorm'
|
|
6602
|
-
width: 1,
|
|
6603
|
-
height: 1,
|
|
6604
|
-
samples: 0
|
|
6605
|
-
});
|
|
6606
6216
|
return __toCommonJS(bundle_exports);
|
|
6607
6217
|
})();
|
|
6608
6218
|
return __exports__;
|