@ -35,6 +35,7 @@ use crate::util::load_raw;
use crate ::util ::timer ::Timer ;
use crate ::util ::vertex ::{ TextureVertex3D , VertexTypes } ;
use crate ::vkprocessor ::VkProcessor ;
use std ::path ::Path ;
pub mod util ;
pub mod vkprocessor ;
@ -87,15 +88,22 @@ pub fn main() {
let mut current_time : f32 = timer . elap_time ( ) ;
let image_data = load_raw ( String ::from ( "funky-bird.jpg" ) ) ;
let image_dimensions_f : ( f32 , f32 ) = ( ( image_data . 1 ) . 0 as f32 , ( image_data . 1 ) . 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 compu_sprite1 : CompuSprite =
CompuSprite ::new ( ( 0.0 , - 0.5 ) , ( 0.4, 0.4 ) , 0 , image_dimensions_f ,
CompuSprite ::new ( ( 0.0 , - 0.5 ) , ( 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 ) ) ;
// Demo gpu toolpath generation
// Need to
let compute_buffer : Arc < CompuBufferHandle > =
processor . new_compute_buffer ( image_data . 0 , image_data . 1 , 4 ) ;
processor . new_compute_buffer ( image_data . 0. clone ( ) , image_data . 1 , 4 ) ;
let first_output_buffer : Arc < CompuBufferHandle > =
processor . new_compute_buffer ( image_data . 0. clone ( ) , image_data . 1. clone ( ) , 4 ) ;
let compute_kernel : Arc < CompuKernelHandle > =
processor . get_kernel_handle ( String ::from ( "simple-edge.compute" ) )
@ -123,10 +131,6 @@ pub fn main() {
let l = hprof ::enter ( "Loop" ) ;
let mut exit = false ;
let mut count = 0 ;
// while let true = processor.is_open() {
//
// // Take care of our timing
@ -164,6 +168,9 @@ pub fn main() {
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 ) ;
compu_frame . add ( compute_buffer . clone ( ) , compute_kernel . clone ( ) ) ;
canvas_frame . draw ( & compu_sprite1 ) ;
{
let g = hprof ::enter ( "Run" ) ;
@ -171,6 +178,7 @@ pub fn main() {
canvas_frame ,
compu_frame ) ;
}
}
Event ::DeviceEvent { event : DeviceEvent ::Key ( keyboard_input ) , .. } = > {
match keyboard_input . virtual_keycode . unwrap ( ) {
@ -178,6 +186,12 @@ pub fn main() {
if keyboard_input . state = = ElementState ::Pressed {
// processor.save_edges_image();
}
} ,
VirtualKeyCode ::P = > {
if keyboard_input . state = = ElementState ::Pressed {
let data = processor . read_compute_buffer ( compute_buffer . clone ( ) ) ;
image ::save_buffer ( & Path ::new ( "image.png" ) , data . as_slice ( ) , ( image_data . 1 ) . 0 , ( image_data . 1 ) . 1 , image ::RGBA ( 8 ) ) ;
}
}
_ = > ( )
}