From 19d831c5b1d56070c193d0c8310272f34ad3160d Mon Sep 17 00:00:00 2001 From: Mica White Date: Mon, 8 Dec 2025 19:50:10 -0500 Subject: Stuff --- sys/alligator_backend.lib | Bin 625152 -> 0 bytes sys/build.rs | 7 ++----- sys/src/lib.rs | 32 +++++++++++++++++++++++++------- sys/src/window.rs | 25 ++++++++++++++++--------- 4 files changed, 43 insertions(+), 21 deletions(-) delete mode 100644 sys/alligator_backend.lib (limited to 'sys') diff --git a/sys/alligator_backend.lib b/sys/alligator_backend.lib deleted file mode 100644 index 1b79670..0000000 Binary files a/sys/alligator_backend.lib and /dev/null differ diff --git a/sys/build.rs b/sys/build.rs index 8efc265..1703b4a 100644 --- a/sys/build.rs +++ b/sys/build.rs @@ -1,8 +1,5 @@ fn main() { - let out_dir = std::env::var("OUT_DIR").unwrap(); - eprintln!("{out_dir}"); - println!("cargo:rustc-link-lib=d3d11"); - println!("cargo:rustc-link-search=native=./"); - println!("cargo:rustc-link-lib-static=alligator_backend"); + println!("cargo:rustc-link-lib=static=alligator_backend"); + println!("cargo:rustc-link-search=native=C:\\Users\\epice\\source\\repos\\WindowsAlligatorBackend\\x64\\Debug\\"); println!("cargo:rerun-if-changed=alligator_backend.lib"); } 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,17 +10,23 @@ 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, @@ -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, + 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) { -- cgit v1.2.3