Refactor app context and render pass manager
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 9m10s
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 9m10s
This commit is contained in:
parent
f1ae54bc73
commit
2c169548b9
12 changed files with 846 additions and 466 deletions
135
src/game/scenes/settings_scene.rs
Normal file
135
src/game/scenes/settings_scene.rs
Normal file
|
@ -0,0 +1,135 @@
|
|||
use std::error::Error;
|
||||
|
||||
use crate::core::app::DEPTH_IMAGE_ID;
|
||||
use crate::core::app::context::ApplicationContext;
|
||||
use crate::core::app::user_event::UserEvent;
|
||||
use crate::core::render::render_pass_manager::{RenderPassConfig, RenderPassManager};
|
||||
use crate::core::scene::Scene;
|
||||
use egui_winit_vulkano::egui;
|
||||
use vulkano::{
|
||||
command_buffer::AutoCommandBufferBuilder, command_buffer::CommandBufferUsage, sync::GpuFuture,
|
||||
};
|
||||
|
||||
use super::main_scene::MainScene;
|
||||
|
||||
pub struct SettingsSceneState {
|
||||
current_resolution: [f32; 2],
|
||||
available_resolutions: Vec<(u32, u32)>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct SettingsScene {
|
||||
state: Option<SettingsSceneState>,
|
||||
}
|
||||
|
||||
impl Scene for SettingsScene {
|
||||
fn loaded(&self) -> bool {
|
||||
self.state.is_some()
|
||||
}
|
||||
|
||||
fn load(&mut self, app_context: &mut ApplicationContext) -> Result<(), Box<dyn Error>> {
|
||||
let current_resolution = app_context.get_window_size();
|
||||
let available_resolutions = app_context.get_available_resolutions();
|
||||
|
||||
self.state = Some(SettingsSceneState {
|
||||
current_resolution,
|
||||
available_resolutions,
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, _app_context: &mut ApplicationContext) -> Result<(), Box<dyn Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn render(
|
||||
&mut self,
|
||||
before_future: Box<dyn GpuFuture>,
|
||||
app_context: &mut ApplicationContext,
|
||||
) -> Result<Box<dyn GpuFuture>, Box<dyn Error>> {
|
||||
let state = self.state.as_ref().ok_or("State not found")?;
|
||||
|
||||
let mut builder = AutoCommandBufferBuilder::primary(
|
||||
app_context.command_buffer_allocator.clone(),
|
||||
app_context.graphics_queue.queue_family_index(),
|
||||
CommandBufferUsage::OneTimeSubmit,
|
||||
)?;
|
||||
|
||||
// Utiliser le RenderPassManager
|
||||
{
|
||||
let swapchain_image_view =
|
||||
app_context.with_renderer_mut(|renderer| renderer.swapchain_image_view().clone());
|
||||
let depth_stencil_image_view = app_context.with_renderer_mut(|renderer| {
|
||||
renderer.get_additional_image_view(DEPTH_IMAGE_ID).clone()
|
||||
});
|
||||
let config = RenderPassConfig::default();
|
||||
RenderPassManager::begin_standard_rendering(
|
||||
&mut builder,
|
||||
&config,
|
||||
swapchain_image_view,
|
||||
Some(depth_stencil_image_view),
|
||||
app_context.get_window_size(),
|
||||
)?;
|
||||
}
|
||||
|
||||
// Pas de géométrie dans cette scène - juste un écran de paramètres
|
||||
RenderPassManager::end_rendering(&mut builder)?;
|
||||
|
||||
let command_buffer = builder.build()?;
|
||||
|
||||
let render_future =
|
||||
before_future.then_execute(app_context.graphics_queue.clone(), command_buffer)?;
|
||||
|
||||
let swapchain_image_view =
|
||||
app_context.with_renderer_mut(|renderer| renderer.swapchain_image_view().clone());
|
||||
|
||||
let event_loop_proxy = app_context.event_loop_proxy.clone();
|
||||
let window_id = app_context.window_id;
|
||||
|
||||
let render_future = app_context.with_gui_mut(|gui| {
|
||||
gui.immediate_ui(|gui| {
|
||||
let ctx = gui.context();
|
||||
|
||||
egui::CentralPanel::default().show(&ctx, |ui| {
|
||||
ui.heading("Paramètres");
|
||||
|
||||
ui.separator();
|
||||
|
||||
ui.label(format!(
|
||||
"Résolution actuelle: {:?}",
|
||||
state.current_resolution
|
||||
));
|
||||
|
||||
ui.separator();
|
||||
ui.label("Changer la résolution:");
|
||||
|
||||
for &(width, height) in &state.available_resolutions {
|
||||
if ui.button(format!("{}x{}", width, height)).clicked() {
|
||||
let _ = event_loop_proxy.send_event(UserEvent::ChangeResolution(
|
||||
window_id,
|
||||
width as f32,
|
||||
height as f32,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
if ui.button("Retour au jeu").clicked() {
|
||||
let _ = event_loop_proxy.send_event(UserEvent::ChangeScene(
|
||||
window_id,
|
||||
Box::new(MainScene::default()),
|
||||
));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
gui.draw_on_image(render_future, swapchain_image_view.clone())
|
||||
});
|
||||
|
||||
Ok(render_future)
|
||||
}
|
||||
|
||||
fn unload(&mut self) {}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue