aboutsummaryrefslogtreecommitdiff
path: root/stockton-render/src/draw/macros.rs
diff options
context:
space:
mode:
authortcmal <me@aria.rip>2024-08-25 17:44:21 +0100
committertcmal <me@aria.rip>2024-08-25 17:44:21 +0100
commit939fde5ca405342ab4c52ee3da81fb2daa192e3e (patch)
tree0920ca9e70760b2cad50707020a9808ddaa0eca4 /stockton-render/src/draw/macros.rs
parent48ebe87925c4aca8fb9ab8f120b327b677f6812c (diff)
refactor(draw): use macro for buffer attribute descriptions
Diffstat (limited to 'stockton-render/src/draw/macros.rs')
-rw-r--r--stockton-render/src/draw/macros.rs101
1 files changed, 101 insertions, 0 deletions
diff --git a/stockton-render/src/draw/macros.rs b/stockton-render/src/draw/macros.rs
new file mode 100644
index 0000000..d191d5b
--- /dev/null
+++ b/stockton-render/src/draw/macros.rs
@@ -0,0 +1,101 @@
+// Copyright (C) Oscar Shrimpton 2019
+
+// This program is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation, either version 3 of the License, or (at your option)
+// any later version.
+
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this program. If not, see <http://www.gnu.org/licenses/>.
+//! Helper macros, mostly for the graphics pipeline definitions
+
+/// Macro for easily defining buffer attribute descriptions
+/// Usage:
+/// ```
+/// // 0 is the binding value
+/// let attributes: Vec<AttributeDesc> = pipeline_vb_attributes!(0,
+/// size_of::<f32>() * 3; Rgb32Sfloat
+/// size_of::<f32>() * 2; Rg32Sfloat,
+/// size_of::<u32>(); R32Sint
+/// );
+/// ```
+/// See the hal::pso::Format enum for possible types
+macro_rules! pipeline_vb_attributes {
+ // Start of recursion
+ ( $binding:expr,
+ $firstSize:expr; $firstType:ident,
+ $( $size:expr; $type:ident ),*
+ ) => ({
+ use hal::pso::{AttributeDesc, Element};
+
+ let mut vec = Vec::new();
+
+ vec.push(AttributeDesc {
+ location: 0,
+ binding: $binding,
+ element: Element {
+ format: Format::$firstType,
+ offset: 0
+ }
+ });
+
+ pipeline_vb_attributes!(
+ vec; $binding; 1; $firstSize,
+ $($size; $type),*
+ );
+
+ vec
+ });
+
+ // Special case for single item
+ ( $binding:expr; $firstSize:expr; $firstType:ident ) => ({
+ vec![
+ AttributeDesc {
+ location: 0,
+ binding: $binding,
+ element: Element {
+ format: Format::$firstType,
+ offset: $firstSize as u32
+ }
+ }
+ ]
+ });
+
+ // Middle of recursion
+ ( $vec:ident; $binding:expr; $location:expr; $prevSize:expr,
+ $firstSize:expr; $firstType:ident,
+ $($size:expr; $type:ident),* ) => ({
+
+ $vec.push(AttributeDesc {
+ location: $location,
+ binding: $binding,
+ element: Element {
+ format: Format::$firstType,
+ offset: $prevSize as u32
+ }
+ });
+
+ pipeline_vb_attributes!(
+ $vec; $binding; ($location + 1); ($prevSize + $firstSize),
+ $($size; $type),*
+ );
+ });
+
+ // End of recursion
+ ( $vec:ident; $binding:expr; $location:expr; $prevSize:expr,
+ $firstSize:expr; $firstType:ident ) => ({
+ $vec.push(AttributeDesc {
+ location: $location,
+ binding: $binding,
+ element: Element {
+ format: Format::$firstType,
+ offset: $prevSize as u32
+ }
+ });
+ });
+} \ No newline at end of file