use super::{DrawCommand, MaterialSource, TextureId, TextureImage, TextureOptions, Vertex};
use crate::Vec2;
use std::{
ops::Range,
sync::atomic::{AtomicU64, Ordering},
};
static NEXT_SOURCE: AtomicU64 = AtomicU64::new(1);
pub(crate) fn next_source() -> u64 {
NEXT_SOURCE.fetch_add(1, Ordering::Relaxed)
}
#[derive(Clone, Debug, Default)]
pub struct GeometryUpdate {
pub from_revision: u64,
pub to_revision: u64,
pub vertices: Vec<Range<usize>>,
pub indices: Vec<Range<usize>>,
}
#[derive(Debug)]
pub struct DrawData {
pub vertices: Vec<Vertex>,
pub indices: Vec<u32>,
pub commands: Vec<DrawCommand>,
pub logical_size: Vec2,
pub scale_factor: f32,
pub revision: u64,
pub source: u64,
pub textures: Vec<TextureImage>,
pub texture_options: std::collections::HashMap<TextureId, TextureOptions>,
pub texture_budget_bytes: u64,
pub texture_binding_budget: usize,
pub geometry_update: Option<GeometryUpdate>,
pub materials: Vec<MaterialSource>,
pub material_uniforms: Vec<u8>,
}
impl DrawData {
pub fn new(logical_size: Vec2, scale_factor: f32) -> Self {
Self {
logical_size,
scale_factor,
..Self::default()
}
}
}
impl Default for DrawData {
fn default() -> Self {
Self {
vertices: Vec::new(),
indices: Vec::new(),
commands: Vec::new(),
logical_size: Vec2::ZERO,
scale_factor: 0.0,
revision: 0,
source: next_source(),
textures: Vec::new(),
texture_options: Default::default(),
texture_budget_bytes: 256 << 20,
texture_binding_budget: 1024,
geometry_update: None,
materials: Vec::new(),
material_uniforms: Vec::new(),
}
}
}