1#![cfg_attr(
11 feature = "std",
12 doc = r##"
13```rust
14use mint::{ColumnMatrix4, Vector3};
15use crevice_notan::glsl::GlslStruct;
16
17#[derive(GlslStruct)]
18struct SpotLight {
19 transform: ColumnMatrix4<f32>,
20 color: Vector3<f32>,
21 intensity: f32,
22}
23
24println!("{}", SpotLight::glsl_definition());
25```
26"##
27)]
28pub use crevice_notan_derive::GlslStruct;
40
41#[allow(clippy::missing_safety_doc)]
44pub unsafe trait Glsl {
45 const NAME: &'static str;
47}
48
49pub struct GlslField {
51 pub ty: &'static str,
53
54 pub name: &'static str,
56}
57
58#[cfg(feature = "std")]
62#[allow(clippy::missing_safety_doc)]
63pub unsafe trait GlslStruct: Glsl {
64 const FIELDS: &'static [GlslField];
66
67 fn glsl_definition() -> String {
69 let mut output = String::new();
70 output.push_str("struct ");
71 output.push_str(Self::NAME);
72 output.push_str(" {\n");
73
74 for field in Self::FIELDS {
75 output.push('\t');
76 output.push_str(field.ty);
77 output.push(' ');
78 output.push_str(field.name);
79 output.push_str(";\n");
80 }
81
82 output.push_str("};");
83 output
84 }
85}
86
87unsafe impl Glsl for f32 {
88 const NAME: &'static str = "float";
89}
90
91unsafe impl Glsl for f64 {
92 const NAME: &'static str = "double";
93}
94
95unsafe impl Glsl for i32 {
96 const NAME: &'static str = "int";
97}
98
99unsafe impl Glsl for u32 {
100 const NAME: &'static str = "uint";
101}