@deck.gl/extensions 8.6.2 → 8.7.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +108 -108
- package/dist/es5/brushing/brushing.js +49 -80
- package/dist/es5/brushing/brushing.js.map +1 -1
- package/dist/es5/brushing/shader-module.js +15 -16
- package/dist/es5/brushing/shader-module.js.map +1 -1
- package/dist/es5/clip/clip.js +35 -62
- package/dist/es5/clip/clip.js.map +1 -1
- package/dist/es5/data-filter/aggregator.js +14 -19
- package/dist/es5/data-filter/aggregator.js.map +1 -1
- package/dist/es5/data-filter/data-filter.js +148 -172
- package/dist/es5/data-filter/data-filter.js.map +1 -1
- package/dist/es5/data-filter/shader-module.js +37 -58
- package/dist/es5/data-filter/shader-module.js.map +1 -1
- package/dist/es5/fill-style/fill-style.js +158 -244
- package/dist/es5/fill-style/fill-style.js.map +1 -1
- package/dist/es5/fill-style/shaders.glsl.js +19 -18
- package/dist/es5/fill-style/shaders.glsl.js.map +1 -1
- package/dist/es5/fp64/fp64.js +12 -36
- package/dist/es5/fp64/fp64.js.map +1 -1
- package/dist/es5/fp64/project64.js +20 -18
- package/dist/es5/fp64/project64.js.map +1 -1
- package/dist/es5/index.js +7 -7
- package/dist/es5/path-style/path-style.js +89 -121
- package/dist/es5/path-style/path-style.js.map +1 -1
- package/dist/es5/path-style/shaders.glsl.js +2 -2
- package/dist/es5/path-style/shaders.glsl.js.map +1 -1
- package/dist/esm/clip/clip.js.map +1 -1
- package/dist/esm/data-filter/aggregator.js.map +1 -1
- package/dist/esm/fill-style/fill-style.js.map +1 -1
- package/dist.min.js +1 -1
- package/package.json +2 -2
- package/src/clip/clip.js +1 -1
- package/src/data-filter/aggregator.js +107 -107
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/clip/clip.js"],"names":["defaultProps","clipBounds","shaderFunction","shaderModuleVs","name","vs","injectionVs","shaderModuleFs","fs","injectionFs","ClipExtension","clipByInstance","getAttributeManager","attributes","props","state","modules","inject","uniforms","clip_bounds","corner0","projectPosition","corner1","Math","min","max","
|
|
1
|
+
{"version":3,"sources":["../../../src/clip/clip.js"],"names":["defaultProps","clipBounds","shaderFunction","shaderModuleVs","name","vs","injectionVs","shaderModuleFs","fs","injectionFs","ClipExtension","LayerExtension","getShaders","clipByInstance","getAttributeManager","attributes","props","state","modules","inject","draw","uniforms","clip_bounds","corner0","projectPosition","corner1","Math","min","max","extensionName"],"mappings":";;;;;;;AAoBA;;AAEA,MAAMA,YAAY,GAAG;AACnBC,EAAAA,UAAU,EAAE,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV;AADO,CAArB;AAIA,MAAMC,cAAc,oNAApB;AAYA,MAAMC,cAAc,GAAG;AACrBC,EAAAA,IAAI,EAAE,SADe;AAErBC,EAAAA,EAAE,EAAEH;AAFiB,CAAvB;AAKA,MAAMI,WAAW,GAAG;AAClB,iDADkB;AAIlB,6GAJkB;AAOlB,iDAPkB;AAUlB;AAVkB,CAApB;AAmBA,MAAMC,cAAc,GAAG;AACrBH,EAAAA,IAAI,EAAE,SADe;AAErBI,EAAAA,EAAE,EAAEN;AAFiB,CAAvB;AAKA,MAAMO,WAAW,GAAG;AAClB,qDADkB;AAIlB,qFAJkB;AAOlB,qDAPkB;AAUlB;AAVkB,CAApB;;AAee,MAAMC,aAAN,SAA4BC,oBAA5B,CAA2C;AACxDC,EAAAA,UAAU,GAAG;AAKX,QAAIC,cAAc,IAAG,uBAAuB,KAAKC,mBAAL,GAA2BC,UAArD,CAAlB;;AAEA,QAAI,oBAAoB,KAAKC,KAA7B,EAAoC;AAClCH,MAAAA,cAAc,GAAG,KAAKG,KAAL,CAAWH,cAA5B;AACD;;AACD,SAAKI,KAAL,CAAWJ,cAAX,GAA4BA,cAA5B;AAEA,WAAOA,cAAc,GACjB;AACEK,MAAAA,OAAO,EAAE,CAACf,cAAD,CADX;AAEEgB,MAAAA,MAAM,E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Inc.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n\nimport {LayerExtension} from '@deck.gl/core';\n\nconst defaultProps = {\n clipBounds: [0, 0, 1, 1]\n};\n\nconst shaderFunction = `\nuniform vec4 clip_bounds;\n\nbool clip_isInBounds(vec2 position) {\n return position.x >= clip_bounds[0] && position.y >= clip_bounds[1] && position.x < clip_bounds[2] && position.y < clip_bounds[3];\n}\n`;\n\n/*\n * The vertex-shader version clips geometries by their anchor position\n * e.g. ScatterplotLayer - show if the center of a circle is within bounds\n */\nconst shaderModuleVs = {\n name: 'clip-vs',\n vs: shaderFunction\n};\n\nconst injectionVs = {\n 'vs:#decl': `\nvarying float clip_isVisible;\n`,\n 'vs:DECKGL_FILTER_GL_POSITION': `\n clip_isVisible = float(clip_isInBounds(geometry.worldPosition.xy));\n`,\n 'fs:#decl': `\nvarying float clip_isVisible;\n`,\n 'fs:DECKGL_FILTER_COLOR': `\n if (clip_isVisible < 0.5) discard;\n`\n};\n\n/*\n * The fragment-shader version clips pixels at the bounds\n * e.g. PolygonLayer - show the part of the polygon that intersect with the bounds\n */\nconst shaderModuleFs = {\n name: 'clip-fs',\n fs: shaderFunction\n};\n\nconst injectionFs = {\n 'vs:#decl': `\nvarying vec2 clip_commonPosition;\n`,\n 'vs:DECKGL_FILTER_GL_POSITION': `\n clip_commonPosition = geometry.position.xy;\n`,\n 'fs:#decl': `\nvarying vec2 clip_commonPosition;\n`,\n 'fs:DECKGL_FILTER_COLOR': `\n if (!clip_isInBounds(clip_commonPosition)) discard;\n`\n};\n\nexport default class ClipExtension extends LayerExtension {\n getShaders() {\n // If `clipByInstance: true`, the entire object is shown/hidden based on its anchor position (done by vertex shader)\n // Otherwise, the object is trimmed by the clip bounds (done by fragment shader)\n\n // Default behavior: consider a layer instanced if it has attribute `instancePositions`\n let clipByInstance = 'instancePositions' in this.getAttributeManager().attributes;\n // Users can override by setting the `clipByInstance` prop\n if ('clipByInstance' in this.props) {\n clipByInstance = this.props.clipByInstance;\n }\n this.state.clipByInstance = clipByInstance;\n\n return clipByInstance\n ? {\n modules: [shaderModuleVs],\n inject: injectionVs\n }\n : {\n modules: [shaderModuleFs],\n inject: injectionFs\n };\n }\n\n draw({uniforms}) {\n const {clipBounds = defaultProps.clipBounds} = this.props;\n if (this.state.clipByInstance) {\n uniforms.clip_bounds = clipBounds;\n } else {\n const corner0 = this.projectPosition([clipBounds[0], clipBounds[1], 0]);\n const corner1 = this.projectPosition([clipBounds[2], clipBounds[3], 0]);\n\n uniforms.clip_bounds = [\n Math.min(corner0[0], corner1[0]),\n Math.min(corner0[1], corner1[1]),\n Math.max(corner0[0], corner1[0]),\n Math.max(corner0[1], corner1[1])\n ];\n }\n }\n}\n\nClipExtension.extensionName = 'ClipExtension';\nClipExtension.defaultProps = defaultProps;\n"],"file":"clip.js"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
@@ -10,16 +8,10 @@ exports.getFramebuffer = getFramebuffer;
|
|
|
10
8
|
exports.getModel = getModel;
|
|
11
9
|
exports.parameters = void 0;
|
|
12
10
|
|
|
13
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
-
|
|
15
11
|
var _core = require("@luma.gl/core");
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
20
|
-
|
|
21
|
-
var AGGREGATE_VS = "#define SHADER_NAME data-filter-vertex-shader\n\n#ifdef FLOAT_TARGET\n attribute float filterIndices;\n attribute float filterPrevIndices;\n#else\n attribute vec2 filterIndices;\n attribute vec2 filterPrevIndices;\n#endif\n\nvarying vec4 vColor;\nconst float component = 1.0 / 255.0;\n\nvoid main() {\n #ifdef FLOAT_TARGET\n dataFilter_value *= float(filterIndices != filterPrevIndices);\n gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n vColor = vec4(0.0, 0.0, 0.0, 1.0);\n #else\n // Float texture is not supported: pack result into 4 channels x 256 px x 64px\n dataFilter_value *= float(filterIndices.x != filterPrevIndices.x);\n float col = filterIndices.x;\n float row = filterIndices.y * 4.0;\n float channel = floor(row);\n row = fract(row);\n vColor = component * vec4(bvec4(channel == 0.0, channel == 1.0, channel == 2.0, channel == 3.0));\n gl_Position = vec4(col * 2.0 - 1.0, row * 2.0 - 1.0, 0.0, 1.0);\n #endif\n gl_PointSize = 1.0;\n}\n";
|
|
22
|
-
var AGGREGATE_FS = "#define SHADER_NAME data-filter-fragment-shader\nprecision highp float;\n\nvarying vec4 vColor;\n\nvoid main() {\n if (dataFilter_value < 0.5) {\n discard;\n }\n gl_FragColor = vColor;\n}\n";
|
|
13
|
+
const AGGREGATE_VS = "#define SHADER_NAME data-filter-vertex-shader\n\n#ifdef FLOAT_TARGET\n attribute float filterIndices;\n attribute float filterPrevIndices;\n#else\n attribute vec2 filterIndices;\n attribute vec2 filterPrevIndices;\n#endif\n\nvarying vec4 vColor;\nconst float component = 1.0 / 255.0;\n\nvoid main() {\n #ifdef FLOAT_TARGET\n dataFilter_value *= float(filterIndices != filterPrevIndices);\n gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n vColor = vec4(0.0, 0.0, 0.0, 1.0);\n #else\n // Float texture is not supported: pack result into 4 channels x 256 px x 64px\n dataFilter_value *= float(filterIndices.x != filterPrevIndices.x);\n float col = filterIndices.x;\n float row = filterIndices.y * 4.0;\n float channel = floor(row);\n row = fract(row);\n vColor = component * vec4(bvec4(channel == 0.0, channel == 1.0, channel == 2.0, channel == 3.0));\n gl_Position = vec4(col * 2.0 - 1.0, row * 2.0 - 1.0, 0.0, 1.0);\n #endif\n gl_PointSize = 1.0;\n}\n";
|
|
14
|
+
const AGGREGATE_FS = "#define SHADER_NAME data-filter-fragment-shader\nprecision highp float;\n\nvarying vec4 vColor;\n\nvoid main() {\n if (dataFilter_value < 0.5) {\n discard;\n }\n gl_FragColor = vColor;\n}\n";
|
|
23
15
|
|
|
24
16
|
function supportsFloatTarget(gl) {
|
|
25
17
|
return gl.getExtension('EXT_float_blend') && (gl.getExtension('EXT_color_buffer_float') || gl.getExtension('WEBGL_color_buffer_float'));
|
|
@@ -30,11 +22,13 @@ function getFramebuffer(gl, useFloatTarget) {
|
|
|
30
22
|
return new _core.Framebuffer(gl, {
|
|
31
23
|
width: 1,
|
|
32
24
|
height: 1,
|
|
33
|
-
attachments:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
attachments: {
|
|
26
|
+
[36064]: new _core.Texture2D(gl, {
|
|
27
|
+
format: (0, _core.isWebGL2)(gl) ? 34836 : 6408,
|
|
28
|
+
type: 5126,
|
|
29
|
+
mipmaps: false
|
|
30
|
+
})
|
|
31
|
+
}
|
|
38
32
|
});
|
|
39
33
|
}
|
|
40
34
|
|
|
@@ -52,17 +46,18 @@ function getModel(gl, shaderOptions, useFloatTarget) {
|
|
|
52
46
|
shaderOptions.defines.FLOAT_TARGET = 1;
|
|
53
47
|
}
|
|
54
48
|
|
|
55
|
-
return new _core.Model(gl,
|
|
49
|
+
return new _core.Model(gl, {
|
|
56
50
|
id: 'data-filter-aggregation-model',
|
|
57
51
|
vertexCount: 1,
|
|
58
52
|
isInstanced: false,
|
|
59
53
|
drawMode: 0,
|
|
60
54
|
vs: AGGREGATE_VS,
|
|
61
|
-
fs: AGGREGATE_FS
|
|
62
|
-
|
|
55
|
+
fs: AGGREGATE_FS,
|
|
56
|
+
...shaderOptions
|
|
57
|
+
});
|
|
63
58
|
}
|
|
64
59
|
|
|
65
|
-
|
|
60
|
+
const parameters = {
|
|
66
61
|
blend: true,
|
|
67
62
|
blendFunc: [1, 1, 1, 1],
|
|
68
63
|
blendEquation: [32774, 32774],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/data-filter/aggregator.js"],"names":["AGGREGATE_VS","AGGREGATE_FS","supportsFloatTarget","gl","getExtension","getFramebuffer","useFloatTarget","Framebuffer","width","height","attachments","Texture2D","format","type","mipmaps","depth","getModel","shaderOptions","defines","NON_INSTANCED_MODEL","FLOAT_TARGET","Model","id","vertexCount","isInstanced","drawMode","vs","fs","parameters","blend","blendFunc","blendEquation","depthTest"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/data-filter/aggregator.js"],"names":["AGGREGATE_VS","AGGREGATE_FS","supportsFloatTarget","gl","getExtension","getFramebuffer","useFloatTarget","Framebuffer","width","height","attachments","Texture2D","format","type","mipmaps","depth","getModel","shaderOptions","defines","NON_INSTANCED_MODEL","FLOAT_TARGET","Model","id","vertexCount","isInstanced","drawMode","vs","fs","parameters","blend","blendFunc","blendEquation","depthTest"],"mappings":";;;;;;;;;;AAAA;;AAGA,MAAMA,YAAY,89BAAlB;AAiCA,MAAMC,YAAY,wMAAlB;;AAcO,SAASC,mBAAT,CAA6BC,EAA7B,EAAiC;AAEtC,SACEA,EAAE,CAACC,YAAH,CAAgB,iBAAhB,MAECD,EAAE,CAACC,YAAH,CAAgB,wBAAhB,KAECD,EAAE,CAACC,YAAH,CAAgB,0BAAhB,CAJF,CADF;AAOD;;AAGM,SAASC,cAAT,CAAwBF,EAAxB,EAA4BG,cAA5B,EAA4C;AACjD,MAAIA,cAAJ,EAAoB;AAClB,WAAO,IAAIC,iBAAJ,CAAgBJ,EAAhB,EAAoB;AACzBK,MAAAA,KAAK,EAAE,CADkB;AAEzBC,MAAAA,MAAM,EAAE,CAFiB;AAGzBC,MAAAA,WAAW,EAAE;AACX,iBAAwB,IAAIC,eAAJ,CAAcR,EAAd,EAAkB;AACxCS,UAAAA,MAAM,EAAE,oBAAST,EAAT,gBADgC;AAExCU,UAAAA,IAAI,MAFoC;AAGxCC,UAAAA,OAAO,EAAE;AAH+B,SAAlB;AADb;AAHY,KAApB,CAAP;AAWD;;AACD,SAAO,IAAIP,iBAAJ,CAAgBJ,EAAhB,EAAoB;AACzBK,IAAAA,KAAK,EAAE,GADkB;AAEzBC,IAAAA,MAAM,EAAE,EAFiB;AAGzBM,IAAAA,KAAK,EAAE;AAHkB,GAApB,CAAP;AAKD;;AAGM,SAASC,QAAT,CAAkBb,EAAlB,EAAsBc,aAAtB,EAAqCX,cAArC,EAAqD;AAC1DW,EAAAA,aAAa,CAACC,OAAd,CAAsBC,mBAAtB,GAA4C,CAA5C;;AACA,MAAIb,cAAJ,EAAoB;AAClBW,IAAAA,aAAa,CAACC,OAAd,CAAsBE,YAAtB,GAAqC,CAArC;AACD;;AAED,SAAO,IAAIC,WAAJ,CAAUlB,EAAV,EAAc;AACnBmB,IAAAA,EAAE,EAAE,+BADe;AAEnBC,IAAAA,WAAW,EAAE,CAFM;AAGnBC,IAAAA,WAAW,EAAE,KAHM;AAInBC,IAAAA,QAAQ,GAJW;AAKnBC,IAAAA,EAAE,EAAE1B,YALe;AAMnB2B,IAAAA,EAAE,EAAE1B,YANe;AAOnB,OAAGgB;AAPgB,GAAd,CAAP;AASD;;AAEM,MAAMW,UAAU,GAAG;AACxBC,EAAAA,KAAK,EAAE,IADiB;AAExBC,EAAAA,SAAS,EAAE,YAFa;AAGxBC,EAAAA,aAAa,EAAE,cAHS;AAIxBC,EAAAA,SAAS,EAAE;AAJa,CAAnB","sourcesContent":["import {Model, Texture2D, Framebuffer, isWebGL2} from '@luma.gl/core';\nimport GL from '@luma.gl/constants';\n\nconst AGGREGATE_VS = `\\\n#define SHADER_NAME data-filter-vertex-shader\n\n#ifdef FLOAT_TARGET\n attribute float filterIndices;\n attribute float filterPrevIndices;\n#else\n attribute vec2 filterIndices;\n attribute vec2 filterPrevIndices;\n#endif\n\nvarying vec4 vColor;\nconst float component = 1.0 / 255.0;\n\nvoid main() {\n #ifdef FLOAT_TARGET\n dataFilter_value *= float(filterIndices != filterPrevIndices);\n gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n vColor = vec4(0.0, 0.0, 0.0, 1.0);\n #else\n // Float texture is not supported: pack result into 4 channels x 256 px x 64px\n dataFilter_value *= float(filterIndices.x != filterPrevIndices.x);\n float col = filterIndices.x;\n float row = filterIndices.y * 4.0;\n float channel = floor(row);\n row = fract(row);\n vColor = component * vec4(bvec4(channel == 0.0, channel == 1.0, channel == 2.0, channel == 3.0));\n gl_Position = vec4(col * 2.0 - 1.0, row * 2.0 - 1.0, 0.0, 1.0);\n #endif\n gl_PointSize = 1.0;\n}\n`;\n\nconst AGGREGATE_FS = `\\\n#define SHADER_NAME data-filter-fragment-shader\nprecision highp float;\n\nvarying vec4 vColor;\n\nvoid main() {\n if (dataFilter_value < 0.5) {\n discard;\n }\n gl_FragColor = vColor;\n}\n`;\n\nexport function supportsFloatTarget(gl) {\n // https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#Support_for_float_textures_doesnt_mean_you_can_render_into_them!\n return (\n gl.getExtension('EXT_float_blend') &&\n // WebGL 2\n (gl.getExtension('EXT_color_buffer_float') ||\n // WebGL 1\n gl.getExtension('WEBGL_color_buffer_float'))\n );\n}\n\n// A 1x1 framebuffer object that encodes the total count of filtered items\nexport function getFramebuffer(gl, useFloatTarget) {\n if (useFloatTarget) {\n return new Framebuffer(gl, {\n width: 1,\n height: 1,\n attachments: {\n [GL.COLOR_ATTACHMENT0]: new Texture2D(gl, {\n format: isWebGL2(gl) ? GL.RGBA32F : GL.RGBA,\n type: GL.FLOAT,\n mipmaps: false\n })\n }\n });\n }\n return new Framebuffer(gl, {\n width: 256,\n height: 64,\n depth: false\n });\n}\n\n// Increments the counter based on dataFilter_value\nexport function getModel(gl, shaderOptions, useFloatTarget) {\n shaderOptions.defines.NON_INSTANCED_MODEL = 1;\n if (useFloatTarget) {\n shaderOptions.defines.FLOAT_TARGET = 1;\n }\n\n return new Model(gl, {\n id: 'data-filter-aggregation-model',\n vertexCount: 1,\n isInstanced: false,\n drawMode: GL.POINTS,\n vs: AGGREGATE_VS,\n fs: AGGREGATE_FS,\n ...shaderOptions\n });\n}\n\nexport const parameters = {\n blend: true,\n blendFunc: [GL.ONE, GL.ONE, GL.ONE, GL.ONE],\n blendEquation: [GL.FUNC_ADD, GL.FUNC_ADD],\n depthTest: false\n};\n"],"file":"aggregator.js"}
|
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
-
|
|
5
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
3
|
Object.defineProperty(exports, "__esModule", {
|
|
8
4
|
value: true
|
|
9
5
|
});
|
|
10
6
|
exports.default = void 0;
|
|
11
7
|
|
|
12
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
-
|
|
14
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
-
|
|
16
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
-
|
|
18
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
19
|
-
|
|
20
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
21
|
-
|
|
22
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
23
|
-
|
|
24
8
|
var _core = require("@deck.gl/core");
|
|
25
9
|
|
|
26
10
|
var _shaderModule = require("./shader-module");
|
|
@@ -29,15 +13,11 @@ var aggregator = _interopRequireWildcard(require("./aggregator"));
|
|
|
29
13
|
|
|
30
14
|
var _core2 = require("@luma.gl/core");
|
|
31
15
|
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
35
17
|
|
|
36
|
-
function
|
|
18
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
37
19
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var defaultProps = {
|
|
20
|
+
const defaultProps = {
|
|
41
21
|
getFilterValue: {
|
|
42
22
|
type: 'accessor',
|
|
43
23
|
value: 0
|
|
@@ -53,184 +33,180 @@ var defaultProps = {
|
|
|
53
33
|
filterTransformSize: true,
|
|
54
34
|
filterTransformColor: true
|
|
55
35
|
};
|
|
56
|
-
|
|
36
|
+
const DATA_TYPE_FROM_SIZE = {
|
|
57
37
|
1: 'float',
|
|
58
38
|
2: 'vec2',
|
|
59
39
|
3: 'vec3',
|
|
60
40
|
4: 'vec4'
|
|
61
41
|
};
|
|
62
42
|
|
|
63
|
-
|
|
64
|
-
(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
70
|
-
_ref$filterSize = _ref.filterSize,
|
|
71
|
-
filterSize = _ref$filterSize === void 0 ? 1 : _ref$filterSize,
|
|
72
|
-
_ref$fp = _ref.fp64,
|
|
73
|
-
fp64 = _ref$fp === void 0 ? false : _ref$fp,
|
|
74
|
-
_ref$countItems = _ref.countItems,
|
|
75
|
-
countItems = _ref$countItems === void 0 ? false : _ref$countItems;
|
|
76
|
-
|
|
77
|
-
(0, _classCallCheck2.default)(this, DataFilterExtension);
|
|
78
|
-
|
|
43
|
+
class DataFilterExtension extends _core.LayerExtension {
|
|
44
|
+
constructor({
|
|
45
|
+
filterSize = 1,
|
|
46
|
+
fp64 = false,
|
|
47
|
+
countItems = false
|
|
48
|
+
} = {}) {
|
|
79
49
|
if (!DATA_TYPE_FROM_SIZE[filterSize]) {
|
|
80
50
|
throw new Error('filterSize out of range');
|
|
81
51
|
}
|
|
82
52
|
|
|
83
|
-
|
|
84
|
-
filterSize
|
|
85
|
-
fp64
|
|
86
|
-
countItems
|
|
53
|
+
super({
|
|
54
|
+
filterSize,
|
|
55
|
+
fp64,
|
|
56
|
+
countItems
|
|
87
57
|
});
|
|
88
58
|
}
|
|
89
59
|
|
|
90
|
-
(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
instanceFilterValues: {
|
|
120
|
-
divisor: 1
|
|
121
|
-
}
|
|
60
|
+
getShaders(extension) {
|
|
61
|
+
const {
|
|
62
|
+
filterSize,
|
|
63
|
+
fp64
|
|
64
|
+
} = extension.opts;
|
|
65
|
+
return {
|
|
66
|
+
modules: [fp64 ? _shaderModule.shaderModule64 : _shaderModule.shaderModule],
|
|
67
|
+
defines: {
|
|
68
|
+
DATAFILTER_TYPE: DATA_TYPE_FROM_SIZE[filterSize],
|
|
69
|
+
DATAFILTER_DOUBLE: Boolean(fp64)
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
initializeState(context, extension) {
|
|
75
|
+
const attributeManager = this.getAttributeManager();
|
|
76
|
+
|
|
77
|
+
if (attributeManager) {
|
|
78
|
+
attributeManager.add({
|
|
79
|
+
filterValues: {
|
|
80
|
+
size: extension.opts.filterSize,
|
|
81
|
+
type: extension.opts.fp64 ? 5130 : 5126,
|
|
82
|
+
accessor: 'getFilterValue',
|
|
83
|
+
shaderAttributes: {
|
|
84
|
+
filterValues: {
|
|
85
|
+
divisor: 0
|
|
86
|
+
},
|
|
87
|
+
instanceFilterValues: {
|
|
88
|
+
divisor: 1
|
|
122
89
|
}
|
|
123
90
|
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
126
94
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
95
|
+
const {
|
|
96
|
+
gl
|
|
97
|
+
} = this.context;
|
|
98
|
+
|
|
99
|
+
if (attributeManager && extension.opts.countItems) {
|
|
100
|
+
const useFloatTarget = aggregator.supportsFloatTarget(gl);
|
|
101
|
+
attributeManager.add({
|
|
102
|
+
filterIndices: {
|
|
103
|
+
size: useFloatTarget ? 1 : 2,
|
|
104
|
+
vertexOffset: 1,
|
|
105
|
+
type: 5121,
|
|
106
|
+
normalized: true,
|
|
107
|
+
accessor: (object, {
|
|
108
|
+
index
|
|
109
|
+
}) => {
|
|
110
|
+
const i = object && object.__source ? object.__source.index : index;
|
|
111
|
+
return useFloatTarget ? (i + 1) % 255 : [(i + 1) % 255, Math.floor(i / 255) % 255];
|
|
112
|
+
},
|
|
113
|
+
shaderAttributes: {
|
|
114
|
+
filterPrevIndices: {
|
|
115
|
+
vertexOffset: 0
|
|
141
116
|
},
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
vertexOffset: 0
|
|
145
|
-
},
|
|
146
|
-
filterIndices: {
|
|
147
|
-
vertexOffset: 1
|
|
148
|
-
}
|
|
117
|
+
filterIndices: {
|
|
118
|
+
vertexOffset: 1
|
|
149
119
|
}
|
|
150
120
|
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
const filterFBO = aggregator.getFramebuffer(gl, useFloatTarget);
|
|
124
|
+
const filterModel = aggregator.getModel(gl, extension.getShaders(extension), useFloatTarget);
|
|
125
|
+
this.setState({
|
|
126
|
+
filterFBO,
|
|
127
|
+
filterModel
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
updateState({
|
|
133
|
+
props,
|
|
134
|
+
oldProps
|
|
135
|
+
}) {
|
|
136
|
+
if (this.state.filterModel) {
|
|
137
|
+
const attributeManager = this.getAttributeManager();
|
|
138
|
+
const filterNeedsUpdate = attributeManager.attributes.filterValues.needsUpdate() || props.filterEnabled !== oldProps.filterEnabled || props.filterRange !== oldProps.filterRange || props.filterSoftRange !== oldProps.filterSoftRange;
|
|
139
|
+
|
|
140
|
+
if (filterNeedsUpdate) {
|
|
154
141
|
this.setState({
|
|
155
|
-
|
|
156
|
-
filterModel: filterModel
|
|
142
|
+
filterNeedsUpdate
|
|
157
143
|
});
|
|
158
144
|
}
|
|
159
145
|
}
|
|
160
|
-
}
|
|
161
|
-
key: "updateState",
|
|
162
|
-
value: function updateState(_ref3) {
|
|
163
|
-
var props = _ref3.props,
|
|
164
|
-
oldProps = _ref3.oldProps;
|
|
165
|
-
|
|
166
|
-
if (this.state.filterModel) {
|
|
167
|
-
var attributeManager = this.getAttributeManager();
|
|
168
|
-
var filterNeedsUpdate = attributeManager.attributes.filterValues.needsUpdate() || props.filterEnabled !== oldProps.filterEnabled || props.filterRange !== oldProps.filterRange || props.filterSoftRange !== oldProps.filterSoftRange;
|
|
169
|
-
|
|
170
|
-
if (filterNeedsUpdate) {
|
|
171
|
-
this.setState({
|
|
172
|
-
filterNeedsUpdate: filterNeedsUpdate
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}, {
|
|
178
|
-
key: "draw",
|
|
179
|
-
value: function draw(params, extension) {
|
|
180
|
-
var _this$state = this.state,
|
|
181
|
-
filterFBO = _this$state.filterFBO,
|
|
182
|
-
filterModel = _this$state.filterModel,
|
|
183
|
-
filterNeedsUpdate = _this$state.filterNeedsUpdate;
|
|
184
|
-
var onFilteredItemsChange = this.props.onFilteredItemsChange;
|
|
185
|
-
|
|
186
|
-
if (filterNeedsUpdate && onFilteredItemsChange && filterModel) {
|
|
187
|
-
var _this$getAttributeMan = this.getAttributeManager(),
|
|
188
|
-
_this$getAttributeMan2 = _this$getAttributeMan.attributes,
|
|
189
|
-
filterValues = _this$getAttributeMan2.filterValues,
|
|
190
|
-
filterIndices = _this$getAttributeMan2.filterIndices;
|
|
191
|
-
|
|
192
|
-
filterModel.setVertexCount(this.getNumInstances());
|
|
193
|
-
var gl = this.context.gl;
|
|
194
|
-
(0, _core2.clear)(gl, {
|
|
195
|
-
framebuffer: filterFBO,
|
|
196
|
-
color: [0, 0, 0, 0]
|
|
197
|
-
});
|
|
198
|
-
filterModel.updateModuleSettings(params.moduleParameters).setAttributes(_objectSpread(_objectSpread({}, filterValues.getShaderAttributes()), filterIndices && filterIndices.getShaderAttributes())).draw({
|
|
199
|
-
framebuffer: filterFBO,
|
|
200
|
-
parameters: _objectSpread(_objectSpread({}, aggregator.parameters), {}, {
|
|
201
|
-
viewport: [0, 0, filterFBO.width, filterFBO.height]
|
|
202
|
-
})
|
|
203
|
-
});
|
|
204
|
-
var color = (0, _core2.readPixelsToArray)(filterFBO);
|
|
205
|
-
var count = 0;
|
|
146
|
+
}
|
|
206
147
|
|
|
207
|
-
|
|
208
|
-
|
|
148
|
+
draw(params, extension) {
|
|
149
|
+
const {
|
|
150
|
+
filterFBO,
|
|
151
|
+
filterModel,
|
|
152
|
+
filterNeedsUpdate
|
|
153
|
+
} = this.state;
|
|
154
|
+
const {
|
|
155
|
+
onFilteredItemsChange
|
|
156
|
+
} = this.props;
|
|
157
|
+
|
|
158
|
+
if (filterNeedsUpdate && onFilteredItemsChange && filterModel) {
|
|
159
|
+
const {
|
|
160
|
+
attributes: {
|
|
161
|
+
filterValues,
|
|
162
|
+
filterIndices
|
|
163
|
+
}
|
|
164
|
+
} = this.getAttributeManager();
|
|
165
|
+
filterModel.setVertexCount(this.getNumInstances());
|
|
166
|
+
const {
|
|
167
|
+
gl
|
|
168
|
+
} = this.context;
|
|
169
|
+
(0, _core2.clear)(gl, {
|
|
170
|
+
framebuffer: filterFBO,
|
|
171
|
+
color: [0, 0, 0, 0]
|
|
172
|
+
});
|
|
173
|
+
filterModel.updateModuleSettings(params.moduleParameters).setAttributes({ ...filterValues.getShaderAttributes(),
|
|
174
|
+
...(filterIndices && filterIndices.getShaderAttributes())
|
|
175
|
+
}).draw({
|
|
176
|
+
framebuffer: filterFBO,
|
|
177
|
+
parameters: { ...aggregator.parameters,
|
|
178
|
+
viewport: [0, 0, filterFBO.width, filterFBO.height]
|
|
209
179
|
}
|
|
180
|
+
});
|
|
181
|
+
const color = (0, _core2.readPixelsToArray)(filterFBO);
|
|
182
|
+
let count = 0;
|
|
210
183
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
count: count
|
|
214
|
-
});
|
|
215
|
-
this.state.filterNeedsUpdate = false;
|
|
184
|
+
for (let i = 0; i < color.length; i++) {
|
|
185
|
+
count += color[i];
|
|
216
186
|
}
|
|
187
|
+
|
|
188
|
+
onFilteredItemsChange({
|
|
189
|
+
id: this.id,
|
|
190
|
+
count
|
|
191
|
+
});
|
|
192
|
+
this.state.filterNeedsUpdate = false;
|
|
217
193
|
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
finalizeState() {
|
|
197
|
+
const {
|
|
198
|
+
filterFBO,
|
|
199
|
+
filterModel
|
|
200
|
+
} = this.state;
|
|
201
|
+
|
|
202
|
+
if (filterFBO) {
|
|
203
|
+
filterFBO.color.delete();
|
|
204
|
+
filterFBO.delete();
|
|
205
|
+
filterModel.delete();
|
|
230
206
|
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
}
|
|
234
210
|
|
|
235
211
|
exports.default = DataFilterExtension;
|
|
236
212
|
DataFilterExtension.extensionName = 'DataFilterExtension';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/data-filter/data-filter.js"],"names":["defaultProps","getFilterValue","type","value","onFilteredItemsChange","compare","filterEnabled","filterRange","filterSoftRange","filterTransformSize","filterTransformColor","DATA_TYPE_FROM_SIZE","DataFilterExtension","filterSize","fp64","countItems","Error","extension","opts","modules","shaderModule64","shaderModule","defines","DATAFILTER_TYPE","DATAFILTER_DOUBLE","Boolean","context","attributeManager","getAttributeManager","add","filterValues","size","accessor","shaderAttributes","divisor","instanceFilterValues","gl","useFloatTarget","aggregator","supportsFloatTarget","filterIndices","vertexOffset","normalized","object","index","i","__source","Math","floor","filterPrevIndices","filterFBO","getFramebuffer","filterModel","getModel","getShaders","setState","props","oldProps","state","filterNeedsUpdate","attributes","needsUpdate","params","setVertexCount","getNumInstances","framebuffer","color","updateModuleSettings","moduleParameters","setAttributes","getShaderAttributes","draw","parameters","viewport","width","height","count","length","id","delete","LayerExtension","extensionName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoBA;;AACA;;AACA;;AACA;;;;;;;;;;AAGA,IAAMA,YAAY,GAAG;AACnBC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Z;;AACA,aAAK,IAAI/B,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGqB,KAAK,CAACW,MAA1B,EAAkChC,CAAC,EAAnC,EAAuC;AACrC+B,UAAAA,KAAK,IAAIV,KAAK,CAACrB,CAAD,CAAd;AACD;;AACDzC,QAAAA,qBAAqB,CAAC;AAAC0E,UAAAA,EAAE,EAAE,KAAKA,EAAV;AAAcF,UAAAA,KAAK,EAALA;AAAd,SAAD,CAArB;AAEA,aAAKlB,KAAL,CAAWC,iBAAX,GAA+B,KAA/B;AACD;AACF;;;oCAEe;AAAA,yBACmB,KAAKD,KADxB;AAAA,UACPR,SADO,gBACPA,SADO;AAAA,UACIE,WADJ,gBACIA,WADJ;;AAEd,UAAIF,SAAJ,EAAe;AACbA,QAAAA,SAAS,CAACgB,KAAV,CAAgBa,MAAhB;AACA7B,QAAAA,SAAS,CAAC6B,MAAV;AACA3B,QAAAA,WAAW,CAAC2B,MAAZ;AACD;AACF;;;EAnI8CC,oB;;;AAsIjDpE,mBAAmB,CAACqE,aAApB,GAAoC,qBAApC;AACArE,mBAAmB,CAACZ,YAApB,GAAmCA,YAAnC","sourcesContent":["// Copyright (c) 2015 - 2017 Uber Technologies, Inc.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n\nimport {LayerExtension} from '@deck.gl/core';\nimport {shaderModule, shaderModule64} from './shader-module';\nimport * as aggregator from './aggregator';\nimport {readPixelsToArray, clear} from '@luma.gl/core';\nimport GL from '@luma.gl/constants';\n\nconst defaultProps = {\n getFilterValue: {type: 'accessor', value: 0},\n onFilteredItemsChange: {type: 'function', value: null, compare: false},\n\n filterEnabled: true,\n filterRange: [-1, 1],\n filterSoftRange: null,\n filterTransformSize: true,\n filterTransformColor: true\n};\n\nconst DATA_TYPE_FROM_SIZE = {\n 1: 'float',\n 2: 'vec2',\n 3: 'vec3',\n 4: 'vec4'\n};\n\nexport default class DataFilterExtension extends LayerExtension {\n constructor({filterSize = 1, fp64 = false, countItems = false} = {}) {\n if (!DATA_TYPE_FROM_SIZE[filterSize]) {\n throw new Error('filterSize out of range');\n }\n\n super({filterSize, fp64, countItems});\n }\n\n getShaders(extension) {\n const {filterSize, fp64} = extension.opts;\n\n return {\n modules: [fp64 ? shaderModule64 : shaderModule],\n defines: {\n DATAFILTER_TYPE: DATA_TYPE_FROM_SIZE[filterSize],\n DATAFILTER_DOUBLE: Boolean(fp64)\n }\n };\n }\n\n initializeState(context, extension) {\n const attributeManager = this.getAttributeManager();\n if (attributeManager) {\n attributeManager.add({\n filterValues: {\n size: extension.opts.filterSize,\n type: extension.opts.fp64 ? GL.DOUBLE : GL.FLOAT,\n accessor: 'getFilterValue',\n shaderAttributes: {\n filterValues: {\n divisor: 0\n },\n instanceFilterValues: {\n divisor: 1\n }\n }\n }\n });\n }\n\n const {gl} = this.context;\n if (attributeManager && extension.opts.countItems) {\n const useFloatTarget = aggregator.supportsFloatTarget(gl);\n // This attribute is needed for variable-width data, e.g. Path, SolidPolygon, Text\n // The vertex shader checks if a vertex has the same \"index\" as the previous vertex\n // so that we only write one count cross multiple vertices of the same object\n attributeManager.add({\n filterIndices: {\n size: useFloatTarget ? 1 : 2,\n vertexOffset: 1,\n type: GL.UNSIGNED_BYTE,\n normalized: true,\n accessor: (object, {index}) => {\n const i = object && object.__source ? object.__source.index : index;\n return useFloatTarget ? (i + 1) % 255 : [(i + 1) % 255, Math.floor(i / 255) % 255];\n },\n shaderAttributes: {\n filterPrevIndices: {\n vertexOffset: 0\n },\n filterIndices: {\n vertexOffset: 1\n }\n }\n }\n });\n\n const filterFBO = aggregator.getFramebuffer(gl, useFloatTarget);\n const filterModel = aggregator.getModel(gl, extension.getShaders(extension), useFloatTarget);\n this.setState({filterFBO, filterModel});\n }\n }\n\n updateState({props, oldProps}) {\n if (this.state.filterModel) {\n const attributeManager = this.getAttributeManager();\n const filterNeedsUpdate =\n attributeManager.attributes.filterValues.needsUpdate() ||\n props.filterEnabled !== oldProps.filterEnabled ||\n props.filterRange !== oldProps.filterRange ||\n props.filterSoftRange !== oldProps.filterSoftRange;\n if (filterNeedsUpdate) {\n this.setState({filterNeedsUpdate});\n }\n }\n }\n\n draw(params, extension) {\n const {filterFBO, filterModel, filterNeedsUpdate} = this.state;\n const {onFilteredItemsChange} = this.props;\n if (filterNeedsUpdate && onFilteredItemsChange && filterModel) {\n const {\n attributes: {filterValues, filterIndices}\n } = this.getAttributeManager();\n filterModel.setVertexCount(this.getNumInstances());\n\n const {gl} = this.context;\n clear(gl, {framebuffer: filterFBO, color: [0, 0, 0, 0]});\n\n filterModel\n .updateModuleSettings(params.moduleParameters)\n .setAttributes({\n ...filterValues.getShaderAttributes(),\n ...(filterIndices && filterIndices.getShaderAttributes())\n })\n .draw({\n framebuffer: filterFBO,\n parameters: {\n ...aggregator.parameters,\n viewport: [0, 0, filterFBO.width, filterFBO.height]\n }\n });\n const color = readPixelsToArray(filterFBO);\n let count = 0;\n for (let i = 0; i < color.length; i++) {\n count += color[i];\n }\n onFilteredItemsChange({id: this.id, count});\n\n this.state.filterNeedsUpdate = false;\n }\n }\n\n finalizeState() {\n const {filterFBO, filterModel} = this.state;\n if (filterFBO) {\n filterFBO.color.delete();\n filterFBO.delete();\n filterModel.delete();\n }\n }\n}\n\nDataFilterExtension.extensionName = 'DataFilterExtension';\nDataFilterExtension.defaultProps = defaultProps;\n"],"file":"data-filter.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/data-filter/data-filter.js"],"names":["defaultProps","getFilterValue","type","value","onFilteredItemsChange","compare","filterEnabled","filterRange","filterSoftRange","filterTransformSize","filterTransformColor","DATA_TYPE_FROM_SIZE","DataFilterExtension","LayerExtension","constructor","filterSize","fp64","countItems","Error","getShaders","extension","opts","modules","shaderModule64","shaderModule","defines","DATAFILTER_TYPE","DATAFILTER_DOUBLE","Boolean","initializeState","context","attributeManager","getAttributeManager","add","filterValues","size","accessor","shaderAttributes","divisor","instanceFilterValues","gl","useFloatTarget","aggregator","supportsFloatTarget","filterIndices","vertexOffset","normalized","object","index","i","__source","Math","floor","filterPrevIndices","filterFBO","getFramebuffer","filterModel","getModel","setState","updateState","props","oldProps","state","filterNeedsUpdate","attributes","needsUpdate","draw","params","setVertexCount","getNumInstances","framebuffer","color","updateModuleSettings","moduleParameters","setAttributes","getShaderAttributes","parameters","viewport","width","height","count","length","id","finalizeState","delete","extensionName"],"mappings":";;;;;;;AAoBA;;AACA;;AACA;;AACA;;;;;;AAGA,MAAMA,YAAY,GAAG;AACnBC,EAAAA,cAAc,EAAE;AAACC,IAAAA,IAAI,EAAE,UAAP;AAAmBC,IAAAA,KAAK,EAAE;AAA1B,GADG;AAEnBC,EAAAA,qBAAqB,EAAE;AAACF,IAAAA,IAAI,EAAE,UAAP;AAAmBC,IAAAA,KAAK,EAAE,IAA1B;AAAgCE,IAAAA,OAAO,EAAE;AAAzC,GAFJ;AAInBC,EAAAA,aAAa,EAAE,IAJI;AAKnBC,EAAAA,WAAW,EAAE,CAAC,CAAC,CAAF,EAAK,CAAL,CALM;AAMnBC,EAAAA,e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EAAe;AACbA,MAAAA,SAAS,CAACiB,KAAV,CAAgBa,MAAhB;AACA9B,MAAAA,SAAS,CAAC8B,MAAV;AACA5B,MAAAA,WAAW,CAAC4B,MAAZ;AACD;AACF;;AAnI6D;;;AAsIhExE,mBAAmB,CAACyE,aAApB,GAAoC,qBAApC;AACAzE,mBAAmB,CAACZ,YAApB,GAAmCA,YAAnC","sourcesContent":["// Copyright (c) 2015 - 2017 Uber Technologies, Inc.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n\nimport {LayerExtension} from '@deck.gl/core';\nimport {shaderModule, shaderModule64} from './shader-module';\nimport * as aggregator from './aggregator';\nimport {readPixelsToArray, clear} from '@luma.gl/core';\nimport GL from '@luma.gl/constants';\n\nconst defaultProps = {\n getFilterValue: {type: 'accessor', value: 0},\n onFilteredItemsChange: {type: 'function', value: null, compare: false},\n\n filterEnabled: true,\n filterRange: [-1, 1],\n filterSoftRange: null,\n filterTransformSize: true,\n filterTransformColor: true\n};\n\nconst DATA_TYPE_FROM_SIZE = {\n 1: 'float',\n 2: 'vec2',\n 3: 'vec3',\n 4: 'vec4'\n};\n\nexport default class DataFilterExtension extends LayerExtension {\n constructor({filterSize = 1, fp64 = false, countItems = false} = {}) {\n if (!DATA_TYPE_FROM_SIZE[filterSize]) {\n throw new Error('filterSize out of range');\n }\n\n super({filterSize, fp64, countItems});\n }\n\n getShaders(extension) {\n const {filterSize, fp64} = extension.opts;\n\n return {\n modules: [fp64 ? shaderModule64 : shaderModule],\n defines: {\n DATAFILTER_TYPE: DATA_TYPE_FROM_SIZE[filterSize],\n DATAFILTER_DOUBLE: Boolean(fp64)\n }\n };\n }\n\n initializeState(context, extension) {\n const attributeManager = this.getAttributeManager();\n if (attributeManager) {\n attributeManager.add({\n filterValues: {\n size: extension.opts.filterSize,\n type: extension.opts.fp64 ? GL.DOUBLE : GL.FLOAT,\n accessor: 'getFilterValue',\n shaderAttributes: {\n filterValues: {\n divisor: 0\n },\n instanceFilterValues: {\n divisor: 1\n }\n }\n }\n });\n }\n\n const {gl} = this.context;\n if (attributeManager && extension.opts.countItems) {\n const useFloatTarget = aggregator.supportsFloatTarget(gl);\n // This attribute is needed for variable-width data, e.g. Path, SolidPolygon, Text\n // The vertex shader checks if a vertex has the same \"index\" as the previous vertex\n // so that we only write one count cross multiple vertices of the same object\n attributeManager.add({\n filterIndices: {\n size: useFloatTarget ? 1 : 2,\n vertexOffset: 1,\n type: GL.UNSIGNED_BYTE,\n normalized: true,\n accessor: (object, {index}) => {\n const i = object && object.__source ? object.__source.index : index;\n return useFloatTarget ? (i + 1) % 255 : [(i + 1) % 255, Math.floor(i / 255) % 255];\n },\n shaderAttributes: {\n filterPrevIndices: {\n vertexOffset: 0\n },\n filterIndices: {\n vertexOffset: 1\n }\n }\n }\n });\n\n const filterFBO = aggregator.getFramebuffer(gl, useFloatTarget);\n const filterModel = aggregator.getModel(gl, extension.getShaders(extension), useFloatTarget);\n this.setState({filterFBO, filterModel});\n }\n }\n\n updateState({props, oldProps}) {\n if (this.state.filterModel) {\n const attributeManager = this.getAttributeManager();\n const filterNeedsUpdate =\n attributeManager.attributes.filterValues.needsUpdate() ||\n props.filterEnabled !== oldProps.filterEnabled ||\n props.filterRange !== oldProps.filterRange ||\n props.filterSoftRange !== oldProps.filterSoftRange;\n if (filterNeedsUpdate) {\n this.setState({filterNeedsUpdate});\n }\n }\n }\n\n draw(params, extension) {\n const {filterFBO, filterModel, filterNeedsUpdate} = this.state;\n const {onFilteredItemsChange} = this.props;\n if (filterNeedsUpdate && onFilteredItemsChange && filterModel) {\n const {\n attributes: {filterValues, filterIndices}\n } = this.getAttributeManager();\n filterModel.setVertexCount(this.getNumInstances());\n\n const {gl} = this.context;\n clear(gl, {framebuffer: filterFBO, color: [0, 0, 0, 0]});\n\n filterModel\n .updateModuleSettings(params.moduleParameters)\n .setAttributes({\n ...filterValues.getShaderAttributes(),\n ...(filterIndices && filterIndices.getShaderAttributes())\n })\n .draw({\n framebuffer: filterFBO,\n parameters: {\n ...aggregator.parameters,\n viewport: [0, 0, filterFBO.width, filterFBO.height]\n }\n });\n const color = readPixelsToArray(filterFBO);\n let count = 0;\n for (let i = 0; i < color.length; i++) {\n count += color[i];\n }\n onFilteredItemsChange({id: this.id, count});\n\n this.state.filterNeedsUpdate = false;\n }\n }\n\n finalizeState() {\n const {filterFBO, filterModel} = this.state;\n if (filterFBO) {\n filterFBO.color.delete();\n filterFBO.delete();\n filterModel.delete();\n }\n }\n}\n\nDataFilterExtension.extensionName = 'DataFilterExtension';\nDataFilterExtension.defaultProps = defaultProps;\n"],"file":"data-filter.js"}
|