wip: add init egui impl

This commit is contained in:
zack 2025-03-31 14:54:56 -04:00
parent f71f0d8e10
commit b1c164dc6a
No known key found for this signature in database
GPG key ID: EE8A2B709E2401D1
4 changed files with 790 additions and 55 deletions

View file

@ -7,6 +7,7 @@ edition = "2021"
egui.workspace = true
ash.workspace = true
ash-window.workspace = true
color-eyre.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
winit.workspace = true
@ -17,3 +18,4 @@ gfx_hal = { path = "../gfx_hal" }
renderer = { path = "../renderer" }
resource_manager = { path = "../resource_manager" }
clap = { version = "4.5.34", features = ["derive"] }
egui-winit = "0.31.1"

View file

@ -8,6 +8,8 @@ use std::{
use ash::vk;
use clap::Parser;
use egui::{Context, ViewportId};
use egui_winit::State;
use gfx_hal::{
device::Device, error::GfxHalError, instance::Instance, instance::InstanceConfig,
physical_device::PhysicalDevice, queue::Queue, surface::Surface,
@ -57,6 +59,10 @@ struct Application {
// Renderer
renderer: Renderer,
egui_ctx: Context,
egui_winit: State,
egui_app: EditorUI,
// Windowing
window: Arc<Window>, // Use Arc for potential multi-threading later
@ -65,6 +71,19 @@ struct Application {
last_frame_time: Instant,
}
#[derive(Default)]
struct EditorUI {}
impl EditorUI {
fn title() -> String {
"engine".to_string()
}
fn build_ui(&mut self, ctx: &egui::Context) {
egui::Window::new(Self::title()).show(ctx, |ui| ui.label(Self::title()));
}
}
#[derive(Default)]
struct ApplicationWrapper {
app: Option<Application>,
@ -223,14 +242,6 @@ impl Application {
// Get specific queues (assuming graphics and present are the same for simplicity)
let graphics_queue = device.get_graphics_queue();
let queue_associated_device_handle = graphics_queue.device().raw().handle();
info!(
"App: Queue is associated with Device handle: {:?}",
queue_associated_device_handle
);
assert_eq!(
device_handle_at_creation, queue_associated_device_handle,
"Device handle mismatch immediately after queue creation!"
);
// --- 4. Resource Manager ---
let resource_manager = Arc::new(ResourceManager::new(instance.clone(), device.clone())?);
@ -238,14 +249,6 @@ impl Application {
let renderer_device_handle_to_pass = device.raw().handle();
let renderer_queue_device_handle_to_pass = graphics_queue.device().raw().handle();
info!(
"App: Passing Device handle to Renderer: {:?}",
renderer_device_handle_to_pass
);
info!(
"App: Passing Queue associated with Device handle: {:?}",
renderer_queue_device_handle_to_pass
);
// --- 5. Renderer ---
let initial_size = window.inner_size();
@ -258,6 +261,18 @@ impl Application {
initial_size.width,
initial_size.height,
)?;
let egui_ctx = Context::default();
let egui_winit = State::new(
egui_ctx.clone(),
ViewportId::ROOT,
&window,
None,
None,
None,
);
let egui_app = EditorUI::default();
info!("Renderer initialized.");
Ok(Self {
@ -269,6 +284,9 @@ impl Application {
_resource_manager: resource_manager,
renderer,
window,
egui_winit,
egui_ctx,
egui_app,
frame_count: 0,
last_fps_update_time: Instant::now(),
last_frame_time: Instant::now(),
@ -320,8 +338,29 @@ impl Application {
self.last_fps_update_time = now;
}
let raw_input = self.egui_winit.take_egui_input(&self.window);
let egui::FullOutput {
platform_output,
textures_delta,
shapes,
pixels_per_point,
..
} = self.egui_ctx.run(raw_input, |ctx| {
self.egui_app.build_ui(ctx);
});
self.egui_winit
.handle_platform_output(&self.window, platform_output);
let clipped_primitives = self.egui_ctx.tessellate(shapes, pixels_per_point);
// --- Render Frame ---
match self.renderer.render_frame() {
match self.renderer.render_frame(
pixels_per_point,
textures_delta,
&clipped_primitives,
) {
Ok(_) => {
self.window.request_redraw();
}
@ -450,6 +489,7 @@ struct Args {
// --- Entry Point ---
fn main() -> Result<(), Box<dyn Error>> {
color_eyre::install()?;
let args = Args::parse();
let fmt_layer = tracing_subscriber::fmt::layer()