summaryrefslogtreecommitdiff
path: root/bindgen/rust/src/ral.rs
blob: 6c196f8b4ff465469def37690a8ff8457f787ce9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//! Wrapper around the RAL code in celeritas-core

use std::{os::raw::c_void, ptr};

use celeritas_sys::{
    BufferHandle, GPU_CmdEncoder, GPU_CmdEncoder_BeginRender, GPU_CmdEncoder_EndRender,
    GPU_GetDefaultEncoder, GPU_GetDefaultRenderpass, GPU_GraphicsPipeline_Create,
    GraphicsPipelineDesc, ShaderData,
};

/// Holds a pointer to the raw `GPU_CmdEncoder`
pub struct FrameRenderEncoder(*mut GPU_CmdEncoder);

/// Holds a pointer to the raw `GPU_Renderpass`
pub struct RenderPass(*mut celeritas_sys::GPU_Renderpass);

/// Holds a pointer to the raw `GPU_Pipeline`
pub struct Pipeline(*mut celeritas_sys::GPU_Pipeline);

impl FrameRenderEncoder {
    pub fn new(renderpass: &RenderPass) -> Self {
        let enc = unsafe {
            let enc = GPU_GetDefaultEncoder();
            GPU_CmdEncoder_BeginRender(enc, renderpass.0);
            enc
        };
        FrameRenderEncoder(enc)
    }
}

impl Drop for FrameRenderEncoder {
    fn drop(&mut self) {
        unsafe {
            GPU_CmdEncoder_EndRender(self.0);
        }
    }
}

impl FrameRenderEncoder {
    pub fn set_vertex_buffer(&self, buf: BufferHandle) {
        // TODO: Get buffer ptr from handle
        // TODO: assert that buffer type is vertex
        todo!()
    }
    pub fn set_index_buffer(&self, buf: BufferHandle) {
        // TODO: Get buffer ptr from handle
        // TODO: assert that buffer type is index
        todo!()
    }
}

pub struct PipelineBuilder {
    renderpass: Option<RenderPass>,
    data_layouts: Vec<()>,
}
impl PipelineBuilder {
    // pub fn add_

    pub fn build(self) -> Pipeline {
        let shad = ShaderData {
            get_layout: todo!(),
            data: ptr::null_mut(),
        };
        let desc = GraphicsPipelineDesc {
            debug_name: todo!(),
            vertex_desc: todo!(),
            vs: todo!(),
            fs: todo!(),
            data_layouts: todo!(),
            data_layouts_count: todo!(),
            wireframe: todo!(),
            depth_test: todo!(),
        };
        let p = unsafe {
            GPU_GraphicsPipeline_Create(
                todo!(),
                self.renderpass
                    .map(|r| r.0)
                    .unwrap_or(GPU_GetDefaultRenderpass()),
            )
        };
        Pipeline(p)
    }
}
// impl Default for PipelineBuilder {
//     fn default() -> Self {
//         Self {
//             renderpass: Default::default(),

//         }
//     }
// }

// --- types

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum PrimitiveTopology {
    Point,
    Line,
    Triangle,
}
impl From<celeritas_sys::PrimitiveTopology> for PrimitiveTopology {
    fn from(value: celeritas_sys::PrimitiveTopology) -> Self {
        match value {
            celeritas_sys::PrimitiveTopology_PRIMITIVE_TOPOLOGY_POINT => PrimitiveTopology::Point,
            celeritas_sys::PrimitiveTopology_PRIMITIVE_TOPOLOGY_LINE => PrimitiveTopology::Line,
            celeritas_sys::PrimitiveTopology_PRIMITIVE_TOPOLOGY_TRIANGLE => {
                PrimitiveTopology::Triangle
            }
            _ => unreachable!("enum conversion should be infallible"),
        }
    }
}