@deck.gl/extensions 9.0.0-alpha.4 → 9.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/dist/dist.dev.js +1056 -1059
- package/dist.min.js +108 -108
- package/package.json +4 -3
- package/typed/brushing/brushing-extension.d.ts +2 -2
- package/typed/brushing/shader-module.d.ts +1 -1
- package/typed/clip/clip-extension.d.ts +2 -2
- package/typed/collision-filter/collision-filter-effect.d.ts +1 -1
- package/typed/collision-filter/collision-filter-extension.d.ts +1 -1
- package/typed/collision-filter/collision-filter-pass.d.ts +1 -1
- package/typed/collision-filter/shader-module.d.ts +1 -1
- package/typed/data-filter/data-filter-extension.d.ts +2 -2
- package/typed/data-filter/shader-module.d.ts +1 -1
- package/typed/fill-style/fill-style-extension.d.ts +2 -2
- package/typed/fill-style/shaders.glsl.d.ts +1 -1
- package/typed/fp64/fp64-extension.d.ts +2 -2
- package/typed/fp64/project64.d.ts +1 -1
- package/typed/mask/mask-effect.d.ts +1 -1
- package/typed/mask/mask-extension.d.ts +1 -1
- package/typed/mask/mask-pass.d.ts +1 -1
- package/typed/mask/shader-module.d.ts +1 -1
- package/typed/path-style/path-style-extension.d.ts +2 -2
- package/typed/terrain/height-map-builder.d.ts +1 -1
- package/typed/terrain/shader-module.d.ts +1 -1
- package/typed/terrain/terrain-cover.d.ts +1 -1
- package/typed/terrain/terrain-effect.d.ts +1 -1
- package/typed/terrain/terrain-extension.d.ts +2 -2
- package/typed/terrain/terrain-pass.d.ts +1 -1
- package/typed/terrain/terrain-picking-pass.d.ts +1 -1
- package/typed/utils/projection-utils.d.ts +1 -1
- package/typed/package.json +0 -6
package/dist/dist.dev.js
CHANGED
|
@@ -7628,21 +7628,21 @@ varying float dataFilter_value;
|
|
|
7628
7628
|
getUniforms: getUniforms64
|
|
7629
7629
|
};
|
|
7630
7630
|
|
|
7631
|
-
//
|
|
7631
|
+
// ../../node_modules/@luma.gl/engine/dist/model/model.js
|
|
7632
7632
|
var import_core36 = __toESM(require_core2(), 1);
|
|
7633
7633
|
var import_core37 = __toESM(require_core2(), 1);
|
|
7634
7634
|
|
|
7635
|
-
//
|
|
7635
|
+
// ../../node_modules/@luma.gl/shadertools/dist/lib/glsl-utils/highlight.js
|
|
7636
7636
|
var glsl = (x) => `${x}`;
|
|
7637
7637
|
|
|
7638
|
-
//
|
|
7638
|
+
// ../../node_modules/@luma.gl/shadertools/dist/lib/utils/assert.js
|
|
7639
7639
|
function assert17(condition, message2) {
|
|
7640
7640
|
if (!condition) {
|
|
7641
7641
|
throw new Error(message2 || "shadertools: assertion failed.");
|
|
7642
7642
|
}
|
|
7643
7643
|
}
|
|
7644
7644
|
|
|
7645
|
-
//
|
|
7645
|
+
// ../../node_modules/@luma.gl/shadertools/dist/lib/filters/prop-types.js
|
|
7646
7646
|
var DEFAULT_PROP_VALIDATORS = {
|
|
7647
7647
|
number: {
|
|
7648
7648
|
type: "number",
|
|
@@ -7723,7 +7723,7 @@ varying float dataFilter_value;
|
|
|
7723
7723
|
return typeof value;
|
|
7724
7724
|
}
|
|
7725
7725
|
|
|
7726
|
-
//
|
|
7726
|
+
// ../../node_modules/@luma.gl/shadertools/dist/module-injectors.js
|
|
7727
7727
|
var MODULE_INJECTORS_VS = glsl`\
|
|
7728
7728
|
#ifdef MODULE_LOGDEPTH
|
|
7729
7729
|
logdepth_adjustPosition(gl_Position);
|
|
@@ -7752,7 +7752,7 @@ varying float dataFilter_value;
|
|
|
7752
7752
|
#endif
|
|
7753
7753
|
`;
|
|
7754
7754
|
|
|
7755
|
-
//
|
|
7755
|
+
// ../../node_modules/@luma.gl/shadertools/dist/lib/shader-assembly/shader-injections.js
|
|
7756
7756
|
var MODULE_INJECTORS = {
|
|
7757
7757
|
vertex: MODULE_INJECTORS_VS,
|
|
7758
7758
|
fragment: MODULE_INJECTORS_FS
|
|
@@ -7844,7 +7844,7 @@ varying float dataFilter_value;
|
|
|
7844
7844
|
return source;
|
|
7845
7845
|
}
|
|
7846
7846
|
|
|
7847
|
-
//
|
|
7847
|
+
// ../../node_modules/@luma.gl/shadertools/dist/lib/shader-module/shader-module-instance.js
|
|
7848
7848
|
var ShaderModuleInstance = class {
|
|
7849
7849
|
static instantiateModules(modules) {
|
|
7850
7850
|
return modules.map((module) => {
|
|
@@ -7874,7 +7874,7 @@ varying float dataFilter_value;
|
|
|
7874
7874
|
vs: vs5,
|
|
7875
7875
|
fs: fs4,
|
|
7876
7876
|
dependencies = [],
|
|
7877
|
-
|
|
7877
|
+
uniforms = {},
|
|
7878
7878
|
getUniforms: getUniforms4,
|
|
7879
7879
|
deprecations = [],
|
|
7880
7880
|
defines = {},
|
|
@@ -7889,8 +7889,8 @@ varying float dataFilter_value;
|
|
|
7889
7889
|
this.deprecations = this._parseDeprecationDefinitions(deprecations);
|
|
7890
7890
|
this.defines = defines;
|
|
7891
7891
|
this.injections = normalizeInjections(inject6);
|
|
7892
|
-
if (
|
|
7893
|
-
this.uniforms = makePropValidators(
|
|
7892
|
+
if (uniforms) {
|
|
7893
|
+
this.uniforms = makePropValidators(uniforms);
|
|
7894
7894
|
}
|
|
7895
7895
|
}
|
|
7896
7896
|
getModuleSource(stage) {
|
|
@@ -7962,7 +7962,7 @@ ${moduleSource}// END MODULE_${this.name}
|
|
|
7962
7962
|
}
|
|
7963
7963
|
};
|
|
7964
7964
|
|
|
7965
|
-
//
|
|
7965
|
+
// ../../node_modules/@luma.gl/shadertools/dist/lib/shader-assembly/resolve-modules.js
|
|
7966
7966
|
function resolveModules(modules) {
|
|
7967
7967
|
const instances = ShaderModuleInstance.instantiateModules(modules);
|
|
7968
7968
|
return getShaderDependencies(instances);
|
|
@@ -8006,7 +8006,7 @@ ${moduleSource}// END MODULE_${this.name}
|
|
|
8006
8006
|
}
|
|
8007
8007
|
}
|
|
8008
8008
|
|
|
8009
|
-
//
|
|
8009
|
+
// ../../node_modules/@luma.gl/shadertools/dist/lib/shader-assembly/platform-defines.js
|
|
8010
8010
|
function getPlatformShaderDefines(platformInfo) {
|
|
8011
8011
|
switch (platformInfo === null || platformInfo === void 0 ? void 0 : platformInfo.gpu.toLowerCase()) {
|
|
8012
8012
|
case "apple":
|
|
@@ -8106,7 +8106,7 @@ ${moduleSource}// END MODULE_${this.name}
|
|
|
8106
8106
|
return versionDefines;
|
|
8107
8107
|
}
|
|
8108
8108
|
|
|
8109
|
-
//
|
|
8109
|
+
// ../../node_modules/@luma.gl/shadertools/dist/lib/shader-transpiler/transpile-glsl-shader.js
|
|
8110
8110
|
function transpileGLSLShader(source, targetGLSLVersion, stage) {
|
|
8111
8111
|
switch (targetGLSLVersion) {
|
|
8112
8112
|
case 300:
|
|
@@ -8172,7 +8172,7 @@ ${match}`).replace(new RegExp(`\\b${ES100_FRAGMENT_OUTPUT_NAME}\\b`, "g"), outpu
|
|
|
8172
8172
|
return new RegExp(`\\b${qualifier}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`, "g");
|
|
8173
8173
|
}
|
|
8174
8174
|
|
|
8175
|
-
//
|
|
8175
|
+
// ../../node_modules/@luma.gl/shadertools/dist/lib/shader-assembly/shader-hooks.js
|
|
8176
8176
|
function getShaderHooks(hookFunctions, hookInjections) {
|
|
8177
8177
|
let result = "";
|
|
8178
8178
|
for (const hookName in hookFunctions) {
|
|
@@ -8232,7 +8232,7 @@ ${match}`).replace(new RegExp(`\\b${ES100_FRAGMENT_OUTPUT_NAME}\\b`, "g"), outpu
|
|
|
8232
8232
|
return result;
|
|
8233
8233
|
}
|
|
8234
8234
|
|
|
8235
|
-
//
|
|
8235
|
+
// ../../node_modules/@luma.gl/shadertools/dist/lib/shader-assembly/assemble-shaders.js
|
|
8236
8236
|
var INJECT_SHADER_DECLARATIONS = `
|
|
8237
8237
|
|
|
8238
8238
|
${DECLARATION_INJECT_MARKER}
|
|
@@ -8504,7 +8504,7 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
|
|
|
8504
8504
|
return sourceText;
|
|
8505
8505
|
}
|
|
8506
8506
|
|
|
8507
|
-
//
|
|
8507
|
+
// ../../node_modules/@luma.gl/shadertools/dist/lib/shader-assembly/select-shaders.js
|
|
8508
8508
|
function selectShaders(platformInfo, props) {
|
|
8509
8509
|
if (!props.vs) {
|
|
8510
8510
|
throw new Error("no vertex shader");
|
|
@@ -8538,7 +8538,7 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
|
|
|
8538
8538
|
}
|
|
8539
8539
|
}
|
|
8540
8540
|
|
|
8541
|
-
//
|
|
8541
|
+
// ../../node_modules/@luma.gl/shadertools/dist/lib/shader-assembler.js
|
|
8542
8542
|
var ShaderAssembler = class {
|
|
8543
8543
|
constructor() {
|
|
8544
8544
|
this._hookFunctions = [];
|
|
@@ -8601,1036 +8601,297 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
|
|
|
8601
8601
|
};
|
|
8602
8602
|
ShaderAssembler.defaultShaderAssembler = void 0;
|
|
8603
8603
|
|
|
8604
|
-
//
|
|
8605
|
-
|
|
8606
|
-
|
|
8607
|
-
|
|
8608
|
-
|
|
8609
|
-
|
|
8610
|
-
|
|
8611
|
-
|
|
8612
|
-
|
|
8613
|
-
this.indices = void 0;
|
|
8614
|
-
this.attributes = void 0;
|
|
8615
|
-
this.id = props.id || (0, import_core34.uid)("geometry");
|
|
8616
|
-
this.topology = props.topology;
|
|
8617
|
-
this.indices = props.indices || null;
|
|
8618
|
-
this.attributes = props.attributes;
|
|
8619
|
-
this.vertexCount = props.vertexCount;
|
|
8620
|
-
this.bufferLayout = props.bufferLayout || [];
|
|
8621
|
-
if (this.indices) {
|
|
8622
|
-
(0, import_core34.assert)(this.indices.usage === import_core34.Buffer.INDEX);
|
|
8623
|
-
}
|
|
8624
|
-
}
|
|
8625
|
-
destroy() {
|
|
8626
|
-
var _this$attributes$colo;
|
|
8627
|
-
this.indices.destroy();
|
|
8628
|
-
this.attributes.positions.destroy();
|
|
8629
|
-
this.attributes.normals.destroy();
|
|
8630
|
-
this.attributes.texCoords.destroy();
|
|
8631
|
-
(_this$attributes$colo = this.attributes.colors) === null || _this$attributes$colo === void 0 ? void 0 : _this$attributes$colo.destroy();
|
|
8632
|
-
}
|
|
8633
|
-
getVertexCount() {
|
|
8634
|
-
return this.vertexCount;
|
|
8635
|
-
}
|
|
8636
|
-
getAttributes() {
|
|
8637
|
-
return this.attributes;
|
|
8638
|
-
}
|
|
8639
|
-
getIndexes() {
|
|
8640
|
-
return this.indices;
|
|
8641
|
-
}
|
|
8642
|
-
_calculateVertexCount(positions) {
|
|
8643
|
-
const vertexCount = positions.byteLength / 12;
|
|
8644
|
-
return vertexCount;
|
|
8645
|
-
}
|
|
8646
|
-
};
|
|
8647
|
-
function makeGPUGeometry(device, geometry) {
|
|
8648
|
-
if (geometry instanceof GPUGeometry) {
|
|
8649
|
-
return geometry;
|
|
8650
|
-
}
|
|
8651
|
-
const indices = getIndexBufferFromGeometry(device, geometry);
|
|
8652
|
-
const {
|
|
8653
|
-
attributes,
|
|
8654
|
-
bufferLayout
|
|
8655
|
-
} = getAttributeBuffersFromGeometry(device, geometry);
|
|
8656
|
-
return new GPUGeometry({
|
|
8657
|
-
topology: geometry.topology || "triangle-list",
|
|
8658
|
-
bufferLayout,
|
|
8659
|
-
vertexCount: geometry.vertexCount,
|
|
8660
|
-
indices,
|
|
8661
|
-
attributes
|
|
8662
|
-
});
|
|
8604
|
+
// ../../node_modules/@luma.gl/shadertools/dist/modules-webgl1/math/fp64/fp64-utils.js
|
|
8605
|
+
function fp64ify(a) {
|
|
8606
|
+
let out = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
8607
|
+
let startIndex = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 0;
|
|
8608
|
+
const hiPart = Math.fround(a);
|
|
8609
|
+
const loPart = a - hiPart;
|
|
8610
|
+
out[startIndex] = hiPart;
|
|
8611
|
+
out[startIndex + 1] = loPart;
|
|
8612
|
+
return out;
|
|
8663
8613
|
}
|
|
8664
|
-
function
|
|
8665
|
-
|
|
8666
|
-
return void 0;
|
|
8667
|
-
}
|
|
8668
|
-
const data = geometry.indices.value;
|
|
8669
|
-
return device.createBuffer({
|
|
8670
|
-
usage: import_core34.Buffer.INDEX,
|
|
8671
|
-
data
|
|
8672
|
-
});
|
|
8614
|
+
function fp64LowPart(a) {
|
|
8615
|
+
return a - Math.fround(a);
|
|
8673
8616
|
}
|
|
8674
|
-
function
|
|
8675
|
-
const
|
|
8676
|
-
|
|
8677
|
-
|
|
8678
|
-
|
|
8679
|
-
|
|
8680
|
-
case "POSITION":
|
|
8681
|
-
name = "positions";
|
|
8682
|
-
break;
|
|
8683
|
-
case "NORMAL":
|
|
8684
|
-
name = "normals";
|
|
8685
|
-
break;
|
|
8686
|
-
case "TEXCOORD_0":
|
|
8687
|
-
name = "texCoords";
|
|
8688
|
-
break;
|
|
8617
|
+
function fp64ifyMatrix4(matrix) {
|
|
8618
|
+
const matrixFP64 = new Float32Array(32);
|
|
8619
|
+
for (let i = 0; i < 4; ++i) {
|
|
8620
|
+
for (let j = 0; j < 4; ++j) {
|
|
8621
|
+
const index = i * 4 + j;
|
|
8622
|
+
fp64ify(matrix[j * 4 + i], matrixFP64, index * 2);
|
|
8689
8623
|
}
|
|
8690
|
-
attributes[name] = device.createBuffer({
|
|
8691
|
-
data: attribute.value,
|
|
8692
|
-
id: `${attributeName}-buffer`
|
|
8693
|
-
});
|
|
8694
|
-
bufferLayout.push({
|
|
8695
|
-
name,
|
|
8696
|
-
format: `float32x${attribute.size}`
|
|
8697
|
-
});
|
|
8698
8624
|
}
|
|
8699
|
-
|
|
8700
|
-
return {
|
|
8701
|
-
attributes,
|
|
8702
|
-
bufferLayout,
|
|
8703
|
-
vertexCount
|
|
8704
|
-
};
|
|
8625
|
+
return matrixFP64;
|
|
8705
8626
|
}
|
|
8706
8627
|
|
|
8707
|
-
//
|
|
8708
|
-
var
|
|
8709
|
-
|
|
8710
|
-
static getDefaultPipelineFactory(device) {
|
|
8711
|
-
device._lumaData.defaultPipelineFactory = device._lumaData.defaultPipelineFactory || new PipelineFactory(device);
|
|
8712
|
-
return device._lumaData.defaultPipelineFactory;
|
|
8713
|
-
}
|
|
8714
|
-
constructor(device) {
|
|
8715
|
-
this.device = void 0;
|
|
8716
|
-
this._hashCounter = 0;
|
|
8717
|
-
this._hashes = {};
|
|
8718
|
-
this._useCounts = {};
|
|
8719
|
-
this._pipelineCache = {};
|
|
8720
|
-
this.device = device;
|
|
8721
|
-
}
|
|
8722
|
-
createRenderPipeline(options) {
|
|
8723
|
-
const props = {
|
|
8724
|
-
...PipelineFactory.defaultProps,
|
|
8725
|
-
...options
|
|
8726
|
-
};
|
|
8727
|
-
const hash = this._hashRenderPipeline({
|
|
8728
|
-
...props
|
|
8729
|
-
});
|
|
8730
|
-
if (!this._pipelineCache[hash]) {
|
|
8731
|
-
const pipeline = this.device.createRenderPipeline({
|
|
8732
|
-
...props,
|
|
8733
|
-
vs: this.device.createShader({
|
|
8734
|
-
stage: "vertex",
|
|
8735
|
-
source: props.vs
|
|
8736
|
-
}),
|
|
8737
|
-
fs: props.fs ? this.device.createShader({
|
|
8738
|
-
stage: "fragment",
|
|
8739
|
-
source: props.fs
|
|
8740
|
-
}) : null
|
|
8741
|
-
});
|
|
8742
|
-
pipeline.hash = hash;
|
|
8743
|
-
this._pipelineCache[hash] = pipeline;
|
|
8744
|
-
this._useCounts[hash] = 0;
|
|
8745
|
-
}
|
|
8746
|
-
this._useCounts[hash]++;
|
|
8747
|
-
return this._pipelineCache[hash];
|
|
8748
|
-
}
|
|
8749
|
-
release(pipeline) {
|
|
8750
|
-
const hash = pipeline.hash;
|
|
8751
|
-
this._useCounts[hash]--;
|
|
8752
|
-
if (this._useCounts[hash] === 0) {
|
|
8753
|
-
this._pipelineCache[hash].destroy();
|
|
8754
|
-
delete this._pipelineCache[hash];
|
|
8755
|
-
delete this._useCounts[hash];
|
|
8756
|
-
}
|
|
8757
|
-
}
|
|
8758
|
-
_createRenderPipeline(props) {
|
|
8759
|
-
if (!props.fs) {
|
|
8760
|
-
throw new Error("fs");
|
|
8761
|
-
}
|
|
8762
|
-
const pipeline = this.device.createRenderPipeline({
|
|
8763
|
-
...props,
|
|
8764
|
-
vs: this.device.createShader({
|
|
8765
|
-
stage: "vertex",
|
|
8766
|
-
source: props.vs
|
|
8767
|
-
}),
|
|
8768
|
-
fs: props.fs ? this.device.createShader({
|
|
8769
|
-
stage: "fragment",
|
|
8770
|
-
source: props.fs
|
|
8771
|
-
}) : null
|
|
8772
|
-
});
|
|
8773
|
-
return pipeline;
|
|
8774
|
-
}
|
|
8775
|
-
_hashRenderPipeline(props) {
|
|
8776
|
-
const vsHash = this._getHash(props.vs);
|
|
8777
|
-
const fsHash = props.fs ? this._getHash(props.fs) : 0;
|
|
8778
|
-
const varyingHash = "-";
|
|
8779
|
-
switch (this.device.info.type) {
|
|
8780
|
-
case "webgpu":
|
|
8781
|
-
const parameterHash = this._getHash(JSON.stringify(props.parameters));
|
|
8782
|
-
const bufferLayoutHash = this._getHash(JSON.stringify(props.bufferLayout));
|
|
8783
|
-
return `${vsHash}/${fsHash}V${varyingHash}T${props.topology}P${parameterHash}BL${bufferLayoutHash}}`;
|
|
8784
|
-
default:
|
|
8785
|
-
return `${vsHash}/${fsHash}V${varyingHash}`;
|
|
8786
|
-
}
|
|
8787
|
-
}
|
|
8788
|
-
_getHash(key) {
|
|
8789
|
-
if (this._hashes[key] === void 0) {
|
|
8790
|
-
this._hashes[key] = this._hashCounter++;
|
|
8791
|
-
}
|
|
8792
|
-
return this._hashes[key];
|
|
8793
|
-
}
|
|
8794
|
-
};
|
|
8795
|
-
PipelineFactory.defaultProps = {
|
|
8796
|
-
...import_core35.RenderPipeline.defaultProps,
|
|
8797
|
-
vs: void 0,
|
|
8798
|
-
fs: void 0
|
|
8799
|
-
};
|
|
8628
|
+
// ../../node_modules/@luma.gl/shadertools/dist/modules-webgl1/math/fp64/fp64-arithmetic.glsl.js
|
|
8629
|
+
var fp64arithmeticShader = glsl`\
|
|
8630
|
+
uniform float ONE;
|
|
8800
8631
|
|
|
8801
|
-
|
|
8802
|
-
|
|
8803
|
-
constructor(device, props) {
|
|
8804
|
-
this.device = void 0;
|
|
8805
|
-
this.id = void 0;
|
|
8806
|
-
this.vs = void 0;
|
|
8807
|
-
this.fs = void 0;
|
|
8808
|
-
this.pipelineFactory = void 0;
|
|
8809
|
-
this.userData = {};
|
|
8810
|
-
this.parameters = void 0;
|
|
8811
|
-
this.topology = void 0;
|
|
8812
|
-
this.bufferLayout = void 0;
|
|
8813
|
-
this.vertexCount = void 0;
|
|
8814
|
-
this.instanceCount = 0;
|
|
8815
|
-
this.indexBuffer = null;
|
|
8816
|
-
this.bufferAttributes = {};
|
|
8817
|
-
this.constantAttributes = {};
|
|
8818
|
-
this.bindings = {};
|
|
8819
|
-
this.uniforms = {};
|
|
8820
|
-
this.pipeline = void 0;
|
|
8821
|
-
this.vertexArray = void 0;
|
|
8822
|
-
this._pipelineNeedsUpdate = "newly created";
|
|
8823
|
-
this._attributeInfos = {};
|
|
8824
|
-
this._gpuGeometry = null;
|
|
8825
|
-
this._getModuleUniforms = void 0;
|
|
8826
|
-
this.props = void 0;
|
|
8827
|
-
this.props = {
|
|
8828
|
-
...Model.defaultProps,
|
|
8829
|
-
...props
|
|
8830
|
-
};
|
|
8831
|
-
props = this.props;
|
|
8832
|
-
this.id = props.id || (0, import_core36.uid)("model");
|
|
8833
|
-
this.device = device;
|
|
8834
|
-
Object.assign(this.userData, props.userData);
|
|
8835
|
-
const platformInfo = {
|
|
8836
|
-
type: device.info.type,
|
|
8837
|
-
shaderLanguage: device.info.shadingLanguages[0],
|
|
8838
|
-
gpu: device.info.gpu,
|
|
8839
|
-
features: device.features
|
|
8840
|
-
};
|
|
8841
|
-
const {
|
|
8842
|
-
vs: vs5,
|
|
8843
|
-
fs: fs4,
|
|
8844
|
-
getUniforms: getUniforms4
|
|
8845
|
-
} = this.props.shaderAssembler.assembleShaders(platformInfo, this.props);
|
|
8846
|
-
this.vs = vs5;
|
|
8847
|
-
this.fs = fs4;
|
|
8848
|
-
this._getModuleUniforms = getUniforms4;
|
|
8849
|
-
this.vertexCount = this.props.vertexCount;
|
|
8850
|
-
this.instanceCount = this.props.instanceCount;
|
|
8851
|
-
this.topology = this.props.topology;
|
|
8852
|
-
this.bufferLayout = this.props.bufferLayout;
|
|
8853
|
-
this.parameters = this.props.parameters;
|
|
8854
|
-
if (props.geometry) {
|
|
8855
|
-
this._gpuGeometry = this.setGeometry(props.geometry);
|
|
8856
|
-
}
|
|
8857
|
-
this.pipelineFactory = props.pipelineFactory || PipelineFactory.getDefaultPipelineFactory(this.device);
|
|
8858
|
-
this.pipeline = this._updatePipeline();
|
|
8859
|
-
this.vertexArray = device.createVertexArray({
|
|
8860
|
-
renderPipeline: this.pipeline
|
|
8861
|
-
});
|
|
8862
|
-
if (this._gpuGeometry) {
|
|
8863
|
-
this._setGeometryAttributes(this._gpuGeometry);
|
|
8864
|
-
}
|
|
8865
|
-
if (props.vertexCount) {
|
|
8866
|
-
this.setVertexCount(props.vertexCount);
|
|
8867
|
-
}
|
|
8868
|
-
if (props.instanceCount) {
|
|
8869
|
-
this.setInstanceCount(props.instanceCount);
|
|
8870
|
-
}
|
|
8871
|
-
if (props.indices) {
|
|
8872
|
-
throw new Error("Model.props.indices removed. Use props.indexBuffer");
|
|
8873
|
-
}
|
|
8874
|
-
if (props.indexBuffer) {
|
|
8875
|
-
this.setIndexBuffer(props.indexBuffer);
|
|
8876
|
-
}
|
|
8877
|
-
if (props.attributes) {
|
|
8878
|
-
this.setAttributes(props.attributes);
|
|
8879
|
-
}
|
|
8880
|
-
if (props.constantAttributes) {
|
|
8881
|
-
this.setConstantAttributes(props.constantAttributes);
|
|
8882
|
-
}
|
|
8883
|
-
if (props.bindings) {
|
|
8884
|
-
this.setBindings(props.bindings);
|
|
8885
|
-
}
|
|
8886
|
-
if (props.uniforms) {
|
|
8887
|
-
this.setUniforms(props.uniforms);
|
|
8888
|
-
}
|
|
8889
|
-
if (props.moduleSettings) {
|
|
8890
|
-
this.updateModuleSettings(props.moduleSettings);
|
|
8891
|
-
}
|
|
8892
|
-
this.setUniforms(this._getModuleUniforms());
|
|
8893
|
-
Object.seal(this);
|
|
8894
|
-
}
|
|
8895
|
-
destroy() {
|
|
8896
|
-
this.pipelineFactory.release(this.pipeline);
|
|
8897
|
-
}
|
|
8898
|
-
draw(renderPass) {
|
|
8899
|
-
this.pipeline = this._updatePipeline();
|
|
8900
|
-
this.pipeline.setBindings(this.bindings);
|
|
8901
|
-
this.pipeline.setUniforms(this.uniforms);
|
|
8902
|
-
this.pipeline.draw({
|
|
8903
|
-
renderPass,
|
|
8904
|
-
vertexArray: this.vertexArray,
|
|
8905
|
-
vertexCount: this.vertexCount,
|
|
8906
|
-
instanceCount: this.instanceCount
|
|
8907
|
-
});
|
|
8908
|
-
}
|
|
8909
|
-
setGeometry(geometry) {
|
|
8910
|
-
const gpuGeometry = geometry && makeGPUGeometry(this.device, geometry);
|
|
8911
|
-
this.setTopology(gpuGeometry.topology || "triangle-list");
|
|
8912
|
-
this.bufferLayout = mergeBufferLayouts(this.bufferLayout, gpuGeometry.bufferLayout);
|
|
8913
|
-
if (this.vertexArray) {
|
|
8914
|
-
this._setGeometryAttributes(gpuGeometry);
|
|
8915
|
-
}
|
|
8916
|
-
return gpuGeometry;
|
|
8917
|
-
}
|
|
8918
|
-
_setGeometryAttributes(gpuGeometry) {
|
|
8919
|
-
this.vertexCount = gpuGeometry.vertexCount;
|
|
8920
|
-
this.setAttributes(gpuGeometry.attributes);
|
|
8921
|
-
this.setIndexBuffer(gpuGeometry.indices);
|
|
8922
|
-
}
|
|
8923
|
-
setTopology(topology) {
|
|
8924
|
-
if (topology !== this.topology) {
|
|
8925
|
-
this.topology = topology;
|
|
8926
|
-
this._setPipelineNeedsUpdate("topology");
|
|
8927
|
-
}
|
|
8928
|
-
}
|
|
8929
|
-
setBufferLayout(bufferLayout) {
|
|
8930
|
-
this.bufferLayout = this._gpuGeometry ? mergeBufferLayouts(bufferLayout, this._gpuGeometry.bufferLayout) : bufferLayout;
|
|
8931
|
-
this._setPipelineNeedsUpdate("bufferLayout");
|
|
8932
|
-
this.pipeline = this._updatePipeline();
|
|
8933
|
-
this.vertexArray = this.device.createVertexArray({
|
|
8934
|
-
renderPipeline: this.pipeline
|
|
8935
|
-
});
|
|
8936
|
-
if (this._gpuGeometry) {
|
|
8937
|
-
this._setGeometryAttributes(this._gpuGeometry);
|
|
8938
|
-
}
|
|
8939
|
-
}
|
|
8940
|
-
setParameters(parameters2) {
|
|
8941
|
-
if (!(0, import_core36.deepEqual)(parameters2, this.parameters, 2)) {
|
|
8942
|
-
this.parameters = parameters2;
|
|
8943
|
-
this._setPipelineNeedsUpdate("parameters");
|
|
8944
|
-
}
|
|
8945
|
-
}
|
|
8946
|
-
setVertexCount(vertexCount) {
|
|
8947
|
-
this.vertexCount = vertexCount;
|
|
8948
|
-
}
|
|
8949
|
-
setInstanceCount(instanceCount) {
|
|
8950
|
-
this.instanceCount = instanceCount;
|
|
8951
|
-
}
|
|
8952
|
-
setShaderModuleProps(props) {
|
|
8953
|
-
const uniforms = this._getModuleUniforms(props);
|
|
8954
|
-
const keys = Object.keys(uniforms).filter((k) => {
|
|
8955
|
-
const uniform = uniforms[k];
|
|
8956
|
-
return !(0, import_core36.isNumberArray)(uniform) && typeof uniform !== "number" && typeof uniform !== "boolean";
|
|
8957
|
-
});
|
|
8958
|
-
const bindings = {};
|
|
8959
|
-
for (const k of keys) {
|
|
8960
|
-
bindings[k] = uniforms[k];
|
|
8961
|
-
delete uniforms[k];
|
|
8962
|
-
}
|
|
8963
|
-
Object.assign(this.uniforms, uniforms);
|
|
8964
|
-
Object.assign(this.bindings, bindings);
|
|
8965
|
-
}
|
|
8966
|
-
updateModuleSettings(props) {
|
|
8967
|
-
this.setShaderModuleProps(props);
|
|
8968
|
-
}
|
|
8969
|
-
setBindings(bindings) {
|
|
8970
|
-
Object.assign(this.bindings, bindings);
|
|
8971
|
-
}
|
|
8972
|
-
setUniforms(uniforms) {
|
|
8973
|
-
this.pipeline.setUniforms(uniforms);
|
|
8974
|
-
Object.assign(this.uniforms, uniforms);
|
|
8975
|
-
}
|
|
8976
|
-
setIndexBuffer(indexBuffer) {
|
|
8977
|
-
this.vertexArray.setIndexBuffer(indexBuffer);
|
|
8978
|
-
}
|
|
8979
|
-
setAttributes(buffers) {
|
|
8980
|
-
if (buffers.indices) {
|
|
8981
|
-
import_core36.log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`);
|
|
8982
|
-
}
|
|
8983
|
-
for (const [bufferName, buffer] of Object.entries(buffers)) {
|
|
8984
|
-
var _bufferLayout$attribu;
|
|
8985
|
-
const bufferLayout = this.bufferLayout.find((layout) => layout.name === bufferName);
|
|
8986
|
-
if (!bufferLayout) {
|
|
8987
|
-
continue;
|
|
8988
|
-
}
|
|
8989
|
-
const attributeNames = bufferLayout.attributes ? (_bufferLayout$attribu = bufferLayout.attributes) === null || _bufferLayout$attribu === void 0 ? void 0 : _bufferLayout$attribu.map((layout) => layout.attribute) : [bufferLayout.name];
|
|
8990
|
-
let set2 = false;
|
|
8991
|
-
for (const attributeName of attributeNames) {
|
|
8992
|
-
const attributeInfo = this._attributeInfos[attributeName];
|
|
8993
|
-
if (attributeInfo) {
|
|
8994
|
-
this.vertexArray.setBuffer(attributeInfo.location, buffer);
|
|
8995
|
-
set2 = true;
|
|
8996
|
-
}
|
|
8997
|
-
}
|
|
8998
|
-
if (!set2) {
|
|
8999
|
-
import_core36.log.warn(`Model(${this.id}): Ignoring buffer "${buffer.id}" for unknown attribute "${bufferName}"`)();
|
|
9000
|
-
}
|
|
9001
|
-
}
|
|
9002
|
-
}
|
|
9003
|
-
setConstantAttributes(attributes) {
|
|
9004
|
-
for (const [attributeName, value] of Object.entries(attributes)) {
|
|
9005
|
-
const attributeInfo = this._attributeInfos[attributeName];
|
|
9006
|
-
if (attributeInfo) {
|
|
9007
|
-
this.vertexArray.setConstant(attributeInfo.location, value);
|
|
9008
|
-
} else {
|
|
9009
|
-
import_core36.log.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${attributeName}"`)();
|
|
9010
|
-
}
|
|
9011
|
-
}
|
|
9012
|
-
}
|
|
9013
|
-
_setPipelineNeedsUpdate(reason) {
|
|
9014
|
-
this._pipelineNeedsUpdate = this._pipelineNeedsUpdate || reason;
|
|
9015
|
-
}
|
|
9016
|
-
_updatePipeline() {
|
|
9017
|
-
if (this._pipelineNeedsUpdate) {
|
|
9018
|
-
if (this.pipeline) {
|
|
9019
|
-
import_core36.log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
|
|
9020
|
-
}
|
|
9021
|
-
this._pipelineNeedsUpdate = false;
|
|
9022
|
-
this.pipeline = this.device.createRenderPipeline({
|
|
9023
|
-
...this.props,
|
|
9024
|
-
bufferLayout: this.bufferLayout,
|
|
9025
|
-
topology: this.topology,
|
|
9026
|
-
parameters: this.parameters,
|
|
9027
|
-
vs: this.device.createShader({
|
|
9028
|
-
id: "{$this.id}-vertex",
|
|
9029
|
-
stage: "vertex",
|
|
9030
|
-
source: this.vs
|
|
9031
|
-
}),
|
|
9032
|
-
fs: this.fs ? this.device.createShader({
|
|
9033
|
-
id: "{$this.id}-fragment",
|
|
9034
|
-
stage: "fragment",
|
|
9035
|
-
source: this.fs
|
|
9036
|
-
}) : null
|
|
9037
|
-
});
|
|
9038
|
-
this._attributeInfos = (0, import_core37.getAttributeInfosFromLayouts)(this.pipeline.shaderLayout, this.bufferLayout);
|
|
9039
|
-
}
|
|
9040
|
-
return this.pipeline;
|
|
9041
|
-
}
|
|
9042
|
-
};
|
|
9043
|
-
Model.defaultProps = {
|
|
9044
|
-
...import_core36.RenderPipeline.defaultProps,
|
|
9045
|
-
vs: null,
|
|
9046
|
-
fs: null,
|
|
9047
|
-
id: "unnamed",
|
|
9048
|
-
handle: void 0,
|
|
9049
|
-
userData: {},
|
|
9050
|
-
defines: {},
|
|
9051
|
-
modules: [],
|
|
9052
|
-
moduleSettings: {},
|
|
9053
|
-
geometry: null,
|
|
9054
|
-
indexBuffer: null,
|
|
9055
|
-
attributes: {},
|
|
9056
|
-
constantAttributes: {},
|
|
9057
|
-
pipelineFactory: void 0,
|
|
9058
|
-
shaderAssembler: ShaderAssembler.getDefaultShaderAssembler()
|
|
9059
|
-
};
|
|
9060
|
-
function mergeBufferLayouts(layouts1, layouts2) {
|
|
9061
|
-
const layouts = [...layouts1];
|
|
9062
|
-
for (const attribute of layouts2) {
|
|
9063
|
-
const index = layouts.findIndex((attribute2) => attribute2.name === attribute.name);
|
|
9064
|
-
if (index < 0) {
|
|
9065
|
-
layouts.push(attribute);
|
|
9066
|
-
} else {
|
|
9067
|
-
layouts[index] = attribute;
|
|
9068
|
-
}
|
|
9069
|
-
}
|
|
9070
|
-
return layouts;
|
|
9071
|
-
}
|
|
8632
|
+
/*
|
|
8633
|
+
About LUMA_FP64_CODE_ELIMINATION_WORKAROUND
|
|
9072
8634
|
|
|
9073
|
-
|
|
9074
|
-
|
|
8635
|
+
The purpose of this workaround is to prevent shader compilers from
|
|
8636
|
+
optimizing away necessary arithmetic operations by swapping their sequences
|
|
8637
|
+
or transform the equation to some 'equivalent' from.
|
|
9075
8638
|
|
|
9076
|
-
|
|
9077
|
-
|
|
9078
|
-
|
|
8639
|
+
The method is to multiply an artifical variable, ONE, which will be known to
|
|
8640
|
+
the compiler to be 1 only at runtime. The whole expression is then represented
|
|
8641
|
+
as a polynomial with respective to ONE. In the coefficients of all terms, only one a
|
|
8642
|
+
and one b should appear
|
|
8643
|
+
|
|
8644
|
+
err = (a + b) * ONE^6 - a * ONE^5 - (a + b) * ONE^4 + a * ONE^3 - b - (a + b) * ONE^2 + a * ONE
|
|
8645
|
+
*/
|
|
8646
|
+
|
|
8647
|
+
// Divide float number to high and low floats to extend fraction bits
|
|
8648
|
+
vec2 split(float a) {
|
|
8649
|
+
const float SPLIT = 4097.0;
|
|
8650
|
+
float t = a * SPLIT;
|
|
8651
|
+
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
8652
|
+
float a_hi = t * ONE - (t - a);
|
|
8653
|
+
float a_lo = a * ONE - a_hi;
|
|
9079
8654
|
#else
|
|
9080
|
-
|
|
9081
|
-
|
|
8655
|
+
float a_hi = t - (t - a);
|
|
8656
|
+
float a_lo = a - a_hi;
|
|
9082
8657
|
#endif
|
|
8658
|
+
return vec2(a_hi, a_lo);
|
|
8659
|
+
}
|
|
9083
8660
|
|
|
9084
|
-
|
|
9085
|
-
|
|
8661
|
+
// Divide float number again when high float uses too many fraction bits
|
|
8662
|
+
vec2 split2(vec2 a) {
|
|
8663
|
+
vec2 b = split(a.x);
|
|
8664
|
+
b.y += a.y;
|
|
8665
|
+
return b;
|
|
8666
|
+
}
|
|
9086
8667
|
|
|
9087
|
-
|
|
9088
|
-
|
|
9089
|
-
|
|
9090
|
-
|
|
9091
|
-
|
|
9092
|
-
|
|
9093
|
-
|
|
9094
|
-
|
|
9095
|
-
|
|
9096
|
-
|
|
9097
|
-
float channel = floor(row);
|
|
9098
|
-
row = fract(row);
|
|
9099
|
-
vColor = component * vec4(bvec4(channel == 0.0, channel == 1.0, channel == 2.0, channel == 3.0));
|
|
9100
|
-
gl_Position = vec4(col * 2.0 - 1.0, row * 2.0 - 1.0, 0.0, 1.0);
|
|
9101
|
-
#endif
|
|
9102
|
-
gl_PointSize = 1.0;
|
|
8668
|
+
// Special sum operation when a > b
|
|
8669
|
+
vec2 quickTwoSum(float a, float b) {
|
|
8670
|
+
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
8671
|
+
float sum = (a + b) * ONE;
|
|
8672
|
+
float err = b - (sum - a) * ONE;
|
|
8673
|
+
#else
|
|
8674
|
+
float sum = a + b;
|
|
8675
|
+
float err = b - (sum - a);
|
|
8676
|
+
#endif
|
|
8677
|
+
return vec2(sum, err);
|
|
9103
8678
|
}
|
|
9104
|
-
`;
|
|
9105
|
-
var AGGREGATE_FS = `#define SHADER_NAME data-filter-fragment-shader
|
|
9106
|
-
precision highp float;
|
|
9107
8679
|
|
|
9108
|
-
|
|
8680
|
+
// General sum operation
|
|
8681
|
+
vec2 twoSum(float a, float b) {
|
|
8682
|
+
float s = (a + b);
|
|
8683
|
+
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
8684
|
+
float v = (s * ONE - a) * ONE;
|
|
8685
|
+
float err = (a - (s - v) * ONE) * ONE * ONE * ONE + (b - v);
|
|
8686
|
+
#else
|
|
8687
|
+
float v = s - a;
|
|
8688
|
+
float err = (a - (s - v)) + (b - v);
|
|
8689
|
+
#endif
|
|
8690
|
+
return vec2(s, err);
|
|
8691
|
+
}
|
|
9109
8692
|
|
|
9110
|
-
|
|
9111
|
-
|
|
9112
|
-
|
|
9113
|
-
|
|
9114
|
-
|
|
8693
|
+
vec2 twoSub(float a, float b) {
|
|
8694
|
+
float s = (a - b);
|
|
8695
|
+
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
8696
|
+
float v = (s * ONE - a) * ONE;
|
|
8697
|
+
float err = (a - (s - v) * ONE) * ONE * ONE * ONE - (b + v);
|
|
8698
|
+
#else
|
|
8699
|
+
float v = s - a;
|
|
8700
|
+
float err = (a - (s - v)) - (b + v);
|
|
8701
|
+
#endif
|
|
8702
|
+
return vec2(s, err);
|
|
8703
|
+
}
|
|
8704
|
+
|
|
8705
|
+
vec2 twoSqr(float a) {
|
|
8706
|
+
float prod = a * a;
|
|
8707
|
+
vec2 a_fp64 = split(a);
|
|
8708
|
+
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
8709
|
+
float err = ((a_fp64.x * a_fp64.x - prod) * ONE + 2.0 * a_fp64.x *
|
|
8710
|
+
a_fp64.y * ONE * ONE) + a_fp64.y * a_fp64.y * ONE * ONE * ONE;
|
|
8711
|
+
#else
|
|
8712
|
+
float err = ((a_fp64.x * a_fp64.x - prod) + 2.0 * a_fp64.x * a_fp64.y) + a_fp64.y * a_fp64.y;
|
|
8713
|
+
#endif
|
|
8714
|
+
return vec2(prod, err);
|
|
8715
|
+
}
|
|
8716
|
+
|
|
8717
|
+
vec2 twoProd(float a, float b) {
|
|
8718
|
+
float prod = a * b;
|
|
8719
|
+
vec2 a_fp64 = split(a);
|
|
8720
|
+
vec2 b_fp64 = split(b);
|
|
8721
|
+
float err = ((a_fp64.x * b_fp64.x - prod) + a_fp64.x * b_fp64.y +
|
|
8722
|
+
a_fp64.y * b_fp64.x) + a_fp64.y * b_fp64.y;
|
|
8723
|
+
return vec2(prod, err);
|
|
8724
|
+
}
|
|
8725
|
+
|
|
8726
|
+
vec2 sum_fp64(vec2 a, vec2 b) {
|
|
8727
|
+
vec2 s, t;
|
|
8728
|
+
s = twoSum(a.x, b.x);
|
|
8729
|
+
t = twoSum(a.y, b.y);
|
|
8730
|
+
s.y += t.x;
|
|
8731
|
+
s = quickTwoSum(s.x, s.y);
|
|
8732
|
+
s.y += t.y;
|
|
8733
|
+
s = quickTwoSum(s.x, s.y);
|
|
8734
|
+
return s;
|
|
8735
|
+
}
|
|
8736
|
+
|
|
8737
|
+
vec2 sub_fp64(vec2 a, vec2 b) {
|
|
8738
|
+
vec2 s, t;
|
|
8739
|
+
s = twoSub(a.x, b.x);
|
|
8740
|
+
t = twoSub(a.y, b.y);
|
|
8741
|
+
s.y += t.x;
|
|
8742
|
+
s = quickTwoSum(s.x, s.y);
|
|
8743
|
+
s.y += t.y;
|
|
8744
|
+
s = quickTwoSum(s.x, s.y);
|
|
8745
|
+
return s;
|
|
8746
|
+
}
|
|
8747
|
+
|
|
8748
|
+
vec2 mul_fp64(vec2 a, vec2 b) {
|
|
8749
|
+
vec2 prod = twoProd(a.x, b.x);
|
|
8750
|
+
// y component is for the error
|
|
8751
|
+
prod.y += a.x * b.y;
|
|
8752
|
+
#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)
|
|
8753
|
+
prod = split2(prod);
|
|
8754
|
+
#endif
|
|
8755
|
+
prod = quickTwoSum(prod.x, prod.y);
|
|
8756
|
+
prod.y += a.y * b.x;
|
|
8757
|
+
#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)
|
|
8758
|
+
prod = split2(prod);
|
|
8759
|
+
#endif
|
|
8760
|
+
prod = quickTwoSum(prod.x, prod.y);
|
|
8761
|
+
return prod;
|
|
8762
|
+
}
|
|
8763
|
+
|
|
8764
|
+
vec2 div_fp64(vec2 a, vec2 b) {
|
|
8765
|
+
float xn = 1.0 / b.x;
|
|
8766
|
+
#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)
|
|
8767
|
+
vec2 yn = mul_fp64(a, vec2(xn, 0));
|
|
8768
|
+
#else
|
|
8769
|
+
vec2 yn = a * xn;
|
|
8770
|
+
#endif
|
|
8771
|
+
float diff = (sub_fp64(a, mul_fp64(b, yn))).x;
|
|
8772
|
+
vec2 prod = twoProd(xn, diff);
|
|
8773
|
+
return sum_fp64(yn, prod);
|
|
8774
|
+
}
|
|
8775
|
+
|
|
8776
|
+
vec2 sqrt_fp64(vec2 a) {
|
|
8777
|
+
if (a.x == 0.0 && a.y == 0.0) return vec2(0.0, 0.0);
|
|
8778
|
+
if (a.x < 0.0) return vec2(0.0 / 0.0, 0.0 / 0.0);
|
|
8779
|
+
|
|
8780
|
+
float x = 1.0 / sqrt(a.x);
|
|
8781
|
+
float yn = a.x * x;
|
|
8782
|
+
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
8783
|
+
vec2 yn_sqr = twoSqr(yn) * ONE;
|
|
8784
|
+
#else
|
|
8785
|
+
vec2 yn_sqr = twoSqr(yn);
|
|
8786
|
+
#endif
|
|
8787
|
+
float diff = sub_fp64(a, yn_sqr).x;
|
|
8788
|
+
vec2 prod = twoProd(x * 0.5, diff);
|
|
8789
|
+
#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)
|
|
8790
|
+
return sum_fp64(split(yn), prod);
|
|
8791
|
+
#else
|
|
8792
|
+
return sum_fp64(vec2(yn, 0.0), prod);
|
|
8793
|
+
#endif
|
|
9115
8794
|
}
|
|
9116
8795
|
`;
|
|
9117
|
-
|
|
9118
|
-
|
|
9119
|
-
|
|
9120
|
-
|
|
9121
|
-
|
|
9122
|
-
|
|
9123
|
-
|
|
9124
|
-
|
|
9125
|
-
|
|
9126
|
-
|
|
9127
|
-
|
|
9128
|
-
|
|
9129
|
-
|
|
9130
|
-
|
|
9131
|
-
|
|
9132
|
-
|
|
9133
|
-
|
|
9134
|
-
|
|
9135
|
-
|
|
9136
|
-
|
|
9137
|
-
|
|
9138
|
-
|
|
9139
|
-
|
|
9140
|
-
|
|
9141
|
-
|
|
9142
|
-
|
|
9143
|
-
|
|
9144
|
-
|
|
9145
|
-
|
|
9146
|
-
|
|
8796
|
+
|
|
8797
|
+
// ../../node_modules/@luma.gl/shadertools/dist/modules-webgl1/math/fp64/fp64-functions.glsl.js
|
|
8798
|
+
var fp64functionShader = glsl`\
|
|
8799
|
+
const vec2 E_FP64 = vec2(2.7182817459106445e+00, 8.254840366817007e-08);
|
|
8800
|
+
const vec2 LOG2_FP64 = vec2(0.6931471824645996e+00, -1.9046542121259336e-09);
|
|
8801
|
+
const vec2 PI_FP64 = vec2(3.1415927410125732, -8.742278012618954e-8);
|
|
8802
|
+
const vec2 TWO_PI_FP64 = vec2(6.2831854820251465, -1.7484556025237907e-7);
|
|
8803
|
+
const vec2 PI_2_FP64 = vec2(1.5707963705062866, -4.371139006309477e-8);
|
|
8804
|
+
const vec2 PI_4_FP64 = vec2(0.7853981852531433, -2.1855695031547384e-8);
|
|
8805
|
+
const vec2 PI_16_FP64 = vec2(0.19634954631328583, -5.463923757886846e-9);
|
|
8806
|
+
const vec2 PI_16_2_FP64 = vec2(0.39269909262657166, -1.0927847515773692e-8);
|
|
8807
|
+
const vec2 PI_16_3_FP64 = vec2(0.5890486240386963, -1.4906100798128818e-9);
|
|
8808
|
+
const vec2 PI_180_FP64 = vec2(0.01745329238474369, 1.3519960498364902e-10);
|
|
8809
|
+
|
|
8810
|
+
const vec2 SIN_TABLE_0_FP64 = vec2(0.19509032368659973, -1.6704714833615242e-9);
|
|
8811
|
+
const vec2 SIN_TABLE_1_FP64 = vec2(0.3826834261417389, 6.22335089017767e-9);
|
|
8812
|
+
const vec2 SIN_TABLE_2_FP64 = vec2(0.5555702447891235, -1.1769521357507529e-8);
|
|
8813
|
+
const vec2 SIN_TABLE_3_FP64 = vec2(0.7071067690849304, 1.2101617041793133e-8);
|
|
8814
|
+
|
|
8815
|
+
const vec2 COS_TABLE_0_FP64 = vec2(0.9807852506637573, 2.9739473106360492e-8);
|
|
8816
|
+
const vec2 COS_TABLE_1_FP64 = vec2(0.9238795042037964, 2.8307490351764386e-8);
|
|
8817
|
+
const vec2 COS_TABLE_2_FP64 = vec2(0.8314695954322815, 1.6870263741530778e-8);
|
|
8818
|
+
const vec2 COS_TABLE_3_FP64 = vec2(0.7071067690849304, 1.2101617152815436e-8);
|
|
8819
|
+
|
|
8820
|
+
const vec2 INVERSE_FACTORIAL_3_FP64 = vec2(1.666666716337204e-01, -4.967053879312289e-09); // 1/3!
|
|
8821
|
+
const vec2 INVERSE_FACTORIAL_4_FP64 = vec2(4.16666679084301e-02, -1.2417634698280722e-09); // 1/4!
|
|
8822
|
+
const vec2 INVERSE_FACTORIAL_5_FP64 = vec2(8.333333767950535e-03, -4.34617203337595e-10); // 1/5!
|
|
8823
|
+
const vec2 INVERSE_FACTORIAL_6_FP64 = vec2(1.3888889225199819e-03, -3.3631094437103215e-11); // 1/6!
|
|
8824
|
+
const vec2 INVERSE_FACTORIAL_7_FP64 = vec2(1.9841270113829523e-04, -2.725596874933456e-12); // 1/7!
|
|
8825
|
+
const vec2 INVERSE_FACTORIAL_8_FP64 = vec2(2.4801587642286904e-05, -3.406996025904184e-13); // 1/8!
|
|
8826
|
+
const vec2 INVERSE_FACTORIAL_9_FP64 = vec2(2.75573188446287533e-06, 3.7935713937038186e-14); // 1/9!
|
|
8827
|
+
const vec2 INVERSE_FACTORIAL_10_FP64 = vec2(2.755731998149713e-07, -7.575112367869873e-15); // 1/10!
|
|
8828
|
+
|
|
8829
|
+
float nint(float d) {
|
|
8830
|
+
if (d == floor(d)) return d;
|
|
8831
|
+
return floor(d + 0.5);
|
|
8832
|
+
}
|
|
8833
|
+
|
|
8834
|
+
vec2 nint_fp64(vec2 a) {
|
|
8835
|
+
float hi = nint(a.x);
|
|
8836
|
+
float lo;
|
|
8837
|
+
vec2 tmp;
|
|
8838
|
+
if (hi == a.x) {
|
|
8839
|
+
lo = nint(a.y);
|
|
8840
|
+
tmp = quickTwoSum(hi, lo);
|
|
8841
|
+
} else {
|
|
8842
|
+
lo = 0.0;
|
|
8843
|
+
if (abs(hi - a.x) == 0.5 && a.y < 0.0) {
|
|
8844
|
+
hi -= 1.0;
|
|
8845
|
+
}
|
|
8846
|
+
tmp = vec2(hi, lo);
|
|
9147
8847
|
}
|
|
9148
|
-
return
|
|
9149
|
-
|
|
9150
|
-
vertexCount: 1,
|
|
9151
|
-
isInstanced: false,
|
|
9152
|
-
drawMode: 0,
|
|
9153
|
-
vs: AGGREGATE_VS,
|
|
9154
|
-
fs: AGGREGATE_FS,
|
|
9155
|
-
...shaderOptions
|
|
9156
|
-
});
|
|
9157
|
-
}
|
|
9158
|
-
var parameters = {
|
|
9159
|
-
blend: true,
|
|
9160
|
-
blendFunc: [1, 1, 1, 1],
|
|
9161
|
-
blendEquation: [32774, 32774],
|
|
9162
|
-
depthTest: false
|
|
9163
|
-
};
|
|
8848
|
+
return tmp;
|
|
8849
|
+
}
|
|
9164
8850
|
|
|
9165
|
-
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
|
|
9171
|
-
onFilteredItemsChange: {
|
|
9172
|
-
type: "function",
|
|
9173
|
-
value: null,
|
|
9174
|
-
optional: true
|
|
9175
|
-
},
|
|
9176
|
-
filterEnabled: true,
|
|
9177
|
-
filterRange: [-1, 1],
|
|
9178
|
-
filterSoftRange: null,
|
|
9179
|
-
filterTransformSize: true,
|
|
9180
|
-
filterTransformColor: true
|
|
9181
|
-
};
|
|
9182
|
-
var DATA_TYPE_FROM_SIZE = {
|
|
9183
|
-
1: "float",
|
|
9184
|
-
2: "vec2",
|
|
9185
|
-
3: "vec3",
|
|
9186
|
-
4: "vec4"
|
|
9187
|
-
};
|
|
9188
|
-
var DataFilterExtension = class extends import_core38.LayerExtension {
|
|
9189
|
-
constructor({
|
|
9190
|
-
filterSize = 1,
|
|
9191
|
-
fp64: fp642 = false,
|
|
9192
|
-
countItems = false
|
|
9193
|
-
} = {}) {
|
|
9194
|
-
if (!DATA_TYPE_FROM_SIZE[filterSize]) {
|
|
9195
|
-
throw new Error("filterSize out of range");
|
|
9196
|
-
}
|
|
9197
|
-
super({
|
|
9198
|
-
filterSize,
|
|
9199
|
-
fp64: fp642,
|
|
9200
|
-
countItems
|
|
9201
|
-
});
|
|
9202
|
-
}
|
|
9203
|
-
getShaders(extension) {
|
|
9204
|
-
const {
|
|
9205
|
-
filterSize,
|
|
9206
|
-
fp64: fp642
|
|
9207
|
-
} = extension.opts;
|
|
9208
|
-
return {
|
|
9209
|
-
modules: [fp642 ? shaderModule64 : shaderModule],
|
|
9210
|
-
defines: {
|
|
9211
|
-
DATAFILTER_TYPE: DATA_TYPE_FROM_SIZE[filterSize],
|
|
9212
|
-
DATAFILTER_DOUBLE: Boolean(fp642)
|
|
9213
|
-
}
|
|
9214
|
-
};
|
|
9215
|
-
}
|
|
9216
|
-
initializeState(context, extension) {
|
|
9217
|
-
const attributeManager = this.getAttributeManager();
|
|
9218
|
-
if (attributeManager) {
|
|
9219
|
-
attributeManager.add({
|
|
9220
|
-
filterValues: {
|
|
9221
|
-
size: extension.opts.filterSize,
|
|
9222
|
-
type: extension.opts.fp64 ? 5130 : 5126,
|
|
9223
|
-
accessor: "getFilterValue",
|
|
9224
|
-
shaderAttributes: {
|
|
9225
|
-
filterValues: {
|
|
9226
|
-
divisor: 0
|
|
9227
|
-
},
|
|
9228
|
-
instanceFilterValues: {
|
|
9229
|
-
divisor: 1
|
|
9230
|
-
}
|
|
9231
|
-
}
|
|
9232
|
-
}
|
|
9233
|
-
});
|
|
9234
|
-
}
|
|
9235
|
-
const {
|
|
9236
|
-
device
|
|
9237
|
-
} = this.context;
|
|
9238
|
-
if (attributeManager && extension.opts.countItems) {
|
|
9239
|
-
const useFloatTarget = supportsFloatTarget(device);
|
|
9240
|
-
attributeManager.add({
|
|
9241
|
-
filterIndices: {
|
|
9242
|
-
size: useFloatTarget ? 1 : 2,
|
|
9243
|
-
vertexOffset: 1,
|
|
9244
|
-
type: 5121,
|
|
9245
|
-
normalized: true,
|
|
9246
|
-
accessor: (object, {
|
|
9247
|
-
index
|
|
9248
|
-
}) => {
|
|
9249
|
-
const i = object && object.__source ? object.__source.index : index;
|
|
9250
|
-
return useFloatTarget ? (i + 1) % 255 : [(i + 1) % 255, Math.floor(i / 255) % 255];
|
|
9251
|
-
},
|
|
9252
|
-
shaderAttributes: {
|
|
9253
|
-
filterPrevIndices: {
|
|
9254
|
-
vertexOffset: 0
|
|
9255
|
-
},
|
|
9256
|
-
filterIndices: {
|
|
9257
|
-
vertexOffset: 1
|
|
9258
|
-
}
|
|
9259
|
-
}
|
|
9260
|
-
}
|
|
9261
|
-
});
|
|
9262
|
-
const filterFBO = getFramebuffer3(device, useFloatTarget);
|
|
9263
|
-
const filterModel = getModel(device, extension.getShaders.call(this, extension), useFloatTarget);
|
|
9264
|
-
this.setState({
|
|
9265
|
-
filterFBO,
|
|
9266
|
-
filterModel
|
|
9267
|
-
});
|
|
9268
|
-
}
|
|
9269
|
-
}
|
|
9270
|
-
updateState({
|
|
9271
|
-
props,
|
|
9272
|
-
oldProps
|
|
9273
|
-
}) {
|
|
9274
|
-
if (this.state.filterModel) {
|
|
9275
|
-
const attributeManager = this.getAttributeManager();
|
|
9276
|
-
const filterNeedsUpdate = attributeManager.attributes.filterValues.needsUpdate() || props.filterEnabled !== oldProps.filterEnabled || props.filterRange !== oldProps.filterRange || props.filterSoftRange !== oldProps.filterSoftRange;
|
|
9277
|
-
if (filterNeedsUpdate) {
|
|
9278
|
-
this.setState({
|
|
9279
|
-
filterNeedsUpdate
|
|
9280
|
-
});
|
|
9281
|
-
}
|
|
9282
|
-
}
|
|
9283
|
-
}
|
|
9284
|
-
draw(params, extension) {
|
|
9285
|
-
const filterFBO = this.state.filterFBO;
|
|
9286
|
-
const filterModel = this.state.filterModel;
|
|
9287
|
-
const filterNeedsUpdate = this.state.filterNeedsUpdate;
|
|
9288
|
-
const {
|
|
9289
|
-
onFilteredItemsChange
|
|
9290
|
-
} = this.props;
|
|
9291
|
-
if (filterNeedsUpdate && onFilteredItemsChange && filterModel) {
|
|
9292
|
-
const {
|
|
9293
|
-
attributes: {
|
|
9294
|
-
filterValues,
|
|
9295
|
-
filterIndices
|
|
9296
|
-
}
|
|
9297
|
-
} = this.getAttributeManager();
|
|
9298
|
-
filterModel.setVertexCount(this.getNumInstances());
|
|
9299
|
-
clear(this.context.device, {
|
|
9300
|
-
framebuffer: filterFBO,
|
|
9301
|
-
color: [0, 0, 0, 0]
|
|
9302
|
-
});
|
|
9303
|
-
filterModel.updateModuleSettings(params.moduleParameters);
|
|
9304
|
-
filterModel.setAttributes({
|
|
9305
|
-
...filterValues.getValue(),
|
|
9306
|
-
...filterIndices?.getValue()
|
|
9307
|
-
});
|
|
9308
|
-
withGLParameters(filterModel.device, {
|
|
9309
|
-
framebuffer: filterFBO,
|
|
9310
|
-
...parameters,
|
|
9311
|
-
viewport: [0, 0, filterFBO.width, filterFBO.height]
|
|
9312
|
-
}, () => {
|
|
9313
|
-
filterModel.draw(this.context.renderPass);
|
|
9314
|
-
});
|
|
9315
|
-
const color = readPixelsToArray(filterFBO);
|
|
9316
|
-
let count = 0;
|
|
9317
|
-
for (let i = 0; i < color.length; i++) {
|
|
9318
|
-
count += color[i];
|
|
9319
|
-
}
|
|
9320
|
-
onFilteredItemsChange({
|
|
9321
|
-
id: this.id,
|
|
9322
|
-
count
|
|
9323
|
-
});
|
|
9324
|
-
this.state.filterNeedsUpdate = false;
|
|
9325
|
-
}
|
|
9326
|
-
}
|
|
9327
|
-
finalizeState() {
|
|
9328
|
-
const filterFBO = this.state.filterFBO;
|
|
9329
|
-
const filterModel = this.state.filterModel;
|
|
9330
|
-
filterFBO?.destroy();
|
|
9331
|
-
filterModel?.destroy();
|
|
9332
|
-
}
|
|
9333
|
-
};
|
|
9334
|
-
__publicField(DataFilterExtension, "defaultProps", defaultProps2);
|
|
9335
|
-
__publicField(DataFilterExtension, "extensionName", "DataFilterExtension");
|
|
8851
|
+
/* k_power controls how much range reduction we would like to have
|
|
8852
|
+
Range reduction uses the following method:
|
|
8853
|
+
assume a = k_power * r + m * log(2), k and m being integers.
|
|
8854
|
+
Set k_power = 4 (we can choose other k to trade accuracy with performance.
|
|
8855
|
+
we only need to calculate exp(r) and using exp(a) = 2^m * exp(r)^k_power;
|
|
8856
|
+
*/
|
|
9336
8857
|
|
|
9337
|
-
|
|
9338
|
-
|
|
8858
|
+
vec2 exp_fp64(vec2 a) {
|
|
8859
|
+
// We need to make sure these two numbers match
|
|
8860
|
+
// as bit-wise shift is not available in GLSL 1.0
|
|
8861
|
+
const int k_power = 4;
|
|
8862
|
+
const float k = 16.0;
|
|
9339
8863
|
|
|
9340
|
-
|
|
9341
|
-
var glsl2 = (x) => `${x}`;
|
|
8864
|
+
const float inv_k = 1.0 / k;
|
|
9342
8865
|
|
|
9343
|
-
|
|
9344
|
-
|
|
9345
|
-
|
|
9346
|
-
|
|
9347
|
-
const hiPart = Math.fround(a);
|
|
9348
|
-
const loPart = a - hiPart;
|
|
9349
|
-
out[startIndex] = hiPart;
|
|
9350
|
-
out[startIndex + 1] = loPart;
|
|
9351
|
-
return out;
|
|
9352
|
-
}
|
|
9353
|
-
function fp64LowPart(a) {
|
|
9354
|
-
return a - Math.fround(a);
|
|
9355
|
-
}
|
|
9356
|
-
function fp64ifyMatrix4(matrix) {
|
|
9357
|
-
const matrixFP64 = new Float32Array(32);
|
|
9358
|
-
for (let i = 0; i < 4; ++i) {
|
|
9359
|
-
for (let j = 0; j < 4; ++j) {
|
|
9360
|
-
const index = i * 4 + j;
|
|
9361
|
-
fp64ify(matrix[j * 4 + i], matrixFP64, index * 2);
|
|
9362
|
-
}
|
|
9363
|
-
}
|
|
9364
|
-
return matrixFP64;
|
|
9365
|
-
}
|
|
8866
|
+
if (a.x <= -88.0) return vec2(0.0, 0.0);
|
|
8867
|
+
if (a.x >= 88.0) return vec2(1.0 / 0.0, 1.0 / 0.0);
|
|
8868
|
+
if (a.x == 0.0 && a.y == 0.0) return vec2(1.0, 0.0);
|
|
8869
|
+
if (a.x == 1.0 && a.y == 0.0) return E_FP64;
|
|
9366
8870
|
|
|
9367
|
-
|
|
9368
|
-
|
|
9369
|
-
|
|
8871
|
+
float m = floor(a.x / LOG2_FP64.x + 0.5);
|
|
8872
|
+
vec2 r = sub_fp64(a, mul_fp64(LOG2_FP64, vec2(m, 0.0))) * inv_k;
|
|
8873
|
+
vec2 s, t, p;
|
|
9370
8874
|
|
|
9371
|
-
|
|
9372
|
-
|
|
8875
|
+
p = mul_fp64(r, r);
|
|
8876
|
+
s = sum_fp64(r, p * 0.5);
|
|
8877
|
+
p = mul_fp64(p, r);
|
|
8878
|
+
t = mul_fp64(p, INVERSE_FACTORIAL_3_FP64);
|
|
9373
8879
|
|
|
9374
|
-
|
|
9375
|
-
|
|
9376
|
-
|
|
8880
|
+
s = sum_fp64(s, t);
|
|
8881
|
+
p = mul_fp64(p, r);
|
|
8882
|
+
t = mul_fp64(p, INVERSE_FACTORIAL_4_FP64);
|
|
9377
8883
|
|
|
9378
|
-
|
|
9379
|
-
|
|
9380
|
-
|
|
9381
|
-
and one b should appear
|
|
8884
|
+
s = sum_fp64(s, t);
|
|
8885
|
+
p = mul_fp64(p, r);
|
|
8886
|
+
t = mul_fp64(p, INVERSE_FACTORIAL_5_FP64);
|
|
9382
8887
|
|
|
9383
|
-
|
|
9384
|
-
|
|
8888
|
+
// s = sum_fp64(s, t);
|
|
8889
|
+
// p = mul_fp64(p, r);
|
|
8890
|
+
// t = mul_fp64(p, INVERSE_FACTORIAL_6_FP64);
|
|
9385
8891
|
|
|
9386
|
-
//
|
|
9387
|
-
|
|
9388
|
-
|
|
9389
|
-
float t = a * SPLIT;
|
|
9390
|
-
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
9391
|
-
float a_hi = t * ONE - (t - a);
|
|
9392
|
-
float a_lo = a * ONE - a_hi;
|
|
9393
|
-
#else
|
|
9394
|
-
float a_hi = t - (t - a);
|
|
9395
|
-
float a_lo = a - a_hi;
|
|
9396
|
-
#endif
|
|
9397
|
-
return vec2(a_hi, a_lo);
|
|
9398
|
-
}
|
|
9399
|
-
|
|
9400
|
-
// Divide float number again when high float uses too many fraction bits
|
|
9401
|
-
vec2 split2(vec2 a) {
|
|
9402
|
-
vec2 b = split(a.x);
|
|
9403
|
-
b.y += a.y;
|
|
9404
|
-
return b;
|
|
9405
|
-
}
|
|
9406
|
-
|
|
9407
|
-
// Special sum operation when a > b
|
|
9408
|
-
vec2 quickTwoSum(float a, float b) {
|
|
9409
|
-
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
9410
|
-
float sum = (a + b) * ONE;
|
|
9411
|
-
float err = b - (sum - a) * ONE;
|
|
9412
|
-
#else
|
|
9413
|
-
float sum = a + b;
|
|
9414
|
-
float err = b - (sum - a);
|
|
9415
|
-
#endif
|
|
9416
|
-
return vec2(sum, err);
|
|
9417
|
-
}
|
|
9418
|
-
|
|
9419
|
-
// General sum operation
|
|
9420
|
-
vec2 twoSum(float a, float b) {
|
|
9421
|
-
float s = (a + b);
|
|
9422
|
-
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
9423
|
-
float v = (s * ONE - a) * ONE;
|
|
9424
|
-
float err = (a - (s - v) * ONE) * ONE * ONE * ONE + (b - v);
|
|
9425
|
-
#else
|
|
9426
|
-
float v = s - a;
|
|
9427
|
-
float err = (a - (s - v)) + (b - v);
|
|
9428
|
-
#endif
|
|
9429
|
-
return vec2(s, err);
|
|
9430
|
-
}
|
|
9431
|
-
|
|
9432
|
-
vec2 twoSub(float a, float b) {
|
|
9433
|
-
float s = (a - b);
|
|
9434
|
-
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
9435
|
-
float v = (s * ONE - a) * ONE;
|
|
9436
|
-
float err = (a - (s - v) * ONE) * ONE * ONE * ONE - (b + v);
|
|
9437
|
-
#else
|
|
9438
|
-
float v = s - a;
|
|
9439
|
-
float err = (a - (s - v)) - (b + v);
|
|
9440
|
-
#endif
|
|
9441
|
-
return vec2(s, err);
|
|
9442
|
-
}
|
|
9443
|
-
|
|
9444
|
-
vec2 twoSqr(float a) {
|
|
9445
|
-
float prod = a * a;
|
|
9446
|
-
vec2 a_fp64 = split(a);
|
|
9447
|
-
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
9448
|
-
float err = ((a_fp64.x * a_fp64.x - prod) * ONE + 2.0 * a_fp64.x *
|
|
9449
|
-
a_fp64.y * ONE * ONE) + a_fp64.y * a_fp64.y * ONE * ONE * ONE;
|
|
9450
|
-
#else
|
|
9451
|
-
float err = ((a_fp64.x * a_fp64.x - prod) + 2.0 * a_fp64.x * a_fp64.y) + a_fp64.y * a_fp64.y;
|
|
9452
|
-
#endif
|
|
9453
|
-
return vec2(prod, err);
|
|
9454
|
-
}
|
|
9455
|
-
|
|
9456
|
-
vec2 twoProd(float a, float b) {
|
|
9457
|
-
float prod = a * b;
|
|
9458
|
-
vec2 a_fp64 = split(a);
|
|
9459
|
-
vec2 b_fp64 = split(b);
|
|
9460
|
-
float err = ((a_fp64.x * b_fp64.x - prod) + a_fp64.x * b_fp64.y +
|
|
9461
|
-
a_fp64.y * b_fp64.x) + a_fp64.y * b_fp64.y;
|
|
9462
|
-
return vec2(prod, err);
|
|
9463
|
-
}
|
|
9464
|
-
|
|
9465
|
-
vec2 sum_fp64(vec2 a, vec2 b) {
|
|
9466
|
-
vec2 s, t;
|
|
9467
|
-
s = twoSum(a.x, b.x);
|
|
9468
|
-
t = twoSum(a.y, b.y);
|
|
9469
|
-
s.y += t.x;
|
|
9470
|
-
s = quickTwoSum(s.x, s.y);
|
|
9471
|
-
s.y += t.y;
|
|
9472
|
-
s = quickTwoSum(s.x, s.y);
|
|
9473
|
-
return s;
|
|
9474
|
-
}
|
|
9475
|
-
|
|
9476
|
-
vec2 sub_fp64(vec2 a, vec2 b) {
|
|
9477
|
-
vec2 s, t;
|
|
9478
|
-
s = twoSub(a.x, b.x);
|
|
9479
|
-
t = twoSub(a.y, b.y);
|
|
9480
|
-
s.y += t.x;
|
|
9481
|
-
s = quickTwoSum(s.x, s.y);
|
|
9482
|
-
s.y += t.y;
|
|
9483
|
-
s = quickTwoSum(s.x, s.y);
|
|
9484
|
-
return s;
|
|
9485
|
-
}
|
|
9486
|
-
|
|
9487
|
-
vec2 mul_fp64(vec2 a, vec2 b) {
|
|
9488
|
-
vec2 prod = twoProd(a.x, b.x);
|
|
9489
|
-
// y component is for the error
|
|
9490
|
-
prod.y += a.x * b.y;
|
|
9491
|
-
#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)
|
|
9492
|
-
prod = split2(prod);
|
|
9493
|
-
#endif
|
|
9494
|
-
prod = quickTwoSum(prod.x, prod.y);
|
|
9495
|
-
prod.y += a.y * b.x;
|
|
9496
|
-
#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)
|
|
9497
|
-
prod = split2(prod);
|
|
9498
|
-
#endif
|
|
9499
|
-
prod = quickTwoSum(prod.x, prod.y);
|
|
9500
|
-
return prod;
|
|
9501
|
-
}
|
|
9502
|
-
|
|
9503
|
-
vec2 div_fp64(vec2 a, vec2 b) {
|
|
9504
|
-
float xn = 1.0 / b.x;
|
|
9505
|
-
#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)
|
|
9506
|
-
vec2 yn = mul_fp64(a, vec2(xn, 0));
|
|
9507
|
-
#else
|
|
9508
|
-
vec2 yn = a * xn;
|
|
9509
|
-
#endif
|
|
9510
|
-
float diff = (sub_fp64(a, mul_fp64(b, yn))).x;
|
|
9511
|
-
vec2 prod = twoProd(xn, diff);
|
|
9512
|
-
return sum_fp64(yn, prod);
|
|
9513
|
-
}
|
|
9514
|
-
|
|
9515
|
-
vec2 sqrt_fp64(vec2 a) {
|
|
9516
|
-
if (a.x == 0.0 && a.y == 0.0) return vec2(0.0, 0.0);
|
|
9517
|
-
if (a.x < 0.0) return vec2(0.0 / 0.0, 0.0 / 0.0);
|
|
9518
|
-
|
|
9519
|
-
float x = 1.0 / sqrt(a.x);
|
|
9520
|
-
float yn = a.x * x;
|
|
9521
|
-
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
9522
|
-
vec2 yn_sqr = twoSqr(yn) * ONE;
|
|
9523
|
-
#else
|
|
9524
|
-
vec2 yn_sqr = twoSqr(yn);
|
|
9525
|
-
#endif
|
|
9526
|
-
float diff = sub_fp64(a, yn_sqr).x;
|
|
9527
|
-
vec2 prod = twoProd(x * 0.5, diff);
|
|
9528
|
-
#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)
|
|
9529
|
-
return sum_fp64(split(yn), prod);
|
|
9530
|
-
#else
|
|
9531
|
-
return sum_fp64(vec2(yn, 0.0), prod);
|
|
9532
|
-
#endif
|
|
9533
|
-
}
|
|
9534
|
-
`;
|
|
9535
|
-
|
|
9536
|
-
// ../../node_modules/@luma.gl/shadertools/dist/modules-webgl1/math/fp64/fp64-functions.glsl.js
|
|
9537
|
-
var fp64functionShader = glsl2`\
|
|
9538
|
-
const vec2 E_FP64 = vec2(2.7182817459106445e+00, 8.254840366817007e-08);
|
|
9539
|
-
const vec2 LOG2_FP64 = vec2(0.6931471824645996e+00, -1.9046542121259336e-09);
|
|
9540
|
-
const vec2 PI_FP64 = vec2(3.1415927410125732, -8.742278012618954e-8);
|
|
9541
|
-
const vec2 TWO_PI_FP64 = vec2(6.2831854820251465, -1.7484556025237907e-7);
|
|
9542
|
-
const vec2 PI_2_FP64 = vec2(1.5707963705062866, -4.371139006309477e-8);
|
|
9543
|
-
const vec2 PI_4_FP64 = vec2(0.7853981852531433, -2.1855695031547384e-8);
|
|
9544
|
-
const vec2 PI_16_FP64 = vec2(0.19634954631328583, -5.463923757886846e-9);
|
|
9545
|
-
const vec2 PI_16_2_FP64 = vec2(0.39269909262657166, -1.0927847515773692e-8);
|
|
9546
|
-
const vec2 PI_16_3_FP64 = vec2(0.5890486240386963, -1.4906100798128818e-9);
|
|
9547
|
-
const vec2 PI_180_FP64 = vec2(0.01745329238474369, 1.3519960498364902e-10);
|
|
9548
|
-
|
|
9549
|
-
const vec2 SIN_TABLE_0_FP64 = vec2(0.19509032368659973, -1.6704714833615242e-9);
|
|
9550
|
-
const vec2 SIN_TABLE_1_FP64 = vec2(0.3826834261417389, 6.22335089017767e-9);
|
|
9551
|
-
const vec2 SIN_TABLE_2_FP64 = vec2(0.5555702447891235, -1.1769521357507529e-8);
|
|
9552
|
-
const vec2 SIN_TABLE_3_FP64 = vec2(0.7071067690849304, 1.2101617041793133e-8);
|
|
9553
|
-
|
|
9554
|
-
const vec2 COS_TABLE_0_FP64 = vec2(0.9807852506637573, 2.9739473106360492e-8);
|
|
9555
|
-
const vec2 COS_TABLE_1_FP64 = vec2(0.9238795042037964, 2.8307490351764386e-8);
|
|
9556
|
-
const vec2 COS_TABLE_2_FP64 = vec2(0.8314695954322815, 1.6870263741530778e-8);
|
|
9557
|
-
const vec2 COS_TABLE_3_FP64 = vec2(0.7071067690849304, 1.2101617152815436e-8);
|
|
9558
|
-
|
|
9559
|
-
const vec2 INVERSE_FACTORIAL_3_FP64 = vec2(1.666666716337204e-01, -4.967053879312289e-09); // 1/3!
|
|
9560
|
-
const vec2 INVERSE_FACTORIAL_4_FP64 = vec2(4.16666679084301e-02, -1.2417634698280722e-09); // 1/4!
|
|
9561
|
-
const vec2 INVERSE_FACTORIAL_5_FP64 = vec2(8.333333767950535e-03, -4.34617203337595e-10); // 1/5!
|
|
9562
|
-
const vec2 INVERSE_FACTORIAL_6_FP64 = vec2(1.3888889225199819e-03, -3.3631094437103215e-11); // 1/6!
|
|
9563
|
-
const vec2 INVERSE_FACTORIAL_7_FP64 = vec2(1.9841270113829523e-04, -2.725596874933456e-12); // 1/7!
|
|
9564
|
-
const vec2 INVERSE_FACTORIAL_8_FP64 = vec2(2.4801587642286904e-05, -3.406996025904184e-13); // 1/8!
|
|
9565
|
-
const vec2 INVERSE_FACTORIAL_9_FP64 = vec2(2.75573188446287533e-06, 3.7935713937038186e-14); // 1/9!
|
|
9566
|
-
const vec2 INVERSE_FACTORIAL_10_FP64 = vec2(2.755731998149713e-07, -7.575112367869873e-15); // 1/10!
|
|
9567
|
-
|
|
9568
|
-
float nint(float d) {
|
|
9569
|
-
if (d == floor(d)) return d;
|
|
9570
|
-
return floor(d + 0.5);
|
|
9571
|
-
}
|
|
9572
|
-
|
|
9573
|
-
vec2 nint_fp64(vec2 a) {
|
|
9574
|
-
float hi = nint(a.x);
|
|
9575
|
-
float lo;
|
|
9576
|
-
vec2 tmp;
|
|
9577
|
-
if (hi == a.x) {
|
|
9578
|
-
lo = nint(a.y);
|
|
9579
|
-
tmp = quickTwoSum(hi, lo);
|
|
9580
|
-
} else {
|
|
9581
|
-
lo = 0.0;
|
|
9582
|
-
if (abs(hi - a.x) == 0.5 && a.y < 0.0) {
|
|
9583
|
-
hi -= 1.0;
|
|
9584
|
-
}
|
|
9585
|
-
tmp = vec2(hi, lo);
|
|
9586
|
-
}
|
|
9587
|
-
return tmp;
|
|
9588
|
-
}
|
|
9589
|
-
|
|
9590
|
-
/* k_power controls how much range reduction we would like to have
|
|
9591
|
-
Range reduction uses the following method:
|
|
9592
|
-
assume a = k_power * r + m * log(2), k and m being integers.
|
|
9593
|
-
Set k_power = 4 (we can choose other k to trade accuracy with performance.
|
|
9594
|
-
we only need to calculate exp(r) and using exp(a) = 2^m * exp(r)^k_power;
|
|
9595
|
-
*/
|
|
9596
|
-
|
|
9597
|
-
vec2 exp_fp64(vec2 a) {
|
|
9598
|
-
// We need to make sure these two numbers match
|
|
9599
|
-
// as bit-wise shift is not available in GLSL 1.0
|
|
9600
|
-
const int k_power = 4;
|
|
9601
|
-
const float k = 16.0;
|
|
9602
|
-
|
|
9603
|
-
const float inv_k = 1.0 / k;
|
|
9604
|
-
|
|
9605
|
-
if (a.x <= -88.0) return vec2(0.0, 0.0);
|
|
9606
|
-
if (a.x >= 88.0) return vec2(1.0 / 0.0, 1.0 / 0.0);
|
|
9607
|
-
if (a.x == 0.0 && a.y == 0.0) return vec2(1.0, 0.0);
|
|
9608
|
-
if (a.x == 1.0 && a.y == 0.0) return E_FP64;
|
|
9609
|
-
|
|
9610
|
-
float m = floor(a.x / LOG2_FP64.x + 0.5);
|
|
9611
|
-
vec2 r = sub_fp64(a, mul_fp64(LOG2_FP64, vec2(m, 0.0))) * inv_k;
|
|
9612
|
-
vec2 s, t, p;
|
|
9613
|
-
|
|
9614
|
-
p = mul_fp64(r, r);
|
|
9615
|
-
s = sum_fp64(r, p * 0.5);
|
|
9616
|
-
p = mul_fp64(p, r);
|
|
9617
|
-
t = mul_fp64(p, INVERSE_FACTORIAL_3_FP64);
|
|
9618
|
-
|
|
9619
|
-
s = sum_fp64(s, t);
|
|
9620
|
-
p = mul_fp64(p, r);
|
|
9621
|
-
t = mul_fp64(p, INVERSE_FACTORIAL_4_FP64);
|
|
9622
|
-
|
|
9623
|
-
s = sum_fp64(s, t);
|
|
9624
|
-
p = mul_fp64(p, r);
|
|
9625
|
-
t = mul_fp64(p, INVERSE_FACTORIAL_5_FP64);
|
|
9626
|
-
|
|
9627
|
-
// s = sum_fp64(s, t);
|
|
9628
|
-
// p = mul_fp64(p, r);
|
|
9629
|
-
// t = mul_fp64(p, INVERSE_FACTORIAL_6_FP64);
|
|
9630
|
-
|
|
9631
|
-
// s = sum_fp64(s, t);
|
|
9632
|
-
// p = mul_fp64(p, r);
|
|
9633
|
-
// t = mul_fp64(p, INVERSE_FACTORIAL_7_FP64);
|
|
8892
|
+
// s = sum_fp64(s, t);
|
|
8893
|
+
// p = mul_fp64(p, r);
|
|
8894
|
+
// t = mul_fp64(p, INVERSE_FACTORIAL_7_FP64);
|
|
9634
8895
|
|
|
9635
8896
|
s = sum_fp64(s, t);
|
|
9636
8897
|
|
|
@@ -10676,53 +9937,789 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
|
|
|
10676
9937
|
function str(a) {
|
|
10677
9938
|
return "vec3(".concat(a[0], ", ").concat(a[1], ", ").concat(a[2], ")");
|
|
10678
9939
|
}
|
|
10679
|
-
function exactEquals(a, b) {
|
|
10680
|
-
return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
|
|
9940
|
+
function exactEquals(a, b) {
|
|
9941
|
+
return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
|
|
9942
|
+
}
|
|
9943
|
+
function equals2(a, b) {
|
|
9944
|
+
const a0 = a[0];
|
|
9945
|
+
const a1 = a[1];
|
|
9946
|
+
const a2 = a[2];
|
|
9947
|
+
const b0 = b[0];
|
|
9948
|
+
const b1 = b[1];
|
|
9949
|
+
const b2 = b[2];
|
|
9950
|
+
return Math.abs(a0 - b0) <= EPSILON * Math.max(1, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1, Math.abs(a2), Math.abs(b2));
|
|
9951
|
+
}
|
|
9952
|
+
var sub = subtract;
|
|
9953
|
+
var mul = multiply;
|
|
9954
|
+
var div = divide;
|
|
9955
|
+
var dist = distance;
|
|
9956
|
+
var sqrDist = squaredDistance;
|
|
9957
|
+
var len = length;
|
|
9958
|
+
var sqrLen = squaredLength;
|
|
9959
|
+
var forEach = function() {
|
|
9960
|
+
const vec = create();
|
|
9961
|
+
return function(a, stride, offset, count, fn, arg) {
|
|
9962
|
+
let i;
|
|
9963
|
+
let l;
|
|
9964
|
+
if (!stride) {
|
|
9965
|
+
stride = 3;
|
|
9966
|
+
}
|
|
9967
|
+
if (!offset) {
|
|
9968
|
+
offset = 0;
|
|
9969
|
+
}
|
|
9970
|
+
if (count) {
|
|
9971
|
+
l = Math.min(count * stride + offset, a.length);
|
|
9972
|
+
} else {
|
|
9973
|
+
l = a.length;
|
|
9974
|
+
}
|
|
9975
|
+
for (i = offset; i < l; i += stride) {
|
|
9976
|
+
vec[0] = a[i];
|
|
9977
|
+
vec[1] = a[i + 1];
|
|
9978
|
+
vec[2] = a[i + 2];
|
|
9979
|
+
fn(vec, vec, arg);
|
|
9980
|
+
a[i] = vec[0];
|
|
9981
|
+
a[i + 1] = vec[1];
|
|
9982
|
+
a[i + 2] = vec[2];
|
|
9983
|
+
}
|
|
9984
|
+
return a;
|
|
9985
|
+
};
|
|
9986
|
+
}();
|
|
9987
|
+
|
|
9988
|
+
// ../../node_modules/@luma.gl/engine/dist/geometry/gpu-geometry.js
|
|
9989
|
+
var import_core34 = __toESM(require_core2(), 1);
|
|
9990
|
+
var GPUGeometry = class {
|
|
9991
|
+
constructor(props) {
|
|
9992
|
+
this.id = void 0;
|
|
9993
|
+
this.userData = {};
|
|
9994
|
+
this.topology = void 0;
|
|
9995
|
+
this.bufferLayout = [];
|
|
9996
|
+
this.vertexCount = void 0;
|
|
9997
|
+
this.indices = void 0;
|
|
9998
|
+
this.attributes = void 0;
|
|
9999
|
+
this.id = props.id || (0, import_core34.uid)("geometry");
|
|
10000
|
+
this.topology = props.topology;
|
|
10001
|
+
this.indices = props.indices || null;
|
|
10002
|
+
this.attributes = props.attributes;
|
|
10003
|
+
this.vertexCount = props.vertexCount;
|
|
10004
|
+
this.bufferLayout = props.bufferLayout || [];
|
|
10005
|
+
if (this.indices) {
|
|
10006
|
+
(0, import_core34.assert)(this.indices.usage === import_core34.Buffer.INDEX);
|
|
10007
|
+
}
|
|
10008
|
+
}
|
|
10009
|
+
destroy() {
|
|
10010
|
+
var _this$attributes$colo;
|
|
10011
|
+
this.indices.destroy();
|
|
10012
|
+
this.attributes.positions.destroy();
|
|
10013
|
+
this.attributes.normals.destroy();
|
|
10014
|
+
this.attributes.texCoords.destroy();
|
|
10015
|
+
(_this$attributes$colo = this.attributes.colors) === null || _this$attributes$colo === void 0 ? void 0 : _this$attributes$colo.destroy();
|
|
10016
|
+
}
|
|
10017
|
+
getVertexCount() {
|
|
10018
|
+
return this.vertexCount;
|
|
10019
|
+
}
|
|
10020
|
+
getAttributes() {
|
|
10021
|
+
return this.attributes;
|
|
10022
|
+
}
|
|
10023
|
+
getIndexes() {
|
|
10024
|
+
return this.indices;
|
|
10025
|
+
}
|
|
10026
|
+
_calculateVertexCount(positions) {
|
|
10027
|
+
const vertexCount = positions.byteLength / 12;
|
|
10028
|
+
return vertexCount;
|
|
10029
|
+
}
|
|
10030
|
+
};
|
|
10031
|
+
function makeGPUGeometry(device, geometry) {
|
|
10032
|
+
if (geometry instanceof GPUGeometry) {
|
|
10033
|
+
return geometry;
|
|
10034
|
+
}
|
|
10035
|
+
const indices = getIndexBufferFromGeometry(device, geometry);
|
|
10036
|
+
const {
|
|
10037
|
+
attributes,
|
|
10038
|
+
bufferLayout
|
|
10039
|
+
} = getAttributeBuffersFromGeometry(device, geometry);
|
|
10040
|
+
return new GPUGeometry({
|
|
10041
|
+
topology: geometry.topology || "triangle-list",
|
|
10042
|
+
bufferLayout,
|
|
10043
|
+
vertexCount: geometry.vertexCount,
|
|
10044
|
+
indices,
|
|
10045
|
+
attributes
|
|
10046
|
+
});
|
|
10047
|
+
}
|
|
10048
|
+
function getIndexBufferFromGeometry(device, geometry) {
|
|
10049
|
+
if (!geometry.indices) {
|
|
10050
|
+
return void 0;
|
|
10051
|
+
}
|
|
10052
|
+
const data = geometry.indices.value;
|
|
10053
|
+
return device.createBuffer({
|
|
10054
|
+
usage: import_core34.Buffer.INDEX,
|
|
10055
|
+
data
|
|
10056
|
+
});
|
|
10057
|
+
}
|
|
10058
|
+
function getAttributeBuffersFromGeometry(device, geometry) {
|
|
10059
|
+
const bufferLayout = [];
|
|
10060
|
+
const attributes = {};
|
|
10061
|
+
for (const [attributeName, attribute] of Object.entries(geometry.attributes)) {
|
|
10062
|
+
let name = attributeName;
|
|
10063
|
+
switch (attributeName) {
|
|
10064
|
+
case "POSITION":
|
|
10065
|
+
name = "positions";
|
|
10066
|
+
break;
|
|
10067
|
+
case "NORMAL":
|
|
10068
|
+
name = "normals";
|
|
10069
|
+
break;
|
|
10070
|
+
case "TEXCOORD_0":
|
|
10071
|
+
name = "texCoords";
|
|
10072
|
+
break;
|
|
10073
|
+
}
|
|
10074
|
+
attributes[name] = device.createBuffer({
|
|
10075
|
+
data: attribute.value,
|
|
10076
|
+
id: `${attributeName}-buffer`
|
|
10077
|
+
});
|
|
10078
|
+
bufferLayout.push({
|
|
10079
|
+
name,
|
|
10080
|
+
format: `float32x${attribute.size}`
|
|
10081
|
+
});
|
|
10082
|
+
}
|
|
10083
|
+
const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices);
|
|
10084
|
+
return {
|
|
10085
|
+
attributes,
|
|
10086
|
+
bufferLayout,
|
|
10087
|
+
vertexCount
|
|
10088
|
+
};
|
|
10089
|
+
}
|
|
10090
|
+
|
|
10091
|
+
// ../../node_modules/@luma.gl/engine/dist/lib/pipeline-factory.js
|
|
10092
|
+
var import_core35 = __toESM(require_core2(), 1);
|
|
10093
|
+
var PipelineFactory = class {
|
|
10094
|
+
static getDefaultPipelineFactory(device) {
|
|
10095
|
+
device._lumaData.defaultPipelineFactory = device._lumaData.defaultPipelineFactory || new PipelineFactory(device);
|
|
10096
|
+
return device._lumaData.defaultPipelineFactory;
|
|
10097
|
+
}
|
|
10098
|
+
constructor(device) {
|
|
10099
|
+
this.device = void 0;
|
|
10100
|
+
this._hashCounter = 0;
|
|
10101
|
+
this._hashes = {};
|
|
10102
|
+
this._useCounts = {};
|
|
10103
|
+
this._pipelineCache = {};
|
|
10104
|
+
this.device = device;
|
|
10105
|
+
}
|
|
10106
|
+
createRenderPipeline(options) {
|
|
10107
|
+
const props = {
|
|
10108
|
+
...PipelineFactory.defaultProps,
|
|
10109
|
+
...options
|
|
10110
|
+
};
|
|
10111
|
+
const hash = this._hashRenderPipeline({
|
|
10112
|
+
...props
|
|
10113
|
+
});
|
|
10114
|
+
if (!this._pipelineCache[hash]) {
|
|
10115
|
+
const pipeline = this.device.createRenderPipeline({
|
|
10116
|
+
...props,
|
|
10117
|
+
vs: this.device.createShader({
|
|
10118
|
+
stage: "vertex",
|
|
10119
|
+
source: props.vs
|
|
10120
|
+
}),
|
|
10121
|
+
fs: props.fs ? this.device.createShader({
|
|
10122
|
+
stage: "fragment",
|
|
10123
|
+
source: props.fs
|
|
10124
|
+
}) : null
|
|
10125
|
+
});
|
|
10126
|
+
pipeline.hash = hash;
|
|
10127
|
+
this._pipelineCache[hash] = pipeline;
|
|
10128
|
+
this._useCounts[hash] = 0;
|
|
10129
|
+
}
|
|
10130
|
+
this._useCounts[hash]++;
|
|
10131
|
+
return this._pipelineCache[hash];
|
|
10132
|
+
}
|
|
10133
|
+
release(pipeline) {
|
|
10134
|
+
const hash = pipeline.hash;
|
|
10135
|
+
this._useCounts[hash]--;
|
|
10136
|
+
if (this._useCounts[hash] === 0) {
|
|
10137
|
+
this._pipelineCache[hash].destroy();
|
|
10138
|
+
delete this._pipelineCache[hash];
|
|
10139
|
+
delete this._useCounts[hash];
|
|
10140
|
+
}
|
|
10141
|
+
}
|
|
10142
|
+
_createRenderPipeline(props) {
|
|
10143
|
+
if (!props.fs) {
|
|
10144
|
+
throw new Error("fs");
|
|
10145
|
+
}
|
|
10146
|
+
const pipeline = this.device.createRenderPipeline({
|
|
10147
|
+
...props,
|
|
10148
|
+
vs: this.device.createShader({
|
|
10149
|
+
stage: "vertex",
|
|
10150
|
+
source: props.vs
|
|
10151
|
+
}),
|
|
10152
|
+
fs: props.fs ? this.device.createShader({
|
|
10153
|
+
stage: "fragment",
|
|
10154
|
+
source: props.fs
|
|
10155
|
+
}) : null
|
|
10156
|
+
});
|
|
10157
|
+
return pipeline;
|
|
10158
|
+
}
|
|
10159
|
+
_hashRenderPipeline(props) {
|
|
10160
|
+
const vsHash = this._getHash(props.vs);
|
|
10161
|
+
const fsHash = props.fs ? this._getHash(props.fs) : 0;
|
|
10162
|
+
const varyingHash = "-";
|
|
10163
|
+
switch (this.device.info.type) {
|
|
10164
|
+
case "webgpu":
|
|
10165
|
+
const parameterHash = this._getHash(JSON.stringify(props.parameters));
|
|
10166
|
+
const bufferLayoutHash = this._getHash(JSON.stringify(props.bufferLayout));
|
|
10167
|
+
return `${vsHash}/${fsHash}V${varyingHash}T${props.topology}P${parameterHash}BL${bufferLayoutHash}}`;
|
|
10168
|
+
default:
|
|
10169
|
+
return `${vsHash}/${fsHash}V${varyingHash}`;
|
|
10170
|
+
}
|
|
10171
|
+
}
|
|
10172
|
+
_getHash(key) {
|
|
10173
|
+
if (this._hashes[key] === void 0) {
|
|
10174
|
+
this._hashes[key] = this._hashCounter++;
|
|
10175
|
+
}
|
|
10176
|
+
return this._hashes[key];
|
|
10177
|
+
}
|
|
10178
|
+
};
|
|
10179
|
+
PipelineFactory.defaultProps = {
|
|
10180
|
+
...import_core35.RenderPipeline.defaultProps,
|
|
10181
|
+
vs: void 0,
|
|
10182
|
+
fs: void 0
|
|
10183
|
+
};
|
|
10184
|
+
|
|
10185
|
+
// ../../node_modules/@luma.gl/engine/dist/model/model.js
|
|
10186
|
+
var Model = class {
|
|
10187
|
+
constructor(device, props) {
|
|
10188
|
+
this.device = void 0;
|
|
10189
|
+
this.id = void 0;
|
|
10190
|
+
this.vs = void 0;
|
|
10191
|
+
this.fs = void 0;
|
|
10192
|
+
this.pipelineFactory = void 0;
|
|
10193
|
+
this.userData = {};
|
|
10194
|
+
this.parameters = void 0;
|
|
10195
|
+
this.topology = void 0;
|
|
10196
|
+
this.bufferLayout = void 0;
|
|
10197
|
+
this.vertexCount = void 0;
|
|
10198
|
+
this.instanceCount = 0;
|
|
10199
|
+
this.indexBuffer = null;
|
|
10200
|
+
this.bufferAttributes = {};
|
|
10201
|
+
this.constantAttributes = {};
|
|
10202
|
+
this.bindings = {};
|
|
10203
|
+
this.uniforms = {};
|
|
10204
|
+
this.pipeline = void 0;
|
|
10205
|
+
this.vertexArray = void 0;
|
|
10206
|
+
this._pipelineNeedsUpdate = "newly created";
|
|
10207
|
+
this._attributeInfos = {};
|
|
10208
|
+
this._gpuGeometry = null;
|
|
10209
|
+
this._getModuleUniforms = void 0;
|
|
10210
|
+
this.props = void 0;
|
|
10211
|
+
this.props = {
|
|
10212
|
+
...Model.defaultProps,
|
|
10213
|
+
...props
|
|
10214
|
+
};
|
|
10215
|
+
props = this.props;
|
|
10216
|
+
this.id = props.id || (0, import_core36.uid)("model");
|
|
10217
|
+
this.device = device;
|
|
10218
|
+
Object.assign(this.userData, props.userData);
|
|
10219
|
+
const platformInfo = {
|
|
10220
|
+
type: device.info.type,
|
|
10221
|
+
shaderLanguage: device.info.shadingLanguages[0],
|
|
10222
|
+
gpu: device.info.gpu,
|
|
10223
|
+
features: device.features
|
|
10224
|
+
};
|
|
10225
|
+
const {
|
|
10226
|
+
vs: vs5,
|
|
10227
|
+
fs: fs4,
|
|
10228
|
+
getUniforms: getUniforms4
|
|
10229
|
+
} = this.props.shaderAssembler.assembleShaders(platformInfo, this.props);
|
|
10230
|
+
this.vs = vs5;
|
|
10231
|
+
this.fs = fs4;
|
|
10232
|
+
this._getModuleUniforms = getUniforms4;
|
|
10233
|
+
this.vertexCount = this.props.vertexCount;
|
|
10234
|
+
this.instanceCount = this.props.instanceCount;
|
|
10235
|
+
this.topology = this.props.topology;
|
|
10236
|
+
this.bufferLayout = this.props.bufferLayout;
|
|
10237
|
+
this.parameters = this.props.parameters;
|
|
10238
|
+
if (props.geometry) {
|
|
10239
|
+
this._gpuGeometry = this.setGeometry(props.geometry);
|
|
10240
|
+
}
|
|
10241
|
+
this.pipelineFactory = props.pipelineFactory || PipelineFactory.getDefaultPipelineFactory(this.device);
|
|
10242
|
+
this.pipeline = this._updatePipeline();
|
|
10243
|
+
this.vertexArray = device.createVertexArray({
|
|
10244
|
+
renderPipeline: this.pipeline
|
|
10245
|
+
});
|
|
10246
|
+
if (this._gpuGeometry) {
|
|
10247
|
+
this._setGeometryAttributes(this._gpuGeometry);
|
|
10248
|
+
}
|
|
10249
|
+
if (props.vertexCount) {
|
|
10250
|
+
this.setVertexCount(props.vertexCount);
|
|
10251
|
+
}
|
|
10252
|
+
if (props.instanceCount) {
|
|
10253
|
+
this.setInstanceCount(props.instanceCount);
|
|
10254
|
+
}
|
|
10255
|
+
if (props.indices) {
|
|
10256
|
+
throw new Error("Model.props.indices removed. Use props.indexBuffer");
|
|
10257
|
+
}
|
|
10258
|
+
if (props.indexBuffer) {
|
|
10259
|
+
this.setIndexBuffer(props.indexBuffer);
|
|
10260
|
+
}
|
|
10261
|
+
if (props.attributes) {
|
|
10262
|
+
this.setAttributes(props.attributes);
|
|
10263
|
+
}
|
|
10264
|
+
if (props.constantAttributes) {
|
|
10265
|
+
this.setConstantAttributes(props.constantAttributes);
|
|
10266
|
+
}
|
|
10267
|
+
if (props.bindings) {
|
|
10268
|
+
this.setBindings(props.bindings);
|
|
10269
|
+
}
|
|
10270
|
+
if (props.uniforms) {
|
|
10271
|
+
this.setUniforms(props.uniforms);
|
|
10272
|
+
}
|
|
10273
|
+
if (props.moduleSettings) {
|
|
10274
|
+
this.updateModuleSettings(props.moduleSettings);
|
|
10275
|
+
}
|
|
10276
|
+
this.setUniforms(this._getModuleUniforms());
|
|
10277
|
+
Object.seal(this);
|
|
10278
|
+
}
|
|
10279
|
+
destroy() {
|
|
10280
|
+
this.pipelineFactory.release(this.pipeline);
|
|
10281
|
+
}
|
|
10282
|
+
draw(renderPass) {
|
|
10283
|
+
this.pipeline = this._updatePipeline();
|
|
10284
|
+
this.pipeline.setBindings(this.bindings);
|
|
10285
|
+
this.pipeline.setUniforms(this.uniforms);
|
|
10286
|
+
this.pipeline.draw({
|
|
10287
|
+
renderPass,
|
|
10288
|
+
vertexArray: this.vertexArray,
|
|
10289
|
+
vertexCount: this.vertexCount,
|
|
10290
|
+
instanceCount: this.instanceCount
|
|
10291
|
+
});
|
|
10292
|
+
}
|
|
10293
|
+
setGeometry(geometry) {
|
|
10294
|
+
const gpuGeometry = geometry && makeGPUGeometry(this.device, geometry);
|
|
10295
|
+
this.setTopology(gpuGeometry.topology || "triangle-list");
|
|
10296
|
+
this.bufferLayout = mergeBufferLayouts(this.bufferLayout, gpuGeometry.bufferLayout);
|
|
10297
|
+
if (this.vertexArray) {
|
|
10298
|
+
this._setGeometryAttributes(gpuGeometry);
|
|
10299
|
+
}
|
|
10300
|
+
return gpuGeometry;
|
|
10301
|
+
}
|
|
10302
|
+
_setGeometryAttributes(gpuGeometry) {
|
|
10303
|
+
this.vertexCount = gpuGeometry.vertexCount;
|
|
10304
|
+
this.setAttributes(gpuGeometry.attributes);
|
|
10305
|
+
this.setIndexBuffer(gpuGeometry.indices);
|
|
10306
|
+
}
|
|
10307
|
+
setTopology(topology) {
|
|
10308
|
+
if (topology !== this.topology) {
|
|
10309
|
+
this.topology = topology;
|
|
10310
|
+
this._setPipelineNeedsUpdate("topology");
|
|
10311
|
+
}
|
|
10312
|
+
}
|
|
10313
|
+
setBufferLayout(bufferLayout) {
|
|
10314
|
+
this.bufferLayout = this._gpuGeometry ? mergeBufferLayouts(bufferLayout, this._gpuGeometry.bufferLayout) : bufferLayout;
|
|
10315
|
+
this._setPipelineNeedsUpdate("bufferLayout");
|
|
10316
|
+
this.pipeline = this._updatePipeline();
|
|
10317
|
+
this.vertexArray = this.device.createVertexArray({
|
|
10318
|
+
renderPipeline: this.pipeline
|
|
10319
|
+
});
|
|
10320
|
+
if (this._gpuGeometry) {
|
|
10321
|
+
this._setGeometryAttributes(this._gpuGeometry);
|
|
10322
|
+
}
|
|
10323
|
+
}
|
|
10324
|
+
setParameters(parameters2) {
|
|
10325
|
+
if (!(0, import_core36.deepEqual)(parameters2, this.parameters, 2)) {
|
|
10326
|
+
this.parameters = parameters2;
|
|
10327
|
+
this._setPipelineNeedsUpdate("parameters");
|
|
10328
|
+
}
|
|
10329
|
+
}
|
|
10330
|
+
setVertexCount(vertexCount) {
|
|
10331
|
+
this.vertexCount = vertexCount;
|
|
10332
|
+
}
|
|
10333
|
+
setInstanceCount(instanceCount) {
|
|
10334
|
+
this.instanceCount = instanceCount;
|
|
10335
|
+
}
|
|
10336
|
+
setShaderModuleProps(props) {
|
|
10337
|
+
const uniforms = this._getModuleUniforms(props);
|
|
10338
|
+
const keys = Object.keys(uniforms).filter((k) => {
|
|
10339
|
+
const uniform = uniforms[k];
|
|
10340
|
+
return !(0, import_core36.isNumberArray)(uniform) && typeof uniform !== "number" && typeof uniform !== "boolean";
|
|
10341
|
+
});
|
|
10342
|
+
const bindings = {};
|
|
10343
|
+
for (const k of keys) {
|
|
10344
|
+
bindings[k] = uniforms[k];
|
|
10345
|
+
delete uniforms[k];
|
|
10346
|
+
}
|
|
10347
|
+
Object.assign(this.uniforms, uniforms);
|
|
10348
|
+
Object.assign(this.bindings, bindings);
|
|
10349
|
+
}
|
|
10350
|
+
updateModuleSettings(props) {
|
|
10351
|
+
this.setShaderModuleProps(props);
|
|
10352
|
+
}
|
|
10353
|
+
setBindings(bindings) {
|
|
10354
|
+
Object.assign(this.bindings, bindings);
|
|
10355
|
+
}
|
|
10356
|
+
setUniforms(uniforms) {
|
|
10357
|
+
this.pipeline.setUniforms(uniforms);
|
|
10358
|
+
Object.assign(this.uniforms, uniforms);
|
|
10359
|
+
}
|
|
10360
|
+
setIndexBuffer(indexBuffer) {
|
|
10361
|
+
this.vertexArray.setIndexBuffer(indexBuffer);
|
|
10362
|
+
}
|
|
10363
|
+
setAttributes(buffers) {
|
|
10364
|
+
if (buffers.indices) {
|
|
10365
|
+
import_core36.log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`);
|
|
10366
|
+
}
|
|
10367
|
+
for (const [bufferName, buffer] of Object.entries(buffers)) {
|
|
10368
|
+
var _bufferLayout$attribu;
|
|
10369
|
+
const bufferLayout = this.bufferLayout.find((layout) => layout.name === bufferName);
|
|
10370
|
+
if (!bufferLayout) {
|
|
10371
|
+
continue;
|
|
10372
|
+
}
|
|
10373
|
+
const attributeNames = bufferLayout.attributes ? (_bufferLayout$attribu = bufferLayout.attributes) === null || _bufferLayout$attribu === void 0 ? void 0 : _bufferLayout$attribu.map((layout) => layout.attribute) : [bufferLayout.name];
|
|
10374
|
+
let set2 = false;
|
|
10375
|
+
for (const attributeName of attributeNames) {
|
|
10376
|
+
const attributeInfo = this._attributeInfos[attributeName];
|
|
10377
|
+
if (attributeInfo) {
|
|
10378
|
+
this.vertexArray.setBuffer(attributeInfo.location, buffer);
|
|
10379
|
+
set2 = true;
|
|
10380
|
+
}
|
|
10381
|
+
}
|
|
10382
|
+
if (!set2) {
|
|
10383
|
+
import_core36.log.warn(`Model(${this.id}): Ignoring buffer "${buffer.id}" for unknown attribute "${bufferName}"`)();
|
|
10384
|
+
}
|
|
10385
|
+
}
|
|
10386
|
+
}
|
|
10387
|
+
setConstantAttributes(attributes) {
|
|
10388
|
+
for (const [attributeName, value] of Object.entries(attributes)) {
|
|
10389
|
+
const attributeInfo = this._attributeInfos[attributeName];
|
|
10390
|
+
if (attributeInfo) {
|
|
10391
|
+
this.vertexArray.setConstant(attributeInfo.location, value);
|
|
10392
|
+
} else {
|
|
10393
|
+
import_core36.log.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${attributeName}"`)();
|
|
10394
|
+
}
|
|
10395
|
+
}
|
|
10396
|
+
}
|
|
10397
|
+
_setPipelineNeedsUpdate(reason) {
|
|
10398
|
+
this._pipelineNeedsUpdate = this._pipelineNeedsUpdate || reason;
|
|
10399
|
+
}
|
|
10400
|
+
_updatePipeline() {
|
|
10401
|
+
if (this._pipelineNeedsUpdate) {
|
|
10402
|
+
if (this.pipeline) {
|
|
10403
|
+
import_core36.log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
|
|
10404
|
+
}
|
|
10405
|
+
this._pipelineNeedsUpdate = false;
|
|
10406
|
+
this.pipeline = this.device.createRenderPipeline({
|
|
10407
|
+
...this.props,
|
|
10408
|
+
bufferLayout: this.bufferLayout,
|
|
10409
|
+
topology: this.topology,
|
|
10410
|
+
parameters: this.parameters,
|
|
10411
|
+
vs: this.device.createShader({
|
|
10412
|
+
id: "{$this.id}-vertex",
|
|
10413
|
+
stage: "vertex",
|
|
10414
|
+
source: this.vs
|
|
10415
|
+
}),
|
|
10416
|
+
fs: this.fs ? this.device.createShader({
|
|
10417
|
+
id: "{$this.id}-fragment",
|
|
10418
|
+
stage: "fragment",
|
|
10419
|
+
source: this.fs
|
|
10420
|
+
}) : null
|
|
10421
|
+
});
|
|
10422
|
+
this._attributeInfos = (0, import_core37.getAttributeInfosFromLayouts)(this.pipeline.shaderLayout, this.bufferLayout);
|
|
10423
|
+
}
|
|
10424
|
+
return this.pipeline;
|
|
10425
|
+
}
|
|
10426
|
+
};
|
|
10427
|
+
Model.defaultProps = {
|
|
10428
|
+
...import_core36.RenderPipeline.defaultProps,
|
|
10429
|
+
vs: null,
|
|
10430
|
+
fs: null,
|
|
10431
|
+
id: "unnamed",
|
|
10432
|
+
handle: void 0,
|
|
10433
|
+
userData: {},
|
|
10434
|
+
defines: {},
|
|
10435
|
+
modules: [],
|
|
10436
|
+
moduleSettings: {},
|
|
10437
|
+
geometry: null,
|
|
10438
|
+
indexBuffer: null,
|
|
10439
|
+
attributes: {},
|
|
10440
|
+
constantAttributes: {},
|
|
10441
|
+
pipelineFactory: void 0,
|
|
10442
|
+
shaderAssembler: ShaderAssembler.getDefaultShaderAssembler()
|
|
10443
|
+
};
|
|
10444
|
+
function mergeBufferLayouts(layouts1, layouts2) {
|
|
10445
|
+
const layouts = [...layouts1];
|
|
10446
|
+
for (const attribute of layouts2) {
|
|
10447
|
+
const index = layouts.findIndex((attribute2) => attribute2.name === attribute.name);
|
|
10448
|
+
if (index < 0) {
|
|
10449
|
+
layouts.push(attribute);
|
|
10450
|
+
} else {
|
|
10451
|
+
layouts[index] = attribute;
|
|
10452
|
+
}
|
|
10453
|
+
}
|
|
10454
|
+
return layouts;
|
|
10455
|
+
}
|
|
10456
|
+
|
|
10457
|
+
// src/data-filter/aggregator.ts
|
|
10458
|
+
var AGGREGATE_VS = `#define SHADER_NAME data-filter-vertex-shader
|
|
10459
|
+
|
|
10460
|
+
#ifdef FLOAT_TARGET
|
|
10461
|
+
attribute float filterIndices;
|
|
10462
|
+
attribute float filterPrevIndices;
|
|
10463
|
+
#else
|
|
10464
|
+
attribute vec2 filterIndices;
|
|
10465
|
+
attribute vec2 filterPrevIndices;
|
|
10466
|
+
#endif
|
|
10467
|
+
|
|
10468
|
+
varying vec4 vColor;
|
|
10469
|
+
const float component = 1.0 / 255.0;
|
|
10470
|
+
|
|
10471
|
+
void main() {
|
|
10472
|
+
#ifdef FLOAT_TARGET
|
|
10473
|
+
dataFilter_value *= float(filterIndices != filterPrevIndices);
|
|
10474
|
+
gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
|
|
10475
|
+
vColor = vec4(0.0, 0.0, 0.0, 1.0);
|
|
10476
|
+
#else
|
|
10477
|
+
// Float texture is not supported: pack result into 4 channels x 256 px x 64px
|
|
10478
|
+
dataFilter_value *= float(filterIndices.x != filterPrevIndices.x);
|
|
10479
|
+
float col = filterIndices.x;
|
|
10480
|
+
float row = filterIndices.y * 4.0;
|
|
10481
|
+
float channel = floor(row);
|
|
10482
|
+
row = fract(row);
|
|
10483
|
+
vColor = component * vec4(bvec4(channel == 0.0, channel == 1.0, channel == 2.0, channel == 3.0));
|
|
10484
|
+
gl_Position = vec4(col * 2.0 - 1.0, row * 2.0 - 1.0, 0.0, 1.0);
|
|
10485
|
+
#endif
|
|
10486
|
+
gl_PointSize = 1.0;
|
|
10487
|
+
}
|
|
10488
|
+
`;
|
|
10489
|
+
var AGGREGATE_FS = `#define SHADER_NAME data-filter-fragment-shader
|
|
10490
|
+
precision highp float;
|
|
10491
|
+
|
|
10492
|
+
varying vec4 vColor;
|
|
10493
|
+
|
|
10494
|
+
void main() {
|
|
10495
|
+
if (dataFilter_value < 0.5) {
|
|
10496
|
+
discard;
|
|
10497
|
+
}
|
|
10498
|
+
gl_FragColor = vColor;
|
|
10499
|
+
}
|
|
10500
|
+
`;
|
|
10501
|
+
function supportsFloatTarget(device) {
|
|
10502
|
+
const gl = device.gl;
|
|
10503
|
+
return Boolean(gl.getExtension("EXT_float_blend") && (gl.getExtension("EXT_color_buffer_float") || gl.getExtension("WEBGL_color_buffer_float")));
|
|
10504
|
+
}
|
|
10505
|
+
function getFramebuffer3(device, useFloatTarget) {
|
|
10506
|
+
if (useFloatTarget) {
|
|
10507
|
+
return device.createFramebuffer({
|
|
10508
|
+
width: 1,
|
|
10509
|
+
height: 1,
|
|
10510
|
+
colorAttachments: [device.createTexture({
|
|
10511
|
+
format: device.info.type === "webgl2" ? "rgba32float" : "rgba8unorm",
|
|
10512
|
+
type: 5126,
|
|
10513
|
+
mipmaps: false
|
|
10514
|
+
})]
|
|
10515
|
+
});
|
|
10516
|
+
}
|
|
10517
|
+
return device.createFramebuffer({
|
|
10518
|
+
width: 256,
|
|
10519
|
+
height: 64,
|
|
10520
|
+
colorAttachments: [device.createTexture({
|
|
10521
|
+
format: "rgba8unorm",
|
|
10522
|
+
type: 5126,
|
|
10523
|
+
mipmaps: false
|
|
10524
|
+
})]
|
|
10525
|
+
});
|
|
10681
10526
|
}
|
|
10682
|
-
function
|
|
10683
|
-
|
|
10684
|
-
|
|
10685
|
-
|
|
10686
|
-
|
|
10687
|
-
|
|
10688
|
-
|
|
10689
|
-
|
|
10527
|
+
function getModel(device, shaderOptions, useFloatTarget) {
|
|
10528
|
+
shaderOptions.defines.NON_INSTANCED_MODEL = 1;
|
|
10529
|
+
if (useFloatTarget) {
|
|
10530
|
+
shaderOptions.defines.FLOAT_TARGET = 1;
|
|
10531
|
+
}
|
|
10532
|
+
return new Model(device, {
|
|
10533
|
+
id: "data-filter-aggregation-model",
|
|
10534
|
+
vertexCount: 1,
|
|
10535
|
+
isInstanced: false,
|
|
10536
|
+
drawMode: 0,
|
|
10537
|
+
vs: AGGREGATE_VS,
|
|
10538
|
+
fs: AGGREGATE_FS,
|
|
10539
|
+
...shaderOptions
|
|
10540
|
+
});
|
|
10690
10541
|
}
|
|
10691
|
-
var
|
|
10692
|
-
|
|
10693
|
-
|
|
10694
|
-
|
|
10695
|
-
|
|
10696
|
-
|
|
10697
|
-
|
|
10698
|
-
|
|
10699
|
-
|
|
10700
|
-
|
|
10701
|
-
|
|
10702
|
-
|
|
10703
|
-
|
|
10704
|
-
|
|
10542
|
+
var parameters = {
|
|
10543
|
+
blend: true,
|
|
10544
|
+
blendFunc: [1, 1, 1, 1],
|
|
10545
|
+
blendEquation: [32774, 32774],
|
|
10546
|
+
depthTest: false
|
|
10547
|
+
};
|
|
10548
|
+
|
|
10549
|
+
// src/data-filter/data-filter-extension.ts
|
|
10550
|
+
var defaultProps2 = {
|
|
10551
|
+
getFilterValue: {
|
|
10552
|
+
type: "accessor",
|
|
10553
|
+
value: 0
|
|
10554
|
+
},
|
|
10555
|
+
onFilteredItemsChange: {
|
|
10556
|
+
type: "function",
|
|
10557
|
+
value: null,
|
|
10558
|
+
optional: true
|
|
10559
|
+
},
|
|
10560
|
+
filterEnabled: true,
|
|
10561
|
+
filterRange: [-1, 1],
|
|
10562
|
+
filterSoftRange: null,
|
|
10563
|
+
filterTransformSize: true,
|
|
10564
|
+
filterTransformColor: true
|
|
10565
|
+
};
|
|
10566
|
+
var DATA_TYPE_FROM_SIZE = {
|
|
10567
|
+
1: "float",
|
|
10568
|
+
2: "vec2",
|
|
10569
|
+
3: "vec3",
|
|
10570
|
+
4: "vec4"
|
|
10571
|
+
};
|
|
10572
|
+
var DataFilterExtension = class extends import_core38.LayerExtension {
|
|
10573
|
+
constructor({
|
|
10574
|
+
filterSize = 1,
|
|
10575
|
+
fp64: fp642 = false,
|
|
10576
|
+
countItems = false
|
|
10577
|
+
} = {}) {
|
|
10578
|
+
if (!DATA_TYPE_FROM_SIZE[filterSize]) {
|
|
10579
|
+
throw new Error("filterSize out of range");
|
|
10705
10580
|
}
|
|
10706
|
-
|
|
10707
|
-
|
|
10581
|
+
super({
|
|
10582
|
+
filterSize,
|
|
10583
|
+
fp64: fp642,
|
|
10584
|
+
countItems
|
|
10585
|
+
});
|
|
10586
|
+
}
|
|
10587
|
+
getShaders(extension) {
|
|
10588
|
+
const {
|
|
10589
|
+
filterSize,
|
|
10590
|
+
fp64: fp642
|
|
10591
|
+
} = extension.opts;
|
|
10592
|
+
return {
|
|
10593
|
+
modules: [fp642 ? shaderModule64 : shaderModule],
|
|
10594
|
+
defines: {
|
|
10595
|
+
DATAFILTER_TYPE: DATA_TYPE_FROM_SIZE[filterSize],
|
|
10596
|
+
DATAFILTER_DOUBLE: Boolean(fp642)
|
|
10597
|
+
}
|
|
10598
|
+
};
|
|
10599
|
+
}
|
|
10600
|
+
initializeState(context, extension) {
|
|
10601
|
+
const attributeManager = this.getAttributeManager();
|
|
10602
|
+
if (attributeManager) {
|
|
10603
|
+
attributeManager.add({
|
|
10604
|
+
filterValues: {
|
|
10605
|
+
size: extension.opts.filterSize,
|
|
10606
|
+
type: extension.opts.fp64 ? 5130 : 5126,
|
|
10607
|
+
accessor: "getFilterValue",
|
|
10608
|
+
shaderAttributes: {
|
|
10609
|
+
filterValues: {
|
|
10610
|
+
divisor: 0
|
|
10611
|
+
},
|
|
10612
|
+
instanceFilterValues: {
|
|
10613
|
+
divisor: 1
|
|
10614
|
+
}
|
|
10615
|
+
}
|
|
10616
|
+
}
|
|
10617
|
+
});
|
|
10708
10618
|
}
|
|
10709
|
-
|
|
10710
|
-
|
|
10711
|
-
}
|
|
10712
|
-
|
|
10619
|
+
const {
|
|
10620
|
+
device
|
|
10621
|
+
} = this.context;
|
|
10622
|
+
if (attributeManager && extension.opts.countItems) {
|
|
10623
|
+
const useFloatTarget = supportsFloatTarget(device);
|
|
10624
|
+
attributeManager.add({
|
|
10625
|
+
filterIndices: {
|
|
10626
|
+
size: useFloatTarget ? 1 : 2,
|
|
10627
|
+
vertexOffset: 1,
|
|
10628
|
+
type: 5121,
|
|
10629
|
+
normalized: true,
|
|
10630
|
+
accessor: (object, {
|
|
10631
|
+
index
|
|
10632
|
+
}) => {
|
|
10633
|
+
const i = object && object.__source ? object.__source.index : index;
|
|
10634
|
+
return useFloatTarget ? (i + 1) % 255 : [(i + 1) % 255, Math.floor(i / 255) % 255];
|
|
10635
|
+
},
|
|
10636
|
+
shaderAttributes: {
|
|
10637
|
+
filterPrevIndices: {
|
|
10638
|
+
vertexOffset: 0
|
|
10639
|
+
},
|
|
10640
|
+
filterIndices: {
|
|
10641
|
+
vertexOffset: 1
|
|
10642
|
+
}
|
|
10643
|
+
}
|
|
10644
|
+
}
|
|
10645
|
+
});
|
|
10646
|
+
const filterFBO = getFramebuffer3(device, useFloatTarget);
|
|
10647
|
+
const filterModel = getModel(device, extension.getShaders.call(this, extension), useFloatTarget);
|
|
10648
|
+
this.setState({
|
|
10649
|
+
filterFBO,
|
|
10650
|
+
filterModel
|
|
10651
|
+
});
|
|
10713
10652
|
}
|
|
10714
|
-
|
|
10715
|
-
|
|
10716
|
-
|
|
10717
|
-
|
|
10718
|
-
|
|
10719
|
-
|
|
10720
|
-
|
|
10721
|
-
|
|
10653
|
+
}
|
|
10654
|
+
updateState({
|
|
10655
|
+
props,
|
|
10656
|
+
oldProps
|
|
10657
|
+
}) {
|
|
10658
|
+
if (this.state.filterModel) {
|
|
10659
|
+
const attributeManager = this.getAttributeManager();
|
|
10660
|
+
const filterNeedsUpdate = attributeManager.attributes.filterValues.needsUpdate() || props.filterEnabled !== oldProps.filterEnabled || props.filterRange !== oldProps.filterRange || props.filterSoftRange !== oldProps.filterSoftRange;
|
|
10661
|
+
if (filterNeedsUpdate) {
|
|
10662
|
+
this.setState({
|
|
10663
|
+
filterNeedsUpdate
|
|
10664
|
+
});
|
|
10665
|
+
}
|
|
10722
10666
|
}
|
|
10723
|
-
|
|
10724
|
-
|
|
10725
|
-
|
|
10667
|
+
}
|
|
10668
|
+
draw(params, extension) {
|
|
10669
|
+
const filterFBO = this.state.filterFBO;
|
|
10670
|
+
const filterModel = this.state.filterModel;
|
|
10671
|
+
const filterNeedsUpdate = this.state.filterNeedsUpdate;
|
|
10672
|
+
const {
|
|
10673
|
+
onFilteredItemsChange
|
|
10674
|
+
} = this.props;
|
|
10675
|
+
if (filterNeedsUpdate && onFilteredItemsChange && filterModel) {
|
|
10676
|
+
const {
|
|
10677
|
+
attributes: {
|
|
10678
|
+
filterValues,
|
|
10679
|
+
filterIndices
|
|
10680
|
+
}
|
|
10681
|
+
} = this.getAttributeManager();
|
|
10682
|
+
filterModel.setVertexCount(this.getNumInstances());
|
|
10683
|
+
clear(this.context.device, {
|
|
10684
|
+
framebuffer: filterFBO,
|
|
10685
|
+
color: [0, 0, 0, 0]
|
|
10686
|
+
});
|
|
10687
|
+
filterModel.updateModuleSettings(params.moduleParameters);
|
|
10688
|
+
filterModel.setAttributes({
|
|
10689
|
+
...filterValues.getValue(),
|
|
10690
|
+
...filterIndices?.getValue()
|
|
10691
|
+
});
|
|
10692
|
+
withGLParameters(filterModel.device, {
|
|
10693
|
+
framebuffer: filterFBO,
|
|
10694
|
+
...parameters,
|
|
10695
|
+
viewport: [0, 0, filterFBO.width, filterFBO.height]
|
|
10696
|
+
}, () => {
|
|
10697
|
+
filterModel.draw(this.context.renderPass);
|
|
10698
|
+
});
|
|
10699
|
+
const color = readPixelsToArray(filterFBO);
|
|
10700
|
+
let count = 0;
|
|
10701
|
+
for (let i = 0; i < color.length; i++) {
|
|
10702
|
+
count += color[i];
|
|
10703
|
+
}
|
|
10704
|
+
onFilteredItemsChange({
|
|
10705
|
+
id: this.id,
|
|
10706
|
+
count
|
|
10707
|
+
});
|
|
10708
|
+
this.state.filterNeedsUpdate = false;
|
|
10709
|
+
}
|
|
10710
|
+
}
|
|
10711
|
+
finalizeState() {
|
|
10712
|
+
const filterFBO = this.state.filterFBO;
|
|
10713
|
+
const filterModel = this.state.filterModel;
|
|
10714
|
+
filterFBO?.destroy();
|
|
10715
|
+
filterModel?.destroy();
|
|
10716
|
+
}
|
|
10717
|
+
};
|
|
10718
|
+
__publicField(DataFilterExtension, "defaultProps", defaultProps2);
|
|
10719
|
+
__publicField(DataFilterExtension, "extensionName", "DataFilterExtension");
|
|
10720
|
+
|
|
10721
|
+
// src/fp64/fp64-extension.ts
|
|
10722
|
+
var import_core40 = __toESM(require_core());
|
|
10726
10723
|
|
|
10727
10724
|
// src/fp64/project64.ts
|
|
10728
10725
|
var import_core39 = __toESM(require_core());
|