check metal support (#19710)

This commit is contained in:
minggo 2019-05-14 01:38:14 -07:00 committed by GitHub
parent 833ab9bb81
commit a572d088d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -138,8 +138,14 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
self.contentScaleFactor = [[UIScreen mainScreen] scale];
}
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
if (!device)
{
CCLOG("Doesn't support metal.");
return nil;
}
CAMetalLayer* metalLayer = (CAMetalLayer*)[self layer];
metalLayer.device = MTLCreateSystemDefaultDevice();
metalLayer.device = device;
metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
metalLayer.framebufferOnly = NO;
cocos2d::backend::DeviceMTL::setCAMetalLayer(metalLayer);

View File

@ -329,10 +329,17 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram
size.height = static_cast<CGFloat>(fbHeight);
// Initialize device.
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
if (!device)
{
CCLOG("Doesn't support metal.");
return false;
}
NSView* contentView = [getCocoaWindow() contentView];
[contentView setWantsLayer: YES];
CAMetalLayer* layer = [CAMetalLayer layer];
[layer setDevice:MTLCreateSystemDefaultDevice()];
[layer setDevice:device];
[layer setPixelFormat:MTLPixelFormatBGRA8Unorm];
[layer setFramebufferOnly:NO];
[layer setDrawableSize:size];