]> git.nega.tv - josh/narcissus/commitdiff
narcissus-gpu: Expose `is_null` for `Handle` newtypes
authorJosh Simmons <josh@nega.tv>
Sat, 11 May 2024 10:03:46 +0000 (12:03 +0200)
committerJosh Simmons <josh@nega.tv>
Sat, 11 May 2024 10:03:46 +0000 (12:03 +0200)
engine/narcissus-gpu/src/lib.rs

index fc8e284ef23745a5ed165b823ee81a8d47310ad0..10a88f4a32e8f0d9160e4234b1277cb070a9b49d 100644 (file)
@@ -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,