diff --git a/resources/images/ford2.jpg b/resources/images/ford2.jpg new file mode 100644 index 00000000..e0f215f5 Binary files /dev/null and b/resources/images/ford2.jpg differ diff --git a/resources/shaders/simple-edge.compute b/resources/shaders/simple-edge.compute index b7f404f5..60b90632 100644 --- a/resources/shaders/simple-edge.compute +++ b/resources/shaders/simple-edge.compute @@ -55,10 +55,12 @@ void main() { if ((m.x + m.y + m.z) > 200){ p.x = 0; p.y = 0; - p.z = p.z * 2; + p.z = 255; } else { - //p.w = 125; + p.x = 0; + p.y = 0; + p.z = 0; } //write_buffer.buf[0] = write_buffer.buf[0]; diff --git a/src/canvas/canvas_frame.rs b/src/canvas/canvas_frame.rs index 41bd52a9..540d28c3 100644 --- a/src/canvas/canvas_frame.rs +++ b/src/canvas/canvas_frame.rs @@ -7,12 +7,18 @@ use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, Ca use vulkano::pipeline::vertex::Vertex; use std::any::Any; use crate::VertexTypes; +use vulkano::sync::Event; /// Trait which may be inherited by objects that wish to be drawn to the screen pub trait Drawable { fn get(&self) -> VertexTypes; } +/// Trait which may be inherited by objects that wish to receive events +pub trait Eventable { + fn notify(&self, event: &Event) -> (); +} + /// Accumulator for Vectors of VertexTypes #[derive(Default)] pub struct CanvasFrame { @@ -26,3 +32,6 @@ impl CanvasFrame { self.map.push(drawable.get()); } } + + + diff --git a/src/canvas/canvas_state.rs b/src/canvas/canvas_state.rs index 1af6d9d3..45d7acc0 100644 --- a/src/canvas/canvas_state.rs +++ b/src/canvas/canvas_state.rs @@ -499,7 +499,6 @@ impl CanvasState { ).unwrap(); } - // Images let mut shader = self.shader_buffers.get( self.get_shader_handle(String::from("simple_image")) @@ -543,8 +542,6 @@ impl CanvasState { } } - - // Text // let mut shader = self.shader_buffers.get( // self.get_shader_handle(String::from("simple_text")) diff --git a/src/drawables/sprite.rs b/src/drawables/sprite.rs index b00f9e12..e7366b0b 100644 --- a/src/drawables/sprite.rs +++ b/src/drawables/sprite.rs @@ -1,13 +1,13 @@ use std::sync::Arc; use crate::canvas::*; use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle}; -use crate::canvas::canvas_frame::{Drawable}; +use crate::canvas::canvas_frame::{Drawable, Eventable}; use crate::util::vertex::{VertexTypes, TextureVertex3D, Vertex3D}; +use winit::event::{DeviceEvent, MouseButton, ElementState, Event}; /// #[derive(Debug, Clone)] pub struct Sprite { - pub verts: VertexTypes, position: (f32, f32), @@ -16,34 +16,38 @@ pub struct Sprite { /// Container class which implements drawable. impl Sprite { - /// pub fn new(position: (f32, f32), - size: (f32, f32), - depth: u32, - texture_handle: Arc) -> Sprite { - + size: (f32, f32), + depth: u32, + texture_handle: Arc) -> Sprite { let normalized_depth = (depth as f32 / 255.0); let verts = vec![ - TextureVertex3D{ + TextureVertex3D { v_position: [position.0, position.1, normalized_depth], // top left - ti_position: [-0.0, -0.0] }, - TextureVertex3D{ + ti_position: [-0.0, -0.0], + }, + TextureVertex3D { v_position: [position.0, position.1 + size.1, normalized_depth], // bottom left - ti_position: [-0.0, 1.0] }, - TextureVertex3D{ + ti_position: [-0.0, 1.0], + }, + TextureVertex3D { v_position: [position.0 + size.0, position.1 + size.1, normalized_depth], // bottom right - ti_position: [1.0, 1.0] }, - TextureVertex3D{ + ti_position: [1.0, 1.0], + }, + TextureVertex3D { v_position: [position.0, position.1, normalized_depth], // top left - ti_position: [-0.0, -0.0] }, - TextureVertex3D{ + ti_position: [-0.0, -0.0], + }, + TextureVertex3D { v_position: [position.0 + size.0, position.1 + size.1, normalized_depth], // bottom right - ti_position: [1.0, 1.0] }, - TextureVertex3D{ + ti_position: [1.0, 1.0], + }, + TextureVertex3D { v_position: [position.0 + size.0, position.1, normalized_depth], // top right - ti_position: [1.0, -0.0] }, + ti_position: [1.0, -0.0], + }, ]; Sprite { @@ -53,12 +57,29 @@ impl Sprite { } } } -impl Drawable for Sprite{ + +impl Drawable for Sprite { fn get(&self) -> VertexTypes { self.verts.clone() } - } +impl Eventable for Sprite { + fn notify(&self, event: &Event) -> () { + match event { + Event::DeviceEvent { event: DeviceEvent::Button{button, state }, .. } => { + match button.id.unwrap() { + MouseButton::Left => { + if state.state == ElementState::Pressed { + // processor.save_edges_image(); + } + }, + _ => () + } + } + _ => {} + } + } +} diff --git a/src/main.rs b/src/main.rs index 2598216c..9663c43a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,7 +87,7 @@ pub fn main() { let mut accumulator_time: f32 = 0.0; let mut current_time: f32 = timer.elap_time(); - let image_data = load_raw(String::from("funky-bird.jpg")); + let image_data = load_raw(String::from("ford2.jpg")); let image_dimensions_f: (f32, f32) = ((image_data.1).clone().0 as f32, (image_data.1).clone().1 as f32); let image_dimensions_u: (u32, u32) = image_data.1; let compu_sprite1: CompuSprite = @@ -95,9 +95,6 @@ pub fn main() { // Swap image to render the result to. Must match dimensions processor.new_swap_image(image_dimensions_u)); - - // Demo gpu toolpath generation - // Need to let compute_buffer: Arc = processor.new_compute_buffer(image_data.0.clone(), image_data.1, 4); @@ -149,6 +146,16 @@ pub fn main() { // } + + + + + + + + + + // Events loop is borrowed from the surface events_loop.run(move |event, _, control_flow| { match event { @@ -163,15 +170,12 @@ pub fn main() { let mut canvas_frame = CanvasFrame::default(); canvas_frame.draw(&funky_sprite); canvas_frame.draw(&text_sprite); -// canvas_frame.draw(&rect); + canvas_frame.draw(&compu_sprite1); let mut compu_frame = CompuFrame::new(); - //compu_frame.add(compute_buffer.clone(), compute_kernel.clone()); compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1); compu_frame.add(compute_buffer.clone(), compute_kernel.clone()); - canvas_frame.draw(&compu_sprite1); - { let g = hprof::enter("Run"); processor.run(&surface.clone(), diff --git a/src/vkprocessor.rs b/src/vkprocessor.rs index cf0a1d1d..6c5edf4f 100644 --- a/src/vkprocessor.rs +++ b/src/vkprocessor.rs @@ -153,6 +153,7 @@ impl VkProcessor { /// A hardcoded list of textures which can be preloaded from this function pub fn preload_textures(&mut self) { + self.canvas_state.load_texture(String::from("ford2.jpg")); self.canvas_state.load_texture(String::from("funky-bird.jpg")); self.canvas_state.load_texture(String::from("button.png")); self.canvas_state.load_texture(String::from("background.jpg"));