Huge input update, FPS Camera controls system
Long day. I now store winit:🪟:Window in a mutex.
This commit is contained in:
parent
1e9b997aeb
commit
46c8c32819
15 changed files with 307 additions and 39 deletions
|
|
@ -1,4 +1,5 @@
|
|||
use std::any::Any;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use glium::{uniform, Display, Program, Surface};
|
||||
use glium::glutin::surface::WindowSurface;
|
||||
use glium::texture::{RawImage2d, SrgbTexture2d};
|
||||
|
|
@ -20,7 +21,7 @@ pub struct BasicMeshRenderingSystem {
|
|||
}
|
||||
|
||||
impl RenderingSystem for BasicMeshRenderingSystem {
|
||||
fn initialize(display: &Display<WindowSurface>, _window: &glium::winit::window::Window) -> Self {
|
||||
fn initialize(display: &Display<WindowSurface>, _window: Arc<Mutex<glium::winit::window::Window>>) -> Self {
|
||||
const VERT_SRC: &str = include_shader!("gl_textured.vert");
|
||||
const FRAG_SRC: &str = include_shader!("gl_textured.frag");
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Instant;
|
||||
use glium::Display;
|
||||
use glium::glutin::surface::WindowSurface;
|
||||
|
|
@ -19,17 +20,19 @@ pub struct ImguiBridge {
|
|||
}
|
||||
|
||||
impl RenderingSystem for ImguiBridge {
|
||||
fn handle_event(&mut self, window: &mut Window, event: Event<()>) {
|
||||
self.platform.handle_event(self.imgui.io_mut(), window, &event);
|
||||
fn handle_event(&mut self, window: Arc<Mutex<Window>>, event: Event<()>) {
|
||||
let window = window.lock().unwrap();
|
||||
self.platform.handle_event(self.imgui.io_mut(), &*window, &event);
|
||||
}
|
||||
|
||||
fn prepare_frame(&mut self, window: &mut Window) {
|
||||
fn prepare_frame(&mut self, window: Arc<Mutex<Window>>) {
|
||||
self.rendered_this_frame = false;
|
||||
let now = Instant::now();
|
||||
self.imgui.io_mut().update_delta_time(now - self.last_frame);
|
||||
self.last_frame = now;
|
||||
let window = window.lock().unwrap();
|
||||
self.platform
|
||||
.prepare_frame(self.imgui.io_mut(), window)
|
||||
.prepare_frame(self.imgui.io_mut(), &*window)
|
||||
.expect("Failed to prepare frame");
|
||||
}
|
||||
|
||||
|
|
@ -40,7 +43,10 @@ impl RenderingSystem for ImguiBridge {
|
|||
let ui = self.imgui.frame();
|
||||
ctx.debug_ui_buffer.borrow().write_buffer(&ui);
|
||||
|
||||
self.platform.prepare_render(&ui, ctx.window);
|
||||
{
|
||||
let window = ctx.window.lock().unwrap();
|
||||
self.platform.prepare_render(&ui, &*window);
|
||||
}
|
||||
let draw_data = self.imgui.render();
|
||||
if draw_data.total_vtx_count == 0 && draw_data.total_idx_count == 0 {
|
||||
return;
|
||||
|
|
@ -49,11 +55,12 @@ impl RenderingSystem for ImguiBridge {
|
|||
self.renderer.render(ctx.target, draw_data).expect("imgui rendering failed");
|
||||
}
|
||||
|
||||
fn initialize(display: &Display<WindowSurface>, window: &Window) -> Self {
|
||||
fn initialize(display: &Display<WindowSurface>, window: Arc<Mutex<Window>>) -> Self {
|
||||
let mut imgui = ImguiContext::create();
|
||||
imgui.set_ini_filename(None);
|
||||
let mut platform = WinitPlatform::new(&mut imgui);
|
||||
platform.attach_window(imgui.io_mut(), window, HiDpiMode::Default);
|
||||
let window = window.lock().unwrap();
|
||||
platform.attach_window(imgui.io_mut(), &*window, HiDpiMode::Default);
|
||||
imgui.fonts().add_font(&[imgui::FontSource::DefaultFontData { config: None }]);
|
||||
let renderer = ImguiGliumRenderer::new(&mut imgui, display).unwrap();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use std::cell::RefCell;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use glium::{Display, Program, Surface, VertexBuffer, IndexBuffer, implement_vertex};
|
||||
use glium::glutin::surface::WindowSurface;
|
||||
use glium::index::PrimitiveType;
|
||||
|
|
@ -108,7 +109,7 @@ impl SkyboxRenderingSystem {
|
|||
}
|
||||
|
||||
impl RenderingSystem for SkyboxRenderingSystem {
|
||||
fn initialize(display: &Display<WindowSurface>, _window: &glium::winit::window::Window) -> Self {
|
||||
fn initialize(display: &Display<WindowSurface>, _window: Arc<Mutex<glium::winit::window::Window>>) -> Self {
|
||||
const VERT_SRC: &str = include_shader!("skybox.vert");
|
||||
const FRAG_SRC: &str = include_shader!("skybox.frag");
|
||||
let program = Program::from_source(display, VERT_SRC, FRAG_SRC, None).unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue