depth: Fix not resized
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 8m22s
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 8m22s
This commit is contained in:
parent
650b61e3ae
commit
6a6b1821a4
5 changed files with 38 additions and 44 deletions
|
@ -8,6 +8,8 @@ use crate::core::scene::SceneManager;
|
||||||
use crate::core::timer::Timer;
|
use crate::core::timer::Timer;
|
||||||
use crate::game::main_scene::MainScene;
|
use crate::game::main_scene::MainScene;
|
||||||
use egui_winit_vulkano::{Gui, GuiConfig};
|
use egui_winit_vulkano::{Gui, GuiConfig};
|
||||||
|
use vulkano::format::Format;
|
||||||
|
use vulkano::image::ImageUsage;
|
||||||
use vulkano::swapchain::PresentMode;
|
use vulkano::swapchain::PresentMode;
|
||||||
use vulkano_util::context::VulkanoContext;
|
use vulkano_util::context::VulkanoContext;
|
||||||
use vulkano_util::window::{VulkanoWindows, WindowDescriptor};
|
use vulkano_util::window::{VulkanoWindows, WindowDescriptor};
|
||||||
|
@ -16,6 +18,8 @@ use winit::event::WindowEvent;
|
||||||
use winit::event_loop::ActiveEventLoop;
|
use winit::event_loop::ActiveEventLoop;
|
||||||
use winit::window::WindowId;
|
use winit::window::WindowId;
|
||||||
|
|
||||||
|
pub const DEPTH_IMAGE_ID: usize = 0;
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
vulkan_context: Arc<VulkanContext>,
|
vulkan_context: Arc<VulkanContext>,
|
||||||
vulkano_windows: Arc<VulkanoWindows>,
|
vulkano_windows: Arc<VulkanoWindows>,
|
||||||
|
@ -56,8 +60,14 @@ impl ApplicationHandler for App {
|
||||||
|_| {},
|
|_| {},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let renderer = vulkano_windows.get_renderer_mut(window_id).unwrap();
|
||||||
|
renderer.add_additional_image_view(
|
||||||
|
DEPTH_IMAGE_ID,
|
||||||
|
Format::D16_UNORM,
|
||||||
|
ImageUsage::DEPTH_STENCIL_ATTACHMENT,
|
||||||
|
);
|
||||||
|
|
||||||
let gui = {
|
let gui = {
|
||||||
let renderer = vulkano_windows.get_renderer_mut(window_id).unwrap();
|
|
||||||
Gui::new(
|
Gui::new(
|
||||||
event_loop,
|
event_loop,
|
||||||
renderer.surface(),
|
renderer.surface(),
|
||||||
|
@ -124,8 +134,8 @@ impl ApplicationHandler for App {
|
||||||
None => log::error!("Failed to get a mutable reference to the timer"),
|
None => log::error!("Failed to get a mutable reference to the timer"),
|
||||||
}
|
}
|
||||||
|
|
||||||
let scene_context = SceneContext::from((
|
let mut scene_context = SceneContext::from((
|
||||||
&*renderer,
|
&mut *renderer,
|
||||||
&self.vulkan_context,
|
&self.vulkan_context,
|
||||||
&self.input_manager,
|
&self.input_manager,
|
||||||
&self.timer,
|
&self.timer,
|
||||||
|
@ -139,14 +149,10 @@ impl ApplicationHandler for App {
|
||||||
scene.update(&scene_context).unwrap();
|
scene.update(&scene_context).unwrap();
|
||||||
|
|
||||||
let acquire_future = renderer.acquire(None, |_| {}).unwrap();
|
let acquire_future = renderer.acquire(None, |_| {}).unwrap();
|
||||||
let acquire_future = scene
|
// Update the swapchain image view to the current one after acquiring the next image
|
||||||
.render(
|
scene_context.swapchain_image_view = renderer.swapchain_image_view();
|
||||||
&renderer.swapchain_image_view(),
|
|
||||||
acquire_future,
|
let acquire_future = scene.render(acquire_future, &scene_context, gui).unwrap();
|
||||||
&scene_context,
|
|
||||||
gui,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
renderer.present(acquire_future, true);
|
renderer.present(acquire_future, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ impl Camera3D {
|
||||||
// Process camera rotation
|
// Process camera rotation
|
||||||
let camera_delta = camera_sensitivity * timer.delta_time();
|
let camera_delta = camera_sensitivity * timer.delta_time();
|
||||||
self.rotation += Vec3::new(
|
self.rotation += Vec3::new(
|
||||||
-(input_manager.get_virtual_input_state("mouse_y") * camera_delta).to_radians(),
|
(input_manager.get_virtual_input_state("mouse_y") * camera_delta).to_radians(),
|
||||||
(input_manager.get_virtual_input_state("mouse_x") * camera_delta).to_radians(),
|
(input_manager.get_virtual_input_state("mouse_x") * camera_delta).to_radians(),
|
||||||
0.0,
|
0.0,
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,13 +4,15 @@ use vulkano::{
|
||||||
command_buffer::allocator::StandardCommandBufferAllocator,
|
command_buffer::allocator::StandardCommandBufferAllocator,
|
||||||
descriptor_set::allocator::StandardDescriptorSetAllocator,
|
descriptor_set::allocator::StandardDescriptorSetAllocator,
|
||||||
device::{Device, Queue},
|
device::{Device, Queue},
|
||||||
format::Format,
|
image::view::ImageView,
|
||||||
instance::Instance,
|
instance::Instance,
|
||||||
memory::allocator::StandardMemoryAllocator,
|
memory::allocator::StandardMemoryAllocator,
|
||||||
};
|
};
|
||||||
use vulkano_util::renderer::VulkanoWindowRenderer;
|
use vulkano_util::renderer::VulkanoWindowRenderer;
|
||||||
|
|
||||||
use crate::core::{input::InputManager, render::vulkan_context::VulkanContext, timer::Timer};
|
use crate::core::{
|
||||||
|
app::DEPTH_IMAGE_ID, input::InputManager, render::vulkan_context::VulkanContext, timer::Timer,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct SceneContext {
|
pub struct SceneContext {
|
||||||
pub instance: Arc<Instance>,
|
pub instance: Arc<Instance>,
|
||||||
|
@ -23,14 +25,15 @@ pub struct SceneContext {
|
||||||
pub descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
pub descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||||
pub window_size: [f32; 2],
|
pub window_size: [f32; 2],
|
||||||
pub aspect_ratio: f32,
|
pub aspect_ratio: f32,
|
||||||
pub swapchain_format: Format,
|
pub swapchain_image_view: Arc<ImageView>,
|
||||||
|
pub depth_stencil_image_view: Arc<ImageView>,
|
||||||
pub input_manager: Arc<InputManager>,
|
pub input_manager: Arc<InputManager>,
|
||||||
pub timer: Arc<Timer>,
|
pub timer: Arc<Timer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl
|
impl
|
||||||
From<(
|
From<(
|
||||||
&VulkanoWindowRenderer,
|
&mut VulkanoWindowRenderer,
|
||||||
&Arc<VulkanContext>,
|
&Arc<VulkanContext>,
|
||||||
&Arc<InputManager>,
|
&Arc<InputManager>,
|
||||||
&Arc<Timer>,
|
&Arc<Timer>,
|
||||||
|
@ -38,7 +41,7 @@ impl
|
||||||
{
|
{
|
||||||
fn from(
|
fn from(
|
||||||
(renderer, vulkan_context, input_manager, timer): (
|
(renderer, vulkan_context, input_manager, timer): (
|
||||||
&VulkanoWindowRenderer,
|
&mut VulkanoWindowRenderer,
|
||||||
&Arc<VulkanContext>,
|
&Arc<VulkanContext>,
|
||||||
&Arc<InputManager>,
|
&Arc<InputManager>,
|
||||||
&Arc<Timer>,
|
&Arc<Timer>,
|
||||||
|
@ -74,7 +77,8 @@ impl
|
||||||
descriptor_set_allocator,
|
descriptor_set_allocator,
|
||||||
window_size: renderer.window_size(),
|
window_size: renderer.window_size(),
|
||||||
aspect_ratio: renderer.aspect_ratio(),
|
aspect_ratio: renderer.aspect_ratio(),
|
||||||
swapchain_format: renderer.swapchain_format(),
|
swapchain_image_view: renderer.swapchain_image_view(),
|
||||||
|
depth_stencil_image_view: renderer.get_additional_image_view(DEPTH_IMAGE_ID),
|
||||||
input_manager: input_manager.clone(),
|
input_manager: input_manager.clone(),
|
||||||
timer: timer.clone(),
|
timer: timer.clone(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ pub trait Scene {
|
||||||
fn update(&mut self, scene_context: &SceneContext) -> Result<(), Box<dyn Error>>;
|
fn update(&mut self, scene_context: &SceneContext) -> Result<(), Box<dyn Error>>;
|
||||||
fn render(
|
fn render(
|
||||||
&mut self,
|
&mut self,
|
||||||
image_view: &Arc<ImageView>,
|
|
||||||
acquire_future: Box<dyn GpuFuture>,
|
acquire_future: Box<dyn GpuFuture>,
|
||||||
scene_context: &SceneContext,
|
scene_context: &SceneContext,
|
||||||
gui: &mut Gui,
|
gui: &mut Gui,
|
||||||
|
|
|
@ -12,7 +12,6 @@ use glam::Vec3;
|
||||||
use vulkano::format::Format;
|
use vulkano::format::Format;
|
||||||
use vulkano::image::Image;
|
use vulkano::image::Image;
|
||||||
use vulkano::image::ImageCreateInfo;
|
use vulkano::image::ImageCreateInfo;
|
||||||
use vulkano::image::ImageLayout;
|
|
||||||
use vulkano::image::ImageUsage;
|
use vulkano::image::ImageUsage;
|
||||||
use vulkano::memory::allocator::AllocationCreateInfo;
|
use vulkano::memory::allocator::AllocationCreateInfo;
|
||||||
use vulkano::{
|
use vulkano::{
|
||||||
|
@ -34,7 +33,6 @@ pub struct MainSceneState {
|
||||||
camera: Camera3D,
|
camera: Camera3D,
|
||||||
texture: Texture,
|
texture: Texture,
|
||||||
speed: f32,
|
speed: f32,
|
||||||
depth_image_view: Arc<ImageView>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -48,27 +46,11 @@ impl Scene for MainScene {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load(&mut self, scene_context: &SceneContext) -> Result<(), Box<dyn Error>> {
|
fn load(&mut self, scene_context: &SceneContext) -> Result<(), Box<dyn Error>> {
|
||||||
let depth_image = Image::new(
|
|
||||||
scene_context.memory_allocator.clone(),
|
|
||||||
ImageCreateInfo {
|
|
||||||
format: Format::D16_UNORM,
|
|
||||||
extent: [
|
|
||||||
scene_context.window_size[0] as u32,
|
|
||||||
scene_context.window_size[1] as u32,
|
|
||||||
1,
|
|
||||||
],
|
|
||||||
usage: ImageUsage::DEPTH_STENCIL_ATTACHMENT,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
AllocationCreateInfo::default(),
|
|
||||||
)?;
|
|
||||||
let depth_image_view = ImageView::new_default(depth_image)?;
|
|
||||||
|
|
||||||
let square = Square::new(
|
let square = Square::new(
|
||||||
&scene_context.device,
|
&scene_context.device,
|
||||||
&scene_context.memory_allocator,
|
&scene_context.memory_allocator,
|
||||||
scene_context.swapchain_format,
|
scene_context.swapchain_image_view.format(),
|
||||||
Format::D16_UNORM,
|
scene_context.depth_stencil_image_view.format(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let num_instances = 100;
|
let num_instances = 100;
|
||||||
|
@ -122,7 +104,6 @@ impl Scene for MainScene {
|
||||||
camera,
|
camera,
|
||||||
texture,
|
texture,
|
||||||
speed: 50.0,
|
speed: 50.0,
|
||||||
depth_image_view,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -143,7 +124,6 @@ impl Scene for MainScene {
|
||||||
|
|
||||||
fn render(
|
fn render(
|
||||||
&mut self,
|
&mut self,
|
||||||
image_view: &Arc<ImageView>,
|
|
||||||
acquire_future: Box<dyn GpuFuture>,
|
acquire_future: Box<dyn GpuFuture>,
|
||||||
scene_context: &SceneContext,
|
scene_context: &SceneContext,
|
||||||
gui: &mut Gui,
|
gui: &mut Gui,
|
||||||
|
@ -169,13 +149,17 @@ impl Scene for MainScene {
|
||||||
load_op: AttachmentLoadOp::Clear,
|
load_op: AttachmentLoadOp::Clear,
|
||||||
store_op: AttachmentStoreOp::Store,
|
store_op: AttachmentStoreOp::Store,
|
||||||
clear_value: Some([0.0, 0.0, 0.0, 1.0].into()),
|
clear_value: Some([0.0, 0.0, 0.0, 1.0].into()),
|
||||||
..RenderingAttachmentInfo::image_view(image_view.clone())
|
..RenderingAttachmentInfo::image_view(
|
||||||
|
scene_context.swapchain_image_view.clone(),
|
||||||
|
)
|
||||||
})],
|
})],
|
||||||
depth_attachment: Some(RenderingAttachmentInfo {
|
depth_attachment: Some(RenderingAttachmentInfo {
|
||||||
load_op: AttachmentLoadOp::Clear,
|
load_op: AttachmentLoadOp::Clear,
|
||||||
store_op: AttachmentStoreOp::DontCare,
|
store_op: AttachmentStoreOp::DontCare,
|
||||||
clear_value: Some([1.0].into()),
|
clear_value: Some([1.0].into()),
|
||||||
..RenderingAttachmentInfo::image_view(state.depth_image_view.clone())
|
..RenderingAttachmentInfo::image_view(
|
||||||
|
scene_context.depth_stencil_image_view.clone(),
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})?
|
})?
|
||||||
|
@ -230,7 +214,8 @@ impl Scene for MainScene {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
let render_future = gui.draw_on_image(render_future, image_view.clone());
|
let render_future =
|
||||||
|
gui.draw_on_image(render_future, scene_context.swapchain_image_view.clone());
|
||||||
|
|
||||||
Ok(render_future)
|
Ok(render_future)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue