comes together fast when you actually use the library correctly. compute works

a-star
mitchellhansen 4 years ago
parent 34b5d7b3d0
commit e7bbf1f1db

@ -60,20 +60,7 @@ impl CompuFrame {
images: &Images, images: &Images,
geom: Geometry, 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))
// };
// }
} }
} }

@ -68,18 +68,13 @@ struct EventSystem;
impl<'a> System<'a> for EventSystem { impl<'a> System<'a> for EventSystem {
type SystemData = ( type SystemData = (
WriteStorage<'a, Render>,
Write<'a, PersistentState>, Write<'a, PersistentState>,
Write<'a, VkProcessor>, Write<'a, VkProcessor>,
Write<'a, Vec<TrEvent<TrEventExtension>>> Write<'a, Vec<TrEvent<TrEventExtension>>>
); );
fn run(&mut self, (mut draw, mut state, mut vk_processor, event_stack): Self::SystemData) { fn run(&mut self, (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)
// }
// }
} }
} }
@ -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_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 image_dimensions_u: (u32, u32) = image_data.1;
let compute_buffer: Arc<CompuBufferHandle> = let compute_buffer: Arc<CompuBufferHandle> =
processor.new_compute_buffer(image_data.0.clone(), image_data.1, 4); 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)), 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() world.create_entity()
.with(Render { vertices: vec![] })// just a drawable .with(Render { vertices: vec![] })// just a drawable
.with(Position { x: 0.0, y: 0.0, z: 0 }) .with(Position { x: 0.0, y: 0.0, z: 0 })
@ -170,8 +170,8 @@ pub fn main() {
.build(); .build();
world.create_entity() world.create_entity()
.with(Render { vertices: vec![] })// just a drawable .with(Render { vertices: vec![] })
.with(Position { x: 600.0, y: 500.0, z: 0 }) .with(Position { x: 900.0, y: 900.0, z: 0 })
.with(Geometry { size_x: 600.0, size_y: 600.0, rotation: 0.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] }) .with(Images { images: vec![compu_image], image_resolutions: vec![image_dimensions_u] })
.build(); .build();
@ -183,7 +183,6 @@ pub fn main() {
.with(CompuSystem, "compu_s", &["event_s"]) .with(CompuSystem, "compu_s", &["event_s"])
.with(RenderSystem, "render_s", &["event_s", "compu_s"]).build(); .with(RenderSystem, "render_s", &["event_s", "compu_s"]).build();
let event_loop_proxy = events_loop.create_proxy(); let event_loop_proxy = events_loop.create_proxy();
std::thread::spawn(move || { std::thread::spawn(move || {

@ -1,12 +1,13 @@
use std::sync::Arc;
use specs::{Component, Join, System, VecStorage, Write, WriteStorage}; use specs::{Component, Join, System, VecStorage, Write, WriteStorage};
use crate::canvas::canvas_frame::CanvasFrame; use crate::canvas::canvas_frame::CanvasFrame;
use crate::canvas::compu_frame::CompuFrame; use crate::canvas::compu_frame::CompuFrame;
use crate::canvas::managed::handles::{CanvasImageHandle, CanvasTextureHandle}; use crate::canvas::managed::handles::{CanvasImageHandle, CanvasTextureHandle};
use crate::PersistentState; use crate::PersistentState;
use crate::util::vertex::{TextureVertex3D, VertexTypeContainer, ImageVertex3D}; use crate::util::vertex::{ImageVertex3D, TextureVertex3D, VertexTypeContainer};
use crate::vkprocessor::VkProcessor; use crate::vkprocessor::VkProcessor;
use std::sync::Arc;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Position { pub struct Position {
@ -81,7 +82,6 @@ impl<'a> System<'a> for RenderSystem {
mut vk_processor mut vk_processor
): Self::SystemData) { ): Self::SystemData) {
state.canvas_frame = CanvasFrame::new(state.window_size); 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_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
// compu_frame.add(compute_buffer.clone(), compute_kernel.clone()); // compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
@ -98,7 +98,7 @@ impl<'a> System<'a> for RenderSystem {
let textured_vertices = vec![ let textured_vertices = vec![
VertexTypeContainer::TextureType( VertexTypeContainer::TextureType(
generate_textured_verts(window_size, pos, size, normalized_depth), 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![ let textured_vertices = vec![
VertexTypeContainer::ImageType( VertexTypeContainer::ImageType(
generate_image_verts(window_size, pos, size, images.image_resolutions.get(0).unwrap().clone(), normalized_depth), 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); state.canvas_frame.add(textured_vertices);
} }
let compu_frame = &state.compu_frame;
vk_processor.run(&state.surface.clone().unwrap(), vk_processor.run(&state.surface.clone().unwrap(),
&state.canvas_frame, &state.canvas_frame,
&state.compu_frame); compu_frame);
} }
} }
@ -137,7 +138,6 @@ fn generate_image_verts(
image_size: (u32, u32), image_size: (u32, u32),
depth: f32, depth: f32,
) -> Vec<ImageVertex3D> { ) -> Vec<ImageVertex3D> {
let image_size = (image_size.0 as f32, image_size.1 as f32); let image_size = (image_size.0 as f32, image_size.1 as f32);
// screen space position // screen space position
@ -161,27 +161,27 @@ fn generate_image_verts(
vec![ vec![
ImageVertex3D { ImageVertex3D {
v_position: [ss_position.0, ss_position.1, depth], // top left v_position: [ss_position.0, ss_position.1, depth], // top left
ti_position: [-0.0, -0.0] ti_position: [-0.0, -0.0],
}, },
ImageVertex3D { ImageVertex3D {
v_position: [ss_position.0, ss_position.1 + ss_size.1, depth], // bottom left 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 { ImageVertex3D {
v_position: [ss_position.0 + ss_size.0, ss_position.1 + ss_size.1, depth], // bottom right 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 { ImageVertex3D {
v_position: [ss_position.0, ss_position.1, depth], // top left v_position: [ss_position.0, ss_position.1, depth], // top left
ti_position: [-0.0, -0.0] ti_position: [-0.0, -0.0],
}, },
ImageVertex3D { ImageVertex3D {
v_position: [ss_position.0 + ss_size.0, ss_position.1 + ss_size.1, depth], // bottom right 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 { ImageVertex3D {
v_position: [ss_position.0 + ss_size.0, ss_position.1, depth], // top right 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), size: (f32, f32),
depth: f32, depth: f32,
) -> Vec<TextureVertex3D> { ) -> Vec<TextureVertex3D> {
let ss_position = ( let ss_position = (
position.0 / window_size.0 as f32 - 1.0, position.0 / window_size.0 as f32 - 1.0,
position.1 / window_size.1 as f32 - 1.0 position.1 / window_size.1 as f32 - 1.0

Loading…
Cancel
Save