use std::error::Error; use crate::core::app::user_event::UserEvent; use crate::core::scene::Scene; use crate::core::scene::SceneContext; use egui_winit_vulkano::{Gui, egui}; use vulkano::command_buffer::AutoCommandBufferBuilder; use vulkano::command_buffer::CommandBufferUsage; use vulkano::command_buffer::RenderingAttachmentInfo; use vulkano::command_buffer::RenderingInfo; use vulkano::pipeline::graphics::viewport::Viewport; use vulkano::render_pass::AttachmentLoadOp; use vulkano::render_pass::AttachmentStoreOp; use vulkano::sync::GpuFuture; use super::main_scene::MainScene; pub struct MainSceneState {} #[derive(Default)] pub struct TestScene { state: Option, } impl Scene for TestScene { fn loaded(&self) -> bool { self.state.is_some() } fn load(&mut self, scene_context: &SceneContext) -> Result<(), Box> { self.state = Some(MainSceneState {}); Ok(()) } fn update(&mut self, scene_context: &SceneContext) -> Result<(), Box> { Ok(()) } fn render( &mut self, acquire_future: Box, scene_context: &SceneContext, gui: &mut Gui, ) -> Result, Box> { let mut builder = AutoCommandBufferBuilder::primary( scene_context.command_buffer_allocator.clone(), scene_context.graphics_queue.queue_family_index(), CommandBufferUsage::OneTimeSubmit, )?; { let viewport = Viewport { offset: [0.0, 0.0], extent: scene_context.window_size, depth_range: 0.0..=1.0, }; builder .begin_rendering(RenderingInfo { color_attachments: vec![Some(RenderingAttachmentInfo { load_op: AttachmentLoadOp::Clear, store_op: AttachmentStoreOp::Store, clear_value: Some([0.0, 0.0, 0.0, 1.0].into()), ..RenderingAttachmentInfo::image_view( scene_context.swapchain_image_view.clone(), ) })], depth_attachment: Some(RenderingAttachmentInfo { load_op: AttachmentLoadOp::Clear, store_op: AttachmentStoreOp::DontCare, clear_value: Some([1.0].into()), ..RenderingAttachmentInfo::image_view( scene_context.depth_stencil_image_view.clone(), ) }), ..Default::default() })? .set_viewport(0, [viewport].into_iter().collect())?; } builder.end_rendering()?; let command_buffer = builder.build()?; let render_future = acquire_future.then_execute(scene_context.graphics_queue.clone(), command_buffer)?; gui.immediate_ui(|gui| { let ctx = gui.context(); egui::CentralPanel::default().show(&ctx, |ui| { if ui.button("Start Game").clicked() { let _ = scene_context .event_loop_proxy .send_event(UserEvent::ChangeScene( scene_context.window_id, Box::new(MainScene::default()), )); } }); }); let render_future = gui.draw_on_image(render_future, scene_context.swapchain_image_view.clone()); Ok(render_future) } fn unload(&mut self) {} }