Skip to main content

mln_engine/draw/
tile_render_data.rs

1use crate::draw::dynamic_texture_atlas::{DynamicTextureAtlas, PageId};
2use crate::draw::store::Texture;
3
4/// The glyph and icon (+ pattern) atlas textures of a tile's layout: the
5/// pages its glyphs and images are on, and their GPU textures, which the
6/// atlas makes in the frame's upload.
7#[derive(Clone, Debug, Default)]
8pub struct TileAtlasTextures {
9    glyph_page: Option<PageId>,
10    icon_page: Option<PageId>,
11    glyph: Option<Texture>,
12    icon: Option<Texture>,
13}
14
15impl TileAtlasTextures {
16    /// The textures of the pages `glyph` and `icon`, which `resolve` finds.
17    pub(crate) fn new(glyph: PageId, icon: PageId) -> Self {
18        TileAtlasTextures { glyph_page: Some(glyph), icon_page: Some(icon), glyph: None, icon: None }
19    }
20
21    /// Finds the pages' textures in `atlas`, once it uploaded them.
22    pub(crate) fn resolve(&mut self, atlas: &DynamicTextureAtlas) {
23        if self.glyph.is_none() {
24            self.glyph = self.glyph_page.and_then(|page| atlas.page_texture(page)).cloned();
25        }
26        if self.icon.is_none() {
27            self.icon = self.icon_page.and_then(|page| atlas.page_texture(page)).cloned();
28        }
29    }
30
31    /// The glyph page's texture, once uploaded.
32    #[must_use]
33    pub fn glyph(&self) -> Option<&Texture> {
34        self.glyph.as_ref()
35    }
36
37    /// The icon and pattern page's texture, once uploaded.
38    #[must_use]
39    pub fn icon(&self) -> Option<&Texture> {
40        self.icon.as_ref()
41    }
42}