简体   繁体   English

找不到金属“纹理”

[英]Metal 'texture' not found

With every Implementation of Metal based ImageView I'm facing the same problem 在基于Metal的ImageView的每个实现中,我都面临着相同的问题

let targetTexture = currentDrawable?.texture else{ return }

Value of type 'MTLDrawable' has no member 'texture' 类型“ MTLDrawable”的值没有成员“纹理”

Seems like apple has changed some metal api 好像苹果已经改变了一些金属API

here is the full function I'm tryong to use: 这是我尝试使用的全部功能:

func renderImage()
{
    guard let
        image = image,
        let targetTexture = currentDrawable?.texture else{return}

    let commandBuffer = commandQueue.makeCommandBuffer()

    let bounds = CGRect(origin: CGPoint.zero, size: drawableSize)

    let originX = image.extent.origin.x
    let originY = image.extent.origin.y

    let scaleX = drawableSize.width / image.extent.width
    let scaleY = drawableSize.height / image.extent.height
    let scale = min(scaleX, scaleY)

    let scaledImage = image
        .applying(CGAffineTransform(translationX: -originX, y: -originY))
        .applying(CGAffineTransform(scaleX: scale, y: scale))

    ciContext.render(scaledImage,
                     to: targetTexture,
                     commandBuffer: commandBuffer,
                     bounds: bounds,
                     colorSpace: colorSpace)

    commandBuffer.present(currentDrawable!)

    commandBuffer.commit()
}

I had the same problem after performing a system and xcode update. 执行系统和xcode更新后,我遇到了同样的问题。 Turns out during the update process, xcode switched the build target to the simulator. 事实证明,在更新过程中,xcode将构建目标切换到了模拟器。 Once I switched the target back to the device it all compiled again. 将目标切换回设备后,所有内容都会再次编译。

Metal doesn't work for simulators, but if you just want the build to pass and focus in other areas of your app you can try to do something similar to this: For those who still want to run on simulators, there's a workaround for at least getting it running and compile (no Metal functionality though) Metal不适用于模拟器,但是如果您只希望构建通过并专注于应用程序的其他区域,则可以尝试执行以下类似操作:对于仍然希望在模拟器上运行的用户,可以通过以下方法解决最少让它运行和编译(尽管没有Metal功能)

https://navoshta.com/metal-camera-bonus-running-simulator/ https://navoshta.com/metal-camera-bonus-running-simulator/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM