mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-11-22 14:56:42 +00:00
Improve vulkano-win (#1386)
* Use winit's hinstance() function * Require HasRawWindowHandle for the window and remove handle parameter Co-authored-by: Antonino Siena <a.siena@gmx.de>
This commit is contained in:
parent
c5dd6eda3e
commit
b0c8eca283
@ -9,24 +9,22 @@ use std::ffi::c_void;
|
|||||||
use std::os::raw::c_ulong;
|
use std::os::raw::c_ulong;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use raw_window_handle::RawWindowHandle;
|
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
|
||||||
use vulkano::instance::Instance;
|
use vulkano::instance::Instance;
|
||||||
use vulkano::swapchain::Surface;
|
use vulkano::swapchain::Surface;
|
||||||
use vulkano::swapchain::SurfaceCreationError;
|
use vulkano::swapchain::SurfaceCreationError;
|
||||||
|
|
||||||
/// Creates a vulkan surface from an os-dependent handle
|
/// Creates a vulkan surface from a generic window
|
||||||
/// window here is a generic type for a Window which can be handed over
|
/// which implements HasRawWindowHandle and thus can reveal the os-dependent handle
|
||||||
/// to ensure that it will be dropped after the surface
|
|
||||||
pub fn create_vk_surface_from_handle<W>(
|
pub fn create_vk_surface_from_handle<W>(
|
||||||
window: W,
|
window: W,
|
||||||
handle: RawWindowHandle,
|
|
||||||
instance: Arc<Instance>,
|
instance: Arc<Instance>,
|
||||||
) -> Result<Arc<Surface<W>>, SurfaceCreationError>
|
) -> Result<Arc<Surface<W>>, SurfaceCreationError>
|
||||||
where
|
where
|
||||||
W: Sized,
|
W: HasRawWindowHandle,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
match handle {
|
match window.raw_window_handle(){
|
||||||
#[cfg(target_os = "ios")]
|
#[cfg(target_os = "ios")]
|
||||||
RawWindowHandle::IOS(h) => handle_to_surface(h.ui_view, instance, window),
|
RawWindowHandle::IOS(h) => handle_to_surface(h.ui_view, instance, window),
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
|
@ -179,7 +179,7 @@ unsafe fn winit_to_surface<W: SafeBorrow<Window>>(
|
|||||||
|
|
||||||
Surface::from_hwnd(
|
Surface::from_hwnd(
|
||||||
instance,
|
instance,
|
||||||
ptr::null() as *const (), // FIXME
|
win.borrow().hinstance(),
|
||||||
win.borrow().hwnd(),
|
win.borrow().hwnd(),
|
||||||
win,
|
win,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user