split vertex to vulkan::data, use immutable buffers

ecs
q3k 2020-01-20 03:26:06 +01:00
parent 154dd2b5dc
commit fde3c4f94c
4 changed files with 31 additions and 24 deletions

View File

@ -8,6 +8,7 @@ rust_binary(
"src/render/mod.rs",
"src/render/vulkan/mod.rs",
"src/render/vulkan/binding.rs",
"src/render/vulkan/data.rs",
"src/render/vulkan/qfi.rs",
"src/render/vulkan/shaders.rs",
"src/render/vulkan/swapchains.rs",

View File

@ -0,0 +1,20 @@
#[derive(Copy, Clone)]
pub struct Vertex {
pos: [f32; 3],
color: [f32; 3],
}
impl Vertex {
pub fn new(pos: [f32; 3], color: [f32; 3]) -> Self {
Self { pos, color }
}
}
vulkano::impl_vertex!(Vertex, pos, color);
pub fn vertices() -> [Vertex; 3] {
[
Vertex::new([0.0, -0.5, 0.0], [1.0, 1.0, 1.0]),
Vertex::new([0.5, 0.5, 0.0], [0.0, 1.0, 0.0]),
Vertex::new([-0.5, 0.5, 0.0], [0.0, 0.0, 1.])
]
}

View File

@ -11,6 +11,7 @@ use vulkano::pipeline as vp;
use vulkano::sync::{FenceSignalFuture, GpuFuture};
mod binding;
mod data;
mod shaders;
mod swapchains;
mod qfi;
@ -102,8 +103,14 @@ impl<WT: 'static + Send + Sync> Instance<WT> {
let render_pass = self.render_pass.as_ref().unwrap().clone();
let pipeline = shaders::pipeline_forward(device.clone(), chain.dimensions(), render_pass);
let buffer = vb::cpu_access::CpuAccessibleBuffer::from_iter(device.clone(),
vb::BufferUsage::vertex_buffer(), vertices().iter().cloned()).unwrap();
let (buffer, future) = vb::immutable::ImmutableBuffer::from_iter(
data::vertices().iter().cloned(),
vb::BufferUsage::vertex_buffer(),
self.binding.as_ref().unwrap().graphics_queue.clone(),
).unwrap();
future.flush().unwrap();
self.create_command_buffers(pipeline, buffer);
self.previous_frame_end = None;
@ -230,24 +237,3 @@ impl<WT: 'static + Send + Sync> Instance<WT> {
}).expect("could not create debug callback")
}
}
#[derive(Copy, Clone)]
struct Vertex {
pos: [f32; 3],
color: [f32; 3],
}
impl Vertex {
pub fn new(pos: [f32; 3], color: [f32; 3]) -> Self {
Self { pos, color }
}
}
vulkano::impl_vertex!(Vertex, pos, color);
fn vertices() -> [Vertex; 3] {
[
Vertex::new([0.0, -0.5, 0.0], [1.0, 1.0, 1.0]),
Vertex::new([0.5, 0.5, 0.0], [0.0, 1.0, 0.0]),
Vertex::new([-0.5, 0.5, 0.0], [0.0, 0.0, 1.])
]
}

View File

@ -50,7 +50,7 @@ pub fn pipeline_forward(
};
Arc::new(vp::GraphicsPipeline::start()
.vertex_input_single_buffer::<super::Vertex>()
.vertex_input_single_buffer::<super::data::Vertex>()
.vertex_shader(vertex.entry_point(), ())
.triangle_list()
.primitive_restart(false)