@mapwhit/tilerenderer 0.47.1
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/LICENSE.txt +87 -0
- package/README.md +25 -0
- package/build/min/.dir +0 -0
- package/build/min/package.json +3 -0
- package/build/min/src/shaders/_prelude.fragment.glsl.txt +13 -0
- package/build/min/src/shaders/_prelude.vertex.glsl.txt +14 -0
- package/build/min/src/shaders/background.fragment.glsl.txt +5 -0
- package/build/min/src/shaders/background.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/background_pattern.fragment.glsl.txt +5 -0
- package/build/min/src/shaders/background_pattern.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/circle.fragment.glsl.txt +20 -0
- package/build/min/src/shaders/circle.vertex.glsl.txt +17 -0
- package/build/min/src/shaders/clipping_mask.fragment.glsl.txt +1 -0
- package/build/min/src/shaders/clipping_mask.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/collision_box.fragment.glsl.txt +1 -0
- package/build/min/src/shaders/collision_box.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/collision_circle.fragment.glsl.txt +1 -0
- package/build/min/src/shaders/collision_circle.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/debug.fragment.glsl.txt +1 -0
- package/build/min/src/shaders/debug.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/fill.fragment.glsl.txt +10 -0
- package/build/min/src/shaders/fill.vertex.glsl.txt +7 -0
- package/build/min/src/shaders/fill_extrusion.fragment.glsl.txt +13 -0
- package/build/min/src/shaders/fill_extrusion.vertex.glsl.txt +9 -0
- package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.txt +15 -0
- package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.txt +11 -0
- package/build/min/src/shaders/fill_outline.fragment.glsl.txt +10 -0
- package/build/min/src/shaders/fill_outline.vertex.glsl.txt +7 -0
- package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.txt +13 -0
- package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.txt +9 -0
- package/build/min/src/shaders/fill_pattern.fragment.glsl.txt +13 -0
- package/build/min/src/shaders/fill_pattern.vertex.glsl.txt +9 -0
- package/build/min/src/shaders/heatmap.fragment.glsl.txt +10 -0
- package/build/min/src/shaders/heatmap.vertex.glsl.txt +8 -0
- package/build/min/src/shaders/heatmap_texture.fragment.glsl.txt +5 -0
- package/build/min/src/shaders/heatmap_texture.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/hillshade.fragment.glsl.txt +7 -0
- package/build/min/src/shaders/hillshade.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/hillshade_prepare.fragment.glsl.txt +8 -0
- package/build/min/src/shaders/hillshade_prepare.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/line.fragment.glsl.txt +12 -0
- package/build/min/src/shaders/line.vertex.glsl.txt +17 -0
- package/build/min/src/shaders/line_gradient.fragment.glsl.txt +10 -0
- package/build/min/src/shaders/line_gradient.vertex.glsl.txt +16 -0
- package/build/min/src/shaders/line_pattern.fragment.glsl.txt +15 -0
- package/build/min/src/shaders/line_pattern.vertex.glsl.txt +20 -0
- package/build/min/src/shaders/line_sdf.fragment.glsl.txt +17 -0
- package/build/min/src/shaders/line_sdf.vertex.glsl.txt +20 -0
- package/build/min/src/shaders/raster.fragment.glsl.txt +5 -0
- package/build/min/src/shaders/raster.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/symbol_icon.fragment.glsl.txt +9 -0
- package/build/min/src/shaders/symbol_icon.vertex.glsl.txt +5 -0
- package/build/min/src/shaders/symbol_sdf.fragment.glsl.txt +19 -0
- package/build/min/src/shaders/symbol_sdf.vertex.glsl.txt +13 -0
- package/package.json +44 -0
- package/src/css/mapbox-gl.css +506 -0
- package/src/css/svg/mapboxgl-ctrl-attrib.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-compass.svg +4 -0
- package/src/css/svg/mapboxgl-ctrl-fullscreen.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-geolocate-background.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-geolocate.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-logo-compact.svg +2 -0
- package/src/css/svg/mapboxgl-ctrl-logo.svg +1 -0
- package/src/css/svg/mapboxgl-ctrl-shrink.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-zoom-in.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-zoom-out.svg +3 -0
- package/src/data/array_types.js +1138 -0
- package/src/data/bucket/circle_attributes.js +5 -0
- package/src/data/bucket/circle_bucket.js +118 -0
- package/src/data/bucket/fill_attributes.js +5 -0
- package/src/data/bucket/fill_bucket.js +166 -0
- package/src/data/bucket/fill_extrusion_attributes.js +11 -0
- package/src/data/bucket/fill_extrusion_bucket.js +247 -0
- package/src/data/bucket/heatmap_bucket.js +12 -0
- package/src/data/bucket/line_attributes.js +11 -0
- package/src/data/bucket/line_bucket.js +625 -0
- package/src/data/bucket/pattern_attributes.js +9 -0
- package/src/data/bucket/pattern_bucket_features.js +44 -0
- package/src/data/bucket/symbol_attributes.js +95 -0
- package/src/data/bucket/symbol_bucket.js +697 -0
- package/src/data/bucket.js +53 -0
- package/src/data/dem_data.js +126 -0
- package/src/data/extent.js +17 -0
- package/src/data/feature_index.js +254 -0
- package/src/data/index_array_type.js +14 -0
- package/src/data/load_geometry.js +42 -0
- package/src/data/pos_attributes.js +3 -0
- package/src/data/program_configuration.js +782 -0
- package/src/data/raster_bounds_attributes.js +6 -0
- package/src/data/segment.js +63 -0
- package/src/geo/coordinate.js +78 -0
- package/src/geo/lng_lat.js +129 -0
- package/src/geo/lng_lat_bounds.js +253 -0
- package/src/geo/transform.js +605 -0
- package/src/gl/color_mode.js +21 -0
- package/src/gl/context.js +193 -0
- package/src/gl/cull_face_mode.js +22 -0
- package/src/gl/depth_mode.js +18 -0
- package/src/gl/framebuffer.js +28 -0
- package/src/gl/index_buffer.js +52 -0
- package/src/gl/stencil_mode.js +17 -0
- package/src/gl/types.js +0 -0
- package/src/gl/value.js +676 -0
- package/src/gl/vertex_buffer.js +101 -0
- package/src/index.js +50 -0
- package/src/render/draw_background.js +60 -0
- package/src/render/draw_circle.js +55 -0
- package/src/render/draw_collision_debug.js +45 -0
- package/src/render/draw_debug.js +429 -0
- package/src/render/draw_fill.js +143 -0
- package/src/render/draw_fill_extrusion.js +101 -0
- package/src/render/draw_heatmap.js +159 -0
- package/src/render/draw_hillshade.js +144 -0
- package/src/render/draw_line.js +99 -0
- package/src/render/draw_raster.js +151 -0
- package/src/render/draw_symbol.js +231 -0
- package/src/render/glyph_atlas.js +55 -0
- package/src/render/glyph_manager.js +145 -0
- package/src/render/image_atlas.js +97 -0
- package/src/render/image_manager.js +183 -0
- package/src/render/line_atlas.js +139 -0
- package/src/render/painter.js +483 -0
- package/src/render/program/background_program.js +46 -0
- package/src/render/program/circle_program.js +40 -0
- package/src/render/program/clipping_mask_program.js +11 -0
- package/src/render/program/collision_program.js +28 -0
- package/src/render/program/debug_program.js +13 -0
- package/src/render/program/fill_extrusion_program.js +76 -0
- package/src/render/program/fill_program.js +60 -0
- package/src/render/program/heatmap_program.js +46 -0
- package/src/render/program/hillshade_program.js +77 -0
- package/src/render/program/line_program.js +119 -0
- package/src/render/program/pattern.js +57 -0
- package/src/render/program/program_uniforms.js +46 -0
- package/src/render/program/raster_program.js +50 -0
- package/src/render/program/symbol_program.js +112 -0
- package/src/render/program.js +133 -0
- package/src/render/texture.js +88 -0
- package/src/render/tile_mask.js +108 -0
- package/src/render/uniform_binding.js +129 -0
- package/src/render/vertex_array_object.js +155 -0
- package/src/shaders/README.md +42 -0
- package/src/shaders/_prelude.fragment.glsl +17 -0
- package/src/shaders/_prelude.vertex.glsl +73 -0
- package/src/shaders/background.fragment.glsl +10 -0
- package/src/shaders/background.vertex.glsl +7 -0
- package/src/shaders/background_pattern.fragment.glsl +28 -0
- package/src/shaders/background_pattern.vertex.glsl +20 -0
- package/src/shaders/circle.fragment.glsl +39 -0
- package/src/shaders/circle.vertex.glsl +63 -0
- package/src/shaders/clipping_mask.fragment.glsl +3 -0
- package/src/shaders/clipping_mask.vertex.glsl +7 -0
- package/src/shaders/collision_box.fragment.glsl +21 -0
- package/src/shaders/collision_box.vertex.glsl +26 -0
- package/src/shaders/collision_circle.fragment.glsl +34 -0
- package/src/shaders/collision_circle.vertex.glsl +36 -0
- package/src/shaders/debug.fragment.glsl +5 -0
- package/src/shaders/debug.vertex.glsl +7 -0
- package/src/shaders/encode_attribute.js +19 -0
- package/src/shaders/fill.fragment.glsl +13 -0
- package/src/shaders/fill.vertex.glsl +13 -0
- package/src/shaders/fill_extrusion.fragment.glsl +16 -0
- package/src/shaders/fill_extrusion.vertex.glsl +66 -0
- package/src/shaders/fill_extrusion_pattern.fragment.glsl +41 -0
- package/src/shaders/fill_extrusion_pattern.vertex.glsl +76 -0
- package/src/shaders/fill_outline.fragment.glsl +17 -0
- package/src/shaders/fill_outline.vertex.glsl +17 -0
- package/src/shaders/fill_outline_pattern.fragment.glsl +43 -0
- package/src/shaders/fill_outline_pattern.vertex.glsl +41 -0
- package/src/shaders/fill_pattern.fragment.glsl +36 -0
- package/src/shaders/fill_pattern.vertex.glsl +36 -0
- package/src/shaders/heatmap.fragment.glsl +21 -0
- package/src/shaders/heatmap.vertex.glsl +53 -0
- package/src/shaders/heatmap_texture.fragment.glsl +14 -0
- package/src/shaders/heatmap_texture.vertex.glsl +11 -0
- package/src/shaders/hillshade.fragment.glsl +52 -0
- package/src/shaders/hillshade.vertex.glsl +11 -0
- package/src/shaders/hillshade_prepare.fragment.glsl +72 -0
- package/src/shaders/hillshade_prepare.vertex.glsl +15 -0
- package/src/shaders/index.js +194 -0
- package/src/shaders/line.fragment.glsl +28 -0
- package/src/shaders/line.vertex.glsl +84 -0
- package/src/shaders/line_gradient.fragment.glsl +34 -0
- package/src/shaders/line_gradient.vertex.glsl +84 -0
- package/src/shaders/line_pattern.fragment.glsl +69 -0
- package/src/shaders/line_pattern.vertex.glsl +88 -0
- package/src/shaders/line_sdf.fragment.glsl +44 -0
- package/src/shaders/line_sdf.vertex.glsl +95 -0
- package/src/shaders/raster.fragment.glsl +52 -0
- package/src/shaders/raster.vertex.glsl +21 -0
- package/src/shaders/symbol_icon.fragment.glsl +17 -0
- package/src/shaders/symbol_icon.vertex.glsl +91 -0
- package/src/shaders/symbol_sdf.fragment.glsl +50 -0
- package/src/shaders/symbol_sdf.vertex.glsl +117 -0
- package/src/source/geojson_source.js +267 -0
- package/src/source/geojson_worker_source.js +210 -0
- package/src/source/geojson_wrapper.js +67 -0
- package/src/source/image_source.js +213 -0
- package/src/source/load_tilejson.js +40 -0
- package/src/source/pixels_to_tile_units.js +17 -0
- package/src/source/query_features.js +198 -0
- package/src/source/raster_dem_tile_source.js +140 -0
- package/src/source/raster_dem_tile_worker_source.js +26 -0
- package/src/source/raster_tile_source.js +126 -0
- package/src/source/rtl_text_plugin.js +63 -0
- package/src/source/source.js +75 -0
- package/src/source/source_cache.js +794 -0
- package/src/source/source_state.js +55 -0
- package/src/source/tile.js +332 -0
- package/src/source/tile_bounds.js +40 -0
- package/src/source/tile_cache.js +122 -0
- package/src/source/tile_id.js +150 -0
- package/src/source/vector_tile_source.js +144 -0
- package/src/source/vector_tile_worker_source.js +126 -0
- package/src/source/worker.js +175 -0
- package/src/source/worker_source.js +14 -0
- package/src/source/worker_tile.js +199 -0
- package/src/style/create_style_layer.js +25 -0
- package/src/style/evaluation_parameters.js +45 -0
- package/src/style/light.js +112 -0
- package/src/style/load_glyph_range.js +17 -0
- package/src/style/load_sprite.js +26 -0
- package/src/style/parse_glyph_pbf.js +45 -0
- package/src/style/pauseable_placement.js +88 -0
- package/src/style/properties.js +691 -0
- package/src/style/query_utils.js +39 -0
- package/src/style/style.js +955 -0
- package/src/style/style_layer/background_style_layer.js +11 -0
- package/src/style/style_layer/background_style_layer_properties.js +25 -0
- package/src/style/style_layer/circle_style_layer.js +93 -0
- package/src/style/style_layer/circle_style_layer_properties.js +76 -0
- package/src/style/style_layer/fill_extrusion_style_layer.js +194 -0
- package/src/style/style_layer/fill_extrusion_style_layer_properties.js +56 -0
- package/src/style/style_layer/fill_style_layer.js +46 -0
- package/src/style/style_layer/fill_style_layer_properties.js +45 -0
- package/src/style/style_layer/heatmap_style_layer.js +51 -0
- package/src/style/style_layer/heatmap_style_layer_properties.js +52 -0
- package/src/style/style_layer/hillshade_style_layer.js +15 -0
- package/src/style/style_layer/hillshade_style_layer_properties.js +43 -0
- package/src/style/style_layer/line_style_layer.js +129 -0
- package/src/style/style_layer/line_style_layer_properties.js +104 -0
- package/src/style/style_layer/raster_style_layer.js +11 -0
- package/src/style/style_layer/raster_style_layer_properties.js +55 -0
- package/src/style/style_layer/symbol_style_layer.js +66 -0
- package/src/style/style_layer/symbol_style_layer_properties.js +288 -0
- package/src/style/style_layer.js +183 -0
- package/src/style/style_layer_index.js +61 -0
- package/src/style/zoom_history.js +36 -0
- package/src/style-spec/deref.js +51 -0
- package/src/style-spec/error/parsing_error.js +8 -0
- package/src/style-spec/error/validation_error.js +10 -0
- package/src/style-spec/expression/compound_expression.js +118 -0
- package/src/style-spec/expression/definitions/array.js +82 -0
- package/src/style-spec/expression/definitions/assertion.js +69 -0
- package/src/style-spec/expression/definitions/at.js +57 -0
- package/src/style-spec/expression/definitions/case.js +73 -0
- package/src/style-spec/expression/definitions/coalesce.js +68 -0
- package/src/style-spec/expression/definitions/coercion.js +96 -0
- package/src/style-spec/expression/definitions/collator.js +102 -0
- package/src/style-spec/expression/definitions/equals.js +93 -0
- package/src/style-spec/expression/definitions/index.js +407 -0
- package/src/style-spec/expression/definitions/interpolate.js +235 -0
- package/src/style-spec/expression/definitions/length.js +54 -0
- package/src/style-spec/expression/definitions/let.js +60 -0
- package/src/style-spec/expression/definitions/literal.js +64 -0
- package/src/style-spec/expression/definitions/match.js +142 -0
- package/src/style-spec/expression/definitions/step.js +116 -0
- package/src/style-spec/expression/definitions/var.js +38 -0
- package/src/style-spec/expression/evaluation_context.js +35 -0
- package/src/style-spec/expression/index.js +329 -0
- package/src/style-spec/expression/is_constant.js +63 -0
- package/src/style-spec/expression/parsing_context.js +213 -0
- package/src/style-spec/expression/parsing_error.js +9 -0
- package/src/style-spec/expression/runtime_error.js +12 -0
- package/src/style-spec/expression/scope.js +34 -0
- package/src/style-spec/expression/stops.js +37 -0
- package/src/style-spec/expression/types.js +77 -0
- package/src/style-spec/expression/values.js +126 -0
- package/src/style-spec/feature_filter/README.md +55 -0
- package/src/style-spec/feature_filter/index.js +158 -0
- package/src/style-spec/function/convert.js +256 -0
- package/src/style-spec/function/index.js +299 -0
- package/src/style-spec/group_by_layout.js +68 -0
- package/src/style-spec/reference/v8.json +5356 -0
- package/src/style-spec/util/color.js +73 -0
- package/src/style-spec/util/color_spaces.js +128 -0
- package/src/style-spec/util/eval_support.js +8 -0
- package/src/style-spec/util/get_type.js +18 -0
- package/src/style-spec/util/interpolate.js +21 -0
- package/src/style-spec/util/properties.js +17 -0
- package/src/style-spec/util/ref_properties.js +1 -0
- package/src/style-spec/util/result.js +19 -0
- package/src/symbol/anchor.js +21 -0
- package/src/symbol/check_max_angle.js +75 -0
- package/src/symbol/clip_line.js +73 -0
- package/src/symbol/collision_feature.js +230 -0
- package/src/symbol/collision_index.js +379 -0
- package/src/symbol/cross_tile_symbol_index.js +270 -0
- package/src/symbol/get_anchors.js +177 -0
- package/src/symbol/grid_index.js +318 -0
- package/src/symbol/mergelines.js +75 -0
- package/src/symbol/opacity_state.js +21 -0
- package/src/symbol/placement.js +563 -0
- package/src/symbol/projection.js +601 -0
- package/src/symbol/quads.js +173 -0
- package/src/symbol/shaping.js +347 -0
- package/src/symbol/symbol_layout.js +519 -0
- package/src/symbol/symbol_size.js +110 -0
- package/src/symbol/transform_text.js +16 -0
- package/src/ui/anchor.js +24 -0
- package/src/ui/bind_handlers.js +199 -0
- package/src/ui/camera.js +954 -0
- package/src/ui/events.js +210 -0
- package/src/ui/handler/box_zoom.js +151 -0
- package/src/ui/handler/dblclick_zoom.js +91 -0
- package/src/ui/handler/drag_pan.js +285 -0
- package/src/ui/handler/drag_rotate.js +290 -0
- package/src/ui/handler/frame.js +28 -0
- package/src/ui/handler/inertia.js +45 -0
- package/src/ui/handler/keyboard.js +148 -0
- package/src/ui/handler/scroll_zoom.js +284 -0
- package/src/ui/handler/touch_zoom_rotate.js +263 -0
- package/src/ui/map.js +1645 -0
- package/src/util/actor.js +104 -0
- package/src/util/async.js +23 -0
- package/src/util/browser.js +61 -0
- package/src/util/callback.js +26 -0
- package/src/util/classify_rings.js +43 -0
- package/src/util/color_ramp.js +24 -0
- package/src/util/config.js +24 -0
- package/src/util/dictionary_coder.js +25 -0
- package/src/util/dispatcher.js +68 -0
- package/src/util/dom.js +102 -0
- package/src/util/evented.js +182 -0
- package/src/util/find_pole_of_inaccessibility.js +129 -0
- package/src/util/global_worker_pool.js +15 -0
- package/src/util/image.js +124 -0
- package/src/util/interpolate.js +5 -0
- package/src/util/intersection_tests.js +207 -0
- package/src/util/is_char_in_unicode_block.js +287 -0
- package/src/util/loader/image.js +32 -0
- package/src/util/object.js +178 -0
- package/src/util/script_detection.js +337 -0
- package/src/util/struct_array.js +197 -0
- package/src/util/task_queue.js +57 -0
- package/src/util/throttle.js +26 -0
- package/src/util/tile_cover.js +114 -0
- package/src/util/token.js +13 -0
- package/src/util/unique_id.js +12 -0
- package/src/util/util.js +192 -0
- package/src/util/vectortile_to_geojson.js +44 -0
- package/src/util/verticalize_punctuation.js +112 -0
- package/src/util/warn.js +21 -0
- package/src/util/web_worker.js +5 -0
- package/src/util/web_worker_transfer.js +228 -0
- package/src/util/worker_pool.js +41 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
|
|
3
|
+
class VertexArrayObject {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.boundProgram = null;
|
|
6
|
+
this.boundLayoutVertexBuffer = null;
|
|
7
|
+
this.boundPaintVertexBuffers = [];
|
|
8
|
+
this.boundIndexBuffer = null;
|
|
9
|
+
this.boundVertexOffset = null;
|
|
10
|
+
this.boundDynamicVertexBuffer = null;
|
|
11
|
+
this.vao = null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
bind(
|
|
15
|
+
context,
|
|
16
|
+
program,
|
|
17
|
+
layoutVertexBuffer,
|
|
18
|
+
paintVertexBuffers,
|
|
19
|
+
indexBuffer,
|
|
20
|
+
vertexOffset,
|
|
21
|
+
dynamicVertexBuffer,
|
|
22
|
+
dynamicVertexBuffer2
|
|
23
|
+
) {
|
|
24
|
+
this.context = context;
|
|
25
|
+
|
|
26
|
+
let paintBuffersDiffer = this.boundPaintVertexBuffers.length !== paintVertexBuffers.length;
|
|
27
|
+
for (let i = 0; !paintBuffersDiffer && i < paintVertexBuffers.length; i++) {
|
|
28
|
+
if (this.boundPaintVertexBuffers[i] !== paintVertexBuffers[i]) {
|
|
29
|
+
paintBuffersDiffer = true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const isFreshBindRequired =
|
|
34
|
+
!this.vao ||
|
|
35
|
+
this.boundProgram !== program ||
|
|
36
|
+
this.boundLayoutVertexBuffer !== layoutVertexBuffer ||
|
|
37
|
+
paintBuffersDiffer ||
|
|
38
|
+
this.boundIndexBuffer !== indexBuffer ||
|
|
39
|
+
this.boundVertexOffset !== vertexOffset ||
|
|
40
|
+
this.boundDynamicVertexBuffer !== dynamicVertexBuffer ||
|
|
41
|
+
this.boundDynamicVertexBuffer2 !== dynamicVertexBuffer2;
|
|
42
|
+
|
|
43
|
+
if (!context.extVertexArrayObject || isFreshBindRequired) {
|
|
44
|
+
this.freshBind(
|
|
45
|
+
program,
|
|
46
|
+
layoutVertexBuffer,
|
|
47
|
+
paintVertexBuffers,
|
|
48
|
+
indexBuffer,
|
|
49
|
+
vertexOffset,
|
|
50
|
+
dynamicVertexBuffer,
|
|
51
|
+
dynamicVertexBuffer2
|
|
52
|
+
);
|
|
53
|
+
} else {
|
|
54
|
+
context.bindVertexArrayOES.set(this.vao);
|
|
55
|
+
|
|
56
|
+
if (dynamicVertexBuffer) {
|
|
57
|
+
// The buffer may have been updated. Rebind to upload data.
|
|
58
|
+
dynamicVertexBuffer.bind();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (indexBuffer?.dynamicDraw) {
|
|
62
|
+
indexBuffer.bind();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (dynamicVertexBuffer2) {
|
|
66
|
+
dynamicVertexBuffer2.bind();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
freshBind(
|
|
72
|
+
program,
|
|
73
|
+
layoutVertexBuffer,
|
|
74
|
+
paintVertexBuffers,
|
|
75
|
+
indexBuffer,
|
|
76
|
+
vertexOffset,
|
|
77
|
+
dynamicVertexBuffer,
|
|
78
|
+
dynamicVertexBuffer2
|
|
79
|
+
) {
|
|
80
|
+
let numPrevAttributes;
|
|
81
|
+
const numNextAttributes = program.numAttributes;
|
|
82
|
+
|
|
83
|
+
const context = this.context;
|
|
84
|
+
const gl = context.gl;
|
|
85
|
+
|
|
86
|
+
if (context.extVertexArrayObject) {
|
|
87
|
+
if (this.vao) this.destroy();
|
|
88
|
+
this.vao = context.extVertexArrayObject.createVertexArrayOES();
|
|
89
|
+
context.bindVertexArrayOES.set(this.vao);
|
|
90
|
+
numPrevAttributes = 0;
|
|
91
|
+
|
|
92
|
+
// store the arguments so that we can verify them when the vao is bound again
|
|
93
|
+
this.boundProgram = program;
|
|
94
|
+
this.boundLayoutVertexBuffer = layoutVertexBuffer;
|
|
95
|
+
this.boundPaintVertexBuffers = paintVertexBuffers;
|
|
96
|
+
this.boundIndexBuffer = indexBuffer;
|
|
97
|
+
this.boundVertexOffset = vertexOffset;
|
|
98
|
+
this.boundDynamicVertexBuffer = dynamicVertexBuffer;
|
|
99
|
+
this.boundDynamicVertexBuffer2 = dynamicVertexBuffer2;
|
|
100
|
+
} else {
|
|
101
|
+
numPrevAttributes = context.currentNumAttributes || 0;
|
|
102
|
+
|
|
103
|
+
// Disable all attributes from the previous program that aren't used in
|
|
104
|
+
// the new program. Note: attribute indices are *not* program specific!
|
|
105
|
+
for (let i = numNextAttributes; i < numPrevAttributes; i++) {
|
|
106
|
+
// WebGL breaks if you disable attribute 0.
|
|
107
|
+
// http://stackoverflow.com/questions/20305231
|
|
108
|
+
assert(i !== 0);
|
|
109
|
+
gl.disableVertexAttribArray(i);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
layoutVertexBuffer.enableAttributes(gl, program);
|
|
114
|
+
for (const vertexBuffer of paintVertexBuffers) {
|
|
115
|
+
vertexBuffer.enableAttributes(gl, program);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (dynamicVertexBuffer) {
|
|
119
|
+
dynamicVertexBuffer.enableAttributes(gl, program);
|
|
120
|
+
}
|
|
121
|
+
if (dynamicVertexBuffer2) {
|
|
122
|
+
dynamicVertexBuffer2.enableAttributes(gl, program);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
layoutVertexBuffer.bind();
|
|
126
|
+
layoutVertexBuffer.setVertexAttribPointers(gl, program, vertexOffset);
|
|
127
|
+
for (const vertexBuffer of paintVertexBuffers) {
|
|
128
|
+
vertexBuffer.bind();
|
|
129
|
+
vertexBuffer.setVertexAttribPointers(gl, program, vertexOffset);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (dynamicVertexBuffer) {
|
|
133
|
+
dynamicVertexBuffer.bind();
|
|
134
|
+
dynamicVertexBuffer.setVertexAttribPointers(gl, program, vertexOffset);
|
|
135
|
+
}
|
|
136
|
+
if (indexBuffer) {
|
|
137
|
+
indexBuffer.bind();
|
|
138
|
+
}
|
|
139
|
+
if (dynamicVertexBuffer2) {
|
|
140
|
+
dynamicVertexBuffer2.bind();
|
|
141
|
+
dynamicVertexBuffer2.setVertexAttribPointers(gl, program, vertexOffset);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
context.currentNumAttributes = numNextAttributes;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
destroy() {
|
|
148
|
+
if (this.vao) {
|
|
149
|
+
this.context.extVertexArrayObject.deleteVertexArrayOES(this.vao);
|
|
150
|
+
this.vao = null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
module.exports = VertexArrayObject;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Mapbox GL Shaders
|
|
2
|
+
|
|
3
|
+
This repository contains GL shaders which are shared by [Mapbox GL JS](https://github.com/mapbox/mapbox-gl-js) and [Mapbox GL Native](https://github.com/mapbox/mapbox-gl-native).
|
|
4
|
+
|
|
5
|
+
## Pragmas
|
|
6
|
+
|
|
7
|
+
Some variables change type depending on their context:
|
|
8
|
+
|
|
9
|
+
- if the variable is the same for all features, we declare it as a `uniform`
|
|
10
|
+
- if the variable is different for each feature, we declare it as an `attribute` (in the vertex shader) and an accompanying `varying` (in both the vertex and fragment shaders).
|
|
11
|
+
- if the variable is different for each feature and a function of zoom, we declare several `attributes` and `uniforms` then calculate the value using interpolation
|
|
12
|
+
|
|
13
|
+
We abstract over this functionality using pragmas.
|
|
14
|
+
|
|
15
|
+
```glsl
|
|
16
|
+
#pragma mapbox: define highp vec4 color
|
|
17
|
+
|
|
18
|
+
main() {
|
|
19
|
+
#pragma mapbox: initialize highp vec4 color
|
|
20
|
+
...
|
|
21
|
+
gl_FragColor = color;
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
This program defines a variable within `main` called `color`, initialize the value of `color`, then sets `gl_FragColor` to the value of `color`.
|
|
26
|
+
|
|
27
|
+
Pragmas take the following form.
|
|
28
|
+
|
|
29
|
+
```glsl
|
|
30
|
+
#pragma mapbox: (define|initialize) (lowp|mediump|highp) (float|vec2|vec3|vec4) {name}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
When using pragmas, the following requirements apply.
|
|
34
|
+
|
|
35
|
+
- all pragma-defined variables must have both `define` and `initialize` pragmas
|
|
36
|
+
- `define` pragmas must be in file scope
|
|
37
|
+
- `initialize` pragmas must be in function scope
|
|
38
|
+
- all pragma-defined variables defined and initialized in the fragment shader must also be defined and initialized in the vertex shader because `attribute`s are not accessible from the fragment shader
|
|
39
|
+
|
|
40
|
+
## Util
|
|
41
|
+
|
|
42
|
+
The `util.glsl` file is automatically included in all shaders by the compiler.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#ifdef GL_ES
|
|
2
|
+
precision highp float;
|
|
3
|
+
#else
|
|
4
|
+
|
|
5
|
+
#if !defined(lowp)
|
|
6
|
+
#define lowp
|
|
7
|
+
#endif
|
|
8
|
+
|
|
9
|
+
#if !defined(mediump)
|
|
10
|
+
#define mediump
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
#if !defined(highp)
|
|
14
|
+
#define highp
|
|
15
|
+
#endif
|
|
16
|
+
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
// Unpack a pair of values that have been packed into a single float.
|
|
20
|
+
// The packed values are assumed to be 8-bit unsigned integers, and are
|
|
21
|
+
// packed like so:
|
|
22
|
+
// packedValue = floor(input[0]) * 256 + input[1],
|
|
23
|
+
vec2 unpack_float(const float packedValue) {
|
|
24
|
+
int packedIntValue = int(packedValue);
|
|
25
|
+
int v0 = packedIntValue / 256;
|
|
26
|
+
return vec2(v0, packedIntValue - v0 * 256);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
vec2 unpack_opacity(const float packedOpacity) {
|
|
30
|
+
int intOpacity = int(packedOpacity) / 2;
|
|
31
|
+
return vec2(float(intOpacity) / 127.0, mod(packedOpacity, 2.0));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// To minimize the number of attributes needed, we encode a 4-component
|
|
35
|
+
// color into a pair of floats (i.e. a vec2) as follows:
|
|
36
|
+
// [ floor(color.r * 255) * 256 + color.g * 255,
|
|
37
|
+
// floor(color.b * 255) * 256 + color.g * 255 ]
|
|
38
|
+
vec4 decode_color(const vec2 encodedColor) {
|
|
39
|
+
return vec4(
|
|
40
|
+
unpack_float(encodedColor[0]) / 255.0,
|
|
41
|
+
unpack_float(encodedColor[1]) / 255.0
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Unpack a pair of paint values and interpolate between them.
|
|
46
|
+
float unpack_mix_vec2(const vec2 packedValue, const float t) {
|
|
47
|
+
return mix(packedValue[0], packedValue[1], t);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Unpack a pair of paint values and interpolate between them.
|
|
51
|
+
vec4 unpack_mix_color(const vec4 packedColors, const float t) {
|
|
52
|
+
vec4 minColor = decode_color(vec2(packedColors[0], packedColors[1]));
|
|
53
|
+
vec4 maxColor = decode_color(vec2(packedColors[2], packedColors[3]));
|
|
54
|
+
return mix(minColor, maxColor, t);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// The offset depends on how many pixels are between the world origin and the edge of the tile:
|
|
58
|
+
// vec2 offset = mod(pixel_coord, size)
|
|
59
|
+
//
|
|
60
|
+
// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile.
|
|
61
|
+
// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that.
|
|
62
|
+
//
|
|
63
|
+
// The pixel_coord is passed in as two 16 bit values:
|
|
64
|
+
// pixel_coord_upper = floor(pixel_coord / 2^16)
|
|
65
|
+
// pixel_coord_lower = mod(pixel_coord, 2^16)
|
|
66
|
+
//
|
|
67
|
+
// The offset is calculated in a series of steps that should preserve this precision:
|
|
68
|
+
vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower,
|
|
69
|
+
const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) {
|
|
70
|
+
|
|
71
|
+
vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size);
|
|
72
|
+
return (tile_units_to_pixels * pos + offset) / pattern_size;
|
|
73
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
uniform vec2 u_pattern_tl_a;
|
|
2
|
+
uniform vec2 u_pattern_br_a;
|
|
3
|
+
uniform vec2 u_pattern_tl_b;
|
|
4
|
+
uniform vec2 u_pattern_br_b;
|
|
5
|
+
uniform vec2 u_texsize;
|
|
6
|
+
uniform float u_mix;
|
|
7
|
+
uniform float u_opacity;
|
|
8
|
+
|
|
9
|
+
uniform sampler2D u_image;
|
|
10
|
+
|
|
11
|
+
varying vec2 v_pos_a;
|
|
12
|
+
varying vec2 v_pos_b;
|
|
13
|
+
|
|
14
|
+
void main() {
|
|
15
|
+
vec2 imagecoord = mod(v_pos_a, 1.0);
|
|
16
|
+
vec2 pos = mix(u_pattern_tl_a / u_texsize, u_pattern_br_a / u_texsize, imagecoord);
|
|
17
|
+
vec4 color1 = texture2D(u_image, pos);
|
|
18
|
+
|
|
19
|
+
vec2 imagecoord_b = mod(v_pos_b, 1.0);
|
|
20
|
+
vec2 pos2 = mix(u_pattern_tl_b / u_texsize, u_pattern_br_b / u_texsize, imagecoord_b);
|
|
21
|
+
vec4 color2 = texture2D(u_image, pos2);
|
|
22
|
+
|
|
23
|
+
gl_FragColor = mix(color1, color2, u_mix) * u_opacity;
|
|
24
|
+
|
|
25
|
+
#ifdef OVERDRAW_INSPECTOR
|
|
26
|
+
gl_FragColor = vec4(1.0);
|
|
27
|
+
#endif
|
|
28
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
uniform mat4 u_matrix;
|
|
2
|
+
uniform vec2 u_pattern_size_a;
|
|
3
|
+
uniform vec2 u_pattern_size_b;
|
|
4
|
+
uniform vec2 u_pixel_coord_upper;
|
|
5
|
+
uniform vec2 u_pixel_coord_lower;
|
|
6
|
+
uniform float u_scale_a;
|
|
7
|
+
uniform float u_scale_b;
|
|
8
|
+
uniform float u_tile_units_to_pixels;
|
|
9
|
+
|
|
10
|
+
attribute vec2 a_pos;
|
|
11
|
+
|
|
12
|
+
varying vec2 v_pos_a;
|
|
13
|
+
varying vec2 v_pos_b;
|
|
14
|
+
|
|
15
|
+
void main() {
|
|
16
|
+
gl_Position = u_matrix * vec4(a_pos, 0, 1);
|
|
17
|
+
|
|
18
|
+
v_pos_a = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, u_scale_a * u_pattern_size_a, u_tile_units_to_pixels, a_pos);
|
|
19
|
+
v_pos_b = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, u_scale_b * u_pattern_size_b, u_tile_units_to_pixels, a_pos);
|
|
20
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#pragma mapbox: define highp vec4 color
|
|
2
|
+
#pragma mapbox: define mediump float radius
|
|
3
|
+
#pragma mapbox: define lowp float blur
|
|
4
|
+
#pragma mapbox: define lowp float opacity
|
|
5
|
+
#pragma mapbox: define highp vec4 stroke_color
|
|
6
|
+
#pragma mapbox: define mediump float stroke_width
|
|
7
|
+
#pragma mapbox: define lowp float stroke_opacity
|
|
8
|
+
|
|
9
|
+
varying vec3 v_data;
|
|
10
|
+
|
|
11
|
+
void main() {
|
|
12
|
+
#pragma mapbox: initialize highp vec4 color
|
|
13
|
+
#pragma mapbox: initialize mediump float radius
|
|
14
|
+
#pragma mapbox: initialize lowp float blur
|
|
15
|
+
#pragma mapbox: initialize lowp float opacity
|
|
16
|
+
#pragma mapbox: initialize highp vec4 stroke_color
|
|
17
|
+
#pragma mapbox: initialize mediump float stroke_width
|
|
18
|
+
#pragma mapbox: initialize lowp float stroke_opacity
|
|
19
|
+
|
|
20
|
+
vec2 extrude = v_data.xy;
|
|
21
|
+
float extrude_length = length(extrude);
|
|
22
|
+
|
|
23
|
+
lowp float antialiasblur = v_data.z;
|
|
24
|
+
float antialiased_blur = -max(blur, antialiasblur);
|
|
25
|
+
|
|
26
|
+
float opacity_t = smoothstep(0.0, antialiased_blur, extrude_length - 1.0);
|
|
27
|
+
|
|
28
|
+
float color_t = stroke_width < 0.01 ? 0.0 : smoothstep(
|
|
29
|
+
antialiased_blur,
|
|
30
|
+
0.0,
|
|
31
|
+
extrude_length - radius / (radius + stroke_width)
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
gl_FragColor = opacity_t * mix(color * opacity, stroke_color * stroke_opacity, color_t);
|
|
35
|
+
|
|
36
|
+
#ifdef OVERDRAW_INSPECTOR
|
|
37
|
+
gl_FragColor = vec4(1.0);
|
|
38
|
+
#endif
|
|
39
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
uniform mat4 u_matrix;
|
|
2
|
+
uniform bool u_scale_with_map;
|
|
3
|
+
uniform bool u_pitch_with_map;
|
|
4
|
+
uniform vec2 u_extrude_scale;
|
|
5
|
+
uniform highp float u_camera_to_center_distance;
|
|
6
|
+
|
|
7
|
+
attribute vec2 a_pos;
|
|
8
|
+
|
|
9
|
+
#pragma mapbox: define highp vec4 color
|
|
10
|
+
#pragma mapbox: define mediump float radius
|
|
11
|
+
#pragma mapbox: define lowp float blur
|
|
12
|
+
#pragma mapbox: define lowp float opacity
|
|
13
|
+
#pragma mapbox: define highp vec4 stroke_color
|
|
14
|
+
#pragma mapbox: define mediump float stroke_width
|
|
15
|
+
#pragma mapbox: define lowp float stroke_opacity
|
|
16
|
+
|
|
17
|
+
varying vec3 v_data;
|
|
18
|
+
|
|
19
|
+
void main(void) {
|
|
20
|
+
#pragma mapbox: initialize highp vec4 color
|
|
21
|
+
#pragma mapbox: initialize mediump float radius
|
|
22
|
+
#pragma mapbox: initialize lowp float blur
|
|
23
|
+
#pragma mapbox: initialize lowp float opacity
|
|
24
|
+
#pragma mapbox: initialize highp vec4 stroke_color
|
|
25
|
+
#pragma mapbox: initialize mediump float stroke_width
|
|
26
|
+
#pragma mapbox: initialize lowp float stroke_opacity
|
|
27
|
+
|
|
28
|
+
// unencode the extrusion vector that we snuck into the a_pos vector
|
|
29
|
+
vec2 extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0);
|
|
30
|
+
|
|
31
|
+
// multiply a_pos by 0.5, since we had it * 2 in order to sneak
|
|
32
|
+
// in extrusion data
|
|
33
|
+
vec2 circle_center = floor(a_pos * 0.5);
|
|
34
|
+
if (u_pitch_with_map) {
|
|
35
|
+
vec2 corner_position = circle_center;
|
|
36
|
+
if (u_scale_with_map) {
|
|
37
|
+
corner_position += extrude * (radius + stroke_width) * u_extrude_scale;
|
|
38
|
+
} else {
|
|
39
|
+
// Pitching the circle with the map effectively scales it with the map
|
|
40
|
+
// To counteract the effect for pitch-scale: viewport, we rescale the
|
|
41
|
+
// whole circle based on the pitch scaling effect at its central point
|
|
42
|
+
vec4 projected_center = u_matrix * vec4(circle_center, 0, 1);
|
|
43
|
+
corner_position += extrude * (radius + stroke_width) * u_extrude_scale * (projected_center.w / u_camera_to_center_distance);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
gl_Position = u_matrix * vec4(corner_position, 0, 1);
|
|
47
|
+
} else {
|
|
48
|
+
gl_Position = u_matrix * vec4(circle_center, 0, 1);
|
|
49
|
+
|
|
50
|
+
if (u_scale_with_map) {
|
|
51
|
+
gl_Position.xy += extrude * (radius + stroke_width) * u_extrude_scale * u_camera_to_center_distance;
|
|
52
|
+
} else {
|
|
53
|
+
gl_Position.xy += extrude * (radius + stroke_width) * u_extrude_scale * gl_Position.w;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// This is a minimum blur distance that serves as a faux-antialiasing for
|
|
58
|
+
// the circle. since blur is a ratio of the circle's size and the intent is
|
|
59
|
+
// to keep the blur at roughly 1px, the two are inversely related.
|
|
60
|
+
lowp float antialiasblur = 1.0 / DEVICE_PIXEL_RATIO / (radius + stroke_width);
|
|
61
|
+
|
|
62
|
+
v_data = vec3(extrude.x, extrude.y, antialiasblur);
|
|
63
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
varying float v_placed;
|
|
3
|
+
varying float v_notUsed;
|
|
4
|
+
|
|
5
|
+
void main() {
|
|
6
|
+
|
|
7
|
+
float alpha = 0.5;
|
|
8
|
+
|
|
9
|
+
// Red = collision, hide label
|
|
10
|
+
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0) * alpha;
|
|
11
|
+
|
|
12
|
+
// Blue = no collision, label is showing
|
|
13
|
+
if (v_placed > 0.5) {
|
|
14
|
+
gl_FragColor = vec4(0.0, 0.0, 1.0, 0.5) * alpha;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (v_notUsed > 0.5) {
|
|
18
|
+
// This box not used, fade it out
|
|
19
|
+
gl_FragColor *= .1;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
attribute vec2 a_pos;
|
|
2
|
+
attribute vec2 a_anchor_pos;
|
|
3
|
+
attribute vec2 a_extrude;
|
|
4
|
+
attribute vec2 a_placed;
|
|
5
|
+
|
|
6
|
+
uniform mat4 u_matrix;
|
|
7
|
+
uniform vec2 u_extrude_scale;
|
|
8
|
+
uniform float u_camera_to_center_distance;
|
|
9
|
+
|
|
10
|
+
varying float v_placed;
|
|
11
|
+
varying float v_notUsed;
|
|
12
|
+
|
|
13
|
+
void main() {
|
|
14
|
+
vec4 projectedPoint = u_matrix * vec4(a_anchor_pos, 0, 1);
|
|
15
|
+
highp float camera_to_anchor_distance = projectedPoint.w;
|
|
16
|
+
highp float collision_perspective_ratio = clamp(
|
|
17
|
+
0.5 + 0.5 * (u_camera_to_center_distance / camera_to_anchor_distance),
|
|
18
|
+
0.0, // Prevents oversized near-field boxes in pitched/overzoomed tiles
|
|
19
|
+
4.0);
|
|
20
|
+
|
|
21
|
+
gl_Position = u_matrix * vec4(a_pos, 0.0, 1.0);
|
|
22
|
+
gl_Position.xy += a_extrude * u_extrude_scale * gl_Position.w * collision_perspective_ratio;
|
|
23
|
+
|
|
24
|
+
v_placed = a_placed.x;
|
|
25
|
+
v_notUsed = a_placed.y;
|
|
26
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
uniform float u_overscale_factor;
|
|
2
|
+
|
|
3
|
+
varying float v_placed;
|
|
4
|
+
varying float v_notUsed;
|
|
5
|
+
varying float v_radius;
|
|
6
|
+
varying vec2 v_extrude;
|
|
7
|
+
varying vec2 v_extrude_scale;
|
|
8
|
+
|
|
9
|
+
void main() {
|
|
10
|
+
float alpha = 0.5;
|
|
11
|
+
|
|
12
|
+
// Red = collision, hide label
|
|
13
|
+
vec4 color = vec4(1.0, 0.0, 0.0, 1.0) * alpha;
|
|
14
|
+
|
|
15
|
+
// Blue = no collision, label is showing
|
|
16
|
+
if (v_placed > 0.5) {
|
|
17
|
+
color = vec4(0.0, 0.0, 1.0, 0.5) * alpha;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (v_notUsed > 0.5) {
|
|
21
|
+
// This box not used, fade it out
|
|
22
|
+
color *= .2;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
float extrude_scale_length = length(v_extrude_scale);
|
|
26
|
+
float extrude_length = length(v_extrude) * extrude_scale_length;
|
|
27
|
+
float stroke_width = 15.0 * extrude_scale_length / u_overscale_factor;
|
|
28
|
+
float radius = v_radius * extrude_scale_length;
|
|
29
|
+
|
|
30
|
+
float distance_to_edge = abs(extrude_length - radius);
|
|
31
|
+
float opacity_t = smoothstep(-stroke_width, 0.0, -distance_to_edge);
|
|
32
|
+
|
|
33
|
+
gl_FragColor = opacity_t * color;
|
|
34
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
attribute vec2 a_pos;
|
|
2
|
+
attribute vec2 a_anchor_pos;
|
|
3
|
+
attribute vec2 a_extrude;
|
|
4
|
+
attribute vec2 a_placed;
|
|
5
|
+
|
|
6
|
+
uniform mat4 u_matrix;
|
|
7
|
+
uniform vec2 u_extrude_scale;
|
|
8
|
+
uniform float u_camera_to_center_distance;
|
|
9
|
+
|
|
10
|
+
varying float v_placed;
|
|
11
|
+
varying float v_notUsed;
|
|
12
|
+
varying float v_radius;
|
|
13
|
+
|
|
14
|
+
varying vec2 v_extrude;
|
|
15
|
+
varying vec2 v_extrude_scale;
|
|
16
|
+
|
|
17
|
+
void main() {
|
|
18
|
+
vec4 projectedPoint = u_matrix * vec4(a_anchor_pos, 0, 1);
|
|
19
|
+
highp float camera_to_anchor_distance = projectedPoint.w;
|
|
20
|
+
highp float collision_perspective_ratio = clamp(
|
|
21
|
+
0.5 + 0.5 * (u_camera_to_center_distance / camera_to_anchor_distance),
|
|
22
|
+
0.0, // Prevents oversized near-field circles in pitched/overzoomed tiles
|
|
23
|
+
4.0);
|
|
24
|
+
|
|
25
|
+
gl_Position = u_matrix * vec4(a_pos, 0.0, 1.0);
|
|
26
|
+
|
|
27
|
+
highp float padding_factor = 1.2; // Pad the vertices slightly to make room for anti-alias blur
|
|
28
|
+
gl_Position.xy += a_extrude * u_extrude_scale * padding_factor * gl_Position.w * collision_perspective_ratio;
|
|
29
|
+
|
|
30
|
+
v_placed = a_placed.x;
|
|
31
|
+
v_notUsed = a_placed.y;
|
|
32
|
+
v_radius = abs(a_extrude.y); // We don't pitch the circles, so both units of the extrusion vector are equal in magnitude to the radius
|
|
33
|
+
|
|
34
|
+
v_extrude = a_extrude * padding_factor;
|
|
35
|
+
v_extrude_scale = u_extrude_scale * u_camera_to_center_distance * collision_perspective_ratio;
|
|
36
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const { clamp } = require('../util/util');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Packs two numbers, interpreted as 8-bit unsigned integers, into a single
|
|
5
|
+
* float. Unpack them in the shader using the `unpack_float()` function,
|
|
6
|
+
* defined in _prelude.vertex.glsl
|
|
7
|
+
*
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
10
|
+
function pack(a, b) {
|
|
11
|
+
// coerce a and b to 8-bit ints
|
|
12
|
+
a = clamp(Math.floor(a), 0, 255);
|
|
13
|
+
b = clamp(Math.floor(b), 0, 255);
|
|
14
|
+
return 256 * a + b;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
packUint8ToFloat: pack
|
|
19
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#pragma mapbox: define highp vec4 color
|
|
2
|
+
#pragma mapbox: define lowp float opacity
|
|
3
|
+
|
|
4
|
+
void main() {
|
|
5
|
+
#pragma mapbox: initialize highp vec4 color
|
|
6
|
+
#pragma mapbox: initialize lowp float opacity
|
|
7
|
+
|
|
8
|
+
gl_FragColor = color * opacity;
|
|
9
|
+
|
|
10
|
+
#ifdef OVERDRAW_INSPECTOR
|
|
11
|
+
gl_FragColor = vec4(1.0);
|
|
12
|
+
#endif
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
attribute vec2 a_pos;
|
|
2
|
+
|
|
3
|
+
uniform mat4 u_matrix;
|
|
4
|
+
|
|
5
|
+
#pragma mapbox: define highp vec4 color
|
|
6
|
+
#pragma mapbox: define lowp float opacity
|
|
7
|
+
|
|
8
|
+
void main() {
|
|
9
|
+
#pragma mapbox: initialize highp vec4 color
|
|
10
|
+
#pragma mapbox: initialize lowp float opacity
|
|
11
|
+
|
|
12
|
+
gl_Position = u_matrix * vec4(a_pos, 0, 1);
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
varying vec4 v_color;
|
|
2
|
+
#pragma mapbox: define lowp float base
|
|
3
|
+
#pragma mapbox: define lowp float height
|
|
4
|
+
#pragma mapbox: define highp vec4 color
|
|
5
|
+
|
|
6
|
+
void main() {
|
|
7
|
+
#pragma mapbox: initialize lowp float base
|
|
8
|
+
#pragma mapbox: initialize lowp float height
|
|
9
|
+
#pragma mapbox: initialize highp vec4 color
|
|
10
|
+
|
|
11
|
+
gl_FragColor = v_color;
|
|
12
|
+
|
|
13
|
+
#ifdef OVERDRAW_INSPECTOR
|
|
14
|
+
gl_FragColor = vec4(1.0);
|
|
15
|
+
#endif
|
|
16
|
+
}
|