You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Trac3r-rust/src/main.rs

205 lines
5.1 KiB

6 years ago
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
6 years ago
6 years ago
extern crate cgmath;
extern crate image;
6 years ago
extern crate nalgebra as na;
extern crate rand;
6 years ago
extern crate sfml;
extern crate time;
use sfml::system::*;
use vulkano::sync;
6 years ago
use crate::timer::Timer;
use vulkano::instance::{Instance};
use vulkano::sync::GpuFuture;
use winit::{EventsLoop, WindowBuilder, WindowEvent, Event, DeviceEvent, VirtualKeyCode, ElementState};
use winit::dpi::LogicalSize;
use vulkano_win::VkSurfaceBuild;
use sprite::Sprite;
use crate::compu_state::CompuState;
use crate::compu_frame::CompuFrame;
use crate::compu_sprite::CompuSprite;
use crate::compu_kernel::CompuKernel;
use crate::compu_buffer::CompuBuffers;
use crate::util::load_raw;
use crate::canvas_frame::CanvasFrame;
mod util;
6 years ago
mod timer;
mod input;
mod vkprocessor;
mod vertex_2d;
mod vertex_3d;
mod sprite;
mod canvas;
mod canvas_frame;
mod canvas_shader;
mod compu_state;
mod compu_frame;
mod compu_sprite;
mod compu_kernel;
mod compu_buffer;
/*
Alright, what the hell do I do next...
Canvas works, but I want to use CPU accessible buffer instead of immutable buffer
I think it would be faster if we reuse fewer oversized buffers than vis versa
*/
fn main() {
let instance = {
let extensions = vulkano_win::required_extensions();
Instance::new(None, &extensions, None).unwrap()
};
let mut events_loop = EventsLoop::new();
let mut surface = WindowBuilder::new()
.with_dimensions(LogicalSize::from((800, 800)))
.build_vk_surface(&events_loop, instance.clone()).unwrap();
let mut window = surface.window();
let mut processor = vkprocessor::VkProcessor::new(&instance, &surface);
processor.create_swapchain(&surface);
processor.preload_kernels();
processor.preload_shaders();
processor.preload_textures();
6 years ago
let mut timer = Timer::new();
let mut frame_future = Box::new(sync::now(processor.device.clone())) as Box<dyn GpuFuture>;
let step_size: f32 = 0.005;
let mut elapsed_time: f32;
let mut delta_time: f32;
6 years ago
let mut accumulator_time: f32 = 0.0;
let mut current_time: f32 = timer.elap_time();
6 years ago
5 years ago
let mut mouse_xy = Vector2i::new(0,0);
let sprite = Sprite::new_with_color((0.,0.), (0.1,0.1), (1.,0.,0.,1.));
let sprite2 = Sprite::new_with_color((-1.,-0.5), (0.1,0.1), (0.,1.,0.,1.));
let compu_sprite1 = CompuSprite::new((-1.,-0.5), (0.1,0.1),
// This swap image needs to match the size of the compute
processor.new_swap_image((720, 756)));
let image_data = load_raw(String::from("funky-bird.jpg"));
let compute_buffer = processor.new_compute_buffer(image_data.0, image_data.1, 4);
let compute_kernel = processor.get_kernel_handle(String::from("simple-edge.compute"))
.expect("Can't find that kernel");
let handle = processor.get_texture_handle(String::from("funky-bird.jpg")).unwrap();
let sprite3 = Sprite::new_with_texture((0.3, 0.5), (0.1,0.1), handle.clone());
while let Some(p) = window.get_position() {
6 years ago
elapsed_time = timer.elap_time();
6 years ago
delta_time = elapsed_time - current_time;
current_time = elapsed_time;
if delta_time > 0.02 {
delta_time = 0.02;
6 years ago
}
6 years ago
accumulator_time += delta_time;
6 years ago
6 years ago
while (accumulator_time - step_size) >= step_size {
accumulator_time -= step_size;
}
6 years ago
println!("{}", delta_time);
let mut exit = false;
events_loop.poll_events(|event| {
match event {
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } =>
{
exit = true;
},
Event::WindowEvent { event: WindowEvent::Resized(_), .. } => {
processor.recreate_swapchain(&surface);
},
Event::DeviceEvent { event: DeviceEvent::Key(keyboard_input), .. } => {
match keyboard_input.virtual_keycode.unwrap() {
VirtualKeyCode::A => {
if keyboard_input.state == ElementState::Pressed {
// processor.save_edges_image();
}
}
_ => ()
}
},
// Event::DeviceEvent { event: DeviceEvent::Button(mouse_input), .. } => {
// mouse_xy.x
// },
_ => ()
}
});
if exit {
return;
}
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);
let mut canvas = CanvasFrame::new();
canvas.draw(&sprite);
canvas.draw(&sprite2);
canvas.draw(&sprite3);
canvas.draw(&compu_sprite1);
(frame_future) = processor.run(&surface, frame_future,
canvas,
compu_frame);
}
}
7 years ago