Skip to main content

Module layer

Module layer 

Source
Expand description

The layer contract: what a crate implements to add a layer type that the renderer draws.

A layer type has two halves, which RegistryBuilder::add_layer_type::<L>() registers together under the style half’s name:

  • The style half, a marker type that implements mln_style’s StyleLayerType: the type’s name, its kind of source and its properties.
  • The render half, a struct that implements Layer, one value per style layer of the type, which names its style half (Layer::Style).

§What a layer type writes

  1. What it draws from, its Layer::Input: a geometry source’s tiles, whose features a Layout lays out into a Bucket per tile on a tile worker (Features); a raster or image source’s tiles, each tile’s image (RasterTiles, RasterTile); a raster-dem source’s tiles, each tile’s elevations (DemTiles, DemContents); or nothing, for a layer without a source (NoTiles). The registration doesn’t compile for an input of another kind of source than the style half names.
  2. Its tile values. Layer::tile makes what the layer keeps of a frame tile that has data for it, typically the meshes it draws the tile with. The engine keeps the value with the tile until the tile shows the layer something else, leaves the frame, or the layer’s draws drop for a restyle or a switch between Mercator and the globe; it then hands the next tile of the tile the previous value, so that a layer carries over what it made of contents that are still the tile’s, such as a texture of its image.
  3. Its draws. Layer::prepare pushes the frame’s draws of the layer’s meshes into Draws, with the values of their programs’ blocks: the engine writes, orders, uploads and draws them in the frame’s passes, at the layer’s place in the layers’ order and depth, so a layer never sees a pass, a stencil or a uniform buffer. A layer may draw into targets of its own first (Draws::target), or ask for the backend’s own commands (Draws::lend, Layer::lend), and free what it makes with them once the GPU is done with it (AfterGpu).

Layer::evaluate says whether and how the layer draws with its freshly evaluated values (Evaluation); Layer::update brings up to date what the layer keeps for all its tiles in the frame’s update.

§Terrain

A type says how its layers meet terrain (Layer::TERRAIN, OnTerrain). One that drapes draws flat into the textures of the terrain’s tiles rather than onto the frame: the engine prepares the layer again for each drape it draws, with the drape’s frame (LayerFrame) and the tiles that overlap the drape, which draw the same tile values as the map’s frame, so a tile’s value holds nothing of the frame or the world copy it is first drawn in. The engine draws a drape again only when what it shows changed. One that stands on terrain draws the terrain variant of its programs, whose points read the ground’s height, and one that hides behind the ground reads its depth (draw::ground).

§Shared targets

An extension can route the draws of other layers, of any type, into textures of the frame’s size that several layers share, and process them: a [Router], which it registers (RegistryBuilder::add_router), declares the frames’ shared targets from the style, such as from its extension members (mln_style::member), and routes layers into them, and a layer reads one in its prepare for the map’s frame (PrepareCx::read_target). The engine draws each target’s pass before the frame’s, after the passes of the targets its layers read, and refuses the routes that don’t fit, whose layers draw on the map.

§Queries

A rendered-feature query finds a tile’s features near its geometry in the tile’s feature index, padded by the layer’s query_radius, and keeps those the layer hits. A layer that draws other than its tiles’ features, such as one without a source, answers from the last frame (Layer::hit_frame, FrameQuery): its hits come with the tiled layers’, in the layers’ order, and the query’s filter places them, for within, in a tile that holds their geometry.

§Buckets

A bucket keeps its vertices and indexes in GeometryVecs and its data-driven paint values in binders (binders, declared with paint_property_binders!), which it names in its upload: the engine moves them into the context’s stores, where a layer’s tile value reads them (bucket_vertices, bucket_indexes, paint_vertices), and rewrites the binders’ values where feature state changes.

The layer and every hook but the layout’s run on the renderer’s thread; the layout and the bucket are Send, and a bucket crosses to a tile worker with memory of its own through the worker codec.

Re-exports§

pub use crate::layer::bucket::Bucket;
pub use crate::layer::bucket::Upload;

Modules§

binders
The binders of a layer type’s data-driven paint values: what a bucket keeps of each feature’s values for its layers’ draws, which feature state rewrites, and the macro that declares a type’s binders.
bucket
Buckets: what a tile’s layout makes of a layer group’s features for the layers’ draws, their vertices, indices and paint values. Workers build buckets and send them to the render thread, which owns each one once, in its tile’s contents, as a Stored bucket behind dyn ErasedBucket. A layer type’s Bucket names its data to an Upload; the engine keeps the rest: the bucket’s identity, whether it uploaded, and the feature-state rewrites of its paint values.

Structs§

BucketChanges
What of a bucket’s vertex data changed since a tile’s draws copied it.
BucketGeometry
The geometry of a tile’s buckets in the context’s stores, by the key of the bucket’s vector it was made of. The tile keeps one per layout result, so it lives as long as the buckets it was made from.
BuildCx
What a layout reads and writes while it builds its bucket.
DemContents
A raster-dem tile’s DEM, which the tile backfills from its neighbours, and the parts of the tile it draws. The layers and the terrain that read it make their textures and quads of it.
EvaluateCx
What a layer’s Layer::evaluate reads and completes.
EvaluatedLayer
The values of a layer of the style half T for a frame.
Evaluation
What a layer’s evaluation says of how it draws with its values.
Features
The tiles of a geometry source, whose features the layout L turns into a bucket per tile. A tile’s data is its LayerBucket.
FrameQuery
A rendered-feature query of a layer L, for what it shows other than its tiles’ features, as of the last update (Layer::hit_frame).
FrameTile
A render tile of a frame, with what it holds for a layer of the type T and the world copy the layer draws it in.
GeometryVec
A bucket’s vertices or indices. The worker fills it through get_mut; the render thread can move the data out (BucketGeometry), after which len still counts it.
ImageQuad
Where the raster shader puts the unit square that a draw’s vertices span (0 to EXTENT on both axes), in its tile’s units: onto the quad of four corners, warped by an ImageWarp. The shader evaluates the warp per vertex and interpolates the texture coordinates projectively, so a projective warp draws exactly on two triangles.
LayerBucket
A bucket of a layer of the type T in a tile’s layout, of the bucket type B, with the layer’s values it was laid out with and the rest of what the layout’s contents hold for the tile’s draws.
LayerValues
A layer’s values of its style half T: its style, its paint values in transition, and their evaluation for the last frame.
LayoutCx
What a layout reads of its tile while it selects features.
PrepareCx
What a layer’s Layer::prepare reads and changes: its base and values, its values of the tiles it draws (TileMap), which the frame and its drapes share, by the tiles’ own ids (FrameTile::id), and the frame it makes its draws for, the map’s or a drape’s.
QueryRegion
Where a query looks in a tile: its geometry in tile units, seen through the camera.
SurfaceLight
The shading that the surface adds to a stack’s drapes, which hold a hillshade’s slopes, as the hillshade’s own draws would shade them: so that a hillshade lit from the viewport keeps its drapes as the map turns, while its light stays where the viewport puts it.
TileCx
What a layer’s Layer::tile reads to make a tile’s value.
UpdateCx
What a layer’s Layer::update reads, besides its tiles.

Enums§

NoTiles
No tiles, for a layer without a source, which picks what it draws itself.
OnTerrain
How a layer type meets terrain.
RasterTile
What a raster tile, or a tile that an image source’s image draws in, holds for a layer: an image, and the parts of the tile it draws.
TileOrder
An order a layer draws its source’s tiles in.

Traits§

Layer
A layer type’s render half: what it makes of its values, its tiles’ data and the frame, whose hooks the engine calls on a render layer of the type (Hosted). The engine keeps the layer’s base, its values of the layer type Type, its value of each tile it draws, a Tile, which the map’s frame and every drape the tile overlaps draw, and its draws (Draws) in the frame and in each drape it draws in.
Layout
How a group of layers of the type T that share their layout becomes a tile’s bucket, on a tile worker: new selects the tile’s features, and once the glyphs and images it asked for are resolved, build makes the bucket.
TileInput
What a layer of the style half T draws from: a kind of tile and what such a tile holds for the layer, its Data.

Functions§

bucket_indexes
The indexes that a bucket’s upload moved vec, one of its vectors, into, which its tile’s geometry keeps and its draws share.
bucket_vertices
The vertices that a bucket’s upload moved vec, one of its vectors, into, which its tile’s geometry keeps.
copied_indexes
Indexes holding a copy of indexes, which a draw owns.
copied_vertices
Vertices of context’s store holding a copy of vertices, which the draws that bind them don’t change: draws replace such vertices instead.
derived_vertices
The vertices that a bucket’s upload made of vec, one of its vectors, with GeometryUpload::derive_vertices, which its tile’s geometry keeps.
layers_by_id
The group’s layers by id, the first of each id kept.
paint_vertices
The vertices of a layer’s data-driven paint values: those that a bucket’s upload moved, which its tile’s geometry keeps, or a copy in context’s store of the values that feature state rewrites, which stay in the bucket, and which the draws copy again each time they change.

Type Aliases§

TileData
What a frame’s tile holds for a layer of the type L: its Layer::Input’s Data.