Skip to main content

rotex_types/resource/
descriptors.rs

1use crate::resource::geometry::{IndexFormat, VertexBufferLayout};
2use crate::resource::ids::TextureId;
3
4#[derive(Debug, Clone)]
5pub struct MeshDescriptor {
6    pub vertex_data: Vec<u8>,
7    pub vertex_layout: VertexBufferLayout,
8    pub index_data: Vec<u8>,
9    pub index_format: IndexFormat,
10    pub index_count: u32,
11}
12
13#[derive(Debug, Clone, Copy)]
14pub enum TextureFormat {
15    Rgba8Unorm,
16}
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19pub enum CullMode {
20    None,
21    Front,
22    Back,
23}
24
25impl Default for CullMode {
26    fn default() -> Self {
27        Self::Back
28    }
29}
30
31#[derive(Debug, Clone)]
32pub struct TextureDescriptor {
33    pub width: u32,
34    pub height: u32,
35    pub format: TextureFormat,
36    pub data: Vec<u8>,
37}
38
39#[derive(Debug, Clone)]
40pub struct MaterialDescriptor {
41    pub vertex_shader_spv: Vec<u8>,
42    pub vertex_entry: String,
43    pub fragment_shader_spv: Vec<u8>,
44    pub fragment_entry: String,
45    pub enable_depth: bool,
46    pub cull_mode: CullMode,
47    pub texture: Option<TextureId>,
48}
49
50impl MaterialDescriptor {
51    pub fn new(
52        vertex_shader_spv: Vec<u8>,
53        vertex_entry: String,
54        fragment_shader_spv: Vec<u8>,
55        fragment_entry: String,
56        enable_depth: bool,
57        texture: Option<TextureId>,
58    ) -> Self {
59        Self {
60            vertex_shader_spv,
61            vertex_entry,
62            fragment_shader_spv,
63            fragment_entry,
64            enable_depth,
65            cull_mode: CullMode::default(),
66            texture,
67        }
68    }
69
70    pub fn with_vertex_entry(mut self, entry: impl Into<String>) -> Self {
71        self.vertex_entry = entry.into();
72        self
73    }
74
75    pub fn with_fragment_entry(mut self, entry: impl Into<String>) -> Self {
76        self.fragment_entry = entry.into();
77        self
78    }
79
80    pub fn with_cull_mode(mut self, cull_mode: CullMode) -> Self {
81        self.cull_mode = cull_mode;
82        self
83    }
84}