@deck.gl/aggregation-layers 8.8.13 → 8.8.14

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.
Files changed (48) hide show
  1. package/dist/dist.dev.js +267 -267
  2. package/package.json +2 -2
  3. package/typed/aggregation-layer.js +0 -151
  4. package/typed/contour-layer/contour-layer.js +0 -234
  5. package/typed/contour-layer/contour-utils.js +0 -64
  6. package/typed/contour-layer/marching-squares-codes.js +0 -337
  7. package/typed/contour-layer/marching-squares.js +0 -147
  8. package/typed/cpu-grid-layer/cpu-grid-layer.js +0 -129
  9. package/typed/cpu-grid-layer/grid-aggregator.js +0 -141
  10. package/typed/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.js +0 -34
  11. package/typed/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js +0 -141
  12. package/typed/gpu-grid-layer/gpu-grid-cell-layer.js +0 -143
  13. package/typed/gpu-grid-layer/gpu-grid-layer.js +0 -289
  14. package/typed/grid-aggregation-layer.js +0 -172
  15. package/typed/grid-layer/grid-layer.js +0 -60
  16. package/typed/heatmap-layer/heatmap-layer-utils.js +0 -78
  17. package/typed/heatmap-layer/heatmap-layer.js +0 -478
  18. package/typed/heatmap-layer/max-fs.glsl.js +0 -7
  19. package/typed/heatmap-layer/max-vs.glsl.js +0 -12
  20. package/typed/heatmap-layer/triangle-layer-fragment.glsl.js +0 -58
  21. package/typed/heatmap-layer/triangle-layer-vertex.glsl.js +0 -51
  22. package/typed/heatmap-layer/triangle-layer.js +0 -67
  23. package/typed/heatmap-layer/weights-fs.glsl.js +0 -19
  24. package/typed/heatmap-layer/weights-vs.glsl.js +0 -23
  25. package/typed/hexagon-layer/hexagon-aggregator.js +0 -112
  26. package/typed/hexagon-layer/hexagon-layer.js +0 -171
  27. package/typed/index.js +0 -33
  28. package/typed/screen-grid-layer/screen-grid-cell-layer.js +0 -159
  29. package/typed/screen-grid-layer/screen-grid-layer-fragment.glsl.js +0 -37
  30. package/typed/screen-grid-layer/screen-grid-layer-vertex.glsl.js +0 -83
  31. package/typed/screen-grid-layer/screen-grid-layer.js +0 -216
  32. package/typed/types.js +0 -1
  33. package/typed/utils/aggregation-operation-utils.js +0 -94
  34. package/typed/utils/bin-sorter.js +0 -167
  35. package/typed/utils/color-utils.js +0 -53
  36. package/typed/utils/cpu-aggregator.js +0 -417
  37. package/typed/utils/gpu-grid-aggregation/aggregate-all-fs.glsl.js +0 -39
  38. package/typed/utils/gpu-grid-aggregation/aggregate-all-vs.glsl.js +0 -53
  39. package/typed/utils/gpu-grid-aggregation/aggregate-to-grid-fs.glsl.js +0 -31
  40. package/typed/utils/gpu-grid-aggregation/aggregate-to-grid-vs.glsl.js +0 -77
  41. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator-constants.js +0 -41
  42. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator-utils.js +0 -1
  43. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator.js +0 -562
  44. package/typed/utils/gpu-grid-aggregation/transform-mean-vs.glsl.js +0 -36
  45. package/typed/utils/grid-aggregation-utils.js +0 -114
  46. package/typed/utils/prop-utils.js +0 -28
  47. package/typed/utils/resource-utils.js +0 -40
  48. package/typed/utils/scale-utils.js +0 -184
@@ -1,562 +0,0 @@
1
- // Copyright (c) 2015 - 2018 Uber Technologies, Inc.
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy
4
- // of this software and associated documentation files (the "Software"), to deal
5
- // in the Software without restriction, including without limitation the rights
6
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- // copies of the Software, and to permit persons to whom the Software is
8
- // furnished to do so, subject to the following conditions:
9
- //
10
- // The above copyright notice and this permission notice shall be included in
11
- // all copies or substantial portions of the Software.
12
- //
13
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- // THE SOFTWARE.
20
- import GL from '@luma.gl/constants';
21
- import { Model, Transform, FEATURES, hasFeatures, isWebGL2, readPixelsToBuffer, withParameters } from '@luma.gl/core';
22
- import { fp64arithmetic } from '@luma.gl/shadertools';
23
- import { log, project32, _mergeShaders as mergeShaders } from '@deck.gl/core';
24
- import { DEFAULT_RUN_PARAMS, MAX_32_BIT_FLOAT, MIN_BLEND_EQUATION, MAX_BLEND_EQUATION, MAX_MIN_BLEND_EQUATION, EQUATION_MAP, DEFAULT_WEIGHT_PARAMS, PIXEL_SIZE } from './gpu-grid-aggregator-constants';
25
- import { AGGREGATION_OPERATION } from '../aggregation-operation-utils';
26
- import AGGREGATE_TO_GRID_VS from './aggregate-to-grid-vs.glsl';
27
- import AGGREGATE_TO_GRID_FS from './aggregate-to-grid-fs.glsl';
28
- import AGGREGATE_ALL_VS from './aggregate-all-vs.glsl';
29
- import AGGREGATE_ALL_FS from './aggregate-all-fs.glsl';
30
- import TRANSFORM_MEAN_VS from './transform-mean-vs.glsl';
31
- import { getFloatTexture, getFramebuffer } from './../resource-utils.js';
32
- const BUFFER_NAMES = ['aggregationBuffer', 'maxMinBuffer', 'minBuffer', 'maxBuffer'];
33
- const ARRAY_BUFFER_MAP = {
34
- maxData: 'maxBuffer',
35
- minData: 'minBuffer',
36
- maxMinData: 'maxMinBuffer'
37
- };
38
- const REQUIRED_FEATURES = [
39
- FEATURES.WEBGL2,
40
- FEATURES.COLOR_ATTACHMENT_RGBA32F,
41
- FEATURES.BLEND_EQUATION_MINMAX,
42
- FEATURES.FLOAT_BLEND,
43
- FEATURES.TEXTURE_FLOAT
44
- ];
45
- export default class GPUGridAggregator {
46
- // Decode and return aggregation data of given pixel.
47
- static getAggregationData({ aggregationData, maxData, minData, maxMinData, pixelIndex }) {
48
- const index = pixelIndex * PIXEL_SIZE;
49
- const results = {};
50
- if (aggregationData) {
51
- results.cellCount = aggregationData[index + 3];
52
- results.cellWeight = aggregationData[index];
53
- }
54
- if (maxMinData) {
55
- results.maxCellWieght = maxMinData[0];
56
- results.minCellWeight = maxMinData[3];
57
- }
58
- else {
59
- if (maxData) {
60
- results.maxCellWieght = maxData[0];
61
- results.totalCount = maxData[3];
62
- }
63
- if (minData) {
64
- results.minCellWeight = minData[0];
65
- results.totalCount = maxData[3];
66
- }
67
- }
68
- return results;
69
- }
70
- // Decodes and retuns counts and weights of all cells
71
- static getCellData({ countsData, size = 1 }) {
72
- const numCells = countsData.length / 4;
73
- const cellWeights = new Float32Array(numCells * size);
74
- const cellCounts = new Uint32Array(numCells);
75
- for (let i = 0; i < numCells; i++) {
76
- // weights in RGB channels
77
- for (let sizeIndex = 0; sizeIndex < size; sizeIndex++) {
78
- cellWeights[i * size + sizeIndex] = countsData[i * 4 + sizeIndex];
79
- }
80
- // count in Alpha channel
81
- cellCounts[i] = countsData[i * 4 + 3];
82
- }
83
- return { cellCounts, cellWeights };
84
- }
85
- static isSupported(gl) {
86
- return hasFeatures(gl, REQUIRED_FEATURES);
87
- }
88
- // DEBUG ONLY
89
- // static logData({aggregationBuffer, minBuffer, maxBuffer, maxMinBuffer, limit = 10}) {
90
- // if (aggregationBuffer) {
91
- // console.log('Aggregation Data:');
92
- // const agrData = aggregationBuffer.getData();
93
- // for (let index = 0; index < agrData.length && limit > 0; index += 4) {
94
- // if (agrData[index + 3] > 0) {
95
- // console.log(
96
- // `index: ${index} weights: ${agrData[index]} ${agrData[index + 1]} ${
97
- // agrData[index + 2]
98
- // } count: ${agrData[index + 3]}`
99
- // );
100
- // limit--;
101
- // }
102
- // }
103
- // }
104
- // const obj = {minBuffer, maxBuffer, maxMinBuffer};
105
- // for (const key in obj) {
106
- // if (obj[key]) {
107
- // const data = obj[key].getData();
108
- // console.log(`${key} data : R: ${data[0]} G: ${data[1]} B: ${data[2]} A: ${data[3]}`);
109
- // }
110
- // }
111
- // }
112
- constructor(gl, opts = {}) {
113
- this.id = opts.id || 'gpu-grid-aggregator';
114
- this.gl = gl;
115
- this.state = {
116
- // per weight GPU resources
117
- weightAttributes: {},
118
- textures: {},
119
- meanTextures: {},
120
- buffers: {},
121
- framebuffers: {},
122
- maxMinFramebuffers: {},
123
- minFramebuffers: {},
124
- maxFramebuffers: {},
125
- equations: {},
126
- // common resources to be deleted
127
- resources: {},
128
- // results
129
- results: {}
130
- };
131
- this._hasGPUSupport =
132
- isWebGL2(gl) && // gl_InstanceID usage in min/max calculation shaders
133
- hasFeatures(this.gl, FEATURES.BLEND_EQUATION_MINMAX, // set min/max blend modes
134
- FEATURES.COLOR_ATTACHMENT_RGBA32F, // render to float texture
135
- FEATURES.TEXTURE_FLOAT // sample from a float texture
136
- );
137
- if (this._hasGPUSupport) {
138
- this._setupModels();
139
- }
140
- }
141
- // Delete owned resources.
142
- delete() {
143
- const { gridAggregationModel, allAggregationModel, meanTransform } = this;
144
- const { textures, framebuffers, maxMinFramebuffers, minFramebuffers, maxFramebuffers, meanTextures, resources } = this.state;
145
- gridAggregationModel?.delete();
146
- allAggregationModel?.delete();
147
- meanTransform?.delete();
148
- deleteResources([
149
- framebuffers,
150
- textures,
151
- maxMinFramebuffers,
152
- minFramebuffers,
153
- maxFramebuffers,
154
- meanTextures,
155
- resources
156
- ]);
157
- }
158
- // Perform aggregation and retun the results
159
- run(opts = {}) {
160
- // reset results
161
- this.setState({ results: {} });
162
- const aggregationParams = this._normalizeAggregationParams(opts);
163
- if (!this._hasGPUSupport) {
164
- log.log(1, 'GPUGridAggregator: not supported')();
165
- }
166
- return this._runAggregation(aggregationParams);
167
- }
168
- // Reads aggregation data into JS Array object
169
- // For WebGL1, data is available in JS Array objects already.
170
- // For WebGL2, data is read from Buffer objects and cached for subsequent queries.
171
- getData(weightId) {
172
- const data = {};
173
- const results = this.state.results;
174
- if (!results[weightId].aggregationData) {
175
- // cache the results if reading from the buffer (WebGL2 path)
176
- results[weightId].aggregationData = results[weightId].aggregationBuffer.getData();
177
- }
178
- data.aggregationData = results[weightId].aggregationData;
179
- // Check for optional results
180
- for (const arrayName in ARRAY_BUFFER_MAP) {
181
- const bufferName = ARRAY_BUFFER_MAP[arrayName];
182
- if (results[weightId][arrayName] || results[weightId][bufferName]) {
183
- // cache the result
184
- results[weightId][arrayName] =
185
- results[weightId][arrayName] || results[weightId][bufferName].getData();
186
- data[arrayName] = results[weightId][arrayName];
187
- }
188
- }
189
- return data;
190
- }
191
- updateShaders(shaderOptions = {}) {
192
- this.setState({ shaderOptions, modelDirty: true });
193
- }
194
- // PRIVATE
195
- _normalizeAggregationParams(opts) {
196
- const aggregationParams = { ...DEFAULT_RUN_PARAMS, ...opts };
197
- const { weights } = aggregationParams;
198
- if (weights) {
199
- aggregationParams.weights = normalizeWeightParams(weights);
200
- }
201
- return aggregationParams;
202
- }
203
- // Update priveate state
204
- setState(updateObject) {
205
- Object.assign(this.state, updateObject);
206
- }
207
- // GPU Aggregation methods
208
- _getAggregateData(opts) {
209
- const results = {};
210
- const { textures, framebuffers, maxMinFramebuffers, minFramebuffers, maxFramebuffers, resources } = this.state;
211
- const { weights } = opts;
212
- for (const id in weights) {
213
- results[id] = {};
214
- const { needMin, needMax, combineMaxMin } = weights[id];
215
- results[id].aggregationTexture = textures[id];
216
- results[id].aggregationBuffer = readPixelsToBuffer(framebuffers[id], {
217
- target: weights[id].aggregationBuffer,
218
- sourceType: GL.FLOAT
219
- });
220
- if (needMin && needMax && combineMaxMin) {
221
- results[id].maxMinBuffer = readPixelsToBuffer(maxMinFramebuffers[id], {
222
- target: weights[id].maxMinBuffer,
223
- sourceType: GL.FLOAT
224
- });
225
- results[id].maxMinTexture = resources[`${id}-maxMinTexture`];
226
- }
227
- else {
228
- if (needMin) {
229
- results[id].minBuffer = readPixelsToBuffer(minFramebuffers[id], {
230
- target: weights[id].minBuffer,
231
- sourceType: GL.FLOAT
232
- });
233
- results[id].minTexture = resources[`${id}-minTexture`];
234
- }
235
- if (needMax) {
236
- results[id].maxBuffer = readPixelsToBuffer(maxFramebuffers[id], {
237
- target: weights[id].maxBuffer,
238
- sourceType: GL.FLOAT
239
- });
240
- results[id].maxTexture = resources[`${id}-maxTexture`];
241
- }
242
- }
243
- }
244
- this._trackGPUResultBuffers(results, weights);
245
- return results;
246
- }
247
- _renderAggregateData(opts) {
248
- const { cellSize, projectPoints, attributes, moduleSettings, numCol, numRow, weights, translation, scaling } = opts;
249
- const { maxMinFramebuffers, minFramebuffers, maxFramebuffers } = this.state;
250
- const gridSize = [numCol, numRow];
251
- const parameters = {
252
- blend: true,
253
- depthTest: false,
254
- blendFunc: [GL.ONE, GL.ONE]
255
- };
256
- const uniforms = {
257
- cellSize,
258
- gridSize,
259
- projectPoints,
260
- translation,
261
- scaling
262
- };
263
- for (const id in weights) {
264
- const { needMin, needMax } = weights[id];
265
- const combineMaxMin = needMin && needMax && weights[id].combineMaxMin;
266
- this._renderToWeightsTexture({
267
- id,
268
- parameters,
269
- moduleSettings,
270
- uniforms,
271
- gridSize,
272
- attributes,
273
- weights
274
- });
275
- if (combineMaxMin) {
276
- this._renderToMaxMinTexture({
277
- id,
278
- parameters: { ...parameters, blendEquation: MAX_MIN_BLEND_EQUATION },
279
- gridSize,
280
- minOrMaxFb: maxMinFramebuffers[id],
281
- clearParams: { clearColor: [0, 0, 0, MAX_32_BIT_FLOAT] },
282
- combineMaxMin
283
- });
284
- }
285
- else {
286
- if (needMin) {
287
- this._renderToMaxMinTexture({
288
- id,
289
- parameters: { ...parameters, blendEquation: MIN_BLEND_EQUATION },
290
- gridSize,
291
- minOrMaxFb: minFramebuffers[id],
292
- clearParams: { clearColor: [MAX_32_BIT_FLOAT, MAX_32_BIT_FLOAT, MAX_32_BIT_FLOAT, 0] },
293
- combineMaxMin
294
- });
295
- }
296
- if (needMax) {
297
- this._renderToMaxMinTexture({
298
- id,
299
- parameters: { ...parameters, blendEquation: MAX_BLEND_EQUATION },
300
- gridSize,
301
- minOrMaxFb: maxFramebuffers[id],
302
- clearParams: { clearColor: [0, 0, 0, 0] },
303
- combineMaxMin
304
- });
305
- }
306
- }
307
- }
308
- }
309
- // render all aggregated grid-cells to generate Min, Max or MaxMin data texture
310
- _renderToMaxMinTexture(opts) {
311
- const { id, parameters, gridSize, minOrMaxFb, combineMaxMin, clearParams = {} } = opts;
312
- const { framebuffers } = this.state;
313
- const { gl, allAggregationModel } = this;
314
- withParameters(gl, {
315
- ...clearParams,
316
- framebuffer: minOrMaxFb,
317
- viewport: [0, 0, gridSize[0], gridSize[1]]
318
- }, () => {
319
- gl.clear(gl.COLOR_BUFFER_BIT);
320
- allAggregationModel.draw({
321
- parameters,
322
- uniforms: {
323
- uSampler: framebuffers[id].texture,
324
- gridSize,
325
- combineMaxMin
326
- }
327
- });
328
- });
329
- }
330
- // render all data points to aggregate weights
331
- _renderToWeightsTexture(opts) {
332
- const { id, parameters, moduleSettings, uniforms, gridSize, weights } = opts;
333
- const { framebuffers, equations, weightAttributes } = this.state;
334
- const { gl, gridAggregationModel } = this;
335
- const { operation } = weights[id];
336
- const clearColor = operation === AGGREGATION_OPERATION.MIN
337
- ? [MAX_32_BIT_FLOAT, MAX_32_BIT_FLOAT, MAX_32_BIT_FLOAT, 0]
338
- : [0, 0, 0, 0];
339
- withParameters(gl, {
340
- framebuffer: framebuffers[id],
341
- viewport: [0, 0, gridSize[0], gridSize[1]],
342
- clearColor
343
- }, () => {
344
- gl.clear(gl.COLOR_BUFFER_BIT);
345
- const attributes = { weights: weightAttributes[id] };
346
- gridAggregationModel.draw({
347
- parameters: { ...parameters, blendEquation: equations[id] },
348
- moduleSettings,
349
- uniforms,
350
- attributes
351
- });
352
- });
353
- if (operation === AGGREGATION_OPERATION.MEAN) {
354
- const { meanTextures, textures } = this.state;
355
- const transformOptions = {
356
- _sourceTextures: { aggregationValues: meanTextures[id] },
357
- _targetTexture: textures[id],
358
- elementCount: textures[id].width * textures[id].height
359
- };
360
- if (this.meanTransform) {
361
- this.meanTransform.update(transformOptions);
362
- }
363
- else {
364
- this.meanTransform = getMeanTransform(gl, transformOptions);
365
- }
366
- this.meanTransform.run({
367
- parameters: {
368
- blend: false,
369
- depthTest: false
370
- }
371
- });
372
- // update framebuffer with mean results so readPixelsToBuffer returns mean values
373
- framebuffers[id].attach({ [GL.COLOR_ATTACHMENT0]: textures[id] });
374
- }
375
- }
376
- _runAggregation(opts) {
377
- this._updateModels(opts);
378
- this._setupFramebuffers(opts);
379
- this._renderAggregateData(opts);
380
- const results = this._getAggregateData(opts);
381
- this.setState({ results });
382
- return results;
383
- }
384
- // set up framebuffer for each weight
385
- /* eslint-disable complexity, max-depth, max-statements*/
386
- _setupFramebuffers(opts) {
387
- const { textures, framebuffers, maxMinFramebuffers, minFramebuffers, maxFramebuffers, meanTextures, equations } = this.state;
388
- const { weights } = opts;
389
- const { numCol, numRow } = opts;
390
- const framebufferSize = { width: numCol, height: numRow };
391
- for (const id in weights) {
392
- const { needMin, needMax, combineMaxMin, operation } = weights[id];
393
- textures[id] =
394
- weights[id].aggregationTexture ||
395
- textures[id] ||
396
- getFloatTexture(this.gl, { id: `${id}-texture`, width: numCol, height: numRow });
397
- textures[id].resize(framebufferSize);
398
- let texture = textures[id];
399
- if (operation === AGGREGATION_OPERATION.MEAN) {
400
- // For MEAN, we first aggregatet into a temp texture
401
- meanTextures[id] =
402
- meanTextures[id] ||
403
- getFloatTexture(this.gl, { id: `${id}-mean-texture`, width: numCol, height: numRow });
404
- meanTextures[id].resize(framebufferSize);
405
- texture = meanTextures[id];
406
- }
407
- if (framebuffers[id]) {
408
- framebuffers[id].attach({ [GL.COLOR_ATTACHMENT0]: texture });
409
- }
410
- else {
411
- framebuffers[id] = getFramebuffer(this.gl, {
412
- id: `${id}-fb`,
413
- width: numCol,
414
- height: numRow,
415
- texture
416
- });
417
- }
418
- framebuffers[id].resize(framebufferSize);
419
- equations[id] = EQUATION_MAP[operation] || EQUATION_MAP.SUM;
420
- // For min/max framebuffers will use default size 1X1
421
- if (needMin || needMax) {
422
- if (needMin && needMax && combineMaxMin) {
423
- if (!maxMinFramebuffers[id]) {
424
- texture = weights[id].maxMinTexture || this._getMinMaxTexture(`${id}-maxMinTexture`);
425
- maxMinFramebuffers[id] = getFramebuffer(this.gl, { id: `${id}-maxMinFb`, texture });
426
- }
427
- }
428
- else {
429
- if (needMin) {
430
- if (!minFramebuffers[id]) {
431
- texture = weights[id].minTexture || this._getMinMaxTexture(`${id}-minTexture`);
432
- minFramebuffers[id] = getFramebuffer(this.gl, {
433
- id: `${id}-minFb`,
434
- texture
435
- });
436
- }
437
- }
438
- if (needMax) {
439
- if (!maxFramebuffers[id]) {
440
- texture = weights[id].maxTexture || this._getMinMaxTexture(`${id}-maxTexture`);
441
- maxFramebuffers[id] = getFramebuffer(this.gl, {
442
- id: `${id}-maxFb`,
443
- texture
444
- });
445
- }
446
- }
447
- }
448
- }
449
- }
450
- }
451
- /* eslint-enable complexity, max-depth, max-statements */
452
- _getMinMaxTexture(name) {
453
- const { resources } = this.state;
454
- if (!resources[name]) {
455
- resources[name] = getFloatTexture(this.gl, { id: `resourceName` });
456
- }
457
- return resources[name];
458
- }
459
- _setupModels({ numCol = 0, numRow = 0 } = {}) {
460
- const { gl } = this;
461
- const { shaderOptions } = this.state;
462
- this.gridAggregationModel?.delete();
463
- this.gridAggregationModel = getAggregationModel(gl, shaderOptions);
464
- if (!this.allAggregationModel) {
465
- const instanceCount = numCol * numRow;
466
- this.allAggregationModel = getAllAggregationModel(gl, instanceCount);
467
- }
468
- }
469
- // set up buffers for all weights
470
- _setupWeightAttributes(opts) {
471
- const { weightAttributes } = this.state;
472
- const { weights } = opts;
473
- for (const id in weights) {
474
- weightAttributes[id] = opts.attributes[id];
475
- }
476
- }
477
- // GPU Aggregation results are provided in Buffers, if new Buffer objects are created track them for later deletion.
478
- /* eslint-disable max-depth */
479
- _trackGPUResultBuffers(results, weights) {
480
- const { resources } = this.state;
481
- for (const id in results) {
482
- if (results[id]) {
483
- for (const bufferName of BUFFER_NAMES) {
484
- if (results[id][bufferName] && weights[id][bufferName] !== results[id][bufferName]) {
485
- // No result buffer is provided in weights object, `readPixelsToBuffer` has created a new Buffer object
486
- // collect the new buffer for garabge collection
487
- const name = `gpu-result-${id}-${bufferName}`;
488
- if (resources[name]) {
489
- resources[name].delete();
490
- }
491
- resources[name] = results[id][bufferName];
492
- }
493
- }
494
- }
495
- }
496
- }
497
- /* eslint-enable max-depth */
498
- _updateModels(opts) {
499
- const { vertexCount, attributes, numCol, numRow } = opts;
500
- const { modelDirty } = this.state;
501
- if (modelDirty) {
502
- this._setupModels(opts);
503
- this.setState({ modelDirty: false });
504
- }
505
- // this maps color/elevation to weight name.
506
- this._setupWeightAttributes(opts);
507
- this.gridAggregationModel.setVertexCount(vertexCount);
508
- this.gridAggregationModel.setAttributes(attributes);
509
- this.allAggregationModel.setInstanceCount(numCol * numRow);
510
- }
511
- }
512
- // HELPER METHODS
513
- function normalizeWeightParams(weights) {
514
- const result = {};
515
- for (const id in weights) {
516
- result[id] = { ...DEFAULT_WEIGHT_PARAMS, ...weights[id] };
517
- }
518
- return result;
519
- }
520
- function deleteResources(resources) {
521
- resources = Array.isArray(resources) ? resources : [resources];
522
- resources.forEach(obj => {
523
- for (const name in obj) {
524
- obj[name].delete();
525
- }
526
- });
527
- }
528
- function getAggregationModel(gl, shaderOptions) {
529
- const shaders = mergeShaders({
530
- vs: AGGREGATE_TO_GRID_VS,
531
- fs: AGGREGATE_TO_GRID_FS,
532
- modules: [fp64arithmetic, project32]
533
- }, shaderOptions);
534
- return new Model(gl, {
535
- id: 'Gird-Aggregation-Model',
536
- vertexCount: 1,
537
- drawMode: GL.POINTS,
538
- ...shaders
539
- });
540
- }
541
- function getAllAggregationModel(gl, instanceCount) {
542
- return new Model(gl, {
543
- id: 'All-Aggregation-Model',
544
- vs: AGGREGATE_ALL_VS,
545
- fs: AGGREGATE_ALL_FS,
546
- modules: [fp64arithmetic],
547
- vertexCount: 1,
548
- drawMode: GL.POINTS,
549
- isInstanced: true,
550
- instanceCount,
551
- attributes: {
552
- position: [0, 0]
553
- }
554
- });
555
- }
556
- function getMeanTransform(gl, opts) {
557
- return new Transform(gl, {
558
- vs: TRANSFORM_MEAN_VS,
559
- _targetTextureVarying: 'meanValues',
560
- ...opts
561
- });
562
- }
@@ -1,36 +0,0 @@
1
- // Copyright (c) 2015 - 2018 Uber Technologies, Inc.
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy
4
- // of this software and associated documentation files (the "Software"), to deal
5
- // in the Software without restriction, including without limitation the rights
6
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- // copies of the Software, and to permit persons to whom the Software is
8
- // furnished to do so, subject to the following conditions:
9
- //
10
- // The above copyright notice and this permission notice shall be included in
11
- // all copies or substantial portions of the Software.
12
- //
13
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- // THE SOFTWARE.
20
- export default `\
21
- #define SHADER_NAME gpu-aggregation-transform-mean-vs
22
- attribute vec4 aggregationValues;
23
- varying vec4 meanValues;
24
-
25
- void main()
26
- {
27
- // TODO: Use 64-bit division ?? not needed given this is aggregation ??
28
- bool isCellValid = bool(aggregationValues.w > 0.);
29
- // aggregationValues: XYZ contain aggregated values, W contains count
30
- meanValues.xyz = isCellValid ? aggregationValues.xyz/aggregationValues.w : vec3(0, 0, 0);
31
- meanValues.w = aggregationValues.w;
32
-
33
- // Enforce default value for ANGLE issue (https://bugs.chromium.org/p/angleproject/issues/detail?id=3941)
34
- gl_PointSize = 1.0;
35
- }
36
- `;