@luma.gl/core 9.0.0-beta.4 → 9.0.0-beta.5
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/attribute-utils/get-attribute-from-layouts.js +140 -109
- package/dist/adapter/canvas-context.js +305 -233
- package/dist/adapter/device.d.ts +9 -11
- package/dist/adapter/device.d.ts.map +1 -1
- package/dist/adapter/device.js +114 -95
- package/dist/adapter/resources/buffer.d.ts +1 -1
- package/dist/adapter/resources/buffer.d.ts.map +1 -1
- package/dist/adapter/resources/buffer.js +65 -57
- package/dist/adapter/resources/command-buffer.js +13 -13
- package/dist/adapter/resources/command-encoder.js +17 -17
- package/dist/adapter/resources/compute-pass.js +10 -13
- package/dist/adapter/resources/compute-pipeline.js +19 -18
- package/dist/adapter/resources/external-texture.js +10 -15
- package/dist/adapter/resources/framebuffer.js +155 -94
- package/dist/adapter/resources/render-pass.js +28 -21
- package/dist/adapter/resources/render-pipeline.d.ts +3 -1
- package/dist/adapter/resources/render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/render-pipeline.js +37 -34
- package/dist/adapter/resources/resource.js +131 -93
- package/dist/adapter/resources/sampler.js +24 -24
- package/dist/adapter/resources/shader.d.ts +2 -2
- package/dist/adapter/resources/shader.d.ts.map +1 -1
- package/dist/adapter/resources/shader.js +90 -78
- package/dist/adapter/resources/texture.js +49 -43
- package/dist/adapter/resources/transform-feedback.d.ts +2 -2
- package/dist/adapter/resources/transform-feedback.d.ts.map +1 -1
- package/dist/adapter/resources/transform-feedback.js +13 -15
- package/dist/adapter/resources/vertex-array.js +30 -22
- package/dist/adapter/type-utils/decode-attribute-type.js +56 -52
- package/dist/adapter/type-utils/decode-data-type.js +36 -35
- package/dist/adapter/type-utils/decode-shader-types.js +36 -97
- package/dist/adapter/type-utils/decode-texture-format.js +160 -93
- package/dist/adapter/type-utils/decode-vertex-format.js +28 -23
- package/dist/adapter/type-utils/vertex-format-from-attribute.js +69 -65
- package/dist/adapter/type-utils/wgsl-utils.js +14 -13
- package/dist/adapter/types/accessor.js +0 -1
- package/dist/adapter/types/buffer-layout.js +0 -1
- package/dist/adapter/types/parameters.js +31 -26
- package/dist/adapter/types/shader-layout.js +0 -1
- package/dist/adapter/types/shader-types.js +2 -1
- package/dist/adapter/types/texture-formats.d.ts +1 -1
- package/dist/adapter/types/texture-formats.d.ts.map +1 -1
- package/dist/adapter/types/texture-formats.js +2 -1
- package/dist/adapter/types/types.js +0 -1
- package/dist/adapter/types/vertex-formats.js +2 -1
- package/dist/dist.dev.js +453 -270
- package/dist/index.cjs +66 -168
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +57 -46
- package/dist/init.js +29 -19
- package/dist/lib/compiler-log/compiler-message.js +2 -1
- package/dist/lib/compiler-log/format-compiler-log.js +66 -48
- package/dist/lib/compiler-log/get-shader-info.js +22 -19
- package/dist/lib/luma.d.ts.map +1 -1
- package/dist/lib/luma.js +60 -55
- package/dist/lib/uniforms/uniform-block.d.ts +0 -1
- package/dist/lib/uniforms/uniform-block.d.ts.map +1 -1
- package/dist/lib/uniforms/uniform-block.js +50 -43
- package/dist/lib/uniforms/uniform-buffer-layout.js +87 -70
- package/dist/lib/uniforms/uniform-store.js +112 -79
- package/dist/lib/uniforms/uniform.js +13 -16
- package/dist/types.js +1 -3
- package/dist/utils/array-equal.js +25 -23
- package/dist/utils/array-utils-flat.js +28 -28
- package/dist/utils/assert.js +5 -4
- package/dist/utils/cast.js +2 -2
- package/dist/utils/check-props.js +28 -27
- package/dist/utils/deep-equal.js +39 -32
- package/dist/utils/format-value.js +33 -39
- package/dist/utils/is-array.js +17 -6
- package/dist/utils/load-file.js +62 -37
- package/dist/utils/log.js +2 -4
- package/dist/utils/random.js +10 -9
- package/dist/utils/request-animation-frame.js +9 -3
- package/dist/utils/stats-manager.js +13 -14
- package/dist/utils/stub-methods.js +13 -13
- package/dist/utils/utils.d.ts +0 -6
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +20 -15
- package/dist.min.js +8 -23
- package/package.json +6 -6
- package/src/adapter/device.ts +38 -59
- package/src/adapter/resources/buffer.ts +1 -1
- package/src/adapter/resources/render-pipeline.ts +3 -1
- package/src/adapter/resources/shader.ts +2 -2
- package/src/adapter/resources/transform-feedback.ts +2 -2
- package/src/adapter/types/texture-formats.ts +1 -1
- package/src/index.ts +1 -1
- package/src/lib/luma.ts +0 -2
- package/src/lib/uniforms/uniform-block.ts +0 -1
- package/src/utils/utils.ts +0 -9
- package/dist/adapter/attribute-utils/get-attribute-from-layouts.js.map +0 -1
- package/dist/adapter/canvas-context.js.map +0 -1
- package/dist/adapter/device.js.map +0 -1
- package/dist/adapter/resources/buffer.js.map +0 -1
- package/dist/adapter/resources/command-buffer.js.map +0 -1
- package/dist/adapter/resources/command-encoder.js.map +0 -1
- package/dist/adapter/resources/compute-pass.js.map +0 -1
- package/dist/adapter/resources/compute-pipeline.js.map +0 -1
- package/dist/adapter/resources/external-texture.js.map +0 -1
- package/dist/adapter/resources/framebuffer.js.map +0 -1
- package/dist/adapter/resources/render-pass.js.map +0 -1
- package/dist/adapter/resources/render-pipeline.js.map +0 -1
- package/dist/adapter/resources/resource.js.map +0 -1
- package/dist/adapter/resources/sampler.js.map +0 -1
- package/dist/adapter/resources/shader.js.map +0 -1
- package/dist/adapter/resources/texture.js.map +0 -1
- package/dist/adapter/resources/transform-feedback.js.map +0 -1
- package/dist/adapter/resources/vertex-array.js.map +0 -1
- package/dist/adapter/type-utils/decode-attribute-type.js.map +0 -1
- package/dist/adapter/type-utils/decode-data-type.js.map +0 -1
- package/dist/adapter/type-utils/decode-shader-types.js.map +0 -1
- package/dist/adapter/type-utils/decode-texture-format.js.map +0 -1
- package/dist/adapter/type-utils/decode-vertex-format.js.map +0 -1
- package/dist/adapter/type-utils/vertex-format-from-attribute.js.map +0 -1
- package/dist/adapter/type-utils/wgsl-utils.js.map +0 -1
- package/dist/adapter/types/accessor.js.map +0 -1
- package/dist/adapter/types/buffer-layout.js.map +0 -1
- package/dist/adapter/types/parameters.js.map +0 -1
- package/dist/adapter/types/shader-layout.js.map +0 -1
- package/dist/adapter/types/shader-types.js.map +0 -1
- package/dist/adapter/types/texture-formats.js.map +0 -1
- package/dist/adapter/types/types.js.map +0 -1
- package/dist/adapter/types/vertex-formats.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/init.js.map +0 -1
- package/dist/lib/compiler-log/compiler-message.js.map +0 -1
- package/dist/lib/compiler-log/format-compiler-log.js.map +0 -1
- package/dist/lib/compiler-log/get-shader-info.js.map +0 -1
- package/dist/lib/luma.js.map +0 -1
- package/dist/lib/uniforms/uniform-block.js.map +0 -1
- package/dist/lib/uniforms/uniform-buffer-layout.js.map +0 -1
- package/dist/lib/uniforms/uniform-store.js.map +0 -1
- package/dist/lib/uniforms/uniform.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/array-equal.js.map +0 -1
- package/dist/utils/array-utils-flat.js.map +0 -1
- package/dist/utils/assert.js.map +0 -1
- package/dist/utils/cast.js.map +0 -1
- package/dist/utils/check-props.js.map +0 -1
- package/dist/utils/deep-equal.js.map +0 -1
- package/dist/utils/format-value.js.map +0 -1
- package/dist/utils/is-array.js.map +0 -1
- package/dist/utils/load-file.js.map +0 -1
- package/dist/utils/log.js.map +0 -1
- package/dist/utils/random.js.map +0 -1
- package/dist/utils/request-animation-frame.js.map +0 -1
- package/dist/utils/stats-manager.js.map +0 -1
- package/dist/utils/stub-methods.js.map +0 -1
- package/dist/utils/utils.js.map +0 -1
package/dist/dist.dev.js
CHANGED
|
@@ -75,7 +75,6 @@ var __exports__ = (() => {
|
|
|
75
75
|
glsl: () => glsl,
|
|
76
76
|
isNumberArray: () => isNumberArray,
|
|
77
77
|
isObjectEmpty: () => isObjectEmpty,
|
|
78
|
-
isPowerOfTwo: () => isPowerOfTwo,
|
|
79
78
|
isTypedArray: () => isTypedArray,
|
|
80
79
|
isUniformValue: () => isUniformValue,
|
|
81
80
|
loadFile: () => loadFile,
|
|
@@ -176,20 +175,20 @@ var __exports__ = (() => {
|
|
|
176
175
|
function formatTime(ms) {
|
|
177
176
|
let formatted;
|
|
178
177
|
if (ms < 10) {
|
|
179
|
-
formatted =
|
|
178
|
+
formatted = `${ms.toFixed(2)}ms`;
|
|
180
179
|
} else if (ms < 100) {
|
|
181
|
-
formatted =
|
|
180
|
+
formatted = `${ms.toFixed(1)}ms`;
|
|
182
181
|
} else if (ms < 1e3) {
|
|
183
|
-
formatted =
|
|
182
|
+
formatted = `${ms.toFixed(0)}ms`;
|
|
184
183
|
} else {
|
|
185
|
-
formatted =
|
|
184
|
+
formatted = `${(ms / 1e3).toFixed(2)}s`;
|
|
186
185
|
}
|
|
187
186
|
return formatted;
|
|
188
187
|
}
|
|
189
188
|
function leftPad(string) {
|
|
190
189
|
let length = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 8;
|
|
191
190
|
const padLength = Math.max(length - string.length, 0);
|
|
192
|
-
return "
|
|
191
|
+
return `${" ".repeat(padLength)}${string}`;
|
|
193
192
|
}
|
|
194
193
|
function formatImage(image, message, scale) {
|
|
195
194
|
let maxWidth = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 600;
|
|
@@ -199,8 +198,8 @@ var __exports__ = (() => {
|
|
|
199
198
|
}
|
|
200
199
|
const width = image.width * scale;
|
|
201
200
|
const height = image.height * scale;
|
|
202
|
-
const style = ["font-size:1px;",
|
|
203
|
-
return [
|
|
201
|
+
const style = ["font-size:1px;", `padding:${Math.floor(height / 2)}px ${Math.floor(width / 2)}px;`, `line-height:${height}px;`, `background:url(${imageUrl});`, `background-size:${width}px ${height}px;`, "color:transparent;"].join("");
|
|
202
|
+
return [`${message} %c+`, style];
|
|
204
203
|
}
|
|
205
204
|
|
|
206
205
|
// ../../node_modules/@probe.gl/log/dist/utils/color.js
|
|
@@ -235,11 +234,11 @@ var __exports__ = (() => {
|
|
|
235
234
|
if (!isBrowser && typeof string === "string") {
|
|
236
235
|
if (color) {
|
|
237
236
|
const colorCode = getColor(color);
|
|
238
|
-
string =
|
|
237
|
+
string = `\x1B[${colorCode}m${string}\x1B[39m`;
|
|
239
238
|
}
|
|
240
239
|
if (background) {
|
|
241
240
|
const colorCode = getColor(background);
|
|
242
|
-
string =
|
|
241
|
+
string = `\x1B[${colorCode + BACKGROUND_INCREMENT}m${string}\x1B[49m`;
|
|
243
242
|
}
|
|
244
243
|
}
|
|
245
244
|
return string;
|
|
@@ -318,8 +317,8 @@ var __exports__ = (() => {
|
|
|
318
317
|
this.LOG_THROTTLE_TIMEOUT = 0;
|
|
319
318
|
this.id = id;
|
|
320
319
|
this.userData = {};
|
|
321
|
-
this._storage = new LocalStorage(
|
|
322
|
-
this.timeStamp(
|
|
320
|
+
this._storage = new LocalStorage(`__probe-${this.id}__`, DEFAULT_LOG_CONFIGURATION);
|
|
321
|
+
this.timeStamp(`${this.id} started`);
|
|
323
322
|
autobind(this);
|
|
324
323
|
Object.seal(this);
|
|
325
324
|
}
|
|
@@ -388,10 +387,10 @@ var __exports__ = (() => {
|
|
|
388
387
|
return this._getLogFunction(0, message, originalConsole.error, arguments);
|
|
389
388
|
}
|
|
390
389
|
deprecated(oldUsage, newUsage) {
|
|
391
|
-
return this.warn(
|
|
390
|
+
return this.warn(`\`${oldUsage}\` is deprecated and will be removed in a later version. Use \`${newUsage}\` instead`);
|
|
392
391
|
}
|
|
393
392
|
removed(oldUsage, newUsage) {
|
|
394
|
-
return this.error(
|
|
393
|
+
return this.error(`\`${oldUsage}\` has been removed. Use \`${newUsage}\` instead`);
|
|
395
394
|
}
|
|
396
395
|
probe(logLevel, message) {
|
|
397
396
|
return this._getLogFunction(logLevel, message, originalConsole.log, arguments, {
|
|
@@ -566,7 +565,7 @@ var __exports__ = (() => {
|
|
|
566
565
|
function decorateMessage(id, message, opts) {
|
|
567
566
|
if (typeof message === "string") {
|
|
568
567
|
const time = opts.time ? leftPad(formatTime(opts.total)) : "";
|
|
569
|
-
message = opts.time ?
|
|
568
|
+
message = opts.time ? `${id}: ${time} ${message}` : `${id}: ${message}`;
|
|
570
569
|
message = addColor(message, opts.color, opts.background);
|
|
571
570
|
}
|
|
572
571
|
return message;
|
|
@@ -617,15 +616,16 @@ var __exports__ = (() => {
|
|
|
617
616
|
return "empty";
|
|
618
617
|
}
|
|
619
618
|
|
|
619
|
+
// ../../node_modules/@probe.gl/log/dist/init.js
|
|
620
|
+
globalThis.probe = {};
|
|
621
|
+
|
|
620
622
|
// ../../node_modules/@probe.gl/log/dist/index.js
|
|
621
623
|
var dist_default = new Log({
|
|
622
624
|
id: "@probe.gl/log"
|
|
623
625
|
});
|
|
624
626
|
|
|
625
627
|
// src/utils/log.ts
|
|
626
|
-
var log = new Log({
|
|
627
|
-
id: "luma.gl"
|
|
628
|
-
});
|
|
628
|
+
var log = new Log({ id: "luma.gl" });
|
|
629
629
|
|
|
630
630
|
// ../../node_modules/@probe.gl/stats/dist/utils/hi-res-timestamp.js
|
|
631
631
|
function getHiResTimestamp2() {
|
|
@@ -826,9 +826,7 @@ var __exports__ = (() => {
|
|
|
826
826
|
}
|
|
827
827
|
get(name2) {
|
|
828
828
|
if (!this.stats.has(name2)) {
|
|
829
|
-
this.stats.set(name2, new Stats({
|
|
830
|
-
id: name2
|
|
831
|
-
}));
|
|
829
|
+
this.stats.set(name2, new Stats({ id: name2 }));
|
|
832
830
|
}
|
|
833
831
|
return this.stats.get(name2);
|
|
834
832
|
}
|
|
@@ -850,6 +848,8 @@ var __exports__ = (() => {
|
|
|
850
848
|
VERSION: VERSION3,
|
|
851
849
|
version: VERSION3,
|
|
852
850
|
log,
|
|
851
|
+
// A global stats object that various components can add information to
|
|
852
|
+
// E.g. see webgl/resource.js
|
|
853
853
|
stats: lumaStats
|
|
854
854
|
};
|
|
855
855
|
}
|
|
@@ -875,9 +875,6 @@ var __exports__ = (() => {
|
|
|
875
875
|
const count = uidCounters[id]++;
|
|
876
876
|
return `${id}-${count}`;
|
|
877
877
|
}
|
|
878
|
-
function isPowerOfTwo(n) {
|
|
879
|
-
return n > 0 && (n & n - 1) === 0;
|
|
880
|
-
}
|
|
881
878
|
function isObjectEmpty(obj) {
|
|
882
879
|
let isEmpty = true;
|
|
883
880
|
for (const key in obj) {
|
|
@@ -889,10 +886,20 @@ var __exports__ = (() => {
|
|
|
889
886
|
|
|
890
887
|
// src/adapter/resources/resource.ts
|
|
891
888
|
var Resource = class {
|
|
889
|
+
/** props.id, for debugging. */
|
|
890
|
+
id;
|
|
891
|
+
props;
|
|
892
892
|
userData = {};
|
|
893
|
+
_device;
|
|
894
|
+
/** Whether this resource has been destroyed */
|
|
893
895
|
destroyed = false;
|
|
896
|
+
/** For resources that allocate GPU memory */
|
|
894
897
|
allocatedBytes = 0;
|
|
898
|
+
/** Attached resources will be destroyed when this resource is destroyed. Tracks auto-created "sub" resources. */
|
|
895
899
|
_attachedResources = /* @__PURE__ */ new Set();
|
|
900
|
+
/**
|
|
901
|
+
* Create a new Resource. Called from Subclass
|
|
902
|
+
*/
|
|
896
903
|
constructor(device, props, defaultProps) {
|
|
897
904
|
if (!device) {
|
|
898
905
|
throw new Error("no device");
|
|
@@ -905,9 +912,13 @@ var __exports__ = (() => {
|
|
|
905
912
|
this.userData = this.props.userData || {};
|
|
906
913
|
this.addStats();
|
|
907
914
|
}
|
|
915
|
+
/**
|
|
916
|
+
* destroy can be called on any resource to release it before it is garbage collected.
|
|
917
|
+
*/
|
|
908
918
|
destroy() {
|
|
909
919
|
this.destroyResource();
|
|
910
920
|
}
|
|
921
|
+
/** @deprecated Use destroy() */
|
|
911
922
|
delete() {
|
|
912
923
|
this.destroy();
|
|
913
924
|
return this;
|
|
@@ -915,48 +926,70 @@ var __exports__ = (() => {
|
|
|
915
926
|
toString() {
|
|
916
927
|
return `${this[Symbol.toStringTag] || this.constructor.name}(${this.id})`;
|
|
917
928
|
}
|
|
929
|
+
/**
|
|
930
|
+
* Combines a map of user props and default props, only including props from defaultProps
|
|
931
|
+
* @returns returns a map of overridden default props
|
|
932
|
+
*/
|
|
918
933
|
getProps() {
|
|
919
934
|
return this.props;
|
|
920
935
|
}
|
|
936
|
+
// ATTACHED RESOURCES
|
|
937
|
+
/**
|
|
938
|
+
* Attaches a resource. Attached resources are auto destroyed when this resource is destroyed
|
|
939
|
+
* Called automatically when sub resources are auto created but can be called by application
|
|
940
|
+
*/
|
|
921
941
|
attachResource(resource) {
|
|
922
942
|
this._attachedResources.add(resource);
|
|
923
943
|
}
|
|
944
|
+
/**
|
|
945
|
+
* Detach an attached resource. The resource will no longer be auto-destroyed when this resource is destroyed.
|
|
946
|
+
*/
|
|
924
947
|
detachResource(resource) {
|
|
925
948
|
this._attachedResources.delete(resource);
|
|
926
949
|
}
|
|
950
|
+
/**
|
|
951
|
+
* Destroys a resource (only if owned), and removes from the owned (auto-destroy) list for this resource.
|
|
952
|
+
*/
|
|
927
953
|
destroyAttachedResource(resource) {
|
|
928
954
|
if (this._attachedResources.delete(resource)) {
|
|
929
955
|
resource.destroy();
|
|
930
956
|
}
|
|
931
957
|
}
|
|
958
|
+
/** Destroy all owned resources. Make sure the resources are no longer needed before calling. */
|
|
932
959
|
destroyAttachedResources() {
|
|
933
960
|
for (const resource of Object.values(this._attachedResources)) {
|
|
934
961
|
resource.destroy();
|
|
935
962
|
}
|
|
936
963
|
this._attachedResources = /* @__PURE__ */ new Set();
|
|
937
964
|
}
|
|
965
|
+
// PROTECTED METHODS
|
|
966
|
+
/** Perform all destroy steps. Can be called by derived resources when overriding destroy() */
|
|
938
967
|
destroyResource() {
|
|
939
968
|
this.destroyAttachedResources();
|
|
940
969
|
this.removeStats();
|
|
941
970
|
this.destroyed = true;
|
|
942
971
|
}
|
|
972
|
+
/** Called by .destroy() to track object destruction. Subclass must call if overriding destroy() */
|
|
943
973
|
removeStats() {
|
|
944
974
|
const stats = this._device.statsManager.getStats("Resource Counts");
|
|
945
975
|
const name2 = this[Symbol.toStringTag];
|
|
946
976
|
stats.get(`${name2}s Active`).decrementCount();
|
|
947
977
|
}
|
|
978
|
+
/** Called by subclass to track memory allocations */
|
|
948
979
|
trackAllocatedMemory(bytes, name2 = this[Symbol.toStringTag]) {
|
|
949
980
|
const stats = this._device.statsManager.getStats("Resource Counts");
|
|
950
981
|
stats.get("GPU Memory").addCount(bytes);
|
|
951
982
|
stats.get(`${name2} Memory`).addCount(bytes);
|
|
952
983
|
this.allocatedBytes = bytes;
|
|
953
984
|
}
|
|
985
|
+
/** Called by subclass to track memory deallocations */
|
|
954
986
|
trackDeallocatedMemory(name2 = this[Symbol.toStringTag]) {
|
|
955
987
|
const stats = this._device.statsManager.getStats("Resource Counts");
|
|
956
988
|
stats.get("GPU Memory").subtractCount(this.allocatedBytes);
|
|
957
989
|
stats.get(`${name2} Memory`).subtractCount(this.allocatedBytes);
|
|
958
990
|
this.allocatedBytes = 0;
|
|
959
991
|
}
|
|
992
|
+
/** Called by resource constructor to track object creation */
|
|
960
993
|
addStats() {
|
|
961
994
|
const stats = this._device.statsManager.getStats("Resource Counts");
|
|
962
995
|
const name2 = this[Symbol.toStringTag];
|
|
@@ -965,15 +998,14 @@ var __exports__ = (() => {
|
|
|
965
998
|
stats.get(`${name2}s Active`).incrementCount();
|
|
966
999
|
}
|
|
967
1000
|
};
|
|
1001
|
+
/** Default properties for resource */
|
|
968
1002
|
__publicField(Resource, "defaultProps", {
|
|
969
1003
|
id: "undefined",
|
|
970
1004
|
handle: void 0,
|
|
971
1005
|
userData: void 0
|
|
972
1006
|
});
|
|
973
1007
|
function selectivelyMerge(props, defaultProps) {
|
|
974
|
-
const mergedProps = {
|
|
975
|
-
...defaultProps
|
|
976
|
-
};
|
|
1008
|
+
const mergedProps = { ...defaultProps };
|
|
977
1009
|
for (const key in props) {
|
|
978
1010
|
if (props[key] !== void 0) {
|
|
979
1011
|
mergedProps[key] = props[key];
|
|
@@ -987,10 +1019,12 @@ var __exports__ = (() => {
|
|
|
987
1019
|
get [Symbol.toStringTag]() {
|
|
988
1020
|
return "Buffer";
|
|
989
1021
|
}
|
|
1022
|
+
/** The usage with which this buffer was created */
|
|
1023
|
+
usage;
|
|
1024
|
+
/** For index buffers, whether indices are 16 or 32 bit */
|
|
1025
|
+
indexType;
|
|
990
1026
|
constructor(device, props) {
|
|
991
|
-
const deducedProps = {
|
|
992
|
-
...props
|
|
993
|
-
};
|
|
1027
|
+
const deducedProps = { ...props };
|
|
994
1028
|
if ((props.usage || 0) & _Buffer.INDEX && !props.indexType) {
|
|
995
1029
|
if (props.data instanceof Uint32Array) {
|
|
996
1030
|
deducedProps.indexType = "uint32";
|
|
@@ -1002,10 +1036,13 @@ var __exports__ = (() => {
|
|
|
1002
1036
|
this.usage = props.usage || 0;
|
|
1003
1037
|
this.indexType = deducedProps.indexType;
|
|
1004
1038
|
}
|
|
1005
|
-
|
|
1039
|
+
/** Read data synchronously. @note WebGL2 only */
|
|
1040
|
+
readSyncWebGL(byteOffset, byteLength) {
|
|
1006
1041
|
throw new Error("not implemented");
|
|
1007
1042
|
}
|
|
1043
|
+
/** A partial CPU-side copy of the data in this buffer, for debugging purposes */
|
|
1008
1044
|
debugData = new ArrayBuffer(0);
|
|
1045
|
+
/** This doesn't handle partial non-zero offset updates correctly */
|
|
1009
1046
|
_setDebugData(data, byteOffset, byteLength) {
|
|
1010
1047
|
const buffer = ArrayBuffer.isView(data) ? data.buffer : data;
|
|
1011
1048
|
const debugDataLength = Math.min(data ? data.byteLength : byteLength, _Buffer.DEBUG_DATA_MAX_LENGTH);
|
|
@@ -1022,22 +1059,30 @@ var __exports__ = (() => {
|
|
|
1022
1059
|
__publicField(Buffer2, "defaultProps", {
|
|
1023
1060
|
...Resource.defaultProps,
|
|
1024
1061
|
usage: 0,
|
|
1062
|
+
// Buffer.COPY_DST | Buffer.COPY_SRC
|
|
1025
1063
|
byteLength: 0,
|
|
1026
1064
|
byteOffset: 0,
|
|
1027
1065
|
data: null,
|
|
1028
1066
|
indexType: "uint16",
|
|
1029
1067
|
mappedAtCreation: false
|
|
1030
1068
|
});
|
|
1069
|
+
// Usage Flags
|
|
1031
1070
|
__publicField(Buffer2, "MAP_READ", 1);
|
|
1032
1071
|
__publicField(Buffer2, "MAP_WRITE", 2);
|
|
1033
1072
|
__publicField(Buffer2, "COPY_SRC", 4);
|
|
1034
1073
|
__publicField(Buffer2, "COPY_DST", 8);
|
|
1074
|
+
/** Index buffer */
|
|
1035
1075
|
__publicField(Buffer2, "INDEX", 16);
|
|
1076
|
+
/** Vertex buffer */
|
|
1036
1077
|
__publicField(Buffer2, "VERTEX", 32);
|
|
1078
|
+
/** Uniform buffer */
|
|
1037
1079
|
__publicField(Buffer2, "UNIFORM", 64);
|
|
1080
|
+
/** Storage buffer */
|
|
1038
1081
|
__publicField(Buffer2, "STORAGE", 128);
|
|
1039
1082
|
__publicField(Buffer2, "INDIRECT", 256);
|
|
1040
1083
|
__publicField(Buffer2, "QUERY_RESOLVE", 512);
|
|
1084
|
+
// PROTECTED METHODS (INTENDED FOR USE BY OTHER FRAMEWORK CODE ONLY)
|
|
1085
|
+
/** Max amount of debug data saved. Two vec4's */
|
|
1041
1086
|
__publicField(Buffer2, "DEBUG_DATA_MAX_LENGTH", 32);
|
|
1042
1087
|
|
|
1043
1088
|
// src/adapter/device.ts
|
|
@@ -1046,18 +1091,28 @@ var __exports__ = (() => {
|
|
|
1046
1091
|
return "Device";
|
|
1047
1092
|
}
|
|
1048
1093
|
constructor(props) {
|
|
1049
|
-
this.props = {
|
|
1050
|
-
..._Device.defaultProps,
|
|
1051
|
-
...props
|
|
1052
|
-
};
|
|
1094
|
+
this.props = { ..._Device.defaultProps, ...props };
|
|
1053
1095
|
this.id = this.props.id || uid(this[Symbol.toStringTag].toLowerCase());
|
|
1054
1096
|
}
|
|
1097
|
+
/** id of this device, primarily for debugging */
|
|
1098
|
+
id;
|
|
1099
|
+
/** stats */
|
|
1055
1100
|
statsManager = lumaStats;
|
|
1101
|
+
/** A copy of the device props */
|
|
1102
|
+
props;
|
|
1103
|
+
/** Available for the application to store data on the device */
|
|
1056
1104
|
userData = {};
|
|
1105
|
+
/** Used by other luma.gl modules to store data on the device */
|
|
1057
1106
|
_lumaData = {};
|
|
1107
|
+
/**
|
|
1108
|
+
* Trigger device loss.
|
|
1109
|
+
* @returns `true` if context loss could actually be triggered.
|
|
1110
|
+
* @note primarily intended for testing how application reacts to device loss
|
|
1111
|
+
*/
|
|
1058
1112
|
loseDevice() {
|
|
1059
1113
|
return false;
|
|
1060
1114
|
}
|
|
1115
|
+
/** Returns the default / primary canvas context. Throws an error if no canvas context is available (a WebGPU compute device) */
|
|
1061
1116
|
getCanvasContext() {
|
|
1062
1117
|
if (!this.canvasContext) {
|
|
1063
1118
|
throw new Error("Device has no CanvasContext");
|
|
@@ -1066,42 +1121,45 @@ var __exports__ = (() => {
|
|
|
1066
1121
|
}
|
|
1067
1122
|
createTexture(props) {
|
|
1068
1123
|
if (props instanceof Promise || typeof props === "string") {
|
|
1069
|
-
props = {
|
|
1070
|
-
data: props
|
|
1071
|
-
};
|
|
1124
|
+
props = { data: props };
|
|
1072
1125
|
}
|
|
1073
1126
|
return this._createTexture(props);
|
|
1074
1127
|
}
|
|
1075
1128
|
createCommandEncoder(props = {}) {
|
|
1076
1129
|
throw new Error("not implemented");
|
|
1077
1130
|
}
|
|
1131
|
+
// WebGL specific HACKS - enables app to remove webgl import
|
|
1132
|
+
// Use until we have a better way to handle these
|
|
1133
|
+
/** @deprecated - will be removed - should use command encoder */
|
|
1078
1134
|
readPixelsToArrayWebGL(source, options) {
|
|
1079
1135
|
throw new Error("not implemented");
|
|
1080
1136
|
}
|
|
1137
|
+
/** @deprecated - will be removed - should use command encoder */
|
|
1081
1138
|
readPixelsToBufferWebGL(source, options) {
|
|
1082
1139
|
throw new Error("not implemented");
|
|
1083
1140
|
}
|
|
1141
|
+
/** @deprecated - will be removed - should use WebGPU parameters (pipeline) */
|
|
1084
1142
|
setParametersWebGL(parameters) {
|
|
1085
1143
|
throw new Error("not implemented");
|
|
1086
1144
|
}
|
|
1145
|
+
/** @deprecated - will be removed - should use WebGPU parameters (pipeline) */
|
|
1087
1146
|
getParametersWebGL(parameters) {
|
|
1088
1147
|
throw new Error("not implemented");
|
|
1089
1148
|
}
|
|
1149
|
+
/** @deprecated - will be removed - should use WebGPU parameters (pipeline) */
|
|
1090
1150
|
withParametersWebGL(parameters, func) {
|
|
1091
1151
|
throw new Error("not implemented");
|
|
1092
1152
|
}
|
|
1153
|
+
/** @deprecated - will be removed - should use clear arguments in RenderPass */
|
|
1093
1154
|
clearWebGL(options) {
|
|
1094
1155
|
throw new Error("not implemented");
|
|
1095
1156
|
}
|
|
1157
|
+
// Implementation
|
|
1096
1158
|
_getBufferProps(props) {
|
|
1097
1159
|
if (props instanceof ArrayBuffer || ArrayBuffer.isView(props)) {
|
|
1098
|
-
props = {
|
|
1099
|
-
data: props
|
|
1100
|
-
};
|
|
1160
|
+
props = { data: props };
|
|
1101
1161
|
}
|
|
1102
|
-
const newProps = {
|
|
1103
|
-
...props
|
|
1104
|
-
};
|
|
1162
|
+
const newProps = { ...props };
|
|
1105
1163
|
if ((props.usage || 0) & Buffer2.INDEX && !props.indexType) {
|
|
1106
1164
|
if (props.data instanceof Uint32Array) {
|
|
1107
1165
|
newProps.indexType = "uint32";
|
|
@@ -1120,13 +1178,20 @@ var __exports__ = (() => {
|
|
|
1120
1178
|
type: "best-available",
|
|
1121
1179
|
canvas: null,
|
|
1122
1180
|
container: null,
|
|
1123
|
-
webgl2: true,
|
|
1124
|
-
webgl1: true,
|
|
1125
1181
|
manageState: true,
|
|
1126
1182
|
width: 800,
|
|
1183
|
+
// width are height are only used by headless gl
|
|
1127
1184
|
height: 600,
|
|
1128
1185
|
debug: Boolean(log.get("debug")),
|
|
1186
|
+
// Instrument context (at the expense of performance)
|
|
1129
1187
|
break: [],
|
|
1188
|
+
// alpha: undefined,
|
|
1189
|
+
// depth: undefined,
|
|
1190
|
+
// stencil: undefined,
|
|
1191
|
+
// antialias: undefined,
|
|
1192
|
+
// premultipliedAlpha: undefined,
|
|
1193
|
+
// preserveDrawingBuffer: undefined,
|
|
1194
|
+
// failIfMajorPerformanceCaveat: undefined
|
|
1130
1195
|
gl: null
|
|
1131
1196
|
});
|
|
1132
1197
|
__publicField(Device, "VERSION", VERSION2);
|
|
@@ -1156,11 +1221,9 @@ var __exports__ = (() => {
|
|
|
1156
1221
|
static setDefaultDeviceProps(props) {
|
|
1157
1222
|
Object.assign(Device.defaultProps, props);
|
|
1158
1223
|
}
|
|
1224
|
+
/** Creates a device. Asynchronously. */
|
|
1159
1225
|
static async createDevice(props = {}) {
|
|
1160
|
-
props = {
|
|
1161
|
-
...Device.defaultProps,
|
|
1162
|
-
...props
|
|
1163
|
-
};
|
|
1226
|
+
props = { ...Device.defaultProps, ...props };
|
|
1164
1227
|
if (props.gl) {
|
|
1165
1228
|
props.type = "webgl";
|
|
1166
1229
|
}
|
|
@@ -1173,8 +1236,6 @@ var __exports__ = (() => {
|
|
|
1173
1236
|
}
|
|
1174
1237
|
break;
|
|
1175
1238
|
case "webgl":
|
|
1176
|
-
case "webgl1":
|
|
1177
|
-
case "webgl2":
|
|
1178
1239
|
DeviceClass = deviceList.get("webgl");
|
|
1179
1240
|
if (DeviceClass) {
|
|
1180
1241
|
return await DeviceClass.create(props);
|
|
@@ -1194,7 +1255,9 @@ var __exports__ = (() => {
|
|
|
1194
1255
|
throw new Error("No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.");
|
|
1195
1256
|
}
|
|
1196
1257
|
};
|
|
1258
|
+
/** Global stats for all devices */
|
|
1197
1259
|
__publicField(luma, "stats", lumaStats);
|
|
1260
|
+
/** Global log */
|
|
1198
1261
|
__publicField(luma, "log", log);
|
|
1199
1262
|
|
|
1200
1263
|
// src/adapter/canvas-context.ts
|
|
@@ -1203,6 +1266,7 @@ var __exports__ = (() => {
|
|
|
1203
1266
|
var DEFAULT_CANVAS_CONTEXT_PROPS = {
|
|
1204
1267
|
canvas: null,
|
|
1205
1268
|
width: 800,
|
|
1269
|
+
// width are height are only used by headless gl
|
|
1206
1270
|
height: 600,
|
|
1207
1271
|
useDevicePixels: true,
|
|
1208
1272
|
autoResize: true,
|
|
@@ -1212,21 +1276,23 @@ var __exports__ = (() => {
|
|
|
1212
1276
|
alphaMode: "opaque"
|
|
1213
1277
|
};
|
|
1214
1278
|
var CanvasContext = class {
|
|
1279
|
+
id;
|
|
1280
|
+
props;
|
|
1281
|
+
canvas;
|
|
1282
|
+
htmlCanvas;
|
|
1283
|
+
offscreenCanvas;
|
|
1284
|
+
type;
|
|
1215
1285
|
width = 1;
|
|
1216
1286
|
height = 1;
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
};
|
|
1287
|
+
resizeObserver;
|
|
1288
|
+
/** State used by luma.gl classes: TODO - move to canvasContext*/
|
|
1289
|
+
_canvasSizeInfo = { clientWidth: 0, clientHeight: 0, devicePixelRatio: 1 };
|
|
1290
|
+
/** Check if the DOM is loaded */
|
|
1222
1291
|
static get isPageLoaded() {
|
|
1223
1292
|
return isPageLoaded();
|
|
1224
1293
|
}
|
|
1225
1294
|
constructor(props) {
|
|
1226
|
-
this.props = {
|
|
1227
|
-
...DEFAULT_CANVAS_CONTEXT_PROPS,
|
|
1228
|
-
...props
|
|
1229
|
-
};
|
|
1295
|
+
this.props = { ...DEFAULT_CANVAS_CONTEXT_PROPS, ...props };
|
|
1230
1296
|
props = this.props;
|
|
1231
1297
|
if (!isBrowser()) {
|
|
1232
1298
|
this.id = "node-canvas-context";
|
|
@@ -1269,6 +1335,10 @@ var __exports__ = (() => {
|
|
|
1269
1335
|
this.resizeObserver.observe(this.canvas);
|
|
1270
1336
|
}
|
|
1271
1337
|
}
|
|
1338
|
+
/**
|
|
1339
|
+
* Returns the current DPR, if props.useDevicePixels is true
|
|
1340
|
+
* Device refers to physical
|
|
1341
|
+
*/
|
|
1272
1342
|
getDevicePixelRatio(useDevicePixels) {
|
|
1273
1343
|
if (typeof OffscreenCanvas !== "undefined" && this.canvas instanceof OffscreenCanvas) {
|
|
1274
1344
|
return 1;
|
|
@@ -1283,6 +1353,12 @@ var __exports__ = (() => {
|
|
|
1283
1353
|
}
|
|
1284
1354
|
return useDevicePixels;
|
|
1285
1355
|
}
|
|
1356
|
+
/**
|
|
1357
|
+
* Returns the size of drawing buffer in device pixels.
|
|
1358
|
+
* @note This can be different from the 'CSS' size of a canvas, and also from the
|
|
1359
|
+
* canvas' internal drawing buffer size (.width, .height).
|
|
1360
|
+
* This is the size required to cover the canvas, adjusted for DPR
|
|
1361
|
+
*/
|
|
1286
1362
|
getPixelSize() {
|
|
1287
1363
|
switch (this.type) {
|
|
1288
1364
|
case "node":
|
|
@@ -1301,22 +1377,30 @@ var __exports__ = (() => {
|
|
|
1301
1377
|
const [width, height] = this.getPixelSize();
|
|
1302
1378
|
return width / height;
|
|
1303
1379
|
}
|
|
1380
|
+
/**
|
|
1381
|
+
* Returns multiplier need to convert CSS size to Device size
|
|
1382
|
+
*/
|
|
1304
1383
|
cssToDeviceRatio() {
|
|
1305
1384
|
try {
|
|
1306
1385
|
const [drawingBufferWidth] = this.getDrawingBufferSize();
|
|
1307
|
-
const {
|
|
1308
|
-
clientWidth
|
|
1309
|
-
} = this._canvasSizeInfo;
|
|
1386
|
+
const { clientWidth } = this._canvasSizeInfo;
|
|
1310
1387
|
return clientWidth ? drawingBufferWidth / clientWidth : 1;
|
|
1311
1388
|
} catch {
|
|
1312
1389
|
return 1;
|
|
1313
1390
|
}
|
|
1314
1391
|
}
|
|
1392
|
+
/**
|
|
1393
|
+
* Maps CSS pixel position to device pixel position
|
|
1394
|
+
*/
|
|
1315
1395
|
cssToDevicePixels(cssPixel, yInvert = true) {
|
|
1316
1396
|
const ratio = this.cssToDeviceRatio();
|
|
1317
1397
|
const [width, height] = this.getDrawingBufferSize();
|
|
1318
1398
|
return scalePixels(cssPixel, ratio, width, height, yInvert);
|
|
1319
1399
|
}
|
|
1400
|
+
/**
|
|
1401
|
+
* Use devicePixelRatio to set canvas width and height
|
|
1402
|
+
* @note this is a raw port of luma.gl v8 code. Might be worth a review
|
|
1403
|
+
*/
|
|
1320
1404
|
setDevicePixelRatio(devicePixelRatio, options = {}) {
|
|
1321
1405
|
if (!this.htmlCanvas) {
|
|
1322
1406
|
return;
|
|
@@ -1338,7 +1422,10 @@ var __exports__ = (() => {
|
|
|
1338
1422
|
this.htmlCanvas.height = canvasHeight;
|
|
1339
1423
|
const [drawingBufferWidth, drawingBufferHeight] = this.getDrawingBufferSize();
|
|
1340
1424
|
if (drawingBufferWidth !== canvasWidth || drawingBufferHeight !== canvasHeight) {
|
|
1341
|
-
clampedPixelRatio = Math.min(
|
|
1425
|
+
clampedPixelRatio = Math.min(
|
|
1426
|
+
drawingBufferWidth / clientWidth,
|
|
1427
|
+
drawingBufferHeight / clientHeight
|
|
1428
|
+
);
|
|
1342
1429
|
this.htmlCanvas.width = Math.floor(clientWidth * clampedPixelRatio);
|
|
1343
1430
|
this.htmlCanvas.height = Math.floor(clientHeight * clampedPixelRatio);
|
|
1344
1431
|
log.warn("Device pixel ratio clamped")();
|
|
@@ -1348,6 +1435,8 @@ var __exports__ = (() => {
|
|
|
1348
1435
|
this._canvasSizeInfo.devicePixelRatio = devicePixelRatio;
|
|
1349
1436
|
}
|
|
1350
1437
|
}
|
|
1438
|
+
// PRIVATE
|
|
1439
|
+
/** @todo Major hack done to port the CSS methods above, base canvas context should not depend on WebGL */
|
|
1351
1440
|
getDrawingBufferSize() {
|
|
1352
1441
|
const gl = this.device.gl;
|
|
1353
1442
|
if (!gl) {
|
|
@@ -1355,12 +1444,22 @@ var __exports__ = (() => {
|
|
|
1355
1444
|
}
|
|
1356
1445
|
return [gl.drawingBufferWidth, gl.drawingBufferHeight];
|
|
1357
1446
|
}
|
|
1447
|
+
/**
|
|
1448
|
+
* Allows subclass constructor to override the canvas id for auto created canvases.
|
|
1449
|
+
* This can really help when debugging DOM in apps that create multiple devices
|
|
1450
|
+
*/
|
|
1358
1451
|
_setAutoCreatedCanvasId(id) {
|
|
1359
1452
|
if (this.htmlCanvas?.id === "lumagl-auto-created-canvas") {
|
|
1360
1453
|
this.htmlCanvas.id = id;
|
|
1361
1454
|
}
|
|
1362
1455
|
}
|
|
1363
1456
|
};
|
|
1457
|
+
/**
|
|
1458
|
+
* Get a 'lazy' promise that resolves when the DOM is loaded.
|
|
1459
|
+
* @note Since there may be limitations on number of `load` event listeners,
|
|
1460
|
+
* it is recommended avoid calling this function until actually needed.
|
|
1461
|
+
* I.e. don't call it until you know that you will be looking up a string in the DOM.
|
|
1462
|
+
*/
|
|
1364
1463
|
__publicField(CanvasContext, "pageLoaded", getPageLoadPromise());
|
|
1365
1464
|
function getPageLoadPromise() {
|
|
1366
1465
|
if (isPageLoaded() || typeof window === "undefined") {
|
|
@@ -1396,10 +1495,7 @@ var __exports__ = (() => {
|
|
|
1396
1495
|
return canvas;
|
|
1397
1496
|
}
|
|
1398
1497
|
function createCanvas(props) {
|
|
1399
|
-
const {
|
|
1400
|
-
width,
|
|
1401
|
-
height
|
|
1402
|
-
} = props;
|
|
1498
|
+
const { width, height } = props;
|
|
1403
1499
|
const targetCanvas = document.createElement("canvas");
|
|
1404
1500
|
targetCanvas.id = "lumagl-auto-created-canvas";
|
|
1405
1501
|
targetCanvas.width = width || 1;
|
|
@@ -1426,6 +1522,7 @@ var __exports__ = (() => {
|
|
|
1426
1522
|
return {
|
|
1427
1523
|
x,
|
|
1428
1524
|
y,
|
|
1525
|
+
// when ratio < 1, current css pixel and next css pixel may point to same device pixel, set width/height to 1 in those cases.
|
|
1429
1526
|
width: Math.max(xHigh - x + 1, 1),
|
|
1430
1527
|
height: Math.max(yHigh - y + 1, 1)
|
|
1431
1528
|
};
|
|
@@ -1443,6 +1540,16 @@ var __exports__ = (() => {
|
|
|
1443
1540
|
get [Symbol.toStringTag]() {
|
|
1444
1541
|
return "Texture";
|
|
1445
1542
|
}
|
|
1543
|
+
/** dimension of this texture */
|
|
1544
|
+
dimension;
|
|
1545
|
+
/** format of this texture */
|
|
1546
|
+
format;
|
|
1547
|
+
/** width in pixels of this texture */
|
|
1548
|
+
width;
|
|
1549
|
+
/** height in pixels of this texture */
|
|
1550
|
+
height;
|
|
1551
|
+
/** depth of this texture */
|
|
1552
|
+
depth;
|
|
1446
1553
|
constructor(device, props, defaultProps = _Texture.defaultProps) {
|
|
1447
1554
|
super(device, props, defaultProps);
|
|
1448
1555
|
this.dimension = this.props.dimension;
|
|
@@ -1463,8 +1570,11 @@ var __exports__ = (() => {
|
|
|
1463
1570
|
depth: 1,
|
|
1464
1571
|
mipmaps: true,
|
|
1465
1572
|
sampler: {},
|
|
1573
|
+
// type: undefined,
|
|
1466
1574
|
compressed: false,
|
|
1575
|
+
// mipLevels: 1,
|
|
1467
1576
|
usage: 0,
|
|
1577
|
+
// usage: GPUTextureUsage.COPY_DST
|
|
1468
1578
|
mipLevels: void 0,
|
|
1469
1579
|
samples: void 0,
|
|
1470
1580
|
type: void 0
|
|
@@ -1587,18 +1697,24 @@ ${numberedLines}${positionIndicator}${message.type.toUpperCase()}: ${message.mes
|
|
|
1587
1697
|
get [Symbol.toStringTag]() {
|
|
1588
1698
|
return "Shader";
|
|
1589
1699
|
}
|
|
1700
|
+
/** The stage of this shader */
|
|
1701
|
+
stage;
|
|
1702
|
+
/** The source code of this shader */
|
|
1703
|
+
source;
|
|
1704
|
+
/** The compilation status of the shader. 'pending' if compilation is asynchronous, and on production */
|
|
1590
1705
|
compilationStatus = "pending";
|
|
1706
|
+
/** Create a new Shader instance */
|
|
1591
1707
|
constructor(device, props) {
|
|
1592
|
-
super(device, {
|
|
1593
|
-
id: getShaderIdFromProps(props),
|
|
1594
|
-
...props
|
|
1595
|
-
}, _Shader.defaultProps);
|
|
1708
|
+
super(device, { id: getShaderIdFromProps(props), ...props }, _Shader.defaultProps);
|
|
1596
1709
|
this.stage = this.props.stage;
|
|
1597
1710
|
this.source = this.props.source;
|
|
1598
1711
|
}
|
|
1712
|
+
/** Get compiler log synchronously (WebGL only) */
|
|
1599
1713
|
getCompilationInfoSync() {
|
|
1600
1714
|
return null;
|
|
1601
1715
|
}
|
|
1716
|
+
// PORTABLE HELPERS
|
|
1717
|
+
/** In browser logging of errors */
|
|
1602
1718
|
async debugShader() {
|
|
1603
1719
|
switch (this.props.debug) {
|
|
1604
1720
|
case "never":
|
|
@@ -1618,16 +1734,15 @@ ${numberedLines}${positionIndicator}${message.type.toUpperCase()}: ${message.mes
|
|
|
1618
1734
|
}
|
|
1619
1735
|
this._displayShaderLog(messages);
|
|
1620
1736
|
}
|
|
1737
|
+
// PRIVATE
|
|
1738
|
+
/** In-browser UI logging of errors */
|
|
1621
1739
|
_displayShaderLog(messages) {
|
|
1622
1740
|
if (typeof document === "undefined" || !document?.createElement) {
|
|
1623
1741
|
return;
|
|
1624
1742
|
}
|
|
1625
1743
|
const shaderName = getShaderInfo(this.source).name;
|
|
1626
1744
|
const shaderTitle = `${this.stage} ${shaderName}`;
|
|
1627
|
-
const htmlLog = formatCompilerLog(messages, this.source, {
|
|
1628
|
-
showSourceCode: "all",
|
|
1629
|
-
html: true
|
|
1630
|
-
});
|
|
1745
|
+
const htmlLog = formatCompilerLog(messages, this.source, { showSourceCode: "all", html: true });
|
|
1631
1746
|
const button = document.createElement("Button");
|
|
1632
1747
|
button.innerHTML = `
|
|
1633
1748
|
<h1>Shader Compilation Error in ${shaderTitle}</h1><br /><br />
|
|
@@ -1686,6 +1801,7 @@ ${htmlLog}
|
|
|
1686
1801
|
mipmapFilter: "nearest",
|
|
1687
1802
|
lodMinClamp: 0,
|
|
1688
1803
|
lodMaxClamp: 32,
|
|
1804
|
+
// Per WebGPU spec
|
|
1689
1805
|
compare: "less-equal",
|
|
1690
1806
|
maxAnisotropy: 1
|
|
1691
1807
|
});
|
|
@@ -1695,7 +1811,13 @@ ${htmlLog}
|
|
|
1695
1811
|
get [Symbol.toStringTag]() {
|
|
1696
1812
|
return "Framebuffer";
|
|
1697
1813
|
}
|
|
1814
|
+
/** Width of all attachments in this framebuffer */
|
|
1815
|
+
width;
|
|
1816
|
+
/** Height of all attachments in this framebuffer */
|
|
1817
|
+
height;
|
|
1818
|
+
/** Color attachments */
|
|
1698
1819
|
colorAttachments = [];
|
|
1820
|
+
/** Depth-stencil attachment, if provided */
|
|
1699
1821
|
depthStencilAttachment = null;
|
|
1700
1822
|
constructor(device, props = {}) {
|
|
1701
1823
|
super(device, props, _Framebuffer.defaultProps);
|
|
@@ -1715,6 +1837,51 @@ ${htmlLog}
|
|
|
1715
1837
|
this.resizeAttachments(this.width, this.height);
|
|
1716
1838
|
}
|
|
1717
1839
|
}
|
|
1840
|
+
// /** Returns fully populated attachment object. */
|
|
1841
|
+
// protected normalizeColorAttachment(
|
|
1842
|
+
// attachment: Texture | ColorTextureFormat
|
|
1843
|
+
// ): Required<ColorAttachment> {
|
|
1844
|
+
// const COLOR_ATTACHMENT_DEFAULTS: Required<ColorAttachment> = {
|
|
1845
|
+
// texture: undefined!,
|
|
1846
|
+
// format: undefined!,
|
|
1847
|
+
// clearValue: [0.0, 0.0, 0.0, 0.0],
|
|
1848
|
+
// loadOp: 'clear',
|
|
1849
|
+
// storeOp: 'store'
|
|
1850
|
+
// };
|
|
1851
|
+
// if (attachment instanceof Texture) {
|
|
1852
|
+
// return {...COLOR_ATTACHMENT_DEFAULTS, texture: attachment};
|
|
1853
|
+
// }
|
|
1854
|
+
// if (typeof attachment === 'string') {
|
|
1855
|
+
// return {...COLOR_ATTACHMENT_DEFAULTS, format: attachment};
|
|
1856
|
+
// }
|
|
1857
|
+
// return {...COLOR_ATTACHMENT_DEFAULTS, ...attachment};
|
|
1858
|
+
// }
|
|
1859
|
+
// /** Wraps texture inside fully populated attachment object. */
|
|
1860
|
+
// protected normalizeDepthStencilAttachment(
|
|
1861
|
+
// attachment: DepthStencilAttachment | Texture | DepthStencilTextureFormat
|
|
1862
|
+
// ): Required<DepthStencilAttachment> {
|
|
1863
|
+
// const DEPTH_STENCIL_ATTACHMENT_DEFAULTS: Required<DepthStencilAttachment> = {
|
|
1864
|
+
// texture: undefined!,
|
|
1865
|
+
// format: undefined!,
|
|
1866
|
+
// depthClearValue: 1.0,
|
|
1867
|
+
// depthLoadOp: 'clear',
|
|
1868
|
+
// depthStoreOp: 'store',
|
|
1869
|
+
// depthReadOnly: false,
|
|
1870
|
+
// stencilClearValue: 0,
|
|
1871
|
+
// stencilLoadOp: 'clear',
|
|
1872
|
+
// stencilStoreOp: 'store',
|
|
1873
|
+
// stencilReadOnly: false
|
|
1874
|
+
// };
|
|
1875
|
+
// if (typeof attachment === 'string') {
|
|
1876
|
+
// return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, format: attachment};
|
|
1877
|
+
// }
|
|
1878
|
+
// // @ts-expect-error attachment instanceof Texture doesn't cover Renderbuffer
|
|
1879
|
+
// if (attachment.handle || attachment instanceof Texture) {
|
|
1880
|
+
// return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, texture: attachment as Texture};
|
|
1881
|
+
// }
|
|
1882
|
+
// return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, ...attachment};
|
|
1883
|
+
// }
|
|
1884
|
+
/** Auto creates any textures */
|
|
1718
1885
|
autoCreateAttachmentTextures() {
|
|
1719
1886
|
this.colorAttachments = this.props.colorAttachments.map((attachment) => {
|
|
1720
1887
|
if (typeof attachment === "string") {
|
|
@@ -1734,6 +1901,7 @@ ${htmlLog}
|
|
|
1734
1901
|
}
|
|
1735
1902
|
}
|
|
1736
1903
|
}
|
|
1904
|
+
/** Create a color texture */
|
|
1737
1905
|
createColorTexture(format) {
|
|
1738
1906
|
return this.device.createTexture({
|
|
1739
1907
|
id: "color-attachment",
|
|
@@ -1743,6 +1911,7 @@ ${htmlLog}
|
|
|
1743
1911
|
height: this.height
|
|
1744
1912
|
});
|
|
1745
1913
|
}
|
|
1914
|
+
/** Create depth stencil texture */
|
|
1746
1915
|
createDepthStencilTexture(format) {
|
|
1747
1916
|
return this.device.createTexture({
|
|
1748
1917
|
id: "depth-stencil-attachment",
|
|
@@ -1752,6 +1921,11 @@ ${htmlLog}
|
|
|
1752
1921
|
height: this.height
|
|
1753
1922
|
});
|
|
1754
1923
|
}
|
|
1924
|
+
/**
|
|
1925
|
+
* Default implementation of resize
|
|
1926
|
+
* Creates new textures with correct size for all attachments.
|
|
1927
|
+
* and destroys existing textures if owned
|
|
1928
|
+
*/
|
|
1755
1929
|
resizeAttachments(width, height) {
|
|
1756
1930
|
for (let i = 0; i < this.colorAttachments.length; ++i) {
|
|
1757
1931
|
if (this.colorAttachments[i]) {
|
|
@@ -1776,6 +1950,37 @@ ${htmlLog}
|
|
|
1776
1950
|
this.attachResource(resizedTexture);
|
|
1777
1951
|
}
|
|
1778
1952
|
}
|
|
1953
|
+
/** Create a color attachment for WebGL *
|
|
1954
|
+
protected override createColorTexture(colorAttachment: Required<ColorAttachment>): Required<ColorAttachment> {
|
|
1955
|
+
return this.device._createTexture({
|
|
1956
|
+
id: `${this.id}-color`,
|
|
1957
|
+
data: null, // reserves texture memory, but texels are undefined
|
|
1958
|
+
format,
|
|
1959
|
+
// type: GL.UNSIGNED_BYTE,
|
|
1960
|
+
width: this.width,
|
|
1961
|
+
height: this.height,
|
|
1962
|
+
// Note: Mipmapping can be disabled by texture resource when we resize the texture
|
|
1963
|
+
// to a non-power-of-two dimenstion (NPOT texture) under WebGL1. To have consistant
|
|
1964
|
+
// behavior we always disable mipmaps.
|
|
1965
|
+
mipmaps: false,
|
|
1966
|
+
// Set MIN and MAG filtering parameters so mipmaps are not used in sampling.
|
|
1967
|
+
// Use LINEAR so subpixel algos like fxaa work.
|
|
1968
|
+
// Set WRAP modes that support NPOT textures too.
|
|
1969
|
+
sampler: {
|
|
1970
|
+
minFilter: 'linear',
|
|
1971
|
+
magFilter: 'linear',
|
|
1972
|
+
addressModeU: 'clamp-to-edge',
|
|
1973
|
+
addressModeV: 'clamp-to-edge'
|
|
1974
|
+
}
|
|
1975
|
+
// parameters: {
|
|
1976
|
+
// [GL.TEXTURE_MIN_FILTER]: GL.LINEAR,
|
|
1977
|
+
// [GL.TEXTURE_MAG_FILTER]: GL.LINEAR,
|
|
1978
|
+
// [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
|
|
1979
|
+
// [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE
|
|
1980
|
+
// }
|
|
1981
|
+
});
|
|
1982
|
+
}
|
|
1983
|
+
*/
|
|
1779
1984
|
};
|
|
1780
1985
|
var Framebuffer = _Framebuffer;
|
|
1781
1986
|
__publicField(Framebuffer, "defaultProps", {
|
|
@@ -1783,7 +1988,9 @@ ${htmlLog}
|
|
|
1783
1988
|
width: 1,
|
|
1784
1989
|
height: 1,
|
|
1785
1990
|
colorAttachments: [],
|
|
1991
|
+
// ['rgba8unorm-unsized'],
|
|
1786
1992
|
depthStencilAttachment: null
|
|
1993
|
+
// 'depth24plus-stencil8'
|
|
1787
1994
|
});
|
|
1788
1995
|
|
|
1789
1996
|
// src/adapter/resources/render-pipeline.ts
|
|
@@ -1792,6 +1999,12 @@ ${htmlLog}
|
|
|
1792
1999
|
return "RenderPipeline";
|
|
1793
2000
|
}
|
|
1794
2001
|
hash = "";
|
|
2002
|
+
/** The merged layout */
|
|
2003
|
+
shaderLayout;
|
|
2004
|
+
/** Buffer map describing buffer interleaving etc */
|
|
2005
|
+
bufferLayout;
|
|
2006
|
+
/** The linking status of the pipeline. 'pending' if linking is asynchronous, and on production */
|
|
2007
|
+
linkStatus = "pending";
|
|
1795
2008
|
constructor(device, props) {
|
|
1796
2009
|
super(device, props, _RenderPipeline.defaultProps);
|
|
1797
2010
|
this.shaderLayout = this.props.shaderLayout;
|
|
@@ -1803,9 +2016,11 @@ ${htmlLog}
|
|
|
1803
2016
|
...Resource.defaultProps,
|
|
1804
2017
|
vs: null,
|
|
1805
2018
|
vsEntryPoint: "",
|
|
2019
|
+
// main
|
|
1806
2020
|
vsConstants: {},
|
|
1807
2021
|
fs: null,
|
|
1808
2022
|
fsEntryPoint: "",
|
|
2023
|
+
// main
|
|
1809
2024
|
fsConstants: {},
|
|
1810
2025
|
shaderLayout: null,
|
|
1811
2026
|
bufferLayout: [],
|
|
@@ -1844,8 +2059,44 @@ ${htmlLog}
|
|
|
1844
2059
|
constructor(device, props) {
|
|
1845
2060
|
super(device, props, _RenderPass.defaultProps);
|
|
1846
2061
|
}
|
|
2062
|
+
// writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;
|
|
2063
|
+
// beginOcclusionQuery(queryIndex: number): void;
|
|
2064
|
+
// endOcclusionQuery(): void;
|
|
2065
|
+
// executeBundles(bundles: Iterable<GPURenderBundle>): void;
|
|
2066
|
+
// In WebGPU the following methods are on the renderpass.
|
|
2067
|
+
// luma.gl keeps them on the pipeline for now
|
|
2068
|
+
/*
|
|
2069
|
+
setPipeline(pipeline: RenderPipeline): void {}
|
|
2070
|
+
|
|
2071
|
+
setIndexBuffer(
|
|
2072
|
+
buffer: Buffer,
|
|
2073
|
+
indexFormat: 'uint16' | 'uint32',
|
|
2074
|
+
offset?: number,
|
|
2075
|
+
size?: number
|
|
2076
|
+
): void {}
|
|
2077
|
+
|
|
2078
|
+
abstract setVertexBuffer(slot: number, buffer: Buffer, offset: number): void;
|
|
2079
|
+
|
|
2080
|
+
abstract setBindings(bindings: Record<string, Binding>): void;
|
|
2081
|
+
|
|
2082
|
+
abstract setParameters(parameters: RenderPassParameters);
|
|
2083
|
+
|
|
2084
|
+
draw(options: {
|
|
2085
|
+
vertexCount?: number; // Either vertexCount or indexCount must be provided
|
|
2086
|
+
indexCount?: number; // Activates indexed drawing (call setIndexBuffer())
|
|
2087
|
+
instanceCount?: number; //
|
|
2088
|
+
firstVertex?: number;
|
|
2089
|
+
firstIndex?: number; // requires device.features.has('indirect-first-instance')?
|
|
2090
|
+
firstInstance?: number;
|
|
2091
|
+
baseVertex?: number;
|
|
2092
|
+
}): void {}
|
|
2093
|
+
|
|
2094
|
+
drawIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): void;
|
|
2095
|
+
drawIndexedIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): void;
|
|
2096
|
+
*/
|
|
1847
2097
|
};
|
|
1848
2098
|
var RenderPass = _RenderPass;
|
|
2099
|
+
/** Default properties for RenderPass */
|
|
1849
2100
|
__publicField(RenderPass, "defaultProps", {
|
|
1850
2101
|
...Resource.defaultProps,
|
|
1851
2102
|
framebuffer: null,
|
|
@@ -1866,6 +2117,9 @@ ${htmlLog}
|
|
|
1866
2117
|
constructor(device, props) {
|
|
1867
2118
|
super(device, props, Resource.defaultProps);
|
|
1868
2119
|
}
|
|
2120
|
+
// writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;
|
|
2121
|
+
// beginPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;
|
|
2122
|
+
// endPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;
|
|
1869
2123
|
};
|
|
1870
2124
|
__publicField(ComputePass, "defaultProps", {
|
|
1871
2125
|
...Resource.defaultProps
|
|
@@ -1885,6 +2139,14 @@ ${htmlLog}
|
|
|
1885
2139
|
}
|
|
1886
2140
|
insertDebugMarker(markerLabel) {
|
|
1887
2141
|
}
|
|
2142
|
+
// writeTimestamp(querySet: Query, queryIndex: number): void;
|
|
2143
|
+
// resolveQuerySet(options: {
|
|
2144
|
+
// querySet: GPUQuerySet,
|
|
2145
|
+
// firstQuery: number,
|
|
2146
|
+
// queryCount: number,
|
|
2147
|
+
// destination: Buffer,
|
|
2148
|
+
// destinationOffset?: number;
|
|
2149
|
+
// }): void;
|
|
1888
2150
|
};
|
|
1889
2151
|
var CommandEncoder = _CommandEncoder;
|
|
1890
2152
|
__publicField(CommandEncoder, "defaultProps", {
|
|
@@ -1965,6 +2227,7 @@ ${htmlLog}
|
|
|
1965
2227
|
f16: 2,
|
|
1966
2228
|
i32: 4,
|
|
1967
2229
|
u32: 4
|
|
2230
|
+
// 'bool-webgl': 4,
|
|
1968
2231
|
};
|
|
1969
2232
|
|
|
1970
2233
|
// src/adapter/type-utils/decode-data-type.ts
|
|
@@ -2040,7 +2303,11 @@ ${htmlLog}
|
|
|
2040
2303
|
function getAttributeInfosFromLayouts(shaderLayout, bufferLayout) {
|
|
2041
2304
|
const attributeInfos = {};
|
|
2042
2305
|
for (const attribute of shaderLayout.attributes) {
|
|
2043
|
-
attributeInfos[attribute.name] = getAttributeInfoFromLayouts(
|
|
2306
|
+
attributeInfos[attribute.name] = getAttributeInfoFromLayouts(
|
|
2307
|
+
shaderLayout,
|
|
2308
|
+
bufferLayout,
|
|
2309
|
+
attribute.name
|
|
2310
|
+
);
|
|
2044
2311
|
}
|
|
2045
2312
|
return attributeInfos;
|
|
2046
2313
|
}
|
|
@@ -2071,7 +2338,9 @@ ${htmlLog}
|
|
|
2071
2338
|
vertexFormat,
|
|
2072
2339
|
bufferDataType: vertexFormatInfo.type,
|
|
2073
2340
|
bufferComponents: vertexFormatInfo.components,
|
|
2341
|
+
// normalized is a property of the buffer's vertex format
|
|
2074
2342
|
normalized: vertexFormatInfo.normalized,
|
|
2343
|
+
// integer is a property of the shader declaration
|
|
2075
2344
|
integer: attributeTypeInfo.integer,
|
|
2076
2345
|
stepMode: bufferMapping?.stepMode || shaderDeclaration.stepMode,
|
|
2077
2346
|
byteOffset: bufferMapping?.byteOffset || 0,
|
|
@@ -2113,6 +2382,7 @@ ${htmlLog}
|
|
|
2113
2382
|
bufferName: name2,
|
|
2114
2383
|
stepMode: bufferLayout.stepMode,
|
|
2115
2384
|
vertexFormat: bufferLayout.format,
|
|
2385
|
+
// If offset is needed, use `attributes` field.
|
|
2116
2386
|
byteOffset: 0,
|
|
2117
2387
|
byteStride: bufferLayout.byteStride || 0
|
|
2118
2388
|
};
|
|
@@ -2146,9 +2416,7 @@ ${htmlLog}
|
|
|
2146
2416
|
function mergeShaderLayout(baseLayout, overrideLayout) {
|
|
2147
2417
|
const mergedLayout = {
|
|
2148
2418
|
...baseLayout,
|
|
2149
|
-
attributes: baseLayout.attributes.map((attribute) => ({
|
|
2150
|
-
...attribute
|
|
2151
|
-
}))
|
|
2419
|
+
attributes: baseLayout.attributes.map((attribute) => ({ ...attribute }))
|
|
2152
2420
|
};
|
|
2153
2421
|
for (const attribute of overrideLayout?.attributes || []) {
|
|
2154
2422
|
const baseAttribute = mergedLayout.attributes.find((attr) => attr.name === attribute.name);
|
|
@@ -2167,12 +2435,23 @@ ${htmlLog}
|
|
|
2167
2435
|
get [Symbol.toStringTag]() {
|
|
2168
2436
|
return "VertexArray";
|
|
2169
2437
|
}
|
|
2438
|
+
/** Max number of vertex attributes */
|
|
2439
|
+
maxVertexAttributes;
|
|
2440
|
+
/** Attribute infos indexed by location - TODO only needed by webgl module? */
|
|
2441
|
+
attributeInfos;
|
|
2442
|
+
/** Index buffer */
|
|
2170
2443
|
indexBuffer = null;
|
|
2444
|
+
/** Attributes indexed by buffer slot */
|
|
2445
|
+
attributes;
|
|
2171
2446
|
constructor(device, props) {
|
|
2172
2447
|
super(device, props, _VertexArray.defaultProps);
|
|
2173
2448
|
this.maxVertexAttributes = device.limits.maxVertexAttributes;
|
|
2174
2449
|
this.attributes = new Array(this.maxVertexAttributes).fill(null);
|
|
2175
|
-
this.attributeInfos = getAttributeInfosByLocation(
|
|
2450
|
+
this.attributeInfos = getAttributeInfosByLocation(
|
|
2451
|
+
props.renderPipeline.shaderLayout,
|
|
2452
|
+
props.renderPipeline.bufferLayout,
|
|
2453
|
+
this.maxVertexAttributes
|
|
2454
|
+
);
|
|
2176
2455
|
}
|
|
2177
2456
|
};
|
|
2178
2457
|
var VertexArray = _VertexArray;
|
|
@@ -2199,90 +2478,28 @@ ${htmlLog}
|
|
|
2199
2478
|
|
|
2200
2479
|
// src/adapter/type-utils/decode-shader-types.ts
|
|
2201
2480
|
var UNIFORM_FORMATS = {
|
|
2202
|
-
"f32": {
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
},
|
|
2206
|
-
"
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
},
|
|
2210
|
-
"
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
},
|
|
2214
|
-
"
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
},
|
|
2218
|
-
"
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
},
|
|
2222
|
-
"
|
|
2223
|
-
|
|
2224
|
-
components: 4
|
|
2225
|
-
},
|
|
2226
|
-
"vec2<i32>": {
|
|
2227
|
-
type: "i32",
|
|
2228
|
-
components: 2
|
|
2229
|
-
},
|
|
2230
|
-
"vec3<i32>": {
|
|
2231
|
-
type: "i32",
|
|
2232
|
-
components: 3
|
|
2233
|
-
},
|
|
2234
|
-
"vec4<i32>": {
|
|
2235
|
-
type: "i32",
|
|
2236
|
-
components: 4
|
|
2237
|
-
},
|
|
2238
|
-
"vec2<u32>": {
|
|
2239
|
-
type: "u32",
|
|
2240
|
-
components: 2
|
|
2241
|
-
},
|
|
2242
|
-
"vec3<u32>": {
|
|
2243
|
-
type: "u32",
|
|
2244
|
-
components: 3
|
|
2245
|
-
},
|
|
2246
|
-
"vec4<u32>": {
|
|
2247
|
-
type: "u32",
|
|
2248
|
-
components: 4
|
|
2249
|
-
},
|
|
2250
|
-
"mat2x2<f32>": {
|
|
2251
|
-
type: "f32",
|
|
2252
|
-
components: 4
|
|
2253
|
-
},
|
|
2254
|
-
"mat2x3<f32>": {
|
|
2255
|
-
type: "f32",
|
|
2256
|
-
components: 6
|
|
2257
|
-
},
|
|
2258
|
-
"mat2x4<f32>": {
|
|
2259
|
-
type: "f32",
|
|
2260
|
-
components: 8
|
|
2261
|
-
},
|
|
2262
|
-
"mat3x2<f32>": {
|
|
2263
|
-
type: "f32",
|
|
2264
|
-
components: 6
|
|
2265
|
-
},
|
|
2266
|
-
"mat3x3<f32>": {
|
|
2267
|
-
type: "f32",
|
|
2268
|
-
components: 9
|
|
2269
|
-
},
|
|
2270
|
-
"mat3x4<f32>": {
|
|
2271
|
-
type: "f32",
|
|
2272
|
-
components: 12
|
|
2273
|
-
},
|
|
2274
|
-
"mat4x2<f32>": {
|
|
2275
|
-
type: "f32",
|
|
2276
|
-
components: 8
|
|
2277
|
-
},
|
|
2278
|
-
"mat4x3<f32>": {
|
|
2279
|
-
type: "f32",
|
|
2280
|
-
components: 12
|
|
2281
|
-
},
|
|
2282
|
-
"mat4x4<f32>": {
|
|
2283
|
-
type: "f32",
|
|
2284
|
-
components: 16
|
|
2285
|
-
}
|
|
2481
|
+
"f32": { type: "f32", components: 1 },
|
|
2482
|
+
"i32": { type: "i32", components: 1 },
|
|
2483
|
+
"u32": { type: "u32", components: 1 },
|
|
2484
|
+
// 'bool-webgl': {type: 'bool-webgl', components: 1},
|
|
2485
|
+
"vec2<f32>": { type: "f32", components: 2 },
|
|
2486
|
+
"vec3<f32>": { type: "f32", components: 3 },
|
|
2487
|
+
"vec4<f32>": { type: "f32", components: 4 },
|
|
2488
|
+
"vec2<i32>": { type: "i32", components: 2 },
|
|
2489
|
+
"vec3<i32>": { type: "i32", components: 3 },
|
|
2490
|
+
"vec4<i32>": { type: "i32", components: 4 },
|
|
2491
|
+
"vec2<u32>": { type: "u32", components: 2 },
|
|
2492
|
+
"vec3<u32>": { type: "u32", components: 3 },
|
|
2493
|
+
"vec4<u32>": { type: "u32", components: 4 },
|
|
2494
|
+
"mat2x2<f32>": { type: "f32", components: 4 },
|
|
2495
|
+
"mat2x3<f32>": { type: "f32", components: 6 },
|
|
2496
|
+
"mat2x4<f32>": { type: "f32", components: 8 },
|
|
2497
|
+
"mat3x2<f32>": { type: "f32", components: 6 },
|
|
2498
|
+
"mat3x3<f32>": { type: "f32", components: 9 },
|
|
2499
|
+
"mat3x4<f32>": { type: "f32", components: 12 },
|
|
2500
|
+
"mat4x2<f32>": { type: "f32", components: 8 },
|
|
2501
|
+
"mat4x3<f32>": { type: "f32", components: 12 },
|
|
2502
|
+
"mat4x4<f32>": { type: "f32", components: 16 }
|
|
2286
2503
|
};
|
|
2287
2504
|
function decodeShaderUniformType(format) {
|
|
2288
2505
|
const decoded = UNIFORM_FORMATS[format];
|
|
@@ -2313,12 +2530,7 @@ ${htmlLog}
|
|
|
2313
2530
|
return new Type(scratchArrayBuffer, 0, length);
|
|
2314
2531
|
}
|
|
2315
2532
|
function fillArray(options) {
|
|
2316
|
-
const {
|
|
2317
|
-
target,
|
|
2318
|
-
source,
|
|
2319
|
-
start = 0,
|
|
2320
|
-
count = 1
|
|
2321
|
-
} = options;
|
|
2533
|
+
const { target, source, start = 0, count = 1 } = options;
|
|
2322
2534
|
const length = source.length;
|
|
2323
2535
|
const total = count * length;
|
|
2324
2536
|
let copied = 0;
|
|
@@ -2341,27 +2553,24 @@ ${htmlLog}
|
|
|
2341
2553
|
var minBufferSize = 1024;
|
|
2342
2554
|
var UniformBufferLayout = class {
|
|
2343
2555
|
layout = {};
|
|
2556
|
+
/** number of bytes needed for buffer allocation */
|
|
2557
|
+
byteLength;
|
|
2558
|
+
/** Create a new UniformBufferLayout given a map of attributes. */
|
|
2344
2559
|
constructor(uniformTypes) {
|
|
2345
2560
|
let size = 0;
|
|
2346
2561
|
for (const [key, uniformType] of Object.entries(uniformTypes)) {
|
|
2347
2562
|
const typeAndComponents = decodeShaderUniformType(uniformType);
|
|
2348
|
-
const {
|
|
2349
|
-
type,
|
|
2350
|
-
components: count
|
|
2351
|
-
} = typeAndComponents;
|
|
2563
|
+
const { type, components: count } = typeAndComponents;
|
|
2352
2564
|
size = alignTo(size, count);
|
|
2353
2565
|
const offset = size;
|
|
2354
2566
|
size += count;
|
|
2355
|
-
this.layout[key] = {
|
|
2356
|
-
type,
|
|
2357
|
-
size: count,
|
|
2358
|
-
offset
|
|
2359
|
-
};
|
|
2567
|
+
this.layout[key] = { type, size: count, offset };
|
|
2360
2568
|
}
|
|
2361
2569
|
size += (4 - size % 4) % 4;
|
|
2362
2570
|
const actualByteLength = size * 4;
|
|
2363
2571
|
this.byteLength = Math.max(actualByteLength, minBufferSize);
|
|
2364
2572
|
}
|
|
2573
|
+
/** Get the data for the complete buffer */
|
|
2365
2574
|
getData(uniformValues) {
|
|
2366
2575
|
const bufferSize = Math.max(this.byteLength, minBufferSize);
|
|
2367
2576
|
const arrayBuffer2 = getScratchArrayBuffer(bufferSize);
|
|
@@ -2369,6 +2578,7 @@ ${htmlLog}
|
|
|
2369
2578
|
i32: new Int32Array(arrayBuffer2),
|
|
2370
2579
|
u32: new Uint32Array(arrayBuffer2),
|
|
2371
2580
|
f32: new Float32Array(arrayBuffer2),
|
|
2581
|
+
// TODO not implemented
|
|
2372
2582
|
f16: new Uint16Array(arrayBuffer2)
|
|
2373
2583
|
};
|
|
2374
2584
|
for (const [name2, value] of Object.entries(uniformValues)) {
|
|
@@ -2377,11 +2587,7 @@ ${htmlLog}
|
|
|
2377
2587
|
log.warn(`Supplied uniform value ${name2} not present in uniform block layout`)();
|
|
2378
2588
|
continue;
|
|
2379
2589
|
}
|
|
2380
|
-
const {
|
|
2381
|
-
type,
|
|
2382
|
-
size,
|
|
2383
|
-
offset
|
|
2384
|
-
} = uniformLayout;
|
|
2590
|
+
const { type, size, offset } = uniformLayout;
|
|
2385
2591
|
const typedArray = typedArrays[type];
|
|
2386
2592
|
if (size === 1) {
|
|
2387
2593
|
if (typeof value !== "number" && typeof value !== "boolean") {
|
|
@@ -2400,9 +2606,11 @@ ${htmlLog}
|
|
|
2400
2606
|
}
|
|
2401
2607
|
return new Uint8Array(arrayBuffer2);
|
|
2402
2608
|
}
|
|
2609
|
+
/** Does this layout have a field with specified name */
|
|
2403
2610
|
has(name2) {
|
|
2404
2611
|
return Boolean(this.layout[name2]);
|
|
2405
2612
|
}
|
|
2613
|
+
/** Get offset and size for a field with specified name */
|
|
2406
2614
|
get(name2) {
|
|
2407
2615
|
const layout = this.layout[name2];
|
|
2408
2616
|
return layout;
|
|
@@ -2438,6 +2646,7 @@ ${htmlLog}
|
|
|
2438
2646
|
|
|
2439
2647
|
// src/lib/uniforms/uniform-block.ts
|
|
2440
2648
|
var UniformBlock = class {
|
|
2649
|
+
name;
|
|
2441
2650
|
uniforms = {};
|
|
2442
2651
|
modifiedUniforms = {};
|
|
2443
2652
|
modified = true;
|
|
@@ -2446,7 +2655,9 @@ ${htmlLog}
|
|
|
2446
2655
|
constructor(props) {
|
|
2447
2656
|
this.name = props?.name;
|
|
2448
2657
|
if (props?.name && props?.shaderLayout) {
|
|
2449
|
-
const binding = props?.shaderLayout.bindings?.find(
|
|
2658
|
+
const binding = props?.shaderLayout.bindings?.find(
|
|
2659
|
+
(binding2) => binding2.type === "uniform" && binding2.name === props?.name
|
|
2660
|
+
);
|
|
2450
2661
|
if (!binding) {
|
|
2451
2662
|
throw new Error(props?.name);
|
|
2452
2663
|
}
|
|
@@ -2456,6 +2667,7 @@ ${htmlLog}
|
|
|
2456
2667
|
}
|
|
2457
2668
|
}
|
|
2458
2669
|
}
|
|
2670
|
+
/** Set a map of uniforms */
|
|
2459
2671
|
setUniforms(uniforms) {
|
|
2460
2672
|
for (const [key, value] of Object.entries(uniforms)) {
|
|
2461
2673
|
this._setUniform(key, value);
|
|
@@ -2467,11 +2679,13 @@ ${htmlLog}
|
|
|
2467
2679
|
setNeedsRedraw(reason) {
|
|
2468
2680
|
this.needsRedraw = this.needsRedraw || reason;
|
|
2469
2681
|
}
|
|
2682
|
+
/** Returns all uniforms */
|
|
2470
2683
|
getAllUniforms() {
|
|
2471
2684
|
this.modifiedUniforms = {};
|
|
2472
2685
|
this.needsRedraw = false;
|
|
2473
2686
|
return this.uniforms || {};
|
|
2474
2687
|
}
|
|
2688
|
+
/** Set a single uniform */
|
|
2475
2689
|
_setUniform(key, value) {
|
|
2476
2690
|
if (arrayEqual(this.uniforms[key], value)) {
|
|
2477
2691
|
return;
|
|
@@ -2484,39 +2698,55 @@ ${htmlLog}
|
|
|
2484
2698
|
|
|
2485
2699
|
// src/lib/uniforms/uniform-store.ts
|
|
2486
2700
|
var UniformStore = class {
|
|
2701
|
+
/** Stores the uniform values for each uniform block */
|
|
2487
2702
|
uniformBlocks = /* @__PURE__ */ new Map();
|
|
2703
|
+
/** Can generate data for a uniform buffer for each block from data */
|
|
2488
2704
|
uniformBufferLayouts = /* @__PURE__ */ new Map();
|
|
2705
|
+
/** Actual buffer for the blocks */
|
|
2489
2706
|
uniformBuffers = /* @__PURE__ */ new Map();
|
|
2707
|
+
/**
|
|
2708
|
+
* Create a new UniformStore instance
|
|
2709
|
+
* @param blocks
|
|
2710
|
+
*/
|
|
2490
2711
|
constructor(blocks) {
|
|
2491
2712
|
for (const [bufferName, block] of Object.entries(blocks)) {
|
|
2492
2713
|
const uniformBufferName = bufferName;
|
|
2493
2714
|
const uniformBufferLayout = new UniformBufferLayout(block.uniformTypes || {});
|
|
2494
2715
|
this.uniformBufferLayouts.set(uniformBufferName, uniformBufferLayout);
|
|
2495
|
-
const uniformBlock = new UniformBlock({
|
|
2496
|
-
name: bufferName
|
|
2497
|
-
});
|
|
2716
|
+
const uniformBlock = new UniformBlock({ name: bufferName });
|
|
2498
2717
|
uniformBlock.setUniforms(block.defaultUniforms || {});
|
|
2499
2718
|
this.uniformBlocks.set(uniformBufferName, uniformBlock);
|
|
2500
2719
|
}
|
|
2501
2720
|
}
|
|
2721
|
+
/** Destroy any managed uniform buffers */
|
|
2502
2722
|
destroy() {
|
|
2503
2723
|
for (const uniformBuffer of Object.values(this.uniformBuffers)) {
|
|
2504
2724
|
uniformBuffer.destroy();
|
|
2505
2725
|
}
|
|
2506
2726
|
}
|
|
2727
|
+
/**
|
|
2728
|
+
* Set uniforms
|
|
2729
|
+
* Makes all properties partial
|
|
2730
|
+
*/
|
|
2507
2731
|
setUniforms(uniforms) {
|
|
2508
2732
|
for (const [blockName, uniformValues] of Object.entries(uniforms)) {
|
|
2509
2733
|
this.uniformBlocks.get(blockName).setUniforms(uniformValues);
|
|
2510
2734
|
}
|
|
2511
2735
|
this.updateUniformBuffers();
|
|
2512
2736
|
}
|
|
2737
|
+
/** Get the required minimum length of the uniform buffer */
|
|
2513
2738
|
getUniformBufferByteLength(uniformBufferName) {
|
|
2514
2739
|
return this.uniformBufferLayouts.get(uniformBufferName).byteLength;
|
|
2515
2740
|
}
|
|
2741
|
+
/** Get formatted binary memory that can be uploaded to a buffer */
|
|
2516
2742
|
getUniformBufferData(uniformBufferName) {
|
|
2517
2743
|
const uniformValues = this.uniformBlocks.get(uniformBufferName).getAllUniforms();
|
|
2518
2744
|
return this.uniformBufferLayouts.get(uniformBufferName).getData(uniformValues);
|
|
2519
2745
|
}
|
|
2746
|
+
/**
|
|
2747
|
+
* Creates an unmanaged uniform buffer (umnanaged means that application is responsible for destroying it)
|
|
2748
|
+
* The new buffer is initialized with current / supplied values
|
|
2749
|
+
*/
|
|
2520
2750
|
createUniformBuffer(device, uniformBufferName, uniforms) {
|
|
2521
2751
|
if (uniforms) {
|
|
2522
2752
|
this.setUniforms(uniforms);
|
|
@@ -2530,6 +2760,7 @@ ${htmlLog}
|
|
|
2530
2760
|
uniformBuffer.write(uniformBufferData);
|
|
2531
2761
|
return uniformBuffer;
|
|
2532
2762
|
}
|
|
2763
|
+
/** Get the managed uniform buffer. "managed" resources are destroyed when the uniformStore is destroyed. */
|
|
2533
2764
|
getManagedUniformBuffer(device, uniformBufferName) {
|
|
2534
2765
|
if (!this.uniformBuffers.get(uniformBufferName)) {
|
|
2535
2766
|
const byteLength = this.getUniformBufferByteLength(uniformBufferName);
|
|
@@ -2541,6 +2772,7 @@ ${htmlLog}
|
|
|
2541
2772
|
}
|
|
2542
2773
|
return this.uniformBuffers.get(uniformBufferName);
|
|
2543
2774
|
}
|
|
2775
|
+
/** Updates all uniform buffers where values have changed */
|
|
2544
2776
|
updateUniformBuffers() {
|
|
2545
2777
|
let reason = false;
|
|
2546
2778
|
for (const uniformBufferName of this.uniformBlocks.keys()) {
|
|
@@ -2552,6 +2784,7 @@ ${htmlLog}
|
|
|
2552
2784
|
}
|
|
2553
2785
|
return reason;
|
|
2554
2786
|
}
|
|
2787
|
+
/** Update one uniform buffer. Only updates if values have changed */
|
|
2555
2788
|
updateUniformBuffer(uniformBufferName) {
|
|
2556
2789
|
const uniformBlock = this.uniformBlocks.get(uniformBufferName);
|
|
2557
2790
|
const uniformBuffer = this.uniformBuffers.get(uniformBufferName);
|
|
@@ -2562,7 +2795,12 @@ ${htmlLog}
|
|
|
2562
2795
|
const uniformBuffer2 = this.uniformBuffers.get(uniformBufferName);
|
|
2563
2796
|
uniformBuffer2.write(uniformBufferData);
|
|
2564
2797
|
const uniformValues = this.uniformBlocks.get(uniformBufferName).getAllUniforms();
|
|
2565
|
-
log.log(
|
|
2798
|
+
log.log(
|
|
2799
|
+
4,
|
|
2800
|
+
`Writing to uniform buffer ${String(uniformBufferName)}`,
|
|
2801
|
+
uniformBufferData,
|
|
2802
|
+
uniformValues
|
|
2803
|
+
)();
|
|
2566
2804
|
}
|
|
2567
2805
|
return reason;
|
|
2568
2806
|
}
|
|
@@ -2580,6 +2818,7 @@ ${htmlLog}
|
|
|
2580
2818
|
return {
|
|
2581
2819
|
format: format2,
|
|
2582
2820
|
components: format2.length,
|
|
2821
|
+
// dataType - overwritten by decodedType
|
|
2583
2822
|
srgb: srgb === "-srgb",
|
|
2584
2823
|
unsized: suffix === "-unsized",
|
|
2585
2824
|
webgl: suffix === "-webgl",
|
|
@@ -2590,69 +2829,25 @@ ${htmlLog}
|
|
|
2590
2829
|
return decodeNonStandardFormat(format);
|
|
2591
2830
|
}
|
|
2592
2831
|
var EXCEPTIONS = {
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
},
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
},
|
|
2601
|
-
"
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
},
|
|
2605
|
-
"
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
"
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
},
|
|
2613
|
-
"rgb10a2unorm": {
|
|
2614
|
-
format: "rgba",
|
|
2615
|
-
bbp: 4
|
|
2616
|
-
},
|
|
2617
|
-
"rgb10a2unorm-webgl": {
|
|
2618
|
-
format: "rgba",
|
|
2619
|
-
bbp: 4
|
|
2620
|
-
},
|
|
2621
|
-
"stencil8": {
|
|
2622
|
-
components: 1,
|
|
2623
|
-
bpp: 1,
|
|
2624
|
-
a: "stencil"
|
|
2625
|
-
},
|
|
2626
|
-
"depth16unorm": {
|
|
2627
|
-
components: 1,
|
|
2628
|
-
bpp: 2,
|
|
2629
|
-
a: "depth"
|
|
2630
|
-
},
|
|
2631
|
-
"depth24plus": {
|
|
2632
|
-
components: 1,
|
|
2633
|
-
bpp: 3,
|
|
2634
|
-
a: "depth"
|
|
2635
|
-
},
|
|
2636
|
-
"depth32float": {
|
|
2637
|
-
components: 1,
|
|
2638
|
-
bpp: 4,
|
|
2639
|
-
a: "depth"
|
|
2640
|
-
},
|
|
2641
|
-
"depth24plus-stencil8": {
|
|
2642
|
-
components: 2,
|
|
2643
|
-
bpp: 4,
|
|
2644
|
-
a: "depth-stencil"
|
|
2645
|
-
},
|
|
2646
|
-
"depth24unorm-stencil8": {
|
|
2647
|
-
components: 2,
|
|
2648
|
-
bpp: 4,
|
|
2649
|
-
a: "depth-stencil"
|
|
2650
|
-
},
|
|
2651
|
-
"depth32float-stencil8": {
|
|
2652
|
-
components: 2,
|
|
2653
|
-
bpp: 4,
|
|
2654
|
-
a: "depth-stencil"
|
|
2655
|
-
}
|
|
2832
|
+
// Packed 16 bit formats
|
|
2833
|
+
"rgba4unorm-webgl": { format: "rgba", bpp: 2 },
|
|
2834
|
+
"rgb565unorm-webgl": { format: "rgb", bpp: 2 },
|
|
2835
|
+
"rgb5a1unorm-webgl": { format: "rgba", bbp: 2 },
|
|
2836
|
+
// Packed 32 bit formats
|
|
2837
|
+
"rgb9e5ufloat": { format: "rgb", bbp: 4 },
|
|
2838
|
+
"rg11b10ufloat": { format: "rgb", bbp: 4 },
|
|
2839
|
+
"rgb10a2unorm": { format: "rgba", bbp: 4 },
|
|
2840
|
+
"rgb10a2unorm-webgl": { format: "rgba", bbp: 4 },
|
|
2841
|
+
// Depth/stencil
|
|
2842
|
+
"stencil8": { components: 1, bpp: 1, a: "stencil" },
|
|
2843
|
+
"depth16unorm": { components: 1, bpp: 2, a: "depth" },
|
|
2844
|
+
"depth24plus": { components: 1, bpp: 3, a: "depth" },
|
|
2845
|
+
"depth32float": { components: 1, bpp: 4, a: "depth" },
|
|
2846
|
+
"depth24plus-stencil8": { components: 2, bpp: 4, a: "depth-stencil" },
|
|
2847
|
+
// "depth24unorm-stencil8" feature
|
|
2848
|
+
"depth24unorm-stencil8": { components: 2, bpp: 4, a: "depth-stencil" },
|
|
2849
|
+
// "depth32float-stencil8" feature
|
|
2850
|
+
"depth32float-stencil8": { components: 2, bpp: 4, a: "depth-stencil" }
|
|
2656
2851
|
};
|
|
2657
2852
|
function decodeNonStandardFormat(format) {
|
|
2658
2853
|
const data = EXCEPTIONS[format];
|
|
@@ -2755,10 +2950,7 @@ ${htmlLog}
|
|
|
2755
2950
|
return isNumberArray(value) !== null || typeof value === "number" || typeof value === "boolean";
|
|
2756
2951
|
}
|
|
2757
2952
|
function splitUniformsAndBindings(uniforms) {
|
|
2758
|
-
const result = {
|
|
2759
|
-
bindings: {},
|
|
2760
|
-
uniforms: {}
|
|
2761
|
-
};
|
|
2953
|
+
const result = { bindings: {}, uniforms: {} };
|
|
2762
2954
|
Object.keys(uniforms).forEach((name2) => {
|
|
2763
2955
|
const uniform = uniforms[name2];
|
|
2764
2956
|
if (isUniformValue(uniform)) {
|
|
@@ -2772,10 +2964,7 @@ ${htmlLog}
|
|
|
2772
2964
|
|
|
2773
2965
|
// src/utils/format-value.ts
|
|
2774
2966
|
function formatArrayValue(v, opts = {}) {
|
|
2775
|
-
const {
|
|
2776
|
-
maxElts = 16,
|
|
2777
|
-
size = 1
|
|
2778
|
-
} = opts;
|
|
2967
|
+
const { maxElts = 16, size = 1 } = opts;
|
|
2779
2968
|
let string = "[";
|
|
2780
2969
|
for (let i = 0; i < v.length && i < maxElts; ++i) {
|
|
2781
2970
|
if (i > 0) {
|
|
@@ -2788,9 +2977,7 @@ ${htmlLog}
|
|
|
2788
2977
|
}
|
|
2789
2978
|
function formatValue(v, opts = {}) {
|
|
2790
2979
|
const EPSILON = 1e-16;
|
|
2791
|
-
const {
|
|
2792
|
-
isInteger = false
|
|
2793
|
-
} = opts;
|
|
2980
|
+
const { isInteger = false } = opts;
|
|
2794
2981
|
if (Array.isArray(v) || ArrayBuffer.isView(v)) {
|
|
2795
2982
|
return formatArrayValue(v, opts);
|
|
2796
2983
|
}
|
|
@@ -2828,11 +3015,7 @@ ${htmlLog}
|
|
|
2828
3015
|
|
|
2829
3016
|
// src/utils/check-props.ts
|
|
2830
3017
|
function checkProps(className, props, propChecks) {
|
|
2831
|
-
const {
|
|
2832
|
-
removedProps = {},
|
|
2833
|
-
deprecatedProps = {},
|
|
2834
|
-
replacedProps = {}
|
|
2835
|
-
} = propChecks;
|
|
3018
|
+
const { removedProps = {}, deprecatedProps = {}, replacedProps = {} } = propChecks;
|
|
2836
3019
|
for (const propName in removedProps) {
|
|
2837
3020
|
if (propName in props) {
|
|
2838
3021
|
const replacementProp = removedProps[propName];
|