@luma.gl/webgl 9.0.0-alpha.30 → 9.0.0-alpha.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/converters/shader-formats.d.ts +9 -0
- package/dist/adapter/converters/shader-formats.d.ts.map +1 -0
- package/dist/adapter/converters/shader-formats.js +53 -0
- package/dist/adapter/converters/shader-formats.js.map +1 -0
- package/dist/adapter/converters/texture-formats.d.ts +1 -2
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +2 -23
- package/dist/adapter/converters/texture-formats.js.map +1 -1
- package/dist/adapter/converters/vertex-formats.d.ts +8 -2
- package/dist/adapter/converters/vertex-formats.d.ts.map +1 -1
- package/dist/adapter/converters/vertex-formats.js +47 -9
- package/dist/adapter/converters/vertex-formats.js.map +1 -1
- package/dist/adapter/helpers/{uniforms.d.ts → decode-webgl-types.d.ts} +9 -8
- package/dist/adapter/helpers/decode-webgl-types.d.ts.map +1 -0
- package/dist/adapter/helpers/{uniforms.js → decode-webgl-types.js} +14 -13
- package/dist/adapter/helpers/decode-webgl-types.js.map +1 -0
- package/dist/adapter/helpers/get-shader-layout.d.ts +1 -51
- package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
- package/dist/adapter/helpers/get-shader-layout.js +14 -86
- package/dist/adapter/helpers/get-shader-layout.js.map +1 -1
- package/dist/adapter/helpers/{attribute-utils.d.ts → webgl-topology-utils.d.ts} +1 -1
- package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -0
- package/dist/adapter/helpers/{attribute-utils.js → webgl-topology-utils.js} +1 -1
- package/dist/adapter/helpers/webgl-topology-utils.js.map +1 -0
- package/dist/adapter/objects/webgl-vertex-array-object.d.ts +2 -1
- package/dist/adapter/objects/webgl-vertex-array-object.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-vertex-array-object.js.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.js +1 -1
- package/dist/adapter/resources/webgl-command-encoder.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +14 -9
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +58 -59
- package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
- package/dist/dist.dev.js +478 -391
- package/dist/index.cjs +641 -695
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist.min.js +22 -22
- package/package.json +5 -5
- package/src/adapter/converters/shader-formats.ts +41 -0
- package/src/adapter/converters/texture-formats.ts +3 -16
- package/src/adapter/converters/vertex-formats.ts +67 -10
- package/src/adapter/helpers/{uniforms.ts → decode-webgl-types.ts} +22 -17
- package/src/adapter/helpers/get-shader-layout.ts +51 -159
- package/src/adapter/objects/webgl-vertex-array-object.ts +2 -1
- package/src/adapter/resources/webgl-command-encoder.ts +1 -1
- package/src/adapter/resources/webgl-render-pipeline.ts +121 -77
- package/src/index.ts +1 -1
- package/src/types.ts +2 -0
- package/dist/adapter/helpers/attribute-utils.d.ts.map +0 -1
- package/dist/adapter/helpers/attribute-utils.js.map +0 -1
- package/dist/adapter/helpers/uniforms.d.ts.map +0 -1
- package/dist/adapter/helpers/uniforms.js.map +0 -1
- /package/src/adapter/helpers/{attribute-utils.ts → webgl-topology-utils.ts} +0 -0
package/dist/dist.dev.js
CHANGED
|
@@ -11,8 +11,8 @@ var __exports__ = (() => {
|
|
|
11
11
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
12
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
13
|
var __export = (target, all) => {
|
|
14
|
-
for (var
|
|
15
|
-
__defProp(target,
|
|
14
|
+
for (var name2 in all)
|
|
15
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
16
16
|
};
|
|
17
17
|
var __copyProps = (to, from, except, desc) => {
|
|
18
18
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -59,7 +59,6 @@ var __exports__ = (() => {
|
|
|
59
59
|
getWebGL2Context: () => getWebGL2Context,
|
|
60
60
|
isWebGL: () => isWebGL,
|
|
61
61
|
isWebGL2: () => isWebGL2,
|
|
62
|
-
mergeShaderLayout: () => mergeShaderLayout,
|
|
63
62
|
polyfillContext: () => polyfillContext,
|
|
64
63
|
popContextState: () => popContextState,
|
|
65
64
|
pushContextState: () => pushContextState,
|
|
@@ -304,7 +303,7 @@ var __exports__ = (() => {
|
|
|
304
303
|
for (const key of propNames) {
|
|
305
304
|
const value = object[key];
|
|
306
305
|
if (typeof value === "function") {
|
|
307
|
-
if (!predefined.find((
|
|
306
|
+
if (!predefined.find((name2) => key === name2)) {
|
|
308
307
|
object[key] = value.bind(obj);
|
|
309
308
|
}
|
|
310
309
|
}
|
|
@@ -693,7 +692,7 @@ var __exports__ = (() => {
|
|
|
693
692
|
|
|
694
693
|
// ../../node_modules/@probe.gl/stats/dist/lib/stat.js
|
|
695
694
|
var Stat = class {
|
|
696
|
-
constructor(
|
|
695
|
+
constructor(name2, type) {
|
|
697
696
|
this.name = void 0;
|
|
698
697
|
this.type = void 0;
|
|
699
698
|
this.sampleSize = 1;
|
|
@@ -708,7 +707,7 @@ var __exports__ = (() => {
|
|
|
708
707
|
this._samples = 0;
|
|
709
708
|
this._startTime = 0;
|
|
710
709
|
this._timerPending = false;
|
|
711
|
-
this.name =
|
|
710
|
+
this.name = name2;
|
|
712
711
|
this.type = type;
|
|
713
712
|
this.reset();
|
|
714
713
|
}
|
|
@@ -813,10 +812,10 @@ var __exports__ = (() => {
|
|
|
813
812
|
this._initializeStats(options.stats);
|
|
814
813
|
Object.seal(this);
|
|
815
814
|
}
|
|
816
|
-
get(
|
|
815
|
+
get(name2) {
|
|
817
816
|
let type = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "count";
|
|
818
817
|
return this._getOrCreate({
|
|
819
|
-
name,
|
|
818
|
+
name: name2,
|
|
820
819
|
type
|
|
821
820
|
});
|
|
822
821
|
}
|
|
@@ -852,17 +851,17 @@ var __exports__ = (() => {
|
|
|
852
851
|
}
|
|
853
852
|
_getOrCreate(stat) {
|
|
854
853
|
const {
|
|
855
|
-
name,
|
|
854
|
+
name: name2,
|
|
856
855
|
type
|
|
857
856
|
} = stat;
|
|
858
|
-
let result = this.stats[
|
|
857
|
+
let result = this.stats[name2];
|
|
859
858
|
if (!result) {
|
|
860
859
|
if (stat instanceof Stat) {
|
|
861
860
|
result = stat;
|
|
862
861
|
} else {
|
|
863
|
-
result = new Stat(
|
|
862
|
+
result = new Stat(name2, type);
|
|
864
863
|
}
|
|
865
|
-
this.stats[
|
|
864
|
+
this.stats[name2] = result;
|
|
866
865
|
}
|
|
867
866
|
return result;
|
|
868
867
|
}
|
|
@@ -871,16 +870,16 @@ var __exports__ = (() => {
|
|
|
871
870
|
// ../core/src/lib/utils/stats-manager.ts
|
|
872
871
|
var StatsManager = class {
|
|
873
872
|
stats = /* @__PURE__ */ new Map();
|
|
874
|
-
getStats(
|
|
875
|
-
return this.get(
|
|
873
|
+
getStats(name2) {
|
|
874
|
+
return this.get(name2);
|
|
876
875
|
}
|
|
877
|
-
get(
|
|
878
|
-
if (!this.stats.has(
|
|
879
|
-
this.stats.set(
|
|
880
|
-
id:
|
|
876
|
+
get(name2) {
|
|
877
|
+
if (!this.stats.has(name2)) {
|
|
878
|
+
this.stats.set(name2, new Stats({
|
|
879
|
+
id: name2
|
|
881
880
|
}));
|
|
882
881
|
}
|
|
883
|
-
return this.stats.get(
|
|
882
|
+
return this.stats.get(name2);
|
|
884
883
|
}
|
|
885
884
|
};
|
|
886
885
|
var lumaStats = new StatsManager();
|
|
@@ -929,11 +928,6 @@ var __exports__ = (() => {
|
|
|
929
928
|
}
|
|
930
929
|
|
|
931
930
|
// ../core/src/adapter/resources/resource.ts
|
|
932
|
-
var DEFAULT_RESOURCE_PROPS = {
|
|
933
|
-
id: "undefined",
|
|
934
|
-
handle: void 0,
|
|
935
|
-
userData: void 0
|
|
936
|
-
};
|
|
937
931
|
var Resource = class {
|
|
938
932
|
/** props.id, for debugging. */
|
|
939
933
|
userData = {};
|
|
@@ -1018,34 +1012,38 @@ var __exports__ = (() => {
|
|
|
1018
1012
|
/** Called by .destroy() to track object destruction. Subclass must call if overriding destroy() */
|
|
1019
1013
|
removeStats() {
|
|
1020
1014
|
const stats = this._device.statsManager.getStats("Resource Counts");
|
|
1021
|
-
const
|
|
1022
|
-
stats.get(`${
|
|
1015
|
+
const name2 = this[Symbol.toStringTag];
|
|
1016
|
+
stats.get(`${name2}s Active`).decrementCount();
|
|
1023
1017
|
}
|
|
1024
1018
|
/** Called by subclass to track memory allocations */
|
|
1025
|
-
trackAllocatedMemory(bytes,
|
|
1019
|
+
trackAllocatedMemory(bytes, name2 = this[Symbol.toStringTag]) {
|
|
1026
1020
|
const stats = this._device.statsManager.getStats("Resource Counts");
|
|
1027
1021
|
stats.get("GPU Memory").addCount(bytes);
|
|
1028
|
-
stats.get(`${
|
|
1022
|
+
stats.get(`${name2} Memory`).addCount(bytes);
|
|
1029
1023
|
this.allocatedBytes = bytes;
|
|
1030
1024
|
}
|
|
1031
1025
|
/** Called by subclass to track memory deallocations */
|
|
1032
|
-
trackDeallocatedMemory(
|
|
1026
|
+
trackDeallocatedMemory(name2 = this[Symbol.toStringTag]) {
|
|
1033
1027
|
const stats = this._device.statsManager.getStats("Resource Counts");
|
|
1034
1028
|
stats.get("GPU Memory").subtractCount(this.allocatedBytes);
|
|
1035
|
-
stats.get(`${
|
|
1029
|
+
stats.get(`${name2} Memory`).subtractCount(this.allocatedBytes);
|
|
1036
1030
|
this.allocatedBytes = 0;
|
|
1037
1031
|
}
|
|
1038
1032
|
/** Called by resource constructor to track object creation */
|
|
1039
1033
|
addStats() {
|
|
1040
1034
|
const stats = this._device.statsManager.getStats("Resource Counts");
|
|
1041
|
-
const
|
|
1035
|
+
const name2 = this[Symbol.toStringTag];
|
|
1042
1036
|
stats.get("Resources Created").incrementCount();
|
|
1043
|
-
stats.get(`${
|
|
1044
|
-
stats.get(`${
|
|
1037
|
+
stats.get(`${name2}s Created`).incrementCount();
|
|
1038
|
+
stats.get(`${name2}s Active`).incrementCount();
|
|
1045
1039
|
}
|
|
1046
1040
|
};
|
|
1047
1041
|
/** Default properties for resource */
|
|
1048
|
-
__publicField(Resource, "defaultProps",
|
|
1042
|
+
__publicField(Resource, "defaultProps", {
|
|
1043
|
+
id: "undefined",
|
|
1044
|
+
handle: void 0,
|
|
1045
|
+
userData: void 0
|
|
1046
|
+
});
|
|
1049
1047
|
function selectivelyMerge(props, defaultProps) {
|
|
1050
1048
|
const mergedProps = {
|
|
1051
1049
|
...defaultProps
|
|
@@ -1059,16 +1057,6 @@ var __exports__ = (() => {
|
|
|
1059
1057
|
}
|
|
1060
1058
|
|
|
1061
1059
|
// ../core/src/adapter/resources/buffer.ts
|
|
1062
|
-
var DEFAULT_BUFFER_PROPS = {
|
|
1063
|
-
...DEFAULT_RESOURCE_PROPS,
|
|
1064
|
-
usage: 0,
|
|
1065
|
-
// Buffer.COPY_DST | Buffer.COPY_SRC
|
|
1066
|
-
byteLength: 0,
|
|
1067
|
-
byteOffset: 0,
|
|
1068
|
-
data: null,
|
|
1069
|
-
indexType: "uint16",
|
|
1070
|
-
mappedAtCreation: false
|
|
1071
|
-
};
|
|
1072
1060
|
var _Buffer = class extends Resource {
|
|
1073
1061
|
get [Symbol.toStringTag]() {
|
|
1074
1062
|
return "Buffer";
|
|
@@ -1085,7 +1073,7 @@ var __exports__ = (() => {
|
|
|
1085
1073
|
deducedProps.indexType = "uint16";
|
|
1086
1074
|
}
|
|
1087
1075
|
}
|
|
1088
|
-
super(device, deducedProps,
|
|
1076
|
+
super(device, deducedProps, _Buffer.defaultProps);
|
|
1089
1077
|
}
|
|
1090
1078
|
write(data, byteOffset) {
|
|
1091
1079
|
throw new Error("not implemented");
|
|
@@ -1143,6 +1131,16 @@ var __exports__ = (() => {
|
|
|
1143
1131
|
// abstract unmap(): void;
|
|
1144
1132
|
};
|
|
1145
1133
|
var Buffer2 = _Buffer;
|
|
1134
|
+
__publicField(Buffer2, "defaultProps", {
|
|
1135
|
+
...Resource.defaultProps,
|
|
1136
|
+
usage: 0,
|
|
1137
|
+
// Buffer.COPY_DST | Buffer.COPY_SRC
|
|
1138
|
+
byteLength: 0,
|
|
1139
|
+
byteOffset: 0,
|
|
1140
|
+
data: null,
|
|
1141
|
+
indexType: "uint16",
|
|
1142
|
+
mappedAtCreation: false
|
|
1143
|
+
});
|
|
1146
1144
|
// Usage Flags
|
|
1147
1145
|
__publicField(Buffer2, "MAP_READ", 1);
|
|
1148
1146
|
__publicField(Buffer2, "MAP_WRITE", 2);
|
|
@@ -1192,8 +1190,14 @@ var __exports__ = (() => {
|
|
|
1192
1190
|
};
|
|
1193
1191
|
this.id = this.props.id || uid(this[Symbol.toStringTag].toLowerCase());
|
|
1194
1192
|
}
|
|
1193
|
+
/** id of this device, primarily for debugging */
|
|
1194
|
+
/** stats */
|
|
1195
1195
|
statsManager = lumaStats;
|
|
1196
|
+
/** A copy of the device props */
|
|
1197
|
+
/** Available for the application to store data on the device */
|
|
1196
1198
|
userData = {};
|
|
1199
|
+
/** Used by other luma.gl modules to store data on the device */
|
|
1200
|
+
_lumaData = {};
|
|
1197
1201
|
// Capabilities
|
|
1198
1202
|
/** Information about the device (vendor, versions etc) */
|
|
1199
1203
|
/** Optional capability discovery */
|
|
@@ -1540,25 +1544,7 @@ var __exports__ = (() => {
|
|
|
1540
1544
|
}
|
|
1541
1545
|
|
|
1542
1546
|
// ../core/src/adapter/resources/texture.ts
|
|
1543
|
-
var
|
|
1544
|
-
...DEFAULT_RESOURCE_PROPS,
|
|
1545
|
-
data: null,
|
|
1546
|
-
dimension: "2d",
|
|
1547
|
-
format: "rgba8unorm",
|
|
1548
|
-
width: void 0,
|
|
1549
|
-
height: void 0,
|
|
1550
|
-
depth: 1,
|
|
1551
|
-
mipmaps: true,
|
|
1552
|
-
sampler: {},
|
|
1553
|
-
// type: undefined,
|
|
1554
|
-
compressed: false,
|
|
1555
|
-
// mipLevels: 1,
|
|
1556
|
-
usage: 0,
|
|
1557
|
-
mipLevels: void 0,
|
|
1558
|
-
samples: void 0,
|
|
1559
|
-
type: void 0
|
|
1560
|
-
};
|
|
1561
|
-
var Texture = class extends Resource {
|
|
1547
|
+
var _Texture = class extends Resource {
|
|
1562
1548
|
get [Symbol.toStringTag]() {
|
|
1563
1549
|
return "Texture";
|
|
1564
1550
|
}
|
|
@@ -1568,7 +1554,7 @@ var __exports__ = (() => {
|
|
|
1568
1554
|
/** height in pixels of this texture */
|
|
1569
1555
|
/** depth of this texture */
|
|
1570
1556
|
/** Default sampler for this texture */
|
|
1571
|
-
constructor(device, props, defaultProps =
|
|
1557
|
+
constructor(device, props, defaultProps = _Texture.defaultProps) {
|
|
1572
1558
|
super(device, props, defaultProps);
|
|
1573
1559
|
this.dimension = this.props.dimension;
|
|
1574
1560
|
this.format = this.props.format;
|
|
@@ -1577,6 +1563,26 @@ var __exports__ = (() => {
|
|
|
1577
1563
|
this.depth = this.props.depth;
|
|
1578
1564
|
}
|
|
1579
1565
|
};
|
|
1566
|
+
var Texture = _Texture;
|
|
1567
|
+
__publicField(Texture, "defaultProps", {
|
|
1568
|
+
...Resource.defaultProps,
|
|
1569
|
+
data: null,
|
|
1570
|
+
dimension: "2d",
|
|
1571
|
+
format: "rgba8unorm",
|
|
1572
|
+
width: void 0,
|
|
1573
|
+
height: void 0,
|
|
1574
|
+
depth: 1,
|
|
1575
|
+
mipmaps: true,
|
|
1576
|
+
sampler: {},
|
|
1577
|
+
// type: undefined,
|
|
1578
|
+
compressed: false,
|
|
1579
|
+
// mipLevels: 1,
|
|
1580
|
+
usage: 0,
|
|
1581
|
+
// usage: GPUTextureUsage.COPY_DST
|
|
1582
|
+
mipLevels: void 0,
|
|
1583
|
+
samples: void 0,
|
|
1584
|
+
type: void 0
|
|
1585
|
+
});
|
|
1580
1586
|
__publicField(Texture, "COPY_SRC", 1);
|
|
1581
1587
|
__publicField(Texture, "COPY_DST", 2);
|
|
1582
1588
|
__publicField(Texture, "TEXTURE_BINDING", 4);
|
|
@@ -1584,28 +1590,38 @@ var __exports__ = (() => {
|
|
|
1584
1590
|
__publicField(Texture, "RENDER_ATTACHMENT", 16);
|
|
1585
1591
|
|
|
1586
1592
|
// ../core/src/adapter/resources/shader.ts
|
|
1587
|
-
var
|
|
1588
|
-
...DEFAULT_RESOURCE_PROPS,
|
|
1589
|
-
stage: "vertex",
|
|
1590
|
-
source: "",
|
|
1591
|
-
sourceMap: null,
|
|
1592
|
-
language: "glsl",
|
|
1593
|
-
shaderType: 0
|
|
1594
|
-
};
|
|
1595
|
-
var Shader = class extends Resource {
|
|
1593
|
+
var _Shader = class extends Resource {
|
|
1596
1594
|
get [Symbol.toStringTag]() {
|
|
1597
1595
|
return "Shader";
|
|
1598
1596
|
}
|
|
1599
1597
|
constructor(device, props) {
|
|
1600
|
-
super(device, props,
|
|
1598
|
+
super(device, props, _Shader.defaultProps);
|
|
1601
1599
|
this.stage = this.props.stage;
|
|
1602
1600
|
this.source = this.props.source;
|
|
1603
1601
|
}
|
|
1604
1602
|
};
|
|
1603
|
+
var Shader = _Shader;
|
|
1604
|
+
__publicField(Shader, "defaultProps", {
|
|
1605
|
+
...Resource.defaultProps,
|
|
1606
|
+
stage: "vertex",
|
|
1607
|
+
source: "",
|
|
1608
|
+
sourceMap: null,
|
|
1609
|
+
language: "glsl",
|
|
1610
|
+
shaderType: 0
|
|
1611
|
+
});
|
|
1605
1612
|
|
|
1606
1613
|
// ../core/src/adapter/resources/sampler.ts
|
|
1607
|
-
var
|
|
1608
|
-
|
|
1614
|
+
var _Sampler = class extends Resource {
|
|
1615
|
+
get [Symbol.toStringTag]() {
|
|
1616
|
+
return "Sampler";
|
|
1617
|
+
}
|
|
1618
|
+
constructor(device, props) {
|
|
1619
|
+
super(device, props, _Sampler.defaultProps);
|
|
1620
|
+
}
|
|
1621
|
+
};
|
|
1622
|
+
var Sampler = _Sampler;
|
|
1623
|
+
__publicField(Sampler, "defaultProps", {
|
|
1624
|
+
...Resource.defaultProps,
|
|
1609
1625
|
type: "color-sampler",
|
|
1610
1626
|
addressModeU: "clamp-to-edge",
|
|
1611
1627
|
addressModeV: "clamp-to-edge",
|
|
@@ -1618,27 +1634,10 @@ var __exports__ = (() => {
|
|
|
1618
1634
|
// Per WebGPU spec
|
|
1619
1635
|
compare: "less-equal",
|
|
1620
1636
|
maxAnisotropy: 1
|
|
1621
|
-
};
|
|
1622
|
-
var Sampler = class extends Resource {
|
|
1623
|
-
get [Symbol.toStringTag]() {
|
|
1624
|
-
return "Sampler";
|
|
1625
|
-
}
|
|
1626
|
-
constructor(device, props) {
|
|
1627
|
-
super(device, props, DEFAULT_SAMPLER_PROPS);
|
|
1628
|
-
}
|
|
1629
|
-
};
|
|
1637
|
+
});
|
|
1630
1638
|
|
|
1631
1639
|
// ../core/src/adapter/resources/framebuffer.ts
|
|
1632
|
-
var
|
|
1633
|
-
...DEFAULT_RESOURCE_PROPS,
|
|
1634
|
-
width: 1,
|
|
1635
|
-
height: 1,
|
|
1636
|
-
colorAttachments: [],
|
|
1637
|
-
// ['rgba8unorm-unsized'],
|
|
1638
|
-
depthStencilAttachment: null
|
|
1639
|
-
// 'depth24plus-stencil8'
|
|
1640
|
-
};
|
|
1641
|
-
var Framebuffer = class extends Resource {
|
|
1640
|
+
var _Framebuffer = class extends Resource {
|
|
1642
1641
|
get [Symbol.toStringTag]() {
|
|
1643
1642
|
return "Framebuffer";
|
|
1644
1643
|
}
|
|
@@ -1649,7 +1648,7 @@ var __exports__ = (() => {
|
|
|
1649
1648
|
/** Depth-stencil attachment, if provided */
|
|
1650
1649
|
depthStencilAttachment = null;
|
|
1651
1650
|
constructor(device, props = {}) {
|
|
1652
|
-
super(device, props,
|
|
1651
|
+
super(device, props, _Framebuffer.defaultProps);
|
|
1653
1652
|
this.width = this.props.width;
|
|
1654
1653
|
this.height = this.props.height;
|
|
1655
1654
|
}
|
|
@@ -1815,10 +1814,36 @@ var __exports__ = (() => {
|
|
|
1815
1814
|
}
|
|
1816
1815
|
*/
|
|
1817
1816
|
};
|
|
1817
|
+
var Framebuffer = _Framebuffer;
|
|
1818
|
+
__publicField(Framebuffer, "defaultProps", {
|
|
1819
|
+
...Resource.defaultProps,
|
|
1820
|
+
width: 1,
|
|
1821
|
+
height: 1,
|
|
1822
|
+
colorAttachments: [],
|
|
1823
|
+
// ['rgba8unorm-unsized'],
|
|
1824
|
+
depthStencilAttachment: null
|
|
1825
|
+
// 'depth24plus-stencil8'
|
|
1826
|
+
});
|
|
1818
1827
|
|
|
1819
1828
|
// ../core/src/adapter/resources/render-pipeline.ts
|
|
1820
|
-
var
|
|
1821
|
-
|
|
1829
|
+
var _RenderPipeline = class extends Resource {
|
|
1830
|
+
get [Symbol.toStringTag]() {
|
|
1831
|
+
return "RenderPipeline";
|
|
1832
|
+
}
|
|
1833
|
+
hash = "";
|
|
1834
|
+
constructor(device, props) {
|
|
1835
|
+
super(device, props, _RenderPipeline.defaultProps);
|
|
1836
|
+
}
|
|
1837
|
+
/** Set attributes (stored on pipeline and set before each call) */
|
|
1838
|
+
/** Set attributes (stored on pipeline and set before each call) */
|
|
1839
|
+
/** Set constant attributes (WebGL only) */
|
|
1840
|
+
/** Set bindings (stored on pipeline and set before each call) */
|
|
1841
|
+
/** Uniforms (only supported on WebGL devices. Reset before each call to enable pipeline sharing) */
|
|
1842
|
+
/** Draw call */
|
|
1843
|
+
};
|
|
1844
|
+
var RenderPipeline = _RenderPipeline;
|
|
1845
|
+
__publicField(RenderPipeline, "defaultProps", {
|
|
1846
|
+
...Resource.defaultProps,
|
|
1822
1847
|
vs: null,
|
|
1823
1848
|
vsEntryPoint: "",
|
|
1824
1849
|
// main
|
|
@@ -1827,36 +1852,17 @@ var __exports__ = (() => {
|
|
|
1827
1852
|
fsEntryPoint: "",
|
|
1828
1853
|
// main
|
|
1829
1854
|
fsConstants: {},
|
|
1830
|
-
|
|
1831
|
-
|
|
1855
|
+
shaderLayout: null,
|
|
1856
|
+
bufferLayout: [],
|
|
1832
1857
|
topology: "triangle-list",
|
|
1833
|
-
// targets:
|
|
1834
1858
|
parameters: {},
|
|
1835
|
-
bufferMap: [],
|
|
1836
1859
|
vertexCount: 0,
|
|
1837
1860
|
instanceCount: 0,
|
|
1838
1861
|
indices: null,
|
|
1839
1862
|
attributes: {},
|
|
1840
1863
|
bindings: {},
|
|
1841
1864
|
uniforms: {}
|
|
1842
|
-
};
|
|
1843
|
-
var RenderPipeline = class extends Resource {
|
|
1844
|
-
get [Symbol.toStringTag]() {
|
|
1845
|
-
return "RenderPipeline";
|
|
1846
|
-
}
|
|
1847
|
-
hash = "";
|
|
1848
|
-
constructor(device, props) {
|
|
1849
|
-
super(device, props, DEFAULT_RENDER_PIPELINE_PROPS);
|
|
1850
|
-
}
|
|
1851
|
-
};
|
|
1852
|
-
/** Set attributes (stored on pipeline and set before each call) */
|
|
1853
|
-
/** Set attributes (stored on pipeline and set before each call) */
|
|
1854
|
-
/** Set constant attributes (WebGL only) */
|
|
1855
|
-
/** Set bindings (stored on pipeline and set before each call) */
|
|
1856
|
-
/** Uniforms (only supported on WebGL devices. Reset before each call to enable pipeline sharing) */
|
|
1857
|
-
/** Draw call */
|
|
1858
|
-
/** Private "export" for Model class */
|
|
1859
|
-
__publicField(RenderPipeline, "_DEFAULT_PROPS", DEFAULT_RENDER_PIPELINE_PROPS);
|
|
1865
|
+
});
|
|
1860
1866
|
|
|
1861
1867
|
// ../core/src/adapter/resources/render-pass.ts
|
|
1862
1868
|
var _RenderPass = class extends Resource {
|
|
@@ -1916,15 +1922,12 @@ var __exports__ = (() => {
|
|
|
1916
1922
|
});
|
|
1917
1923
|
|
|
1918
1924
|
// ../core/src/adapter/resources/command-encoder.ts
|
|
1919
|
-
var
|
|
1920
|
-
...DEFAULT_RESOURCE_PROPS
|
|
1921
|
-
};
|
|
1922
|
-
var CommandEncoder = class extends Resource {
|
|
1925
|
+
var _CommandEncoder = class extends Resource {
|
|
1923
1926
|
get [Symbol.toStringTag]() {
|
|
1924
1927
|
return "CommandEncoder";
|
|
1925
1928
|
}
|
|
1926
|
-
constructor(props) {
|
|
1927
|
-
super(props,
|
|
1929
|
+
constructor(device, props) {
|
|
1930
|
+
super(device, props, _CommandEncoder.defaultProps);
|
|
1928
1931
|
}
|
|
1929
1932
|
// TODO - return the CommandBuffer?
|
|
1930
1933
|
// beginRenderPass(GPURenderPassDescriptor descriptor): GPURenderPassEncoder;
|
|
@@ -1945,19 +1948,25 @@ var __exports__ = (() => {
|
|
|
1945
1948
|
// destinationOffset?: number;
|
|
1946
1949
|
// }): void;
|
|
1947
1950
|
};
|
|
1951
|
+
var CommandEncoder = _CommandEncoder;
|
|
1952
|
+
__publicField(CommandEncoder, "defaultProps", {
|
|
1953
|
+
...Resource.defaultProps,
|
|
1954
|
+
measureExecutionTime: void 0
|
|
1955
|
+
});
|
|
1948
1956
|
|
|
1949
1957
|
// ../core/src/adapter/resources/command-buffer.ts
|
|
1950
|
-
var
|
|
1951
|
-
...DEFAULT_RESOURCE_PROPS
|
|
1952
|
-
};
|
|
1953
|
-
var CommandBuffer = class extends Resource {
|
|
1958
|
+
var _CommandBuffer = class extends Resource {
|
|
1954
1959
|
get [Symbol.toStringTag]() {
|
|
1955
1960
|
return "CommandBuffer";
|
|
1956
1961
|
}
|
|
1957
1962
|
constructor(props) {
|
|
1958
|
-
super(props,
|
|
1963
|
+
super(props, _CommandBuffer.defaultProps);
|
|
1959
1964
|
}
|
|
1960
1965
|
};
|
|
1966
|
+
var CommandBuffer = _CommandBuffer;
|
|
1967
|
+
__publicField(CommandBuffer, "defaultProps", {
|
|
1968
|
+
...Resource.defaultProps
|
|
1969
|
+
});
|
|
1961
1970
|
|
|
1962
1971
|
// ../core/src/lib/utils/assert.ts
|
|
1963
1972
|
function assert2(condition, message2) {
|
|
@@ -1966,7 +1975,7 @@ var __exports__ = (() => {
|
|
|
1966
1975
|
}
|
|
1967
1976
|
}
|
|
1968
1977
|
|
|
1969
|
-
// ../core/src/adapter/utils/decode-data-type.ts
|
|
1978
|
+
// ../core/src/adapter/type-utils/decode-data-type.ts
|
|
1970
1979
|
function decodeVertexType(type) {
|
|
1971
1980
|
const dataType = TYPE_MAP[type];
|
|
1972
1981
|
const bytes = getDataTypeBytes(dataType);
|
|
@@ -2010,7 +2019,7 @@ var __exports__ = (() => {
|
|
|
2010
2019
|
sint32: 4
|
|
2011
2020
|
};
|
|
2012
2021
|
|
|
2013
|
-
// ../core/src/adapter/utils/decode-vertex-format.ts
|
|
2022
|
+
// ../core/src/adapter/type-utils/decode-vertex-format.ts
|
|
2014
2023
|
function decodeVertexFormat(format) {
|
|
2015
2024
|
let webglOnly;
|
|
2016
2025
|
if (format.endsWith("-webgl")) {
|
|
@@ -2035,7 +2044,7 @@ var __exports__ = (() => {
|
|
|
2035
2044
|
return result;
|
|
2036
2045
|
}
|
|
2037
2046
|
|
|
2038
|
-
// ../core/src/adapter/utils/decode-texture-format.ts
|
|
2047
|
+
// ../core/src/adapter/type-utils/decode-texture-format.ts
|
|
2039
2048
|
var REGEX = /^(rg?b?a?)([0-9]*)([a-z]*)(-srgb)?(-webgl|-unsized)?$/;
|
|
2040
2049
|
function decodeTextureFormat(format) {
|
|
2041
2050
|
const matches = REGEX.exec(format);
|
|
@@ -2141,6 +2150,68 @@ var __exports__ = (() => {
|
|
|
2141
2150
|
};
|
|
2142
2151
|
}
|
|
2143
2152
|
|
|
2153
|
+
// ../core/src/adapter/type-utils/decode-attribute-type.ts
|
|
2154
|
+
function decodeShaderAttributeType(attributeType) {
|
|
2155
|
+
const [dataType, components] = TYPE_INFO[attributeType];
|
|
2156
|
+
const integer = dataType === "i32" || dataType === "u32";
|
|
2157
|
+
const signed = dataType !== "u32";
|
|
2158
|
+
const byteLength = TYPE_SIZES2[dataType] * components;
|
|
2159
|
+
const defaultVertexFormat = getCompatibleVertexFormat(dataType, components);
|
|
2160
|
+
return {
|
|
2161
|
+
dataType,
|
|
2162
|
+
components,
|
|
2163
|
+
defaultVertexFormat,
|
|
2164
|
+
byteLength,
|
|
2165
|
+
integer,
|
|
2166
|
+
signed
|
|
2167
|
+
};
|
|
2168
|
+
}
|
|
2169
|
+
function getCompatibleVertexFormat(dataType, components) {
|
|
2170
|
+
let vertexType;
|
|
2171
|
+
switch (dataType) {
|
|
2172
|
+
case "f32":
|
|
2173
|
+
vertexType = "float32";
|
|
2174
|
+
break;
|
|
2175
|
+
case "i32":
|
|
2176
|
+
vertexType = "sint32";
|
|
2177
|
+
break;
|
|
2178
|
+
case "u32":
|
|
2179
|
+
vertexType = "uint32";
|
|
2180
|
+
break;
|
|
2181
|
+
case "f16":
|
|
2182
|
+
return components <= 2 ? "float16x2" : "float16x4";
|
|
2183
|
+
}
|
|
2184
|
+
if (components === 1) {
|
|
2185
|
+
return vertexType;
|
|
2186
|
+
}
|
|
2187
|
+
return `${vertexType}x${components}`;
|
|
2188
|
+
}
|
|
2189
|
+
var TYPE_INFO = {
|
|
2190
|
+
f32: ["f32", 1],
|
|
2191
|
+
"vec2<f32>": ["f32", 2],
|
|
2192
|
+
"vec3<f32>": ["f32", 3],
|
|
2193
|
+
"vec4<f32>": ["f32", 4],
|
|
2194
|
+
f16: ["f16", 1],
|
|
2195
|
+
"vec2<f16>": ["f16", 2],
|
|
2196
|
+
"vec3<f16>": ["f16", 3],
|
|
2197
|
+
"vec4<f16>": ["f16", 4],
|
|
2198
|
+
i32: ["i32", 1],
|
|
2199
|
+
"vec2<i32>": ["i32", 2],
|
|
2200
|
+
"vec3<i32>": ["i32", 3],
|
|
2201
|
+
"vec4<i32>": ["i32", 4],
|
|
2202
|
+
u32: ["u32", 1],
|
|
2203
|
+
"vec2<u32>": ["u32", 2],
|
|
2204
|
+
"vec3<u32>": ["u32", 3],
|
|
2205
|
+
"vec4<u32>": ["u32", 4]
|
|
2206
|
+
};
|
|
2207
|
+
var TYPE_SIZES2 = {
|
|
2208
|
+
f32: 4,
|
|
2209
|
+
f16: 2,
|
|
2210
|
+
i32: 4,
|
|
2211
|
+
u32: 4
|
|
2212
|
+
// 'bool-webgl': 4,
|
|
2213
|
+
};
|
|
2214
|
+
|
|
2144
2215
|
// ../core/src/lib/compiler-log/format-compiler-log.ts
|
|
2145
2216
|
function formatCompilerLog(shaderLog, source, options) {
|
|
2146
2217
|
const lines = source.split(/\r?\n/);
|
|
@@ -2181,6 +2252,102 @@ var __exports__ = (() => {
|
|
|
2181
2252
|
return result + string;
|
|
2182
2253
|
}
|
|
2183
2254
|
|
|
2255
|
+
// ../core/src/adapter/attribute-utils/get-attribute-from-layouts.ts
|
|
2256
|
+
function getAttributeInfosFromLayouts(shaderLayout, bufferLayout) {
|
|
2257
|
+
const attributeInfos = {};
|
|
2258
|
+
for (const attribute of shaderLayout.attributes) {
|
|
2259
|
+
attributeInfos[attribute.name] = getAttributeInfoFromLayouts(shaderLayout, bufferLayout, attribute.name);
|
|
2260
|
+
}
|
|
2261
|
+
return attributeInfos;
|
|
2262
|
+
}
|
|
2263
|
+
function getAttributeInfoFromLayouts(shaderLayout, bufferLayout, name2) {
|
|
2264
|
+
const shaderDeclaration = getAttributeFromShaderLayout(shaderLayout, name2);
|
|
2265
|
+
const bufferMapping = getAttributeFromBufferLayout(bufferLayout, name2);
|
|
2266
|
+
if (!shaderDeclaration) {
|
|
2267
|
+
return null;
|
|
2268
|
+
}
|
|
2269
|
+
const attributeTypeInfo = decodeShaderAttributeType(shaderDeclaration.type);
|
|
2270
|
+
const vertexFormat = bufferMapping?.vertexFormat || attributeTypeInfo.defaultVertexFormat;
|
|
2271
|
+
const vertexFormatInfo = decodeVertexFormat(vertexFormat);
|
|
2272
|
+
return {
|
|
2273
|
+
name: name2,
|
|
2274
|
+
bufferName: bufferMapping?.name || name2,
|
|
2275
|
+
location: shaderDeclaration.location,
|
|
2276
|
+
shaderType: shaderDeclaration.type,
|
|
2277
|
+
shaderDataType: attributeTypeInfo.dataType,
|
|
2278
|
+
shaderComponents: attributeTypeInfo.components,
|
|
2279
|
+
vertexFormat,
|
|
2280
|
+
bufferDataType: vertexFormatInfo.type,
|
|
2281
|
+
bufferComponents: vertexFormatInfo.components,
|
|
2282
|
+
// normalized is a property of the buffer's vertex format
|
|
2283
|
+
normalized: vertexFormatInfo.normalized,
|
|
2284
|
+
// integer is a property of the shader declaration
|
|
2285
|
+
integer: attributeTypeInfo.integer,
|
|
2286
|
+
stepMode: bufferMapping?.stepMode || shaderDeclaration.stepMode,
|
|
2287
|
+
byteOffset: bufferMapping?.byteOffset || 0,
|
|
2288
|
+
byteStride: bufferMapping?.byteStride || 0
|
|
2289
|
+
};
|
|
2290
|
+
}
|
|
2291
|
+
function getAttributeFromShaderLayout(shaderLayout, name2) {
|
|
2292
|
+
const attribute = shaderLayout.attributes.find((attr) => attr.name === name2);
|
|
2293
|
+
if (!attribute) {
|
|
2294
|
+
log.warn(`shader layout attribute "${name2}" not present in shader`);
|
|
2295
|
+
}
|
|
2296
|
+
return attribute || null;
|
|
2297
|
+
}
|
|
2298
|
+
function getAttributeFromBufferLayout(bufferLayout, name2) {
|
|
2299
|
+
for (const bufferMapping of bufferLayout) {
|
|
2300
|
+
if (bufferMapping.name === name2) {
|
|
2301
|
+
return {
|
|
2302
|
+
name: bufferMapping.name,
|
|
2303
|
+
bufferName: name2,
|
|
2304
|
+
vertexFormat: bufferMapping.format,
|
|
2305
|
+
byteOffset: bufferMapping.byteOffset || 0,
|
|
2306
|
+
byteStride: bufferMapping.byteStride || 0
|
|
2307
|
+
};
|
|
2308
|
+
}
|
|
2309
|
+
let nextByteOffset = bufferMapping.byteOffset || 0;
|
|
2310
|
+
let byteStride = 0;
|
|
2311
|
+
for (const interleavedMapping of bufferMapping.attributes || []) {
|
|
2312
|
+
const info = decodeVertexFormat(interleavedMapping.format);
|
|
2313
|
+
byteStride += info.byteLength;
|
|
2314
|
+
}
|
|
2315
|
+
for (const interleavedMapping of bufferMapping.attributes || []) {
|
|
2316
|
+
const byteOffset = nextByteOffset;
|
|
2317
|
+
nextByteOffset += interleavedMapping?.byteStrideOffset || decodeVertexFormat(interleavedMapping.format).byteLength;
|
|
2318
|
+
if (interleavedMapping.name === name2) {
|
|
2319
|
+
return {
|
|
2320
|
+
name: bufferMapping.name,
|
|
2321
|
+
bufferName: name2,
|
|
2322
|
+
vertexFormat: interleavedMapping.format,
|
|
2323
|
+
byteOffset,
|
|
2324
|
+
byteStride: bufferMapping.byteStride || byteStride
|
|
2325
|
+
};
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
log.warn(`layout for attribute "${name2}" not present in buffer layout`);
|
|
2330
|
+
return null;
|
|
2331
|
+
}
|
|
2332
|
+
function mergeShaderLayout(baseLayout, overrideLayout) {
|
|
2333
|
+
const mergedLayout = {
|
|
2334
|
+
...baseLayout,
|
|
2335
|
+
attributes: baseLayout.attributes.map((attribute) => ({
|
|
2336
|
+
...attribute
|
|
2337
|
+
}))
|
|
2338
|
+
};
|
|
2339
|
+
for (const attribute of overrideLayout?.attributes || []) {
|
|
2340
|
+
const baseAttribute = mergedLayout.attributes.find((attr) => attr.name === attribute.name);
|
|
2341
|
+
if (!baseAttribute) {
|
|
2342
|
+
log.warn(`shader layout attribute ${attribute.name} not present in shader`);
|
|
2343
|
+
} else {
|
|
2344
|
+
baseAttribute.type = attribute.type || baseAttribute.type;
|
|
2345
|
+
baseAttribute.stepMode = attribute.stepMode || baseAttribute.stepMode;
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
return mergedLayout;
|
|
2349
|
+
}
|
|
2350
|
+
|
|
2184
2351
|
// ../core/src/lib/utils/cast.ts
|
|
2185
2352
|
function cast(value) {
|
|
2186
2353
|
return value;
|
|
@@ -2554,12 +2721,12 @@ var __exports__ = (() => {
|
|
|
2554
2721
|
return list;
|
|
2555
2722
|
};
|
|
2556
2723
|
const original_getExtension = gl2.getExtension;
|
|
2557
|
-
gl2.getExtension = function getExtension(
|
|
2558
|
-
const ext = original_getExtension.call(this,
|
|
2724
|
+
gl2.getExtension = function getExtension(name2) {
|
|
2725
|
+
const ext = original_getExtension.call(this, name2);
|
|
2559
2726
|
if (ext) {
|
|
2560
2727
|
return ext;
|
|
2561
2728
|
}
|
|
2562
|
-
if (
|
|
2729
|
+
if (name2 !== "OES_vertex_array_object") {
|
|
2563
2730
|
return null;
|
|
2564
2731
|
}
|
|
2565
2732
|
if (!gl2.__OESVertexArrayObject) {
|
|
@@ -4416,6 +4583,37 @@ var __exports__ = (() => {
|
|
|
4416
4583
|
return isMSIE || isTrident;
|
|
4417
4584
|
}
|
|
4418
4585
|
|
|
4586
|
+
// src/adapter/converters/vertex-formats.ts
|
|
4587
|
+
function getGLFromVertexType(dataType) {
|
|
4588
|
+
switch (dataType) {
|
|
4589
|
+
case "uint8":
|
|
4590
|
+
return GL.UNSIGNED_BYTE;
|
|
4591
|
+
case "sint8":
|
|
4592
|
+
return GL.BYTE;
|
|
4593
|
+
case "unorm8":
|
|
4594
|
+
return GL.UNSIGNED_BYTE;
|
|
4595
|
+
case "snorm8":
|
|
4596
|
+
return GL.BYTE;
|
|
4597
|
+
case "uint16":
|
|
4598
|
+
return GL.UNSIGNED_SHORT;
|
|
4599
|
+
case "sint16":
|
|
4600
|
+
return GL.SHORT;
|
|
4601
|
+
case "unorm16":
|
|
4602
|
+
return GL.UNSIGNED_SHORT;
|
|
4603
|
+
case "snorm16":
|
|
4604
|
+
return GL.SHORT;
|
|
4605
|
+
case "uint32":
|
|
4606
|
+
return GL.UNSIGNED_INT;
|
|
4607
|
+
case "sint32":
|
|
4608
|
+
return GL.INT;
|
|
4609
|
+
case "float16":
|
|
4610
|
+
return GL.HALF_FLOAT;
|
|
4611
|
+
case "float32":
|
|
4612
|
+
return GL.FLOAT;
|
|
4613
|
+
}
|
|
4614
|
+
throw new Error(String(dataType));
|
|
4615
|
+
}
|
|
4616
|
+
|
|
4419
4617
|
// src/adapter/converters/texture-formats.ts
|
|
4420
4618
|
var texture_compression_bc = "texture-compression-bc";
|
|
4421
4619
|
var texture_compression_astc = "texture-compression-astc";
|
|
@@ -5197,7 +5395,7 @@ var __exports__ = (() => {
|
|
|
5197
5395
|
[GL.LUMINANCE]: 1,
|
|
5198
5396
|
[GL.LUMINANCE_ALPHA]: 2
|
|
5199
5397
|
};
|
|
5200
|
-
var
|
|
5398
|
+
var TYPE_SIZES3 = {
|
|
5201
5399
|
[GL.FLOAT]: 4,
|
|
5202
5400
|
[GL.UNSIGNED_INT]: 4,
|
|
5203
5401
|
[GL.INT]: 4,
|
|
@@ -5281,7 +5479,8 @@ var __exports__ = (() => {
|
|
|
5281
5479
|
return {
|
|
5282
5480
|
format: webglFormat,
|
|
5283
5481
|
dataFormat: getWebGLPixelDataFormat(decoded.format, decoded.integer, decoded.normalized, webglFormat),
|
|
5284
|
-
type
|
|
5482
|
+
// depth formats don't have a type
|
|
5483
|
+
type: decoded.dataType ? getGLFromVertexType(decoded.dataType) : GL.UNSIGNED_BYTE,
|
|
5285
5484
|
// @ts-expect-error
|
|
5286
5485
|
compressed: decoded.compressed
|
|
5287
5486
|
};
|
|
@@ -5320,7 +5519,7 @@ var __exports__ = (() => {
|
|
|
5320
5519
|
const format = convertGLToTextureFormat(formatOrGL);
|
|
5321
5520
|
const params = getWebGLTextureParameters(format, isWebGL23);
|
|
5322
5521
|
const channels = DATA_FORMAT_CHANNELS[params.dataFormat] || 4;
|
|
5323
|
-
const channelSize =
|
|
5522
|
+
const channelSize = TYPE_SIZES3[params.type] || 1;
|
|
5324
5523
|
return channels * channelSize;
|
|
5325
5524
|
}
|
|
5326
5525
|
function getWebGLPixelDataFormat(dataFormat, integer, normalized, format) {
|
|
@@ -5340,28 +5539,6 @@ var __exports__ = (() => {
|
|
|
5340
5539
|
return GL.RGBA;
|
|
5341
5540
|
}
|
|
5342
5541
|
}
|
|
5343
|
-
function getWebGLDataType(dataType) {
|
|
5344
|
-
switch (dataType) {
|
|
5345
|
-
case "uint8":
|
|
5346
|
-
return GL.UNSIGNED_BYTE;
|
|
5347
|
-
case "sint8":
|
|
5348
|
-
return GL.BYTE;
|
|
5349
|
-
case "uint16":
|
|
5350
|
-
return GL.UNSIGNED_SHORT;
|
|
5351
|
-
case "sint16":
|
|
5352
|
-
return GL.SHORT;
|
|
5353
|
-
case "uint32":
|
|
5354
|
-
return GL.UNSIGNED_INT;
|
|
5355
|
-
case "sint32":
|
|
5356
|
-
return GL.INT;
|
|
5357
|
-
case "float16":
|
|
5358
|
-
return GL.HALF_FLOAT;
|
|
5359
|
-
case "float32":
|
|
5360
|
-
return GL.FLOAT;
|
|
5361
|
-
default:
|
|
5362
|
-
return GL.UNSIGNED_BYTE;
|
|
5363
|
-
}
|
|
5364
|
-
}
|
|
5365
5542
|
|
|
5366
5543
|
// src/adapter/device-helpers/device-features.ts
|
|
5367
5544
|
function getDeviceFeatures(gl2) {
|
|
@@ -6797,17 +6974,17 @@ void main(void) {}`;
|
|
|
6797
6974
|
}
|
|
6798
6975
|
|
|
6799
6976
|
// src/adapter/objects/constants-to-keys.ts
|
|
6800
|
-
function getKeyValue(gl2,
|
|
6801
|
-
if (typeof
|
|
6802
|
-
return
|
|
6977
|
+
function getKeyValue(gl2, name2) {
|
|
6978
|
+
if (typeof name2 !== "string") {
|
|
6979
|
+
return name2;
|
|
6803
6980
|
}
|
|
6804
|
-
const number = Number(
|
|
6981
|
+
const number = Number(name2);
|
|
6805
6982
|
if (!isNaN(number)) {
|
|
6806
6983
|
return number;
|
|
6807
6984
|
}
|
|
6808
|
-
|
|
6809
|
-
const value = gl2[
|
|
6810
|
-
assert2(value !== void 0, `Accessing undefined constant GL.${
|
|
6985
|
+
name2 = name2.replace(/^.*\./, "");
|
|
6986
|
+
const value = gl2[name2];
|
|
6987
|
+
assert2(value !== void 0, `Accessing undefined constant GL.${name2}`);
|
|
6811
6988
|
return value;
|
|
6812
6989
|
}
|
|
6813
6990
|
|
|
@@ -8234,7 +8411,7 @@ ${formattedLog}`)();
|
|
|
8234
8411
|
// });
|
|
8235
8412
|
};
|
|
8236
8413
|
|
|
8237
|
-
// src/adapter/helpers/
|
|
8414
|
+
// src/adapter/helpers/decode-webgl-types.ts
|
|
8238
8415
|
function isSamplerUniform(type) {
|
|
8239
8416
|
return SAMPLER_TYPES.includes(type);
|
|
8240
8417
|
}
|
|
@@ -8252,10 +8429,11 @@ ${formattedLog}`)();
|
|
|
8252
8429
|
[GL.UNSIGNED_INT_VEC2]: [GL.UNSIGNED_INT, 2, "uvec2", "vec2<u32>", "uint32x2"],
|
|
8253
8430
|
[GL.UNSIGNED_INT_VEC3]: [GL.UNSIGNED_INT, 3, "uvec3", "vec3<u32>", "uint32x3"],
|
|
8254
8431
|
[GL.UNSIGNED_INT_VEC4]: [GL.UNSIGNED_INT, 4, "uvec4", "vec4<u32>", "uint32x4"],
|
|
8255
|
-
[GL.BOOL]: [GL.FLOAT, 1, "bool", "f32", "
|
|
8256
|
-
[GL.BOOL_VEC2]: [GL.FLOAT, 2, "bvec2", "vec2<f32>"],
|
|
8257
|
-
[GL.BOOL_VEC3]: [GL.FLOAT, 3, "bvec3", "vec3<f32>"],
|
|
8258
|
-
[GL.BOOL_VEC4]: [GL.FLOAT, 4, "bvec4", "vec4<f32>"],
|
|
8432
|
+
[GL.BOOL]: [GL.FLOAT, 1, "bool", "f32", "float32"],
|
|
8433
|
+
[GL.BOOL_VEC2]: [GL.FLOAT, 2, "bvec2", "vec2<f32>", "float32x2"],
|
|
8434
|
+
[GL.BOOL_VEC3]: [GL.FLOAT, 3, "bvec3", "vec3<f32>", "float32x3"],
|
|
8435
|
+
[GL.BOOL_VEC4]: [GL.FLOAT, 4, "bvec4", "vec4<f32>", "float32x4"],
|
|
8436
|
+
// TODO - are sizes/components below correct?
|
|
8259
8437
|
[GL.FLOAT_MAT2]: [GL.FLOAT, 8, "mat2", "mat2x2<f32>"],
|
|
8260
8438
|
// 4
|
|
8261
8439
|
[GL.FLOAT_MAT2x3]: [GL.FLOAT, 8, "mat2x3", "mat2x3<f32>"],
|
|
@@ -8275,8 +8453,8 @@ ${formattedLog}`)();
|
|
|
8275
8453
|
[GL.FLOAT_MAT4]: [GL.FLOAT, 16, "mat4", "mat4x4<f32>"]
|
|
8276
8454
|
// 16
|
|
8277
8455
|
};
|
|
8278
|
-
function
|
|
8279
|
-
const typeAndSize = COMPOSITE_GL_TYPES[
|
|
8456
|
+
function decodeGLUniformType(glUniformType) {
|
|
8457
|
+
const typeAndSize = COMPOSITE_GL_TYPES[glUniformType];
|
|
8280
8458
|
if (!typeAndSize) {
|
|
8281
8459
|
throw new Error("uniform");
|
|
8282
8460
|
}
|
|
@@ -8287,68 +8465,27 @@ ${formattedLog}`)();
|
|
|
8287
8465
|
glType
|
|
8288
8466
|
};
|
|
8289
8467
|
}
|
|
8290
|
-
function
|
|
8291
|
-
const typeAndSize = COMPOSITE_GL_TYPES[
|
|
8468
|
+
function decodeGLAttributeType(glAttributeType) {
|
|
8469
|
+
const typeAndSize = COMPOSITE_GL_TYPES[glAttributeType];
|
|
8292
8470
|
if (!typeAndSize) {
|
|
8293
8471
|
throw new Error("attribute");
|
|
8294
8472
|
}
|
|
8295
|
-
const [
|
|
8473
|
+
const [, components, , shaderType, vertexFormat] = typeAndSize;
|
|
8474
|
+
const attributeType = shaderType;
|
|
8296
8475
|
return {
|
|
8297
|
-
|
|
8298
|
-
|
|
8299
|
-
|
|
8476
|
+
attributeType,
|
|
8477
|
+
vertexFormat,
|
|
8478
|
+
components
|
|
8300
8479
|
};
|
|
8301
8480
|
}
|
|
8302
8481
|
|
|
8303
|
-
// src/adapter/converters/vertex-formats.ts
|
|
8304
|
-
function getVertexFormat(type, components) {
|
|
8305
|
-
const base = getDataFormat(type);
|
|
8306
|
-
switch (components) {
|
|
8307
|
-
case 1:
|
|
8308
|
-
return base;
|
|
8309
|
-
case 2:
|
|
8310
|
-
return `${base}x2`;
|
|
8311
|
-
case 3:
|
|
8312
|
-
return `${base}x3`;
|
|
8313
|
-
case 4:
|
|
8314
|
-
return `${base}x4`;
|
|
8315
|
-
default:
|
|
8316
|
-
throw new Error(String(components));
|
|
8317
|
-
}
|
|
8318
|
-
}
|
|
8319
|
-
function getDataFormat(type) {
|
|
8320
|
-
switch (type) {
|
|
8321
|
-
case GL.INT:
|
|
8322
|
-
return "sint32";
|
|
8323
|
-
case GL.UNSIGNED_INT:
|
|
8324
|
-
return "uint32";
|
|
8325
|
-
case GL.FLOAT:
|
|
8326
|
-
return "float32";
|
|
8327
|
-
default:
|
|
8328
|
-
throw new Error(String(type));
|
|
8329
|
-
}
|
|
8330
|
-
}
|
|
8331
|
-
|
|
8332
8482
|
// src/adapter/helpers/get-shader-layout.ts
|
|
8333
8483
|
function getShaderLayout(gl2, program) {
|
|
8334
8484
|
const shaderLayout = {
|
|
8335
8485
|
attributes: [],
|
|
8336
8486
|
bindings: []
|
|
8337
8487
|
};
|
|
8338
|
-
|
|
8339
|
-
for (const attribute of attributes) {
|
|
8340
|
-
const size = Math.min(attribute.accessor.size, 4);
|
|
8341
|
-
const format = (
|
|
8342
|
-
// attribute.accessor.format ||
|
|
8343
|
-
getVertexFormat(attribute.accessor.type || GL.FLOAT, size)
|
|
8344
|
-
);
|
|
8345
|
-
shaderLayout.attributes.push({
|
|
8346
|
-
name: attribute.name,
|
|
8347
|
-
location: attribute.location,
|
|
8348
|
-
format,
|
|
8349
|
-
stepMode: attribute.accessor.divisor === 1 ? "instance" : "vertex"
|
|
8350
|
-
});
|
|
8351
|
-
}
|
|
8488
|
+
shaderLayout.attributes = readAttributeDeclarations(gl2, program);
|
|
8352
8489
|
const uniformBlocks = readUniformBlocks(gl2, program);
|
|
8353
8490
|
for (const uniformBlock of uniformBlocks) {
|
|
8354
8491
|
const uniforms2 = uniformBlock.uniforms.map((uniform) => ({
|
|
@@ -8395,58 +8532,7 @@ ${formattedLog}`)();
|
|
|
8395
8532
|
}
|
|
8396
8533
|
return shaderLayout;
|
|
8397
8534
|
}
|
|
8398
|
-
function
|
|
8399
|
-
const mergedLayout = {
|
|
8400
|
-
...baseLayout,
|
|
8401
|
-
attributes: baseLayout.attributes.map((attribute) => ({
|
|
8402
|
-
...attribute
|
|
8403
|
-
}))
|
|
8404
|
-
};
|
|
8405
|
-
for (const attribute of overrideLayout?.attributes || []) {
|
|
8406
|
-
const baseAttribute = mergedLayout.attributes.find((attr) => attr.name === attribute.name);
|
|
8407
|
-
if (!baseAttribute) {
|
|
8408
|
-
log.warn(`shader layout attribute ${attribute.name} not present in shader`);
|
|
8409
|
-
} else {
|
|
8410
|
-
baseAttribute.format = attribute.format || baseAttribute.format;
|
|
8411
|
-
baseAttribute.stepMode = attribute.stepMode || baseAttribute.stepMode;
|
|
8412
|
-
}
|
|
8413
|
-
}
|
|
8414
|
-
return mergedLayout;
|
|
8415
|
-
}
|
|
8416
|
-
function mergeBufferMap(baseLayout, bufferMap) {
|
|
8417
|
-
const mergedLayout = {
|
|
8418
|
-
...baseLayout,
|
|
8419
|
-
attributes: baseLayout.attributes.map((attribute) => ({
|
|
8420
|
-
...attribute
|
|
8421
|
-
}))
|
|
8422
|
-
};
|
|
8423
|
-
for (const bufferMapping of bufferMap) {
|
|
8424
|
-
switch (bufferMapping.type) {
|
|
8425
|
-
case "interleave":
|
|
8426
|
-
for (const attributeOverride of bufferMapping.attributes) {
|
|
8427
|
-
overrideShaderLayoutAttribute(mergedLayout, attributeOverride);
|
|
8428
|
-
}
|
|
8429
|
-
break;
|
|
8430
|
-
default:
|
|
8431
|
-
overrideShaderLayoutAttribute(mergedLayout, bufferMapping);
|
|
8432
|
-
}
|
|
8433
|
-
}
|
|
8434
|
-
return mergedLayout;
|
|
8435
|
-
}
|
|
8436
|
-
function overrideShaderLayoutAttribute(layout, attributeOverride) {
|
|
8437
|
-
const attribute = getAttributeFromLayout(layout, attributeOverride.name);
|
|
8438
|
-
if (attribute && attributeOverride.format) {
|
|
8439
|
-
attribute.format = attributeOverride.format;
|
|
8440
|
-
}
|
|
8441
|
-
}
|
|
8442
|
-
function getAttributeFromLayout(shaderLayout, name) {
|
|
8443
|
-
const attribute = shaderLayout.attributes.find((attr) => attr.name === name);
|
|
8444
|
-
if (!attribute) {
|
|
8445
|
-
log.warn(`shader layout attribute "${name}" not present in shader`);
|
|
8446
|
-
}
|
|
8447
|
-
return attribute || null;
|
|
8448
|
-
}
|
|
8449
|
-
function readAttributeBindings(gl2, program) {
|
|
8535
|
+
function readAttributeDeclarations(gl2, program) {
|
|
8450
8536
|
const attributes = [];
|
|
8451
8537
|
const count = gl2.getProgramParameter(program, gl2.ACTIVE_ATTRIBUTES);
|
|
8452
8538
|
for (let index = 0; index < count; index++) {
|
|
@@ -8455,29 +8541,23 @@ ${formattedLog}`)();
|
|
|
8455
8541
|
throw new Error("activeInfo");
|
|
8456
8542
|
}
|
|
8457
8543
|
const {
|
|
8458
|
-
name,
|
|
8459
|
-
type: compositeType
|
|
8460
|
-
size
|
|
8544
|
+
name: name2,
|
|
8545
|
+
type: compositeType
|
|
8546
|
+
/* , size*/
|
|
8461
8547
|
} = activeInfo;
|
|
8462
|
-
const location = gl2.getAttribLocation(program,
|
|
8548
|
+
const location = gl2.getAttribLocation(program, name2);
|
|
8463
8549
|
if (location >= 0) {
|
|
8464
8550
|
const {
|
|
8465
|
-
|
|
8466
|
-
|
|
8467
|
-
|
|
8468
|
-
|
|
8469
|
-
|
|
8470
|
-
size: size * components
|
|
8471
|
-
};
|
|
8472
|
-
if (/instance/i.test(name)) {
|
|
8473
|
-
accessor.divisor = 1;
|
|
8474
|
-
}
|
|
8475
|
-
const attributeInfo = {
|
|
8551
|
+
attributeType
|
|
8552
|
+
} = decodeGLAttributeType(compositeType);
|
|
8553
|
+
const stepMode = /instance/i.test(name2) ? "instance" : "vertex";
|
|
8554
|
+
attributes.push({
|
|
8555
|
+
name: name2,
|
|
8476
8556
|
location,
|
|
8477
|
-
|
|
8478
|
-
|
|
8479
|
-
|
|
8480
|
-
|
|
8557
|
+
stepMode,
|
|
8558
|
+
type: attributeType
|
|
8559
|
+
// size - for arrays, size is the number of elements in the array
|
|
8560
|
+
});
|
|
8481
8561
|
}
|
|
8482
8562
|
}
|
|
8483
8563
|
attributes.sort((a, b) => a.location - b.location);
|
|
@@ -8496,21 +8576,21 @@ ${formattedLog}`)();
|
|
|
8496
8576
|
throw new Error("activeInfo");
|
|
8497
8577
|
}
|
|
8498
8578
|
const {
|
|
8499
|
-
name,
|
|
8579
|
+
name: name2,
|
|
8500
8580
|
type: compositeType,
|
|
8501
8581
|
size
|
|
8502
8582
|
} = activeInfo;
|
|
8503
8583
|
const {
|
|
8504
8584
|
glType,
|
|
8505
8585
|
components
|
|
8506
|
-
} =
|
|
8586
|
+
} = decodeGLUniformType(compositeType);
|
|
8507
8587
|
const accessor = new Accessor({
|
|
8508
8588
|
type: glType,
|
|
8509
8589
|
size: size * components
|
|
8510
8590
|
});
|
|
8511
8591
|
const varying = {
|
|
8512
8592
|
location,
|
|
8513
|
-
name,
|
|
8593
|
+
name: name2,
|
|
8514
8594
|
accessor
|
|
8515
8595
|
};
|
|
8516
8596
|
varyings.push(varying);
|
|
@@ -8532,14 +8612,14 @@ ${formattedLog}`)();
|
|
|
8532
8612
|
type
|
|
8533
8613
|
} = activeInfo;
|
|
8534
8614
|
const {
|
|
8535
|
-
name,
|
|
8615
|
+
name: name2,
|
|
8536
8616
|
isArray: isArray2
|
|
8537
8617
|
} = parseUniformName(rawName);
|
|
8538
|
-
let webglLocation = gl2.getUniformLocation(program,
|
|
8618
|
+
let webglLocation = gl2.getUniformLocation(program, name2);
|
|
8539
8619
|
const uniformInfo = {
|
|
8540
8620
|
// WebGL locations are uniquely typed but just numbers
|
|
8541
8621
|
location: webglLocation,
|
|
8542
|
-
name,
|
|
8622
|
+
name: name2,
|
|
8543
8623
|
size,
|
|
8544
8624
|
type,
|
|
8545
8625
|
isArray: isArray2
|
|
@@ -8547,7 +8627,7 @@ ${formattedLog}`)();
|
|
|
8547
8627
|
uniforms.push(uniformInfo);
|
|
8548
8628
|
if (uniformInfo.size > 1) {
|
|
8549
8629
|
for (let j = 0; j < uniformInfo.size; j++) {
|
|
8550
|
-
const elementName = `${
|
|
8630
|
+
const elementName = `${name2}[${j}]`;
|
|
8551
8631
|
webglLocation = gl2.getUniformLocation(program, elementName);
|
|
8552
8632
|
const arrayElementUniformInfo = {
|
|
8553
8633
|
...uniformInfo,
|
|
@@ -8590,7 +8670,7 @@ ${formattedLog}`)();
|
|
|
8590
8670
|
}
|
|
8591
8671
|
blockInfo.uniforms.push({
|
|
8592
8672
|
name: activeInfo.name,
|
|
8593
|
-
format:
|
|
8673
|
+
format: decodeGLUniformType(uniformType[i]).format,
|
|
8594
8674
|
type: uniformType[i],
|
|
8595
8675
|
arrayLength: uniformArrayLength[i],
|
|
8596
8676
|
byteOffset: uniformOffset[i],
|
|
@@ -8632,18 +8712,18 @@ ${formattedLog}`)();
|
|
|
8632
8712
|
sampleType
|
|
8633
8713
|
};
|
|
8634
8714
|
}
|
|
8635
|
-
function parseUniformName(
|
|
8636
|
-
if (
|
|
8715
|
+
function parseUniformName(name2) {
|
|
8716
|
+
if (name2[name2.length - 1] !== "]") {
|
|
8637
8717
|
return {
|
|
8638
|
-
name,
|
|
8718
|
+
name: name2,
|
|
8639
8719
|
length: 1,
|
|
8640
8720
|
isArray: false
|
|
8641
8721
|
};
|
|
8642
8722
|
}
|
|
8643
8723
|
const UNIFORM_NAME_REGEXP = /([^[]*)(\[[0-9]+\])?/;
|
|
8644
|
-
const matches = UNIFORM_NAME_REGEXP.exec(
|
|
8724
|
+
const matches = UNIFORM_NAME_REGEXP.exec(name2);
|
|
8645
8725
|
if (!matches || matches.length < 2) {
|
|
8646
|
-
throw new Error(`Failed to parse GLSL uniform name ${
|
|
8726
|
+
throw new Error(`Failed to parse GLSL uniform name ${name2}`);
|
|
8647
8727
|
}
|
|
8648
8728
|
return {
|
|
8649
8729
|
name: matches[1],
|
|
@@ -8934,8 +9014,8 @@ ${formattedLog}`)();
|
|
|
8934
9014
|
/** Handle to underlying WebGL program */
|
|
8935
9015
|
/** vertex shader */
|
|
8936
9016
|
/** fragment shader */
|
|
8937
|
-
/** The merged layout */
|
|
8938
9017
|
/** The layout extracted from shader by WebGL introspection APIs */
|
|
9018
|
+
/** The merged layout */
|
|
8939
9019
|
/** Buffer map describing buffer interleaving etc */
|
|
8940
9020
|
/** Uniforms set on this model */
|
|
8941
9021
|
uniforms = {};
|
|
@@ -8972,9 +9052,8 @@ ${formattedLog}`)();
|
|
|
8972
9052
|
}
|
|
8973
9053
|
this._compileAndLink();
|
|
8974
9054
|
this.introspectedLayout = getShaderLayout(this.device.gl, this.handle);
|
|
8975
|
-
this.
|
|
8976
|
-
this.
|
|
8977
|
-
this.layout = mergeBufferMap(this.layout, this.bufferMap);
|
|
9055
|
+
this.shaderLayout = mergeShaderLayout(this.introspectedLayout, props.shaderLayout);
|
|
9056
|
+
this.bufferLayout = props.bufferLayout || [];
|
|
8978
9057
|
this.vertexArrayObject = new WEBGLVertexArrayObject(this.device);
|
|
8979
9058
|
}
|
|
8980
9059
|
destroy() {
|
|
@@ -8989,70 +9068,75 @@ ${formattedLog}`)();
|
|
|
8989
9068
|
this._indexBuffer = webglBuffer;
|
|
8990
9069
|
}
|
|
8991
9070
|
/** @todo needed for portable model */
|
|
8992
|
-
setAttributes(
|
|
8993
|
-
|
|
8994
|
-
|
|
8995
|
-
|
|
8996
|
-
|
|
8997
|
-
|
|
8998
|
-
|
|
9071
|
+
setAttributes(buffers) {
|
|
9072
|
+
const attributeInfos = getAttributeInfosFromLayouts(this.shaderLayout, this.bufferLayout);
|
|
9073
|
+
for (const [bufferName, buffer] of Object.entries(buffers)) {
|
|
9074
|
+
let set = false;
|
|
9075
|
+
for (const attributeInfo of Object.values(attributeInfos)) {
|
|
9076
|
+
if (attributeInfo.bufferName !== bufferName) {
|
|
9077
|
+
continue;
|
|
9078
|
+
}
|
|
9079
|
+
const webglBuffer = cast(buffer);
|
|
9080
|
+
const glType = getGLFromVertexType(attributeInfo.bufferDataType);
|
|
9081
|
+
log.log(1, {
|
|
9082
|
+
setAttribute: attributeInfo.name,
|
|
9083
|
+
toBuffer: bufferName,
|
|
9084
|
+
size: attributeInfo.bufferComponents,
|
|
9085
|
+
type: glType,
|
|
9086
|
+
stride: attributeInfo.byteStride,
|
|
9087
|
+
offset: attributeInfo.byteOffset,
|
|
9088
|
+
normalized: attributeInfo.normalized,
|
|
9089
|
+
// it is the shader attribute declaration, not the vertex memory format,
|
|
9090
|
+
// that determines if the data in the buffer will be treated as integers.
|
|
9091
|
+
// /
|
|
9092
|
+
// Also note that WebGL supports assigning non-normalized integer data to floating point attributes,
|
|
9093
|
+
// but as far as we can tell, WebGPU does not.
|
|
9094
|
+
integer: attributeInfo.integer,
|
|
9095
|
+
divisor: attributeInfo.stepMode === "instance" ? 1 : 0
|
|
9096
|
+
})();
|
|
9097
|
+
this.vertexArrayObject.setBuffer(attributeInfo.location, webglBuffer, {
|
|
9098
|
+
size: attributeInfo.bufferComponents,
|
|
9099
|
+
type: glType,
|
|
9100
|
+
stride: attributeInfo.byteStride,
|
|
9101
|
+
offset: attributeInfo.byteOffset,
|
|
9102
|
+
normalized: attributeInfo.normalized,
|
|
9103
|
+
// it is the shader attribute declaration, not the vertex memory format,
|
|
9104
|
+
// that determines if the data in the buffer will be treated as integers.
|
|
9105
|
+
// /
|
|
9106
|
+
// Also note that WebGL supports assigning non-normalized integer data to floating point attributes,
|
|
9107
|
+
// but as far as we can tell, WebGPU does not.
|
|
9108
|
+
integer: attributeInfo.integer,
|
|
9109
|
+
divisor: attributeInfo.stepMode === "instance" ? 1 : 0
|
|
9110
|
+
});
|
|
9111
|
+
set = true;
|
|
9112
|
+
}
|
|
9113
|
+
if (!set) {
|
|
9114
|
+
log.warn(`setAttributes(): Ignoring (buffer "${buffer.id}" for unknown attribute "${name}" in pipeline "${this.id}"`)();
|
|
8999
9115
|
}
|
|
9000
|
-
const decoded = decodeVertexFormat(attribute.format);
|
|
9001
|
-
const {
|
|
9002
|
-
type: typeString,
|
|
9003
|
-
components: size,
|
|
9004
|
-
byteLength: stride,
|
|
9005
|
-
normalized
|
|
9006
|
-
/* , integer*/
|
|
9007
|
-
} = decoded;
|
|
9008
|
-
const divisor = attribute.stepMode === "instance" ? 1 : 0;
|
|
9009
|
-
const type = getWebGLDataType(typeString);
|
|
9010
|
-
this.vertexArrayObject.setBuffer(attribute.location, webglBuffer, {
|
|
9011
|
-
size,
|
|
9012
|
-
type,
|
|
9013
|
-
stride,
|
|
9014
|
-
offset: 0,
|
|
9015
|
-
normalized,
|
|
9016
|
-
// it is the shader attribute declaration, not the vertex memory format,
|
|
9017
|
-
// that determines if the data in the buffer will be treated as integers.
|
|
9018
|
-
// /
|
|
9019
|
-
// Also note that WebGL supports assigning non-normalized integer data to floating point attributes,
|
|
9020
|
-
// but as far as we can tell, WebGPU does not.
|
|
9021
|
-
integer: false,
|
|
9022
|
-
divisor
|
|
9023
|
-
});
|
|
9024
9116
|
}
|
|
9025
9117
|
}
|
|
9026
9118
|
/**
|
|
9027
9119
|
* Constant attributes are only supported in WebGL, not in WebGPU
|
|
9028
9120
|
* Any attribute that is disabled in the current vertex array object
|
|
9029
9121
|
* is read from the context's global constant value for that attribute location.
|
|
9030
|
-
* @param attributes
|
|
9122
|
+
* @param attributes
|
|
9031
9123
|
*/
|
|
9032
9124
|
setConstantAttributes(attributes) {
|
|
9033
|
-
for (const [name, value] of Object.entries(attributes)) {
|
|
9034
|
-
const attribute = getAttributeLayout(this.layout, name);
|
|
9035
|
-
if (!attribute) {
|
|
9036
|
-
log.warn(`Ignoring constant value supplied for unknown attribute "${name}" in pipeline "${this.id}"`)();
|
|
9037
|
-
continue;
|
|
9038
|
-
}
|
|
9039
|
-
this.vertexArrayObject.setConstant(attribute.location, value);
|
|
9040
|
-
}
|
|
9041
9125
|
Object.assign(this.constantAttributes, attributes);
|
|
9042
9126
|
}
|
|
9043
|
-
/**
|
|
9127
|
+
/**
|
|
9044
9128
|
* Bindings include: textures, samplers and uniform buffers
|
|
9045
|
-
* @todo needed for portable model
|
|
9129
|
+
* @todo needed for portable model
|
|
9046
9130
|
*/
|
|
9047
9131
|
setBindings(bindings) {
|
|
9048
|
-
for (const [
|
|
9049
|
-
const binding = this.
|
|
9132
|
+
for (const [name2, value] of Object.entries(bindings)) {
|
|
9133
|
+
const binding = this.shaderLayout.bindings.find((binding2) => binding2.name === name2);
|
|
9050
9134
|
if (!binding) {
|
|
9051
|
-
log.warn(`Unknown binding ${
|
|
9135
|
+
log.warn(`Unknown binding ${name2} in render pipeline ${this.id}`)();
|
|
9052
9136
|
continue;
|
|
9053
9137
|
}
|
|
9054
9138
|
if (!value) {
|
|
9055
|
-
log.warn(`Unsetting binding ${
|
|
9139
|
+
log.warn(`Unsetting binding ${name2} in render pipeline ${this.id}`)();
|
|
9056
9140
|
}
|
|
9057
9141
|
switch (binding.type) {
|
|
9058
9142
|
case "uniform":
|
|
@@ -9066,12 +9150,12 @@ ${formattedLog}`)();
|
|
|
9066
9150
|
}
|
|
9067
9151
|
break;
|
|
9068
9152
|
case "sampler":
|
|
9069
|
-
log.warn(`Ignoring sampler ${
|
|
9153
|
+
log.warn(`Ignoring sampler ${name2}`)();
|
|
9070
9154
|
break;
|
|
9071
9155
|
default:
|
|
9072
9156
|
throw new Error(binding.type);
|
|
9073
9157
|
}
|
|
9074
|
-
this.bindings[
|
|
9158
|
+
this.bindings[name2] = value;
|
|
9075
9159
|
}
|
|
9076
9160
|
}
|
|
9077
9161
|
setUniforms(uniforms) {
|
|
@@ -9092,7 +9176,7 @@ ${formattedLog}`)();
|
|
|
9092
9176
|
// firstInstance,
|
|
9093
9177
|
// baseVertex
|
|
9094
9178
|
} = options;
|
|
9095
|
-
const drawMode =
|
|
9179
|
+
const drawMode = getGLDrawMode(this.props.topology);
|
|
9096
9180
|
const isIndexed = Boolean(this._indexBuffer);
|
|
9097
9181
|
const indexType = this._indexBuffer?.glIndexType;
|
|
9098
9182
|
const isInstanced = Number(options.instanceCount) > 0;
|
|
@@ -9178,7 +9262,24 @@ ${formattedLog}`)();
|
|
|
9178
9262
|
}
|
|
9179
9263
|
return texturesRenderable;
|
|
9180
9264
|
}
|
|
9181
|
-
/**
|
|
9265
|
+
/**
|
|
9266
|
+
* Constant attributes need to be reset before every draw call
|
|
9267
|
+
* Any attribute that is disabled in the current vertex array object
|
|
9268
|
+
* is read from the context's global constant value for that attribute location.
|
|
9269
|
+
* @note Constant attributes are only supported in WebGL, not in WebGPU
|
|
9270
|
+
*/
|
|
9271
|
+
_applyConstantAttributes() {
|
|
9272
|
+
const attributeInfos = getAttributeInfosFromLayouts(this.shaderLayout, this.bufferLayout);
|
|
9273
|
+
for (const [name2, value] of Object.entries(this.constantAttributes)) {
|
|
9274
|
+
const attributeInfo = attributeInfos[name2];
|
|
9275
|
+
if (!attributeInfo) {
|
|
9276
|
+
log.warn(`Ignoring constant value supplied for unknown attribute "${name2}" in pipeline "${this.id}"`)();
|
|
9277
|
+
continue;
|
|
9278
|
+
}
|
|
9279
|
+
this.vertexArrayObject.setConstant(attributeInfo.location, value);
|
|
9280
|
+
}
|
|
9281
|
+
}
|
|
9282
|
+
/** Apply any bindings (before each draw call) */
|
|
9182
9283
|
_applyBindings() {
|
|
9183
9284
|
this.device.gl.useProgram(this.handle);
|
|
9184
9285
|
const {
|
|
@@ -9189,7 +9290,7 @@ ${formattedLog}`)();
|
|
|
9189
9290
|
}
|
|
9190
9291
|
let textureUnit = 0;
|
|
9191
9292
|
let uniformBufferIndex = 0;
|
|
9192
|
-
for (const binding of this.
|
|
9293
|
+
for (const binding of this.shaderLayout.bindings) {
|
|
9193
9294
|
const value = this.bindings[binding.name];
|
|
9194
9295
|
if (!value) {
|
|
9195
9296
|
throw new Error(`No value for binding ${binding.name} in ${this.id}`);
|
|
@@ -9197,11 +9298,11 @@ ${formattedLog}`)();
|
|
|
9197
9298
|
switch (binding.type) {
|
|
9198
9299
|
case "uniform":
|
|
9199
9300
|
const {
|
|
9200
|
-
name
|
|
9301
|
+
name: name2
|
|
9201
9302
|
} = binding;
|
|
9202
|
-
const location = gl2.getUniformBlockIndex(this.handle,
|
|
9303
|
+
const location = gl2.getUniformBlockIndex(this.handle, name2);
|
|
9203
9304
|
if (location === GL.INVALID_INDEX) {
|
|
9204
|
-
throw new Error(`Invalid uniform block name ${
|
|
9305
|
+
throw new Error(`Invalid uniform block name ${name2}`);
|
|
9205
9306
|
}
|
|
9206
9307
|
gl2.uniformBlockBinding(this.handle, uniformBufferIndex, location);
|
|
9207
9308
|
if (value instanceof WEBGLBuffer) {
|
|
@@ -9228,37 +9329,26 @@ ${formattedLog}`)();
|
|
|
9228
9329
|
}
|
|
9229
9330
|
}
|
|
9230
9331
|
}
|
|
9332
|
+
/**
|
|
9333
|
+
* Due to program sharing, uniforms need to be reset before every draw call
|
|
9334
|
+
* (though caching will avoid redundant WebGL calls)
|
|
9335
|
+
*/
|
|
9231
9336
|
_applyUniforms() {
|
|
9232
|
-
for (const uniformLayout of this.
|
|
9337
|
+
for (const uniformLayout of this.shaderLayout.uniforms || []) {
|
|
9233
9338
|
const {
|
|
9234
|
-
name,
|
|
9339
|
+
name: name2,
|
|
9235
9340
|
location,
|
|
9236
9341
|
type,
|
|
9237
9342
|
textureUnit
|
|
9238
9343
|
} = uniformLayout;
|
|
9239
|
-
const value = this.uniforms[
|
|
9344
|
+
const value = this.uniforms[name2] ?? textureUnit;
|
|
9240
9345
|
if (value !== void 0) {
|
|
9241
9346
|
setUniform(this.device.gl, location, type, value);
|
|
9242
9347
|
}
|
|
9243
9348
|
}
|
|
9244
9349
|
}
|
|
9245
|
-
/**
|
|
9246
|
-
* Constant attributes are only supported in WebGL, not in WebGPU
|
|
9247
|
-
* Any attribute that is disabled in the current vertex array object
|
|
9248
|
-
* is read from the context's global constant value for that attribute location.
|
|
9249
|
-
*/
|
|
9250
|
-
_applyConstantAttributes() {
|
|
9251
|
-
for (const [name, value] of Object.entries(this.constantAttributes)) {
|
|
9252
|
-
const attribute = getAttributeLayout(this.layout, name);
|
|
9253
|
-
if (!attribute) {
|
|
9254
|
-
log.warn(`Ignoring constant value supplied for unknown attribute "${name}" in pipeline "${this.id}"`)();
|
|
9255
|
-
continue;
|
|
9256
|
-
}
|
|
9257
|
-
this.vertexArrayObject.setConstant(attribute.location, value);
|
|
9258
|
-
}
|
|
9259
|
-
}
|
|
9260
9350
|
};
|
|
9261
|
-
function
|
|
9351
|
+
function getGLDrawMode(topology) {
|
|
9262
9352
|
switch (topology) {
|
|
9263
9353
|
case "point-list":
|
|
9264
9354
|
return GL.POINTS;
|
|
@@ -9298,9 +9388,6 @@ ${formattedLog}`)();
|
|
|
9298
9388
|
throw new Error(topology);
|
|
9299
9389
|
}
|
|
9300
9390
|
}
|
|
9301
|
-
function getAttributeLayout(layout, name) {
|
|
9302
|
-
return layout.attributes.find((binding) => binding.name === name) || null;
|
|
9303
|
-
}
|
|
9304
9391
|
|
|
9305
9392
|
// src/adapter/resources/webgl-command-buffer.ts
|
|
9306
9393
|
function cast2(value) {
|
|
@@ -9501,7 +9588,7 @@ ${formattedLog}`)();
|
|
|
9501
9588
|
// src/adapter/resources/webgl-command-encoder.ts
|
|
9502
9589
|
var WEBGLCommandEncoder = class extends CommandEncoder {
|
|
9503
9590
|
constructor(device, props) {
|
|
9504
|
-
super(props);
|
|
9591
|
+
super(device, props);
|
|
9505
9592
|
this.device = device;
|
|
9506
9593
|
this.commandBuffer = new WEBGLCommandBuffer(device);
|
|
9507
9594
|
}
|