summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bindgen/rust/src/lib.rs6
-rw-r--r--bindgen/rust/src/ral.rs61
2 files changed, 65 insertions, 2 deletions
diff --git a/bindgen/rust/src/lib.rs b/bindgen/rust/src/lib.rs
index 49d0391..c8e56df 100644
--- a/bindgen/rust/src/lib.rs
+++ b/bindgen/rust/src/lib.rs
@@ -8,6 +8,8 @@ pub use celeritas_sys as ffi;
/// Commonly used types
pub mod prelude;
+pub mod ral;
+
use std::{
fs::{self, File},
io::Write,
@@ -26,7 +28,7 @@ pub struct ModelPath(String);
#[derive(Debug, Serialize, Deserialize)]
pub struct ModelNode {
model_path: ModelPath,
- transform: Transform
+ transform: Transform,
}
/// Scene that can be saved and loaded from disk
@@ -61,4 +63,4 @@ pub enum Light {
Point(ffi::PointLight),
Directional(ffi::DirectionalLight),
// Spot(ffi::Spotlight)
-} \ No newline at end of file
+}
diff --git a/bindgen/rust/src/ral.rs b/bindgen/rust/src/ral.rs
new file mode 100644
index 0000000..f9c44e4
--- /dev/null
+++ b/bindgen/rust/src/ral.rs
@@ -0,0 +1,61 @@
+//! Wrapper around the RAL code in celeritas-core
+
+use celeritas_sys::{
+ BufferHandle, GPU_Buffer, GPU_CmdEncoder, GPU_CmdEncoder_BeginRender, GPU_CmdEncoder_EndRender, GPU_GetDefaultEncoder
+};
+
+pub struct FrameRenderEncoder(*mut GPU_CmdEncoder);
+
+/// Holds a pointer into the raw `GPU_Renderpass`
+pub struct RenderPass(*mut celeritas_sys::GPU_Renderpass);
+
+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!()
+ }
+}
+
+// --- 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")
+ }
+ }
+} \ No newline at end of file