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

191 lines
4.5 KiB

#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
extern crate cgmath;
extern crate image;
extern crate nalgebra as na;
extern crate rand;
extern crate sfml;
extern crate time;
use sfml::graphics::*;
use sfml::graphics::{
Color, RenderTarget, RenderWindow,
};
use sfml::system::*;
use sfml::window::{Key, Style};
use sfml::window::mouse::*;
use sfml::window::mouse;
use vulkano::sync;
use std::sync::Arc;
use std::{fs, mem, iter, ptr};
use std::path::PathBuf;
use std::result;
use crate::input::Input;
use crate::slider::Slider;
use crate::timer::Timer;
use na::DimAdd;
use std::time::{SystemTime, Duration};
use std::ffi::CStr;
use std::ptr::write;
use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer, DeviceLocalBuffer, ImmutableBuffer, BufferAccess};
use vulkano::command_buffer::AutoCommandBufferBuilder;
use vulkano::descriptor::descriptor_set::PersistentDescriptorSet;
use vulkano::device::{Device, DeviceExtensions};
use vulkano::instance::{Instance, InstanceExtensions, PhysicalDevice};
use vulkano::pipeline::ComputePipeline;
use vulkano::descriptor::pipeline_layout::PipelineLayoutAbstract;
use vulkano::sync::GpuFuture;
use shaderc::CompileOptions;
use shade_runner::CompileError;
use crate::workpiece::{WorkpieceLoader, Workpiece};
use winit::{EventsLoop, WindowBuilder, WindowEvent, Event};
use vulkano_win::VkSurfaceBuild;
mod slider;
mod timer;
mod input;
mod vkprocessor;
mod util;
mod button;
mod workpiece;
/*
*/
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()
.build_vk_surface(&events_loop, instance.clone()).unwrap();
let mut window = surface.window();
let mut processor = vkprocessor::VkProcessor::new(&instance, &surface);
processor.compile_kernel(String::from("simple-edge.compute"));
processor.compile_shaders(String::from("simple"), &surface);
processor.load_buffers(String::from("funky-bird.jpg"));
let mut timer = Timer::new();
let mut input = Input::new();
let step_size: f32 = 0.005;
let mut elapsed_time: f32;
let mut delta_time: f32;
let mut accumulator_time: f32 = 0.0;
let mut current_time: f32 = timer.elap_time();
let mut mouse_xy = Vector2i::new(0,0);
let mut s = Box::new(sync::now(processor.device.clone())) as Box<dyn GpuFuture>;
while let Some(p) = window.get_position() {
// Event::MouseButtonPressed { button, x, y} => {
// let x = x as u32;
// let y = y as u32;
// mouse_xy = mouse::desktop_position();
// let r = processor.image_buffer[((processor.xy.0 * y + x) * 4 + 0) as usize] as u8;
// let g = processor.image_buffer[((processor.xy.0 * y + x) * 4 + 1) as usize] as u8;
// let b = processor.image_buffer[((processor.xy.0 * y + x) * 4 + 2) as usize] as u8;
// let a = processor.image_buffer[((processor.xy.0 * y + x) * 4 + 3) as usize] as u8;
//
// selected_colors.push(
// RectangleShape::with_size(Vector2f::new(30.0, 30.0))
// );
//
// let mut x_position = 45.0 * selected_colors.len() as f32;
//
// selected_colors.last_mut().unwrap().set_position(Vector2f::new(x_position, 80.0));
// selected_colors.last_mut().unwrap().set_fill_color(&Color::rgba(r,g,b,a));
// }
elapsed_time = timer.elap_time();
delta_time = elapsed_time - current_time;
current_time = elapsed_time;
if delta_time > 0.02 {
delta_time = 0.02;
}
accumulator_time += delta_time;
while (accumulator_time - step_size) >= step_size {
accumulator_time -= step_size;
}
let mut exit = false;
events_loop.poll_events(|ev| {
match ev {
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } =>
{
exit = true;
},
Event::WindowEvent { event: WindowEvent::Resized(_), .. } => {
processor.recreate_swapchain(&surface);
},
_ => ()
}
});
if exit {
return;
}
s = processor.run(&surface, s);
}
}