Add instances support
This commit is contained in:
parent
f8b81f3269
commit
77c717f90b
7 changed files with 158 additions and 31 deletions
|
@ -30,26 +30,26 @@ use vulkano::{
|
|||
};
|
||||
|
||||
use crate::core::render::{
|
||||
primitives::{mvp::MVP, vertex::Vertex2D},
|
||||
primitives::{mvp::MVP, transform::TransformRaw, vertex::Vertex3D},
|
||||
texture::Texture,
|
||||
};
|
||||
|
||||
const VERTICES: [Vertex2D; 4] = [
|
||||
Vertex2D {
|
||||
position: [0.0, 0.0],
|
||||
const VERTICES: [Vertex3D; 4] = [
|
||||
Vertex3D {
|
||||
position: [-0.5, -0.5, 0.0],
|
||||
uv: [0.0, 0.0],
|
||||
},
|
||||
Vertex2D {
|
||||
position: [0.0, 5.0],
|
||||
uv: [0.0, 0.5],
|
||||
Vertex3D {
|
||||
position: [-0.5, 0.5, 0.0],
|
||||
uv: [0.0, 1.0],
|
||||
},
|
||||
Vertex2D {
|
||||
position: [10.0, 0.0],
|
||||
Vertex3D {
|
||||
position: [0.5, -0.5, 0.0],
|
||||
uv: [1.0, 0.0],
|
||||
},
|
||||
Vertex2D {
|
||||
position: [10.0, 5.0],
|
||||
uv: [1.0, 0.5],
|
||||
Vertex3D {
|
||||
position: [0.5, 0.5, 0.0],
|
||||
uv: [1.0, 1.0],
|
||||
},
|
||||
];
|
||||
|
||||
|
@ -74,7 +74,7 @@ pub mod shaders {
|
|||
}
|
||||
|
||||
pub struct Square {
|
||||
vertex_buffer: Subbuffer<[Vertex2D]>,
|
||||
vertex_buffer: Subbuffer<[Vertex3D]>,
|
||||
index_buffer: Subbuffer<[u32]>,
|
||||
pipeline: Arc<GraphicsPipeline>,
|
||||
}
|
||||
|
@ -120,7 +120,8 @@ impl Square {
|
|||
.entry_point("main")
|
||||
.ok_or("Failed find main entry point of fragment shader".to_string())?;
|
||||
|
||||
let vertex_input_state = Vertex2D::per_vertex().definition(&vs)?;
|
||||
let vertex_input_state =
|
||||
[Vertex3D::per_vertex(), TransformRaw::per_instance()].definition(&vs)?;
|
||||
|
||||
let stages = [
|
||||
PipelineShaderStageCreateInfo::new(vs),
|
||||
|
@ -207,6 +208,7 @@ impl Square {
|
|||
command_buffer: &mut AutoCommandBufferBuilder<PrimaryAutoCommandBuffer>,
|
||||
descriptor_set_allocator: &Arc<StandardDescriptorSetAllocator>,
|
||||
mvp_uniform: &Subbuffer<[MVP]>,
|
||||
transform_uniform: &Subbuffer<[TransformRaw]>,
|
||||
texture: &Texture,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let layouts = self.pipeline.layout().set_layouts();
|
||||
|
@ -235,11 +237,18 @@ impl Square {
|
|||
0,
|
||||
vec![uniform_descriptor_set, texture_descriptor_set],
|
||||
)?;
|
||||
command_buffer.bind_vertex_buffers(0, self.vertex_buffer.clone())?;
|
||||
command_buffer
|
||||
.bind_vertex_buffers(0, (self.vertex_buffer.clone(), transform_uniform.clone()))?;
|
||||
command_buffer.bind_index_buffer(self.index_buffer.clone())?;
|
||||
|
||||
unsafe {
|
||||
command_buffer.draw_indexed(INDICES.len() as u32, 1, 0, 0, 0)?;
|
||||
command_buffer.draw_indexed(
|
||||
INDICES.len() as u32,
|
||||
transform_uniform.len() as u32,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue