ori_core/image/
texture.rsuse std::sync::atomic::{AtomicU64, Ordering};
use super::Image;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct TextureId {
index: u64,
}
impl Default for TextureId {
fn default() -> Self {
Self::from_index(0)
}
}
impl TextureId {
pub fn new() -> Self {
static NEXT_ID: AtomicU64 = AtomicU64::new(1);
let index = NEXT_ID.fetch_add(1, Ordering::Relaxed);
Self { index }
}
pub const fn from_index(index: u64) -> Self {
Self { index }
}
pub const fn to_index(self) -> u64 {
self.index
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum Texture {
Image(Image),
Backend(TextureId),
}
impl Default for Texture {
fn default() -> Self {
Self::Image(Image::default())
}
}
impl From<Image> for Texture {
fn from(image: Image) -> Self {
Self::Image(image)
}
}
impl From<TextureId> for Texture {
fn from(id: TextureId) -> Self {
Self::Backend(id)
}
}