mln_runtime/render/frame.rs
1//! Frame demands and the results that they finish with.
2
3use mln_map::{MapView, RenderMode};
4use mln_renderer::FrameProjection;
5
6/// When a demand draws a frame.
7#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
8pub enum DemandMode {
9 /// Draws a frame when the map changed since the last one, and otherwise
10 /// finishes with [`FrameDisposition::NoUpdate`].
11 #[default]
12 IfChanged,
13 /// Draws a frame even when nothing changed.
14 Force,
15 /// Draws a frame when the map changed since the last one, and otherwise
16 /// waits for the map's next update.
17 WaitForUpdate,
18}
19
20/// A demand for one frame.
21#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
22pub struct FrameDemand {
23 pub mode: DemandMode,
24 /// A value of the host's choice that the demand's result carries.
25 pub token: u64,
26}
27
28impl FrameDemand {
29 #[must_use]
30 pub fn new(mode: DemandMode, token: u64) -> Self {
31 FrameDemand { mode, token }
32 }
33}
34
35/// How a frame demand finished.
36#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
37pub enum FrameDisposition {
38 Rendered,
39 /// The map had nothing new to draw, or a barrier ended the demand.
40 NoUpdate,
41 /// The session couldn't take the frame, as after a detach or an abandon.
42 TargetNotReady,
43 /// A later demand with the same mode replaced this one.
44 Superseded,
45 /// The session failed. Its snapshot says why.
46 Failed,
47}
48
49/// How one frame demand finished.
50#[derive(Clone, Copy, Debug, PartialEq)]
51pub struct FrameResult {
52 pub disposition: FrameDisposition,
53 /// The token of the demand that the result finishes, or `None` for the
54 /// session's demand of a still image that
55 /// [`Map::request_still_image`](crate::Map::request_still_image) asked
56 /// for.
57 pub token: Option<u64>,
58 /// The map update that a rendered frame shows, or the latest one for a
59 /// demand that rendered nothing. The frame includes a command's change
60 /// when this is at least the command's
61 /// [`render_update_generation`](crate::Applied::render_update_generation).
62 pub map_update_generation: u64,
63 /// The session's generation when it rendered the frame: it grows when the
64 /// session resizes. Zero for a demand that rendered nothing.
65 pub generation: u64,
66 /// Counts the session's rendered frames, this one included. Zero for a
67 /// demand that rendered nothing.
68 pub frame_generation: u64,
69 /// Whether the map has transitions still running after this frame.
70 pub needs_repaint: bool,
71 /// The camera and extent that a rendered frame shows.
72 pub view: Option<MapView>,
73 /// Whether everything that a rendered frame shows had loaded.
74 pub mode: RenderMode,
75 /// Where a rendered frame drew the map, and the depth that it wrote.
76 pub projection: Option<FrameProjection>,
77}
78
79impl FrameResult {
80 /// The result of a demand that rendered nothing.
81 pub(crate) fn unrendered(token: Option<u64>, disposition: FrameDisposition, map_update_generation: u64) -> Self {
82 FrameResult {
83 disposition,
84 token,
85 map_update_generation,
86 generation: 0,
87 frame_generation: 0,
88 needs_repaint: false,
89 view: None,
90 mode: RenderMode::Partial,
91 projection: None,
92 }
93 }
94}