mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-11-21 14:24:18 +00:00
Use hard-coded vertices in eligible examples (#2454)
* Use hard-coded vertices in eligible examples * Remove outdated todos
This commit is contained in:
parent
b202cb8813
commit
94f50f18bd
@ -51,8 +51,6 @@ impl AmbientLightingSystem {
|
||||
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
||||
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||
) -> AmbientLightingSystem {
|
||||
// TODO: vulkano doesn't allow us to draw without a vertex buffer, otherwise we could
|
||||
// hard-code these values in the shader
|
||||
let vertices = [
|
||||
LightingVertex {
|
||||
position: [-1.0, -1.0],
|
||||
|
@ -52,8 +52,6 @@ impl DirectionalLightingSystem {
|
||||
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
||||
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||
) -> DirectionalLightingSystem {
|
||||
// TODO: vulkano doesn't allow us to draw without a vertex buffer, otherwise we could
|
||||
// hard-code these values in the shader
|
||||
let vertices = [
|
||||
LightingVertex {
|
||||
position: [-1.0, -1.0],
|
||||
|
@ -51,8 +51,6 @@ impl PointLightingSystem {
|
||||
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
||||
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||
) -> PointLightingSystem {
|
||||
// TODO: vulkano doesn't allow us to draw without a vertex buffer, otherwise we could
|
||||
// hard-code these values in the shader
|
||||
let vertices = [
|
||||
LightingVertex {
|
||||
position: [-1.0, -1.0],
|
||||
|
@ -79,7 +79,6 @@ impl FractalApp {
|
||||
),
|
||||
place_over_frame: RenderPassPlaceOverFrame::new(
|
||||
gfx_queue,
|
||||
memory_allocator.clone(),
|
||||
command_buffer_allocator,
|
||||
descriptor_set_allocator,
|
||||
image_format,
|
||||
|
@ -1,6 +1,5 @@
|
||||
use std::sync::Arc;
|
||||
use vulkano::{
|
||||
buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer},
|
||||
command_buffer::{
|
||||
allocator::StandardCommandBufferAllocator, CommandBuffer, CommandBufferBeginInfo,
|
||||
CommandBufferInheritanceInfo, CommandBufferLevel, CommandBufferUsage,
|
||||
@ -14,14 +13,13 @@ use vulkano::{
|
||||
sampler::{Filter, Sampler, SamplerAddressMode, SamplerCreateInfo, SamplerMipmapMode},
|
||||
view::ImageView,
|
||||
},
|
||||
memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator},
|
||||
pipeline::{
|
||||
graphics::{
|
||||
color_blend::{ColorBlendAttachmentState, ColorBlendState},
|
||||
input_assembly::InputAssemblyState,
|
||||
multisample::MultisampleState,
|
||||
rasterization::RasterizationState,
|
||||
vertex_input::{Vertex, VertexDefinition},
|
||||
vertex_input::VertexInputState,
|
||||
viewport::{Viewport, ViewportState},
|
||||
GraphicsPipelineCreateInfo,
|
||||
},
|
||||
@ -32,40 +30,6 @@ use vulkano::{
|
||||
render_pass::Subpass,
|
||||
};
|
||||
|
||||
/// Vertex for textured quads.
|
||||
#[derive(BufferContents, Vertex)]
|
||||
#[repr(C)]
|
||||
pub struct TexturedVertex {
|
||||
#[format(R32G32_SFLOAT)]
|
||||
pub position: [f32; 2],
|
||||
#[format(R32G32_SFLOAT)]
|
||||
pub tex_coords: [f32; 2],
|
||||
}
|
||||
|
||||
pub fn textured_quad(width: f32, height: f32) -> (Vec<TexturedVertex>, Vec<u32>) {
|
||||
(
|
||||
vec![
|
||||
TexturedVertex {
|
||||
position: [-(width / 2.0), -(height / 2.0)],
|
||||
tex_coords: [0.0, 1.0],
|
||||
},
|
||||
TexturedVertex {
|
||||
position: [-(width / 2.0), height / 2.0],
|
||||
tex_coords: [0.0, 0.0],
|
||||
},
|
||||
TexturedVertex {
|
||||
position: [width / 2.0, height / 2.0],
|
||||
tex_coords: [1.0, 0.0],
|
||||
},
|
||||
TexturedVertex {
|
||||
position: [width / 2.0, -(height / 2.0)],
|
||||
tex_coords: [1.0, 1.0],
|
||||
},
|
||||
],
|
||||
vec![0, 2, 1, 0, 3, 2],
|
||||
)
|
||||
}
|
||||
|
||||
/// A subpass pipeline that fills a quad over frame.
|
||||
pub struct PixelsDrawPipeline {
|
||||
gfx_queue: Arc<Queue>,
|
||||
@ -73,48 +37,15 @@ pub struct PixelsDrawPipeline {
|
||||
pipeline: Arc<GraphicsPipeline>,
|
||||
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
||||
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||
vertices: Subbuffer<[TexturedVertex]>,
|
||||
indices: Subbuffer<[u32]>,
|
||||
}
|
||||
|
||||
impl PixelsDrawPipeline {
|
||||
pub fn new(
|
||||
gfx_queue: Arc<Queue>,
|
||||
subpass: Subpass,
|
||||
memory_allocator: Arc<StandardMemoryAllocator>,
|
||||
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
||||
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||
) -> PixelsDrawPipeline {
|
||||
let (vertices, indices) = textured_quad(2.0, 2.0);
|
||||
let vertex_buffer = Buffer::from_iter(
|
||||
memory_allocator.clone(),
|
||||
BufferCreateInfo {
|
||||
usage: BufferUsage::VERTEX_BUFFER,
|
||||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo {
|
||||
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
|
||||
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
|
||||
..Default::default()
|
||||
},
|
||||
vertices,
|
||||
)
|
||||
.unwrap();
|
||||
let index_buffer = Buffer::from_iter(
|
||||
memory_allocator,
|
||||
BufferCreateInfo {
|
||||
usage: BufferUsage::INDEX_BUFFER,
|
||||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo {
|
||||
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
|
||||
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
|
||||
..Default::default()
|
||||
},
|
||||
indices,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let pipeline = {
|
||||
let device = gfx_queue.device();
|
||||
let vs = vs::load(device.clone())
|
||||
@ -125,9 +56,6 @@ impl PixelsDrawPipeline {
|
||||
.expect("failed to create shader module")
|
||||
.entry_point("main")
|
||||
.expect("shader entry point not found");
|
||||
let vertex_input_state = TexturedVertex::per_vertex()
|
||||
.definition(&vs.info().input_interface)
|
||||
.unwrap();
|
||||
let stages = [
|
||||
PipelineShaderStageCreateInfo::new(vs),
|
||||
PipelineShaderStageCreateInfo::new(fs),
|
||||
@ -145,7 +73,7 @@ impl PixelsDrawPipeline {
|
||||
None,
|
||||
GraphicsPipelineCreateInfo {
|
||||
stages: stages.into_iter().collect(),
|
||||
vertex_input_state: Some(vertex_input_state),
|
||||
vertex_input_state: Some(VertexInputState::default()),
|
||||
input_assembly_state: Some(InputAssemblyState::default()),
|
||||
viewport_state: Some(ViewportState::default()),
|
||||
rasterization_state: Some(RasterizationState::default()),
|
||||
@ -168,8 +96,6 @@ impl PixelsDrawPipeline {
|
||||
pipeline,
|
||||
command_buffer_allocator,
|
||||
descriptor_set_allocator,
|
||||
vertices: vertex_buffer,
|
||||
indices: index_buffer,
|
||||
}
|
||||
}
|
||||
|
||||
@ -236,16 +162,10 @@ impl PixelsDrawPipeline {
|
||||
0,
|
||||
self.create_descriptor_set(image),
|
||||
)
|
||||
.unwrap()
|
||||
.bind_vertex_buffers(0, self.vertices.clone())
|
||||
.unwrap()
|
||||
.bind_index_buffer(self.indices.clone())
|
||||
.unwrap();
|
||||
|
||||
unsafe {
|
||||
builder
|
||||
.draw_indexed(self.indices.len() as u32, 1, 0, 0, 0)
|
||||
.unwrap();
|
||||
builder.draw(6, 1, 0, 0).unwrap();
|
||||
}
|
||||
|
||||
builder.end().unwrap()
|
||||
@ -257,14 +177,30 @@ mod vs {
|
||||
ty: "vertex",
|
||||
src: r"
|
||||
#version 450
|
||||
layout(location=0) in vec2 position;
|
||||
layout(location=1) in vec2 tex_coords;
|
||||
|
||||
const vec2[6] POSITIONS = {
|
||||
vec2(-1.0, -1.0),
|
||||
vec2( 1.0, 1.0),
|
||||
vec2(-1.0, 1.0),
|
||||
vec2(-1.0, -1.0),
|
||||
vec2( 1.0, -1.0),
|
||||
vec2( 1.0, 1.0),
|
||||
};
|
||||
|
||||
const vec2[6] TEX_COORDS = {
|
||||
vec2(0.0, 1.0),
|
||||
vec2(1.0, 0.0),
|
||||
vec2(0.0, 0.0),
|
||||
vec2(0.0, 1.0),
|
||||
vec2(1.0, 1.0),
|
||||
vec2(1.0, 0.0),
|
||||
};
|
||||
|
||||
layout(location = 0) out vec2 f_tex_coords;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(position, 0.0, 1.0);
|
||||
f_tex_coords = tex_coords;
|
||||
gl_Position = vec4(POSITIONS[gl_VertexIndex], 0.0, 1.0);
|
||||
f_tex_coords = TEX_COORDS[gl_VertexIndex];
|
||||
}
|
||||
",
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ use vulkano::{
|
||||
device::Queue,
|
||||
format::Format,
|
||||
image::view::ImageView,
|
||||
memory::allocator::StandardMemoryAllocator,
|
||||
render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass, Subpass},
|
||||
sync::GpuFuture,
|
||||
};
|
||||
@ -26,7 +25,6 @@ pub struct RenderPassPlaceOverFrame {
|
||||
impl RenderPassPlaceOverFrame {
|
||||
pub fn new(
|
||||
gfx_queue: Arc<Queue>,
|
||||
memory_allocator: Arc<StandardMemoryAllocator>,
|
||||
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
||||
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||
output_format: Format,
|
||||
@ -51,7 +49,6 @@ impl RenderPassPlaceOverFrame {
|
||||
let pixels_draw_pipeline = PixelsDrawPipeline::new(
|
||||
gfx_queue.clone(),
|
||||
subpass,
|
||||
memory_allocator,
|
||||
command_buffer_allocator.clone(),
|
||||
descriptor_set_allocator,
|
||||
);
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::app::App;
|
||||
use std::sync::Arc;
|
||||
use vulkano::{
|
||||
buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer},
|
||||
command_buffer::{
|
||||
allocator::StandardCommandBufferAllocator, CommandBuffer, CommandBufferBeginInfo,
|
||||
CommandBufferInheritanceInfo, CommandBufferLevel, CommandBufferUsage,
|
||||
@ -15,14 +14,13 @@ use vulkano::{
|
||||
sampler::{Filter, Sampler, SamplerAddressMode, SamplerCreateInfo, SamplerMipmapMode},
|
||||
view::ImageView,
|
||||
},
|
||||
memory::allocator::{AllocationCreateInfo, MemoryTypeFilter},
|
||||
pipeline::{
|
||||
graphics::{
|
||||
color_blend::{ColorBlendAttachmentState, ColorBlendState},
|
||||
input_assembly::InputAssemblyState,
|
||||
multisample::MultisampleState,
|
||||
rasterization::RasterizationState,
|
||||
vertex_input::{Vertex, VertexDefinition},
|
||||
vertex_input::VertexInputState,
|
||||
viewport::{Viewport, ViewportState},
|
||||
GraphicsPipelineCreateInfo,
|
||||
},
|
||||
@ -33,40 +31,6 @@ use vulkano::{
|
||||
render_pass::Subpass,
|
||||
};
|
||||
|
||||
/// Vertex for textured quads.
|
||||
#[derive(BufferContents, Vertex)]
|
||||
#[repr(C)]
|
||||
pub struct TexturedVertex {
|
||||
#[format(R32G32_SFLOAT)]
|
||||
pub position: [f32; 2],
|
||||
#[format(R32G32_SFLOAT)]
|
||||
pub tex_coords: [f32; 2],
|
||||
}
|
||||
|
||||
pub fn textured_quad(width: f32, height: f32) -> (Vec<TexturedVertex>, Vec<u32>) {
|
||||
(
|
||||
vec![
|
||||
TexturedVertex {
|
||||
position: [-(width / 2.0), -(height / 2.0)],
|
||||
tex_coords: [0.0, 1.0],
|
||||
},
|
||||
TexturedVertex {
|
||||
position: [-(width / 2.0), height / 2.0],
|
||||
tex_coords: [0.0, 0.0],
|
||||
},
|
||||
TexturedVertex {
|
||||
position: [width / 2.0, height / 2.0],
|
||||
tex_coords: [1.0, 0.0],
|
||||
},
|
||||
TexturedVertex {
|
||||
position: [width / 2.0, -(height / 2.0)],
|
||||
tex_coords: [1.0, 1.0],
|
||||
},
|
||||
],
|
||||
vec![0, 2, 1, 0, 3, 2],
|
||||
)
|
||||
}
|
||||
|
||||
/// A subpass pipeline that fills a quad over the frame.
|
||||
pub struct PixelsDrawPipeline {
|
||||
gfx_queue: Arc<Queue>,
|
||||
@ -74,43 +38,10 @@ pub struct PixelsDrawPipeline {
|
||||
pipeline: Arc<GraphicsPipeline>,
|
||||
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
||||
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||
vertices: Subbuffer<[TexturedVertex]>,
|
||||
indices: Subbuffer<[u32]>,
|
||||
}
|
||||
|
||||
impl PixelsDrawPipeline {
|
||||
pub fn new(app: &App, gfx_queue: Arc<Queue>, subpass: Subpass) -> PixelsDrawPipeline {
|
||||
let (vertices, indices) = textured_quad(2.0, 2.0);
|
||||
let memory_allocator = app.context.memory_allocator();
|
||||
let vertex_buffer = Buffer::from_iter(
|
||||
memory_allocator.clone(),
|
||||
BufferCreateInfo {
|
||||
usage: BufferUsage::VERTEX_BUFFER,
|
||||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo {
|
||||
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
|
||||
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
|
||||
..Default::default()
|
||||
},
|
||||
vertices,
|
||||
)
|
||||
.unwrap();
|
||||
let index_buffer = Buffer::from_iter(
|
||||
memory_allocator.clone(),
|
||||
BufferCreateInfo {
|
||||
usage: BufferUsage::INDEX_BUFFER,
|
||||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo {
|
||||
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
|
||||
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
|
||||
..Default::default()
|
||||
},
|
||||
indices,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let pipeline = {
|
||||
let device = gfx_queue.device();
|
||||
let vs = vs::load(device.clone())
|
||||
@ -121,9 +52,6 @@ impl PixelsDrawPipeline {
|
||||
.expect("failed to create shader module")
|
||||
.entry_point("main")
|
||||
.expect("shader entry point not found");
|
||||
let vertex_input_state = TexturedVertex::per_vertex()
|
||||
.definition(&vs.info().input_interface)
|
||||
.unwrap();
|
||||
let stages = [
|
||||
PipelineShaderStageCreateInfo::new(vs),
|
||||
PipelineShaderStageCreateInfo::new(fs),
|
||||
@ -141,7 +69,7 @@ impl PixelsDrawPipeline {
|
||||
None,
|
||||
GraphicsPipelineCreateInfo {
|
||||
stages: stages.into_iter().collect(),
|
||||
vertex_input_state: Some(vertex_input_state),
|
||||
vertex_input_state: Some(VertexInputState::default()),
|
||||
input_assembly_state: Some(InputAssemblyState::default()),
|
||||
viewport_state: Some(ViewportState::default()),
|
||||
rasterization_state: Some(RasterizationState::default()),
|
||||
@ -164,8 +92,6 @@ impl PixelsDrawPipeline {
|
||||
pipeline,
|
||||
command_buffer_allocator: app.command_buffer_allocator.clone(),
|
||||
descriptor_set_allocator: app.descriptor_set_allocator.clone(),
|
||||
vertices: vertex_buffer,
|
||||
indices: index_buffer,
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,16 +158,10 @@ impl PixelsDrawPipeline {
|
||||
0,
|
||||
self.create_image_sampler_nearest(image),
|
||||
)
|
||||
.unwrap()
|
||||
.bind_vertex_buffers(0, self.vertices.clone())
|
||||
.unwrap()
|
||||
.bind_index_buffer(self.indices.clone())
|
||||
.unwrap();
|
||||
|
||||
unsafe {
|
||||
builder
|
||||
.draw_indexed(self.indices.len() as u32, 1, 0, 0, 0)
|
||||
.unwrap();
|
||||
builder.draw(6, 1, 0, 0).unwrap();
|
||||
}
|
||||
|
||||
builder.end().unwrap()
|
||||
@ -253,14 +173,30 @@ mod vs {
|
||||
ty: "vertex",
|
||||
src: r"
|
||||
#version 450
|
||||
layout(location=0) in vec2 position;
|
||||
layout(location=1) in vec2 tex_coords;
|
||||
|
||||
const vec2[6] POSITIONS = {
|
||||
vec2(-1.0, -1.0),
|
||||
vec2( 1.0, 1.0),
|
||||
vec2(-1.0, 1.0),
|
||||
vec2(-1.0, -1.0),
|
||||
vec2( 1.0, -1.0),
|
||||
vec2( 1.0, 1.0),
|
||||
};
|
||||
|
||||
const vec2[6] TEX_COORDS = {
|
||||
vec2(0.0, 1.0),
|
||||
vec2(1.0, 0.0),
|
||||
vec2(0.0, 0.0),
|
||||
vec2(0.0, 1.0),
|
||||
vec2(1.0, 1.0),
|
||||
vec2(1.0, 0.0),
|
||||
};
|
||||
|
||||
layout(location = 0) out vec2 f_tex_coords;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(position, 0.0, 1.0);
|
||||
f_tex_coords = tex_coords;
|
||||
gl_Position = vec4(POSITIONS[gl_VertexIndex], 0.0, 1.0);
|
||||
f_tex_coords = TEX_COORDS[gl_VertexIndex];
|
||||
}
|
||||
",
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user