From: Josh Simmons Date: Sat, 11 May 2024 10:03:46 +0000 (+0200) Subject: narcissus-gpu: Expose `is_null` for `Handle` newtypes X-Git-Url: https://git.nega.tv//gitweb.cgi?a=commitdiff_plain;h=2c608e83f1b8d00191bc743ee6ce4aac2fbee06f;p=josh%2Fnarcissus narcissus-gpu: Expose `is_null` for `Handle` newtypes --- diff --git a/engine/narcissus-gpu/src/lib.rs b/engine/narcissus-gpu/src/lib.rs index fc8e284..10a88f4 100644 --- a/engine/narcissus-gpu/src/lib.rs +++ b/engine/narcissus-gpu/src/lib.rs @@ -48,11 +48,24 @@ pub struct Extent3d { pub depth: u32, } -#[derive(Clone, Copy, PartialEq, Eq, Hash, Default)] -pub struct Image(Handle); +macro_rules! handle_newtype { + ($name:ident) => { + #[derive(Clone, Copy, PartialEq, Eq, Hash, Default)] + pub struct $name(Handle); + + impl $name { + pub fn is_null(self) -> bool { + self.0.is_null() + } + } + }; +} -#[derive(Clone, Copy, PartialEq, Eq, Hash)] -pub struct Buffer(Handle); +handle_newtype!(Image); +handle_newtype!(Buffer); +handle_newtype!(Sampler); +handle_newtype!(BindGroupLayout); +handle_newtype!(Pipeline); impl Buffer { pub fn to_arg(self) -> BufferArg<'static> { @@ -60,15 +73,6 @@ impl Buffer { } } -#[derive(Clone, Copy, PartialEq, Eq, Hash)] -pub struct Sampler(Handle); - -#[derive(Clone, Copy, PartialEq, Eq, Hash)] -pub struct BindGroupLayout(Handle); - -#[derive(Clone, Copy, PartialEq, Eq, Hash)] -pub struct Pipeline(Handle); - #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub enum MemoryLocation { Host,