ol 7.0.0-dev.1658443472213 → 7.0.0-dev.1658477212801

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 (68) hide show
  1. package/package.json +2 -1
  2. package/render/webgl/BatchRenderer.d.ts +92 -0
  3. package/render/webgl/BatchRenderer.d.ts.map +1 -0
  4. package/render/webgl/BatchRenderer.js +165 -0
  5. package/render/webgl/BatchRenderer.js.map +1 -0
  6. package/render/webgl/LineStringBatchRenderer.d.ts +27 -0
  7. package/render/webgl/LineStringBatchRenderer.d.ts.map +1 -0
  8. package/render/webgl/LineStringBatchRenderer.js +114 -0
  9. package/render/webgl/LineStringBatchRenderer.js.map +1 -0
  10. package/render/webgl/MixedGeometryBatch.d.ts +306 -0
  11. package/render/webgl/MixedGeometryBatch.d.ts.map +1 -0
  12. package/render/webgl/MixedGeometryBatch.js +342 -0
  13. package/render/webgl/MixedGeometryBatch.js.map +1 -0
  14. package/render/webgl/PointBatchRenderer.d.ts +26 -0
  15. package/render/webgl/PointBatchRenderer.d.ts.map +1 -0
  16. package/render/webgl/PointBatchRenderer.js +102 -0
  17. package/render/webgl/PointBatchRenderer.js.map +1 -0
  18. package/render/webgl/PolygonBatchRenderer.d.ts +25 -0
  19. package/render/webgl/PolygonBatchRenderer.d.ts.map +1 -0
  20. package/render/webgl/PolygonBatchRenderer.js +110 -0
  21. package/render/webgl/PolygonBatchRenderer.js.map +1 -0
  22. package/render/webgl/constants.d.ts +43 -0
  23. package/render/webgl/constants.d.ts.map +1 -0
  24. package/render/webgl/constants.js +26 -0
  25. package/render/webgl/constants.js.map +1 -0
  26. package/render/webgl/utils.d.ts +76 -0
  27. package/render/webgl/utils.d.ts.map +1 -0
  28. package/render/webgl/utils.js +257 -0
  29. package/render/webgl/utils.js.map +1 -0
  30. package/renderer/webgl/Layer.d.ts +0 -98
  31. package/renderer/webgl/Layer.d.ts.map +1 -1
  32. package/renderer/webgl/Layer.js +0 -134
  33. package/renderer/webgl/Layer.js.map +1 -1
  34. package/renderer/webgl/PointsLayer.d.ts +4 -1
  35. package/renderer/webgl/PointsLayer.d.ts.map +1 -1
  36. package/renderer/webgl/PointsLayer.js +15 -8
  37. package/renderer/webgl/PointsLayer.js.map +1 -1
  38. package/renderer/webgl/TileLayer.js +1 -1
  39. package/renderer/webgl/TileLayer.js.map +1 -1
  40. package/renderer/webgl/VectorLayer.d.ts +142 -0
  41. package/renderer/webgl/VectorLayer.d.ts.map +1 -0
  42. package/renderer/webgl/VectorLayer.js +304 -0
  43. package/renderer/webgl/VectorLayer.js.map +1 -0
  44. package/renderer/webgl/shaders.d.ts +43 -0
  45. package/renderer/webgl/shaders.d.ts.map +1 -0
  46. package/renderer/webgl/shaders.js +53 -0
  47. package/renderer/webgl/shaders.js.map +1 -0
  48. package/src/render/webgl/BatchRenderer.js +201 -0
  49. package/src/render/webgl/LineStringBatchRenderer.js +116 -0
  50. package/src/render/webgl/MixedGeometryBatch.js +364 -0
  51. package/src/render/webgl/PointBatchRenderer.js +97 -0
  52. package/src/render/webgl/PolygonBatchRenderer.js +117 -0
  53. package/src/render/webgl/constants.js +27 -0
  54. package/src/render/webgl/utils.js +351 -0
  55. package/src/renderer/webgl/Layer.js +0 -160
  56. package/src/renderer/webgl/PointsLayer.js +16 -12
  57. package/src/renderer/webgl/TileLayer.js +1 -1
  58. package/src/renderer/webgl/VectorLayer.js +409 -0
  59. package/src/renderer/webgl/shaders.js +198 -0
  60. package/src/webgl/Helper.js +30 -45
  61. package/src/worker/webgl.js +1 -1
  62. package/util.js +1 -1
  63. package/webgl/Helper.d.ts +17 -25
  64. package/webgl/Helper.d.ts.map +1 -1
  65. package/webgl/Helper.js +29 -43
  66. package/webgl/Helper.js.map +1 -1
  67. package/worker/webgl.js +1 -1
  68. package/worker/webgl.js.map +1 -1
@@ -0,0 +1,116 @@
1
+ /**
2
+ * @module ol/render/webgl/LineStringBatchRenderer
3
+ */
4
+ import AbstractBatchRenderer from './BatchRenderer.js';
5
+ import {AttributeType} from '../../webgl/Helper.js';
6
+ import {transform2D} from '../../geom/flat/transform.js';
7
+
8
+ /**
9
+ * Names of attributes made available to the vertex shader.
10
+ * Please note: changing these *will* break custom shaders!
11
+ * @enum {string}
12
+ */
13
+ export const Attributes = {
14
+ SEGMENT_START: 'a_segmentStart',
15
+ SEGMENT_END: 'a_segmentEnd',
16
+ PARAMETERS: 'a_parameters',
17
+ };
18
+
19
+ class LineStringBatchRenderer extends AbstractBatchRenderer {
20
+ /**
21
+ * @param {import("../../webgl/Helper.js").default} helper WebGL helper instance
22
+ * @param {Worker} worker WebGL worker instance
23
+ * @param {string} vertexShader Vertex shader
24
+ * @param {string} fragmentShader Fragment shader
25
+ * @param {Array<import('./BatchRenderer.js').CustomAttribute>} customAttributes List of custom attributes
26
+ */
27
+ constructor(helper, worker, vertexShader, fragmentShader, customAttributes) {
28
+ super(helper, worker, vertexShader, fragmentShader, customAttributes);
29
+
30
+ // vertices for lines must hold both a position (x,y) and an offset (dx,dy)
31
+ this.attributes = [
32
+ {
33
+ name: Attributes.SEGMENT_START,
34
+ size: 2,
35
+ type: AttributeType.FLOAT,
36
+ },
37
+ {
38
+ name: Attributes.SEGMENT_END,
39
+ size: 2,
40
+ type: AttributeType.FLOAT,
41
+ },
42
+ {
43
+ name: Attributes.PARAMETERS,
44
+ size: 1,
45
+ type: AttributeType.FLOAT,
46
+ },
47
+ ].concat(
48
+ customAttributes.map(function (attribute) {
49
+ return {
50
+ name: 'a_' + attribute.name,
51
+ size: 1,
52
+ type: AttributeType.FLOAT,
53
+ };
54
+ })
55
+ );
56
+ }
57
+
58
+ /**
59
+ * Render instructions for lines are structured like so:
60
+ * [ customAttr0, ... , customAttrN, numberOfVertices0, x0, y0, ... , xN, yN, numberOfVertices1, ... ]
61
+ * @param {import("./MixedGeometryBatch.js").LineStringGeometryBatch} batch Linestring geometry batch
62
+ * @override
63
+ */
64
+ generateRenderInstructions(batch) {
65
+ // here we anticipate the amount of render instructions for lines:
66
+ // 2 instructions per vertex for position (x and y)
67
+ // + 1 instruction per line per custom attributes
68
+ // + 1 instruction per line (for vertices count)
69
+ const totalInstructionsCount =
70
+ 2 * batch.verticesCount +
71
+ (1 + this.customAttributes.length) * batch.geometriesCount;
72
+ if (
73
+ !batch.renderInstructions ||
74
+ batch.renderInstructions.length !== totalInstructionsCount
75
+ ) {
76
+ batch.renderInstructions = new Float32Array(totalInstructionsCount);
77
+ }
78
+
79
+ // loop on features to fill the render instructions
80
+ let batchEntry;
81
+ const flatCoords = [];
82
+ let renderIndex = 0;
83
+ let value;
84
+ for (const featureUid in batch.entries) {
85
+ batchEntry = batch.entries[featureUid];
86
+ for (let i = 0, ii = batchEntry.flatCoordss.length; i < ii; i++) {
87
+ flatCoords.length = batchEntry.flatCoordss[i].length;
88
+ transform2D(
89
+ batchEntry.flatCoordss[i],
90
+ 0,
91
+ flatCoords.length,
92
+ 2,
93
+ batch.renderInstructionsTransform,
94
+ flatCoords
95
+ );
96
+
97
+ // custom attributes
98
+ for (let k = 0, kk = this.customAttributes.length; k < kk; k++) {
99
+ value = this.customAttributes[k].callback(batchEntry.feature);
100
+ batch.renderInstructions[renderIndex++] = value;
101
+ }
102
+
103
+ // vertices count
104
+ batch.renderInstructions[renderIndex++] = flatCoords.length / 2;
105
+
106
+ // looping on points for positions
107
+ for (let j = 0, jj = flatCoords.length; j < jj; j += 2) {
108
+ batch.renderInstructions[renderIndex++] = flatCoords[j];
109
+ batch.renderInstructions[renderIndex++] = flatCoords[j + 1];
110
+ }
111
+ }
112
+ }
113
+ }
114
+ }
115
+
116
+ export default LineStringBatchRenderer;
@@ -0,0 +1,364 @@
1
+ /**
2
+ * @module ol/render/webgl/MixedGeometryBatch
3
+ */
4
+ import WebGLArrayBuffer from '../../webgl/Buffer.js';
5
+ import {ARRAY_BUFFER, DYNAMIC_DRAW, ELEMENT_ARRAY_BUFFER} from '../../webgl.js';
6
+ import {create as createTransform} from '../../transform.js';
7
+ import {getUid} from '../../util.js';
8
+
9
+ /**
10
+ * @typedef {Object} GeometryBatchItem Object that holds a reference to a feature as well as the raw coordinates of its various geometries
11
+ * @property {import("../../Feature").default} feature Feature
12
+ * @property {Array<Array<number>>} flatCoordss Array of flat coordinates arrays, one for each geometry related to the feature
13
+ * @property {number} [verticesCount] Only defined for linestring and polygon batches
14
+ * @property {number} [ringsCount] Only defined for polygon batches
15
+ * @property {Array<Array<number>>} [ringsVerticesCounts] Array of vertices counts in each ring for each geometry; only defined for polygons batches
16
+ */
17
+
18
+ /**
19
+ * @typedef {PointGeometryBatch|LineStringGeometryBatch|PolygonGeometryBatch} GeometryBatch
20
+ */
21
+
22
+ /**
23
+ * @typedef {Object} PolygonGeometryBatch A geometry batch specific to polygons
24
+ * @property {Object<string, GeometryBatchItem>} entries Dictionary of all entries in the batch with associated computed values.
25
+ * One entry corresponds to one feature. Key is feature uid.
26
+ * @property {number} geometriesCount Amount of geometries in the batch.
27
+ * @property {Float32Array} renderInstructions Render instructions for polygons are structured like so:
28
+ * [ numberOfRings, numberOfVerticesInRing0, ..., numberOfVerticesInRingN, x0, y0, customAttr0, ..., xN, yN, customAttrN, numberOfRings,... ]
29
+ * @property {WebGLArrayBuffer} verticesBuffer Vertices WebGL buffer
30
+ * @property {WebGLArrayBuffer} indicesBuffer Indices WebGL buffer
31
+ * @property {import("../../transform.js").Transform} renderInstructionsTransform Converts world space coordinates to screen space; applies to the rendering instructions
32
+ * @property {import("../../transform.js").Transform} verticesBufferTransform Converts world space coordinates to screen space; applies to the webgl vertices buffer
33
+ * @property {import("../../transform.js").Transform} invertVerticesBufferTransform Screen space to world space; applies to the webgl vertices buffer
34
+ * @property {number} verticesCount Amount of vertices from geometries in the batch.
35
+ * @property {number} ringsCount How many outer and inner rings in this batch.
36
+ */
37
+
38
+ /**
39
+ * @typedef {Object} LineStringGeometryBatch A geometry batch specific to lines
40
+ * @property {Object<string, GeometryBatchItem>} entries Dictionary of all entries in the batch with associated computed values.
41
+ * One entry corresponds to one feature. Key is feature uid.
42
+ * @property {number} geometriesCount Amount of geometries in the batch.
43
+ * @property {Float32Array} renderInstructions Render instructions for polygons are structured like so:
44
+ * [ numberOfRings, numberOfVerticesInRing0, ..., numberOfVerticesInRingN, x0, y0, customAttr0, ..., xN, yN, customAttrN, numberOfRings,... ]
45
+ * @property {WebGLArrayBuffer} verticesBuffer Vertices WebGL buffer
46
+ * @property {WebGLArrayBuffer} indicesBuffer Indices WebGL buffer
47
+ * @property {import("../../transform.js").Transform} renderInstructionsTransform Converts world space coordinates to screen space; applies to the rendering instructions
48
+ * @property {import("../../transform.js").Transform} verticesBufferTransform Converts world space coordinates to screen space; applies to the webgl vertices buffer
49
+ * @property {import("../../transform.js").Transform} invertVerticesBufferTransform Screen space to world space; applies to the webgl vertices buffer
50
+ * @property {number} verticesCount Amount of vertices from geometries in the batch.
51
+ */
52
+
53
+ /**
54
+ * @typedef {Object} PointGeometryBatch A geometry batch specific to points
55
+ * @property {Object<string, GeometryBatchItem>} entries Dictionary of all entries in the batch with associated computed values.
56
+ * One entry corresponds to one feature. Key is feature uid.
57
+ * @property {number} geometriesCount Amount of geometries in the batch.
58
+ * @property {Float32Array} renderInstructions Render instructions for polygons are structured like so:
59
+ * [ numberOfRings, numberOfVerticesInRing0, ..., numberOfVerticesInRingN, x0, y0, customAttr0, ..., xN, yN, customAttrN, numberOfRings,... ]
60
+ * @property {WebGLArrayBuffer} verticesBuffer Vertices WebGL buffer
61
+ * @property {WebGLArrayBuffer} indicesBuffer Indices WebGL buffer
62
+ * @property {import("../../transform.js").Transform} renderInstructionsTransform Converts world space coordinates to screen space; applies to the rendering instructions
63
+ * @property {import("../../transform.js").Transform} verticesBufferTransform Converts world space coordinates to screen space; applies to the webgl vertices buffer
64
+ * @property {import("../../transform.js").Transform} invertVerticesBufferTransform Screen space to world space; applies to the webgl vertices buffer
65
+ */
66
+
67
+ /**
68
+ * @classdesc This class is used to group several geometries of various types together for faster rendering.
69
+ * Three inner batches are maintained for polygons, lines and points. Each time a feature is added, changed or removed
70
+ * from the batch, these inner batches are modified accordingly in order to keep them up-to-date.
71
+ *
72
+ * A feature can be present in several inner batches, for example a polygon geometry will be present in the polygon batch
73
+ * and its linar rings will be present in the line batch. Multi geometries are also broken down into individual geometries
74
+ * and added to the corresponding batches in a recursive manner.
75
+ *
76
+ * Corresponding {@link module:ol/render/webgl/BatchRenderer} instances are then used to generate the render instructions
77
+ * and WebGL buffers (vertices and indices) for each inner batches; render instructions are stored on the inner batches,
78
+ * alongside the transform used to convert world coords to screen coords at the time these instructions were generated.
79
+ * The resulting WebGL buffers are stored on the batches as well.
80
+ *
81
+ * An important aspect of geometry batches is that there is no guarantee that render instructions and WebGL buffers
82
+ * are synchronized, i.e. render instructions can describe a new state while WebGL buffers might not have been written yet.
83
+ * This is why two world-to-screen transforms are stored on each batch: one for the render instructions and one for
84
+ * the WebGL buffers.
85
+ */
86
+ class MixedGeometryBatch {
87
+ constructor() {
88
+ /**
89
+ * @type {PolygonGeometryBatch}
90
+ */
91
+ this.polygonBatch = {
92
+ entries: {},
93
+ geometriesCount: 0,
94
+ verticesCount: 0,
95
+ ringsCount: 0,
96
+ renderInstructions: new Float32Array(0),
97
+ verticesBuffer: new WebGLArrayBuffer(ARRAY_BUFFER, DYNAMIC_DRAW),
98
+ indicesBuffer: new WebGLArrayBuffer(ELEMENT_ARRAY_BUFFER, DYNAMIC_DRAW),
99
+ renderInstructionsTransform: createTransform(),
100
+ verticesBufferTransform: createTransform(),
101
+ invertVerticesBufferTransform: createTransform(),
102
+ };
103
+
104
+ /**
105
+ * @type {PointGeometryBatch}
106
+ */
107
+ this.pointBatch = {
108
+ entries: {},
109
+ geometriesCount: 0,
110
+ renderInstructions: new Float32Array(0),
111
+ verticesBuffer: new WebGLArrayBuffer(ARRAY_BUFFER, DYNAMIC_DRAW),
112
+ indicesBuffer: new WebGLArrayBuffer(ELEMENT_ARRAY_BUFFER, DYNAMIC_DRAW),
113
+ renderInstructionsTransform: createTransform(),
114
+ verticesBufferTransform: createTransform(),
115
+ invertVerticesBufferTransform: createTransform(),
116
+ };
117
+
118
+ /**
119
+ * @type {LineStringGeometryBatch}
120
+ */
121
+ this.lineStringBatch = {
122
+ entries: {},
123
+ geometriesCount: 0,
124
+ verticesCount: 0,
125
+ renderInstructions: new Float32Array(0),
126
+ verticesBuffer: new WebGLArrayBuffer(ARRAY_BUFFER, DYNAMIC_DRAW),
127
+ indicesBuffer: new WebGLArrayBuffer(ELEMENT_ARRAY_BUFFER, DYNAMIC_DRAW),
128
+ renderInstructionsTransform: createTransform(),
129
+ verticesBufferTransform: createTransform(),
130
+ invertVerticesBufferTransform: createTransform(),
131
+ };
132
+ }
133
+
134
+ /**
135
+ * @param {Array<import("../../Feature").default>} features Array of features to add to the batch
136
+ */
137
+ addFeatures(features) {
138
+ for (let i = 0; i < features.length; i++) {
139
+ this.addFeature(features[i]);
140
+ }
141
+ }
142
+
143
+ /**
144
+ * @param {import("../../Feature").default} feature Feature to add to the batch
145
+ */
146
+ addFeature(feature) {
147
+ const geometry = feature.getGeometry();
148
+ if (!geometry) {
149
+ return;
150
+ }
151
+ this.addGeometry_(geometry, feature);
152
+ }
153
+
154
+ /**
155
+ * @param {import("../../Feature").default} feature Feature
156
+ * @return {GeometryBatchItem} Batch item added (or existing one)
157
+ * @private
158
+ */
159
+ addFeatureEntryInPointBatch_(feature) {
160
+ const uid = getUid(feature);
161
+ if (!(uid in this.pointBatch.entries)) {
162
+ this.pointBatch.entries[uid] = {
163
+ feature: feature,
164
+ flatCoordss: [],
165
+ };
166
+ }
167
+ return this.pointBatch.entries[uid];
168
+ }
169
+
170
+ /**
171
+ * @param {import("../../Feature").default} feature Feature
172
+ * @return {GeometryBatchItem} Batch item added (or existing one)
173
+ * @private
174
+ */
175
+ addFeatureEntryInLineStringBatch_(feature) {
176
+ const uid = getUid(feature);
177
+ if (!(uid in this.lineStringBatch.entries)) {
178
+ this.lineStringBatch.entries[uid] = {
179
+ feature: feature,
180
+ flatCoordss: [],
181
+ verticesCount: 0,
182
+ };
183
+ }
184
+ return this.lineStringBatch.entries[uid];
185
+ }
186
+
187
+ /**
188
+ * @param {import("../../Feature").default} feature Feature
189
+ * @return {GeometryBatchItem} Batch item added (or existing one)
190
+ * @private
191
+ */
192
+ addFeatureEntryInPolygonBatch_(feature) {
193
+ const uid = getUid(feature);
194
+ if (!(uid in this.polygonBatch.entries)) {
195
+ this.polygonBatch.entries[uid] = {
196
+ feature: feature,
197
+ flatCoordss: [],
198
+ verticesCount: 0,
199
+ ringsCount: 0,
200
+ ringsVerticesCounts: [],
201
+ };
202
+ }
203
+ return this.polygonBatch.entries[uid];
204
+ }
205
+
206
+ /**
207
+ * @param {import("../../Feature").default} feature Feature
208
+ * @private
209
+ */
210
+ clearFeatureEntryInPointBatch_(feature) {
211
+ const entry = this.pointBatch.entries[getUid(feature)];
212
+ if (!entry) {
213
+ return;
214
+ }
215
+ this.pointBatch.geometriesCount -= entry.flatCoordss.length;
216
+ delete this.pointBatch.entries[getUid(feature)];
217
+ }
218
+
219
+ /**
220
+ * @param {import("../../Feature").default} feature Feature
221
+ * @private
222
+ */
223
+ clearFeatureEntryInLineStringBatch_(feature) {
224
+ const entry = this.lineStringBatch.entries[getUid(feature)];
225
+ if (!entry) {
226
+ return;
227
+ }
228
+ this.lineStringBatch.verticesCount -= entry.verticesCount;
229
+ this.lineStringBatch.geometriesCount -= entry.flatCoordss.length;
230
+ delete this.lineStringBatch.entries[getUid(feature)];
231
+ }
232
+
233
+ /**
234
+ * @param {import("../../Feature").default} feature Feature
235
+ * @private
236
+ */
237
+ clearFeatureEntryInPolygonBatch_(feature) {
238
+ const entry = this.polygonBatch.entries[getUid(feature)];
239
+ if (!entry) {
240
+ return;
241
+ }
242
+ this.polygonBatch.verticesCount -= entry.verticesCount;
243
+ this.polygonBatch.ringsCount -= entry.ringsCount;
244
+ this.polygonBatch.geometriesCount -= entry.flatCoordss.length;
245
+ delete this.polygonBatch.entries[getUid(feature)];
246
+ }
247
+
248
+ /**
249
+ * @param {import("../../geom").Geometry} geometry Geometry
250
+ * @param {import("../../Feature").default} feature Feature
251
+ * @private
252
+ */
253
+ addGeometry_(geometry, feature) {
254
+ const type = geometry.getType();
255
+ let flatCoords;
256
+ let verticesCount;
257
+ let batchEntry;
258
+ switch (type) {
259
+ case 'GeometryCollection':
260
+ /** @type {import("../../geom").GeometryCollection} */ (geometry)
261
+ .getGeometries()
262
+ .map((geom) => this.addGeometry_(geom, feature));
263
+ break;
264
+ case 'MultiPolygon':
265
+ /** @type {import("../../geom").MultiPolygon} */ (geometry)
266
+ .getPolygons()
267
+ .map((polygon) => this.addGeometry_(polygon, feature));
268
+ break;
269
+ case 'MultiLineString':
270
+ /** @type {import("../../geom").MultiLineString} */ (geometry)
271
+ .getLineStrings()
272
+ .map((line) => this.addGeometry_(line, feature));
273
+ break;
274
+ case 'MultiPoint':
275
+ /** @type {import("../../geom").MultiPoint} */ (geometry)
276
+ .getPoints()
277
+ .map((point) => this.addGeometry_(point, feature));
278
+ break;
279
+ case 'Polygon':
280
+ const polygonGeom = /** @type {import("../../geom").Polygon} */ (
281
+ geometry
282
+ );
283
+ batchEntry = this.addFeatureEntryInPolygonBatch_(feature);
284
+ flatCoords = polygonGeom.getFlatCoordinates();
285
+ verticesCount = flatCoords.length / 2;
286
+ const ringsCount = polygonGeom.getLinearRingCount();
287
+ const ringsVerticesCount = polygonGeom
288
+ .getEnds()
289
+ .map((end, ind, arr) =>
290
+ ind > 0 ? (end - arr[ind - 1]) / 2 : end / 2
291
+ );
292
+ this.polygonBatch.verticesCount += verticesCount;
293
+ this.polygonBatch.ringsCount += ringsCount;
294
+ this.polygonBatch.geometriesCount++;
295
+ batchEntry.flatCoordss.push(flatCoords);
296
+ batchEntry.ringsVerticesCounts.push(ringsVerticesCount);
297
+ batchEntry.verticesCount += verticesCount;
298
+ batchEntry.ringsCount += ringsCount;
299
+ polygonGeom
300
+ .getLinearRings()
301
+ .map((ring) => this.addGeometry_(ring, feature));
302
+ break;
303
+ case 'Point':
304
+ const pointGeom = /** @type {import("../../geom").Point} */ (geometry);
305
+ batchEntry = this.addFeatureEntryInPointBatch_(feature);
306
+ flatCoords = pointGeom.getFlatCoordinates();
307
+ this.pointBatch.geometriesCount++;
308
+ batchEntry.flatCoordss.push(flatCoords);
309
+ break;
310
+ case 'LineString':
311
+ case 'LinearRing':
312
+ const lineGeom = /** @type {import("../../geom").LineString} */ (
313
+ geometry
314
+ );
315
+ batchEntry = this.addFeatureEntryInLineStringBatch_(feature);
316
+ flatCoords = lineGeom.getFlatCoordinates();
317
+ verticesCount = flatCoords.length / 2;
318
+ this.lineStringBatch.verticesCount += verticesCount;
319
+ this.lineStringBatch.geometriesCount++;
320
+ batchEntry.flatCoordss.push(flatCoords);
321
+ batchEntry.verticesCount += verticesCount;
322
+ break;
323
+ default:
324
+ // pass
325
+ }
326
+ }
327
+
328
+ /**
329
+ * @param {import("../../Feature").default} feature Feature
330
+ */
331
+ changeFeature(feature) {
332
+ this.clearFeatureEntryInPointBatch_(feature);
333
+ this.clearFeatureEntryInPolygonBatch_(feature);
334
+ this.clearFeatureEntryInLineStringBatch_(feature);
335
+ const geometry = feature.getGeometry();
336
+ if (!geometry) {
337
+ return;
338
+ }
339
+ this.addGeometry_(geometry, feature);
340
+ }
341
+
342
+ /**
343
+ * @param {import("../../Feature").default} feature Feature
344
+ */
345
+ removeFeature(feature) {
346
+ this.clearFeatureEntryInPointBatch_(feature);
347
+ this.clearFeatureEntryInPolygonBatch_(feature);
348
+ this.clearFeatureEntryInLineStringBatch_(feature);
349
+ }
350
+
351
+ clear() {
352
+ this.polygonBatch.entries = {};
353
+ this.polygonBatch.geometriesCount = 0;
354
+ this.polygonBatch.verticesCount = 0;
355
+ this.polygonBatch.ringsCount = 0;
356
+ this.lineStringBatch.entries = {};
357
+ this.lineStringBatch.geometriesCount = 0;
358
+ this.lineStringBatch.verticesCount = 0;
359
+ this.pointBatch.entries = {};
360
+ this.pointBatch.geometriesCount = 0;
361
+ }
362
+ }
363
+
364
+ export default MixedGeometryBatch;
@@ -0,0 +1,97 @@
1
+ /**
2
+ * @module ol/render/webgl/PointBatchRenderer
3
+ */
4
+
5
+ import AbstractBatchRenderer from './BatchRenderer.js';
6
+ import {AttributeType} from '../../webgl/Helper.js';
7
+ import {apply as applyTransform} from '../../transform.js';
8
+
9
+ /**
10
+ * Names of attributes made available to the vertex shader.
11
+ * Please note: changing these *will* break custom shaders!
12
+ * @enum {string}
13
+ */
14
+ export const Attributes = {
15
+ POSITION: 'a_position',
16
+ INDEX: 'a_index',
17
+ };
18
+
19
+ class PointBatchRenderer extends AbstractBatchRenderer {
20
+ /**
21
+ * @param {import("../../webgl/Helper.js").default} helper WebGL helper instance
22
+ * @param {Worker} worker WebGL worker instance
23
+ * @param {string} vertexShader Vertex shader
24
+ * @param {string} fragmentShader Fragment shader
25
+ * @param {Array<import('./BatchRenderer.js').CustomAttribute>} customAttributes List of custom attributes
26
+ */
27
+ constructor(helper, worker, vertexShader, fragmentShader, customAttributes) {
28
+ super(helper, worker, vertexShader, fragmentShader, customAttributes);
29
+
30
+ // vertices for point must hold both a position (x,y) and an index (their position in the quad)
31
+ this.attributes = [
32
+ {
33
+ name: Attributes.POSITION,
34
+ size: 2,
35
+ type: AttributeType.FLOAT,
36
+ },
37
+ {
38
+ name: Attributes.INDEX,
39
+ size: 1,
40
+ type: AttributeType.FLOAT,
41
+ },
42
+ ].concat(
43
+ customAttributes.map(function (attribute) {
44
+ return {
45
+ name: 'a_' + attribute.name,
46
+ size: 1,
47
+ type: AttributeType.FLOAT,
48
+ };
49
+ })
50
+ );
51
+ }
52
+
53
+ /**
54
+ * Render instructions for lines are structured like so:
55
+ * [ x0, y0, customAttr0, ... , xN, yN, customAttrN ]
56
+ * @param {import("./MixedGeometryBatch.js").PointGeometryBatch} batch Point geometry batch
57
+ * @override
58
+ */
59
+ generateRenderInstructions(batch) {
60
+ // here we anticipate the amount of render instructions for points:
61
+ // 2 instructions per vertex for position (x and y)
62
+ // + 1 instruction per vertex per custom attributes
63
+ const totalInstructionsCount =
64
+ (2 + this.customAttributes.length) * batch.geometriesCount;
65
+ if (
66
+ !batch.renderInstructions ||
67
+ batch.renderInstructions.length !== totalInstructionsCount
68
+ ) {
69
+ batch.renderInstructions = new Float32Array(totalInstructionsCount);
70
+ }
71
+
72
+ // loop on features to fill the render instructions
73
+ let batchEntry;
74
+ const tmpCoords = [];
75
+ let renderIndex = 0;
76
+ let value;
77
+ for (const featureUid in batch.entries) {
78
+ batchEntry = batch.entries[featureUid];
79
+ for (let i = 0, ii = batchEntry.flatCoordss.length; i < ii; i++) {
80
+ tmpCoords[0] = batchEntry.flatCoordss[i][0];
81
+ tmpCoords[1] = batchEntry.flatCoordss[i][1];
82
+ applyTransform(batch.renderInstructionsTransform, tmpCoords);
83
+
84
+ batch.renderInstructions[renderIndex++] = tmpCoords[0];
85
+ batch.renderInstructions[renderIndex++] = tmpCoords[1];
86
+
87
+ // pushing custom attributes
88
+ for (let j = 0, jj = this.customAttributes.length; j < jj; j++) {
89
+ value = this.customAttributes[j].callback(batchEntry.feature);
90
+ batch.renderInstructions[renderIndex++] = value;
91
+ }
92
+ }
93
+ }
94
+ }
95
+ }
96
+
97
+ export default PointBatchRenderer;
@@ -0,0 +1,117 @@
1
+ /**
2
+ * @module ol/render/webgl/PolygonBatchRenderer
3
+ */
4
+ import AbstractBatchRenderer from './BatchRenderer.js';
5
+ import {AttributeType} from '../../webgl/Helper.js';
6
+ import {transform2D} from '../../geom/flat/transform.js';
7
+
8
+ /**
9
+ * Names of attributes made available to the vertex shader.
10
+ * Please note: changing these *will* break custom shaders!
11
+ * @enum {string}
12
+ */
13
+ export const Attributes = {
14
+ POSITION: 'a_position',
15
+ };
16
+
17
+ class PolygonBatchRenderer extends AbstractBatchRenderer {
18
+ /**
19
+ * @param {import("../../webgl/Helper.js").default} helper WebGL helper instance
20
+ * @param {Worker} worker WebGL worker instance
21
+ * @param {string} vertexShader Vertex shader
22
+ * @param {string} fragmentShader Fragment shader
23
+ * @param {Array<import('./BatchRenderer.js').CustomAttribute>} customAttributes List of custom attributes
24
+ */
25
+ constructor(helper, worker, vertexShader, fragmentShader, customAttributes) {
26
+ super(helper, worker, vertexShader, fragmentShader, customAttributes);
27
+
28
+ // By default only a position attribute is required to render polygons
29
+ this.attributes = [
30
+ {
31
+ name: Attributes.POSITION,
32
+ size: 2,
33
+ type: AttributeType.FLOAT,
34
+ },
35
+ ].concat(
36
+ customAttributes.map(function (attribute) {
37
+ return {
38
+ name: 'a_' + attribute.name,
39
+ size: 1,
40
+ type: AttributeType.FLOAT,
41
+ };
42
+ })
43
+ );
44
+ }
45
+
46
+ /**
47
+ * Render instructions for polygons are structured like so:
48
+ * [ customAttr0, ..., customAttrN, numberOfRings, numberOfVerticesInRing0, ..., numberOfVerticesInRingN, x0, y0, ..., xN, yN, numberOfRings,... ]
49
+ * @param {import("./MixedGeometryBatch.js").PolygonGeometryBatch} batch Polygon geometry batch
50
+ * @override
51
+ */
52
+ generateRenderInstructions(batch) {
53
+ // here we anticipate the amount of render instructions for polygons:
54
+ // 2 instructions per vertex for position (x and y)
55
+ // + 1 instruction per polygon per custom attributes
56
+ // + 1 instruction per polygon (for vertices count in polygon)
57
+ // + 1 instruction per ring (for vertices count in ring)
58
+ const totalInstructionsCount =
59
+ 2 * batch.verticesCount +
60
+ (1 + this.customAttributes.length) * batch.geometriesCount +
61
+ batch.ringsCount;
62
+ if (
63
+ !batch.renderInstructions ||
64
+ batch.renderInstructions.length !== totalInstructionsCount
65
+ ) {
66
+ batch.renderInstructions = new Float32Array(totalInstructionsCount);
67
+ }
68
+
69
+ // loop on features to fill the render instructions
70
+ let batchEntry;
71
+ const flatCoords = [];
72
+ let renderIndex = 0;
73
+ let value;
74
+ for (const featureUid in batch.entries) {
75
+ batchEntry = batch.entries[featureUid];
76
+ for (let i = 0, ii = batchEntry.flatCoordss.length; i < ii; i++) {
77
+ flatCoords.length = batchEntry.flatCoordss[i].length;
78
+ transform2D(
79
+ batchEntry.flatCoordss[i],
80
+ 0,
81
+ flatCoords.length,
82
+ 2,
83
+ batch.renderInstructionsTransform,
84
+ flatCoords
85
+ );
86
+
87
+ // custom attributes
88
+ for (let k = 0, kk = this.customAttributes.length; k < kk; k++) {
89
+ value = this.customAttributes[k].callback(batchEntry.feature);
90
+ batch.renderInstructions[renderIndex++] = value;
91
+ }
92
+
93
+ // ring count
94
+ batch.renderInstructions[renderIndex++] =
95
+ batchEntry.ringsVerticesCounts[i].length;
96
+
97
+ // vertices count in each ring
98
+ for (
99
+ let j = 0, jj = batchEntry.ringsVerticesCounts[i].length;
100
+ j < jj;
101
+ j++
102
+ ) {
103
+ batch.renderInstructions[renderIndex++] =
104
+ batchEntry.ringsVerticesCounts[i][j];
105
+ }
106
+
107
+ // looping on points for positions
108
+ for (let j = 0, jj = flatCoords.length; j < jj; j += 2) {
109
+ batch.renderInstructions[renderIndex++] = flatCoords[j];
110
+ batch.renderInstructions[renderIndex++] = flatCoords[j + 1];
111
+ }
112
+ }
113
+ }
114
+ }
115
+ }
116
+
117
+ export default PolygonBatchRenderer;