Split vulkan resources
This commit is contained in:
parent
b977f446d3
commit
f585ba78e7
9 changed files with 483 additions and 244 deletions
|
@ -5,12 +5,12 @@ use std::sync::Arc;
|
|||
use vulkano::image::view::ImageView;
|
||||
use vulkano::image::{Image, ImageUsage};
|
||||
use vulkano::pipeline::graphics::viewport::Viewport;
|
||||
use vulkano::swapchain::{Swapchain, SwapchainCreateInfo};
|
||||
use vulkano::swapchain::{Surface, Swapchain, SwapchainCreateInfo};
|
||||
use vulkano::sync::{self, GpuFuture};
|
||||
use vulkano::{Validated, VulkanError};
|
||||
use winit::window::Window;
|
||||
|
||||
use super::vulkan_context::VulkanContext;
|
||||
use crate::{VulkanDevice, VulkanInstance};
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct WindowRenderContext {
|
||||
|
@ -25,27 +25,36 @@ pub struct WindowRenderContext {
|
|||
impl From<&App> for WindowRenderContext {
|
||||
fn from(app: &App) -> Self {
|
||||
let world = app.world();
|
||||
let vulkan_context = world.get_resource::<VulkanContext>().unwrap();
|
||||
let window_handle = world.get_resource::<WindowWrapper>().unwrap();
|
||||
let window_handle = world
|
||||
.get_resource::<WindowWrapper>()
|
||||
.expect("Failed to find window handle");
|
||||
let vulkan_instance = world
|
||||
.get_resource::<VulkanInstance>()
|
||||
.expect("Failed to find vulkan instance");
|
||||
let vulkan_device = world
|
||||
.get_resource::<VulkanDevice>()
|
||||
.expect("Failed to find vulkan device");
|
||||
|
||||
let window_size = window_handle.0.inner_size();
|
||||
|
||||
let surface = vulkan_context.create_surface(window_handle.0.clone());
|
||||
let surface = Surface::from_window(vulkan_instance.0.clone(), window_handle.0.clone())
|
||||
.expect("Failed to create surface");
|
||||
|
||||
let (swapchain, images) = {
|
||||
let surface_capabilities = vulkan_context
|
||||
.device
|
||||
let surface_capabilities = vulkan_device
|
||||
.0
|
||||
.physical_device()
|
||||
.surface_capabilities(&surface, Default::default())
|
||||
.unwrap();
|
||||
|
||||
let (image_format, _) = vulkan_context
|
||||
.device
|
||||
let (image_format, _) = vulkan_device
|
||||
.0
|
||||
.physical_device()
|
||||
.surface_formats(&surface, Default::default())
|
||||
.unwrap()[0];
|
||||
|
||||
Swapchain::new(
|
||||
vulkan_context.device.clone(),
|
||||
vulkan_device.0.clone(),
|
||||
surface,
|
||||
SwapchainCreateInfo {
|
||||
// 2 because with some graphics driver, it crash on fullscreen because fullscreen need to min image to works.
|
||||
|
@ -74,7 +83,7 @@ impl From<&App> for WindowRenderContext {
|
|||
};
|
||||
|
||||
let recreate_swapchain = false;
|
||||
let previous_frame_end = Some(sync::now(vulkan_context.device.clone()).boxed_send_sync());
|
||||
let previous_frame_end = Some(sync::now(vulkan_device.0.clone()).boxed_send_sync());
|
||||
|
||||
Self {
|
||||
window: window_handle.0.clone(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue