CAMetalLayer 是 Apple Core Animation Framework 的内部模块, 它 管理Metal Texture Pool, 并且负责渲染MTL Texture到窗口。
CAMetalLayer 的使用
device: 需要为其创建 MTLDevice 对象
pixelFormat: MTLTexture的像素格式, 目前支持 MTLPixelFormatBGRA8Unorm 和 MTLPixelFormatBGRA8Unorm_sRGB 两种。
示例代码:
-(instancetype)initWithCoder:(NSCoder *)aDecoder {
if( self = [super initWithCoder:aDecoder] ){
self.mDevice = MTLCreateSystemDefaultDevice();
self.mCommandQueue = [self.mDevice newCommandQueue];
self.metalLayer.device = self.mDevice;
self.metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
}
return self;
}
framebufferOnly: YES means MTLTexture 是为了渲染特别优化的, 不能支持对Texture 进行Rea