ol 10.6.2-dev.1751637866951 → 10.6.2-dev.1751964281167

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.
@@ -14,95 +14,57 @@ const tmpArray_ = [];
14
14
  /**
15
15
  * An object holding positions both in an index and a vertex buffer.
16
16
  * @typedef {Object} BufferPositions
17
- * @property {number} vertexPosition Position in the vertex buffer
18
- * @property {number} indexPosition Position in the index buffer
17
+ * @property {number} vertexAttributesPosition Position in the vertex buffer
18
+ * @property {number} instanceAttributesPosition Position in the vertex buffer
19
+ * @property {number} indicesPosition Position in the index buffer
19
20
  */
20
- const bufferPositions_ = {vertexPosition: 0, indexPosition: 0};
21
-
22
- /**
23
- * @param {Float32Array} buffer Buffer
24
- * @param {number} pos Position
25
- * @param {number} x X
26
- * @param {number} y Y
27
- * @param {number} index Index
28
- */
29
- function writePointVertex(buffer, pos, x, y, index) {
30
- buffer[pos + 0] = x;
31
- buffer[pos + 1] = y;
32
- buffer[pos + 2] = index;
33
- }
21
+ const bufferPositions_ = {
22
+ vertexAttributesPosition: 0,
23
+ instanceAttributesPosition: 0,
24
+ indicesPosition: 0,
25
+ };
34
26
 
35
27
  /**
36
28
  * Pushes a quad (two triangles) based on a point geometry
37
29
  * @param {Float32Array} instructions Array of render instructions for points.
38
30
  * @param {number} elementIndex Index from which render instructions will be read.
39
- * @param {Float32Array} vertexBuffer Buffer in the form of a typed array.
40
- * @param {Uint32Array} indexBuffer Buffer in the form of a typed array.
31
+ * @param {Float32Array} instanceAttributesBuffer Buffer in the form of a typed array.
41
32
  * @param {number} customAttributesSize Amount of custom attributes for each element.
42
33
  * @param {BufferPositions} [bufferPositions] Buffer write positions; if not specified, positions will be set at 0.
43
34
  * @return {BufferPositions} New buffer positions where to write next
44
- * @property {number} vertexPosition New position in the vertex buffer where future writes should start.
45
- * @property {number} indexPosition New position in the index buffer where future writes should start.
35
+ * @property {number} vertexAttributesPosition New position in the vertex buffer where future writes should start.
36
+ * @property {number} indicesPosition New position in the index buffer where future writes should start.
46
37
  * @private
47
38
  */
48
39
  export function writePointFeatureToBuffers(
49
40
  instructions,
50
41
  elementIndex,
51
- vertexBuffer,
52
- indexBuffer,
42
+ instanceAttributesBuffer,
53
43
  customAttributesSize,
54
44
  bufferPositions,
55
45
  ) {
56
- // This is for x, y and index
57
- const baseVertexAttrsCount = 3;
58
- const baseInstructionsCount = 2;
59
- const stride = baseVertexAttrsCount + customAttributesSize;
60
-
61
- const x = instructions[elementIndex + 0];
62
- const y = instructions[elementIndex + 1];
46
+ const x = instructions[elementIndex++];
47
+ const y = instructions[elementIndex++];
63
48
 
64
49
  // read custom numerical attributes on the feature
65
50
  const customAttrs = tmpArray_;
66
51
  customAttrs.length = customAttributesSize;
67
52
  for (let i = 0; i < customAttrs.length; i++) {
68
- customAttrs[i] = instructions[elementIndex + baseInstructionsCount + i];
53
+ customAttrs[i] = instructions[elementIndex + i];
69
54
  }
70
55
 
71
- let vPos = bufferPositions ? bufferPositions.vertexPosition : 0;
72
- let iPos = bufferPositions ? bufferPositions.indexPosition : 0;
73
- const baseIndex = vPos / stride;
74
-
75
- // push vertices for each of the four quad corners (first standard then custom attributes)
76
- writePointVertex(vertexBuffer, vPos, x, y, 0);
77
- customAttrs.length &&
78
- vertexBuffer.set(customAttrs, vPos + baseVertexAttrsCount);
79
- vPos += stride;
80
-
81
- writePointVertex(vertexBuffer, vPos, x, y, 1);
82
- customAttrs.length &&
83
- vertexBuffer.set(customAttrs, vPos + baseVertexAttrsCount);
84
- vPos += stride;
56
+ let instPos = bufferPositions
57
+ ? bufferPositions.instanceAttributesPosition
58
+ : 0;
85
59
 
86
- writePointVertex(vertexBuffer, vPos, x, y, 2);
87
- customAttrs.length &&
88
- vertexBuffer.set(customAttrs, vPos + baseVertexAttrsCount);
89
- vPos += stride;
90
-
91
- writePointVertex(vertexBuffer, vPos, x, y, 3);
92
- customAttrs.length &&
93
- vertexBuffer.set(customAttrs, vPos + baseVertexAttrsCount);
94
- vPos += stride;
95
-
96
- indexBuffer[iPos++] = baseIndex;
97
- indexBuffer[iPos++] = baseIndex + 1;
98
- indexBuffer[iPos++] = baseIndex + 3;
99
- indexBuffer[iPos++] = baseIndex + 1;
100
- indexBuffer[iPos++] = baseIndex + 2;
101
- indexBuffer[iPos++] = baseIndex + 3;
102
-
103
- bufferPositions_.vertexPosition = vPos;
104
- bufferPositions_.indexPosition = iPos;
60
+ instanceAttributesBuffer[instPos++] = x;
61
+ instanceAttributesBuffer[instPos++] = y;
62
+ if (customAttrs.length) {
63
+ instanceAttributesBuffer.set(customAttrs, instPos);
64
+ instPos += customAttrs.length;
65
+ }
105
66
 
67
+ bufferPositions_.instanceAttributesPosition = instPos;
106
68
  return bufferPositions_;
107
69
  }
108
70
 
@@ -131,8 +93,7 @@ export function writePointFeatureToBuffers(
131
93
  * @param {number} segmentEndIndex Index of the segment end point from which render instructions will be read.
132
94
  * @param {number|null} beforeSegmentIndex Index of the point right before the segment (null if none, e.g this is a line start)
133
95
  * @param {number|null} afterSegmentIndex Index of the point right after the segment (null if none, e.g this is a line end)
134
- * @param {Array<number>} vertexArray Array containing vertices.
135
- * @param {Array<number>} indexArray Array containing indices.
96
+ * @param {Array<number>} instanceAttributesArray Array containing instance attributes.
136
97
  * @param {Array<number>} customAttributes Array of custom attributes value
137
98
  * @param {import('../../transform.js').Transform} toWorldTransform Transform matrix used to obtain world coordinates from instructions
138
99
  * @param {number} currentLength Cumulated length of segments processed so far
@@ -146,18 +107,12 @@ export function writeLineSegmentToBuffers(
146
107
  segmentEndIndex,
147
108
  beforeSegmentIndex,
148
109
  afterSegmentIndex,
149
- vertexArray,
150
- indexArray,
110
+ instanceAttributesArray,
151
111
  customAttributes,
152
112
  toWorldTransform,
153
113
  currentLength,
154
114
  currentAngleTangentSum,
155
115
  ) {
156
- // compute the stride to determine how many vertices were already pushed
157
- const baseVertexAttrsCount = 10; // base attributes: x0, y0, m0, x1, y1, m1, angle0, angle1, distance, params
158
- const stride = baseVertexAttrsCount + customAttributes.length;
159
- const baseIndex = vertexArray.length / stride;
160
-
161
116
  // The segment is composed of two positions called P0[x0, y0] and P1[x1, y1]
162
117
  // Depending on whether there are points before and after the segment, its final shape
163
118
  // will be different
@@ -242,62 +197,7 @@ export function writeLineSegmentToBuffers(
242
197
  }
243
198
  }
244
199
 
245
- /**
246
- * @param {number} vertexIndex From 0 to 3, indicating position in the quad
247
- * @param {number} angleSum Sum of the join angles encountered so far (used to compute distance offset
248
- * @return {number} A float value containing both information
249
- */
250
- function computeParameters(vertexIndex, angleSum) {
251
- if (angleSum === 0) {
252
- return vertexIndex * 10000;
253
- }
254
- return Math.sign(angleSum) * (vertexIndex * 10000 + Math.abs(angleSum));
255
- }
256
-
257
- // add main segment triangles
258
- vertexArray.push(
259
- p0[0],
260
- p0[1],
261
- m0,
262
- p1[0],
263
- p1[1],
264
- m1,
265
- angle0,
266
- angle1,
267
- currentLength,
268
- computeParameters(0, currentAngleTangentSum),
269
- );
270
- vertexArray.push(...customAttributes);
271
-
272
- vertexArray.push(
273
- p0[0],
274
- p0[1],
275
- m0,
276
- p1[0],
277
- p1[1],
278
- m1,
279
- angle0,
280
- angle1,
281
- currentLength,
282
- computeParameters(1, currentAngleTangentSum),
283
- );
284
- vertexArray.push(...customAttributes);
285
-
286
- vertexArray.push(
287
- p0[0],
288
- p0[1],
289
- m0,
290
- p1[0],
291
- p1[1],
292
- m1,
293
- angle0,
294
- angle1,
295
- currentLength,
296
- computeParameters(2, currentAngleTangentSum),
297
- );
298
- vertexArray.push(...customAttributes);
299
-
300
- vertexArray.push(
200
+ instanceAttributesArray.push(
301
201
  p0[0],
302
202
  p0[1],
303
203
  m0,
@@ -307,18 +207,9 @@ export function writeLineSegmentToBuffers(
307
207
  angle0,
308
208
  angle1,
309
209
  currentLength,
310
- computeParameters(3, currentAngleTangentSum),
311
- );
312
- vertexArray.push(...customAttributes);
313
-
314
- indexArray.push(
315
- baseIndex,
316
- baseIndex + 1,
317
- baseIndex + 2,
318
- baseIndex + 1,
319
- baseIndex + 3,
320
- baseIndex + 2,
210
+ currentAngleTangentSum,
321
211
  );
212
+ instanceAttributesArray.push(...customAttributes);
322
213
 
323
214
  return {
324
215
  length:
@@ -28,13 +28,17 @@ export type WebGLWorkerGenerateBuffersMessage = {
28
28
  */
29
29
  customAttributesSize?: number | undefined;
30
30
  /**
31
- * Vertices array raw binary buffer (sent by the worker).
31
+ * Indices array raw binary buffer (sent by the worker).
32
32
  */
33
- vertexBuffer?: ArrayBuffer | undefined;
33
+ indicesBuffer?: ArrayBuffer | undefined;
34
34
  /**
35
- * Indices array raw binary buffer (sent by the worker).
35
+ * Vertex attributes array raw binary buffer (sent by the worker).
36
+ */
37
+ vertexAttributesBuffer?: ArrayBuffer | undefined;
38
+ /**
39
+ * Instance attributes array raw binary buffer (sent by the worker).
36
40
  */
37
- indexBuffer?: ArrayBuffer | undefined;
41
+ instanceAttributesBuffer?: ArrayBuffer | undefined;
38
42
  /**
39
43
  * Transformation matrix used to project the instructions coordinates
40
44
  */
@@ -21,7 +21,8 @@ export const WebGLWorkerMessageType = {
21
21
  * @property {WebGLWorkerMessageType} type Message type
22
22
  * @property {ArrayBuffer} renderInstructions render instructions raw binary buffer.
23
23
  * @property {number} [customAttributesSize] Amount of hit detection + custom attributes count in the render instructions.
24
- * @property {ArrayBuffer} [vertexBuffer] Vertices array raw binary buffer (sent by the worker).
25
- * @property {ArrayBuffer} [indexBuffer] Indices array raw binary buffer (sent by the worker).
24
+ * @property {ArrayBuffer} [indicesBuffer] Indices array raw binary buffer (sent by the worker).
25
+ * @property {ArrayBuffer} [vertexAttributesBuffer] Vertex attributes array raw binary buffer (sent by the worker).
26
+ * @property {ArrayBuffer} [instanceAttributesBuffer] Instance attributes array raw binary buffer (sent by the worker).
26
27
  * @property {import("../../transform").Transform} [renderInstructionsTransform] Transformation matrix used to project the instructions coordinates
27
28
  */
@@ -183,6 +183,10 @@ declare class WebGLPointsLayerRenderer extends WebGLLayerRenderer<any> {
183
183
  * @private
184
184
  */
185
185
  private verticesBuffer_;
186
+ /**
187
+ * @private
188
+ */
189
+ private instanceAttributesBuffer_;
186
190
  /**
187
191
  * @private
188
192
  */
@@ -206,11 +210,14 @@ declare class WebGLPointsLayerRenderer extends WebGLLayerRenderer<any> {
206
210
  */
207
211
  private hitDetectionEnabled_;
208
212
  /**
209
- * A list of attributes used by the renderer. By default only the position and
210
- * index of the vertex (0 to 3) are required.
213
+ * A list of attributes used by the renderer.
211
214
  * @type {Array<import('../../webgl/Helper.js').AttributeDescription>}
212
215
  */
213
216
  attributes: Array<import("../../webgl/Helper.js").AttributeDescription>;
217
+ /**
218
+ * @type {Array<import('../../webgl/Helper.js').AttributeDescription>}
219
+ */
220
+ instanceAttributes: Array<import("../../webgl/Helper.js").AttributeDescription>;
214
221
  customAttributes: CustomAttribute[];
215
222
  /**
216
223
  * @private
@@ -1 +1 @@
1
- {"version":3,"file":"PointsLayer.d.ts","sourceRoot":"","sources":["PointsLayer.js"],"names":[],"mappings":";oBA4Bc,OAAO,qBAAqB,EAAE,OAAO;2BACrC,OAAO,eAAe,EAAE,OAAO,CAAC,KAAK,CAAC;;;;;;;;;UAKtC,MAAM;;;;;cACN,CAAS,IAAY,EAAZ,YAAY,EAAE,IAAiB,EAAjB;YAAO,MAAM,GAAE,GAAC;KAAC,KAAE,MAAM;;;;;;;;;;aAOhD,YAAY;;;;;;;;;;qBAEZ,OAAO,qBAAqB,EAAE,UAAU;;;;;;;;;;;;;;;;;;kBAWxC,MAAM;;;;oBACN,MAAM;;;;;;;;;;;;;;;;;AA5BpB,6DAA6D;AAC7D,qEAAqE;AAErE;;;;;;GAMG;AAEH;;;;;;GAMG;AAEH;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH;IACE;;;OAGG;IACH,mBAHW,OAAO,sBAAsB,EAAE,OAAO,WACtC,OAAO,EAyOjB;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ACH,iCAJW,OAAO,cAAc,EAAE,UAAU,GAChC,WAAW,CA6BtB;IAyCD;;;;OAIG;IACH,wBAwEC;IA8CD;;;;;;;OAOG;IACH,yBANW,OAAO,cAAc,EAAE,UAAU,mBACjC,OAAO,cACP,MAAM,YACN,MAAM,cACN,MAAM,QAyChB;IAeD,wBAAoB;CACrB;+BAjsB8B,YAAY"}
@@ -148,6 +148,13 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
148
148
  * @private
149
149
  */
150
150
  this.verticesBuffer_ = new WebGLArrayBuffer(ARRAY_BUFFER, DYNAMIC_DRAW);
151
+ /**
152
+ * @private
153
+ */
154
+ this.instanceAttributesBuffer_ = new WebGLArrayBuffer(
155
+ ARRAY_BUFFER,
156
+ DYNAMIC_DRAW,
157
+ );
151
158
  /**
152
159
  * @private
153
160
  */
@@ -189,36 +196,41 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
189
196
  : [];
190
197
 
191
198
  /**
192
- * A list of attributes used by the renderer. By default only the position and
193
- * index of the vertex (0 to 3) are required.
199
+ * A list of attributes used by the renderer.
194
200
  * @type {Array<import('../../webgl/Helper.js').AttributeDescription>}
195
201
  */
196
202
  this.attributes = [
197
203
  {
198
- name: 'a_position',
204
+ name: 'a_localPosition',
199
205
  size: 2,
200
206
  type: AttributeType.FLOAT,
201
207
  },
208
+ ];
209
+
210
+ /**
211
+ * @type {Array<import('../../webgl/Helper.js').AttributeDescription>}
212
+ */
213
+ this.instanceAttributes = [
202
214
  {
203
- name: 'a_index',
204
- size: 1,
215
+ name: 'a_position',
216
+ size: 2,
205
217
  type: AttributeType.FLOAT,
206
218
  },
207
219
  ];
208
220
 
209
221
  if (this.hitDetectionEnabled_) {
210
- this.attributes.push({
222
+ this.instanceAttributes.push({
211
223
  name: 'a_hitColor',
212
224
  size: 4,
213
225
  type: AttributeType.FLOAT,
214
226
  });
215
- this.attributes.push({
227
+ this.instanceAttributes.push({
216
228
  name: 'a_featureUid',
217
229
  size: 1,
218
230
  type: AttributeType.FLOAT,
219
231
  });
220
232
  }
221
- this.attributes.push(...customAttributes);
233
+ this.instanceAttributes.push(...customAttributes);
222
234
 
223
235
  this.customAttributes = options.attributes ? options.attributes : [];
224
236
 
@@ -282,9 +294,13 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
282
294
  const received = event.data;
283
295
  if (received.type === WebGLWorkerMessageType.GENERATE_POINT_BUFFERS) {
284
296
  const projectionTransform = received.projectionTransform;
285
- this.verticesBuffer_.fromArrayBuffer(received.vertexBuffer);
297
+ this.verticesBuffer_.fromArrayBuffer(received.vertexAttributesBuffer);
298
+ this.instanceAttributesBuffer_.fromArrayBuffer(
299
+ received.instanceAttributesBuffer,
300
+ );
286
301
  this.helper.flushBufferData(this.verticesBuffer_);
287
- this.indicesBuffer_.fromArrayBuffer(received.indexBuffer);
302
+ this.helper.flushBufferData(this.instanceAttributesBuffer_);
303
+ this.indicesBuffer_.fromArrayBuffer(received.indicesBuffer);
288
304
  this.helper.flushBufferData(this.indicesBuffer_);
289
305
 
290
306
  this.renderTransform_ = projectionTransform;
@@ -523,11 +539,6 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
523
539
  this.helper.useProgram(this.program_, frameState);
524
540
  this.helper.prepareDraw(frameState);
525
541
 
526
- // write new data
527
- this.helper.bindBuffer(this.verticesBuffer_);
528
- this.helper.bindBuffer(this.indicesBuffer_);
529
- this.helper.enableAttributes(this.attributes);
530
-
531
542
  return true;
532
543
  }
533
544
 
@@ -679,18 +690,27 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
679
690
  );
680
691
  }
681
692
 
682
- this.helper.bindBuffer(this.verticesBuffer_);
683
- this.helper.bindBuffer(this.indicesBuffer_);
684
- this.helper.enableAttributes(this.attributes);
693
+ const instanceAttributesStride = this.instanceAttributes.reduce(
694
+ (prev, curr) => prev + (curr.size || 1),
695
+ 0,
696
+ );
697
+ const instanceCount =
698
+ this.instanceAttributesBuffer_.getSize() / instanceAttributesStride;
685
699
 
686
700
  do {
701
+ this.helper.bindBuffer(this.indicesBuffer_);
702
+ this.helper.bindBuffer(this.verticesBuffer_);
703
+ this.helper.enableAttributes(this.attributes);
704
+ this.helper.bindBuffer(this.instanceAttributesBuffer_);
705
+ this.helper.enableAttributesInstanced(this.instanceAttributes);
706
+
687
707
  this.helper.makeProjectionTransform(frameState, this.currentTransform_);
688
708
  translateTransform(this.currentTransform_, world * worldWidth, 0);
689
709
  multiplyTransform(this.currentTransform_, this.invertRenderTransform_);
690
710
  this.helper.applyUniforms(frameState);
691
711
  this.helper.applyHitDetectionUniform(forHitDetection);
692
712
  const renderCount = this.indicesBuffer_.getSize();
693
- this.helper.drawElements(0, renderCount);
713
+ this.helper.drawElementsInstanced(0, renderCount, instanceCount);
694
714
  } while (++world < endWorld);
695
715
  }
696
716
 
package/util.js CHANGED
@@ -33,4 +33,4 @@ export function getUid(obj) {
33
33
  * OpenLayers version.
34
34
  * @type {string}
35
35
  */
36
- export const VERSION = '10.6.2-dev.1751637866951';
36
+ export const VERSION = '10.6.2-dev.1751964281167';
package/webgl/Helper.d.ts CHANGED
@@ -387,6 +387,11 @@ declare class WebGLHelper extends Disposable {
387
387
  * @return {Object|null} The extension or null if not supported.
388
388
  */
389
389
  getExtension(name: string): any | null;
390
+ /**
391
+ * Will throw if the extension is not available
392
+ * @return {ANGLE_instanced_arrays} Extension
393
+ */
394
+ getInstancedRenderingExtension_(): ANGLE_instanced_arrays;
390
395
  /**
391
396
  * Just bind the buffer if it's in the cache. Otherwise create
392
397
  * the WebGL buffer, bind it, populate it, and add an entry to
@@ -452,6 +457,14 @@ declare class WebGLHelper extends Disposable {
452
457
  * @param {number} end End index.
453
458
  */
454
459
  drawElements(start: number, end: number): void;
460
+ /**
461
+ * Execute a draw call similar to `drawElements`, but using instanced rendering.
462
+ * Will have no effect if `enableAttributesInstanced` was not called for this rendering pass.
463
+ * @param {number} start Start index.
464
+ * @param {number} end End index.
465
+ * @param {number} instanceCount The number of instances to render
466
+ */
467
+ drawElementsInstanced(start: number, end: number, instanceCount: number): void;
455
468
  /**
456
469
  * Apply the successive post process passes which will eventually render to the actual canvas.
457
470
  * @param {import("../Map.js").FrameState} frameState current frame state
@@ -564,9 +577,16 @@ declare class WebGLHelper extends Disposable {
564
577
  * @param {number} type UNSIGNED_INT, UNSIGNED_BYTE, UNSIGNED_SHORT or FLOAT
565
578
  * @param {number} stride Stride in bytes (0 means attribs are packed)
566
579
  * @param {number} offset Offset in bytes
580
+ * @param {boolean} instanced Whether the attribute is used for instanced rendering
567
581
  * @private
568
582
  */
569
583
  private enableAttributeArray_;
584
+ /**
585
+ * @private
586
+ * @param {Array<AttributeDescription>} attributes Ordered list of attributes to read from the buffer
587
+ * @param {boolean} instanced Whether the attributes are instanced.
588
+ */
589
+ private enableAttributes_;
570
590
  /**
571
591
  * Will enable the following attributes to be read from the currently bound buffer,
572
592
  * i.e. tell the GPU where to read the different attributes in the buffer. An error in the
@@ -574,6 +594,12 @@ declare class WebGLHelper extends Disposable {
574
594
  * @param {Array<AttributeDescription>} attributes Ordered list of attributes to read from the buffer
575
595
  */
576
596
  enableAttributes(attributes: Array<AttributeDescription>): void;
597
+ /**
598
+ * Will enable these attributes as instanced, meaning that they will only be read
599
+ * once per instance instead of per vertex.
600
+ * @param {Array<AttributeDescription>} attributes Ordered list of attributes to read from the buffer
601
+ */
602
+ enableAttributesInstanced(attributes: Array<AttributeDescription>): void;
577
603
  /**
578
604
  * WebGL context was lost
579
605
  * @param {WebGLContextEvent} event The context loss event.
@@ -1 +1 @@
1
- {"version":3,"file":"Helper.d.ts","sourceRoot":"","sources":["Helper.js"],"names":[],"mappings":"AAmsCA;;;;GAIG;AACH,oDAHW,KAAK,CAAC,oBAAoB,CAAC,GAC1B,MAAM,CASjB;;;;yBAlrCS,MAAM;;;;;;;;;6BAUN,MAAM;;;;;;;;;;;;;;;;4BAiBN,MAAM;;;;;;;;;;;;YAjCF,OAAO,aAAa,EAAE,OAAO;;;;iBAC7B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CAIlB;IAED;;;;;;;;;;OAUG;IACH,oBANW,KAAK,CAAC,MAAM,CAAC,QACb,SAAS,GAAC,gBAAgB,GAAC,iBAAiB,GAAC,UAAU,GAAC,IAAI,YAC5D,YAAY,YACZ,OAAO,GACN,YAAY,CAgDvB;CACF;uBAtwCsB,kBAAkB"}
package/webgl/Helper.js CHANGED
@@ -2,6 +2,7 @@
2
2
  * @module ol/webgl/Helper
3
3
  */
4
4
  import Disposable from '../Disposable.js';
5
+ import {assert} from '../asserts.js';
5
6
  import {clear} from '../obj.js';
6
7
  import {
7
8
  compose as composeTransform,
@@ -499,6 +500,19 @@ class WebGLHelper extends Disposable {
499
500
  return extension;
500
501
  }
501
502
 
503
+ /**
504
+ * Will throw if the extension is not available
505
+ * @return {ANGLE_instanced_arrays} Extension
506
+ */
507
+ getInstancedRenderingExtension_() {
508
+ const ext = this.getExtension('ANGLE_instanced_arrays');
509
+ assert(
510
+ !!ext,
511
+ "WebGL extension 'ANGLE_instanced_arrays' is required for vector rendering",
512
+ );
513
+ return ext;
514
+ }
515
+
502
516
  /**
503
517
  * Just bind the buffer if it's in the cache. Otherwise create
504
518
  * the WebGL buffer, bind it, populate it, and add an entry to
@@ -721,6 +735,37 @@ class WebGLHelper extends Disposable {
721
735
  gl.drawElements(gl.TRIANGLES, numItems, elementType, offsetInBytes);
722
736
  }
723
737
 
738
+ /**
739
+ * Execute a draw call similar to `drawElements`, but using instanced rendering.
740
+ * Will have no effect if `enableAttributesInstanced` was not called for this rendering pass.
741
+ * @param {number} start Start index.
742
+ * @param {number} end End index.
743
+ * @param {number} instanceCount The number of instances to render
744
+ */
745
+ drawElementsInstanced(start, end, instanceCount) {
746
+ const gl = this.gl_;
747
+ this.getExtension('OES_element_index_uint');
748
+ const ext = this.getInstancedRenderingExtension_();
749
+
750
+ const elementType = gl.UNSIGNED_INT;
751
+ const elementSize = 4;
752
+
753
+ const numItems = end - start;
754
+ const offsetInBytes = start * elementSize;
755
+ ext.drawElementsInstancedANGLE(
756
+ gl.TRIANGLES,
757
+ numItems,
758
+ elementType,
759
+ offsetInBytes,
760
+ instanceCount,
761
+ );
762
+
763
+ // reset divisor values to avoid side effects
764
+ for (let i = 0; i < this.maxAttributeCount_; i++) {
765
+ ext.vertexAttribDivisorANGLE(i, 0);
766
+ }
767
+ }
768
+
724
769
  /**
725
770
  * Apply the successive post process passes which will eventually render to the actual canvas.
726
771
  * @param {import("../Map.js").FrameState} frameState current frame state
@@ -1092,9 +1137,10 @@ class WebGLHelper extends Disposable {
1092
1137
  * @param {number} type UNSIGNED_INT, UNSIGNED_BYTE, UNSIGNED_SHORT or FLOAT
1093
1138
  * @param {number} stride Stride in bytes (0 means attribs are packed)
1094
1139
  * @param {number} offset Offset in bytes
1140
+ * @param {boolean} instanced Whether the attribute is used for instanced rendering
1095
1141
  * @private
1096
1142
  */
1097
- enableAttributeArray_(attribName, size, type, stride, offset) {
1143
+ enableAttributeArray_(attribName, size, type, stride, offset, instanced) {
1098
1144
  const location = this.getAttributeLocation(attribName);
1099
1145
  // the attribute has not been found in the shaders or is not used; do not enable it
1100
1146
  if (location < 0) {
@@ -1102,15 +1148,21 @@ class WebGLHelper extends Disposable {
1102
1148
  }
1103
1149
  this.gl_.enableVertexAttribArray(location);
1104
1150
  this.gl_.vertexAttribPointer(location, size, type, false, stride, offset);
1151
+ if (instanced) {
1152
+ // note: this is reset to 0 after drawElementsInstanced is called
1153
+ this.getInstancedRenderingExtension_().vertexAttribDivisorANGLE(
1154
+ location,
1155
+ 1,
1156
+ );
1157
+ }
1105
1158
  }
1106
1159
 
1107
1160
  /**
1108
- * Will enable the following attributes to be read from the currently bound buffer,
1109
- * i.e. tell the GPU where to read the different attributes in the buffer. An error in the
1110
- * size/type/order of attributes will most likely break the rendering and throw a WebGL exception.
1161
+ * @private
1111
1162
  * @param {Array<AttributeDescription>} attributes Ordered list of attributes to read from the buffer
1163
+ * @param {boolean} instanced Whether the attributes are instanced.
1112
1164
  */
1113
- enableAttributes(attributes) {
1165
+ enableAttributes_(attributes, instanced) {
1114
1166
  const stride = computeAttributesStride(attributes);
1115
1167
  let offset = 0;
1116
1168
  for (let i = 0; i < attributes.length; i++) {
@@ -1123,12 +1175,32 @@ class WebGLHelper extends Disposable {
1123
1175
  attr.type || FLOAT,
1124
1176
  stride,
1125
1177
  offset,
1178
+ instanced,
1126
1179
  );
1127
1180
  }
1128
1181
  offset += attr.size * getByteSizeFromType(attr.type);
1129
1182
  }
1130
1183
  }
1131
1184
 
1185
+ /**
1186
+ * Will enable the following attributes to be read from the currently bound buffer,
1187
+ * i.e. tell the GPU where to read the different attributes in the buffer. An error in the
1188
+ * size/type/order of attributes will most likely break the rendering and throw a WebGL exception.
1189
+ * @param {Array<AttributeDescription>} attributes Ordered list of attributes to read from the buffer
1190
+ */
1191
+ enableAttributes(attributes) {
1192
+ this.enableAttributes_(attributes, false);
1193
+ }
1194
+
1195
+ /**
1196
+ * Will enable these attributes as instanced, meaning that they will only be read
1197
+ * once per instance instead of per vertex.
1198
+ * @param {Array<AttributeDescription>} attributes Ordered list of attributes to read from the buffer
1199
+ */
1200
+ enableAttributesInstanced(attributes) {
1201
+ this.enableAttributes_(attributes, true);
1202
+ }
1203
+
1132
1204
  /**
1133
1205
  * WebGL context was lost
1134
1206
  * @param {WebGLContextEvent} event The context loss event.