From e7bbf1f1db00a5230f975100cd61bf7dbdb4d5fa Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Fri, 18 Sep 2020 00:19:17 -0700 Subject: [PATCH] comes together fast when you actually use the library correctly. compute works --- src/canvas/compu_frame.rs | 15 +-------------- src/main.rs | 21 ++++++++++----------- src/render_system.rs | 27 +++++++++++++-------------- 3 files changed, 24 insertions(+), 39 deletions(-) diff --git a/src/canvas/compu_frame.rs b/src/canvas/compu_frame.rs index 600cdd54..7b01636c 100644 --- a/src/canvas/compu_frame.rs +++ b/src/canvas/compu_frame.rs @@ -60,20 +60,7 @@ impl CompuFrame { images: &Images, geom: Geometry, ) { + self.swapped_to_image.push((buffer, images.images.get(0).unwrap().clone(), kernel)) - // TODO fix this - // let compu_sprites = sprite.render( - // self.window_size, - // (mv.pos_x, mv.pos_y), - // geom.rotation, - // (geom.size_x, geom.size_y), - // geom.depth, - // ); - // - // if compu_sprites.len() == 1 { - // if let VertexTypeContainer::ImageType(a, b) = compu_sprites.first().unwrap() { - // self.swapped_to_image.push((buffer, b.clone(), kernel)) - // }; - // } } } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 1aa44a6e..28eb0371 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,18 +68,13 @@ struct EventSystem; impl<'a> System<'a> for EventSystem { type SystemData = ( - WriteStorage<'a, Render>, Write<'a, PersistentState>, Write<'a, VkProcessor>, Write<'a, Vec>> ); - fn run(&mut self, (mut draw, mut state, mut vk_processor, event_stack): Self::SystemData) { - // for draw_data in (&mut draw).join() { - // for event in event_stack.iter() { - // draw_data.0.notify(event) - // } - // } + fn run(&mut self, (mut state, mut vk_processor, event_stack): Self::SystemData) { + } } @@ -126,7 +121,6 @@ pub fn main() { 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 compute_buffer: Arc = processor.new_compute_buffer(image_data.0.clone(), image_data.1, 4); @@ -162,6 +156,12 @@ pub fn main() { compu_frame: CompuFrame::new((0, 0)), }); + world.create_entity() + .with(Compu { kernels: vec![compute_kernel], buffers: vec![compute_buffer] })// just a drawable + .with(Geometry { size_x: 300.0, size_y: 300.0, rotation: 0.0 }) + .with(Images { images: vec![compu_image.clone()], image_resolutions: vec![image_dimensions_u] }) + .build(); + world.create_entity() .with(Render { vertices: vec![] })// just a drawable .with(Position { x: 0.0, y: 0.0, z: 0 }) @@ -170,8 +170,8 @@ pub fn main() { .build(); world.create_entity() - .with(Render { vertices: vec![] })// just a drawable - .with(Position { x: 600.0, y: 500.0, z: 0 }) + .with(Render { vertices: vec![] }) + .with(Position { x: 900.0, y: 900.0, z: 0 }) .with(Geometry { size_x: 600.0, size_y: 600.0, rotation: 0.0 }) .with(Images { images: vec![compu_image], image_resolutions: vec![image_dimensions_u] }) .build(); @@ -183,7 +183,6 @@ pub fn main() { .with(CompuSystem, "compu_s", &["event_s"]) .with(RenderSystem, "render_s", &["event_s", "compu_s"]).build(); - let event_loop_proxy = events_loop.create_proxy(); std::thread::spawn(move || { diff --git a/src/render_system.rs b/src/render_system.rs index 5a658abf..179eebaa 100644 --- a/src/render_system.rs +++ b/src/render_system.rs @@ -1,12 +1,13 @@ +use std::sync::Arc; + use specs::{Component, Join, System, VecStorage, Write, WriteStorage}; use crate::canvas::canvas_frame::CanvasFrame; use crate::canvas::compu_frame::CompuFrame; use crate::canvas::managed::handles::{CanvasImageHandle, CanvasTextureHandle}; use crate::PersistentState; -use crate::util::vertex::{TextureVertex3D, VertexTypeContainer, ImageVertex3D}; +use crate::util::vertex::{ImageVertex3D, TextureVertex3D, VertexTypeContainer}; use crate::vkprocessor::VkProcessor; -use std::sync::Arc; #[derive(Debug, Clone)] pub struct Position { @@ -81,7 +82,6 @@ impl<'a> System<'a> for RenderSystem { mut vk_processor ): Self::SystemData) { state.canvas_frame = CanvasFrame::new(state.window_size); - state.compu_frame = CompuFrame::new(state.window_size); // compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1); // compu_frame.add(compute_buffer.clone(), compute_kernel.clone()); @@ -98,7 +98,7 @@ impl<'a> System<'a> for RenderSystem { let textured_vertices = vec![ VertexTypeContainer::TextureType( generate_textured_verts(window_size, pos, size, normalized_depth), - textures.textures.get(0).unwrap().clone() + textures.textures.get(0).unwrap().clone(), ) ]; @@ -117,16 +117,17 @@ impl<'a> System<'a> for RenderSystem { let textured_vertices = vec![ VertexTypeContainer::ImageType( generate_image_verts(window_size, pos, size, images.image_resolutions.get(0).unwrap().clone(), normalized_depth), - images.images.get(0).unwrap().clone() + images.images.get(0).unwrap().clone(), ) ]; state.canvas_frame.add(textured_vertices); } + let compu_frame = &state.compu_frame; vk_processor.run(&state.surface.clone().unwrap(), &state.canvas_frame, - &state.compu_frame); + compu_frame); } } @@ -137,7 +138,6 @@ fn generate_image_verts( image_size: (u32, u32), depth: f32, ) -> Vec { - let image_size = (image_size.0 as f32, image_size.1 as f32); // screen space position @@ -161,27 +161,27 @@ fn generate_image_verts( vec![ ImageVertex3D { v_position: [ss_position.0, ss_position.1, depth], // top left - ti_position: [-0.0, -0.0] + ti_position: [-0.0, -0.0], }, ImageVertex3D { v_position: [ss_position.0, ss_position.1 + ss_size.1, depth], // bottom left - ti_position: [-0.0, image_size.1] + ti_position: [-0.0, image_size.1], }, ImageVertex3D { v_position: [ss_position.0 + ss_size.0, ss_position.1 + ss_size.1, depth], // bottom right - ti_position: [image_size.0, image_size.1] + ti_position: [image_size.0, image_size.1], }, ImageVertex3D { v_position: [ss_position.0, ss_position.1, depth], // top left - ti_position: [-0.0, -0.0] + ti_position: [-0.0, -0.0], }, ImageVertex3D { v_position: [ss_position.0 + ss_size.0, ss_position.1 + ss_size.1, depth], // bottom right - ti_position: [image_size.0, image_size.1] + ti_position: [image_size.0, image_size.1], }, ImageVertex3D { v_position: [ss_position.0 + ss_size.0, ss_position.1, depth], // top right - ti_position: [image_size.0, -0.0] + ti_position: [image_size.0, -0.0], }, ] } @@ -192,7 +192,6 @@ fn generate_textured_verts( size: (f32, f32), depth: f32, ) -> Vec { - let ss_position = ( position.0 / window_size.0 as f32 - 1.0, position.1 / window_size.1 as f32 - 1.0