创建 MTLTexture 对象时出现无法识别的选择器错误

Unrecognized selector error when creating MTLTexture object

我使用以下代码创建了一个 MTLTexture 对象(为清楚起见,仅列出了部分代码)。

int tmpbuf[4096]
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
MTLTextureDescriptor* desc = [MTLTextureDescriptor    texture2DDescriptorWithPixelFormat: MTLPixelFormatA8Unorm  width: 64 height:64 mipmapped: NO];
id<MTLTexture> input_texture    = [device newTextureWithDescpriptor:desc];

//memory for the texture
MTLOrigin texture_origin = { 0, 0,  0};
MTLSize   texture_size   = {64, 64, 0};
MTLRegion texture_region = {texture_origin, texture_size}; 
[input_texture  replaceRegion: texture_region mipmaplevel: 0 withBytes: tmpbuf bytesPerRow: 64 ];

当运行宁代码时:

id<MTLTexture> input_texture    = [device newTextureWithDescpriptor:desc];

[MTLIGAccelDevice newTextureWithDescpriptor:]: unrecognized selector sent to instance 0x7fd0a3012200 was reported. 此代码是在 OS X 系统上编译和 运行 的错误。我不知道为什么会发生此错误。

确保首先在第一行末尾添加一个 ;,然后为第三个 MTLSize 参数添加一个非空值。下面的代码片段在我的 OS X 10.11.6 机器上编译得很好。

    int tmpbuf[4096];
    id<MTLDevice> device = MTLCreateSystemDefaultDevice();
    MTLTextureDescriptor* desc = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat: MTLPixelFormatA8Unorm  width: 64 height:64 mipmapped: NO];
    id<MTLTexture> input_texture = [device newTextureWithDescriptor:desc];
    MTLOrigin texture_origin = { 0, 0,  0};
    MTLSize   texture_size   = {64, 64, 1};
    MTLRegion texture_region = {texture_origin, texture_size};
    [input_texture replaceRegion:texture_region mipmapLevel:0 withBytes:tmpbuf bytesPerRow:64];