From 62ad4618df711c7295574e91b8bc9d6416514fd4 Mon Sep 17 00:00:00 2001 From: Elham Aryanpur Date: Thu, 6 Jun 2024 18:27:49 +0300 Subject: [PATCH] fix: #61 by introducing limits --- .gitignore | 3 ++- Cargo.lock | 2 +- src/header.rs | 7 +++++-- src/render.rs | 8 ++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 3aeebf2..a69aa05 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ target .vscode +.idea tools res -resources/*.png \ No newline at end of file +resources/*.png diff --git a/Cargo.lock b/Cargo.lock index 72db7c7..271d5f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -297,7 +297,7 @@ dependencies = [ [[package]] name = "blue_engine" -version = "0.5.8" +version = "0.5.9" dependencies = [ "android_logger", "bytemuck", diff --git a/src/header.rs b/src/header.rs index e4c0064..c4c57b5 100644 --- a/src/header.rs +++ b/src/header.rs @@ -161,7 +161,7 @@ unsafe impl Sync for ObjectSettings {} /// use blue_engine::header::{Engine, WindowDescriptor}; /// /// fn main() { -/// let engine = Engine::new(WindowDescriptor::default()).expect("Couldn't create the engine"); +/// let engine = Engine::new().expect("Couldn't create the engine"); /// } /// ``` /// The WindowDescriptor simply holds what features you would like for your window. If you are reading this on later version of @@ -270,7 +270,7 @@ unsafe impl Sync for Renderer {} unsafe impl Send for Renderer {} /// Descriptor and settings for a window. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone)] pub struct WindowDescriptor { /// The width of the window pub width: u32, @@ -292,6 +292,8 @@ pub struct WindowDescriptor { pub control_flow: crate::winit::event_loop::ControlFlow, /// The presentation mode of renderer for things like VSync pub present_mode: crate::wgpu::PresentMode, + /// Limits to be required based on the generation of the GPU and the API + pub limits: crate::wgpu::Limits, /// The alpha mode which specifies how the alpha channel of the textures should be handled during compositing. pub alpha_mode: crate::wgpu::CompositeAlphaMode, /// The desired frame latency, check [wgpu::SurfaceConfiguration::desired_maximum_frame_latency] @@ -320,6 +322,7 @@ impl std::default::Default for WindowDescriptor { }, control_flow: crate::winit::event_loop::ControlFlow::Poll, present_mode: crate::wgpu::PresentMode::AutoNoVsync, + limits: crate::wgpu::Limits::default(), alpha_mode: crate::wgpu::CompositeAlphaMode::Auto, desired_maximum_frame_latency: 2, } diff --git a/src/render.rs b/src/render.rs index 36ad349..87dc7e9 100644 --- a/src/render.rs +++ b/src/render.rs @@ -54,7 +54,7 @@ impl Renderer { &wgpu::DeviceDescriptor { label: Some("Device"), required_features: settings.features, - required_limits: wgpu::Limits::default(), + required_limits: settings.limits, }, None, // Trace path ) @@ -185,7 +185,7 @@ impl Renderer { /// # Arguments /// * `new_size` - The new window size. pub(crate) fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { - // check if new_size is non zero + // check if new_size is non-zero if new_size.width != 0 && new_size.height != 0 { self.size = new_size; self.config.width = new_size.width; @@ -270,8 +270,8 @@ impl Renderer { if self.scissor_rect.is_some() { let scissor_rect = self.scissor_rect.unwrap(); // check if scissor bounds are smaller than the window - if scissor_rect.0 + scissor_rect.2 < window_size.width as u32 - && scissor_rect.1 + scissor_rect.3 < window_size.height as u32 + if scissor_rect.0 + scissor_rect.2 < window_size.width + && scissor_rect.1 + scissor_rect.3 < window_size.height { render_pass.set_scissor_rect( scissor_rect.0,