diff --git a/Cargo.lock b/Cargo.lock index c8dfa49..5306829 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -297,7 +297,7 @@ dependencies = [ [[package]] name = "blue_engine" -version = "0.5.4" +version = "0.5.5" dependencies = [ "android_logger", "bytemuck", diff --git a/Cargo.toml b/Cargo.toml index fd7e51b..3b1b3a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "blue_engine" -version = "0.5.4" +version = "0.5.5" authors = ["Elham Aryanpur "] edition = "2021" description = "General-Purpose, Easy-to-use, Fast, and Portable graphics engine" @@ -84,6 +84,14 @@ path = "examples/utils/instancing.rs" name = "render_order" path = "examples/utils/render_order.rs" +[[example]] +name = "wireframe" +path = "examples/utils/wireframe.rs" + +[[example]] +name = "scissor" +path = "examples/utils/scissor.rs" + # Development ONLY [[example]] name = "dev" diff --git a/examples/utils/scissor.rs b/examples/utils/scissor.rs new file mode 100644 index 0000000..0d799bc --- /dev/null +++ b/examples/utils/scissor.rs @@ -0,0 +1,28 @@ +/* + * Blue Engine by Elham Aryanpur + * + * Triangle example using pre-defined shapes + * + * The license is same as the one on the root. +*/ + +use blue_engine::{primitive_shapes::triangle, Engine, ObjectSettings}; + +pub fn main() { + let mut engine = Engine::new().expect("win"); + + triangle( + "Triangle", + ObjectSettings::default(), + &mut engine.renderer, + &mut engine.objects, + ) + .unwrap(); + + // set scissor rect + engine.renderer.scissor_rect = Some((0, 0, 450, 350)); + + engine + .update_loop(move |_, _, _, _, _, _| {}) + .expect("Error during update loop"); +} diff --git a/examples/utils/wireframe.rs b/examples/utils/wireframe.rs new file mode 100644 index 0000000..3f10f44 --- /dev/null +++ b/examples/utils/wireframe.rs @@ -0,0 +1,31 @@ +/* + * Blue Engine by Elham Aryanpur + * + * Triangle example using pre-defined shapes + * + * The license is same as the one on the root. +*/ + +use blue_engine::{primitive_shapes::triangle, Engine, ObjectSettings, ShaderSettings}; + +pub fn main() { + let mut engine = Engine::new().expect("win"); + + triangle( + "Triangle", + ObjectSettings { + shader_settings: ShaderSettings { + polygon_mode: wgpu::PolygonMode::Line, + ..Default::default() + }, + ..Default::default() + }, + &mut engine.renderer, + &mut engine.objects, + ) + .unwrap(); + + engine + .update_loop(move |_, _, _, _, _, _| {}) + .expect("Error during update loop"); +} diff --git a/src/render.rs b/src/render.rs index 7e898d1..b81ffb1 100644 --- a/src/render.rs +++ b/src/render.rs @@ -210,6 +210,7 @@ impl Renderer { pub(crate) fn pre_render( &mut self, objects: &ObjectStorage, + window_size: winit::dpi::PhysicalSize, camera: &Camera, ) -> Result< Option<( @@ -225,7 +226,12 @@ impl Renderer { return Ok(None); }; - let frame = surface.get_current_texture()?; + let frame = if let Ok(frame) = surface.get_current_texture() { + frame + } else { + return Ok(None); + }; + let view = frame .texture .create_view(&wgpu::TextureViewDescriptor::default()); @@ -260,12 +266,17 @@ impl Renderer { if self.scissor_rect.is_some() { let scissor_rect = self.scissor_rect.unwrap(); - render_pass.set_scissor_rect( - scissor_rect.0, - scissor_rect.1, - scissor_rect.2, - scissor_rect.3, - ); + // 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 + { + render_pass.set_scissor_rect( + scissor_rect.0, + scissor_rect.1, + scissor_rect.2, + scissor_rect.3, + ); + } } let default_data = self.default_data.as_ref().unwrap(); diff --git a/src/window.rs b/src/window.rs index 2149b77..323ace9 100644 --- a/src/window.rs +++ b/src/window.rs @@ -152,7 +152,7 @@ impl Engine { } WindowEvent::RedrawRequested => { let pre_render = renderer - .pre_render(&objects, &camera) + .pre_render(&objects, window.inner_size(), &camera) .expect("Couldn't get pre render data"); if pre_render.is_some() { let (mut encoder, view, frame) = pre_render.unwrap();