rendering works in pure ECS. This is actually pretty sweet. broke compu rendering though
This commit is contained in:
108
src/main.rs
108
src/main.rs
@@ -8,14 +8,17 @@ extern crate hprof;
|
||||
extern crate image;
|
||||
extern crate nalgebra as na;
|
||||
extern crate rand;
|
||||
extern crate specs;
|
||||
extern crate time;
|
||||
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use gilrs::{Button, Event as GilEvent, Gamepad, GamepadId, Gilrs};
|
||||
use specs::prelude::*;
|
||||
use vulkano::instance::debug::DebugCallback;
|
||||
use vulkano::instance::Instance;
|
||||
use vulkano::swapchain::Surface;
|
||||
use vulkano::sync;
|
||||
use vulkano::sync::GpuFuture;
|
||||
use vulkano_win::VkSurfaceBuild;
|
||||
@@ -23,44 +26,37 @@ use winit::dpi::LogicalSize;
|
||||
use winit::event::{DeviceEvent, ElementState, Event, MouseButton, StartCause, VirtualKeyCode, WindowEvent};
|
||||
use winit::event_loop::{ControlFlow, EventLoop, EventLoopProxy};
|
||||
use winit::platform::unix::WindowBuilderExtUnix;
|
||||
use winit::window::{WindowBuilder, Window};
|
||||
use winit::window::{Window, WindowBuilder};
|
||||
|
||||
use canvas::compu_frame::CompuFrame;
|
||||
|
||||
use crate::canvas::canvas_frame::{CanvasFrame, Drawable};
|
||||
use crate::canvas::canvas_state::CanvasState;
|
||||
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasTextureHandle, Handle};
|
||||
use canvas::compu_frame::CompuFrame;
|
||||
use crate::canvas::managed::handles::{CompuBufferHandle, CompuKernelHandle};
|
||||
use crate::drawables::compu_sprite::CompuSprite;
|
||||
use crate::drawables::rect::Rect;
|
||||
use crate::drawables::slider::Slider;
|
||||
use crate::drawables::sprite::Sprite;
|
||||
use crate::drawables::text::Text;
|
||||
use crate::render_system::{Geometry, Images, Position, Render, RenderSystem, Textures};
|
||||
use crate::util::load_raw;
|
||||
use crate::util::timer::Timer;
|
||||
use crate::util::tr_event::{TrEventExtension, TrEvent};
|
||||
use crate::util::tr_event::{TrEvent, TrEventExtension};
|
||||
use crate::util::vertex::{TextureVertex3D, VertexTypeContainer};
|
||||
use crate::vkprocessor::VkProcessor;
|
||||
use crate::drawables::slider::Slider;
|
||||
use crate::compu_system::{CompuSystem, Compu};
|
||||
|
||||
pub mod util;
|
||||
pub mod vkprocessor;
|
||||
pub mod drawables;
|
||||
pub mod canvas;
|
||||
pub mod render_system;
|
||||
pub mod compu_system;
|
||||
|
||||
extern crate specs;
|
||||
|
||||
use specs::prelude::*;
|
||||
use vulkano::swapchain::Surface;
|
||||
|
||||
pub struct Render {
|
||||
render_actor: Box<dyn Drawable + Sync + Send>,
|
||||
}
|
||||
|
||||
impl Component for Render {
|
||||
type Storage = VecStorage<Self>;
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct PersistentState {
|
||||
pub struct PersistentState {
|
||||
surface: Option<Arc<Surface<Window>>>,
|
||||
window_size: (u32, u32),
|
||||
delta_time: f32,
|
||||
@@ -68,47 +64,6 @@ struct PersistentState {
|
||||
compu_frame: CompuFrame,
|
||||
}
|
||||
|
||||
struct RenderSystem;
|
||||
|
||||
impl<'a> System<'a> for RenderSystem {
|
||||
type SystemData = (
|
||||
WriteStorage<'a, Render>, // generates the vertices
|
||||
Write<'a, PersistentState>, // delta_time, window size, etc.
|
||||
Write<'a, VkProcessor>, // Renderer
|
||||
);
|
||||
|
||||
fn run(&mut self, (mut mv, mut draw, 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 (mv, geom, draw) in (&mut mv, &mut draw).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();
|
||||
state.canvas_frame.add(draw.0.get(
|
||||
window_size,
|
||||
(geom.pos_x, geom.pos_y),
|
||||
geom.rotation,
|
||||
(geom.size_x, geom.size_y),
|
||||
geom.depth,
|
||||
));
|
||||
}
|
||||
|
||||
for draw_data in (&draw).join() {
|
||||
let size = state.window_size.clone();
|
||||
}
|
||||
|
||||
vk_processor.run(&state.surface.clone().unwrap(),
|
||||
&state.canvas_frame,
|
||||
&state.compu_frame);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct EventSystem;
|
||||
|
||||
impl<'a> System<'a> for EventSystem {
|
||||
@@ -128,13 +83,11 @@ impl<'a> System<'a> for EventSystem {
|
||||
}
|
||||
}
|
||||
|
||||
struct Eventt(u32);
|
||||
|
||||
pub fn main() {
|
||||
//hprof::start_frame();
|
||||
//let g = hprof::enter("vulkan preload");
|
||||
|
||||
|
||||
let instance = {
|
||||
let extensions = vulkano_win::required_extensions();
|
||||
Instance::new(None, &extensions, None).unwrap()
|
||||
@@ -174,11 +127,6 @@ pub fn main() {
|
||||
let image_dimensions_u: (u32, u32) = image_data.1;
|
||||
|
||||
|
||||
let compu_sprite1: CompuSprite =
|
||||
CompuSprite::new((-1.0, -1.0), (1.0, 1.0), 0, image_dimensions_f,
|
||||
// Swap image to render the result to. Must match dimensions
|
||||
processor.new_swap_image(image_dimensions_u));
|
||||
|
||||
let compute_buffer: Arc<CompuBufferHandle> =
|
||||
processor.new_compute_buffer(image_data.0.clone(), image_data.1, 4);
|
||||
|
||||
@@ -189,6 +137,8 @@ pub fn main() {
|
||||
processor.get_kernel_handle(String::from("simple-edge.compute"))
|
||||
.expect("Can't find that kernel");
|
||||
|
||||
let compu_image = processor.new_swap_image(image_dimensions_u);
|
||||
|
||||
// Get the handles for the assets
|
||||
let funky_handle: Arc<CanvasTextureHandle> =
|
||||
processor.get_texture_handle(String::from("funky-bird.jpg")).unwrap();
|
||||
@@ -197,6 +147,11 @@ pub fn main() {
|
||||
|
||||
let mut world = World::new();
|
||||
world.register::<Render>();
|
||||
world.register::<Compu>();
|
||||
world.register::<Position>();
|
||||
world.register::<Geometry>();
|
||||
world.register::<Textures>();
|
||||
world.register::<Images>();
|
||||
world.insert::<VkProcessor>(processor);
|
||||
world.insert::<Vec<TrEvent<TrEventExtension>>>(Vec::new());
|
||||
world.insert::<PersistentState>(PersistentState {
|
||||
@@ -207,26 +162,27 @@ pub fn main() {
|
||||
compu_frame: CompuFrame::new((0, 0)),
|
||||
});
|
||||
|
||||
|
||||
let thing = Box::new(Sprite::new(funky_handle.clone()));
|
||||
|
||||
// An entity may or may not contain some component.
|
||||
let t = world.create_entity()
|
||||
.with(Render{ render_actor: thing })// just a drawable
|
||||
world.create_entity()
|
||||
.with(Render { vertices: vec![] })// just a drawable
|
||||
.with(Position { x: 0.0, y: 0.0, z: 0 })
|
||||
.with(Geometry { size_x: 300.0, size_y: 300.0, rotation: 0.0 })
|
||||
.with(Textures { textures: vec![funky_handle] })
|
||||
.build();
|
||||
|
||||
let thing2 = Box::new(Slider::new((300.0, 50.0), (550.0, 100.0), 30000));
|
||||
|
||||
world.create_entity()
|
||||
.with(Render{ render_actor: thing2 })// just a drawable
|
||||
.with(Render { vertices: vec![] })// just a drawable
|
||||
.with(Position { x: 600.0, y: 500.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();
|
||||
|
||||
|
||||
// call the run method for the following systems & deps
|
||||
let mut dispatcher = DispatcherBuilder::new()
|
||||
// .with(SysA, "sys_a", &[])
|
||||
.with(EventSystem, "event_s", &[])
|
||||
.with(RenderSystem, "render_s", &["event_s"]).build();
|
||||
.with(CompuSystem, "compu_s", &["event_s"])
|
||||
.with(RenderSystem, "render_s", &["event_s", "compu_s"]).build();
|
||||
|
||||
|
||||
let event_loop_proxy = events_loop.create_proxy();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user