Skip to main content

mln_engine/layer/
mod.rs

1//! The layer contract: what a crate implements to add a layer type that the
2//! renderer draws.
3//!
4//! A layer type has two halves, which
5//! [`RegistryBuilder::add_layer_type::<L>()`](crate::RegistryBuilder::add_layer_type)
6//! registers together under the style half's name:
7//!
8//! - **The style half**, a marker type that implements `mln_style`'s
9//!   [`StyleLayerType`](mln_style::layer::StyleLayerType): the type's name,
10//!   its kind of source and its properties.
11//! - **The render half**, a struct that implements [`Layer`], one value per
12//!   style layer of the type, which names its style half
13//!   ([`Layer::Style`]).
14//!
15//! # What a layer type writes
16//!
17//! 1. What it draws from, its [`Layer::Input`]: a geometry source's tiles,
18//!    whose features a [`Layout`] lays out into a [`Bucket`] per tile on a
19//!    tile worker ([`Features`]); a raster or image source's tiles, each
20//!    tile's image ([`RasterTiles`](crate::source::RasterTiles), [`RasterTile`]); a raster-dem source's
21//!    tiles, each tile's elevations ([`DemTiles`](crate::source::DemTiles), [`DemContents`]); or
22//!    nothing, for a layer without a source ([`NoTiles`]). The registration
23//!    doesn't compile for an input of another kind of source than the style
24//!    half names.
25//! 2. Its tile values. [`Layer::tile`] makes what the layer keeps of a frame
26//!    tile that has data for it, typically the meshes it draws the tile
27//!    with. The engine keeps the value with the tile until the tile shows
28//!    the layer something else, leaves the frame, or the layer's draws drop
29//!    for a restyle or a switch between Mercator and the globe; it then
30//!    hands the next [`tile`](Layer::tile) of the tile the previous value,
31//!    so that a layer carries over what it made of contents that are still
32//!    the tile's, such as a texture of its image.
33//! 3. Its draws. [`Layer::prepare`] pushes the frame's draws of the layer's
34//!    meshes into [`Draws`](crate::draw::Draws), with the values of their
35//!    programs' blocks: the engine writes, orders, uploads and draws them in
36//!    the frame's passes, at the layer's place in the layers' order and
37//!    depth, so a layer never sees a pass, a stencil or a uniform buffer. A
38//!    layer may draw into targets of its own first
39//!    ([`Draws::target`](crate::draw::Draws::target)), or ask for the
40//!    backend's own commands ([`Draws::lend`](crate::draw::Draws::lend),
41//!    [`Layer::lend`]), and free what it makes with them once the GPU is
42//!    done with it ([`AfterGpu`](crate::draw::AfterGpu)).
43//!
44//! [`Layer::evaluate`] says whether and how the layer draws with its freshly
45//! evaluated values ([`Evaluation`]); [`Layer::update`] brings up to date
46//! what the layer keeps for all its tiles in the frame's update.
47//!
48//! # Terrain
49//!
50//! A type says how its layers meet terrain ([`Layer::TERRAIN`],
51//! [`OnTerrain`]). One that drapes draws flat into the textures of the
52//! terrain's tiles rather than onto the frame: the engine prepares the layer
53//! again for each drape it draws, with the drape's frame
54//! ([`LayerFrame`](crate::draw::LayerFrame)) and the tiles that overlap the
55//! drape, which draw the same tile values as the map's frame, so a tile's
56//! value holds nothing of the frame or the world copy it is first drawn in.
57//! The engine draws a drape again only when what it shows changed. One that
58//! stands on terrain draws the terrain variant of its programs, whose points
59//! read the ground's height, and one that hides behind the ground reads its
60//! depth ([`draw::ground`](crate::draw::ground)).
61//!
62//! # Shared targets
63//!
64//! An extension can route the draws of other layers, of any type, into
65//! textures of the frame's size that several layers share, and process them:
66//! a [`Router`], which it registers
67//! ([`RegistryBuilder::add_router`](crate::RegistryBuilder::add_router)),
68//! declares the frames' shared targets from the style, such as from its
69//! extension members ([`mln_style::member`]), and routes layers into them,
70//! and a layer reads one in its [`prepare`](Layer::prepare) for the map's
71//! frame ([`PrepareCx::read_target`]). The engine draws each target's pass before
72//! the frame's, after the passes of the targets its layers read, and refuses
73//! the routes that don't fit, whose layers draw on the map.
74//!
75//! # Queries
76//!
77//! A rendered-feature query finds a tile's features near its geometry in the
78//! tile's feature index, padded by the layer's
79//! [`query_radius`](Layer::query_radius), and keeps those the layer
80//! [`hit`](Layer::hit)s. A layer that draws other than its tiles'
81//! features, such as one without a source, answers from the last frame
82//! ([`Layer::hit_frame`], [`FrameQuery`]): its hits come with the tiled
83//! layers', in the layers' order, and the query's filter places them, for
84//! `within`, in a tile that holds their geometry.
85//!
86//! # Buckets
87//!
88//! A bucket keeps its vertices and indexes in [`GeometryVec`]s and its
89//! data-driven paint values in binders ([`binders`], declared with
90//! `paint_property_binders!`), which it names in its
91//! [`upload`](Bucket::upload): the engine moves them into the context's
92//! stores, where a layer's tile value reads them
93//! ([`bucket_vertices`], [`bucket_indexes`], [`paint_vertices`]), and
94//! rewrites the binders' values where feature state changes.
95//!
96//! The layer and every hook but the layout's run on the renderer's thread;
97//! the layout and the bucket are `Send`, and a bucket crosses to a tile
98//! worker with memory of its own through the worker codec.
99
100pub mod bucket;
101
102/// The binders of a layer type's data-driven paint values: what a bucket
103/// keeps of each feature's values for its layers' draws, which feature
104/// state rewrites, and the macro that declares a type's binders.
105pub mod binders {
106    pub use crate::layer::paint_property_binder::{
107        BinderValue, CrossFadedPaintPropertyBinder, InterleavedVertexBuffer, InterleavedVertexData, LayerBinders,
108        PaintBinders, PaintPropertyBinder, PaintPropertyBinderBase, PatternDependency, PatternLayerMap,
109        bind_paint_property, shared_paint,
110    };
111}
112pub(crate) mod bucket_geometry;
113pub(crate) mod bucket_parameters;
114pub(crate) mod filter_groups;
115pub(crate) mod group_by_layout;
116pub(crate) mod layer_drawing;
117pub(crate) mod layer_type;
118pub(crate) mod layout;
119pub(crate) mod paint_property_binder;
120pub(crate) mod paint_property_statistics;
121pub(crate) mod render_layer;
122pub(crate) mod tile_input;
123pub(crate) mod tile_layout;
124
125pub use crate::layer::bucket::{Bucket, Upload};
126pub use crate::layer::bucket_geometry::{
127    BucketGeometry, GeometryVec, bucket_indexes, bucket_vertices, copied_indexes, copied_vertices, derived_vertices,
128    paint_vertices,
129};
130pub use crate::layer::layer_drawing::BucketChanges;
131pub use crate::layer::layer_type::EvaluatedLayer;
132pub use crate::layer::layout::{BuildCx, Layout, LayoutCx, layers_by_id};
133pub use crate::layer::render_layer::{
134    EvaluateCx, Evaluation, FrameQuery, Layer, LayerValues, OnTerrain, PrepareCx, TileCx, UpdateCx,
135};
136pub use crate::layer::tile_input::{Features, LayerBucket, NoTiles, RasterTile, TileData, TileInput};
137pub use crate::query::feature_index::QueryRegion;
138#[doc(hidden)]
139pub use crate::render::shared_targets::{Router, Routes};
140pub use crate::render::terrain::SurfaceLight;
141pub use crate::render::tile::FrameTile;
142pub use crate::source::render_image_source::ImageQuad;
143pub use crate::source::render_source::TileOrder;
144pub use crate::tile_store::dem::DemContents;