我在 Cocoa有一个MTKView. 我正在使用drawable.texture显示纹理 – 但纹理只显示超过四分之一的屏幕 – 非Retina. 我是否需要进行任何其他设置才能使其正常工作? class MyView : MTKView 以下代码无
我正在使用drawable.texture显示纹理 – 但纹理只显示超过四分之一的屏幕 – 非Retina.
我是否需要进行任何其他设置才能使其正常工作?
class MyView : MTKView
以下代码无影响:
let scale = NSScreen.mainScreen()!.backingScaleFactor var s = frame.size s.width *= scale s.height *= scale metalLayer.contentsScale = scale metalLayer.framebufferOnly = false metalLayer.drawableSize = s
更新:
这是我从图像加载纹理的方法:
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")
}
}
以及提供的代码:
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();
原始输入图像和纹理的所有大小都与视图的大小相同.
尝试将视图的contentScaleFactor更改为1.