@tangram.gl/tangram-renderer 0.0.0-stage → 0.0.0
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/README.md +59 -2
- package/dist/core.js +36923 -0
- package/dist/core.js.map +6 -0
- package/dist/index.js +32 -0
- package/dist/loaders-gl-worker.js +82 -0
- package/dist/loaders-gl-worker.js.map +6 -0
- package/dist/map-logic.js +2 -0
- package/dist/map-logic.js.map +6 -0
- package/dist/projected-basemaps-worker.js +3 -0
- package/dist/projected-basemaps-worker.js.map +6 -0
- package/dist/shader-modules.js +141 -0
- package/dist/shader-modules.js.map +6 -0
- package/dist/style-schema.js +126 -0
- package/dist/style-schema.js.map +6 -0
- package/dist/tangram-style.schema.json +882 -0
- package/dist/tangram.debug.mjs +37139 -0
- package/dist/tangram.debug.mjs.map +6 -0
- package/dist/tangram.min.mjs +4950 -0
- package/dist/types/builders/earcut.d.ts +15 -0
- package/dist/types/core.d.ts +29 -0
- package/dist/types/gl/constants.d.ts +2 -0
- package/dist/types/gl/globe_mesh.d.ts +48 -0
- package/dist/types/gl/glsl.d.ts +17 -0
- package/dist/types/gl/vertex-constants.d.ts +4 -0
- package/dist/types/gl/vertex-types.d.ts +34 -0
- package/dist/types/gl/vertex_data.d.ts +32 -0
- package/dist/types/gl/vertex_elements.d.ts +8 -0
- package/dist/types/gl/vertex_layout.d.ts +32 -0
- package/dist/types/glsl.d.ts +14 -0
- package/dist/types/gpu/luma_device_renderer.d.ts +66 -0
- package/dist/types/gpu/resource_lifecycle.d.ts +4 -0
- package/dist/types/gpu/tangram_gpu_backend.d.ts +151 -0
- package/dist/types/index.d.ts +155 -0
- package/dist/types/lights/light-definitions.d.ts +121 -0
- package/dist/types/map-logic/draped-terrain-bounds.d.ts +41 -0
- package/dist/types/map-logic/globe-terrain-preparation.d.ts +85 -0
- package/dist/types/map-logic/globe-terrain.d.ts +54 -0
- package/dist/types/map-logic/index.d.ts +33 -0
- package/dist/types/map-logic/label-identity.d.ts +22 -0
- package/dist/types/map-logic/label-placement.d.ts +32 -0
- package/dist/types/map-logic/screen-bounds.d.ts +15 -0
- package/dist/types/map-logic/terrain-data.d.ts +55 -0
- package/dist/types/map-logic/terrain-error.d.ts +51 -0
- package/dist/types/map-logic/terrain-ground-topology.d.ts +26 -0
- package/dist/types/map-logic/terrain-height-field.d.ts +59 -0
- package/dist/types/map-logic/terrain-navigation.d.ts +27 -0
- package/dist/types/map-logic/terrain-neighborhood.d.ts +5 -0
- package/dist/types/map-logic/terrain-query.d.ts +33 -0
- package/dist/types/map-logic/terrain-resource-budget.d.ts +51 -0
- package/dist/types/map-logic/terrain-transition-topology.d.ts +23 -0
- package/dist/types/map-logic/tile-build-queue.d.ts +51 -0
- package/dist/types/map-logic/tile-cache-policy.d.ts +46 -0
- package/dist/types/map-logic/tile-residency.d.ts +17 -0
- package/dist/types/map-logic/triangle-query-index.d.ts +87 -0
- package/dist/types/procedures/js-yaml.d.ts +15 -0
- package/dist/types/procedures/mesh-projector.d.ts +107 -0
- package/dist/types/procedures/mvt-dependencies.d.ts +20 -0
- package/dist/types/procedures/projected-coordinate-transform.d.ts +27 -0
- package/dist/types/procedures/projection-batch-executor.d.ts +53 -0
- package/dist/types/procedures/scene-yaml-legacy.d.ts +6 -0
- package/dist/types/procedures/terrain-draping.d.ts +165 -0
- package/dist/types/procedures/terrain-globe.d.ts +6 -0
- package/dist/types/procedures/terrain-styled-topology.d.ts +34 -0
- package/dist/types/procedures/web-mercator-legacy.d.ts +4 -0
- package/dist/types/procedures/web-mercator-math.d.ts +4 -0
- package/dist/types/scene/globals.d.ts +11 -0
- package/dist/types/scene/ground_footprint.d.ts +16 -0
- package/dist/types/scene/host_frame.d.ts +54 -0
- package/dist/types/scene/projection_math.d.ts +52 -0
- package/dist/types/scene/scene-resource-types.d.ts +177 -0
- package/dist/types/scene/scene_bundle.d.ts +69 -0
- package/dist/types/scene/visibility_adapter.d.ts +106 -0
- package/dist/types/selection/draped-terrain-surface.d.ts +78 -0
- package/dist/types/selection/terrain_surface.d.ts +149 -0
- package/dist/types/shader-modules/globe-horizon.d.ts +15 -0
- package/dist/types/shader-modules/height-decode.d.ts +13 -0
- package/dist/types/shader-modules/hillshade.d.ts +13 -0
- package/dist/types/shader-modules/index.d.ts +6 -0
- package/dist/types/shader-modules/planar.d.ts +12 -0
- package/dist/types/shader-modules/sphere-map.d.ts +13 -0
- package/dist/types/shader-modules/triplanar.d.ts +15 -0
- package/dist/types/sources/decoded_tile_store.d.ts +95 -0
- package/dist/types/sources/tile_source_metadata.d.ts +32 -0
- package/dist/types/styles/text/fontfaceobserver.d.ts +10 -0
- package/dist/types/tile/tile_id.d.ts +37 -0
- package/dist/types/tile/tile_traversal_adapter.d.ts +63 -0
- package/dist/types/types.d.ts +293 -0
- package/dist/types/utils/geo.d.ts +57 -0
- package/dist/types/utils/hash.d.ts +1 -0
- package/dist/types/utils/log.d.ts +27 -0
- package/dist/types/utils/props.d.ts +6 -0
- package/dist/types/utils/subscribe.d.ts +10 -0
- package/dist/types/utils/thread.d.ts +6 -0
- package/dist/types/utils/urls.d.ts +26 -0
- package/dist/types/utils/utils.d.ts +26 -0
- package/dist/types/utils/version.d.ts +2 -0
- package/dist/types/utils/worker-types.d.ts +68 -0
- package/dist/types/utils/worker_broker.d.ts +3 -0
- package/package.json +103 -3
- package/src/builders/common.ts +41 -0
- package/src/builders/earcut.d.ts +15 -0
- package/src/builders/geometry-types.ts +60 -0
- package/src/builders/points.ts +115 -0
- package/src/builders/polygons.ts +225 -0
- package/src/builders/polylines.ts +682 -0
- package/src/builders/wireframe.ts +31 -0
- package/src/core.d.ts +29 -0
- package/src/core.ts +33 -0
- package/src/experimental/loaders-gl-worker.ts +19 -0
- package/src/experimental/projected-basemaps-worker.ts +13 -0
- package/src/experimental/projected-mesh-cache.ts +137 -0
- package/src/experimental/projected-mesh-domain.ts +110 -0
- package/src/experimental/projected-mesh-refinement.ts +193 -0
- package/src/experimental/projected-mesh.ts +399 -0
- package/src/experimental/projected-normal.ts +26 -0
- package/src/experimental/projected-symbol-mesh.ts +74 -0
- package/src/gl/constants.ts +18 -0
- package/src/gl/context.ts +103 -0
- package/src/gl/extensions.ts +30 -0
- package/src/gl/globe_mesh.ts +285 -0
- package/src/gl/glsl.ts +257 -0
- package/src/gl/mesh-types.ts +56 -0
- package/src/gl/render_state.ts +111 -0
- package/src/gl/shader_program.ts +1310 -0
- package/src/gl/texture.ts +814 -0
- package/src/gl/uniform_buffer.ts +340 -0
- package/src/gl/vao.ts +154 -0
- package/src/gl/vbo_mesh.ts +349 -0
- package/src/gl/vertex-constants.ts +19 -0
- package/src/gl/vertex-types.ts +35 -0
- package/src/gl/vertex_data.ts +126 -0
- package/src/gl/vertex_elements.ts +54 -0
- package/src/gl/vertex_layout.ts +241 -0
- package/src/glsl.d.ts +14 -0
- package/src/gpu/luma_device_renderer.ts +579 -0
- package/src/gpu/pixel_readback.ts +51 -0
- package/src/gpu/resource_lifecycle.ts +32 -0
- package/src/gpu/tangram_gpu_backend.ts +195 -0
- package/src/index.d.ts +155 -0
- package/src/index.ts +105 -0
- package/src/labels/collision-types.ts +94 -0
- package/src/labels/collision.ts +273 -0
- package/src/labels/collision_grid.ts +61 -0
- package/src/labels/intersect.ts +30 -0
- package/src/labels/label-types.ts +91 -0
- package/src/labels/label.ts +207 -0
- package/src/labels/label_line.ts +801 -0
- package/src/labels/label_point.ts +131 -0
- package/src/labels/main-pass-types.ts +73 -0
- package/src/labels/main_pass.ts +221 -0
- package/src/labels/point_anchor.ts +100 -0
- package/src/labels/point_placement.ts +150 -0
- package/src/labels/projected-pass.ts +259 -0
- package/src/labels/repeat_group.ts +72 -0
- package/src/lights/ambient_light.glsl +18 -0
- package/src/lights/directional_light.glsl +39 -0
- package/src/lights/geographic-lights.ts +21 -0
- package/src/lights/light-definitions.ts +285 -0
- package/src/lights/light.ts +590 -0
- package/src/lights/lighting-uniforms.ts +80 -0
- package/src/lights/lighting-wgsl.ts +116 -0
- package/src/lights/material.glsl +237 -0
- package/src/lights/material.ts +145 -0
- package/src/lights/native-falloff.ts +37 -0
- package/src/lights/point_light.glsl +96 -0
- package/src/lights/spot_light.glsl +111 -0
- package/src/map-logic/draped-terrain-bounds.ts +71 -0
- package/src/map-logic/globe-terrain-preparation.ts +217 -0
- package/src/map-logic/globe-terrain.ts +296 -0
- package/src/map-logic/index.ts +37 -0
- package/src/map-logic/label-identity.ts +36 -0
- package/src/map-logic/label-placement.ts +117 -0
- package/src/map-logic/screen-bounds.ts +34 -0
- package/src/map-logic/terrain-data.ts +107 -0
- package/src/map-logic/terrain-error.ts +134 -0
- package/src/map-logic/terrain-ground-topology.ts +164 -0
- package/src/map-logic/terrain-height-field.ts +254 -0
- package/src/map-logic/terrain-navigation.ts +50 -0
- package/src/map-logic/terrain-neighborhood.ts +43 -0
- package/src/map-logic/terrain-query.ts +51 -0
- package/src/map-logic/terrain-resource-budget.ts +124 -0
- package/src/map-logic/terrain-transition-topology.ts +164 -0
- package/src/map-logic/tile-build-queue.ts +110 -0
- package/src/map-logic/tile-cache-policy.ts +89 -0
- package/src/map-logic/tile-residency.ts +50 -0
- package/src/map-logic/triangle-query-index.ts +265 -0
- package/src/procedures/js-yaml.d.ts +15 -0
- package/src/procedures/mesh-projector.ts +191 -0
- package/src/procedures/mlt-loaders.ts +55 -0
- package/src/procedures/mvt-dependencies.d.ts +20 -0
- package/src/procedures/mvt-legacy.ts +150 -0
- package/src/procedures/mvt-loaders.ts +53 -0
- package/src/procedures/mvt-parser.ts +48 -0
- package/src/procedures/mvt-properties.ts +36 -0
- package/src/procedures/mvt-tile-provider.ts +72 -0
- package/src/procedures/pmtiles-loader.ts +75 -0
- package/src/procedures/projected-coordinate-transform.ts +79 -0
- package/src/procedures/projection-batch-executor.ts +140 -0
- package/src/procedures/scene-yaml-legacy.ts +16 -0
- package/src/procedures/scene-yaml-loaders.ts +10 -0
- package/src/procedures/terrain-draping.ts +713 -0
- package/src/procedures/terrain-globe.ts +32 -0
- package/src/procedures/terrain-styled-topology.ts +184 -0
- package/src/procedures/web-mercator-legacy.ts +24 -0
- package/src/procedures/web-mercator-math.ts +50 -0
- package/src/scene/camera.ts +298 -0
- package/src/scene/camera_base.ts +116 -0
- package/src/scene/classic_scene.ts +20 -0
- package/src/scene/external_camera.ts +101 -0
- package/src/scene/globals.ts +120 -0
- package/src/scene/ground_footprint.ts +139 -0
- package/src/scene/host_frame.ts +326 -0
- package/src/scene/projected_tile_lod.ts +125 -0
- package/src/scene/projection_math.ts +142 -0
- package/src/scene/projection_shaders.ts +183 -0
- package/src/scene/renderer.ts +516 -0
- package/src/scene/scene-resource-types.ts +174 -0
- package/src/scene/scene.ts +2378 -0
- package/src/scene/scene_bundle.ts +304 -0
- package/src/scene/scene_debug.ts +129 -0
- package/src/scene/scene_loader.ts +402 -0
- package/src/scene/scene_worker.ts +528 -0
- package/src/scene/view.ts +683 -0
- package/src/scene/visibility_adapter.ts +319 -0
- package/src/scene/worker_url.ts +15 -0
- package/src/selection/draped-terrain-surface.ts +377 -0
- package/src/selection/selection-types.ts +79 -0
- package/src/selection/selection.ts +542 -0
- package/src/selection/selection_fragment.glsl +18 -0
- package/src/selection/selection_globals.glsl +9 -0
- package/src/selection/selection_pixels.ts +59 -0
- package/src/selection/selection_vertex.glsl +15 -0
- package/src/selection/terrain_surface.ts +298 -0
- package/src/shader-modules/globe-horizon.ts +52 -0
- package/src/shader-modules/height-decode.ts +41 -0
- package/src/shader-modules/hillshade.ts +70 -0
- package/src/shader-modules/index.ts +10 -0
- package/src/shader-modules/planar.ts +24 -0
- package/src/shader-modules/sphere-map.ts +38 -0
- package/src/shader-modules/triplanar.ts +45 -0
- package/src/sources/aligned_tile_source.ts +122 -0
- package/src/sources/data_source.ts +655 -0
- package/src/sources/decoded_tile_store.ts +245 -0
- package/src/sources/geojson.ts +300 -0
- package/src/sources/mvt.ts +247 -0
- package/src/sources/raster.ts +341 -0
- package/src/sources/shared_tile_source_adapter.ts +117 -0
- package/src/sources/sources.ts +10 -0
- package/src/sources/tile_source_adapter.ts +84 -0
- package/src/sources/tile_source_metadata.ts +65 -0
- package/src/sources/tile_source_state.ts +112 -0
- package/src/sources/topojson.ts +90 -0
- package/src/styles/feature_annotations.ts +16 -0
- package/src/styles/filter.ts +190 -0
- package/src/styles/geometry-style-types.ts +209 -0
- package/src/styles/globe_visibility_wgsl.ts +22 -0
- package/src/styles/layer-types.ts +45 -0
- package/src/styles/layer.ts +586 -0
- package/src/styles/lines/dasharray.ts +49 -0
- package/src/styles/lines/lines.ts +707 -0
- package/src/styles/lines/lines_wgsl.ts +224 -0
- package/src/styles/points/point-runtime-types.ts +125 -0
- package/src/styles/points/points.ts +1079 -0
- package/src/styles/points/points_fragment.glsl +126 -0
- package/src/styles/points/points_vertex.glsl +230 -0
- package/src/styles/points/points_wgsl.ts +189 -0
- package/src/styles/polygons/polygons.ts +268 -0
- package/src/styles/polygons/polygons_fragment.glsl +173 -0
- package/src/styles/polygons/polygons_vertex.glsl +213 -0
- package/src/styles/polygons/polygons_wgsl.ts +127 -0
- package/src/styles/property-types.ts +125 -0
- package/src/styles/raster/raster.ts +33 -0
- package/src/styles/raster/raster_globals.glsl +46 -0
- package/src/styles/style-mixing-types.ts +101 -0
- package/src/styles/style-runtime-types.ts +220 -0
- package/src/styles/style-schema.ts +133 -0
- package/src/styles/style.ts +1033 -0
- package/src/styles/style_globals.glsl +69 -0
- package/src/styles/style_manager.ts +464 -0
- package/src/styles/style_parser.ts +620 -0
- package/src/styles/text/font_manager.ts +180 -0
- package/src/styles/text/fontfaceobserver.d.ts +10 -0
- package/src/styles/text/text-types.ts +220 -0
- package/src/styles/text/text.ts +378 -0
- package/src/styles/text/text_canvas.ts +773 -0
- package/src/styles/text/text_labels.ts +436 -0
- package/src/styles/text/text_segments.ts +142 -0
- package/src/styles/text/text_settings.ts +228 -0
- package/src/styles/text/text_wgsl.ts +159 -0
- package/src/styles/text/text_wrap.ts +194 -0
- package/src/tile/globe_tile_preload.ts +40 -0
- package/src/tile/tangram_tileset_2d.ts +108 -0
- package/src/tile/tile-build-types.ts +155 -0
- package/src/tile/tile.ts +807 -0
- package/src/tile/tile_id.ts +172 -0
- package/src/tile/tile_manager.ts +889 -0
- package/src/tile/tile_pyramid.ts +119 -0
- package/src/tile/tile_resource_cache.ts +91 -0
- package/src/tile/tile_traversal_adapter.ts +132 -0
- package/src/types.ts +332 -0
- package/src/utils/debounce.ts +17 -0
- package/src/utils/debug_settings.ts +43 -0
- package/src/utils/errors.ts +12 -0
- package/src/utils/functions.ts +95 -0
- package/src/utils/geo.ts +364 -0
- package/src/utils/hash.ts +14 -0
- package/src/utils/log.ts +108 -0
- package/src/utils/media_capture.ts +193 -0
- package/src/utils/merge.ts +44 -0
- package/src/utils/obb.ts +134 -0
- package/src/utils/props.ts +43 -0
- package/src/utils/slice.ts +14 -0
- package/src/utils/subscribe.ts +58 -0
- package/src/utils/task.ts +154 -0
- package/src/utils/thread.ts +26 -0
- package/src/utils/urls.ts +223 -0
- package/src/utils/utils.ts +310 -0
- package/src/utils/vector.ts +197 -0
- package/src/utils/version.ts +8 -0
- package/src/utils/worker-types.ts +79 -0
- package/src/utils/worker_broker.ts +523 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Tangram
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) 2013-2016 Brett Camper and Mapzen
|
|
4
|
+
|
|
5
|
+
#ifdef TANGRAM_VERTEX_SHADER
|
|
6
|
+
|
|
7
|
+
// Apply layer ordering to avoid z-fighting
|
|
8
|
+
void applyLayerOrder (float layer, inout vec4 position) {
|
|
9
|
+
position.z -= layer * TANGRAM_LAYER_DELTA * position.w;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Vertex position in model space: [0, 1] range over the local tile
|
|
13
|
+
// Note positions can be outside that range due to unclipped geometry, geometry higher than a unit cube, etc.
|
|
14
|
+
vec4 modelPosition() {
|
|
15
|
+
return
|
|
16
|
+
vec4(
|
|
17
|
+
a_position.xyz / TANGRAM_TILE_SCALE // scale coords to ~0-1 range
|
|
18
|
+
* exp2(u_tile_origin.z - u_tile_origin.w), // adjust for tile overzooming
|
|
19
|
+
1.)
|
|
20
|
+
+ vec4(0., 1., 0., 0.);
|
|
21
|
+
// NB: additional offset to account for unusual Tangram JS y coords,
|
|
22
|
+
// should be refactored to remove
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Position in model space as above, but according to tile coordinate (as opposed to style) zoom
|
|
26
|
+
// e.g. unadjusted for tile overzooming
|
|
27
|
+
vec4 modelPositionBaseZoom() {
|
|
28
|
+
return
|
|
29
|
+
vec4(
|
|
30
|
+
a_position.xyz / TANGRAM_TILE_SCALE, // scale coords to ~0-1 range
|
|
31
|
+
1.)
|
|
32
|
+
+ vec4(0., 1., 0., 0.); // see note on offset above
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
// Vertex position in world coordinates, useful for 3d procedural textures, etc.
|
|
38
|
+
vec4 worldPosition() {
|
|
39
|
+
return v_world_position;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Optionally wrap world coordinates (allows more precision at higher zooms)
|
|
43
|
+
// e.g. at wrap 1000, the world space will wrap every 1000 meters
|
|
44
|
+
#ifdef TANGRAM_VERTEX_SHADER
|
|
45
|
+
|
|
46
|
+
vec4 wrapWorldPosition(vec4 world_position) {
|
|
47
|
+
#if defined(TANGRAM_WORLD_POSITION_WRAP)
|
|
48
|
+
vec2 anchor = u_tile_origin.xy - mod(u_tile_origin.xy, TANGRAM_WORLD_POSITION_WRAP);
|
|
49
|
+
world_position.xy -= anchor;
|
|
50
|
+
#endif
|
|
51
|
+
return world_position;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
#endif
|
|
55
|
+
|
|
56
|
+
// Normal in world space
|
|
57
|
+
#if defined(TANGRAM_VERTEX_SHADER)
|
|
58
|
+
|
|
59
|
+
vec3 worldNormal() {
|
|
60
|
+
return TANGRAM_NORMAL;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#elif defined(TANGRAM_FRAGMENT_SHADER)
|
|
64
|
+
|
|
65
|
+
vec3 worldNormal() {
|
|
66
|
+
return u_inverseNormalMatrix * TANGRAM_NORMAL;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
#endif
|
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
// Tangram
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) 2013-2016 Brett Camper and Mapzen
|
|
4
|
+
// Copyright (c) 2026 vis.gl contributors
|
|
5
|
+
|
|
6
|
+
// Manage rendering styles
|
|
7
|
+
import type {ManagedStyle, StyleDefinition, StyleShaderDefinition, MixedStyleShaders, StyleManagerTile, ActiveStyleBlendOrder} from './style-mixing-types';
|
|
8
|
+
|
|
9
|
+
import ShaderProgram from '../gl/shader_program';
|
|
10
|
+
import mergeObjects from '../utils/merge';
|
|
11
|
+
import Geo from '../utils/geo';
|
|
12
|
+
import WorkerBroker from '../utils/worker_broker';
|
|
13
|
+
import log from '../utils/log';
|
|
14
|
+
|
|
15
|
+
import {Polygons} from './polygons/polygons';
|
|
16
|
+
import {Lines} from './lines/lines';
|
|
17
|
+
import {Points} from './points/points';
|
|
18
|
+
import {TextStyle} from './text/text';
|
|
19
|
+
import {RasterStyle} from './raster/raster';
|
|
20
|
+
|
|
21
|
+
import style_globals_source from './style_globals.glsl';
|
|
22
|
+
import selection_globals_source from '../selection/selection_globals.glsl';
|
|
23
|
+
import selection_vertex_source from '../selection/selection_vertex.glsl';
|
|
24
|
+
|
|
25
|
+
/** Builds scene style mixins and owns the registered render-style lifecycle. */
|
|
26
|
+
export class StyleManager {
|
|
27
|
+
/** Registered renderable styles, including reusable built-ins. */
|
|
28
|
+
declare styles: Record<string, ManagedStyle>;
|
|
29
|
+
/** Prototype sources reused when rebuilding custom styles. */
|
|
30
|
+
declare base_styles: Record<string, ManagedStyle>;
|
|
31
|
+
/** Current tile-visible style names. */
|
|
32
|
+
declare active_styles: string[];
|
|
33
|
+
/** Sorted mesh blend-order passes. */
|
|
34
|
+
declare active_blend_orders: ActiveStyleBlendOrder[];
|
|
35
|
+
|
|
36
|
+
constructor () {
|
|
37
|
+
this.styles = {};
|
|
38
|
+
this.base_styles = {};
|
|
39
|
+
this.active_styles = [];
|
|
40
|
+
this.active_blend_orders = [];
|
|
41
|
+
|
|
42
|
+
// Add built-in rendering styles
|
|
43
|
+
this.register(Object.create(Polygons));
|
|
44
|
+
this.register(Object.create(Lines));
|
|
45
|
+
this.register(Object.create(Points));
|
|
46
|
+
this.register(Object.create(TextStyle));
|
|
47
|
+
this.register(Object.create(RasterStyle));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Global configuration for all styles
|
|
51
|
+
init () {
|
|
52
|
+
ShaderProgram.removeBlock('global');
|
|
53
|
+
ShaderProgram.removeBlock('setup');
|
|
54
|
+
|
|
55
|
+
// Model and world position accessors, layer re-ordering function
|
|
56
|
+
ShaderProgram.addBlock('global', style_globals_source);
|
|
57
|
+
|
|
58
|
+
// Feature selection global
|
|
59
|
+
ShaderProgram.addBlock('global', selection_globals_source);
|
|
60
|
+
|
|
61
|
+
// Feature selection vertex shader support
|
|
62
|
+
ShaderProgram.replaceBlock('setup', selection_vertex_source);
|
|
63
|
+
|
|
64
|
+
// Minimum value for float comparisons
|
|
65
|
+
ShaderProgram.defines.TANGRAM_EPSILON = 0.00001;
|
|
66
|
+
|
|
67
|
+
// Minimum depth buffer value separating each `order` unit
|
|
68
|
+
// Assume min 16-bit depth buffer, in practice uses 14-bits, 1 extra bit to handle virtual half-layers
|
|
69
|
+
// for outlines (inserted in between layers), another extra bit to prevent precision loss
|
|
70
|
+
ShaderProgram.defines.TANGRAM_LAYER_DELTA = 1 / (1 << 14);
|
|
71
|
+
|
|
72
|
+
// Internal tile scale
|
|
73
|
+
ShaderProgram.defines.TANGRAM_TILE_SCALE =
|
|
74
|
+
`vec3(${Geo.tile_scale}., ${Geo.tile_scale}., u_meters_per_pixel * ${Geo.tile_size}.)`;
|
|
75
|
+
|
|
76
|
+
// Increases precision for height values
|
|
77
|
+
ShaderProgram.defines.TANGRAM_HEIGHT_SCALE = Geo.height_scale;
|
|
78
|
+
|
|
79
|
+
// Alpha discard threshold (substitute for alpha blending)
|
|
80
|
+
ShaderProgram.defines.TANGRAM_ALPHA_TEST = 0.5;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Destroy all styles for a given rendering resource context
|
|
84
|
+
destroy (resource_context: unknown): void {
|
|
85
|
+
Object.keys(this.styles).forEach((_name) => {
|
|
86
|
+
let style = this.styles[_name];
|
|
87
|
+
if ((style.resource_context || style.gl) === resource_context) {
|
|
88
|
+
log('trace', `StyleManager.destroy: destroying render style ${style.name}`);
|
|
89
|
+
|
|
90
|
+
if (style.base) {
|
|
91
|
+
this.remove(style.name);
|
|
92
|
+
}
|
|
93
|
+
style.destroy();
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Register a style
|
|
99
|
+
register (style: ManagedStyle): void {
|
|
100
|
+
this.styles[style.name] = style;
|
|
101
|
+
this.base_styles[style.name] = style;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Remove a style
|
|
105
|
+
remove (name: string): void {
|
|
106
|
+
delete this.styles[name];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
getActiveStyles () {
|
|
110
|
+
return this.active_styles;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Get list of active styles based on a set of tiles
|
|
114
|
+
updateActiveStyles (tiles: StyleManagerTile[]): string[] {
|
|
115
|
+
this.active_styles = Object.keys(
|
|
116
|
+
tiles.reduce((active, tile) => {
|
|
117
|
+
Object.keys(tile.meshes).forEach(s => active[s] = true);
|
|
118
|
+
return active;
|
|
119
|
+
}, {} as Record<string, boolean>)
|
|
120
|
+
);
|
|
121
|
+
return this.active_styles;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
getActiveBlendOrders () {
|
|
125
|
+
return this.active_blend_orders;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
updateActiveBlendOrders (tiles: StyleManagerTile[]): void {
|
|
129
|
+
const orders: ActiveStyleBlendOrder[] = [];
|
|
130
|
+
tiles.forEach(tile => {
|
|
131
|
+
Object.entries(tile.meshes)
|
|
132
|
+
.forEach(([style, style_meshes]) => { // for each tile's set of meshes, keyed by style name
|
|
133
|
+
style_meshes.forEach(mesh => { // for each style's list of meshes
|
|
134
|
+
// find entry for this mesh's blend order, insert if first entry
|
|
135
|
+
const blend_order = mesh.variant.blend_order;
|
|
136
|
+
let oi = orders.findIndex(x => x.blend_order === blend_order);
|
|
137
|
+
oi = oi > -1 ? oi : orders.push({ blend_order, styles: [] }) - 1;
|
|
138
|
+
|
|
139
|
+
// add style to list for this blend order
|
|
140
|
+
if (orders[oi].styles.indexOf(style) === -1) {
|
|
141
|
+
orders[oi].styles.push(style);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// sort ascending by blend order
|
|
148
|
+
this.active_blend_orders = orders.sort((a, b) => Number(a.blend_order) - Number(b.blend_order));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
mix (style: StyleDefinition, styles: Record<string, StyleDefinition>): StyleDefinition {
|
|
152
|
+
// Exit early if we have already applied mixins to this style
|
|
153
|
+
if (style.mixed) {
|
|
154
|
+
return style;
|
|
155
|
+
}
|
|
156
|
+
style.mixed = {};
|
|
157
|
+
|
|
158
|
+
// Mixin sources, in order
|
|
159
|
+
let sources: StyleDefinition[] = [];
|
|
160
|
+
if (style.mix) {
|
|
161
|
+
const sourceNames: string[] = [];
|
|
162
|
+
if (Array.isArray(style.mix)) {
|
|
163
|
+
sourceNames.push(...style.mix);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
sourceNames.push(style.mix);
|
|
167
|
+
}
|
|
168
|
+
sources = sourceNames.map(x => styles[x]).filter(x => x && x !== style); // TODO: warning on trying to mix into self
|
|
169
|
+
|
|
170
|
+
// Track which styles were mixed into this one
|
|
171
|
+
sources.forEach(s => style.mixed![s.name!] = true);
|
|
172
|
+
}
|
|
173
|
+
sources.push(style);
|
|
174
|
+
|
|
175
|
+
// Flags - OR'd, true if any style has it set
|
|
176
|
+
style.animated = sources.some(x => x && x.animated);
|
|
177
|
+
style.texcoords = sources.some(x => x && x.texcoords);
|
|
178
|
+
|
|
179
|
+
// Overwrites - last definition wins
|
|
180
|
+
style.base = sources.map(x => x.base).filter(x => x).pop();
|
|
181
|
+
style.lighting = sources.map(x => x.lighting).filter(x => x != null).pop();
|
|
182
|
+
style.texture = sources.map(x => x.texture).filter(x => x).pop();
|
|
183
|
+
style.raster = sources.map(x => x.raster).filter(x => x != null).pop();
|
|
184
|
+
style.dash = sources.map(x => x.dash).filter(x => x != null).pop();
|
|
185
|
+
style.dash_background_color = sources.map(x => x.dash_background_color).filter(x => x != null).pop();
|
|
186
|
+
if (sources.some(x => Object.prototype.hasOwnProperty.call(x, 'blend') && x.blend)) {
|
|
187
|
+
// only mix blend if explicitly set, otherwise let base style choose blending mode
|
|
188
|
+
// hasOwnProperty check gives preference to base style prototype
|
|
189
|
+
style.blend = sources.map(x => Object.prototype.hasOwnProperty.call(x, 'blend') && x.blend).filter(x => x).pop();
|
|
190
|
+
}
|
|
191
|
+
style.blend_order = sources.map(x => x.blend_order).filter(x => x != null).pop();
|
|
192
|
+
|
|
193
|
+
// Merges - property-specific rules for merging values
|
|
194
|
+
style.defines = Object.assign({}, ...sources.map(x => x.defines).filter(x => x)); // internal defines (not user-defined)
|
|
195
|
+
style.material = Object.assign({}, ...sources.map(x => x.material).filter(x => x));
|
|
196
|
+
|
|
197
|
+
let draws = sources.map(x => x.draw).filter(x => x); // draw defaults
|
|
198
|
+
if (draws.length > 0) {
|
|
199
|
+
style.draw = mergeObjects({}, ...draws);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Mix shader properties
|
|
203
|
+
this.mixShaders(style, styles, sources);
|
|
204
|
+
return style;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Mix the propertes in the "shaders" block
|
|
208
|
+
mixShaders (style: StyleDefinition, styles: Record<string, StyleDefinition>, sources: StyleDefinition[]): StyleDefinition {
|
|
209
|
+
let shaders = {} as MixedStyleShaders; // newly mixed shaders properties
|
|
210
|
+
let shader_merges = sources.map(x => x.shaders).filter(x => x) as StyleShaderDefinition[]; // just the source styles with shader properties
|
|
211
|
+
|
|
212
|
+
// Defines
|
|
213
|
+
shaders.defines = Object.assign({}, ...shader_merges.map(x => x.defines).filter(x => x));
|
|
214
|
+
|
|
215
|
+
// Attributes
|
|
216
|
+
shaders.attributes = Object.assign({}, ...shader_merges.map(x => x.attributes).filter(x => x));
|
|
217
|
+
|
|
218
|
+
// Uniforms
|
|
219
|
+
shaders.uniforms = {}; // uniforms for this style, both explicitly defined, and mixed from other styles
|
|
220
|
+
shaders._uniforms = (style.shaders && style.shaders.uniforms) || {}; // uniforms explicitly defined by *this* style
|
|
221
|
+
shaders._uniform_scopes = {}; // tracks which style each uniform originated from (this one, or ancestor)
|
|
222
|
+
|
|
223
|
+
// Mix in uniforms from ancestors, providing means to access
|
|
224
|
+
sources
|
|
225
|
+
.filter(x => x.shaders && x.shaders!.uniforms!)
|
|
226
|
+
.forEach(x => {
|
|
227
|
+
for (let u in x.shaders!.uniforms!) {
|
|
228
|
+
shaders._uniform_scopes[u] = x.name!;
|
|
229
|
+
|
|
230
|
+
// Define getter and setter for this uniform
|
|
231
|
+
// Getter returns value for this style if present, otherwise asks appropriate ancestor for it
|
|
232
|
+
// Setter sets the value for this style (whether previously present in this style or not)
|
|
233
|
+
// Mimics JS prototype/hasOwnProperty behavior, but with multiple ancestors (via mixins)
|
|
234
|
+
Object.defineProperty(shaders.uniforms, u, {
|
|
235
|
+
enumerable: true,
|
|
236
|
+
configurable: true,
|
|
237
|
+
get: function () {
|
|
238
|
+
// Uniform is explicitly defined on this style
|
|
239
|
+
if (shaders._uniforms[u] !== undefined) {
|
|
240
|
+
return shaders._uniforms[u];
|
|
241
|
+
}
|
|
242
|
+
// Uniform was mixed from another style, forward request there
|
|
243
|
+
// Identity check is needed to prevent infinite recursion if a previously defined uniform
|
|
244
|
+
// is set to undefined
|
|
245
|
+
else if (styles[shaders._uniform_scopes[u]].shaders!.uniforms! !== shaders.uniforms) {
|
|
246
|
+
return styles[shaders._uniform_scopes[u]].shaders!.uniforms![u];
|
|
247
|
+
}
|
|
248
|
+
return undefined;
|
|
249
|
+
},
|
|
250
|
+
set: function (v) {
|
|
251
|
+
shaders._uniforms[u] = v;
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
// Extensions: build a list of unique extensions
|
|
258
|
+
shaders.extensions = Object.keys(shader_merges
|
|
259
|
+
.map(x => x.extensions)
|
|
260
|
+
.filter(x => x)
|
|
261
|
+
.reduce((prev, cur) => {
|
|
262
|
+
// single extension
|
|
263
|
+
if (typeof cur === 'string') {
|
|
264
|
+
prev[cur] = true;
|
|
265
|
+
}
|
|
266
|
+
// array of extensions
|
|
267
|
+
else {
|
|
268
|
+
cur!.forEach(x => prev[x] = true);
|
|
269
|
+
}
|
|
270
|
+
return prev;
|
|
271
|
+
}, {} as Record<string, boolean>) || {}
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
// Shader blocks
|
|
275
|
+
// Mark all shader blocks for the target style as originating with its own name
|
|
276
|
+
if (style.shaders && style.shaders.blocks) {
|
|
277
|
+
style.shaders.block_scopes = style.shaders.block_scopes || {};
|
|
278
|
+
for (let k in style.shaders.blocks) {
|
|
279
|
+
let block = style.shaders.blocks[k];
|
|
280
|
+
style.shaders.block_scopes[k] = style.shaders.block_scopes[k] || [];
|
|
281
|
+
if (Array.isArray(block)) {
|
|
282
|
+
(style.shaders.block_scopes[k] as string[]).push(...block.map(() => style.name!));
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
(style.shaders.block_scopes[k] as string[]).push(style.name!);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Merge shader blocks, keeping track of which style each block originated from
|
|
291
|
+
let mixed: Record<string, boolean> = {}; // all scopes mixed so far
|
|
292
|
+
shader_merges.forEach(source => {
|
|
293
|
+
if (!source.blocks) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
shaders.blocks = shaders.blocks || {};
|
|
298
|
+
shaders.block_scopes = shaders.block_scopes || {};
|
|
299
|
+
let mixed_source: Record<string, boolean> = {}; // scopes mixed for this source style
|
|
300
|
+
|
|
301
|
+
for (let t in source.blocks) {
|
|
302
|
+
let block = source.blocks[t];
|
|
303
|
+
let block_scope = source.block_scopes![t];
|
|
304
|
+
|
|
305
|
+
shaders.blocks[t] = shaders.blocks[t] || [];
|
|
306
|
+
shaders.block_scopes[t] = shaders.block_scopes[t] || [];
|
|
307
|
+
|
|
308
|
+
// standardize on arrays (block can be single or multi-value)
|
|
309
|
+
block = Array.isArray(block) ? block : [block];
|
|
310
|
+
block_scope = Array.isArray(block_scope) ? block_scope : [block_scope];
|
|
311
|
+
|
|
312
|
+
for (let b=0; b < block.length; b++) {
|
|
313
|
+
// Skip blocks we've already mixed in from the same scope
|
|
314
|
+
// Repeating scope indicates a diamond pattern where a style is being mixed multiple times
|
|
315
|
+
if (mixed[block_scope[b]]) {
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
mixed_source[block_scope[b]] = true;
|
|
319
|
+
|
|
320
|
+
(shaders.blocks[t] as string[]).push(block[b]);
|
|
321
|
+
(shaders.block_scopes[t] as string[]).push(block_scope[b]);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Add styles mixed in from this source - they could be multi-level ancestors,
|
|
326
|
+
// beyond the first-level "parents" defined in this style's `mix` list
|
|
327
|
+
Object.assign(mixed, mixed_source);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
Object.assign(style.mixed!, mixed); // add all newly mixed styles
|
|
331
|
+
|
|
332
|
+
style.shaders = shaders; // assign back to style
|
|
333
|
+
return style;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// Create a new style
|
|
337
|
+
// name: name of new style
|
|
338
|
+
// config: properties of new style
|
|
339
|
+
// styles: working set of styles being built (used for mixing in existing styles)
|
|
340
|
+
create (name: string, config: StyleDefinition, styles: Record<string, StyleDefinition> = {}): StyleDefinition {
|
|
341
|
+
let style = mergeObjects({} as StyleDefinition, config); // deep copy
|
|
342
|
+
style.name = name;
|
|
343
|
+
|
|
344
|
+
// Style mixins
|
|
345
|
+
style = this.mix(style, styles);
|
|
346
|
+
|
|
347
|
+
// Has base style?
|
|
348
|
+
// Only renderable (instantiated) styles should be included for run-time use
|
|
349
|
+
// Others are intermediary/abstract, used during style composition but not execution
|
|
350
|
+
if (style.base && this.base_styles[style.base]) {
|
|
351
|
+
this.styles[name] = style = Object.assign(Object.create(this.base_styles[style.base]), style) as ManagedStyle;
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
style.base = null; // null out invalid base style
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return style;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Called to create and initialize styles
|
|
361
|
+
build (styles_defs: Record<string, StyleDefinition>): Record<string, ManagedStyle> {
|
|
362
|
+
const styles = { ...styles_defs }; // copy to avoid modifying underlying object
|
|
363
|
+
|
|
364
|
+
// Un-register existing styles from cross-thread communication
|
|
365
|
+
if (this.styles) {
|
|
366
|
+
Object.values(this.styles)
|
|
367
|
+
.forEach(s => WorkerBroker.removeTarget(s.main_thread_target));
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// Add default blend/base style pairs as needed
|
|
371
|
+
const blends = ['opaque', 'add', 'multiply', 'overlay', 'inlay', 'translucent'];
|
|
372
|
+
const bases = ['polygons', 'lines', 'points', 'text', 'raster'];
|
|
373
|
+
for (const blend of blends) {
|
|
374
|
+
for (const base of bases) {
|
|
375
|
+
const style = blend + '_' + base;
|
|
376
|
+
if (styles[style] == null) {
|
|
377
|
+
styles[style] = { base, blend };
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Sort styles by dependency, then build them
|
|
383
|
+
let style_deps = Object.keys(styles).sort(
|
|
384
|
+
(a, b) => this.inheritanceDepth(a, styles) - this.inheritanceDepth(b, styles)
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
// Only keep built-in base styles
|
|
388
|
+
for (let sname in this.styles) {
|
|
389
|
+
if (!this.base_styles[sname]) {
|
|
390
|
+
// Rebuilt styles own programs and portable material buffers;
|
|
391
|
+
// release them before their last manager reference is removed.
|
|
392
|
+
this.styles[sname].destroy();
|
|
393
|
+
delete this.styles[sname];
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
// Base styles are reused, but initStyles() replaces their
|
|
397
|
+
// program references. Retire owned GPU resources first.
|
|
398
|
+
this.styles[sname].destroy();
|
|
399
|
+
this.styles[sname].reset();
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// Working set of styles being built
|
|
404
|
+
let ws: Record<string, StyleDefinition> = {};
|
|
405
|
+
style_deps.forEach(sname => {
|
|
406
|
+
ws[sname] = this.create(sname, styles[sname], ws);
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
return this.styles;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// Initialize all styles
|
|
413
|
+
initStyles (scene: import('./style-runtime-types').StyleInitOptions = {}): void {
|
|
414
|
+
// Initialize all
|
|
415
|
+
for (let sname in this.styles) {
|
|
416
|
+
this.styles[sname].init(scene);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// Given a style key in a set of styles to add, count the length of the inheritance chain
|
|
421
|
+
inheritanceDepth (key: string, styles: Record<string, StyleDefinition>): number {
|
|
422
|
+
let parents = 0;
|
|
423
|
+
|
|
424
|
+
for (;;) {
|
|
425
|
+
let style = styles[key];
|
|
426
|
+
if (!style) {
|
|
427
|
+
// this is a scene def error, trying to extend a style that doesn't exist
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// Dependency chain ends when this style isn't mixing in any others
|
|
432
|
+
if (!style.mix) {
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// Traverse next parent style
|
|
437
|
+
parents++;
|
|
438
|
+
|
|
439
|
+
if (Array.isArray(style.mix)) {
|
|
440
|
+
// If multiple mixins, find the deepest one
|
|
441
|
+
parents += Math.max(...style.mix.map(s => {
|
|
442
|
+
// Trying to mix into itself!
|
|
443
|
+
if (key === s) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
return this.inheritanceDepth(s, styles);
|
|
448
|
+
}) as number[]);
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
// Trying to mix into itself!
|
|
453
|
+
if (key === style.mix) {
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// If single mixin, continue loop up the tree
|
|
458
|
+
key = style.mix;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
return parents;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
}
|