From 5f2092ef212eb1fd186961cbee41a6e51fd05162 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Tue, 10 Sep 2019 22:04:13 -0700 Subject: [PATCH] fixed 0,1 coord issue. Going to test multiple vertex buffers now --- resources/shaders/simple-edge.compute | 48 +++++++++++++-------------- src/canvas.rs | 3 +- src/compu_state.rs | 2 +- src/main.rs | 25 +++++++++++--- src/sprite.rs | 18 +++++----- src/vkprocessor.rs | 1 + 6 files changed, 57 insertions(+), 40 deletions(-) diff --git a/resources/shaders/simple-edge.compute b/resources/shaders/simple-edge.compute index 36ce1507..46fae630 100644 --- a/resources/shaders/simple-edge.compute +++ b/resources/shaders/simple-edge.compute @@ -36,30 +36,30 @@ void main() { uint idx = get_idx(0,0); ivec4 p = separate(read_buffer.buf[get_idx(0 , 0)]); -// ivec4 p0 = separate(read_buffer.buf[get_idx(0 , 1)]); -// ivec4 p1 = separate(read_buffer.buf[get_idx(0 ,-1)]); -// ivec4 p2 = separate(read_buffer.buf[get_idx(1 , 1)]); -// ivec4 p3 = separate(read_buffer.buf[get_idx(-1,-1)]); -// ivec4 p4 = separate(read_buffer.buf[get_idx(1 , 0)]); -// ivec4 p5 = separate(read_buffer.buf[get_idx(-1, 0)]); -// ivec4 p6 = separate(read_buffer.buf[get_idx(1 ,-1)]); -// ivec4 p7 = separate(read_buffer.buf[get_idx(-1, 1)]); -// -// ivec3 d0 = abs(p0.xyz - p1.xyz); -// ivec3 d1 = abs(p2.xyz - p3.xyz); -// ivec3 d2 = abs(p4.xyz - p5.xyz); -// ivec3 d3 = abs(p6.xyz - p7.xyz); -// -// ivec3 m = max(max(max(d0, d1), d2), d3); -// -// if ((m.x + m.y + m.z) > 200){ -// p.x = 0; -// p.y = 0; -// p.z = 255; -// } -// else { -// //p.w = 125; -// } + ivec4 p0 = separate(read_buffer.buf[get_idx(0 , 1)]); + ivec4 p1 = separate(read_buffer.buf[get_idx(0 ,-1)]); + ivec4 p2 = separate(read_buffer.buf[get_idx(1 , 1)]); + ivec4 p3 = separate(read_buffer.buf[get_idx(-1,-1)]); + ivec4 p4 = separate(read_buffer.buf[get_idx(1 , 0)]); + ivec4 p5 = separate(read_buffer.buf[get_idx(-1, 0)]); + ivec4 p6 = separate(read_buffer.buf[get_idx(1 ,-1)]); + ivec4 p7 = separate(read_buffer.buf[get_idx(-1, 1)]); + + ivec3 d0 = abs(p0.xyz - p1.xyz); + ivec3 d1 = abs(p2.xyz - p3.xyz); + ivec3 d2 = abs(p4.xyz - p5.xyz); + ivec3 d3 = abs(p6.xyz - p7.xyz); + + ivec3 m = max(max(max(d0, d1), d2), d3); + + if ((m.x + m.y + m.z) > 200){ + p.x = 0; + p.y = 0; + p.z = p.z * 2; + } + else { + //p.w = 125; + } write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x000000FF) ) | (p.x); write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x0000FF00) ) | (p.y << 8); diff --git a/src/canvas.rs b/src/canvas.rs index 6a52ae64..fb0154bb 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -396,7 +396,8 @@ impl CanvasState { self.image_vertex_buffer.insert( k.clone(), ImmutableBuffer::from_iter( - v.first().unwrap().iter().cloned(), + v.iter().fold(Vec::new(), |mut acc, x| [acc.as_slice(), x.as_slice()].concat()).iter(), + //v.first().unwrap().iter().cloned(), BufferUsage::vertex_buffer(), self.queue.clone(), ).unwrap().0, diff --git a/src/compu_state.rs b/src/compu_state.rs index a1e294c2..d4c9d841 100644 --- a/src/compu_state.rs +++ b/src/compu_state.rs @@ -154,7 +154,7 @@ impl CompuState { let size = input_buffer.get_size(); command_buffer = command_buffer - .dispatch([size.0/8, size.1/8,1], pipeline, descriptor_set, ()).unwrap() + // .dispatch([size.0/8, size.1/8,1], pipeline, descriptor_set, ()).unwrap() .copy_buffer( input_buffer.get_output_buffer(), output_buffer.get_input_buffer()).unwrap(); diff --git a/src/main.rs b/src/main.rs index 626c82b6..ce464401 100644 --- a/src/main.rs +++ b/src/main.rs @@ -99,19 +99,24 @@ pub fn main() { let sprite = Sprite::new_with_color((0., 0.), (0.1, 0.1), (1., 0., 0., 1.)); let sprite2 = Sprite::new_with_color((-0.3, -0.5), (0.1, 0.1), (0., 1., 0., 1.)); - let compu_sprite1 = CompuSprite::new((-1., -0.5), (1.0, 1.0), (400.0, 400.0), + let image_data = load_raw(String::from("funky-bird.jpg")); + let image_dimensions_f = ((image_data.1).0 as f32, (image_data.1).1 as f32); + let image_dimensions_u = image_data.1; + let compu_sprite1 = CompuSprite::new((-1., -0.5), (1.0, 1.0), image_dimensions_f, // This swap image needs to match the size of the compute - processor.new_swap_image((400, 400))); + processor.new_swap_image(image_dimensions_u)); - let image_data = load_raw(String::from("test2.png")); 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 funky_handle = processor.get_texture_handle(String::from("funky-bird.jpg")).unwrap(); + let sfml_handle = processor.get_texture_handle(String::from("funky-bird.jpg")).unwrap(); + + let sprite3 = Sprite::new_with_texture((0.0, -0.5), (0.5, 0.5), funky_handle.clone()); + let sprite4 = Sprite::new_with_texture((0.3, 0.5), (0.9, 0.9), sfml_handle.clone()); - let sprite3 = Sprite::new_with_texture((0.3, 0.5), (0.5, 0.5), handle.clone()); drop(q2); drop(q1); @@ -120,6 +125,9 @@ pub fn main() { let mut exit = false; + + let mut count = 0; + while let Some(p) = window.get_position() { elapsed_time = timer.elap_time(); delta_time = elapsed_time - current_time; @@ -168,9 +176,16 @@ pub fn main() { compu_frame.add(compute_buffer.clone(), compute_kernel.clone()); compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1); + if elapsed_time > (count) as f32 { + count += 1; + compu_frame.add_chained(compute_buffer.clone(), compute_buffer.clone(), compute_kernel.clone()); + } + let mut canvas = CanvasFrame::new(); canvas.draw(&sprite); canvas.draw(&sprite2); + + canvas.draw(&sprite4); canvas.draw(&sprite3); canvas.draw(&compu_sprite1); diff --git a/src/sprite.rs b/src/sprite.rs index e038b8c4..5ec2e6d3 100644 --- a/src/sprite.rs +++ b/src/sprite.rs @@ -40,12 +40,12 @@ impl Sprite { position: position, ti_position: [ - (-1.0, -1.0), // top left - (-1.0, 1.0), // bottom left + (-0.0, -0.0), // top left + (-0.0, 1.0), // bottom left ( 1.0, 1.0), // bottom right - (-1.0, -1.0), // top left + (-0.0, -0.0), // top left ( 1.0, 1.0), // bottom right - ( 1.0, -1.0), // top right + ( 1.0, -0.0), // top right ], size: size, color: color, @@ -69,15 +69,15 @@ impl Sprite { ], position: position, ti_position: [ - (-1.0, -1.0), // top left - (-1.0, 1.0), // bottom left + (-0.0, -0.0), // top left + (-0.0, 1.0), // bottom left ( 1.0, 1.0), // bottom right - (-1.0, -1.0), // top left + (-0.0, -0.0), // top left ( 1.0, 1.0), // bottom right - ( 1.0, -1.0), // top right + ( 1.0, -0.0), // top right ], size: size, - color: (0.0, 0.0, 0.0, 0.0), + color: (1.0, 0.0, 0.0, 1.0), textured: true, texture_handle: Some(texture_handle.clone()) } diff --git a/src/vkprocessor.rs b/src/vkprocessor.rs index 651553d9..b6867610 100644 --- a/src/vkprocessor.rs +++ b/src/vkprocessor.rs @@ -145,6 +145,7 @@ impl<'a> VkProcessor<'a> { self.canvas.load_texture(String::from("button.png")); self.canvas.load_texture(String::from("background.jpg")); self.canvas.load_texture(String::from("test2.png")); + self.canvas.load_texture(String::from("sfml.png")); } /// A hardcoded list of kernels which can be preloaded from this function