mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-11-22 06:45:23 +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>,
|
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
||||||
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||||
) -> AmbientLightingSystem {
|
) -> 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 = [
|
let vertices = [
|
||||||
LightingVertex {
|
LightingVertex {
|
||||||
position: [-1.0, -1.0],
|
position: [-1.0, -1.0],
|
||||||
|
@ -52,8 +52,6 @@ impl DirectionalLightingSystem {
|
|||||||
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
||||||
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||||
) -> DirectionalLightingSystem {
|
) -> 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 = [
|
let vertices = [
|
||||||
LightingVertex {
|
LightingVertex {
|
||||||
position: [-1.0, -1.0],
|
position: [-1.0, -1.0],
|
||||||
|
@ -51,8 +51,6 @@ impl PointLightingSystem {
|
|||||||
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
||||||
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||||
) -> PointLightingSystem {
|
) -> 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 = [
|
let vertices = [
|
||||||
LightingVertex {
|
LightingVertex {
|
||||||
position: [-1.0, -1.0],
|
position: [-1.0, -1.0],
|
||||||
|
@ -79,7 +79,6 @@ impl FractalApp {
|
|||||||
),
|
),
|
||||||
place_over_frame: RenderPassPlaceOverFrame::new(
|
place_over_frame: RenderPassPlaceOverFrame::new(
|
||||||
gfx_queue,
|
gfx_queue,
|
||||||
memory_allocator.clone(),
|
|
||||||
command_buffer_allocator,
|
command_buffer_allocator,
|
||||||
descriptor_set_allocator,
|
descriptor_set_allocator,
|
||||||
image_format,
|
image_format,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use vulkano::{
|
use vulkano::{
|
||||||
buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer},
|
|
||||||
command_buffer::{
|
command_buffer::{
|
||||||
allocator::StandardCommandBufferAllocator, CommandBuffer, CommandBufferBeginInfo,
|
allocator::StandardCommandBufferAllocator, CommandBuffer, CommandBufferBeginInfo,
|
||||||
CommandBufferInheritanceInfo, CommandBufferLevel, CommandBufferUsage,
|
CommandBufferInheritanceInfo, CommandBufferLevel, CommandBufferUsage,
|
||||||
@ -14,14 +13,13 @@ use vulkano::{
|
|||||||
sampler::{Filter, Sampler, SamplerAddressMode, SamplerCreateInfo, SamplerMipmapMode},
|
sampler::{Filter, Sampler, SamplerAddressMode, SamplerCreateInfo, SamplerMipmapMode},
|
||||||
view::ImageView,
|
view::ImageView,
|
||||||
},
|
},
|
||||||
memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator},
|
|
||||||
pipeline::{
|
pipeline::{
|
||||||
graphics::{
|
graphics::{
|
||||||
color_blend::{ColorBlendAttachmentState, ColorBlendState},
|
color_blend::{ColorBlendAttachmentState, ColorBlendState},
|
||||||
input_assembly::InputAssemblyState,
|
input_assembly::InputAssemblyState,
|
||||||
multisample::MultisampleState,
|
multisample::MultisampleState,
|
||||||
rasterization::RasterizationState,
|
rasterization::RasterizationState,
|
||||||
vertex_input::{Vertex, VertexDefinition},
|
vertex_input::VertexInputState,
|
||||||
viewport::{Viewport, ViewportState},
|
viewport::{Viewport, ViewportState},
|
||||||
GraphicsPipelineCreateInfo,
|
GraphicsPipelineCreateInfo,
|
||||||
},
|
},
|
||||||
@ -32,40 +30,6 @@ use vulkano::{
|
|||||||
render_pass::Subpass,
|
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.
|
/// A subpass pipeline that fills a quad over frame.
|
||||||
pub struct PixelsDrawPipeline {
|
pub struct PixelsDrawPipeline {
|
||||||
gfx_queue: Arc<Queue>,
|
gfx_queue: Arc<Queue>,
|
||||||
@ -73,48 +37,15 @@ pub struct PixelsDrawPipeline {
|
|||||||
pipeline: Arc<GraphicsPipeline>,
|
pipeline: Arc<GraphicsPipeline>,
|
||||||
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
||||||
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||||
vertices: Subbuffer<[TexturedVertex]>,
|
|
||||||
indices: Subbuffer<[u32]>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PixelsDrawPipeline {
|
impl PixelsDrawPipeline {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
gfx_queue: Arc<Queue>,
|
gfx_queue: Arc<Queue>,
|
||||||
subpass: Subpass,
|
subpass: Subpass,
|
||||||
memory_allocator: Arc<StandardMemoryAllocator>,
|
|
||||||
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
||||||
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||||
) -> PixelsDrawPipeline {
|
) -> 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 pipeline = {
|
||||||
let device = gfx_queue.device();
|
let device = gfx_queue.device();
|
||||||
let vs = vs::load(device.clone())
|
let vs = vs::load(device.clone())
|
||||||
@ -125,9 +56,6 @@ impl PixelsDrawPipeline {
|
|||||||
.expect("failed to create shader module")
|
.expect("failed to create shader module")
|
||||||
.entry_point("main")
|
.entry_point("main")
|
||||||
.expect("shader entry point not found");
|
.expect("shader entry point not found");
|
||||||
let vertex_input_state = TexturedVertex::per_vertex()
|
|
||||||
.definition(&vs.info().input_interface)
|
|
||||||
.unwrap();
|
|
||||||
let stages = [
|
let stages = [
|
||||||
PipelineShaderStageCreateInfo::new(vs),
|
PipelineShaderStageCreateInfo::new(vs),
|
||||||
PipelineShaderStageCreateInfo::new(fs),
|
PipelineShaderStageCreateInfo::new(fs),
|
||||||
@ -145,7 +73,7 @@ impl PixelsDrawPipeline {
|
|||||||
None,
|
None,
|
||||||
GraphicsPipelineCreateInfo {
|
GraphicsPipelineCreateInfo {
|
||||||
stages: stages.into_iter().collect(),
|
stages: stages.into_iter().collect(),
|
||||||
vertex_input_state: Some(vertex_input_state),
|
vertex_input_state: Some(VertexInputState::default()),
|
||||||
input_assembly_state: Some(InputAssemblyState::default()),
|
input_assembly_state: Some(InputAssemblyState::default()),
|
||||||
viewport_state: Some(ViewportState::default()),
|
viewport_state: Some(ViewportState::default()),
|
||||||
rasterization_state: Some(RasterizationState::default()),
|
rasterization_state: Some(RasterizationState::default()),
|
||||||
@ -168,8 +96,6 @@ impl PixelsDrawPipeline {
|
|||||||
pipeline,
|
pipeline,
|
||||||
command_buffer_allocator,
|
command_buffer_allocator,
|
||||||
descriptor_set_allocator,
|
descriptor_set_allocator,
|
||||||
vertices: vertex_buffer,
|
|
||||||
indices: index_buffer,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,16 +162,10 @@ impl PixelsDrawPipeline {
|
|||||||
0,
|
0,
|
||||||
self.create_descriptor_set(image),
|
self.create_descriptor_set(image),
|
||||||
)
|
)
|
||||||
.unwrap()
|
|
||||||
.bind_vertex_buffers(0, self.vertices.clone())
|
|
||||||
.unwrap()
|
|
||||||
.bind_index_buffer(self.indices.clone())
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
builder
|
builder.draw(6, 1, 0, 0).unwrap();
|
||||||
.draw_indexed(self.indices.len() as u32, 1, 0, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.end().unwrap()
|
builder.end().unwrap()
|
||||||
@ -257,14 +177,30 @@ mod vs {
|
|||||||
ty: "vertex",
|
ty: "vertex",
|
||||||
src: r"
|
src: r"
|
||||||
#version 450
|
#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;
|
layout(location = 0) out vec2 f_tex_coords;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = vec4(position, 0.0, 1.0);
|
gl_Position = vec4(POSITIONS[gl_VertexIndex], 0.0, 1.0);
|
||||||
f_tex_coords = tex_coords;
|
f_tex_coords = TEX_COORDS[gl_VertexIndex];
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ use vulkano::{
|
|||||||
device::Queue,
|
device::Queue,
|
||||||
format::Format,
|
format::Format,
|
||||||
image::view::ImageView,
|
image::view::ImageView,
|
||||||
memory::allocator::StandardMemoryAllocator,
|
|
||||||
render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass, Subpass},
|
render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass, Subpass},
|
||||||
sync::GpuFuture,
|
sync::GpuFuture,
|
||||||
};
|
};
|
||||||
@ -26,7 +25,6 @@ pub struct RenderPassPlaceOverFrame {
|
|||||||
impl RenderPassPlaceOverFrame {
|
impl RenderPassPlaceOverFrame {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
gfx_queue: Arc<Queue>,
|
gfx_queue: Arc<Queue>,
|
||||||
memory_allocator: Arc<StandardMemoryAllocator>,
|
|
||||||
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
||||||
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||||
output_format: Format,
|
output_format: Format,
|
||||||
@ -51,7 +49,6 @@ impl RenderPassPlaceOverFrame {
|
|||||||
let pixels_draw_pipeline = PixelsDrawPipeline::new(
|
let pixels_draw_pipeline = PixelsDrawPipeline::new(
|
||||||
gfx_queue.clone(),
|
gfx_queue.clone(),
|
||||||
subpass,
|
subpass,
|
||||||
memory_allocator,
|
|
||||||
command_buffer_allocator.clone(),
|
command_buffer_allocator.clone(),
|
||||||
descriptor_set_allocator,
|
descriptor_set_allocator,
|
||||||
);
|
);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use crate::app::App;
|
use crate::app::App;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use vulkano::{
|
use vulkano::{
|
||||||
buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer},
|
|
||||||
command_buffer::{
|
command_buffer::{
|
||||||
allocator::StandardCommandBufferAllocator, CommandBuffer, CommandBufferBeginInfo,
|
allocator::StandardCommandBufferAllocator, CommandBuffer, CommandBufferBeginInfo,
|
||||||
CommandBufferInheritanceInfo, CommandBufferLevel, CommandBufferUsage,
|
CommandBufferInheritanceInfo, CommandBufferLevel, CommandBufferUsage,
|
||||||
@ -15,14 +14,13 @@ use vulkano::{
|
|||||||
sampler::{Filter, Sampler, SamplerAddressMode, SamplerCreateInfo, SamplerMipmapMode},
|
sampler::{Filter, Sampler, SamplerAddressMode, SamplerCreateInfo, SamplerMipmapMode},
|
||||||
view::ImageView,
|
view::ImageView,
|
||||||
},
|
},
|
||||||
memory::allocator::{AllocationCreateInfo, MemoryTypeFilter},
|
|
||||||
pipeline::{
|
pipeline::{
|
||||||
graphics::{
|
graphics::{
|
||||||
color_blend::{ColorBlendAttachmentState, ColorBlendState},
|
color_blend::{ColorBlendAttachmentState, ColorBlendState},
|
||||||
input_assembly::InputAssemblyState,
|
input_assembly::InputAssemblyState,
|
||||||
multisample::MultisampleState,
|
multisample::MultisampleState,
|
||||||
rasterization::RasterizationState,
|
rasterization::RasterizationState,
|
||||||
vertex_input::{Vertex, VertexDefinition},
|
vertex_input::VertexInputState,
|
||||||
viewport::{Viewport, ViewportState},
|
viewport::{Viewport, ViewportState},
|
||||||
GraphicsPipelineCreateInfo,
|
GraphicsPipelineCreateInfo,
|
||||||
},
|
},
|
||||||
@ -33,40 +31,6 @@ use vulkano::{
|
|||||||
render_pass::Subpass,
|
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.
|
/// A subpass pipeline that fills a quad over the frame.
|
||||||
pub struct PixelsDrawPipeline {
|
pub struct PixelsDrawPipeline {
|
||||||
gfx_queue: Arc<Queue>,
|
gfx_queue: Arc<Queue>,
|
||||||
@ -74,43 +38,10 @@ pub struct PixelsDrawPipeline {
|
|||||||
pipeline: Arc<GraphicsPipeline>,
|
pipeline: Arc<GraphicsPipeline>,
|
||||||
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
||||||
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||||
vertices: Subbuffer<[TexturedVertex]>,
|
|
||||||
indices: Subbuffer<[u32]>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PixelsDrawPipeline {
|
impl PixelsDrawPipeline {
|
||||||
pub fn new(app: &App, gfx_queue: Arc<Queue>, subpass: Subpass) -> 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 pipeline = {
|
||||||
let device = gfx_queue.device();
|
let device = gfx_queue.device();
|
||||||
let vs = vs::load(device.clone())
|
let vs = vs::load(device.clone())
|
||||||
@ -121,9 +52,6 @@ impl PixelsDrawPipeline {
|
|||||||
.expect("failed to create shader module")
|
.expect("failed to create shader module")
|
||||||
.entry_point("main")
|
.entry_point("main")
|
||||||
.expect("shader entry point not found");
|
.expect("shader entry point not found");
|
||||||
let vertex_input_state = TexturedVertex::per_vertex()
|
|
||||||
.definition(&vs.info().input_interface)
|
|
||||||
.unwrap();
|
|
||||||
let stages = [
|
let stages = [
|
||||||
PipelineShaderStageCreateInfo::new(vs),
|
PipelineShaderStageCreateInfo::new(vs),
|
||||||
PipelineShaderStageCreateInfo::new(fs),
|
PipelineShaderStageCreateInfo::new(fs),
|
||||||
@ -141,7 +69,7 @@ impl PixelsDrawPipeline {
|
|||||||
None,
|
None,
|
||||||
GraphicsPipelineCreateInfo {
|
GraphicsPipelineCreateInfo {
|
||||||
stages: stages.into_iter().collect(),
|
stages: stages.into_iter().collect(),
|
||||||
vertex_input_state: Some(vertex_input_state),
|
vertex_input_state: Some(VertexInputState::default()),
|
||||||
input_assembly_state: Some(InputAssemblyState::default()),
|
input_assembly_state: Some(InputAssemblyState::default()),
|
||||||
viewport_state: Some(ViewportState::default()),
|
viewport_state: Some(ViewportState::default()),
|
||||||
rasterization_state: Some(RasterizationState::default()),
|
rasterization_state: Some(RasterizationState::default()),
|
||||||
@ -164,8 +92,6 @@ impl PixelsDrawPipeline {
|
|||||||
pipeline,
|
pipeline,
|
||||||
command_buffer_allocator: app.command_buffer_allocator.clone(),
|
command_buffer_allocator: app.command_buffer_allocator.clone(),
|
||||||
descriptor_set_allocator: app.descriptor_set_allocator.clone(),
|
descriptor_set_allocator: app.descriptor_set_allocator.clone(),
|
||||||
vertices: vertex_buffer,
|
|
||||||
indices: index_buffer,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,16 +158,10 @@ impl PixelsDrawPipeline {
|
|||||||
0,
|
0,
|
||||||
self.create_image_sampler_nearest(image),
|
self.create_image_sampler_nearest(image),
|
||||||
)
|
)
|
||||||
.unwrap()
|
|
||||||
.bind_vertex_buffers(0, self.vertices.clone())
|
|
||||||
.unwrap()
|
|
||||||
.bind_index_buffer(self.indices.clone())
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
builder
|
builder.draw(6, 1, 0, 0).unwrap();
|
||||||
.draw_indexed(self.indices.len() as u32, 1, 0, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.end().unwrap()
|
builder.end().unwrap()
|
||||||
@ -253,14 +173,30 @@ mod vs {
|
|||||||
ty: "vertex",
|
ty: "vertex",
|
||||||
src: r"
|
src: r"
|
||||||
#version 450
|
#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;
|
layout(location = 0) out vec2 f_tex_coords;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = vec4(position, 0.0, 1.0);
|
gl_Position = vec4(POSITIONS[gl_VertexIndex], 0.0, 1.0);
|
||||||
f_tex_coords = tex_coords;
|
f_tex_coords = TEX_COORDS[gl_VertexIndex];
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user