@luma.gl/engine 9.0.0-alpha.32 → 9.0.0-alpha.34
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/animation/key-frames.js +6 -7
- package/dist/animation/key-frames.js.map +1 -1
- package/dist/animation/timeline.js +5 -6
- package/dist/animation/timeline.js.map +1 -1
- package/dist/animation-loop/animation-loop.js +18 -19
- package/dist/animation-loop/animation-loop.js.map +1 -1
- package/dist/dist.dev.js +173 -145
- package/dist/geometries/ico-sphere-geometry.js +1 -1
- package/dist/geometries/ico-sphere-geometry.js.map +1 -1
- package/dist/geometries/plane-geometry.js +4 -4
- package/dist/geometries/plane-geometry.js.map +1 -1
- package/dist/geometry/geometry.d.ts +19 -4
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +9 -11
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/geometry/gpu-geometry.d.ts +10 -18
- package/dist/geometry/gpu-geometry.d.ts.map +1 -1
- package/dist/geometry/gpu-geometry.js +44 -65
- package/dist/geometry/gpu-geometry.js.map +1 -1
- package/dist/index.cjs +68 -93
- package/dist/lib/clip-space.js +16 -3
- package/dist/lib/clip-space.js.map +1 -1
- package/dist/lib/pipeline-factory.d.ts.map +1 -1
- package/dist/lib/pipeline-factory.js +15 -11
- package/dist/lib/pipeline-factory.js.map +1 -1
- package/dist/model/model.d.ts +2 -1
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +42 -44
- package/dist/model/model.js.map +1 -1
- package/dist/scenegraph/group-node.js +1 -2
- package/dist/scenegraph/group-node.js.map +1 -1
- package/dist/scenegraph/model-node.js +3 -4
- package/dist/scenegraph/model-node.js.map +1 -1
- package/dist/scenegraph/scenegraph-node.js +9 -10
- package/dist/scenegraph/scenegraph-node.js.map +1 -1
- package/dist/transform/transform.js +4 -5
- package/dist/transform/transform.js.map +1 -1
- package/dist.min.js +75 -75
- package/package.json +6 -6
- package/src/geometry/geometry.ts +19 -16
- package/src/geometry/gpu-geometry.ts +32 -67
- package/src/lib/pipeline-factory.ts +13 -10
- package/src/model/model.ts +23 -24
- package/dist/model/model-shaders.d.ts +0 -35
- package/dist/model/model-shaders.d.ts.map +0 -1
- package/dist/model/model-shaders.js +0 -38
- package/dist/model/model-shaders.js.map +0 -1
- package/dist/model/model-utils.d.ts +0 -5
- package/dist/model/model-utils.d.ts.map +0 -1
- package/dist/model/model-utils.js +0 -40
- package/dist/model/model-utils.js.map +0 -1
- package/src/model/model-shaders.ts +0 -76
- package/src/model/model-utils.ts +0 -125
package/dist/index.cjs
CHANGED
|
@@ -667,20 +667,8 @@ var GPUGeometry = class {
|
|
|
667
667
|
this.topology = props.topology;
|
|
668
668
|
this.indices = props.indices || null;
|
|
669
669
|
this.attributes = props.attributes;
|
|
670
|
-
this.vertexCount = props.vertexCount
|
|
670
|
+
this.vertexCount = props.vertexCount;
|
|
671
671
|
this.bufferLayout = props.bufferLayout || [];
|
|
672
|
-
if (!this.bufferLayout.find((layout) => layout.name === "positions")) {
|
|
673
|
-
this.bufferLayout.push({ name: "positions", format: "float32x3" });
|
|
674
|
-
}
|
|
675
|
-
if (!this.bufferLayout.find((layout) => layout.name === "normals")) {
|
|
676
|
-
this.bufferLayout.push({ name: "normals", format: "float32x3" });
|
|
677
|
-
}
|
|
678
|
-
if (!this.bufferLayout.find((layout) => layout.name === "texCoords")) {
|
|
679
|
-
this.bufferLayout.push({ name: "texCoords", format: "float32x2" });
|
|
680
|
-
}
|
|
681
|
-
if (!this.bufferLayout.find((layout) => layout.name === "colors")) {
|
|
682
|
-
this.bufferLayout.push({ name: "colors", format: "float32x3" });
|
|
683
|
-
}
|
|
684
672
|
if (this.indices) {
|
|
685
673
|
(0, import_core4.assert)(this.indices.usage === import_core4.Buffer.INDEX);
|
|
686
674
|
}
|
|
@@ -712,9 +700,10 @@ function makeGPUGeometry(device, geometry) {
|
|
|
712
700
|
return geometry;
|
|
713
701
|
}
|
|
714
702
|
const indices = getIndexBufferFromGeometry(device, geometry);
|
|
715
|
-
const attributes = getAttributeBuffersFromGeometry(device, geometry);
|
|
703
|
+
const { attributes, bufferLayout } = getAttributeBuffersFromGeometry(device, geometry);
|
|
716
704
|
return new GPUGeometry({
|
|
717
|
-
topology: geometry.topology,
|
|
705
|
+
topology: geometry.topology || "triangle-list",
|
|
706
|
+
bufferLayout,
|
|
718
707
|
vertexCount: geometry.vertexCount,
|
|
719
708
|
indices,
|
|
720
709
|
attributes
|
|
@@ -724,23 +713,30 @@ function getIndexBufferFromGeometry(device, geometry) {
|
|
|
724
713
|
if (!geometry.indices) {
|
|
725
714
|
return void 0;
|
|
726
715
|
}
|
|
727
|
-
const data = geometry.indices.value
|
|
728
|
-
(0, import_core4.assert)(
|
|
729
|
-
data instanceof Uint16Array || data instanceof Uint32Array,
|
|
730
|
-
'attribute array for "indices" must be of integer type'
|
|
731
|
-
);
|
|
716
|
+
const data = geometry.indices.value;
|
|
732
717
|
return device.createBuffer({ usage: import_core4.Buffer.INDEX, data });
|
|
733
718
|
}
|
|
734
719
|
function getAttributeBuffersFromGeometry(device, geometry) {
|
|
735
|
-
const
|
|
736
|
-
const
|
|
737
|
-
const
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
720
|
+
const bufferLayout = [];
|
|
721
|
+
const attributes = {};
|
|
722
|
+
for (const [attributeName, attribute] of Object.entries(geometry.attributes)) {
|
|
723
|
+
let name = attributeName;
|
|
724
|
+
switch (attributeName) {
|
|
725
|
+
case "POSITION":
|
|
726
|
+
name = "positions";
|
|
727
|
+
break;
|
|
728
|
+
case "NORMAL":
|
|
729
|
+
name = "normals";
|
|
730
|
+
break;
|
|
731
|
+
case "TEXCOORD_0":
|
|
732
|
+
name = "texCoords";
|
|
733
|
+
break;
|
|
734
|
+
}
|
|
735
|
+
attributes[name] = device.createBuffer({ data: attribute.value, id: `${attributeName}-buffer` });
|
|
736
|
+
bufferLayout.push({ name, format: `float32x${attribute.size}` });
|
|
737
|
+
}
|
|
738
|
+
const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices);
|
|
739
|
+
return { attributes, bufferLayout, vertexCount };
|
|
744
740
|
}
|
|
745
741
|
|
|
746
742
|
// src/lib/pipeline-factory.ts
|
|
@@ -796,10 +792,15 @@ var _PipelineFactory = class {
|
|
|
796
792
|
_hashRenderPipeline(props) {
|
|
797
793
|
const vsHash = this._getHash(props.vs);
|
|
798
794
|
const fsHash = props.fs ? this._getHash(props.fs) : 0;
|
|
799
|
-
const parameterHash = this._getHash(JSON.stringify(props.parameters));
|
|
800
|
-
const bufferLayoutHash = this._getHash(JSON.stringify(props.bufferLayout));
|
|
801
795
|
const varyingHash = "-";
|
|
802
|
-
|
|
796
|
+
switch (this.device.info.type) {
|
|
797
|
+
case "webgpu":
|
|
798
|
+
const parameterHash = this._getHash(JSON.stringify(props.parameters));
|
|
799
|
+
const bufferLayoutHash = this._getHash(JSON.stringify(props.bufferLayout));
|
|
800
|
+
return `${vsHash}/${fsHash}V${varyingHash}T${props.topology}P${parameterHash}BL${bufferLayoutHash}}`;
|
|
801
|
+
default:
|
|
802
|
+
return `${vsHash}/${fsHash}V${varyingHash}`;
|
|
803
|
+
}
|
|
803
804
|
}
|
|
804
805
|
_getHash(key) {
|
|
805
806
|
if (this._hashes[key] === void 0) {
|
|
@@ -814,41 +815,6 @@ PipelineFactory.defaultProps = __spreadProps(__spreadValues({}, import_core5.Ren
|
|
|
814
815
|
fs: void 0
|
|
815
816
|
});
|
|
816
817
|
|
|
817
|
-
// src/model/model-shaders.ts
|
|
818
|
-
function buildShaders(device, props) {
|
|
819
|
-
if (!props.vs) {
|
|
820
|
-
throw new Error("no vertex shader");
|
|
821
|
-
}
|
|
822
|
-
const vs = getShaderSource(device, props.vs);
|
|
823
|
-
let fs;
|
|
824
|
-
if (props.fs) {
|
|
825
|
-
fs = getShaderSource(device, props.fs);
|
|
826
|
-
}
|
|
827
|
-
const platformInfo = {
|
|
828
|
-
type: device.info.type,
|
|
829
|
-
gpu: device.info.gpu,
|
|
830
|
-
features: device.features
|
|
831
|
-
};
|
|
832
|
-
return props.shaderAssembler.assembleShaders(platformInfo, __spreadProps(__spreadValues({}, props), { fs, vs }));
|
|
833
|
-
}
|
|
834
|
-
function getShaderSource(device, shader) {
|
|
835
|
-
if (typeof shader === "string") {
|
|
836
|
-
return shader;
|
|
837
|
-
}
|
|
838
|
-
switch (device.info.type) {
|
|
839
|
-
case "webgpu":
|
|
840
|
-
if (shader == null ? void 0 : shader.wgsl) {
|
|
841
|
-
return shader.wgsl;
|
|
842
|
-
}
|
|
843
|
-
throw new Error("WebGPU does not support GLSL shaders");
|
|
844
|
-
default:
|
|
845
|
-
if (shader == null ? void 0 : shader.glsl) {
|
|
846
|
-
return shader.glsl;
|
|
847
|
-
}
|
|
848
|
-
throw new Error("WebGL does not support WGSL shaders");
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
|
|
852
818
|
// src/model/model.ts
|
|
853
819
|
var _Model = class {
|
|
854
820
|
constructor(device, props) {
|
|
@@ -871,7 +837,13 @@ var _Model = class {
|
|
|
871
837
|
this.id = props.id || (0, import_core6.uid)("model");
|
|
872
838
|
this.device = device;
|
|
873
839
|
Object.assign(this.userData, props.userData);
|
|
874
|
-
const
|
|
840
|
+
const platformInfo = {
|
|
841
|
+
type: device.info.type,
|
|
842
|
+
shaderLanguage: device.info.shadingLanguages[0],
|
|
843
|
+
gpu: device.info.gpu,
|
|
844
|
+
features: device.features
|
|
845
|
+
};
|
|
846
|
+
const { vs, fs, getUniforms } = this.props.shaderAssembler.assembleShaders(platformInfo, this.props);
|
|
875
847
|
this.vs = vs;
|
|
876
848
|
this.fs = fs;
|
|
877
849
|
this._getModuleUniforms = getUniforms;
|
|
@@ -880,9 +852,8 @@ var _Model = class {
|
|
|
880
852
|
this.topology = this.props.topology;
|
|
881
853
|
this.bufferLayout = this.props.bufferLayout;
|
|
882
854
|
this.parameters = this.props.parameters;
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
this.setGeometry(gpuGeometry);
|
|
855
|
+
if (props.geometry) {
|
|
856
|
+
this.setGeometry(props.geometry);
|
|
886
857
|
}
|
|
887
858
|
this.pipelineFactory = props.pipelineFactory || PipelineFactory.getDefaultPipelineFactory(this.device);
|
|
888
859
|
this.pipeline = this._updatePipeline();
|
|
@@ -930,14 +901,16 @@ var _Model = class {
|
|
|
930
901
|
// Update fixed fields (can trigger pipeline rebuild)
|
|
931
902
|
/**
|
|
932
903
|
* Updates the optional geometry
|
|
904
|
+
* Geometry, sets several attributes, indices, and also vertex count and topology
|
|
933
905
|
* @note Can trigger a pipeline rebuild / pipeline cache fetch on WebGPU
|
|
934
906
|
*/
|
|
935
907
|
setGeometry(geometry) {
|
|
936
|
-
this.
|
|
937
|
-
this.
|
|
938
|
-
this.
|
|
939
|
-
this.
|
|
940
|
-
this.
|
|
908
|
+
const gpuGeometry = geometry && makeGPUGeometry(this.device, geometry);
|
|
909
|
+
this.setTopology(gpuGeometry.topology || "triangle-list");
|
|
910
|
+
this.bufferLayout = mergeBufferLayouts(this.bufferLayout, gpuGeometry.bufferLayout);
|
|
911
|
+
this.vertexCount = gpuGeometry.vertexCount;
|
|
912
|
+
this.setAttributes(gpuGeometry.attributes);
|
|
913
|
+
this.setIndexBuffer(gpuGeometry.indices);
|
|
941
914
|
}
|
|
942
915
|
/**
|
|
943
916
|
* Updates the primitive topology ('triangle-list', 'triangle-strip' etc).
|
|
@@ -946,9 +919,7 @@ var _Model = class {
|
|
|
946
919
|
setTopology(topology) {
|
|
947
920
|
if (topology !== this.topology) {
|
|
948
921
|
this.topology = topology;
|
|
949
|
-
|
|
950
|
-
this._setPipelineNeedsUpdate("topology");
|
|
951
|
-
}
|
|
922
|
+
this._setPipelineNeedsUpdate("topology");
|
|
952
923
|
}
|
|
953
924
|
}
|
|
954
925
|
/**
|
|
@@ -958,9 +929,7 @@ var _Model = class {
|
|
|
958
929
|
setBufferLayout(bufferLayout) {
|
|
959
930
|
if (bufferLayout !== this.bufferLayout) {
|
|
960
931
|
this.bufferLayout = bufferLayout;
|
|
961
|
-
|
|
962
|
-
this._setPipelineNeedsUpdate("bufferLayout");
|
|
963
|
-
}
|
|
932
|
+
this._setPipelineNeedsUpdate("bufferLayout");
|
|
964
933
|
}
|
|
965
934
|
}
|
|
966
935
|
/**
|
|
@@ -971,9 +940,7 @@ var _Model = class {
|
|
|
971
940
|
setParameters(parameters) {
|
|
972
941
|
if (!(0, import_core6.deepEqual)(parameters, this.parameters, 2)) {
|
|
973
942
|
this.parameters = parameters;
|
|
974
|
-
|
|
975
|
-
this._setPipelineNeedsUpdate("parameters");
|
|
976
|
-
}
|
|
943
|
+
this._setPipelineNeedsUpdate("parameters");
|
|
977
944
|
}
|
|
978
945
|
}
|
|
979
946
|
// Update dynamic fields
|
|
@@ -1208,7 +1175,10 @@ var Geometry = class {
|
|
|
1208
1175
|
getVertexCount() {
|
|
1209
1176
|
return this.vertexCount;
|
|
1210
1177
|
}
|
|
1211
|
-
|
|
1178
|
+
/**
|
|
1179
|
+
* Return an object with all attributes plus indices added as a field.
|
|
1180
|
+
* TODO Geometry types are a mess
|
|
1181
|
+
*/
|
|
1212
1182
|
getAttributes() {
|
|
1213
1183
|
return this.indices ? __spreadValues({ indices: this.indices }, this.attributes) : this.attributes;
|
|
1214
1184
|
}
|
|
@@ -1216,11 +1186,17 @@ var Geometry = class {
|
|
|
1216
1186
|
_print(attributeName) {
|
|
1217
1187
|
return `Geometry ${this.id} attribute ${attributeName}`;
|
|
1218
1188
|
}
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1189
|
+
/**
|
|
1190
|
+
* GeometryAttribute
|
|
1191
|
+
* value: typed array
|
|
1192
|
+
* type: indices, vertices, uvs
|
|
1193
|
+
* size: elements per vertex
|
|
1194
|
+
* target: WebGL buffer type (string or constant)
|
|
1195
|
+
*
|
|
1196
|
+
* @param attributes
|
|
1197
|
+
* @param indices
|
|
1198
|
+
* @returns
|
|
1199
|
+
*/
|
|
1224
1200
|
_setAttributes(attributes, indices) {
|
|
1225
1201
|
return this;
|
|
1226
1202
|
}
|
|
@@ -1229,8 +1205,7 @@ var Geometry = class {
|
|
|
1229
1205
|
return indices.value.length;
|
|
1230
1206
|
}
|
|
1231
1207
|
let vertexCount = Infinity;
|
|
1232
|
-
for (const
|
|
1233
|
-
const attribute = attributes[attributeName];
|
|
1208
|
+
for (const attribute of Object.values(attributes)) {
|
|
1234
1209
|
const { value, size, constant } = attribute;
|
|
1235
1210
|
if (!constant && value && size >= 1) {
|
|
1236
1211
|
vertexCount = Math.min(vertexCount, value.length / size);
|
package/dist/lib/clip-space.js
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
|
-
import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
|
|
2
|
-
var _templateObject;
|
|
3
1
|
import { glsl } from '@luma.gl/core';
|
|
4
2
|
import { WebGLDevice } from '@luma.gl/webgl';
|
|
5
3
|
import { Model } from "../model/model.js";
|
|
6
4
|
import { Geometry } from "../geometry/geometry.js";
|
|
7
|
-
const CLIPSPACE_VERTEX_SHADER = glsl
|
|
5
|
+
const CLIPSPACE_VERTEX_SHADER = glsl`\
|
|
6
|
+
attribute vec2 aClipSpacePosition;
|
|
7
|
+
attribute vec2 aTexCoord;
|
|
8
|
+
attribute vec2 aCoordinate;
|
|
9
|
+
|
|
10
|
+
varying vec2 position;
|
|
11
|
+
varying vec2 coordinate;
|
|
12
|
+
varying vec2 uv;
|
|
13
|
+
|
|
14
|
+
void main(void) {
|
|
15
|
+
gl_Position = vec4(aClipSpacePosition, 0., 1.);
|
|
16
|
+
position = aClipSpacePosition;
|
|
17
|
+
coordinate = aCoordinate;
|
|
18
|
+
uv = aTexCoord;
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
8
21
|
const POSITIONS = [-1, -1, 1, -1, -1, 1, 1, 1];
|
|
9
22
|
export class ClipSpace extends Model {
|
|
10
23
|
constructor(device, opts) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clip-space.js","names":["glsl","WebGLDevice","Model","Geometry","CLIPSPACE_VERTEX_SHADER","
|
|
1
|
+
{"version":3,"file":"clip-space.js","names":["glsl","WebGLDevice","Model","Geometry","CLIPSPACE_VERTEX_SHADER","POSITIONS","ClipSpace","constructor","device","opts","TEX_COORDS","map","coord","attach","vs","vertexCount","geometry","topology","attributes","aClipSpacePosition","size","value","Float32Array","aTexCoord","aCoordinate"],"sources":["../../src/lib/clip-space.ts"],"sourcesContent":["\n// ClipSpace\nimport {Device, glsl} from '@luma.gl/core';\nimport {WebGLDevice} from '@luma.gl/webgl';\nimport {Model, ModelProps} from '../model/model';\nimport {Geometry} from '../geometry/geometry';\n\nconst CLIPSPACE_VERTEX_SHADER = glsl`\\\nattribute vec2 aClipSpacePosition;\nattribute vec2 aTexCoord;\nattribute vec2 aCoordinate;\n\nvarying vec2 position;\nvarying vec2 coordinate;\nvarying vec2 uv;\n\nvoid main(void) {\n gl_Position = vec4(aClipSpacePosition, 0., 1.);\n position = aClipSpacePosition;\n coordinate = aCoordinate;\n uv = aTexCoord;\n}\n`;\n\n/* eslint-disable indent, no-multi-spaces */\nconst POSITIONS = [-1, -1, 1, -1, -1, 1, 1, 1];\n\n/**\n * A flat geometry that covers the \"visible area\" that the GPU renders.\n */\nexport class ClipSpace extends Model {\n constructor(device: Device | WebGLRenderingContext, opts?: ModelProps) {\n const TEX_COORDS = POSITIONS.map((coord) => (coord === -1 ? 0 : coord));\n\n super(\n WebGLDevice.attach(device),\n {\n ...opts,\n vs: CLIPSPACE_VERTEX_SHADER,\n vertexCount: 4,\n geometry: new Geometry({\n topology: 'triangle-strip',\n vertexCount: 4,\n attributes: {\n aClipSpacePosition: {size: 2, value: new Float32Array(POSITIONS)},\n aTexCoord: {size: 2, value: new Float32Array(TEX_COORDS)},\n aCoordinate: {size: 2, value: new Float32Array(T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@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline-factory.d.ts","sourceRoot":"","sources":["../../src/lib/pipeline-factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pipeline-factory.d.ts","sourceRoot":"","sources":["../../src/lib/pipeline-factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,eAAe,CAAC;AACvD,OAAO,EAAC,MAAM,EAAE,cAAc,EAAC,MAAM,eAAe,CAAC;AAErD,mDAAmD;AACnD,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,mBAAmB,EAAE,IAAI,GAAG,IAAI,CAAC,GAAG;IAE1E,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF;;GAEG;AACH,qBAAa,eAAe;IAC1B,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,oBAAoB,CAAC,CAIlD;IAED,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8B;IACtD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA8B;IACzD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAsC;IAErE,MAAM,CAAC,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe;gBAKrD,MAAM,EAAE,MAAM;IAI1B,oBAAoB,CAAC,OAAO,EAAE,oBAAoB,GAAG,cAAc;IAsBnE,OAAO,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IAYvC,qBAAqB,CAAC,KAAK,EAAE,oBAAoB,GAAG,cAAc;IAclE,qEAAqE;IACrE,mBAAmB,CAAC,KAAK,EAAE,oBAAoB,GAAG,MAAM;IAuBxD,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CAM9B"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
1
|
import { RenderPipeline } from '@luma.gl/core';
|
|
3
2
|
export class PipelineFactory {
|
|
4
3
|
static getDefaultPipelineFactory(device) {
|
|
@@ -6,11 +5,11 @@ export class PipelineFactory {
|
|
|
6
5
|
return device._lumaData.defaultPipelineFactory;
|
|
7
6
|
}
|
|
8
7
|
constructor(device) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
this.device = void 0;
|
|
9
|
+
this._hashCounter = 0;
|
|
10
|
+
this._hashes = {};
|
|
11
|
+
this._useCounts = {};
|
|
12
|
+
this._pipelineCache = {};
|
|
14
13
|
this.device = device;
|
|
15
14
|
}
|
|
16
15
|
createRenderPipeline(options) {
|
|
@@ -69,10 +68,15 @@ export class PipelineFactory {
|
|
|
69
68
|
_hashRenderPipeline(props) {
|
|
70
69
|
const vsHash = this._getHash(props.vs);
|
|
71
70
|
const fsHash = props.fs ? this._getHash(props.fs) : 0;
|
|
72
|
-
const parameterHash = this._getHash(JSON.stringify(props.parameters));
|
|
73
|
-
const bufferLayoutHash = this._getHash(JSON.stringify(props.bufferLayout));
|
|
74
71
|
const varyingHash = '-';
|
|
75
|
-
|
|
72
|
+
switch (this.device.info.type) {
|
|
73
|
+
case 'webgpu':
|
|
74
|
+
const parameterHash = this._getHash(JSON.stringify(props.parameters));
|
|
75
|
+
const bufferLayoutHash = this._getHash(JSON.stringify(props.bufferLayout));
|
|
76
|
+
return `${vsHash}/${fsHash}V${varyingHash}T${props.topology}P${parameterHash}BL${bufferLayoutHash}}`;
|
|
77
|
+
default:
|
|
78
|
+
return `${vsHash}/${fsHash}V${varyingHash}`;
|
|
79
|
+
}
|
|
76
80
|
}
|
|
77
81
|
_getHash(key) {
|
|
78
82
|
if (this._hashes[key] === undefined) {
|
|
@@ -81,9 +85,9 @@ export class PipelineFactory {
|
|
|
81
85
|
return this._hashes[key];
|
|
82
86
|
}
|
|
83
87
|
}
|
|
84
|
-
|
|
88
|
+
PipelineFactory.defaultProps = {
|
|
85
89
|
...RenderPipeline.defaultProps,
|
|
86
90
|
vs: undefined,
|
|
87
91
|
fs: undefined
|
|
88
|
-
}
|
|
92
|
+
};
|
|
89
93
|
//# sourceMappingURL=pipeline-factory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline-factory.js","names":["RenderPipeline","PipelineFactory","getDefaultPipelineFactory","device","_lumaData","defaultPipelineFactory","constructor","
|
|
1
|
+
{"version":3,"file":"pipeline-factory.js","names":["RenderPipeline","PipelineFactory","getDefaultPipelineFactory","device","_lumaData","defaultPipelineFactory","constructor","_hashCounter","_hashes","_useCounts","_pipelineCache","createRenderPipeline","options","props","defaultProps","hash","_hashRenderPipeline","pipeline","vs","createShader","stage","source","fs","release","destroy","_createRenderPipeline","Error","vsHash","_getHash","fsHash","varyingHash","info","type","parameterHash","JSON","stringify","parameters","bufferLayoutHash","bufferLayout","topology","key","undefined"],"sources":["../../src/lib/pipeline-factory.ts"],"sourcesContent":["// luma.gl, MIT license\nimport type {RenderPipelineProps} from '@luma.gl/core';\nimport {Device, RenderPipeline} from '@luma.gl/core';\n\n/** Todo - should be same as RenderPipelineProps */\nexport type PipelineFactoryProps = Omit<RenderPipelineProps, 'vs' | 'fs'> & {\n // Only accepts string shaders\n vs: string;\n fs: string;\n};\n\n/** \n * Efficiently creates / caches pipelines\n */\nexport class PipelineFactory {\n static defaultProps: Required<PipelineFactoryProps> = {\n ...RenderPipeline.defaultProps,\n vs: undefined!,\n fs: undefined!\n }\n\n readonly device: Device;\n\n private _hashCounter: number = 0;\n private readonly _hashes: Record<string, number> = {};\n private readonly _useCounts: Record<string, number> = {};\n private readonly _pipelineCache: Record<string, RenderPipeline> = {};\n\n static getDefaultPipelineFactory(device: Device): PipelineFactory {\n device._lumaData.defaultPipelineFactory = device._lumaData.defaultPipelineFactory || new PipelineFactory(device);\n return device._lumaData.defaultPipelineFactory as PipelineFactory;\n }\n\n constructor(device: Device) {\n this.device = device;\n }\n\n createRenderPipeline(options: PipelineFactoryProps): RenderPipeline {\n const props: Required<PipelineFactoryProps> = {...PipelineFactory.defaultProps, ...options};\n\n const hash = this._hashRenderPipeline({...props});\n\n if (!this._pipelineCache[hash]) {\n const pipeline = this.device.createRenderPipeline({\n ...props,\n vs: this.device.createShader({stage: 'vertex', source: props.vs}),\n fs: props.fs ? this.device.createShader({stage: 'fragment', source: props.fs}) : null,\n });\n\n pipeline.hash = hash;\n this._pipelineCache[hash] = pipeline;\n this._useCounts[hash] = 0;\n }\n\n this._useCounts[hash]++;\n\n return this._pipelineCache[hash];\n }\n\n release(pipeline: RenderPipeline): void {\n const hash = pipeline.hash;\n this._useCounts[hash]--;\n if (this._useCounts[hash] === 0) {\n this._pipelineCache[hash].destroy();\n delete this._pipelineCache[hash];\n delete this._useCounts[hash];\n }\n }\n\n // PRIVATE\n\n _createRenderPipeline(props: PipelineFactoryProps): RenderPipeline {\n if (!props.fs) {\n throw new Error('fs');\n }\n\n const pipeline = this.device.createRenderPipeline({\n ...props,\n vs: this.device.createShader({stage: 'vertex', source: props.vs}),\n fs: props.fs ? this.device.createShader({stage: 'fragment', source: props.fs}) : null,\n });\n\n return pipeline;\n }\n\n /** Calculate a hash based on all the inputs for a render pipeline */\n _hashRenderPipeline(props: PipelineFactoryProps): string {\n const vsHash = this._getHash(props.vs);\n const fsHash = props.fs ? this._getHash(props.fs) : 0;\n\n // WebGL specific\n // const {varyings = [], bufferMode = {}} = props;\n // const varyingHashes = varyings.map((v) => this._getHash(v));\n const varyingHash = '-'; // `${varyingHashes.join('/')}B${bufferMode}`\n\n switch (this.device.info.type) {\n case 'webgpu':\n // On WebGPU we need to rebuild the pipeline if topology, parameters or bufferLayout change\n const parameterHash = this._getHash(JSON.stringify(props.parameters));\n const bufferLayoutHash = this._getHash(JSON.stringify(props.bufferLayout));\n // TODO - Can json.stringify() generate different strings for equivalent objects if order of params is different?\n // create a deepHash() to deduplicate?\n return `${vsHash}/${fsHash}V${varyingHash}T${props.topology}P${parameterHash}BL${bufferLayoutHash}}`;\n default:\n // WebGL is more dynamic\n return `${vsHash}/${fsHash}V${varyingHash}`;\n }\n }\n\n _getHash(key: string): number {\n if (this._hashes[key] === undefined) {\n this._hashes[key] = this._hashCounter++;\n }\n return this._hashes[key];\n }\n}\n\n"],"mappings":"AAEA,SAAgBA,cAAc,QAAO,eAAe;AAYpD,OAAO,MAAMC,eAAe,CAAC;EAc3B,OAAOC,yBAAyBA,CAACC,MAAc,EAAmB;IAChEA,MAAM,CAACC,SAAS,CAACC,sBAAsB,GAAGF,MAAM,CAACC,SAAS,CAACC,sBAAsB,IAAI,IAAIJ,eAAe,CAACE,MAAM,CAAC;IAChH,OAAOA,MAAM,CAACC,SAAS,CAACC,sBAAsB;EAChD;EAEAC,WAAWA,CAACH,MAAc,EAAE;IAAA,KAZnBA,MAAM;IAAA,KAEPI,YAAY,GAAW,CAAC;IAAA,KACfC,OAAO,GAA2B,CAAC,CAAC;IAAA,KACpCC,UAAU,GAA2B,CAAC,CAAC;IAAA,KACvCC,cAAc,GAAmC,CAAC,CAAC;IAQlE,IAAI,CAACP,MAAM,GAAGA,MAAM;EACtB;EAEAQ,oBAAoBA,CAACC,OAA6B,EAAkB;IAClE,MAAMC,KAAqC,GAAG;MAAC,GAAGZ,eAAe,CAACa,YAAY;MAAE,GAAGF;IAAO,CAAC;IAE3F,MAAMG,IAAI,GAAG,IAAI,CAACC,mBAAmB,CAAC;MAAC,GAAGH;IAAK,CAAC,CAAC;IAEjD,IAAI,CAAC,IAAI,CAACH,cAAc,CAACK,IAAI,CAAC,EAAE;MAC9B,MAAME,QAAQ,GAAG,IAAI,CAACd,MAAM,CAACQ,oBAAoB,CAAC;QAChD,GAAGE,KAAK;QACRK,EAAE,EAAE,IAAI,CAACf,MAAM,CAACgB,YAAY,CAAC;UAACC,KAAK,EAAE,QAAQ;UAAEC,MAAM,EAAER,KAAK,CAACK;QAAE,CAAC,CAAC;QACjEI,EAAE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,CAAC"}
|
package/dist/model/model.d.ts
CHANGED
|
@@ -82,9 +82,10 @@ export declare class Model {
|
|
|
82
82
|
draw(renderPass: RenderPass): void;
|
|
83
83
|
/**
|
|
84
84
|
* Updates the optional geometry
|
|
85
|
+
* Geometry, sets several attributes, indices, and also vertex count and topology
|
|
85
86
|
* @note Can trigger a pipeline rebuild / pipeline cache fetch on WebGPU
|
|
86
87
|
*/
|
|
87
|
-
setGeometry(geometry: GPUGeometry): void;
|
|
88
|
+
setGeometry(geometry: GPUGeometry | Geometry): void;
|
|
88
89
|
/**
|
|
89
90
|
* Updates the primitive topology ('triangle-list', 'triangle-strip' etc).
|
|
90
91
|
* @note Triggers a pipeline rebuild / pipeline cache fetch on WebGPU
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/model/model.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,UAAU,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AAC3G,OAAO,KAAK,EAAC,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAC,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAsB,MAAM,eAAe,CAAC;AAC9F,OAAO,KAAK,EAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/model/model.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,UAAU,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AAC3G,OAAO,KAAK,EAAC,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAC,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAsB,MAAM,eAAe,CAAC;AAC9F,OAAO,KAAK,EAAC,YAAY,EAAe,MAAM,sBA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
import { RenderPipeline, log, uid, deepEqual } from '@luma.gl/core';
|
|
3
2
|
import { ShaderAssembler } from '@luma.gl/shadertools';
|
|
4
3
|
import { makeGPUGeometry } from "../geometry/gpu-geometry.js";
|
|
5
4
|
import { PipelineFactory } from "../lib/pipeline-factory.js";
|
|
6
|
-
import { buildShaders } from "./model-shaders.js";
|
|
7
5
|
export class Model {
|
|
8
6
|
constructor(device, props) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
7
|
+
this.device = void 0;
|
|
8
|
+
this.id = void 0;
|
|
9
|
+
this.vs = void 0;
|
|
10
|
+
this.fs = void 0;
|
|
11
|
+
this.pipelineFactory = void 0;
|
|
12
|
+
this.userData = {};
|
|
13
|
+
this.parameters = void 0;
|
|
14
|
+
this.topology = void 0;
|
|
15
|
+
this.bufferLayout = void 0;
|
|
16
|
+
this.vertexCount = void 0;
|
|
17
|
+
this.instanceCount = 0;
|
|
18
|
+
this.indices = null;
|
|
19
|
+
this.bufferAttributes = {};
|
|
20
|
+
this.constantAttributes = {};
|
|
21
|
+
this.bindings = {};
|
|
22
|
+
this.uniforms = {};
|
|
23
|
+
this.pipeline = void 0;
|
|
24
|
+
this._pipelineNeedsUpdate = 'newly created';
|
|
25
|
+
this._getModuleUniforms = void 0;
|
|
26
|
+
this.props = void 0;
|
|
29
27
|
this.props = {
|
|
30
28
|
...Model.defaultProps,
|
|
31
29
|
...props
|
|
@@ -34,11 +32,17 @@ export class Model {
|
|
|
34
32
|
this.id = props.id || uid('model');
|
|
35
33
|
this.device = device;
|
|
36
34
|
Object.assign(this.userData, props.userData);
|
|
35
|
+
const platformInfo = {
|
|
36
|
+
type: device.info.type,
|
|
37
|
+
shaderLanguage: device.info.shadingLanguages[0],
|
|
38
|
+
gpu: device.info.gpu,
|
|
39
|
+
features: device.features
|
|
40
|
+
};
|
|
37
41
|
const {
|
|
38
42
|
vs,
|
|
39
43
|
fs,
|
|
40
44
|
getUniforms
|
|
41
|
-
} =
|
|
45
|
+
} = this.props.shaderAssembler.assembleShaders(platformInfo, this.props);
|
|
42
46
|
this.vs = vs;
|
|
43
47
|
this.fs = fs;
|
|
44
48
|
this._getModuleUniforms = getUniforms;
|
|
@@ -47,9 +51,8 @@ export class Model {
|
|
|
47
51
|
this.topology = this.props.topology;
|
|
48
52
|
this.bufferLayout = this.props.bufferLayout;
|
|
49
53
|
this.parameters = this.props.parameters;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.setGeometry(gpuGeometry);
|
|
54
|
+
if (props.geometry) {
|
|
55
|
+
this.setGeometry(props.geometry);
|
|
53
56
|
}
|
|
54
57
|
this.pipelineFactory = props.pipelineFactory || PipelineFactory.getDefaultPipelineFactory(this.device);
|
|
55
58
|
this.pipeline = this._updatePipeline();
|
|
@@ -94,34 +97,29 @@ export class Model {
|
|
|
94
97
|
});
|
|
95
98
|
}
|
|
96
99
|
setGeometry(geometry) {
|
|
97
|
-
this.
|
|
98
|
-
this.
|
|
99
|
-
this.
|
|
100
|
-
this.
|
|
101
|
-
this.
|
|
100
|
+
const gpuGeometry = geometry && makeGPUGeometry(this.device, geometry);
|
|
101
|
+
this.setTopology(gpuGeometry.topology || 'triangle-list');
|
|
102
|
+
this.bufferLayout = mergeBufferLayouts(this.bufferLayout, gpuGeometry.bufferLayout);
|
|
103
|
+
this.vertexCount = gpuGeometry.vertexCount;
|
|
104
|
+
this.setAttributes(gpuGeometry.attributes);
|
|
105
|
+
this.setIndexBuffer(gpuGeometry.indices);
|
|
102
106
|
}
|
|
103
107
|
setTopology(topology) {
|
|
104
108
|
if (topology !== this.topology) {
|
|
105
109
|
this.topology = topology;
|
|
106
|
-
|
|
107
|
-
this._setPipelineNeedsUpdate('topology');
|
|
108
|
-
}
|
|
110
|
+
this._setPipelineNeedsUpdate('topology');
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
113
|
setBufferLayout(bufferLayout) {
|
|
112
114
|
if (bufferLayout !== this.bufferLayout) {
|
|
113
115
|
this.bufferLayout = bufferLayout;
|
|
114
|
-
|
|
115
|
-
this._setPipelineNeedsUpdate('bufferLayout');
|
|
116
|
-
}
|
|
116
|
+
this._setPipelineNeedsUpdate('bufferLayout');
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
setParameters(parameters) {
|
|
120
120
|
if (!deepEqual(parameters, this.parameters, 2)) {
|
|
121
121
|
this.parameters = parameters;
|
|
122
|
-
|
|
123
|
-
this._setPipelineNeedsUpdate('parameters');
|
|
124
|
-
}
|
|
122
|
+
this._setPipelineNeedsUpdate('parameters');
|
|
125
123
|
}
|
|
126
124
|
}
|
|
127
125
|
setVertexCount(vertexCount) {
|
|
@@ -142,7 +140,7 @@ export class Model {
|
|
|
142
140
|
}
|
|
143
141
|
setAttributes(bufferAttributes) {
|
|
144
142
|
if (bufferAttributes.indices) {
|
|
145
|
-
log.warn(
|
|
143
|
+
log.warn(`Model:${this.id} setAttributes() - indices should be set using setIndexBuffer()`);
|
|
146
144
|
}
|
|
147
145
|
Object.assign(this.bufferAttributes, bufferAttributes);
|
|
148
146
|
}
|
|
@@ -161,7 +159,7 @@ export class Model {
|
|
|
161
159
|
}
|
|
162
160
|
_updatePipeline() {
|
|
163
161
|
if (this._pipelineNeedsUpdate) {
|
|
164
|
-
log.log(1,
|
|
162
|
+
log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
|
|
165
163
|
this._pipelineNeedsUpdate = false;
|
|
166
164
|
this.pipeline = this.device.createRenderPipeline({
|
|
167
165
|
...this.props,
|
|
@@ -181,7 +179,7 @@ export class Model {
|
|
|
181
179
|
return this.pipeline;
|
|
182
180
|
}
|
|
183
181
|
}
|
|
184
|
-
|
|
182
|
+
Model.defaultProps = {
|
|
185
183
|
...RenderPipeline.defaultProps,
|
|
186
184
|
vs: null,
|
|
187
185
|
fs: null,
|
|
@@ -194,7 +192,7 @@ _defineProperty(Model, "defaultProps", {
|
|
|
194
192
|
geometry: null,
|
|
195
193
|
pipelineFactory: undefined,
|
|
196
194
|
shaderAssembler: ShaderAssembler.getDefaultShaderAssembler()
|
|
197
|
-
}
|
|
195
|
+
};
|
|
198
196
|
function mergeBufferLayouts(layouts1, layouts2) {
|
|
199
197
|
const layouts = [...layouts1];
|
|
200
198
|
for (const attribute of layouts2) {
|