ol 7.4.1-dev.1686166152921 → 7.4.1-dev.1686296564657

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.
@@ -11,7 +11,9 @@ uniform float u_globalAlpha;
11
11
  uniform float u_time;
12
12
  uniform float u_zoom;
13
13
  uniform float u_resolution;
14
- uniform vec4 u_renderExtent;`;
14
+ uniform vec4 u_renderExtent;
15
+ uniform mediump int u_hitDetection;
16
+ `;
15
17
 
16
18
  /**
17
19
  * @typedef {Object} VaryingDescription
@@ -291,36 +293,22 @@ export class ShaderBuilder {
291
293
  /**
292
294
  * Generates a symbol vertex shader from the builder parameters
293
295
  *
294
- * Four uniforms are hardcoded in all shaders: `u_projectionMatrix`, `u_offsetScaleMatrix`,
295
- * `u_offsetRotateMatrix`, `u_time`.
296
+ * The following uniforms are hardcoded in all shaders: `u_projectionMatrix`, `u_offsetScaleMatrix`,
297
+ * `u_offsetRotateMatrix`, `u_time`, `u_zoom`, `u_resolution`, `u_hitDetection`.
296
298
  *
297
299
  * The following attributes are hardcoded and expected to be present in the vertex buffers:
298
- * `vec2 a_position`, `float a_index` (being the index of the vertex in the quad, 0 to 3).
300
+ * `vec2 a_position`, `float a_index` (being the index of the vertex in the quad, 0 to 3), `vec4 a_hitColor`.
299
301
  *
300
302
  * The following varyings are hardcoded and gives the coordinate of the pixel both in the quad and on the texture:
301
- * `vec2 v_quadCoord`, `vec2 v_texCoord`
303
+ * `vec2 v_quadCoord`, `vec2 v_texCoord`, `vec4 v_hitColor`.
302
304
  *
303
- * @param {boolean} [forHitDetection] If true, the shader will be modified to include hit detection variables
304
- * (namely, hit color with encoded feature id).
305
305
  * @return {string} The full shader as a string.
306
306
  */
307
- getSymbolVertexShader(forHitDetection) {
307
+ getSymbolVertexShader() {
308
308
  const offsetMatrix = this.symbolRotateWithView_
309
309
  ? 'u_offsetScaleMatrix * u_offsetRotateMatrix'
310
310
  : 'u_offsetScaleMatrix';
311
311
 
312
- let attributes = this.attributes_;
313
- let varyings = this.varyings_;
314
-
315
- if (forHitDetection) {
316
- attributes = attributes.concat('vec4 a_hitColor');
317
- varyings = varyings.concat({
318
- name: 'v_hitColor',
319
- type: 'vec4',
320
- expression: 'a_hitColor',
321
- });
322
- }
323
-
324
312
  return `precision mediump float;
325
313
  uniform mat4 u_projectionMatrix;
326
314
  uniform mat4 u_offsetScaleMatrix;
@@ -328,6 +316,8 @@ uniform mat4 u_offsetRotateMatrix;
328
316
  uniform float u_time;
329
317
  uniform float u_zoom;
330
318
  uniform float u_resolution;
319
+ uniform mediump int u_hitDetection;
320
+
331
321
  ${this.uniforms_
332
322
  .map(function (uniform) {
333
323
  return 'uniform ' + uniform + ';';
@@ -335,14 +325,16 @@ ${this.uniforms_
335
325
  .join('\n')}
336
326
  attribute vec2 a_position;
337
327
  attribute float a_index;
338
- ${attributes
328
+ attribute vec4 a_hitColor;
329
+ ${this.attributes_
339
330
  .map(function (attribute) {
340
331
  return 'attribute ' + attribute + ';';
341
332
  })
342
333
  .join('\n')}
343
334
  varying vec2 v_texCoord;
344
335
  varying vec2 v_quadCoord;
345
- ${varyings
336
+ varying vec4 v_hitColor;
337
+ ${this.varyings_
346
338
  .map(function (varying) {
347
339
  return 'varying ' + varying.type + ' ' + varying.name + ';';
348
340
  })
@@ -377,7 +369,8 @@ void main(void) {
377
369
  u = a_index == 0.0 || a_index == 3.0 ? 0.0 : 1.0;
378
370
  v = a_index == 2.0 || a_index == 3.0 ? 0.0 : 1.0;
379
371
  v_quadCoord = vec2(u, v);
380
- ${varyings
372
+ v_hitColor = a_hitColor;
373
+ ${this.varyings_
381
374
  .map(function (varying) {
382
375
  return ' ' + varying.name + ' = ' + varying.expression + ';';
383
376
  })
@@ -389,31 +382,16 @@ ${varyings
389
382
  * Generates a symbol fragment shader from the builder parameters
390
383
  *
391
384
  * Expects the following varyings to be transmitted by the vertex shader:
392
- * `vec2 v_quadCoord`, `vec2 v_texCoord`
385
+ * `vec2 v_quadCoord`, `vec2 v_texCoord`, `vec4 v_hitColor`.
393
386
  *
394
- * @param {boolean} [forHitDetection] If true, the shader will be modified to include hit detection variables
395
- * (namely, hit color with encoded feature id).
396
387
  * @return {string} The full shader as a string.
397
388
  */
398
- getSymbolFragmentShader(forHitDetection) {
399
- const hitDetectionBypass = forHitDetection
400
- ? ' if (gl_FragColor.a < 0.1) { discard; } gl_FragColor = v_hitColor;'
401
- : '';
402
-
403
- let varyings = this.varyings_;
404
-
405
- if (forHitDetection) {
406
- varyings = varyings.concat({
407
- name: 'v_hitColor',
408
- type: 'vec4',
409
- expression: 'a_hitColor',
410
- });
411
- }
412
-
389
+ getSymbolFragmentShader() {
413
390
  return `precision mediump float;
414
391
  uniform float u_time;
415
392
  uniform float u_zoom;
416
393
  uniform float u_resolution;
394
+ uniform mediump int u_hitDetection;
417
395
  ${this.uniforms_
418
396
  .map(function (uniform) {
419
397
  return 'uniform ' + uniform + ';';
@@ -421,7 +399,8 @@ ${this.uniforms_
421
399
  .join('\n')}
422
400
  varying vec2 v_texCoord;
423
401
  varying vec2 v_quadCoord;
424
- ${varyings
402
+ varying vec4 v_hitColor;
403
+ ${this.varyings_
425
404
  .map(function (varying) {
426
405
  return 'varying ' + varying.type + ' ' + varying.name + ';';
427
406
  })
@@ -431,30 +410,18 @@ void main(void) {
431
410
  if (${this.discardExpression_}) { discard; }
432
411
  gl_FragColor = ${this.symbolColorExpression_};
433
412
  gl_FragColor.rgb *= gl_FragColor.a;
434
- ${hitDetectionBypass}
413
+ if (u_hitDetection > 0) {
414
+ if (gl_FragColor.a < 0.1) { discard; };
415
+ gl_FragColor = v_hitColor;
416
+ }
435
417
  }`;
436
418
  }
437
419
 
438
420
  /**
439
421
  * Generates a stroke vertex shader from the builder parameters
440
- *
441
- * @param {boolean} [forHitDetection] If true, the shader will be modified to include hit detection variables
442
- * (namely, hit color with encoded feature id).
443
422
  * @return {string} The full shader as a string.
444
423
  */
445
- getStrokeVertexShader(forHitDetection) {
446
- let attributes = this.attributes_;
447
- let varyings = this.varyings_;
448
-
449
- if (forHitDetection) {
450
- attributes = attributes.concat('vec4 a_hitColor');
451
- varyings = varyings.concat({
452
- name: 'v_hitColor',
453
- type: 'vec4',
454
- expression: 'a_hitColor',
455
- });
456
- }
457
-
424
+ getStrokeVertexShader() {
458
425
  return `#ifdef GL_FRAGMENT_PRECISION_HIGH
459
426
  precision highp float;
460
427
  #else
@@ -471,7 +438,8 @@ attribute float a_index;
471
438
  attribute vec2 a_segmentStart;
472
439
  attribute vec2 a_segmentEnd;
473
440
  attribute float a_parameters;
474
- ${attributes
441
+ attribute vec4 a_hitColor;
442
+ ${this.attributes_
475
443
  .map(function (attribute) {
476
444
  return 'attribute ' + attribute + ';';
477
445
  })
@@ -481,7 +449,8 @@ varying vec2 v_segmentEnd;
481
449
  varying float v_angleStart;
482
450
  varying float v_angleEnd;
483
451
  varying float v_width;
484
- ${varyings
452
+ varying vec4 v_hitColor;
453
+ ${this.varyings_
485
454
  .map(function (varying) {
486
455
  return 'varying ' + varying.type + ' ' + varying.name + ';';
487
456
  })
@@ -527,7 +496,8 @@ void main(void) {
527
496
  v_segmentStart = worldToPx(a_segmentStart);
528
497
  v_segmentEnd = worldToPx(a_segmentEnd);
529
498
  v_width = lineWidth;
530
- ${varyings
499
+ v_hitColor = a_hitColor;
500
+ ${this.varyings_
531
501
  .map(function (varying) {
532
502
  return ' ' + varying.name + ' = ' + varying.expression + ';';
533
503
  })
@@ -538,25 +508,9 @@ ${varyings
538
508
  /**
539
509
  * Generates a stroke fragment shader from the builder parameters
540
510
  *
541
- * @param {boolean} [forHitDetection] If true, the shader will be modified to include hit detection variables
542
- * (namely, hit color with encoded feature id).
543
511
  * @return {string} The full shader as a string.
544
512
  */
545
- getStrokeFragmentShader(forHitDetection) {
546
- const hitDetectionBypass = forHitDetection
547
- ? ' if (gl_FragColor.a < 0.1) { discard; } gl_FragColor = v_hitColor;'
548
- : '';
549
-
550
- let varyings = this.varyings_;
551
-
552
- if (forHitDetection) {
553
- varyings = varyings.concat({
554
- name: 'v_hitColor',
555
- type: 'vec4',
556
- expression: 'a_hitColor',
557
- });
558
- }
559
-
513
+ getStrokeFragmentShader() {
560
514
  return `#ifdef GL_FRAGMENT_PRECISION_HIGH
561
515
  precision highp float;
562
516
  #else
@@ -573,7 +527,8 @@ varying vec2 v_segmentEnd;
573
527
  varying float v_angleStart;
574
528
  varying float v_angleEnd;
575
529
  varying float v_width;
576
- ${varyings
530
+ varying vec4 v_hitColor;
531
+ ${this.varyings_
577
532
  .map(function (varying) {
578
533
  return 'varying ' + varying.type + ' ' + varying.name + ';';
579
534
  })
@@ -610,30 +565,19 @@ void main(void) {
610
565
  if (${this.discardExpression_}) { discard; }
611
566
  gl_FragColor = ${this.strokeColorExpression_} * u_globalAlpha;
612
567
  gl_FragColor *= segmentDistanceField(v_currentPoint, v_segmentStart, v_segmentEnd, v_width);
613
- ${hitDetectionBypass}
568
+ if (u_hitDetection > 0) {
569
+ if (gl_FragColor.a < 0.1) { discard; };
570
+ gl_FragColor = v_hitColor;
571
+ }
614
572
  }`;
615
573
  }
616
574
 
617
575
  /**
618
576
  * Generates a fill vertex shader from the builder parameters
619
577
  *
620
- * @param {boolean} [forHitDetection] If true, the shader will be modified to include hit detection variables
621
- * (namely, hit color with encoded feature id).
622
578
  * @return {string} The full shader as a string.
623
579
  */
624
- getFillVertexShader(forHitDetection) {
625
- let attributes = this.attributes_;
626
- let varyings = this.varyings_;
627
-
628
- if (forHitDetection) {
629
- attributes = attributes.concat('vec4 a_hitColor');
630
- varyings = varyings.concat({
631
- name: 'v_hitColor',
632
- type: 'vec4',
633
- expression: 'a_hitColor',
634
- });
635
- }
636
-
580
+ getFillVertexShader() {
637
581
  return `#ifdef GL_FRAGMENT_PRECISION_HIGH
638
582
  precision highp float;
639
583
  #else
@@ -646,12 +590,14 @@ ${this.uniforms_
646
590
  })
647
591
  .join('\n')}
648
592
  attribute vec2 a_position;
649
- ${attributes
593
+ attribute vec4 a_hitColor;
594
+ ${this.attributes_
650
595
  .map(function (attribute) {
651
596
  return 'attribute ' + attribute + ';';
652
597
  })
653
598
  .join('\n')}
654
- ${varyings
599
+ varying vec4 v_hitColor;
600
+ ${this.varyings_
655
601
  .map(function (varying) {
656
602
  return 'varying ' + varying.type + ' ' + varying.name + ';';
657
603
  })
@@ -659,7 +605,7 @@ ${varyings
659
605
  ${this.vertexShaderFunctions_.join('\n')}
660
606
  void main(void) {
661
607
  gl_Position = u_projectionMatrix * vec4(a_position, 0.0, 1.0);
662
- ${varyings
608
+ ${this.varyings_
663
609
  .map(function (varying) {
664
610
  return ' ' + varying.name + ' = ' + varying.expression + ';';
665
611
  })
@@ -669,26 +615,9 @@ ${varyings
669
615
 
670
616
  /**
671
617
  * Generates a fill fragment shader from the builder parameters
672
- *
673
- * @param {boolean} [forHitDetection] If true, the shader will be modified to include hit detection variables
674
- * (namely, hit color with encoded feature id).
675
618
  * @return {string} The full shader as a string.
676
619
  */
677
- getFillFragmentShader(forHitDetection) {
678
- const hitDetectionBypass = forHitDetection
679
- ? ' if (gl_FragColor.a < 0.1) { discard; } gl_FragColor = v_hitColor;'
680
- : '';
681
-
682
- let varyings = this.varyings_;
683
-
684
- if (forHitDetection) {
685
- varyings = varyings.concat({
686
- name: 'v_hitColor',
687
- type: 'vec4',
688
- expression: 'a_hitColor',
689
- });
690
- }
691
-
620
+ getFillFragmentShader() {
692
621
  return `#ifdef GL_FRAGMENT_PRECISION_HIGH
693
622
  precision highp float;
694
623
  #else
@@ -700,7 +629,8 @@ ${this.uniforms_
700
629
  return 'uniform ' + uniform + ';';
701
630
  })
702
631
  .join('\n')}
703
- ${varyings
632
+ varying vec4 v_hitColor;
633
+ ${this.varyings_
704
634
  .map(function (varying) {
705
635
  return 'varying ' + varying.type + ' ' + varying.name + ';';
706
636
  })
@@ -727,7 +657,10 @@ void main(void) {
727
657
  #endif
728
658
  if (${this.discardExpression_}) { discard; }
729
659
  gl_FragColor = ${this.fillColorExpression_} * u_globalAlpha;
730
- ${hitDetectionBypass}
660
+ if (u_hitDetection > 0) {
661
+ if (gl_FragColor.a < 0.1) { discard; };
662
+ gl_FragColor = v_hitColor;
663
+ }
731
664
  }`;
732
665
  }
733
666
  }