Merge pull request #482 from tomaka/mvk-progress

MoltenVK: Follow-up for added code to get to OutOfDeviceMemory error
This commit is contained in:
tomaka 2017-05-26 21:14:27 +02:00 committed by GitHub
commit c1be5450ae
3 changed files with 39 additions and 0 deletions

View File

@ -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"

View File

@ -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 ())
}

View File

@ -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");
}
}