I have MTKView in Cocoa.
I am showing a texture with drawable.texture - but the texture shows only a quarter of the screen - Non-Retina.
Do I need to make any additional settings to make this work?
class MyView : MTKView
The following code does not affect:
let scale = NSScreen.mainScreen()!.backingScaleFactor
var s = frame.size
s.width *= scale
s.height *= scale
metalLayer.contentsScale = scale
metalLayer.framebufferOnly = false
metalLayer.drawableSize = s
Update:
Here I need to load the texture from the image:
func textureFromImage(image: NSImage, inout tex:MTLTexture?) {
let textureLoader = MTKTextureLoader(device: self.device!)
do {
tex = try textureLoader.newTextureWithCGImage(image.CGImage, options: nil)
}
catch {
fatalError("Can't load texture")
}
}
and code for presentation:
let commandBuffer = commandQueue.commandBuffer()
let commandEncoder = commandBuffer.computeCommandEncoder()
commandEncoder.setComputePipelineState(pipelineState)
commandEncoder.setTexture(originalTexture, atIndex: 0)
commandEncoder.setTexture(drawable.texture, atIndex: 1)
commandEncoder.dispatchThreadgroups(threadgroupsPerGrid, threadsPerThreadgroup: threadsPerThreadgroup)
commandEncoder.endEncoding()
commandBuffer.presentDrawable(drawable)
commandBuffer.commit();
All sizes of the original input image and texture are the same size as the view.
Chris source
share