mln-rs-engine 0.0.22

Part of mln-rs, a MapLibre map renderer written in Rust. Depend on mln-rs instead.
Documentation
//! What a layer draws with: the other half of the [layer
//! contract](crate::layer).
//!
//! A layer makes its GPU objects through the [`Resources`] its hooks get and
//! keeps their handles: [`VertexBuffer`]s of `#[repr(C)]` vertices, which a
//! mesh reads as the attributes of a layout ([`VertexBinding`], [`Vertex`]),
//! [`IndexBuffer`]s and [`Texture`]s; [`Mesh`]es, which draw a program over
//! them ([`MeshDesc`]), a [`DrawRange`] in each draw call; and [`Target`]s,
//! textures of the layer's own that its draws draw into ahead of the frame
//! and that its other draws sample. Meshes share the buffers and textures
//! they read. An object goes once its last handle drops and the GPU is done
//! with it.
//!
//! Each frame, a layer pushes its draws into its [`Draws`]: into its main
//! [`Group`], which draws at its place in the layers' order and depth, and
//! into the groups of its targets. A [`Draw`] of a mesh says where it is
//! among the group's draws, whether it may draw in the opaque pass, how it
//! tests depth ([`Depth`]) and whether it clips to its tile, and comes with
//! the values of its program's blocks of each draw and, for a draw of a
//! tile, the tile's projection ([`projection`]). The engine writes the
//! blocks once for the group, uploads the meshes, and draws the group in
//! the frame's passes.
//!
//! A layer sees its frame as a [`LayerFrame`]: the map's, or a drape's. A
//! layer that draws with the backend's own commands asks the frame to lend
//! them ([`Draws::lend`]), at a time in the frame ([`LendAt`]), and gets them
//! with the frame and where it draws the map ([`Lent`]). What it makes with
//! them, the engine doesn't know of: the layer frees it once the GPU is done
//! with it, through work it queues for after the GPU ([`AfterGpu`]).
//!
//! The objects and their handles belong to the renderer's thread.
//!
//! Inside the engine, the renderer's graphics state over its backend's `Gpu`
//! (`context`) keeps the stores of what draws share, and the queue that
//! releases it in order.

pub(crate) mod after_gpu;
pub(crate) mod buffer;
pub(crate) mod context;
pub(crate) mod draws;
pub(crate) mod dynamic_texture;
pub(crate) mod dynamic_texture_atlas;
pub(crate) mod identity;
pub(crate) mod indexes;
pub(crate) mod objects;
pub(crate) mod owned;
pub mod projection;
pub(crate) mod range;
pub(crate) mod release;
pub(crate) mod resources;
pub(crate) mod store;
pub(crate) mod target;
pub(crate) mod texture2d;
pub(crate) mod tile_render_data;
pub(crate) mod uniform_buffer;
pub(crate) mod upload;
pub(crate) mod vertex;
pub(crate) mod vertex_attribute;
pub(crate) mod vertices;

use mln_gfx::gfx_types::AttributeDataType;
use mln_gfx::shaders::program::Attribute;

/// Binds again in `mesh` the vertices of its bucket's paint values that
/// `refresh` makes, where `changes` says feature state rewrote them: a
/// layer's [`prepare`](crate::layer::Layer::prepare) calls it with the
/// changes it took of its tile (`TileMap::take_changes`).
pub fn refresh_paint_attributes(
    mesh: &Mesh,
    res: &mut Resources<'_>,
    changes: crate::layer::BucketChanges,
    refresh: impl FnOnce(&mut Resources<'_>) -> Option<VertexBinding>,
) {
    if changes.paint
        && let Some(paint) = refresh(res)
    {
        mesh.set_paint(res, &paint);
    }
}

/// The attribute `pos`, a vertex's position: two 16-bit integers, in tile
/// units for a vertex of a tile.
pub const POS: Attribute = Attribute::new("pos", AttributeDataType::Short2);

pub use crate::draw::after_gpu::{AfterGpu, GpuEnd};
pub use crate::draw::draws::{Depth, Draw, Draws, Group, LayerFrame, LendAt, Lent};
pub use crate::draw::objects::{Mesh, MeshDesc, Textures};
pub use crate::draw::range::DrawRange;
pub use crate::draw::resources::Resources;
pub use crate::draw::store::{IndexBuffer, Texture};
pub use crate::draw::target::Target;
pub use crate::draw::vertex::{Vertex, VertexAttribute, VertexBinding};
pub use crate::draw::vertex_attribute::Uniforms;
pub use crate::draw::vertices::VertexBuffer;
pub use crate::render::layer_composite::Composite;
pub use crate::render::light::EvaluatedLight;
pub use crate::render::pass::RenderPass;
pub use crate::render::tile::RenderTile;

/// The grid of a tile on the globe, which a layer that draws whole tiles
/// draws there, and the rows of the poles' vertices.
pub mod globe {
    pub use crate::render::globe::tile_mesh::{TileMesh, tile_mesh};
    pub use crate::render::globe::{NORTH_POLE_Y, SOUTH_POLE_Y};
}

/// What a program of a layer that stands on terrain or hides behind it
/// declares. A program of a layer whose type stands on terrain
/// ([`OnTerrain::Stands`](crate::layer::OnTerrain::Stands)) declares the
/// attribute [`GROUND_HEIGHT`](crate::draw::ground::GROUND_HEIGHT), which the engine fills, for a draw of its
/// terrain variant, with the height of the ground under each of the draw's
/// points; one whose type hides behind the ground in front of it declares the
/// texture [`GROUND_DEPTH`](crate::draw::ground::GROUND_DEPTH), which the engine binds to the depth of the
/// frame's ground.
pub mod ground {
    pub use crate::render::terrain::programs::{GROUND_DEPTH, GROUND_HEIGHT};
    pub use crate::render::terrain::{
        FrameGround, GroundHeights, StandingDraw, TerrainElevation, TileGround, height_binding, point_center,
    };

    /// The GLSL snippets of the ground: `ground_visibility!()`, which a
    /// program that hides behind the ground declares, and
    /// `hillshade_shading!()`, the hillshade's shading of its slopes, which
    /// the terrain's surface shades a lit hillshade's drapes with.
    pub mod glsl {
        pub use crate::{
            terrain_glsl_ground_visibility as ground_visibility, terrain_glsl_hillshade_shading as hillshade_shading,
        };
    }

    /// [`glsl`]'s snippets in MSL.
    pub mod msl {
        pub use crate::{
            terrain_msl_ground_visibility as ground_visibility, terrain_msl_hillshade_shading as hillshade_shading,
        };
    }

    /// [`glsl`]'s snippets in WGSL.
    pub mod wgsl {
        pub use crate::{
            terrain_wgsl_ground_visibility as ground_visibility, terrain_wgsl_hillshade_shading as hillshade_shading,
        };
    }
}