我使用以下代码创建了一个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系统上编译和运行。我不知道为什么会发生这个错误。
答案 0 :(得分:1)
确保首先在第一行的末尾添加;
,然后为第三个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];