ol 7.0.0-dev.1658443472213 → 7.0.0-dev.1658733468997
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/Overlay.d.ts +3 -25
- package/Overlay.d.ts.map +1 -1
- package/Overlay.js +3 -25
- package/Overlay.js.map +1 -1
- package/package.json +2 -1
- package/render/webgl/BatchRenderer.d.ts +92 -0
- package/render/webgl/BatchRenderer.d.ts.map +1 -0
- package/render/webgl/BatchRenderer.js +165 -0
- package/render/webgl/BatchRenderer.js.map +1 -0
- package/render/webgl/LineStringBatchRenderer.d.ts +27 -0
- package/render/webgl/LineStringBatchRenderer.d.ts.map +1 -0
- package/render/webgl/LineStringBatchRenderer.js +114 -0
- package/render/webgl/LineStringBatchRenderer.js.map +1 -0
- package/render/webgl/MixedGeometryBatch.d.ts +306 -0
- package/render/webgl/MixedGeometryBatch.d.ts.map +1 -0
- package/render/webgl/MixedGeometryBatch.js +342 -0
- package/render/webgl/MixedGeometryBatch.js.map +1 -0
- package/render/webgl/PointBatchRenderer.d.ts +26 -0
- package/render/webgl/PointBatchRenderer.d.ts.map +1 -0
- package/render/webgl/PointBatchRenderer.js +102 -0
- package/render/webgl/PointBatchRenderer.js.map +1 -0
- package/render/webgl/PolygonBatchRenderer.d.ts +25 -0
- package/render/webgl/PolygonBatchRenderer.d.ts.map +1 -0
- package/render/webgl/PolygonBatchRenderer.js +110 -0
- package/render/webgl/PolygonBatchRenderer.js.map +1 -0
- package/render/webgl/constants.d.ts +43 -0
- package/render/webgl/constants.d.ts.map +1 -0
- package/render/webgl/constants.js +26 -0
- package/render/webgl/constants.js.map +1 -0
- package/render/webgl/utils.d.ts +76 -0
- package/render/webgl/utils.d.ts.map +1 -0
- package/render/webgl/utils.js +257 -0
- package/render/webgl/utils.js.map +1 -0
- package/renderer/webgl/Layer.d.ts +0 -98
- package/renderer/webgl/Layer.d.ts.map +1 -1
- package/renderer/webgl/Layer.js +0 -134
- package/renderer/webgl/Layer.js.map +1 -1
- package/renderer/webgl/PointsLayer.d.ts +4 -1
- package/renderer/webgl/PointsLayer.d.ts.map +1 -1
- package/renderer/webgl/PointsLayer.js +15 -8
- package/renderer/webgl/PointsLayer.js.map +1 -1
- package/renderer/webgl/TileLayer.js +1 -1
- package/renderer/webgl/TileLayer.js.map +1 -1
- package/renderer/webgl/VectorLayer.d.ts +142 -0
- package/renderer/webgl/VectorLayer.d.ts.map +1 -0
- package/renderer/webgl/VectorLayer.js +304 -0
- package/renderer/webgl/VectorLayer.js.map +1 -0
- package/renderer/webgl/shaders.d.ts +43 -0
- package/renderer/webgl/shaders.d.ts.map +1 -0
- package/renderer/webgl/shaders.js +53 -0
- package/renderer/webgl/shaders.js.map +1 -0
- package/src/Overlay.js +3 -25
- package/src/render/webgl/BatchRenderer.js +201 -0
- package/src/render/webgl/LineStringBatchRenderer.js +116 -0
- package/src/render/webgl/MixedGeometryBatch.js +364 -0
- package/src/render/webgl/PointBatchRenderer.js +97 -0
- package/src/render/webgl/PolygonBatchRenderer.js +117 -0
- package/src/render/webgl/constants.js +27 -0
- package/src/render/webgl/utils.js +351 -0
- package/src/renderer/webgl/Layer.js +0 -160
- package/src/renderer/webgl/PointsLayer.js +16 -12
- package/src/renderer/webgl/TileLayer.js +1 -1
- package/src/renderer/webgl/VectorLayer.js +409 -0
- package/src/renderer/webgl/shaders.js +198 -0
- package/src/webgl/Helper.js +30 -45
- package/src/worker/webgl.js +1 -1
- package/util.js +1 -1
- package/webgl/Helper.d.ts +17 -25
- package/webgl/Helper.d.ts.map +1 -1
- package/webgl/Helper.js +29 -43
- package/webgl/Helper.js.map +1 -1
- package/worker/webgl.js +1 -1
- package/worker/webgl.js.map +1 -1
|
@@ -13,26 +13,6 @@ import {
|
|
|
13
13
|
} from '../../transform.js';
|
|
14
14
|
import {containsCoordinate} from '../../extent.js';
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* @enum {string}
|
|
18
|
-
*/
|
|
19
|
-
export const WebGLWorkerMessageType = {
|
|
20
|
-
GENERATE_BUFFERS: 'GENERATE_BUFFERS',
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @typedef {Object} WebGLWorkerGenerateBuffersMessage
|
|
25
|
-
* This message will trigger the generation of a vertex and an index buffer based on the given render instructions.
|
|
26
|
-
* When the buffers are generated, the worked will send a message of the same type to the main thread, with
|
|
27
|
-
* the generated buffers in it.
|
|
28
|
-
* Note that any addition properties present in the message *will* be sent back to the main thread.
|
|
29
|
-
* @property {WebGLWorkerMessageType} type Message type
|
|
30
|
-
* @property {ArrayBuffer} renderInstructions Render instructions raw binary buffer.
|
|
31
|
-
* @property {ArrayBuffer} [vertexBuffer] Vertices array raw binary buffer (sent by the worker).
|
|
32
|
-
* @property {ArrayBuffer} [indexBuffer] Indices array raw binary buffer (sent by the worker).
|
|
33
|
-
* @property {number} [customAttributesCount] Amount of custom attributes count in the render instructions.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
16
|
/**
|
|
37
17
|
* @typedef {Object} PostProcessesOptions
|
|
38
18
|
* @property {number} [scaleRatio] Scale ratio; if < 1, the post process will render to a texture smaller than
|
|
@@ -343,144 +323,4 @@ class WebGLLayerRenderer extends LayerRenderer {
|
|
|
343
323
|
}
|
|
344
324
|
}
|
|
345
325
|
|
|
346
|
-
const tmpArray_ = [];
|
|
347
|
-
const bufferPositions_ = {vertexPosition: 0, indexPosition: 0};
|
|
348
|
-
|
|
349
|
-
function writePointVertex(buffer, pos, x, y, index) {
|
|
350
|
-
buffer[pos + 0] = x;
|
|
351
|
-
buffer[pos + 1] = y;
|
|
352
|
-
buffer[pos + 2] = index;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* An object holding positions both in an index and a vertex buffer.
|
|
357
|
-
* @typedef {Object} BufferPositions
|
|
358
|
-
* @property {number} vertexPosition Position in the vertex buffer
|
|
359
|
-
* @property {number} indexPosition Position in the index buffer
|
|
360
|
-
*/
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* Pushes a quad (two triangles) based on a point geometry
|
|
364
|
-
* @param {Float32Array} instructions Array of render instructions for points.
|
|
365
|
-
* @param {number} elementIndex Index from which render instructions will be read.
|
|
366
|
-
* @param {Float32Array} vertexBuffer Buffer in the form of a typed array.
|
|
367
|
-
* @param {Uint32Array} indexBuffer Buffer in the form of a typed array.
|
|
368
|
-
* @param {number} customAttributesCount Amount of custom attributes for each element.
|
|
369
|
-
* @param {BufferPositions} [bufferPositions] Buffer write positions; if not specified, positions will be set at 0.
|
|
370
|
-
* @return {BufferPositions} New buffer positions where to write next
|
|
371
|
-
* @property {number} vertexPosition New position in the vertex buffer where future writes should start.
|
|
372
|
-
* @property {number} indexPosition New position in the index buffer where future writes should start.
|
|
373
|
-
* @private
|
|
374
|
-
*/
|
|
375
|
-
export function writePointFeatureToBuffers(
|
|
376
|
-
instructions,
|
|
377
|
-
elementIndex,
|
|
378
|
-
vertexBuffer,
|
|
379
|
-
indexBuffer,
|
|
380
|
-
customAttributesCount,
|
|
381
|
-
bufferPositions
|
|
382
|
-
) {
|
|
383
|
-
// This is for x, y and index
|
|
384
|
-
const baseVertexAttrsCount = 3;
|
|
385
|
-
const baseInstructionsCount = 2;
|
|
386
|
-
const stride = baseVertexAttrsCount + customAttributesCount;
|
|
387
|
-
|
|
388
|
-
const x = instructions[elementIndex + 0];
|
|
389
|
-
const y = instructions[elementIndex + 1];
|
|
390
|
-
|
|
391
|
-
// read custom numerical attributes on the feature
|
|
392
|
-
const customAttrs = tmpArray_;
|
|
393
|
-
customAttrs.length = customAttributesCount;
|
|
394
|
-
for (let i = 0; i < customAttrs.length; i++) {
|
|
395
|
-
customAttrs[i] = instructions[elementIndex + baseInstructionsCount + i];
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
let vPos = bufferPositions ? bufferPositions.vertexPosition : 0;
|
|
399
|
-
let iPos = bufferPositions ? bufferPositions.indexPosition : 0;
|
|
400
|
-
const baseIndex = vPos / stride;
|
|
401
|
-
|
|
402
|
-
// push vertices for each of the four quad corners (first standard then custom attributes)
|
|
403
|
-
writePointVertex(vertexBuffer, vPos, x, y, 0);
|
|
404
|
-
customAttrs.length &&
|
|
405
|
-
vertexBuffer.set(customAttrs, vPos + baseVertexAttrsCount);
|
|
406
|
-
vPos += stride;
|
|
407
|
-
|
|
408
|
-
writePointVertex(vertexBuffer, vPos, x, y, 1);
|
|
409
|
-
customAttrs.length &&
|
|
410
|
-
vertexBuffer.set(customAttrs, vPos + baseVertexAttrsCount);
|
|
411
|
-
vPos += stride;
|
|
412
|
-
|
|
413
|
-
writePointVertex(vertexBuffer, vPos, x, y, 2);
|
|
414
|
-
customAttrs.length &&
|
|
415
|
-
vertexBuffer.set(customAttrs, vPos + baseVertexAttrsCount);
|
|
416
|
-
vPos += stride;
|
|
417
|
-
|
|
418
|
-
writePointVertex(vertexBuffer, vPos, x, y, 3);
|
|
419
|
-
customAttrs.length &&
|
|
420
|
-
vertexBuffer.set(customAttrs, vPos + baseVertexAttrsCount);
|
|
421
|
-
vPos += stride;
|
|
422
|
-
|
|
423
|
-
indexBuffer[iPos++] = baseIndex;
|
|
424
|
-
indexBuffer[iPos++] = baseIndex + 1;
|
|
425
|
-
indexBuffer[iPos++] = baseIndex + 3;
|
|
426
|
-
indexBuffer[iPos++] = baseIndex + 1;
|
|
427
|
-
indexBuffer[iPos++] = baseIndex + 2;
|
|
428
|
-
indexBuffer[iPos++] = baseIndex + 3;
|
|
429
|
-
|
|
430
|
-
bufferPositions_.vertexPosition = vPos;
|
|
431
|
-
bufferPositions_.indexPosition = iPos;
|
|
432
|
-
|
|
433
|
-
return bufferPositions_;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* Returns a texture of 1x1 pixel, white
|
|
438
|
-
* @private
|
|
439
|
-
* @return {ImageData} Image data.
|
|
440
|
-
*/
|
|
441
|
-
export function getBlankImageData() {
|
|
442
|
-
const canvas = document.createElement('canvas');
|
|
443
|
-
const image = canvas.getContext('2d').createImageData(1, 1);
|
|
444
|
-
image.data[0] = 255;
|
|
445
|
-
image.data[1] = 255;
|
|
446
|
-
image.data[2] = 255;
|
|
447
|
-
image.data[3] = 255;
|
|
448
|
-
return image;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
* Generates a color array based on a numerical id
|
|
453
|
-
* Note: the range for each component is 0 to 1 with 256 steps
|
|
454
|
-
* @param {number} id Id
|
|
455
|
-
* @param {Array<number>} [opt_array] Reusable array
|
|
456
|
-
* @return {Array<number>} Color array containing the encoded id
|
|
457
|
-
*/
|
|
458
|
-
export function colorEncodeId(id, opt_array) {
|
|
459
|
-
const array = opt_array || [];
|
|
460
|
-
const radix = 256;
|
|
461
|
-
const divide = radix - 1;
|
|
462
|
-
array[0] = Math.floor(id / radix / radix / radix) / divide;
|
|
463
|
-
array[1] = (Math.floor(id / radix / radix) % radix) / divide;
|
|
464
|
-
array[2] = (Math.floor(id / radix) % radix) / divide;
|
|
465
|
-
array[3] = (id % radix) / divide;
|
|
466
|
-
return array;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* Reads an id from a color-encoded array
|
|
471
|
-
* Note: the expected range for each component is 0 to 1 with 256 steps.
|
|
472
|
-
* @param {Array<number>} color Color array containing the encoded id
|
|
473
|
-
* @return {number} Decoded id
|
|
474
|
-
*/
|
|
475
|
-
export function colorDecodeId(color) {
|
|
476
|
-
let id = 0;
|
|
477
|
-
const radix = 256;
|
|
478
|
-
const mult = radix - 1;
|
|
479
|
-
id += Math.round(color[0] * radix * radix * radix * mult);
|
|
480
|
-
id += Math.round(color[1] * radix * radix * mult);
|
|
481
|
-
id += Math.round(color[2] * radix * mult);
|
|
482
|
-
id += Math.round(color[3] * mult);
|
|
483
|
-
return id;
|
|
484
|
-
}
|
|
485
|
-
|
|
486
326
|
export default WebGLLayerRenderer;
|
|
@@ -5,14 +5,11 @@ import BaseVector from '../../layer/BaseVector.js';
|
|
|
5
5
|
import VectorEventType from '../../source/VectorEventType.js';
|
|
6
6
|
import ViewHint from '../../ViewHint.js';
|
|
7
7
|
import WebGLArrayBuffer from '../../webgl/Buffer.js';
|
|
8
|
-
import WebGLLayerRenderer
|
|
9
|
-
WebGLWorkerMessageType,
|
|
10
|
-
colorDecodeId,
|
|
11
|
-
colorEncodeId,
|
|
12
|
-
} from './Layer.js';
|
|
8
|
+
import WebGLLayerRenderer from './Layer.js';
|
|
13
9
|
import WebGLRenderTarget from '../../webgl/RenderTarget.js';
|
|
14
10
|
import {ARRAY_BUFFER, DYNAMIC_DRAW, ELEMENT_ARRAY_BUFFER} from '../../webgl.js';
|
|
15
11
|
import {AttributeType, DefaultUniform} from '../../webgl/Helper.js';
|
|
12
|
+
import {WebGLWorkerMessageType} from '../../render/webgl/constants.js';
|
|
16
13
|
import {
|
|
17
14
|
apply as applyTransform,
|
|
18
15
|
create as createTransform,
|
|
@@ -22,6 +19,7 @@ import {
|
|
|
22
19
|
} from '../../transform.js';
|
|
23
20
|
import {assert} from '../../asserts.js';
|
|
24
21
|
import {buffer, createEmpty, equals, getWidth} from '../../extent.js';
|
|
22
|
+
import {colorDecodeId, colorEncodeId} from '../../render/webgl/utils.js';
|
|
25
23
|
import {create as createWebGLWorker} from '../../worker/webgl.js';
|
|
26
24
|
import {getUid} from '../../util.js';
|
|
27
25
|
import {listen, unlistenByKey} from '../../events.js';
|
|
@@ -294,7 +292,11 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
|
|
|
294
292
|
*/
|
|
295
293
|
this.generateBuffersRun_ = 0;
|
|
296
294
|
|
|
295
|
+
/**
|
|
296
|
+
* @private
|
|
297
|
+
*/
|
|
297
298
|
this.worker_ = createWebGLWorker();
|
|
299
|
+
|
|
298
300
|
this.worker_.addEventListener(
|
|
299
301
|
'message',
|
|
300
302
|
/**
|
|
@@ -303,7 +305,7 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
|
|
|
303
305
|
*/
|
|
304
306
|
function (event) {
|
|
305
307
|
const received = event.data;
|
|
306
|
-
if (received.type === WebGLWorkerMessageType.
|
|
308
|
+
if (received.type === WebGLWorkerMessageType.GENERATE_POINT_BUFFERS) {
|
|
307
309
|
const projectionTransform = received.projectionTransform;
|
|
308
310
|
if (received.hitDetection) {
|
|
309
311
|
this.hitVerticesBuffer_.fromArrayBuffer(received.vertexBuffer);
|
|
@@ -540,7 +542,7 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
|
|
|
540
542
|
this.previousExtent_ = frameState.extent.slice();
|
|
541
543
|
}
|
|
542
544
|
|
|
543
|
-
this.helper.useProgram(this.program_);
|
|
545
|
+
this.helper.useProgram(this.program_, frameState);
|
|
544
546
|
this.helper.prepareDraw(frameState);
|
|
545
547
|
|
|
546
548
|
// write new data
|
|
@@ -637,9 +639,10 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
|
|
|
637
639
|
}
|
|
638
640
|
}
|
|
639
641
|
|
|
640
|
-
/** @type {import('
|
|
642
|
+
/** @type {import('../../render/webgl/constants.js').WebGLWorkerGenerateBuffersMessage} */
|
|
641
643
|
const message = {
|
|
642
|
-
|
|
644
|
+
id: 0,
|
|
645
|
+
type: WebGLWorkerMessageType.GENERATE_POINT_BUFFERS,
|
|
643
646
|
renderInstructions: this.renderInstructions_.buffer,
|
|
644
647
|
customAttributesCount: this.customAttributes.length,
|
|
645
648
|
};
|
|
@@ -650,10 +653,11 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
|
|
|
650
653
|
this.worker_.postMessage(message, [this.renderInstructions_.buffer]);
|
|
651
654
|
this.renderInstructions_ = null;
|
|
652
655
|
|
|
653
|
-
/** @type {import('
|
|
656
|
+
/** @type {import('../../render/webgl/constants.js').WebGLWorkerGenerateBuffersMessage} */
|
|
654
657
|
if (this.hitDetectionEnabled_) {
|
|
655
658
|
const hitMessage = {
|
|
656
|
-
|
|
659
|
+
id: 0,
|
|
660
|
+
type: WebGLWorkerMessageType.GENERATE_POINT_BUFFERS,
|
|
657
661
|
renderInstructions: this.hitRenderInstructions_.buffer,
|
|
658
662
|
customAttributesCount: 5 + this.customAttributes.length,
|
|
659
663
|
};
|
|
@@ -726,7 +730,7 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
|
|
|
726
730
|
Math.floor(frameState.size[1] / 2),
|
|
727
731
|
]);
|
|
728
732
|
|
|
729
|
-
this.helper.useProgram(this.hitProgram_);
|
|
733
|
+
this.helper.useProgram(this.hitProgram_, frameState);
|
|
730
734
|
this.helper.prepareDrawToRenderTarget(
|
|
731
735
|
frameState,
|
|
732
736
|
this.hitRenderTarget_,
|
|
@@ -508,7 +508,7 @@ class WebGLTileLayerRenderer extends WebGLLayerRenderer {
|
|
|
508
508
|
}
|
|
509
509
|
}
|
|
510
510
|
|
|
511
|
-
this.helper.useProgram(this.program_);
|
|
511
|
+
this.helper.useProgram(this.program_, frameState);
|
|
512
512
|
this.helper.prepareDraw(frameState, !blend);
|
|
513
513
|
|
|
514
514
|
const zs = Object.keys(tileTexturesByZ)
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ol/renderer/webgl/VectorLayer
|
|
3
|
+
*/
|
|
4
|
+
import BaseVector from '../../layer/BaseVector.js';
|
|
5
|
+
import LineStringBatchRenderer from '../../render/webgl/LineStringBatchRenderer.js';
|
|
6
|
+
import MixedGeometryBatch from '../../render/webgl/MixedGeometryBatch.js';
|
|
7
|
+
import PointBatchRenderer from '../../render/webgl/PointBatchRenderer.js';
|
|
8
|
+
import PolygonBatchRenderer from '../../render/webgl/PolygonBatchRenderer.js';
|
|
9
|
+
import VectorEventType from '../../source/VectorEventType.js';
|
|
10
|
+
import ViewHint from '../../ViewHint.js';
|
|
11
|
+
import WebGLLayerRenderer from './Layer.js';
|
|
12
|
+
import {DefaultUniform} from '../../webgl/Helper.js';
|
|
13
|
+
import {
|
|
14
|
+
FILL_FRAGMENT_SHADER,
|
|
15
|
+
FILL_VERTEX_SHADER,
|
|
16
|
+
POINT_FRAGMENT_SHADER,
|
|
17
|
+
POINT_VERTEX_SHADER,
|
|
18
|
+
STROKE_FRAGMENT_SHADER,
|
|
19
|
+
STROKE_VERTEX_SHADER,
|
|
20
|
+
packColor,
|
|
21
|
+
} from './shaders.js';
|
|
22
|
+
import {buffer, createEmpty, equals, getWidth} from '../../extent.js';
|
|
23
|
+
import {create as createTransform} from '../../transform.js';
|
|
24
|
+
import {create as createWebGLWorker} from '../../worker/webgl.js';
|
|
25
|
+
import {listen, unlistenByKey} from '../../events.js';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {function(import("../../Feature").default, Object<string, *>):number} CustomAttributeCallback A callback computing
|
|
29
|
+
* the value of a custom attribute (different for each feature) to be passed on to the GPU.
|
|
30
|
+
* Properties are available as 2nd arg for quicker access.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @typedef {Object} ShaderProgram An object containing both shaders (vertex and fragment) as well as the required attributes
|
|
35
|
+
* @property {string} [vertexShader] Vertex shader source (using the default one if unspecified).
|
|
36
|
+
* @property {string} [fragmentShader] Fragment shader source (using the default one if unspecified).
|
|
37
|
+
* @property {Object<import("./shaders.js").DefaultAttributes,CustomAttributeCallback>} attributes Custom attributes made available in the vertex shader.
|
|
38
|
+
* Keys are the names of the attributes which are then accessible in the vertex shader using the `a_` prefix, e.g.: `a_opacity`.
|
|
39
|
+
* Default shaders rely on the attributes in {@link module:ol/render/webgl/shaders~DefaultAttributes}.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @typedef {Object} Options
|
|
44
|
+
* @property {string} [className='ol-layer'] A CSS class name to set to the canvas element.
|
|
45
|
+
* @property {ShaderProgram} [fill] Attributes and shaders for filling polygons.
|
|
46
|
+
* @property {ShaderProgram} [stroke] Attributes and shaders for line strings and polygon strokes.
|
|
47
|
+
* @property {ShaderProgram} [point] Attributes and shaders for points.
|
|
48
|
+
* @property {Object<string,import("../../webgl/Helper").UniformValue>} [uniforms] Uniform definitions.
|
|
49
|
+
* @property {Array<import("./Layer").PostProcessesOptions>} [postProcesses] Post-processes definitions
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {Object<import("./shaders.js").DefaultAttributes,CustomAttributeCallback>} obj Lookup of attribute getters.
|
|
54
|
+
* @return {Array<import("../../render/webgl/BatchRenderer").CustomAttribute>} An array of attribute descriptors.
|
|
55
|
+
*/
|
|
56
|
+
function toAttributesArray(obj) {
|
|
57
|
+
return Object.keys(obj).map((key) => ({name: key, callback: obj[key]}));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @classdesc
|
|
62
|
+
* Experimental WebGL vector renderer. Supports polygons, lines and points:
|
|
63
|
+
* * Polygons are broken down into triangles
|
|
64
|
+
* * Lines are rendered as strips of quads
|
|
65
|
+
* * Points are rendered as quads
|
|
66
|
+
*
|
|
67
|
+
* You need to provide vertex and fragment shaders as well as custom attributes for each type of geometry. All shaders
|
|
68
|
+
* can access the uniforms in the {@link module:ol/webgl/Helper~DefaultUniform} enum.
|
|
69
|
+
* The vertex shaders can access the following attributes depending on the geometry type:
|
|
70
|
+
* * For polygons: {@link module:ol/render/webgl/PolygonBatchRenderer~Attributes}
|
|
71
|
+
* * For line strings: {@link module:ol/render/webgl/LineStringBatchRenderer~Attributes}
|
|
72
|
+
* * For points: {@link module:ol/render/webgl/PointBatchRenderer~Attributes}
|
|
73
|
+
*
|
|
74
|
+
* Please note that the fragment shaders output should have premultiplied alpha, otherwise visual anomalies may occur.
|
|
75
|
+
*
|
|
76
|
+
* Note: this uses {@link module:ol/webgl/Helper~WebGLHelper} internally.
|
|
77
|
+
*/
|
|
78
|
+
class WebGLVectorLayerRenderer extends WebGLLayerRenderer {
|
|
79
|
+
/**
|
|
80
|
+
* @param {import("../../layer/Layer.js").default} layer Layer.
|
|
81
|
+
* @param {Options} options Options.
|
|
82
|
+
*/
|
|
83
|
+
constructor(layer, options) {
|
|
84
|
+
const uniforms = options.uniforms || {};
|
|
85
|
+
const projectionMatrixTransform = createTransform();
|
|
86
|
+
uniforms[DefaultUniform.PROJECTION_MATRIX] = projectionMatrixTransform;
|
|
87
|
+
|
|
88
|
+
super(layer, {
|
|
89
|
+
uniforms: uniforms,
|
|
90
|
+
postProcesses: options.postProcesses,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
this.sourceRevision_ = -1;
|
|
94
|
+
|
|
95
|
+
this.previousExtent_ = createEmpty();
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* This transform is updated on every frame and is the composition of:
|
|
99
|
+
* - invert of the world->screen transform that was used when rebuilding buffers (see `this.renderTransform_`)
|
|
100
|
+
* - current world->screen transform
|
|
101
|
+
* @type {import("../../transform.js").Transform}
|
|
102
|
+
* @private
|
|
103
|
+
*/
|
|
104
|
+
this.currentTransform_ = projectionMatrixTransform;
|
|
105
|
+
|
|
106
|
+
const fillAttributes = {
|
|
107
|
+
color: function () {
|
|
108
|
+
return packColor('#ddd');
|
|
109
|
+
},
|
|
110
|
+
opacity: function () {
|
|
111
|
+
return 1;
|
|
112
|
+
},
|
|
113
|
+
...(options.fill && options.fill.attributes),
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const strokeAttributes = {
|
|
117
|
+
color: function () {
|
|
118
|
+
return packColor('#eee');
|
|
119
|
+
},
|
|
120
|
+
opacity: function () {
|
|
121
|
+
return 1;
|
|
122
|
+
},
|
|
123
|
+
width: function () {
|
|
124
|
+
return 1.5;
|
|
125
|
+
},
|
|
126
|
+
...(options.stroke && options.stroke.attributes),
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const pointAttributes = {
|
|
130
|
+
color: function () {
|
|
131
|
+
return packColor('#eee');
|
|
132
|
+
},
|
|
133
|
+
opacity: function () {
|
|
134
|
+
return 1;
|
|
135
|
+
},
|
|
136
|
+
...(options.point && options.point.attributes),
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
this.fillVertexShader_ =
|
|
140
|
+
(options.fill && options.fill.vertexShader) || FILL_VERTEX_SHADER;
|
|
141
|
+
this.fillFragmentShader_ =
|
|
142
|
+
(options.fill && options.fill.fragmentShader) || FILL_FRAGMENT_SHADER;
|
|
143
|
+
this.fillAttributes_ = toAttributesArray(fillAttributes);
|
|
144
|
+
|
|
145
|
+
this.strokeVertexShader_ =
|
|
146
|
+
(options.stroke && options.stroke.vertexShader) || STROKE_VERTEX_SHADER;
|
|
147
|
+
this.strokeFragmentShader_ =
|
|
148
|
+
(options.stroke && options.stroke.fragmentShader) ||
|
|
149
|
+
STROKE_FRAGMENT_SHADER;
|
|
150
|
+
this.strokeAttributes_ = toAttributesArray(strokeAttributes);
|
|
151
|
+
|
|
152
|
+
this.pointVertexShader_ =
|
|
153
|
+
(options.point && options.point.vertexShader) || POINT_VERTEX_SHADER;
|
|
154
|
+
this.pointFragmentShader_ =
|
|
155
|
+
(options.point && options.point.fragmentShader) || POINT_FRAGMENT_SHADER;
|
|
156
|
+
this.pointAttributes_ = toAttributesArray(pointAttributes);
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @private
|
|
160
|
+
*/
|
|
161
|
+
this.worker_ = createWebGLWorker();
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* @private
|
|
165
|
+
*/
|
|
166
|
+
this.batch_ = new MixedGeometryBatch();
|
|
167
|
+
|
|
168
|
+
const source = this.getLayer().getSource();
|
|
169
|
+
this.batch_.addFeatures(source.getFeatures());
|
|
170
|
+
this.sourceListenKeys_ = [
|
|
171
|
+
listen(
|
|
172
|
+
source,
|
|
173
|
+
VectorEventType.ADDFEATURE,
|
|
174
|
+
this.handleSourceFeatureAdded_,
|
|
175
|
+
this
|
|
176
|
+
),
|
|
177
|
+
listen(
|
|
178
|
+
source,
|
|
179
|
+
VectorEventType.CHANGEFEATURE,
|
|
180
|
+
this.handleSourceFeatureChanged_,
|
|
181
|
+
this
|
|
182
|
+
),
|
|
183
|
+
listen(
|
|
184
|
+
source,
|
|
185
|
+
VectorEventType.REMOVEFEATURE,
|
|
186
|
+
this.handleSourceFeatureDelete_,
|
|
187
|
+
this
|
|
188
|
+
),
|
|
189
|
+
listen(
|
|
190
|
+
source,
|
|
191
|
+
VectorEventType.CLEAR,
|
|
192
|
+
this.handleSourceFeatureClear_,
|
|
193
|
+
this
|
|
194
|
+
),
|
|
195
|
+
];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
afterHelperCreated() {
|
|
199
|
+
this.polygonRenderer_ = new PolygonBatchRenderer(
|
|
200
|
+
this.helper,
|
|
201
|
+
this.worker_,
|
|
202
|
+
this.fillVertexShader_,
|
|
203
|
+
this.fillFragmentShader_,
|
|
204
|
+
this.fillAttributes_
|
|
205
|
+
);
|
|
206
|
+
this.pointRenderer_ = new PointBatchRenderer(
|
|
207
|
+
this.helper,
|
|
208
|
+
this.worker_,
|
|
209
|
+
this.pointVertexShader_,
|
|
210
|
+
this.pointFragmentShader_,
|
|
211
|
+
this.pointAttributes_
|
|
212
|
+
);
|
|
213
|
+
this.lineStringRenderer_ = new LineStringBatchRenderer(
|
|
214
|
+
this.helper,
|
|
215
|
+
this.worker_,
|
|
216
|
+
this.strokeVertexShader_,
|
|
217
|
+
this.strokeFragmentShader_,
|
|
218
|
+
this.strokeAttributes_
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* @param {import("../../source/Vector.js").VectorSourceEvent} event Event.
|
|
224
|
+
* @private
|
|
225
|
+
*/
|
|
226
|
+
handleSourceFeatureAdded_(event) {
|
|
227
|
+
const feature = event.feature;
|
|
228
|
+
this.batch_.addFeature(feature);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* @param {import("../../source/Vector.js").VectorSourceEvent} event Event.
|
|
233
|
+
* @private
|
|
234
|
+
*/
|
|
235
|
+
handleSourceFeatureChanged_(event) {
|
|
236
|
+
const feature = event.feature;
|
|
237
|
+
this.batch_.changeFeature(feature);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* @param {import("../../source/Vector.js").VectorSourceEvent} event Event.
|
|
242
|
+
* @private
|
|
243
|
+
*/
|
|
244
|
+
handleSourceFeatureDelete_(event) {
|
|
245
|
+
const feature = event.feature;
|
|
246
|
+
this.batch_.removeFeature(feature);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* @private
|
|
251
|
+
*/
|
|
252
|
+
handleSourceFeatureClear_() {
|
|
253
|
+
this.batch_.clear();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Render the layer.
|
|
258
|
+
* @param {import("../../PluggableMap.js").FrameState} frameState Frame state.
|
|
259
|
+
* @return {HTMLElement} The rendered element.
|
|
260
|
+
*/
|
|
261
|
+
renderFrame(frameState) {
|
|
262
|
+
const gl = this.helper.getGL();
|
|
263
|
+
this.preRender(gl, frameState);
|
|
264
|
+
|
|
265
|
+
const layer = this.getLayer();
|
|
266
|
+
const vectorSource = layer.getSource();
|
|
267
|
+
const projection = frameState.viewState.projection;
|
|
268
|
+
const multiWorld = vectorSource.getWrapX() && projection.canWrapX();
|
|
269
|
+
const projectionExtent = projection.getExtent();
|
|
270
|
+
const extent = frameState.extent;
|
|
271
|
+
const worldWidth = multiWorld ? getWidth(projectionExtent) : null;
|
|
272
|
+
const endWorld = multiWorld
|
|
273
|
+
? Math.ceil((extent[2] - projectionExtent[2]) / worldWidth) + 1
|
|
274
|
+
: 1;
|
|
275
|
+
let world = multiWorld
|
|
276
|
+
? Math.floor((extent[0] - projectionExtent[0]) / worldWidth)
|
|
277
|
+
: 0;
|
|
278
|
+
|
|
279
|
+
do {
|
|
280
|
+
this.polygonRenderer_.render(
|
|
281
|
+
this.batch_.polygonBatch,
|
|
282
|
+
this.currentTransform_,
|
|
283
|
+
frameState,
|
|
284
|
+
world * worldWidth
|
|
285
|
+
);
|
|
286
|
+
this.lineStringRenderer_.render(
|
|
287
|
+
this.batch_.lineStringBatch,
|
|
288
|
+
this.currentTransform_,
|
|
289
|
+
frameState,
|
|
290
|
+
world * worldWidth
|
|
291
|
+
);
|
|
292
|
+
this.pointRenderer_.render(
|
|
293
|
+
this.batch_.pointBatch,
|
|
294
|
+
this.currentTransform_,
|
|
295
|
+
frameState,
|
|
296
|
+
world * worldWidth
|
|
297
|
+
);
|
|
298
|
+
} while (++world < endWorld);
|
|
299
|
+
|
|
300
|
+
this.helper.finalizeDraw(frameState);
|
|
301
|
+
|
|
302
|
+
const canvas = this.helper.getCanvas();
|
|
303
|
+
const layerState = frameState.layerStatesArray[frameState.layerIndex];
|
|
304
|
+
const opacity = layerState.opacity;
|
|
305
|
+
if (opacity !== parseFloat(canvas.style.opacity)) {
|
|
306
|
+
canvas.style.opacity = String(opacity);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
this.postRender(gl, frameState);
|
|
310
|
+
return canvas;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Determine whether renderFrame should be called.
|
|
315
|
+
* @param {import("../../PluggableMap.js").FrameState} frameState Frame state.
|
|
316
|
+
* @return {boolean} Layer is ready to be rendered.
|
|
317
|
+
*/
|
|
318
|
+
prepareFrameInternal(frameState) {
|
|
319
|
+
const layer = this.getLayer();
|
|
320
|
+
const vectorSource = layer.getSource();
|
|
321
|
+
const viewState = frameState.viewState;
|
|
322
|
+
const viewNotMoving =
|
|
323
|
+
!frameState.viewHints[ViewHint.ANIMATING] &&
|
|
324
|
+
!frameState.viewHints[ViewHint.INTERACTING];
|
|
325
|
+
const extentChanged = !equals(this.previousExtent_, frameState.extent);
|
|
326
|
+
const sourceChanged = this.sourceRevision_ < vectorSource.getRevision();
|
|
327
|
+
|
|
328
|
+
if (sourceChanged) {
|
|
329
|
+
this.sourceRevision_ = vectorSource.getRevision();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (viewNotMoving && (extentChanged || sourceChanged)) {
|
|
333
|
+
const projection = viewState.projection;
|
|
334
|
+
const resolution = viewState.resolution;
|
|
335
|
+
|
|
336
|
+
const renderBuffer =
|
|
337
|
+
layer instanceof BaseVector ? layer.getRenderBuffer() : 0;
|
|
338
|
+
const extent = buffer(frameState.extent, renderBuffer * resolution);
|
|
339
|
+
vectorSource.loadFeatures(extent, resolution, projection);
|
|
340
|
+
|
|
341
|
+
this.ready = false;
|
|
342
|
+
let remaining = 3;
|
|
343
|
+
const rebuildCb = () => {
|
|
344
|
+
remaining--;
|
|
345
|
+
this.ready = remaining <= 0;
|
|
346
|
+
this.getLayer().changed();
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
this.polygonRenderer_.rebuild(
|
|
350
|
+
this.batch_.polygonBatch,
|
|
351
|
+
frameState,
|
|
352
|
+
'Polygon',
|
|
353
|
+
rebuildCb
|
|
354
|
+
);
|
|
355
|
+
this.lineStringRenderer_.rebuild(
|
|
356
|
+
this.batch_.lineStringBatch,
|
|
357
|
+
frameState,
|
|
358
|
+
'LineString',
|
|
359
|
+
rebuildCb
|
|
360
|
+
);
|
|
361
|
+
this.pointRenderer_.rebuild(
|
|
362
|
+
this.batch_.pointBatch,
|
|
363
|
+
frameState,
|
|
364
|
+
'Point',
|
|
365
|
+
rebuildCb
|
|
366
|
+
);
|
|
367
|
+
this.previousExtent_ = frameState.extent.slice();
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
this.helper.makeProjectionTransform(frameState, this.currentTransform_);
|
|
371
|
+
this.helper.prepareDraw(frameState);
|
|
372
|
+
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* @param {import("../../coordinate.js").Coordinate} coordinate Coordinate.
|
|
378
|
+
* @param {import("../../PluggableMap.js").FrameState} frameState Frame state.
|
|
379
|
+
* @param {number} hitTolerance Hit tolerance in pixels.
|
|
380
|
+
* @param {import("../vector.js").FeatureCallback<T>} callback Feature callback.
|
|
381
|
+
* @param {Array<import("../Map.js").HitMatch<T>>} matches The hit detected matches with tolerance.
|
|
382
|
+
* @return {T|undefined} Callback result.
|
|
383
|
+
* @template T
|
|
384
|
+
*/
|
|
385
|
+
forEachFeatureAtCoordinate(
|
|
386
|
+
coordinate,
|
|
387
|
+
frameState,
|
|
388
|
+
hitTolerance,
|
|
389
|
+
callback,
|
|
390
|
+
matches
|
|
391
|
+
) {
|
|
392
|
+
return undefined;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Clean up.
|
|
397
|
+
*/
|
|
398
|
+
disposeInternal() {
|
|
399
|
+
this.worker_.terminate();
|
|
400
|
+
this.layer_ = null;
|
|
401
|
+
this.sourceListenKeys_.forEach(function (key) {
|
|
402
|
+
unlistenByKey(key);
|
|
403
|
+
});
|
|
404
|
+
this.sourceListenKeys_ = null;
|
|
405
|
+
super.disposeInternal();
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export default WebGLVectorLayerRenderer;
|