parent
76c75c349b
commit
34b5d7b3d0
@ -0,0 +1,61 @@
|
|||||||
|
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, CompuBufferHandle, CompuKernelHandle};
|
||||||
|
use crate::PersistentState;
|
||||||
|
use crate::render_system::{Geometry, Images, Position, Textures};
|
||||||
|
use crate::util::vertex::{ImageVertex3D, TextureVertex3D, VertexTypeContainer};
|
||||||
|
use crate::vkprocessor::VkProcessor;
|
||||||
|
|
||||||
|
pub struct Compu {
|
||||||
|
pub kernels: Vec<Arc<CompuKernelHandle>>,
|
||||||
|
pub buffers: Vec<Arc<CompuBufferHandle>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Component for Compu {
|
||||||
|
type Storage = VecStorage<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct CompuSystem;
|
||||||
|
|
||||||
|
impl<'a> System<'a> for CompuSystem {
|
||||||
|
type SystemData = (
|
||||||
|
WriteStorage<'a, Compu>,
|
||||||
|
WriteStorage<'a, Geometry>,
|
||||||
|
WriteStorage<'a, Images>,
|
||||||
|
Write<'a, PersistentState>, // delta_time, window size, etc.
|
||||||
|
Write<'a, VkProcessor>, // Renderer
|
||||||
|
);
|
||||||
|
|
||||||
|
fn run(&mut self, (
|
||||||
|
mut compu_list,
|
||||||
|
mut geom_list,
|
||||||
|
mut image_list,
|
||||||
|
mut state,
|
||||||
|
mut vk_processor
|
||||||
|
): Self::SystemData) {
|
||||||
|
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());
|
||||||
|
|
||||||
|
for (compute_item, geom, image) in (&mut compu_list, &mut geom_list, &mut image_list).join() {
|
||||||
|
state.compu_frame.add_with_image_swap(
|
||||||
|
compute_item.buffers.get(0).unwrap().clone(),
|
||||||
|
compute_item.kernels.get(0).unwrap().clone(),
|
||||||
|
image,
|
||||||
|
geom.clone(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (compute_item) in (&mut compu_list).join() {
|
||||||
|
state.compu_frame.add(
|
||||||
|
compute_item.buffers.get(0).unwrap().clone(),
|
||||||
|
compute_item.kernels.get(0).unwrap().clone(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,232 @@
|
|||||||
|
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::vkprocessor::VkProcessor;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Position {
|
||||||
|
pub x: f32,
|
||||||
|
pub y: f32,
|
||||||
|
pub z: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Component for Position {
|
||||||
|
type Storage = VecStorage<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Geometry {
|
||||||
|
pub size_x: f32,
|
||||||
|
pub size_y: f32,
|
||||||
|
pub rotation: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Component for Geometry {
|
||||||
|
type Storage = VecStorage<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Render {
|
||||||
|
pub vertices: Vec<VertexTypeContainer>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Component for Render {
|
||||||
|
type Storage = VecStorage<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Textures {
|
||||||
|
pub textures: Vec<Arc<CanvasTextureHandle>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Component for Textures {
|
||||||
|
type Storage = VecStorage<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Images {
|
||||||
|
pub images: Vec<Arc<CanvasImageHandle>>,
|
||||||
|
pub image_resolutions: Vec<(u32, u32)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Component for Images {
|
||||||
|
type Storage = VecStorage<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct RenderSystem;
|
||||||
|
|
||||||
|
impl<'a> System<'a> for RenderSystem {
|
||||||
|
type SystemData = (
|
||||||
|
WriteStorage<'a, Render>,
|
||||||
|
WriteStorage<'a, Position>,
|
||||||
|
WriteStorage<'a, Geometry>,
|
||||||
|
WriteStorage<'a, Textures>,
|
||||||
|
WriteStorage<'a, Images>,
|
||||||
|
Write<'a, PersistentState>, // delta_time, window size, etc.
|
||||||
|
Write<'a, VkProcessor>, // Renderer
|
||||||
|
);
|
||||||
|
|
||||||
|
fn run(&mut self, (
|
||||||
|
mut vertices_list,
|
||||||
|
mut pos_list,
|
||||||
|
mut geom_list,
|
||||||
|
mut textures_list,
|
||||||
|
mut images_list,
|
||||||
|
mut state,
|
||||||
|
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());
|
||||||
|
|
||||||
|
for (vertices, position, geometry, textures) in (&mut vertices_list, &mut pos_list, &mut geom_list, &mut textures_list).join() {
|
||||||
|
// geom.pos_x += mv.vel_x * state.delta_time;
|
||||||
|
// geom.pos_y += mv.vel_y * state.delta_time;
|
||||||
|
|
||||||
|
let window_size = state.window_size.clone();
|
||||||
|
let pos = (position.x, position.y);
|
||||||
|
let size = (geometry.size_x, geometry.size_y);
|
||||||
|
let normalized_depth = position.z as f32 / 255.0;
|
||||||
|
|
||||||
|
let textured_vertices = vec![
|
||||||
|
VertexTypeContainer::TextureType(
|
||||||
|
generate_textured_verts(window_size, pos, size, normalized_depth),
|
||||||
|
textures.textures.get(0).unwrap().clone()
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
state.canvas_frame.add(textured_vertices);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (vertices, position, geometry, images) in (&mut vertices_list, &mut pos_list, &mut geom_list, &mut images_list).join() {
|
||||||
|
// geom.pos_x += mv.vel_x * state.delta_time;
|
||||||
|
// geom.pos_y += mv.vel_y * state.delta_time;
|
||||||
|
|
||||||
|
let window_size = state.window_size.clone();
|
||||||
|
let pos = (position.x, position.y);
|
||||||
|
let size = (geometry.size_x, geometry.size_y);
|
||||||
|
let normalized_depth = position.z as f32 / 255.0;
|
||||||
|
|
||||||
|
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()
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
state.canvas_frame.add(textured_vertices);
|
||||||
|
}
|
||||||
|
|
||||||
|
vk_processor.run(&state.surface.clone().unwrap(),
|
||||||
|
&state.canvas_frame,
|
||||||
|
&state.compu_frame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn generate_image_verts(
|
||||||
|
window_size: (u32, u32),
|
||||||
|
position: (f32, f32),
|
||||||
|
size: (f32, f32),
|
||||||
|
image_size: (u32, u32),
|
||||||
|
depth: f32,
|
||||||
|
) -> Vec<ImageVertex3D> {
|
||||||
|
|
||||||
|
let image_size = (image_size.0 as f32, image_size.1 as f32);
|
||||||
|
|
||||||
|
// screen space position
|
||||||
|
let ss_position = (
|
||||||
|
position.0 / window_size.0 as f32 - 1.0,
|
||||||
|
position.1 / window_size.1 as f32 - 1.0
|
||||||
|
);
|
||||||
|
|
||||||
|
// screen space size
|
||||||
|
let ss_size = (
|
||||||
|
size.0 / window_size.0 as f32,
|
||||||
|
size.1 / window_size.1 as f32
|
||||||
|
);
|
||||||
|
|
||||||
|
// pub fn new(position: (f32, f32),
|
||||||
|
// size: (f32, f32),
|
||||||
|
// depth: u32,
|
||||||
|
// image_size: (f32, f32),
|
||||||
|
// image_handle: Arc<CanvasImageHandle>) -> CompuSprite {
|
||||||
|
|
||||||
|
vec![
|
||||||
|
ImageVertex3D {
|
||||||
|
v_position: [ss_position.0, ss_position.1, depth], // top left
|
||||||
|
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]
|
||||||
|
},
|
||||||
|
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]
|
||||||
|
},
|
||||||
|
ImageVertex3D {
|
||||||
|
v_position: [ss_position.0, ss_position.1, depth], // top left
|
||||||
|
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]
|
||||||
|
},
|
||||||
|
ImageVertex3D {
|
||||||
|
v_position: [ss_position.0 + ss_size.0, ss_position.1, depth], // top right
|
||||||
|
ti_position: [image_size.0, -0.0]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn generate_textured_verts(
|
||||||
|
window_size: (u32, u32),
|
||||||
|
position: (f32, f32),
|
||||||
|
size: (f32, f32),
|
||||||
|
depth: f32,
|
||||||
|
) -> Vec<TextureVertex3D> {
|
||||||
|
|
||||||
|
let ss_position = (
|
||||||
|
position.0 / window_size.0 as f32 - 1.0,
|
||||||
|
position.1 / window_size.1 as f32 - 1.0
|
||||||
|
);
|
||||||
|
|
||||||
|
let ss_size = (
|
||||||
|
size.0 / window_size.0 as f32,
|
||||||
|
size.1 / window_size.1 as f32
|
||||||
|
);
|
||||||
|
|
||||||
|
vec![
|
||||||
|
TextureVertex3D {
|
||||||
|
v_position: [ss_position.0, ss_position.1, depth], // top left
|
||||||
|
ti_position: [-0.0, -0.0],
|
||||||
|
},
|
||||||
|
TextureVertex3D {
|
||||||
|
v_position: [ss_position.0, ss_position.1 + ss_size.1, depth], // bottom left
|
||||||
|
ti_position: [-0.0, 1.0],
|
||||||
|
},
|
||||||
|
TextureVertex3D {
|
||||||
|
v_position: [ss_position.0 + ss_size.0, ss_position.1 + ss_size.1, depth], // bottom right
|
||||||
|
ti_position: [1.0, 1.0],
|
||||||
|
},
|
||||||
|
TextureVertex3D {
|
||||||
|
v_position: [ss_position.0, ss_position.1, depth], // top left
|
||||||
|
ti_position: [-0.0, -0.0],
|
||||||
|
},
|
||||||
|
TextureVertex3D {
|
||||||
|
v_position: [ss_position.0 + ss_size.0, ss_position.1 + ss_size.1, depth], // bottom right
|
||||||
|
ti_position: [1.0, 1.0],
|
||||||
|
},
|
||||||
|
TextureVertex3D {
|
||||||
|
v_position: [ss_position.0 + ss_size.0, ss_position.1, depth], // top right
|
||||||
|
ti_position: [1.0, -0.0],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in new issue