From 2c608e83f1b8d00191bc743ee6ce4aac2fbee06f Mon Sep 17 00:00:00 2001 From: Josh Simmons Date: Sat, 11 May 2024 12:03:46 +0200 Subject: [PATCH] narcissus-gpu: Expose `is_null` for `Handle` newtypes --- engine/narcissus-gpu/src/lib.rs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) 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, -- 2.49.0