diff options
| author | HampusM <hampus@hampusmat.com> | 2026-03-25 18:59:04 +0100 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-03-25 18:59:04 +0100 |
| commit | cee8b3a19833e1143d0551e8031aa812f7c5a92b (patch) | |
| tree | 16036b06d602df6e2cec401ba1e8a04e1e824e4d /engine/src/reflection.rs | |
| parent | f79037ada7c10a28a882aca0681f796d5e4b6645 (diff) | |
feat(engine): pass vertex subsets to shaders
Diffstat (limited to 'engine/src/reflection.rs')
| -rw-r--r-- | engine/src/reflection.rs | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/engine/src/reflection.rs b/engine/src/reflection.rs index 5bd2aef..3ce424e 100644 --- a/engine/src/reflection.rs +++ b/engine/src/reflection.rs @@ -1,5 +1,5 @@ use std::alloc::Layout; -use std::any::TypeId; +use std::any::{TypeId, type_name}; pub use engine_macros::Reflection; @@ -14,14 +14,25 @@ pub trait With: 'static fn get_reflection(&self) -> &'static Reflection; } -#[derive(Debug, Clone)] +#[derive(Debug)] #[non_exhaustive] pub enum Reflection { Struct(Struct), Array(Array), Slice(Slice), - Literal, + Literal(Literal), +} + +impl Reflection +{ + pub const fn as_struct(&self) -> Option<&Struct> + { + match self { + Self::Struct(struct_reflection) => Some(struct_reflection), + _ => None, + } + } } #[derive(Debug, Clone)] @@ -55,12 +66,24 @@ pub struct Slice pub item_reflection: &'static Reflection, } +#[derive(Debug)] +pub struct Literal +{ + pub layout: Layout, + pub type_id: TypeId, + pub type_name: fn() -> &'static str, +} + macro_rules! impl_with_for_literals { ($($literal: ty),*) => { $( impl With for $literal { - const REFLECTION: &Reflection = &Reflection::Literal; + const REFLECTION: &Reflection = &Reflection::Literal(Literal { + layout: Layout::new::<$literal>(), + type_id: TypeId::of::<$literal>(), + type_name: || type_name::<$literal>() + }); fn reflection() -> &'static Reflection where |
