implemented render backend

This commit is contained in:
LunarAkai 2025-08-03 17:59:47 +02:00
commit f5e9bca56b
10 changed files with 310 additions and 474 deletions

View file

@ -5,3 +5,5 @@ version.workspace = true
authors.workspace = true
[dependencies]
moonhare_window = { path = "../moonhare_window" }
glium = "0.36"

View file

@ -0,0 +1,44 @@
use std::{cell::RefCell, ffi::{c_void, CString}, rc::Rc};
use glium::SwapBuffersError;
use moonhare_window::glfw::Context;
// adopted from the glium repo -> examples -> manual_creation.rs
#[derive(Clone)]
struct Backend {
gl_window: Rc<RefCell<moonhare_window::glfw::Window>>,
}
unsafe impl glium::backend::Backend for Backend {
fn swap_buffers(&self) -> Result<(), SwapBuffersError> {
self.gl_window.borrow_mut().swap_buffers();
Ok(())
}
unsafe fn get_proc_address(&self, symbol: &str) -> *const c_void {
let symbol = CString::new(symbol).unwrap();
self.gl_window
.borrow_mut()
.get_proc_address(&symbol.to_str().unwrap()) as *const _
}
fn get_framebuffer_dimensions(&self) -> (u32, u32) {
let window = &self.gl_window.borrow();
(window.get_size().0 as u32, window.get_size().1 as u32)
}
fn resize(&self, new_size: (u32, u32)) {
let _ = &self.gl_window.borrow_mut().set_size(new_size.0 as i32, new_size.1 as i32);
}
fn is_current(&self) -> bool {
self.gl_window.borrow().is_current()
}
unsafe fn make_current(&self) {
let mut gl_window = self.gl_window.borrow_mut();
gl_window.make_current();
}
}

View file

@ -1,4 +1,3 @@
//! Crate for providing an abstraction layer over different graphics APIs
pub mod graphics_server;
pub mod shader;
pub mod shader;
pub mod backend;