diff --git a/resources/shaders/add.compute b/resources/shaders/add.compute index 691d95b3..eb936613 100644 --- a/resources/shaders/add.compute +++ b/resources/shaders/add.compute @@ -1,12 +1,16 @@ #version 450 -layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; +layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in; layout(set = 0, binding = 0) buffer Data { uint data[]; } data; void main() { - uint idx = gl_GlobalInvocationID.x; - data.data[idx] += 100; + uint idx = (gl_GlobalInvocationID.y * 720 + gl_GlobalInvocationID.x); + + data.data[idx+0] = 255; + data.data[idx+1] = 0; + data.data[idx+2] = 0; + } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 36cc0251..52634814 100644 --- a/src/main.rs +++ b/src/main.rs @@ -60,7 +60,7 @@ impl<'t> Edge<'t> { let mut surface = RenderTexture::new(800, 600, false).unwrap(); surface.set_smooth(true); let mut bg_sprite = Sprite::with_texture(bg_texture); - bg_sprite.set_position((135., 100.)); + bg_sprite.set_position((0., 0.)); let mut entities = Vec::new(); for i in 0..6 { @@ -174,7 +174,12 @@ fn main() { let mut img = image::open("resources/images/funky-bird.jpg").unwrap(); let xy = img.dimensions(); let data_length = xy.0*xy.1*3; + println!("Buffer length {}", data_length); + println!("Buffer length {}", img.raw_pixels().len()); + println!("Size {:?}", xy); + + let mut image_buffer = Vec::new(); { // Pull out the image data and place it in a sync'd CPU<->GPU buffer @@ -193,7 +198,7 @@ fn main() { // The command buffer I think pretty much serves to define what runs where for how many times let command_buffer = AutoCommandBufferBuilder::primary_one_time_submit(device.clone(), queue.family()).unwrap() - .dispatch([1024, 1, 1], pipeline.clone(), set.clone(), ()).unwrap() + .dispatch([xy.0, xy.1, 1], pipeline.clone(), set.clone(), ()).unwrap() .build().unwrap(); // Create a future for running the command buffer and then just fence it @@ -202,22 +207,25 @@ fn main() { .then_signal_fence_and_flush().unwrap(); // I think this is redundant and returns immediately - future.wait(None).unwrap(); + // future.wait(None).unwrap(); // The buffer is sync'd so we can just read straight from the handle let data_buffer_content = data_buffer.read().unwrap(); - // - for x in 0 .. xy.0 { - for y in 0 .. xy.1 { + for y in 0 .. xy.1 { + for x in 0 .. xy.0 { let r = data_buffer_content[((xy.0 * y + x) * 3 + 0) as usize] as u8; let g = data_buffer_content[((xy.0 * y + x) * 3 + 1) as usize] as u8; let b = data_buffer_content[((xy.0 * y + x) * 3 + 2) as usize] as u8; - // let a = data_buffer_content[((xy.0 * y + x) * 4 + 3) as usize] as u8; - let old = img.get_pixel(x, y); - img.put_pixel(x, y, image::Rgba([r, g, b, 0])); + image_buffer.push(r); + image_buffer.push(g); + image_buffer.push(b); + image_buffer.push(255); + + img.put_pixel(x, y, image::Rgba([r, g, b, 255])) + } } } @@ -227,7 +235,7 @@ fn main() { println!("Starting"); let mut window = RenderWindow::new( - (512, 512), + (900, 900), "Custom drawable", Style::CLOSE, &Default::default(), @@ -239,7 +247,9 @@ fn main() { //========================================== let font = Font::from_file("resources/fonts/sansation.ttf").unwrap(); - let mut bg_texture = Texture::from_file("output.png").unwrap(); + + let mut bg_texture = Texture::new(xy.0, xy.1).unwrap(); + bg_texture.update_from_pixels(image_buffer.as_slice(), xy.0, xy.1, 0, 0); //let mut bg_texture = Texture::from_file("resources/images/sfml.png").unwrap(); //bg_texture.set_smooth(true);