mirror of https://github.com/axmolengine/axmol.git
check metal support (#19710)
This commit is contained in:
parent
833ab9bb81
commit
a572d088d1
|
@ -138,8 +138,14 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
|
||||||
self.contentScaleFactor = [[UIScreen mainScreen] scale];
|
self.contentScaleFactor = [[UIScreen mainScreen] scale];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
|
||||||
|
if (!device)
|
||||||
|
{
|
||||||
|
CCLOG("Doesn't support metal.");
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
CAMetalLayer* metalLayer = (CAMetalLayer*)[self layer];
|
CAMetalLayer* metalLayer = (CAMetalLayer*)[self layer];
|
||||||
metalLayer.device = MTLCreateSystemDefaultDevice();
|
metalLayer.device = device;
|
||||||
metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
|
metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
|
||||||
metalLayer.framebufferOnly = NO;
|
metalLayer.framebufferOnly = NO;
|
||||||
cocos2d::backend::DeviceMTL::setCAMetalLayer(metalLayer);
|
cocos2d::backend::DeviceMTL::setCAMetalLayer(metalLayer);
|
||||||
|
|
|
@ -329,10 +329,17 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram
|
||||||
size.height = static_cast<CGFloat>(fbHeight);
|
size.height = static_cast<CGFloat>(fbHeight);
|
||||||
|
|
||||||
// Initialize device.
|
// Initialize device.
|
||||||
|
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
|
||||||
|
if (!device)
|
||||||
|
{
|
||||||
|
CCLOG("Doesn't support metal.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
NSView* contentView = [getCocoaWindow() contentView];
|
NSView* contentView = [getCocoaWindow() contentView];
|
||||||
[contentView setWantsLayer: YES];
|
[contentView setWantsLayer: YES];
|
||||||
CAMetalLayer* layer = [CAMetalLayer layer];
|
CAMetalLayer* layer = [CAMetalLayer layer];
|
||||||
[layer setDevice:MTLCreateSystemDefaultDevice()];
|
[layer setDevice:device];
|
||||||
[layer setPixelFormat:MTLPixelFormatBGRA8Unorm];
|
[layer setPixelFormat:MTLPixelFormatBGRA8Unorm];
|
||||||
[layer setFramebufferOnly:NO];
|
[layer setFramebufferOnly:NO];
|
||||||
[layer setDrawableSize:size];
|
[layer setDrawableSize:size];
|
||||||
|
|
Loading…
Reference in New Issue