From d5b84d968b570fbaeb6a1832a93875116001c504 Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 2 Nov 2023 20:47:45 +0100 Subject: refactor(engine): make renderer a struct --- engine/src/lib.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'engine/src/lib.rs') diff --git a/engine/src/lib.rs b/engine/src/lib.rs index 9f82b26..ae603b0 100644 --- a/engine/src/lib.rs +++ b/engine/src/lib.rs @@ -8,6 +8,7 @@ use glfw::{Window, WindowBuilder}; use crate::camera::Camera; use crate::object::{Id as ObjectId, Object}; +use crate::renderer::Renderer; use crate::vector::Vec2; mod matrix; @@ -32,7 +33,7 @@ pub struct Engine /// Objects have to be dropped before window. Otherwise, UB. objects: BTreeMap, window: Window, - camera: Camera, + renderer: Renderer, delta_time: Duration, } @@ -59,15 +60,15 @@ impl Engine .map_err(Error::ConfigureWindowFailed)?; window.set_framebuffer_size_callback(move |new_window_size| { - crate::renderer::set_viewport(&Vec2::ZERO, &new_window_size); + Renderer::set_viewport(&Vec2::ZERO, &new_window_size); }); - crate::renderer::initialize(&window).map_err(Error::InitializeRendererFailed)?; + let renderer = Renderer::new(&window).map_err(Error::InitializeRendererFailed)?; Ok(Self { window, + renderer, objects: BTreeMap::new(), - camera: Camera::new(), delta_time: Duration::ZERO, }) } @@ -110,7 +111,7 @@ impl Engine let window_size = self.window.size().map_err(Error::GetWindowSizeFailed)?; - crate::renderer::render(self.objects.values(), &window_size, &self.camera); + self.renderer.render(self.objects.values(), &window_size); self.window .swap_buffers() @@ -127,12 +128,12 @@ impl Engine #[must_use] pub fn camera(&self) -> &Camera { - &self.camera + self.renderer.camera() } pub fn camera_mut(&mut self) -> &mut Camera { - &mut self.camera + self.renderer.camera_mut() } /// Returns the current delta time. Will be 0 if not called from the function -- cgit v1.2.3-18-g5258