implemented render backend
This commit is contained in:
parent
5be528cf07
commit
f5e9bca56b
10 changed files with 310 additions and 474 deletions
691
Cargo.lock
generated
691
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -3,7 +3,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use moonhare_log::*;
|
||||
use moonhare_window::{glfw, platforms::glfw_window::GLFWWindow, Window, WindowRenderContext};
|
||||
use moonhare_window::{glfw::{self, PWindow}, platforms::glfw_window::GLFWWindow, Window, WindowRenderContext};
|
||||
|
||||
pub mod basic;
|
||||
|
||||
|
|
@ -32,26 +32,14 @@ impl Game {
|
|||
Game::default()
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
pub fn run_window(mut glfw_w: GLFWWindow) {
|
||||
while !glfw_w.glfw_window.should_close() {
|
||||
glfw_w.glfw.poll_events();
|
||||
for(_, event) in glfw::flush_messages(&glfw_w.events) {
|
||||
Self::handle_window_event(&mut glfw_w.glfw_window, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
pub fn run(self) {
|
||||
info("Running Game...");
|
||||
let mut a = self.glfw_window.unwrap();
|
||||
let mut glfw_window_unwrapped: GLFWWindow = self.glfw_window.unwrap();
|
||||
|
||||
while self.is_running {
|
||||
a.glfw_window.glfw.poll_events();
|
||||
for (_, event) in glfw::flush_messages(&a.events) {
|
||||
GLFWWindow::handle_window_event(&mut a.glfw_window, event);
|
||||
}
|
||||
handle_window_event(&mut glfw_window_unwrapped);
|
||||
// update();
|
||||
// render();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -63,4 +51,12 @@ impl Game {
|
|||
|
||||
fn default_game_name() -> String {
|
||||
"Moonhare Game".to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
/// Deals with GLFW Window Events (in `monhare_window`)
|
||||
fn handle_window_event(glfw_window: &mut GLFWWindow) {
|
||||
glfw_window.glfw_window.glfw.poll_events();
|
||||
for (_, event) in glfw::flush_messages(&glfw_window.events) {
|
||||
GLFWWindow::handle_window_event(&mut glfw_window.glfw_window, event);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,3 +5,5 @@ version.workspace = true
|
|||
authors.workspace = true
|
||||
|
||||
[dependencies]
|
||||
moonhare_window = { path = "../moonhare_window" }
|
||||
glium = "0.36"
|
||||
|
|
|
|||
44
crates/moonhare_graphics/src/backend.rs
Normal file
44
crates/moonhare_graphics/src/backend.rs
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
@ -7,6 +7,4 @@ authors.workspace = true
|
|||
[dependencies]
|
||||
moonhare_log = { path = "../moonhare_log" }
|
||||
moonhare_event = { path = "../moonhare_event" }
|
||||
gtk4 = "*"
|
||||
winit = "0.30"
|
||||
glfw = "*"
|
||||
|
|
@ -24,7 +24,6 @@ pub struct Window {
|
|||
|
||||
|
||||
impl Window {
|
||||
/// creates a glfw window while spawning a new thread that the window runs on.
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn create(context: WindowRenderContext) -> GLFWWindow {
|
||||
match context {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use glfw::{Context, Glfw, GlfwReceiver, PWindow, WindowEvent};
|
||||
use gtk4::gdk::Key;
|
||||
use moonhare_event::{event::{self, Event}, events::window_events::window_close_event::WindowCloseEvent};
|
||||
use moonhare_event::{event::Event, events::window_events::window_close_event::WindowCloseEvent};
|
||||
|
||||
use crate::{window_config, MoonhareWindow};
|
||||
|
||||
|
|
@ -23,7 +22,7 @@ impl GLFWWindow {
|
|||
let (mut window, events) = glfw.create_window(
|
||||
config.width,
|
||||
config.height,
|
||||
format!("{} GLFW", config.title).as_str(),
|
||||
format!("{} GLFW {}", config.title, glfw::get_version_string()).as_str(),
|
||||
glfw::WindowMode::Windowed)
|
||||
.unwrap();
|
||||
|
||||
|
|
@ -39,7 +38,7 @@ impl GLFWWindow {
|
|||
}
|
||||
|
||||
|
||||
pub fn handle_window_event(window: &mut glfw::Window, event: glfw::WindowEvent) {
|
||||
pub fn handle_window_event(_window: &mut glfw::Window, event: glfw::WindowEvent) {
|
||||
match event {
|
||||
glfw::WindowEvent::Close => {
|
||||
WindowCloseEvent::emit();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue