mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-11-22 06:45:23 +00:00
Fix game of life example on macos (#1829)
This commit is contained in:
parent
407d99a4a5
commit
d1ab3f6726
@ -23,7 +23,7 @@ use vulkano::{
|
|||||||
sync,
|
sync,
|
||||||
sync::{FlushError, GpuFuture},
|
sync::{FlushError, GpuFuture},
|
||||||
};
|
};
|
||||||
use vulkano_win::create_surface_from_handle;
|
use vulkano_win::create_surface_from_winit;
|
||||||
use winit::window::Window;
|
use winit::window::Window;
|
||||||
|
|
||||||
pub struct VulkanoWindow {
|
pub struct VulkanoWindow {
|
||||||
@ -52,7 +52,7 @@ impl VulkanoWindow {
|
|||||||
vsync: bool,
|
vsync: bool,
|
||||||
) -> VulkanoWindow {
|
) -> VulkanoWindow {
|
||||||
// Create rendering surface from window
|
// Create rendering surface from window
|
||||||
let surface = create_surface_from_handle(window, vulkano_context.instance()).unwrap();
|
let surface = create_surface_from_winit(window, vulkano_context.instance()).unwrap();
|
||||||
// Create swap chain & frame(s) to which we'll render
|
// Create swap chain & frame(s) to which we'll render
|
||||||
let (swapchain, final_views) = vulkano_context.create_swapchain(
|
let (swapchain, final_views) = vulkano_context.create_swapchain(
|
||||||
surface.clone(),
|
surface.clone(),
|
||||||
|
@ -5,7 +5,10 @@ use vulkano::swapchain::Surface;
|
|||||||
use vulkano::swapchain::SurfaceCreationError;
|
use vulkano::swapchain::SurfaceCreationError;
|
||||||
|
|
||||||
/// Creates a vulkan surface from a generic window
|
/// Creates a vulkan surface from a generic window
|
||||||
/// which implements HasRawWindowHandle and thus can reveal the os-dependent handle
|
/// which implements HasRawWindowHandle and thus can reveal the os-dependent handle.
|
||||||
|
/// - Note that if you wish to use this function with MacOS, you will need to ensure that the
|
||||||
|
/// `CAMetalLayer` is set to the ns_view. An example of how one might do that can be found in
|
||||||
|
/// `vulkano_win::set_ca_metal_layer_to_winit`
|
||||||
pub fn create_surface_from_handle<W>(
|
pub fn create_surface_from_handle<W>(
|
||||||
window: W,
|
window: W,
|
||||||
instance: Arc<Instance>,
|
instance: Arc<Instance>,
|
||||||
|
@ -172,11 +172,10 @@ use objc::runtime::YES;
|
|||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
|
/// Ensure `CAMetalLayer` (native rendering surface on MacOs) is used by the ns_view.
|
||||||
|
/// This is necessary to be able to render on Mac.
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
unsafe fn winit_to_surface<W: SafeBorrow<Window>>(
|
unsafe fn set_ca_metal_layer_to_winit<W: SafeBorrow<Window>>(win: W) {
|
||||||
instance: Arc<Instance>,
|
|
||||||
win: W,
|
|
||||||
) -> Result<Arc<Surface<W>>, SurfaceCreationError> {
|
|
||||||
use winit::platform::macos::WindowExtMacOS;
|
use winit::platform::macos::WindowExtMacOS;
|
||||||
|
|
||||||
let wnd: cocoa_id = mem::transmute(win.borrow().ns_window());
|
let wnd: cocoa_id = mem::transmute(win.borrow().ns_window());
|
||||||
@ -191,7 +190,16 @@ unsafe fn winit_to_surface<W: SafeBorrow<Window>>(
|
|||||||
layer.set_contents_scale(view.backingScaleFactor());
|
layer.set_contents_scale(view.backingScaleFactor());
|
||||||
view.setLayer(mem::transmute(layer.as_ref())); // Bombs here with out of memory
|
view.setLayer(mem::transmute(layer.as_ref())); // Bombs here with out of memory
|
||||||
view.setWantsLayer(YES);
|
view.setWantsLayer(YES);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
unsafe fn winit_to_surface<W: SafeBorrow<Window>>(
|
||||||
|
instance: Arc<Instance>,
|
||||||
|
win: W,
|
||||||
|
) -> Result<Arc<Surface<W>>, SurfaceCreationError> {
|
||||||
|
use winit::platform::macos::WindowExtMacOS;
|
||||||
|
|
||||||
|
set_ca_metal_layer_to_winit(win.borrow());
|
||||||
Surface::from_mac_os(instance, win.borrow().ns_view() as *const (), win)
|
Surface::from_mac_os(instance, win.borrow().ns_view() as *const (), win)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user