iOS code to identify metal support in runtime?

后端 未结 4 1442
迷失自我
迷失自我 2021-02-13 15:51

Usually, I use the below code to identify the iOS version of the device.

if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0)

In

4条回答
  •  南旧
    南旧 (楼主)
    2021-02-13 16:47

    It's good that you're looking for something specific to Metal — generally, iOS version checks and hardware name checks are fragile, because they rely on your app knowing all of the OS versions and devices that could ever run it. If Apple were to go back and release an iOS 7.x version that added Metal support (okay, seems unlikely), or a device that supports Metal but isn't one of the hardware names you're looking at (seems much more likely), you'd be stuck having to track all of those things down and update your app to manage them.

    Anyway, the best way to check whether the device you're running on is Metal enough for your awesome graphics code? Just try to get a MTLDevice object:

    id device = MTLCreateSystemDefaultDevice();
    if (device) {
        // ready to rock 

提交回复
热议问题