mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-11-27 01:05:03 +00:00
Merge pull request #482 from tomaka/mvk-progress
MoltenVK: Follow-up for added code to get to OutOfDeviceMemory error
This commit is contained in:
commit
c1be5450ae
@ -10,3 +10,8 @@ categories = ["rendering::graphics-api"]
|
||||
[dependencies]
|
||||
vulkano = { version = "0.3.0", path = "../vulkano" }
|
||||
winit = "0.6.4"
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
metal-rs = "0.3.0"
|
||||
cocoa = "0.8.1"
|
||||
objc = "0.2"
|
||||
|
@ -1,6 +1,13 @@
|
||||
extern crate vulkano;
|
||||
extern crate winit;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
extern crate objc;
|
||||
#[cfg(target_os = "macos")]
|
||||
extern crate cocoa;
|
||||
#[cfg(target_os = "macos")]
|
||||
extern crate metal_rs as metal;
|
||||
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
use std::ptr;
|
||||
@ -13,6 +20,17 @@ use vulkano::swapchain::SurfaceCreationError;
|
||||
use winit::{EventsLoop, WindowBuilder};
|
||||
use winit::CreationError as WindowCreationError;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
use objc::runtime::{YES};
|
||||
#[cfg(target_os = "macos")]
|
||||
use cocoa::base::id as cocoa_id;
|
||||
#[cfg(target_os = "macos")]
|
||||
use cocoa::appkit::{NSWindow, NSView};
|
||||
#[cfg(target_os = "macos")]
|
||||
use metal::*;
|
||||
|
||||
use std::mem;
|
||||
|
||||
pub fn required_extensions() -> InstanceExtensions {
|
||||
let ideal = InstanceExtensions {
|
||||
khr_surface: true,
|
||||
@ -160,5 +178,20 @@ unsafe fn winit_to_surface(instance: &Arc<Instance>, win: &winit::Window)
|
||||
-> Result<Arc<Surface>, SurfaceCreationError>
|
||||
{
|
||||
use winit::os::macos::WindowExt;
|
||||
|
||||
unsafe {
|
||||
let wnd: cocoa_id = mem::transmute(win.get_nswindow());
|
||||
|
||||
let layer = CAMetalLayer::new();
|
||||
|
||||
layer.set_edge_antialiasing_mask(0);
|
||||
layer.set_presents_with_transaction(false);
|
||||
layer.remove_all_animations();
|
||||
|
||||
let view = wnd.contentView();
|
||||
view.setWantsLayer(YES);
|
||||
view.setLayer(mem::transmute(layer.0)); // Bombs here with out of memory
|
||||
}
|
||||
|
||||
Surface::from_macos_moltenvk(instance, win.get_nsview() as *const ())
|
||||
}
|
||||
|
@ -17,5 +17,6 @@ fn main() {
|
||||
println!("cargo:rustc-link-lib=framework=MoltenVK");
|
||||
println!("cargo:rustc-link-lib=framework=QuartzCore");
|
||||
println!("cargo:rustc-link-lib=framework=Metal");
|
||||
println!("cargo:rustc-link-lib=framework=Foundation");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user