feat(renderer): update new() to accept window handles

Updated the Renderer constructor to accept RawDisplayHandle and RawWindowHandle, and updated the client to pass these handles during resumption. This is a prerequisite for surface creation.
This commit is contained in:
Serkyo 2026-04-30 14:46:54 +02:00
parent 70e08dd883
commit 347f868af1
4 changed files with 16 additions and 3 deletions

1
Cargo.lock generated
View file

@ -1054,6 +1054,7 @@ name = "renderer"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"ash", "ash",
"raw-window-handle",
"thiserror 2.0.18", "thiserror 2.0.18",
"tracing", "tracing",
] ]

View file

@ -1,5 +1,5 @@
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use raw_window_handle::HasDisplayHandle; use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
use tracing::info; use tracing::info;
use winit::application::ApplicationHandler; use winit::application::ApplicationHandler;
use winit::event::WindowEvent; use winit::event::WindowEvent;
@ -23,10 +23,15 @@ impl ApplicationHandler for App {
.expect("Failed to get display handle") .expect("Failed to get display handle")
.as_raw(); .as_raw();
// Get the window handle for surface creation
let window_handle = self.window.as_ref().unwrap().window_handle()
.expect("Failed to get window handle")
.as_raw();
let required_extensions = ash_window::enumerate_required_extensions(display_handle) let required_extensions = ash_window::enumerate_required_extensions(display_handle)
.expect("Failed to enumerate required extensions"); .expect("Failed to enumerate required extensions");
let renderer = renderer::Renderer::new(required_extensions) let renderer = renderer::Renderer::new(display_handle, window_handle, required_extensions)
.expect("Failed to initialize Vulkan renderer"); .expect("Failed to initialize Vulkan renderer");
self.renderer = Some(renderer); self.renderer = Some(renderer);

View file

@ -5,5 +5,6 @@ edition = "2024"
[dependencies] [dependencies]
ash = "0.38.0" ash = "0.38.0"
raw-window-handle = "0.6.2"
thiserror = "2.0.18" thiserror = "2.0.18"
tracing = "0.1.44" tracing = "0.1.44"

View file

@ -2,6 +2,7 @@ pub mod error;
use std::ffi::{CStr, c_char}; use std::ffi::{CStr, c_char};
use ash::{Entry, Instance, ext, vk, Device}; use ash::{Entry, Instance, ext, vk, Device};
use raw_window_handle::{RawDisplayHandle, RawWindowHandle};
use tracing::{debug, error, info, warn}; use tracing::{debug, error, info, warn};
pub use error::RendererError; pub use error::RendererError;
@ -32,8 +33,13 @@ impl Renderer {
/// This function loads the Vulkan library, creates an instance, selects a GPU, /// This function loads the Vulkan library, creates an instance, selects a GPU,
/// and initializes a logical device with a graphics queue. /// and initializes a logical device with a graphics queue.
/// ///
/// `display_handle` and `window_handle` are used to create the OS-specific surface.
/// `required_extensions` are raw C-strings (pointers) provided by the windowing system. /// `required_extensions` are raw C-strings (pointers) provided by the windowing system.
pub fn new(required_extensions: &[*const c_char]) -> Result<Self, RendererError> { pub fn new(
display_handle: RawDisplayHandle,
window_handle: RawWindowHandle,
required_extensions: &[*const c_char],
) -> Result<Self, RendererError> {
let entry = unsafe { Entry::load() }?; let entry = unsafe { Entry::load() }?;
// Prepare extensions and layers // Prepare extensions and layers