#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Hash)]
pub enum BufferUsage {
#[default]
Default = 0,
Static = 1,
Dynamic = 2,
Streaming = 3,
ReadOnly = 4,
WriteOnly = 5,
}
impl BufferUsage {
#[inline]
pub fn from_u32(value: u32) -> Option<Self> {
match value {
0 => Some(Self::Default),
1 => Some(Self::Static),
2 => Some(Self::Dynamic),
3 => Some(Self::Streaming),
4 => Some(Self::ReadOnly),
5 => Some(Self::WriteOnly),
_ => None,
}
}
#[inline]
pub const fn name(&self) -> &'static str {
match self {
Self::Default => "Default",
Self::Static => "Static",
Self::Dynamic => "Dynamic",
Self::Streaming => "Streaming",
Self::ReadOnly => "ReadOnly",
Self::WriteOnly => "WriteOnly",
}
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct BufferCapabilities(pub u32);
impl BufferCapabilities {
pub const NONE: Self = Self(0);
pub const CPU_ACCESSIBLE: Self = Self(1 << 0);
pub const GPU_ACCESSIBLE: Self = Self(1 << 1);
pub const DMA_CAPABLE: Self = Self(1 << 2);
pub const CONTIGUOUS: Self = Self(1 << 3);
pub const VIDEO_MEMORY: Self = Self(1 << 4);
pub const SHAREABLE: Self = Self(1 << 5);
pub const RESIZABLE: Self = Self(1 << 6);
pub const READABLE: Self = Self(1 << 7);
pub const WRITABLE: Self = Self(1 << 8);
#[inline]
pub const fn has(&self, flag: Self) -> bool {
(self.0 & flag.0) != 0
}
#[inline]
pub const fn with(&self, flag: Self) -> Self {
Self(self.0 | flag.0)
}
#[inline]
pub const fn without(&self, flag: Self) -> Self {
Self(self.0 & !flag.0)
}
#[inline]
pub const fn bits(&self) -> u32 {
self.0
}
}
impl core::ops::BitOr for BufferCapabilities {
type Output = Self;
#[inline]
fn bitor(self, rhs: Self) -> Self {
Self(self.0 | rhs.0)
}
}
impl core::ops::BitAnd for BufferCapabilities {
type Output = Self;
#[inline]
fn bitand(self, rhs: Self) -> Self {
Self(self.0 & rhs.0)
}
}
impl core::ops::BitOrAssign for BufferCapabilities {
#[inline]
fn bitor_assign(&mut self, rhs: Self) {
self.0 |= rhs.0;
}
}