mln_engine/draw/mod.rs
1//! What a layer draws with: the other half of the [layer
2//! contract](crate::layer).
3//!
4//! A layer makes its GPU objects through the [`Resources`] its hooks get and
5//! keeps their handles: [`VertexBuffer`]s of `#[repr(C)]` vertices, which a
6//! mesh reads as the attributes of a layout ([`VertexBinding`], [`Vertex`]),
7//! [`IndexBuffer`]s and [`Texture`]s; [`Mesh`]es, which draw a program over
8//! them ([`MeshDesc`]), a [`DrawRange`] in each draw call; and [`Target`]s,
9//! textures of the layer's own that its draws draw into ahead of the frame
10//! and that its other draws sample. Meshes share the buffers and textures
11//! they read. An object goes once its last handle drops and the GPU is done
12//! with it.
13//!
14//! Each frame, a layer pushes its draws into its [`Draws`]: into its main
15//! [`Group`], which draws at its place in the layers' order and depth, and
16//! into the groups of its targets. A [`Draw`] of a mesh says where it is
17//! among the group's draws, whether it may draw in the opaque pass, how it
18//! tests depth ([`Depth`]) and whether it clips to its tile, and comes with
19//! the values of its program's blocks of each draw and, for a draw of a
20//! tile, the tile's projection ([`projection`]). The engine writes the
21//! blocks once for the group, uploads the meshes, and draws the group in
22//! the frame's passes.
23//!
24//! A layer sees its frame as a [`LayerFrame`]: the map's, or a drape's. A
25//! layer that draws with the backend's own commands asks the frame to lend
26//! them ([`Draws::lend`]), at a time in the frame ([`LendAt`]), and gets them
27//! with the frame and where it draws the map ([`Lent`]). What it makes with
28//! them, the engine doesn't know of: the layer frees it once the GPU is done
29//! with it, through work it queues for after the GPU ([`AfterGpu`]).
30//!
31//! The objects and their handles belong to the renderer's thread.
32//!
33//! Inside the engine, the renderer's graphics state over its backend's `Gpu`
34//! (`context`) keeps the stores of what draws share, and the queue that
35//! releases it in order.
36
37pub(crate) mod after_gpu;
38pub(crate) mod buffer;
39pub(crate) mod context;
40pub(crate) mod draws;
41pub(crate) mod dynamic_texture;
42pub(crate) mod dynamic_texture_atlas;
43pub(crate) mod identity;
44pub(crate) mod indexes;
45pub(crate) mod objects;
46pub(crate) mod owned;
47pub mod projection;
48pub(crate) mod range;
49pub(crate) mod release;
50pub(crate) mod resources;
51pub(crate) mod store;
52pub(crate) mod target;
53pub(crate) mod texture2d;
54pub(crate) mod tile_render_data;
55pub(crate) mod uniform_buffer;
56pub(crate) mod upload;
57pub(crate) mod vertex;
58pub(crate) mod vertex_attribute;
59pub(crate) mod vertices;
60
61use mln_gfx::gfx_types::AttributeDataType;
62use mln_gfx::shaders::program::Attribute;
63
64/// Binds again in `mesh` the vertices of its bucket's paint values that
65/// `refresh` makes, where `changes` says feature state rewrote them: a
66/// layer's [`prepare`](crate::layer::Layer::prepare) calls it with what its
67/// tile's entry took (`TileEntry::take_changes`).
68pub fn refresh_paint_attributes(
69 mesh: &Mesh,
70 res: &mut Resources<'_>,
71 changes: crate::layer::BucketChanges,
72 refresh: impl FnOnce(&mut Resources<'_>) -> Option<VertexBinding>,
73) {
74 if changes.paint
75 && let Some(paint) = refresh(res)
76 {
77 mesh.set_paint(res, &paint);
78 }
79}
80
81/// The attribute `pos`, a vertex's position: two 16-bit integers, in tile
82/// units for a vertex of a tile.
83pub const POS: Attribute = Attribute::new("pos", AttributeDataType::Short2);
84
85pub use crate::draw::after_gpu::{AfterGpu, GpuEnd};
86pub use crate::draw::draws::{Depth, Draw, Draws, Group, LayerFrame, LendAt, Lent};
87pub use crate::draw::objects::{Mesh, MeshDesc, Textures};
88pub use crate::draw::range::DrawRange;
89pub use crate::draw::resources::Resources;
90pub use crate::draw::store::{IndexBuffer, Texture};
91pub use crate::draw::target::Target;
92pub use crate::draw::vertex::{Vertex, VertexAttribute, VertexBinding};
93pub use crate::draw::vertex_attribute::Uniforms;
94pub use crate::draw::vertices::VertexBuffer;
95pub use crate::render::layer_composite::Composite;
96pub use crate::render::light::EvaluatedLight;
97pub use crate::render::pass::RenderPass;
98pub use crate::render::tile::RenderTile;
99
100/// The grid of a tile on the globe, which a layer that draws whole tiles
101/// draws there, and the rows of the poles' vertices.
102pub mod globe {
103 pub use crate::render::globe::tile_mesh::{TileMesh, tile_mesh};
104 pub use crate::render::globe::{NORTH_POLE_Y, SOUTH_POLE_Y};
105}
106
107/// What a program of a layer that stands on terrain or hides behind it
108/// declares. A program of a layer whose type stands on terrain
109/// ([`OnTerrain::Stands`](crate::layer::OnTerrain::Stands)) declares the
110/// attribute [`GROUND_HEIGHT`](crate::draw::ground::GROUND_HEIGHT), which the engine fills, for a draw of its
111/// terrain variant, with the height of the ground under each of the draw's
112/// points; one whose type hides behind the ground in front of it declares the
113/// texture [`GROUND_DEPTH`](crate::draw::ground::GROUND_DEPTH), which the engine binds to the depth of the
114/// frame's ground.
115pub mod ground {
116 pub use crate::render::terrain::programs::{GROUND_DEPTH, GROUND_HEIGHT};
117 pub use crate::render::terrain::{
118 FrameGround, GroundHeights, StandingDraw, TerrainElevation, TileGround, height_binding, point_center,
119 };
120
121 /// The GLSL snippets of the ground: `ground_visibility!()`, which a
122 /// program that hides behind the ground declares, and
123 /// `hillshade_shading!()`, the hillshade's shading of its slopes, which
124 /// the terrain's surface shades a lit hillshade's drapes with.
125 pub mod glsl {
126 pub use crate::{
127 terrain_glsl_ground_visibility as ground_visibility, terrain_glsl_hillshade_shading as hillshade_shading,
128 };
129 }
130
131 /// [`glsl`]'s snippets in GLSL ES.
132 pub mod glsl_es {
133 pub use crate::{
134 terrain_glsl_es_ground_visibility as ground_visibility,
135 terrain_glsl_es_hillshade_shading as hillshade_shading,
136 };
137 }
138
139 /// [`glsl`]'s snippets in MSL.
140 pub mod msl {
141 pub use crate::{
142 terrain_msl_ground_visibility as ground_visibility, terrain_msl_hillshade_shading as hillshade_shading,
143 };
144 }
145
146 /// [`glsl`]'s snippets in WGSL.
147 pub mod wgsl {
148 pub use crate::{
149 terrain_wgsl_ground_visibility as ground_visibility, terrain_wgsl_hillshade_shading as hillshade_shading,
150 };
151 }
152}