Skip to main content

wgame_shader_macros/
lib.rs

1//! Procedural macros for deriving shader attribute implementations.
2//!
3//! Provides `#[derive(Attribute)]` and `#[derive(AttributeGlobal)]` for named and
4//! tuple structs. These describe vertex/instance attributes, not uniform packing.
5//!
6//! # Examples
7//!
8//! ```rust
9//! use wgame_shader_macros::{Attribute, AttributeGlobal};
10//!
11//! #[derive(Attribute)]
12//! struct Vertex {
13//!     position: [f32; 3],
14//!     normal: [f32; 3],
15//! }
16//!
17//! #[derive(AttributeGlobal)]
18//! struct InstanceTransforms {
19//!     projection: glam::Mat4,
20//!     view: glam::Mat4,
21//! }
22//! ```
23
24mod attribute;
25
26use proc_macro::TokenStream;
27use quote::{ToTokens, quote};
28
29/// Derives vertex/instance attributes using the canonical `wgame::shader` path.
30#[proc_macro_derive(AttributeGlobal)]
31pub fn attribute_global(input: TokenStream) -> TokenStream {
32    match attribute::derive(input.into(), quote!(wgame::shader)) {
33        Ok(expr) => expr.into_token_stream(),
34        Err(err) => err.into_compile_error(),
35    }
36    .into()
37}
38
39/// Derives vertex/instance attributes using the canonical `wgame_shader` path.
40#[proc_macro_derive(Attribute)]
41pub fn attribute(input: TokenStream) -> TokenStream {
42    match attribute::derive(input.into(), quote!(wgame_shader)) {
43        Ok(expr) => expr.into_token_stream(),
44        Err(err) => err.into_compile_error(),
45    }
46    .into()
47}