Refactor vertex buffer creations
This commit is contained in:
parent
1169c76b41
commit
11a5083513
7 changed files with 132 additions and 108 deletions
|
@ -1,20 +1,24 @@
|
|||
use crate::renderer::render_context::RenderContext;
|
||||
use crate::renderer::{window_size_dependent_setup, Scene};
|
||||
use std::sync::Arc;
|
||||
use vulkano::command_buffer::allocator::StandardCommandBufferAllocator;
|
||||
use vulkano::device::{Device, DeviceCreateInfo, DeviceExtensions, DeviceFeatures, Queue, QueueCreateInfo, QueueFlags};
|
||||
use vulkano::command_buffer::{
|
||||
AutoCommandBufferBuilder, CommandBufferUsage, RenderingAttachmentInfo, RenderingInfo,
|
||||
};
|
||||
use vulkano::device::physical::PhysicalDeviceType;
|
||||
use vulkano::device::{
|
||||
Device, DeviceCreateInfo, DeviceExtensions, DeviceFeatures, Queue, QueueCreateInfo, QueueFlags,
|
||||
};
|
||||
use vulkano::instance::{Instance, InstanceCreateFlags, InstanceCreateInfo};
|
||||
use vulkano::memory::allocator::StandardMemoryAllocator;
|
||||
use vulkano::swapchain::{acquire_next_image, Surface, SwapchainCreateInfo, SwapchainPresentInfo};
|
||||
use vulkano::{sync, Validated, Version, VulkanError, VulkanLibrary};
|
||||
use vulkano::command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage, RenderingAttachmentInfo, RenderingInfo};
|
||||
use vulkano::render_pass::{AttachmentLoadOp, AttachmentStoreOp};
|
||||
use vulkano::swapchain::{acquire_next_image, Surface, SwapchainCreateInfo, SwapchainPresentInfo};
|
||||
use vulkano::sync::GpuFuture;
|
||||
use vulkano::{sync, Validated, Version, VulkanError, VulkanLibrary};
|
||||
use winit::application::ApplicationHandler;
|
||||
use winit::event::WindowEvent;
|
||||
use winit::event_loop::{ActiveEventLoop, EventLoop};
|
||||
use winit::window::WindowId;
|
||||
use crate::renderer::render_context::RenderContext;
|
||||
use crate::renderer::{window_size_dependent_setup, Scene};
|
||||
|
||||
pub struct App {
|
||||
instance: Arc<Instance>,
|
||||
|
@ -47,7 +51,7 @@ impl App {
|
|||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
.unwrap();
|
||||
|
||||
let mut device_extensions = DeviceExtensions {
|
||||
khr_swapchain: true,
|
||||
|
@ -60,9 +64,7 @@ impl App {
|
|||
.filter(|p| {
|
||||
p.api_version() >= Version::V1_3 || p.supported_extensions().khr_dynamic_rendering
|
||||
})
|
||||
.filter(|p| {
|
||||
p.supported_extensions().contains(&device_extensions)
|
||||
})
|
||||
.filter(|p| p.supported_extensions().contains(&device_extensions))
|
||||
.filter_map(|p| {
|
||||
p.queue_family_properties()
|
||||
.iter()
|
||||
|
@ -73,15 +75,13 @@ impl App {
|
|||
})
|
||||
.map(|i| (p, i as u32))
|
||||
})
|
||||
.min_by_key(|(p, _)| {
|
||||
match p.properties().device_type {
|
||||
PhysicalDeviceType::DiscreteGpu => 0,
|
||||
PhysicalDeviceType::IntegratedGpu => 1,
|
||||
PhysicalDeviceType::VirtualGpu => 2,
|
||||
PhysicalDeviceType::Cpu => 3,
|
||||
PhysicalDeviceType::Other => 4,
|
||||
_ => 5,
|
||||
}
|
||||
.min_by_key(|(p, _)| match p.properties().device_type {
|
||||
PhysicalDeviceType::DiscreteGpu => 0,
|
||||
PhysicalDeviceType::IntegratedGpu => 1,
|
||||
PhysicalDeviceType::VirtualGpu => 2,
|
||||
PhysicalDeviceType::Cpu => 3,
|
||||
PhysicalDeviceType::Other => 4,
|
||||
_ => 5,
|
||||
})
|
||||
.expect("no suitable physical device found");
|
||||
|
||||
|
@ -110,7 +110,7 @@ impl App {
|
|||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
.unwrap();
|
||||
|
||||
let queue = queues.next().unwrap();
|
||||
let memory_allocator = Arc::new(StandardMemoryAllocator::new_default(device.clone()));
|
||||
|
@ -141,16 +141,16 @@ impl ApplicationHandler for App {
|
|||
f64::from(600),
|
||||
));
|
||||
|
||||
let window = Arc::new(
|
||||
event_loop
|
||||
.create_window(window_attributes)
|
||||
.unwrap(),
|
||||
);
|
||||
let window = Arc::new(event_loop.create_window(window_attributes).unwrap());
|
||||
|
||||
let surface = Surface::from_window(self.instance.clone(), window.clone()).unwrap();
|
||||
|
||||
self.rcx = Some(RenderContext::new(window, surface, &self.device));
|
||||
self.scene = Some(Scene::initialize(&self.device, &self.rcx.as_ref().unwrap().swapchain, &self.memory_allocator));
|
||||
self.scene = Some(Scene::initialize(
|
||||
&self.device,
|
||||
&self.rcx.as_ref().unwrap().swapchain,
|
||||
&self.memory_allocator,
|
||||
));
|
||||
}
|
||||
|
||||
fn window_event(&mut self, event_loop: &ActiveEventLoop, _id: WindowId, event: WindowEvent) {
|
||||
|
@ -192,7 +192,7 @@ impl ApplicationHandler for App {
|
|||
rcx.swapchain.clone(),
|
||||
None,
|
||||
)
|
||||
.map_err(Validated::unwrap)
|
||||
.map_err(Validated::unwrap)
|
||||
{
|
||||
Ok(r) => r,
|
||||
Err(VulkanError::OutOfDate) => {
|
||||
|
@ -211,7 +211,7 @@ impl ApplicationHandler for App {
|
|||
self.queue.queue_family_index(),
|
||||
CommandBufferUsage::OneTimeSubmit,
|
||||
)
|
||||
.unwrap();
|
||||
.unwrap();
|
||||
|
||||
builder
|
||||
.begin_rendering(RenderingInfo {
|
||||
|
@ -233,9 +233,7 @@ impl ApplicationHandler for App {
|
|||
scene.render(&mut builder);
|
||||
}
|
||||
|
||||
builder
|
||||
.end_rendering()
|
||||
.unwrap();
|
||||
builder.end_rendering().unwrap();
|
||||
|
||||
let command_buffer = builder.build().unwrap();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue