Search code examples
iosmetalkitmtkview

iOS MTKView (Metal Kit view) draws image without proper scale


I don't understand why MTKView doesn't use device's scale.

I have a retina device: 2x scale, MTKView.bounds of 400x200, and CIImage size of 800x400, but it draws only left bottom quarter of the image.

Strangely drawableSize returns bounds size (400x200).

Here's the code I use:

id<MTLTexture> targetTexture = self.currentDrawable.texture;
id<MTLCommandBuffer> commandBuffer = [commandQueue commandBuffer];

[ctx render:coreImage toMTLTexture:targetTexture commandBuffer:commandBuffer bounds:self.bounds colorSpace:colorSpace];

[commandBuffer presentDrawable:self.currentDrawable];
[commandBuffer commit];

Solution

  • Found it. I just need to use MTKView's method setDrawableSize to the scaled size I want:

    [self setDrawableSize:coreImage.extent.size];