blob: 1133d7e0cbd675eb94935826f6e012c75cbdc7eb [file] [edit]
// Copyright 2026 the Vello Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! Persistent renderer resources shared across frames.
#[cfg(feature = "text")]
use crate::text::GlyphAtlasResources;
#[cfg(feature = "text")]
use glifo::GlyphPrepCache;
use vello_common::image_cache::ImageCache;
use vello_common::multi_atlas::AtlasConfig;
/// Persistent resources required by Vello GPU for rendering.
///
/// A set of resources must only be used with the renderer instance associated with it.
#[derive(Debug)]
pub struct Resources {
pub(crate) image_cache: ImageCache,
#[cfg(feature = "text")]
pub(crate) glyph_prep_cache: GlyphPrepCache,
#[cfg(feature = "text")]
pub(crate) glyph_resources: Option<GlyphAtlasResources>,
}
impl Resources {
/// Creates resources that are not tied to a renderer yet.
///
/// Renderers create their resources themselves, so this is only needed to build scenes
/// elsewhere, e.g. on another thread, which needs resources for preparing glyphs. Scenes built
/// this way can only be rendered with other resources if they do not reference images uploaded
/// to these resources and do not cache glyphs in the atlas.
pub fn new(image_atlas_config: AtlasConfig) -> Self {
Self {
image_cache: ImageCache::new_with_config(image_atlas_config),
#[cfg(feature = "text")]
glyph_prep_cache: GlyphPrepCache::default(),
// Will be initialized lazily.
#[cfg(feature = "text")]
glyph_resources: None,
}
}
}