adding another buffer for xy

This commit is contained in:
2019-06-30 01:11:29 -07:00
parent 4de26c702d
commit 8c22536653
2 changed files with 85 additions and 28 deletions

View File

@@ -33,6 +33,7 @@ use std::fs;
use crate::input::Input;
use crate::slider::Slider;
use crate::timer::Timer;
use na::DimAdd;
mod slider;
mod timer;
@@ -171,28 +172,42 @@ fn main() {
});
// Load up the input image, determine some details
let mut img = image::open("resources/images/funky-bird.jpg").unwrap();
let mut img = image::open("resources/images/background.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 data_length = xy.0*xy.1*4;
let mut image_buffer = Vec::new();
for i in img.raw_pixels().iter() {
if (image_buffer.len() + 1) % 4 == 0 {
image_buffer.push(255);
}
image_buffer.push(*i);
}
image_buffer.push(255);
println!("Buffer length {}", data_length);
println!("Buffer length {}", image_buffer.len());
println!("Size {:?}", xy);
{
// Pull out the image data and place it in a sync'd CPU<->GPU buffer
// Raw pixels is a u8 rgb buffer (x*y*3)
let data_buffer = {
let mut buff = img.raw_pixels();
let mut buff = buff.iter();
//let mut buff = img.raw_pixels();
let mut buff = image_buffer.iter();
let data_iter = (0 .. data_length).map(|n| *(buff.next().unwrap()));
CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::all(), data_iter).unwrap()
};
let settings_buffer = {
CpuAccessibleBuffer::from_data(device.clone(), BufferUsage::all(), vec![xy.0, xy.1]).unwrap()
};
// Create the data descriptor set for our previously created shader pipeline
let set = Arc::new(PersistentDescriptorSet::start(pipeline.clone(), 0)
.add_buffer(data_buffer.clone()).unwrap()
.add_buffer(settings_buffer.clone()).unwrap()
.build().unwrap()
);
@@ -207,30 +222,30 @@ 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 y in 0 .. xy.1 {
for x in 0 .. xy.0 {
let r = data_buffer_content[((xy.0 * y + x) * 4 + 0) as usize] as u8;
let g = data_buffer_content[((xy.0 * y + x) * 4 + 1) as usize] as u8;
let b = data_buffer_content[((xy.0 * y + x) * 4 + 2) as usize] as u8;
let a = data_buffer_content[((xy.0 * y + x) * 4 + 3) as usize] as u8;
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;
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]))
*image_buffer.get_mut(((xy.0 * y + x) * 4 + 0) as usize).unwrap() = r;
*image_buffer.get_mut(((xy.0 * y + x) * 4 + 1) as usize).unwrap() = g;
*image_buffer.get_mut(((xy.0 * y + x) * 4 + 2) as usize).unwrap() = b;
*image_buffer.get_mut(((xy.0 * y + x) * 4 + 3) as usize).unwrap() = a;
img.put_pixel(x, y, image::Rgba([r, g, b, a]))
}
}
}
img.save("output.png");
img.save("output9.png");
println!("Starting");
@@ -241,6 +256,7 @@ fn main() {
&Default::default(),
);
let mut timer = Timer::new();
let mut input = Input::new();
@@ -311,8 +327,8 @@ fn main() {
accumulator_time -= step_size;
}
let x = window.mouse_position().x as f32 / window.size().x as f32;
let y = window.mouse_position().y as f32 / window.size().y as f32;
let x = 0.;//window.mouse_position().x as f32 / window.size().x as f32;
let y = 0.;//window.mouse_position().y as f32 / window.size().y as f32;
effects[current].update(elapsed_time*1.0, x, y);
window.clear(&Color::BLACK);