summaryrefslogtreecommitdiff
path: root/sys/src
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2025-12-08 19:50:10 -0500
committerMica White <botahamec@outlook.com>2025-12-08 19:50:10 -0500
commit19d831c5b1d56070c193d0c8310272f34ad3160d (patch)
treee3886c715fbd0f63930d4a43f964ea1e575785ba /sys/src
parentea5db5846bc700f0da912225ddcb4be372359044 (diff)
Diffstat (limited to 'sys/src')
-rw-r--r--sys/src/lib.rs32
-rw-r--r--sys/src/window.rs25
2 files changed, 41 insertions, 16 deletions
diff --git a/sys/src/lib.rs b/sys/src/lib.rs
index ddce186..6d20488 100644
--- a/sys/src/lib.rs
+++ b/sys/src/lib.rs
@@ -1,4 +1,5 @@
-use std::ffi::{c_uchar, c_uint, c_void};
+use std::ffi::{c_int, c_uint, c_void};
+use std::num::NonZeroU32;
use std::os::raw::c_char;
mod renderer;
@@ -9,18 +10,24 @@ pub use window::{Window, WindowConfig, WindowEvent};
type CRenderer = *mut ();
type CWindow = *mut ();
+type CVertexBuffer = c_int;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(C)]
pub struct RendererConfig {
pub width: c_uint,
pub height: c_uint,
- pub instance_capacity: c_uint,
- pub fullscreen: bool,
pub vsync: bool,
}
#[repr(C)]
+pub struct DrawCommand {
+ vertex_count: c_uint,
+ start: c_uint,
+ end: c_uint,
+}
+
+#[repr(C)]
pub struct Vertex {
x: f32,
y: f32,
@@ -31,9 +38,6 @@ pub struct Vertex {
color1_g: f32,
color1_b: f32,
color1_a: f32,
- normal_x: f32,
- normal_y: f32,
- normal_z: f32,
}
#[derive(Debug, Clone, Copy)]
@@ -63,8 +67,8 @@ pub enum CWindowEvent {
extern "C" {
fn new_renderer(config: RendererConfig, window: CWindow) -> CRenderer;
fn resize_renderer(renderer: CRenderer, width: c_uint, height: c_uint);
+ fn is_vsync_available(renderer: CRenderer) -> bool;
fn set_vsync(renderer: CRenderer, vsync: bool);
- //fn create_vertex_buffer(renderer: CRenderer, count: c_uint, instances: *const Vertex);
fn set_camera(
renderer: CRenderer,
x: f32,
@@ -74,6 +78,12 @@ extern "C" {
width: f32,
height: f32,
);
+ //fn create_mesh(
+ // renderer: CRenderer,
+ // vertex_count: c_uint,
+ // vertices: *const Vertex,
+ //) -> CVertexBuffer;
+ fn destroy_vertex_buffer(renderer: CRenderer, buffer: CVertexBuffer);
fn render_frame(renderer: CRenderer);
fn destroy_renderer(renderer: CRenderer);
@@ -96,3 +106,11 @@ unsafe extern "C" fn alligator_run_closure(closure: *mut c_void, event: CWindowE
let closure: &mut &mut dyn FnMut(CWindowEvent) = unsafe { &mut *closure.cast() };
closure(event)
}
+
+// avoid linking errors in windows
+
+#[no_mangle]
+extern "C" fn __imp__CrtDbgReport() {}
+
+#[no_mangle]
+extern "C" fn __imp__invalid_parameter() {}
diff --git a/sys/src/window.rs b/sys/src/window.rs
index f9a8832..e66747d 100644
--- a/sys/src/window.rs
+++ b/sys/src/window.rs
@@ -1,13 +1,13 @@
-use std::ffi::{c_void, CString};
-use std::ops::ControlFlow;
+use std::ffi::CString;
+use std::num::NonZeroU32;
use crate::{CWindowConfig, CWindowEvent};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct WindowConfig {
- pub title: String,
- pub default_width: u32,
- pub default_height: u32,
+ pub title: Option<String>,
+ pub default_width: NonZeroU32,
+ pub default_height: NonZeroU32,
pub default_x: u32,
pub default_y: u32,
pub visible: bool,
@@ -34,18 +34,24 @@ impl Drop for Window {
impl Window {
pub fn new(config: WindowConfig) -> Self {
- let title = CString::new(config.title.as_bytes()).unwrap();
+ let title = config
+ .title
+ .map(|title| CString::new(title.as_bytes()).unwrap());
let config = CWindowConfig {
- default_width: config.default_width,
- default_height: config.default_height,
+ default_width: config.default_width.get(),
+ default_height: config.default_height.get(),
default_x: config.default_x,
default_y: config.default_y,
visible: config.visible,
borderless_fullscreen: config.borderless_fullscreen,
- title: title.as_ptr(),
+ title: title
+ .as_ref()
+ .map(|title| title.as_ptr())
+ .unwrap_or(std::ptr::null()),
};
let window = unsafe { crate::create_window(config) };
+ drop(title);
Self { ptr: window }
}
@@ -58,6 +64,7 @@ impl Window {
let string = CString::new(title.to_string().as_bytes()).unwrap();
let bytes = string.as_ptr();
unsafe { crate::set_title(self.ptr, bytes) }
+ drop(string);
}
pub fn resize(&mut self, width: u32, height: u32) {