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:
Antonino Siena 2020-06-12 18:12:47 +02:00 committed by GitHub
parent c5dd6eda3e
commit b0c8eca283
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 8 deletions

View File

@ -9,24 +9,22 @@ use std::ffi::c_void;
use std::os::raw::c_ulong;
use std::sync::Arc;
use raw_window_handle::RawWindowHandle;
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use vulkano::instance::Instance;
use vulkano::swapchain::Surface;
use vulkano::swapchain::SurfaceCreationError;
/// Creates a vulkan surface from an os-dependent handle
/// window here is a generic type for a Window which can be handed over
/// to ensure that it will be dropped after the surface
/// Creates a vulkan surface from a generic window
/// which implements HasRawWindowHandle and thus can reveal the os-dependent handle
pub fn create_vk_surface_from_handle<W>(
window: W,
handle: RawWindowHandle,
instance: Arc<Instance>,
) -> Result<Arc<Surface<W>>, SurfaceCreationError>
where
W: Sized,
W: HasRawWindowHandle,
{
unsafe {
match handle {
match window.raw_window_handle(){
#[cfg(target_os = "ios")]
RawWindowHandle::IOS(h) => handle_to_surface(h.ui_view, instance, window),
#[cfg(target_os = "macos")]

View File

@ -179,7 +179,7 @@ unsafe fn winit_to_surface<W: SafeBorrow<Window>>(
Surface::from_hwnd(
instance,
ptr::null() as *const (), // FIXME
win.borrow().hinstance(),
win.borrow().hwnd(),
win,
)