depth: Fix not resized
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 8m22s

This commit is contained in:
Florian RICHER 2025-05-29 18:16:26 +02:00
parent 650b61e3ae
commit 6a6b1821a4
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
5 changed files with 38 additions and 44 deletions

View file

@ -8,6 +8,8 @@ use crate::core::scene::SceneManager;
use crate::core::timer::Timer;
use crate::game::main_scene::MainScene;
use egui_winit_vulkano::{Gui, GuiConfig};
use vulkano::format::Format;
use vulkano::image::ImageUsage;
use vulkano::swapchain::PresentMode;
use vulkano_util::context::VulkanoContext;
use vulkano_util::window::{VulkanoWindows, WindowDescriptor};
@ -16,6 +18,8 @@ use winit::event::WindowEvent;
use winit::event_loop::ActiveEventLoop;
use winit::window::WindowId;
pub const DEPTH_IMAGE_ID: usize = 0;
pub struct App {
vulkan_context: Arc<VulkanContext>,
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 renderer = vulkano_windows.get_renderer_mut(window_id).unwrap();
Gui::new(
event_loop,
renderer.surface(),
@ -124,8 +134,8 @@ impl ApplicationHandler for App {
None => log::error!("Failed to get a mutable reference to the timer"),
}
let scene_context = SceneContext::from((
&*renderer,
let mut scene_context = SceneContext::from((
&mut *renderer,
&self.vulkan_context,
&self.input_manager,
&self.timer,
@ -139,14 +149,10 @@ impl ApplicationHandler for App {
scene.update(&scene_context).unwrap();
let acquire_future = renderer.acquire(None, |_| {}).unwrap();
let acquire_future = scene
.render(
&renderer.swapchain_image_view(),
acquire_future,
&scene_context,
gui,
)
.unwrap();
// Update the swapchain image view to the current one after acquiring the next image
scene_context.swapchain_image_view = renderer.swapchain_image_view();
let acquire_future = scene.render(acquire_future, &scene_context, gui).unwrap();
renderer.present(acquire_future, true);
}
}

View file

@ -55,7 +55,7 @@ impl Camera3D {
// Process camera rotation
let camera_delta = camera_sensitivity * timer.delta_time();
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(),
0.0,
);

View file

@ -4,13 +4,15 @@ use vulkano::{
command_buffer::allocator::StandardCommandBufferAllocator,
descriptor_set::allocator::StandardDescriptorSetAllocator,
device::{Device, Queue},
format::Format,
image::view::ImageView,
instance::Instance,
memory::allocator::StandardMemoryAllocator,
};
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 instance: Arc<Instance>,
@ -23,14 +25,15 @@ pub struct SceneContext {
pub descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
pub window_size: [f32; 2],
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 timer: Arc<Timer>,
}
impl
From<(
&VulkanoWindowRenderer,
&mut VulkanoWindowRenderer,
&Arc<VulkanContext>,
&Arc<InputManager>,
&Arc<Timer>,
@ -38,7 +41,7 @@ impl
{
fn from(
(renderer, vulkan_context, input_manager, timer): (
&VulkanoWindowRenderer,
&mut VulkanoWindowRenderer,
&Arc<VulkanContext>,
&Arc<InputManager>,
&Arc<Timer>,
@ -74,7 +77,8 @@ impl
descriptor_set_allocator,
window_size: renderer.window_size(),
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(),
timer: timer.clone(),
}

View file

@ -15,7 +15,6 @@ pub trait Scene {
fn update(&mut self, scene_context: &SceneContext) -> Result<(), Box<dyn Error>>;
fn render(
&mut self,
image_view: &Arc<ImageView>,
acquire_future: Box<dyn GpuFuture>,
scene_context: &SceneContext,
gui: &mut Gui,