1#![cfg_attr(
11 feature = "std",
12 doc = r##"
13```rust
14use mint::{ColumnMatrix4, Vector3};
15use crevice::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_derive::GlslStruct;
40
41pub unsafe trait Glsl {
44 const NAME: &'static str;
46}
47
48pub struct GlslField {
50 pub ty: &'static str,
52
53 pub name: &'static str,
55}
56
57#[cfg(feature = "std")]
61pub unsafe trait GlslStruct: Glsl {
62 const FIELDS: &'static [GlslField];
64
65 fn glsl_definition() -> String {
67 let mut output = String::new();
68 output.push_str("struct ");
69 output.push_str(Self::NAME);
70 output.push_str(" {\n");
71
72 for field in Self::FIELDS {
73 output.push('\t');
74 output.push_str(field.ty);
75 output.push(' ');
76 output.push_str(field.name);
77 output.push_str(";\n");
78 }
79
80 output.push_str("};");
81 output
82 }
83}
84
85unsafe impl Glsl for f32 {
86 const NAME: &'static str = "float";
87}
88
89unsafe impl Glsl for f64 {
90 const NAME: &'static str = "double";
91}
92
93unsafe impl Glsl for i32 {
94 const NAME: &'static str = "int";
95}
96
97unsafe impl Glsl for u32 {
98 const NAME: &'static str = "uint";
99}