Reputation: 129
I used the following code to create an MTLTexture
object (for clarity, only part of the code is listed).
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 ];
When running the code:
id<MTLTexture> input_texture = [device newTextureWithDescpriptor:desc];
An error that [MTLIGAccelDevice newTextureWithDescpriptor:]: unrecognized selector sent to instance 0x7fd0a3012200 was reported.
This code was compiled and run on the OS X system. I have no idea why this error happened.
Upvotes: 0
Views: 477
Reputation: 1184
Make sure to first add a ;
at the end of the first line and then add a non-null value for the third MTLSize
argument. This code snippet below compiles just fine on my OS X 10.11.6 machine.
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];
Upvotes: 1