@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,782 @@
|
|
|
1
|
+
const { packUint8ToFloat } = require('../shaders/encode_attribute');
|
|
2
|
+
const { supportsPropertyExpression } = require('../style-spec/util/properties');
|
|
3
|
+
const { register } = require('../util/web_worker_transfer');
|
|
4
|
+
const { PossiblyEvaluatedPropertyValue } = require('../style/properties');
|
|
5
|
+
const {
|
|
6
|
+
StructArrayLayout1f4,
|
|
7
|
+
StructArrayLayout2f8,
|
|
8
|
+
StructArrayLayout4f16,
|
|
9
|
+
PatternLayoutArray
|
|
10
|
+
} = require('./array_types');
|
|
11
|
+
const EvaluationParameters = require('../style/evaluation_parameters');
|
|
12
|
+
const { Uniform1f, UniformColor, Uniform4f } = require('../render/uniform_binding');
|
|
13
|
+
|
|
14
|
+
function packColor(color) {
|
|
15
|
+
return [packUint8ToFloat(255 * color.r, 255 * color.g), packUint8ToFloat(255 * color.b, 255 * color.a)];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* `Binder` is the interface definition for the strategies for constructing,
|
|
20
|
+
* uploading, and binding paint property data as GLSL attributes. Most style-
|
|
21
|
+
* spec properties have a 1:1 relationship to shader attribute/uniforms, but
|
|
22
|
+
* some require multliple values per feature to be passed to the GPU, and in
|
|
23
|
+
* those cases we bind multiple attributes/uniforms.
|
|
24
|
+
*
|
|
25
|
+
* It has three implementations, one for each of the three strategies we use:
|
|
26
|
+
*
|
|
27
|
+
* * For _constant_ properties -- those whose value is a constant, or the constant
|
|
28
|
+
* result of evaluating a camera expression at a particular camera position -- we
|
|
29
|
+
* don't need a vertex attribute buffer, and instead use a uniform.
|
|
30
|
+
* * For data expressions, we use a vertex buffer with a single attribute value,
|
|
31
|
+
* the evaluated result of the source function for the given feature.
|
|
32
|
+
* * For composite expressions, we use a vertex buffer with two attributes: min and
|
|
33
|
+
* max values covering the range of zooms at which we expect the tile to be
|
|
34
|
+
* displayed. These values are calculated by evaluating the composite expression for
|
|
35
|
+
* the given feature at strategically chosen zoom levels. In addition to this
|
|
36
|
+
* attribute data, we also use a uniform value which the shader uses to interpolate
|
|
37
|
+
* between the min and max value at the final displayed zoom level. The use of a
|
|
38
|
+
* uniform allows us to cheaply update the value on every frame.
|
|
39
|
+
*
|
|
40
|
+
* Note that the shader source varies depending on whether we're using a uniform or
|
|
41
|
+
* attribute. We dynamically compile shaders at runtime to accomodate this.
|
|
42
|
+
*
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
class ConstantBinder {
|
|
47
|
+
constructor(value, names, type) {
|
|
48
|
+
this.value = value;
|
|
49
|
+
this.names = names;
|
|
50
|
+
this.uniformNames = this.names.map(name => `u_${name}`);
|
|
51
|
+
this.type = type;
|
|
52
|
+
this.maxValue = Number.NEGATIVE_INFINITY;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
defines() {
|
|
56
|
+
return this.names.map(name => `#define HAS_UNIFORM_u_${name}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
setConstantPatternPositions() {}
|
|
60
|
+
populatePaintArray() {}
|
|
61
|
+
updatePaintArray() {}
|
|
62
|
+
upload() {}
|
|
63
|
+
destroy() {}
|
|
64
|
+
|
|
65
|
+
setUniforms(context, uniform, globals, currentValue) {
|
|
66
|
+
uniform.set(currentValue.constantOr(this.value));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
getBinding(context, location) {
|
|
70
|
+
return this.type === 'color' ? new UniformColor(context, location) : new Uniform1f(context, location);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
class CrossFadedConstantBinder {
|
|
75
|
+
constructor(value, names, type) {
|
|
76
|
+
this.value = value;
|
|
77
|
+
this.names = names;
|
|
78
|
+
this.uniformNames = this.names.map(name => `u_${name}`);
|
|
79
|
+
this.type = type;
|
|
80
|
+
this.maxValue = Number.NEGATIVE_INFINITY;
|
|
81
|
+
this.patternPositions = { patternTo: null, patternFrom: null };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
defines() {
|
|
85
|
+
return this.names.map(name => `#define HAS_UNIFORM_u_${name}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
populatePaintArray() {}
|
|
89
|
+
updatePaintArray() {}
|
|
90
|
+
upload() {}
|
|
91
|
+
destroy() {}
|
|
92
|
+
|
|
93
|
+
setConstantPatternPositions(posTo, posFrom) {
|
|
94
|
+
this.patternPositions.patternTo = posTo.tlbr;
|
|
95
|
+
this.patternPositions.patternFrom = posFrom.tlbr;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
setUniforms(context, uniform, globals, currentValue, uniformName) {
|
|
99
|
+
const pos = this.patternPositions;
|
|
100
|
+
if (uniformName === 'u_pattern_to' && pos.patternTo) uniform.set(pos.patternTo);
|
|
101
|
+
if (uniformName === 'u_pattern_from' && pos.patternFrom) uniform.set(pos.patternFrom);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
getBinding(context, location) {
|
|
105
|
+
return new Uniform4f(context, location);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
class SourceExpressionBinder {
|
|
110
|
+
constructor(expression, names, type, PaintVertexArray) {
|
|
111
|
+
this.expression = expression;
|
|
112
|
+
this.names = names;
|
|
113
|
+
this.type = type;
|
|
114
|
+
this.uniformNames = this.names.map(name => `a_${name}`);
|
|
115
|
+
this.maxValue = Number.NEGATIVE_INFINITY;
|
|
116
|
+
this.paintVertexAttributes = names.map(name => ({
|
|
117
|
+
name: `a_${name}`,
|
|
118
|
+
type: 'Float32',
|
|
119
|
+
components: type === 'color' ? 2 : 1,
|
|
120
|
+
offset: 0
|
|
121
|
+
}));
|
|
122
|
+
this.paintVertexArray = new PaintVertexArray();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
defines() {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
setConstantPatternPositions() {}
|
|
130
|
+
|
|
131
|
+
populatePaintArray(newLength, feature, imagePositions) {
|
|
132
|
+
const paintArray = this.paintVertexArray;
|
|
133
|
+
|
|
134
|
+
const start = paintArray.length;
|
|
135
|
+
paintArray.reserve(newLength);
|
|
136
|
+
|
|
137
|
+
const value = this.expression.evaluate(new EvaluationParameters(0), feature, {});
|
|
138
|
+
|
|
139
|
+
if (this.type === 'color') {
|
|
140
|
+
const color = packColor(value);
|
|
141
|
+
for (let i = start; i < newLength; i++) {
|
|
142
|
+
paintArray.emplaceBack(color[0], color[1]);
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
for (let i = start; i < newLength; i++) {
|
|
146
|
+
paintArray.emplaceBack(value);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
this.maxValue = Math.max(this.maxValue, value);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
updatePaintArray(start, end, feature, featureState, imagePositions) {
|
|
154
|
+
const paintArray = this.paintVertexArray;
|
|
155
|
+
const value = this.expression.evaluate({ zoom: 0 }, feature, featureState);
|
|
156
|
+
|
|
157
|
+
if (this.type === 'color') {
|
|
158
|
+
const color = packColor(value);
|
|
159
|
+
for (let i = start; i < end; i++) {
|
|
160
|
+
paintArray.emplace(i, color[0], color[1]);
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
for (let i = start; i < end; i++) {
|
|
164
|
+
paintArray.emplace(i, value);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
this.maxValue = Math.max(this.maxValue, value);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
upload(context) {
|
|
172
|
+
if (this.paintVertexArray?.arrayBuffer) {
|
|
173
|
+
this.paintVertexBuffer = context.createVertexBuffer(
|
|
174
|
+
this.paintVertexArray,
|
|
175
|
+
this.paintVertexAttributes,
|
|
176
|
+
this.expression.isStateDependent
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
destroy() {
|
|
182
|
+
if (this.paintVertexBuffer) {
|
|
183
|
+
this.paintVertexBuffer.destroy();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
setUniforms(context, uniform) {
|
|
188
|
+
uniform.set(0);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
getBinding(context, location) {
|
|
192
|
+
return new Uniform1f(context, location);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
class CompositeExpressionBinder {
|
|
197
|
+
constructor(expression, names, type, useIntegerZoom, zoom, layout) {
|
|
198
|
+
this.expression = expression;
|
|
199
|
+
this.names = names;
|
|
200
|
+
this.uniformNames = this.names.map(name => `a_${name}_t`);
|
|
201
|
+
this.type = type;
|
|
202
|
+
this.useIntegerZoom = useIntegerZoom;
|
|
203
|
+
this.zoom = zoom;
|
|
204
|
+
this.maxValue = Number.NEGATIVE_INFINITY;
|
|
205
|
+
const PaintVertexArray = layout;
|
|
206
|
+
this.paintVertexAttributes = names.map(name => {
|
|
207
|
+
return {
|
|
208
|
+
name: `a_${name}`,
|
|
209
|
+
type: 'Float32',
|
|
210
|
+
components: type === 'color' ? 4 : 2,
|
|
211
|
+
offset: 0
|
|
212
|
+
};
|
|
213
|
+
});
|
|
214
|
+
this.paintVertexArray = new PaintVertexArray();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
defines() {
|
|
218
|
+
return [];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
setConstantPatternPositions() {}
|
|
222
|
+
|
|
223
|
+
populatePaintArray(newLength, feature) {
|
|
224
|
+
const paintArray = this.paintVertexArray;
|
|
225
|
+
|
|
226
|
+
const start = paintArray.length;
|
|
227
|
+
paintArray.reserve(newLength);
|
|
228
|
+
|
|
229
|
+
const min = this.expression.evaluate(new EvaluationParameters(this.zoom), feature, {});
|
|
230
|
+
const max = this.expression.evaluate(new EvaluationParameters(this.zoom + 1), feature, {});
|
|
231
|
+
|
|
232
|
+
if (this.type === 'color') {
|
|
233
|
+
const minColor = packColor(min);
|
|
234
|
+
const maxColor = packColor(max);
|
|
235
|
+
for (let i = start; i < newLength; i++) {
|
|
236
|
+
paintArray.emplaceBack(minColor[0], minColor[1], maxColor[0], maxColor[1]);
|
|
237
|
+
}
|
|
238
|
+
} else {
|
|
239
|
+
for (let i = start; i < newLength; i++) {
|
|
240
|
+
paintArray.emplaceBack(min, max);
|
|
241
|
+
}
|
|
242
|
+
this.maxValue = Math.max(this.maxValue, min, max);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
updatePaintArray(start, end, feature, featureState) {
|
|
247
|
+
const paintArray = this.paintVertexArray;
|
|
248
|
+
|
|
249
|
+
const min = this.expression.evaluate({ zoom: this.zoom }, feature, featureState);
|
|
250
|
+
const max = this.expression.evaluate({ zoom: this.zoom + 1 }, feature, featureState);
|
|
251
|
+
|
|
252
|
+
if (this.type === 'color') {
|
|
253
|
+
const minColor = packColor(min);
|
|
254
|
+
const maxColor = packColor(max);
|
|
255
|
+
for (let i = start; i < end; i++) {
|
|
256
|
+
paintArray.emplace(i, minColor[0], minColor[1], maxColor[0], maxColor[1]);
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
for (let i = start; i < end; i++) {
|
|
260
|
+
paintArray.emplace(i, min, max);
|
|
261
|
+
}
|
|
262
|
+
this.maxValue = Math.max(this.maxValue, min, max);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
upload(context) {
|
|
267
|
+
if (this.paintVertexArray?.arrayBuffer) {
|
|
268
|
+
this.paintVertexBuffer = context.createVertexBuffer(
|
|
269
|
+
this.paintVertexArray,
|
|
270
|
+
this.paintVertexAttributes,
|
|
271
|
+
this.expression.isStateDependent
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
destroy() {
|
|
277
|
+
if (this.paintVertexBuffer) {
|
|
278
|
+
this.paintVertexBuffer.destroy();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
interpolationFactor(currentZoom) {
|
|
283
|
+
if (this.useIntegerZoom) {
|
|
284
|
+
return this.expression.interpolationFactor(Math.floor(currentZoom), this.zoom, this.zoom + 1);
|
|
285
|
+
}
|
|
286
|
+
return this.expression.interpolationFactor(currentZoom, this.zoom, this.zoom + 1);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
setUniforms(context, uniform, globals) {
|
|
290
|
+
uniform.set(this.interpolationFactor(globals.zoom));
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
getBinding(context, location) {
|
|
294
|
+
return new Uniform1f(context, location);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
class CrossFadedCompositeBinder {
|
|
299
|
+
constructor(expression, names, type, useIntegerZoom, zoom, PaintVertexArray, layerId) {
|
|
300
|
+
this.expression = expression;
|
|
301
|
+
this.names = names;
|
|
302
|
+
this.type = type;
|
|
303
|
+
this.uniformNames = this.names.map(name => `a_${name}_t`);
|
|
304
|
+
this.useIntegerZoom = useIntegerZoom;
|
|
305
|
+
this.zoom = zoom;
|
|
306
|
+
this.maxValue = Number.NEGATIVE_INFINITY;
|
|
307
|
+
this.layerId = layerId;
|
|
308
|
+
|
|
309
|
+
this.paintVertexAttributes = names.map(name => ({
|
|
310
|
+
name: `a_${name}`,
|
|
311
|
+
type: 'Uint16',
|
|
312
|
+
components: 4,
|
|
313
|
+
offset: 0
|
|
314
|
+
}));
|
|
315
|
+
|
|
316
|
+
this.zoomInPaintVertexArray = new PaintVertexArray();
|
|
317
|
+
this.zoomOutPaintVertexArray = new PaintVertexArray();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
defines() {
|
|
321
|
+
return [];
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
setConstantPatternPositions() {}
|
|
325
|
+
|
|
326
|
+
populatePaintArray(length, feature, imagePositions) {
|
|
327
|
+
// We populate two paint arrays because, for cross-faded properties, we don't know which direction
|
|
328
|
+
// we're cross-fading to at layout time. In order to keep vertex attributes to a minimum and not pass
|
|
329
|
+
// unnecessary vertex data to the shaders, we determine which to upload at draw time.
|
|
330
|
+
|
|
331
|
+
const zoomInArray = this.zoomInPaintVertexArray;
|
|
332
|
+
const zoomOutArray = this.zoomOutPaintVertexArray;
|
|
333
|
+
const { layerId } = this;
|
|
334
|
+
const start = zoomInArray.length;
|
|
335
|
+
|
|
336
|
+
zoomInArray.reserve(length);
|
|
337
|
+
zoomOutArray.reserve(length);
|
|
338
|
+
|
|
339
|
+
if (imagePositions && feature.patterns && feature.patterns[layerId]) {
|
|
340
|
+
const { min, mid, max } = feature.patterns[layerId];
|
|
341
|
+
|
|
342
|
+
const imageMin = imagePositions[min];
|
|
343
|
+
const imageMid = imagePositions[mid];
|
|
344
|
+
const imageMax = imagePositions[max];
|
|
345
|
+
|
|
346
|
+
if (!imageMin || !imageMid || !imageMax) return;
|
|
347
|
+
|
|
348
|
+
for (let i = start; i < length; i++) {
|
|
349
|
+
zoomInArray.emplaceBack(
|
|
350
|
+
imageMid.tl[0],
|
|
351
|
+
imageMid.tl[1],
|
|
352
|
+
imageMid.br[0],
|
|
353
|
+
imageMid.br[1],
|
|
354
|
+
imageMin.tl[0],
|
|
355
|
+
imageMin.tl[1],
|
|
356
|
+
imageMin.br[0],
|
|
357
|
+
imageMin.br[1]
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
zoomOutArray.emplaceBack(
|
|
361
|
+
imageMid.tl[0],
|
|
362
|
+
imageMid.tl[1],
|
|
363
|
+
imageMid.br[0],
|
|
364
|
+
imageMid.br[1],
|
|
365
|
+
imageMax.tl[0],
|
|
366
|
+
imageMax.tl[1],
|
|
367
|
+
imageMax.br[0],
|
|
368
|
+
imageMax.br[1]
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
updatePaintArray(start, end, feature, featureState, imagePositions) {
|
|
375
|
+
// We populate two paint arrays because, for cross-faded properties, we don't know which direction
|
|
376
|
+
// we're cross-fading to at layout time. In order to keep vertex attributes to a minimum and not pass
|
|
377
|
+
// unnecessary vertex data to the shaders, we determine which to upload at draw time.
|
|
378
|
+
|
|
379
|
+
const zoomInArray = this.zoomInPaintVertexArray;
|
|
380
|
+
const zoomOutArray = this.zoomOutPaintVertexArray;
|
|
381
|
+
const { layerId } = this;
|
|
382
|
+
|
|
383
|
+
if (imagePositions && feature.patterns && feature.patterns[layerId]) {
|
|
384
|
+
const { min, mid, max } = feature.patterns[layerId];
|
|
385
|
+
const imageMin = imagePositions[min];
|
|
386
|
+
const imageMid = imagePositions[mid];
|
|
387
|
+
const imageMax = imagePositions[max];
|
|
388
|
+
|
|
389
|
+
if (!imageMin || !imageMid || !imageMax) return;
|
|
390
|
+
for (let i = start; i < end; i++) {
|
|
391
|
+
zoomInArray.emplace(
|
|
392
|
+
i,
|
|
393
|
+
imageMid.tl[0],
|
|
394
|
+
imageMid.tl[1],
|
|
395
|
+
imageMid.br[0],
|
|
396
|
+
imageMid.br[1],
|
|
397
|
+
imageMin.tl[0],
|
|
398
|
+
imageMin.tl[1],
|
|
399
|
+
imageMin.br[0],
|
|
400
|
+
imageMin.br[1]
|
|
401
|
+
);
|
|
402
|
+
|
|
403
|
+
zoomOutArray.emplace(
|
|
404
|
+
i,
|
|
405
|
+
imageMid.tl[0],
|
|
406
|
+
imageMid.tl[1],
|
|
407
|
+
imageMid.br[0],
|
|
408
|
+
imageMid.br[1],
|
|
409
|
+
imageMax.tl[0],
|
|
410
|
+
imageMax.tl[1],
|
|
411
|
+
imageMax.br[0],
|
|
412
|
+
imageMax.br[1]
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
upload(context) {
|
|
419
|
+
if (this.zoomInPaintVertexArray?.arrayBuffer && this.zoomOutPaintVertexArray?.arrayBuffer) {
|
|
420
|
+
this.zoomInPaintVertexBuffer = context.createVertexBuffer(
|
|
421
|
+
this.zoomInPaintVertexArray,
|
|
422
|
+
this.paintVertexAttributes,
|
|
423
|
+
this.expression.isStateDependent
|
|
424
|
+
);
|
|
425
|
+
this.zoomOutPaintVertexBuffer = context.createVertexBuffer(
|
|
426
|
+
this.zoomOutPaintVertexArray,
|
|
427
|
+
this.paintVertexAttributes,
|
|
428
|
+
this.expression.isStateDependent
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
destroy() {
|
|
434
|
+
if (this.zoomOutPaintVertexBuffer) this.zoomOutPaintVertexBuffer.destroy();
|
|
435
|
+
if (this.zoomInPaintVertexBuffer) this.zoomInPaintVertexBuffer.destroy();
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
setUniforms(context, uniform) {
|
|
439
|
+
uniform.set(0);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
getBinding(context, location) {
|
|
443
|
+
return new Uniform1f(context, location);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* ProgramConfiguration contains the logic for binding style layer properties and tile
|
|
449
|
+
* layer feature data into GL program uniforms and vertex attributes.
|
|
450
|
+
*
|
|
451
|
+
* Non-data-driven property values are bound to shader uniforms. Data-driven property
|
|
452
|
+
* values are bound to vertex attributes. In order to support a uniform GLSL syntax over
|
|
453
|
+
* both, [Mapbox GL Shaders](https://github.com/mapbox/mapbox-gl-shaders) defines a `#pragma`
|
|
454
|
+
* abstraction, which ProgramConfiguration is responsible for implementing. At runtime,
|
|
455
|
+
* it examines the attributes of a particular layer, combines this with fixed knowledge
|
|
456
|
+
* about how layers of the particular type are implemented, and determines which uniforms
|
|
457
|
+
* and vertex attributes will be required. It can then substitute the appropriate text
|
|
458
|
+
* into the shader source code, create and link a program, and bind the uniforms and
|
|
459
|
+
* vertex attributes in preparation for drawing.
|
|
460
|
+
*
|
|
461
|
+
* When a vector tile is parsed, this same configuration information is used to
|
|
462
|
+
* populate the attribute buffers needed for data-driven styling using the zoom
|
|
463
|
+
* level and feature property data.
|
|
464
|
+
*
|
|
465
|
+
* @private
|
|
466
|
+
*/
|
|
467
|
+
class ProgramConfiguration {
|
|
468
|
+
constructor() {
|
|
469
|
+
this.binders = {};
|
|
470
|
+
this.cacheKey = '';
|
|
471
|
+
|
|
472
|
+
this._buffers = [];
|
|
473
|
+
this._idMap = {};
|
|
474
|
+
this._bufferOffset = 0;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
static createDynamic(layer, zoom, filterProperties) {
|
|
478
|
+
const self = new ProgramConfiguration();
|
|
479
|
+
const keys = [];
|
|
480
|
+
|
|
481
|
+
for (const property in layer.paint._values) {
|
|
482
|
+
if (!filterProperties(property)) continue;
|
|
483
|
+
const value = layer.paint.get(property);
|
|
484
|
+
if (
|
|
485
|
+
!(value instanceof PossiblyEvaluatedPropertyValue) ||
|
|
486
|
+
!supportsPropertyExpression(value.property.specification)
|
|
487
|
+
) {
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
const names = paintAttributeNames(property, layer.type);
|
|
491
|
+
const type = value.property.specification.type;
|
|
492
|
+
const useIntegerZoom = value.property.useIntegerZoom;
|
|
493
|
+
|
|
494
|
+
const isCrossFaded =
|
|
495
|
+
value.property.specification['property-type'] === 'cross-faded' ||
|
|
496
|
+
value.property.specification['property-type'] === 'cross-faded-data-driven';
|
|
497
|
+
|
|
498
|
+
if (isCrossFaded) {
|
|
499
|
+
if (value.value.kind === 'constant') {
|
|
500
|
+
self.binders[property] = new CrossFadedConstantBinder(value.value.value, names, type);
|
|
501
|
+
keys.push(`/u_${property}`);
|
|
502
|
+
} else {
|
|
503
|
+
const StructArrayLayout = layoutType(property, type, 'source');
|
|
504
|
+
self.binders[property] = new CrossFadedCompositeBinder(
|
|
505
|
+
value.value,
|
|
506
|
+
names,
|
|
507
|
+
type,
|
|
508
|
+
useIntegerZoom,
|
|
509
|
+
zoom,
|
|
510
|
+
StructArrayLayout,
|
|
511
|
+
layer.id
|
|
512
|
+
);
|
|
513
|
+
keys.push(`/a_${property}`);
|
|
514
|
+
}
|
|
515
|
+
} else if (value.value.kind === 'constant') {
|
|
516
|
+
self.binders[property] = new ConstantBinder(value.value.value, names, type);
|
|
517
|
+
keys.push(`/u_${property}`);
|
|
518
|
+
} else if (value.value.kind === 'source') {
|
|
519
|
+
const StructArrayLayout = layoutType(property, type, 'source');
|
|
520
|
+
self.binders[property] = new SourceExpressionBinder(value.value, names, type, StructArrayLayout);
|
|
521
|
+
keys.push(`/a_${property}`);
|
|
522
|
+
} else {
|
|
523
|
+
const StructArrayLayout = layoutType(property, type, 'composite');
|
|
524
|
+
self.binders[property] = new CompositeExpressionBinder(
|
|
525
|
+
value.value,
|
|
526
|
+
names,
|
|
527
|
+
type,
|
|
528
|
+
useIntegerZoom,
|
|
529
|
+
zoom,
|
|
530
|
+
StructArrayLayout
|
|
531
|
+
);
|
|
532
|
+
keys.push(`/z_${property}`);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
self.cacheKey = keys.sort().join('');
|
|
537
|
+
|
|
538
|
+
return self;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
populatePaintArrays(newLength, feature, index, imagePositions) {
|
|
542
|
+
for (const property in this.binders) {
|
|
543
|
+
const binder = this.binders[property];
|
|
544
|
+
binder.populatePaintArray(newLength, feature, imagePositions);
|
|
545
|
+
}
|
|
546
|
+
if (feature.id) {
|
|
547
|
+
const featureId = String(feature.id);
|
|
548
|
+
this._idMap[featureId] = this._idMap[featureId] || [];
|
|
549
|
+
this._idMap[featureId].push({
|
|
550
|
+
index: index,
|
|
551
|
+
start: this._bufferOffset,
|
|
552
|
+
end: newLength
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
this._bufferOffset = newLength;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
setConstantPatternPositions(posTo, posFrom) {
|
|
560
|
+
for (const property in this.binders) {
|
|
561
|
+
const binder = this.binders[property];
|
|
562
|
+
binder.setConstantPatternPositions(posTo, posFrom);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
updatePaintArrays(featureStates, vtLayer, layer, imagePositions) {
|
|
567
|
+
let dirty = false;
|
|
568
|
+
for (const id in featureStates) {
|
|
569
|
+
const posArray = this._idMap[id];
|
|
570
|
+
if (!posArray) continue;
|
|
571
|
+
|
|
572
|
+
const featureState = featureStates[id];
|
|
573
|
+
for (const pos of posArray) {
|
|
574
|
+
const feature = vtLayer.feature(pos.index);
|
|
575
|
+
|
|
576
|
+
for (const property in this.binders) {
|
|
577
|
+
const binder = this.binders[property];
|
|
578
|
+
if (binder instanceof ConstantBinder || binder instanceof CrossFadedConstantBinder) continue;
|
|
579
|
+
if (binder.expression.isStateDependent === true) {
|
|
580
|
+
//AHM: Remove after https://github.com/mapbox/mapbox-gl-js/issues/6255
|
|
581
|
+
const value = layer.paint.get(property);
|
|
582
|
+
binder.expression = value.value;
|
|
583
|
+
binder.updatePaintArray(pos.start, pos.end, feature, featureState, imagePositions);
|
|
584
|
+
dirty = true;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
return dirty;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
defines() {
|
|
593
|
+
const result = [];
|
|
594
|
+
for (const property in this.binders) {
|
|
595
|
+
result.push.apply(result, this.binders[property].defines());
|
|
596
|
+
}
|
|
597
|
+
return result;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
getPaintVertexBuffers() {
|
|
601
|
+
return this._buffers;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
getUniforms(context, locations) {
|
|
605
|
+
const result = {};
|
|
606
|
+
for (const property in this.binders) {
|
|
607
|
+
const binder = this.binders[property];
|
|
608
|
+
for (const name of binder.uniformNames) {
|
|
609
|
+
result[name] = binder.getBinding(context, locations[name]);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
return result;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
setUniforms(context, uniformBindings, properties, globals) {
|
|
616
|
+
// Uniform state bindings are owned by the Program, but we set them
|
|
617
|
+
// from within the ProgramConfiguraton's binder members.
|
|
618
|
+
|
|
619
|
+
for (const property in this.binders) {
|
|
620
|
+
const binder = this.binders[property];
|
|
621
|
+
for (const uniformName of binder.uniformNames) {
|
|
622
|
+
binder.setUniforms(context, uniformBindings[uniformName], globals, properties.get(property), uniformName);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
updatePatternPaintBuffers(crossfade) {
|
|
628
|
+
const buffers = [];
|
|
629
|
+
|
|
630
|
+
for (const property in this.binders) {
|
|
631
|
+
const binder = this.binders[property];
|
|
632
|
+
if (binder instanceof CrossFadedCompositeBinder) {
|
|
633
|
+
const patternVertexBuffer =
|
|
634
|
+
crossfade.fromScale === 2 ? binder.zoomInPaintVertexBuffer : binder.zoomOutPaintVertexBuffer;
|
|
635
|
+
if (patternVertexBuffer) buffers.push(patternVertexBuffer);
|
|
636
|
+
} else if (
|
|
637
|
+
(binder instanceof SourceExpressionBinder || binder instanceof CompositeExpressionBinder) &&
|
|
638
|
+
binder.paintVertexBuffer
|
|
639
|
+
) {
|
|
640
|
+
buffers.push(binder.paintVertexBuffer);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
this._buffers = buffers;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
upload(context) {
|
|
648
|
+
for (const property in this.binders) {
|
|
649
|
+
this.binders[property].upload(context);
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
const buffers = [];
|
|
653
|
+
for (const property in this.binders) {
|
|
654
|
+
const binder = this.binders[property];
|
|
655
|
+
if (
|
|
656
|
+
(binder instanceof SourceExpressionBinder || binder instanceof CompositeExpressionBinder) &&
|
|
657
|
+
binder.paintVertexBuffer
|
|
658
|
+
) {
|
|
659
|
+
buffers.push(binder.paintVertexBuffer);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
this._buffers = buffers;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
destroy() {
|
|
666
|
+
for (const property in this.binders) {
|
|
667
|
+
this.binders[property].destroy();
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
class ProgramConfigurationSet {
|
|
673
|
+
constructor(layoutAttributes, layers, zoom, filterProperties = () => true) {
|
|
674
|
+
this.programConfigurations = {};
|
|
675
|
+
for (const layer of layers) {
|
|
676
|
+
this.programConfigurations[layer.id] = ProgramConfiguration.createDynamic(layer, zoom, filterProperties);
|
|
677
|
+
this.programConfigurations[layer.id].layoutAttributes = layoutAttributes;
|
|
678
|
+
}
|
|
679
|
+
this.needsUpload = false;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
populatePaintArrays(length, feature, index, imagePositions) {
|
|
683
|
+
for (const key in this.programConfigurations) {
|
|
684
|
+
this.programConfigurations[key].populatePaintArrays(length, feature, index, imagePositions);
|
|
685
|
+
}
|
|
686
|
+
this.needsUpload = true;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
updatePaintArrays(featureStates, vtLayer, layers, imagePositions) {
|
|
690
|
+
for (const layer of layers) {
|
|
691
|
+
this.needsUpload =
|
|
692
|
+
this.programConfigurations[layer.id].updatePaintArrays(featureStates, vtLayer, layer, imagePositions) ||
|
|
693
|
+
this.needsUpload;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
get(layerId) {
|
|
698
|
+
return this.programConfigurations[layerId];
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
upload(context) {
|
|
702
|
+
if (!this.needsUpload) return;
|
|
703
|
+
for (const layerId in this.programConfigurations) {
|
|
704
|
+
this.programConfigurations[layerId].upload(context);
|
|
705
|
+
}
|
|
706
|
+
this.needsUpload = false;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
destroy() {
|
|
710
|
+
for (const layerId in this.programConfigurations) {
|
|
711
|
+
this.programConfigurations[layerId].destroy();
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
// paint property arrays
|
|
717
|
+
function paintAttributeNames(property, type) {
|
|
718
|
+
const attributeNameExceptions = {
|
|
719
|
+
'text-opacity': ['opacity'],
|
|
720
|
+
'icon-opacity': ['opacity'],
|
|
721
|
+
'text-color': ['fill_color'],
|
|
722
|
+
'icon-color': ['fill_color'],
|
|
723
|
+
'text-halo-color': ['halo_color'],
|
|
724
|
+
'icon-halo-color': ['halo_color'],
|
|
725
|
+
'text-halo-blur': ['halo_blur'],
|
|
726
|
+
'icon-halo-blur': ['halo_blur'],
|
|
727
|
+
'text-halo-width': ['halo_width'],
|
|
728
|
+
'icon-halo-width': ['halo_width'],
|
|
729
|
+
'line-gap-width': ['gapwidth'],
|
|
730
|
+
'line-pattern': ['pattern_to', 'pattern_from'],
|
|
731
|
+
'fill-pattern': ['pattern_to', 'pattern_from'],
|
|
732
|
+
'fill-extrusion-pattern': ['pattern_to', 'pattern_from']
|
|
733
|
+
};
|
|
734
|
+
return attributeNameExceptions[property] || [property.replace(`${type}-`, '').replace(/-/g, '_')];
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
function getLayoutException(property) {
|
|
738
|
+
const propertyExceptions = {
|
|
739
|
+
'line-pattern': {
|
|
740
|
+
source: PatternLayoutArray,
|
|
741
|
+
composite: PatternLayoutArray
|
|
742
|
+
},
|
|
743
|
+
'fill-pattern': {
|
|
744
|
+
source: PatternLayoutArray,
|
|
745
|
+
composite: PatternLayoutArray
|
|
746
|
+
},
|
|
747
|
+
'fill-extrusion-pattern': {
|
|
748
|
+
source: PatternLayoutArray,
|
|
749
|
+
composite: PatternLayoutArray
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
return propertyExceptions[property];
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
function layoutType(property, type, binderType) {
|
|
757
|
+
const defaultLayouts = {
|
|
758
|
+
color: {
|
|
759
|
+
source: StructArrayLayout2f8,
|
|
760
|
+
composite: StructArrayLayout4f16
|
|
761
|
+
},
|
|
762
|
+
number: {
|
|
763
|
+
source: StructArrayLayout1f4,
|
|
764
|
+
composite: StructArrayLayout2f8
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
|
|
768
|
+
const layoutException = getLayoutException(property);
|
|
769
|
+
return layoutException?.[binderType] || defaultLayouts[type][binderType];
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
register('ConstantBinder', ConstantBinder);
|
|
773
|
+
register('CrossFadedConstantBinder', CrossFadedConstantBinder);
|
|
774
|
+
register('SourceExpressionBinder', SourceExpressionBinder);
|
|
775
|
+
register('CrossFadedCompositeBinder', CrossFadedCompositeBinder);
|
|
776
|
+
register('CompositeExpressionBinder', CompositeExpressionBinder);
|
|
777
|
+
register('ProgramConfiguration', ProgramConfiguration, { omit: ['_buffers'] });
|
|
778
|
+
register('ProgramConfigurationSet', ProgramConfigurationSet);
|
|
779
|
+
|
|
780
|
+
ProgramConfiguration.ProgramConfigurationSet = ProgramConfigurationSet;
|
|
781
|
+
|
|
782
|
+
module.exports = ProgramConfiguration;
|