未找到金属 'texture'
Metal 'texture' not found
对于基于 Metal 的 ImageView 的每个实现,我都面临着同样的问题
let targetTexture = currentDrawable?.texture else{ return }
Value of type 'MTLDrawable' has no member 'texture'
好像苹果换了一些金属api
这是我尝试使用的完整功能:
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()
}
我在执行系统和 xcode 更新后遇到了同样的问题。原来在更新过程中,xcode 将构建目标切换到了模拟器。一旦我将目标切换回设备,它就会再次编译。
Metal 不适用于模拟器,但如果您只想让构建通过并专注于应用程序的其他区域,您可以尝试执行与此类似的操作:
对于那些仍然想 运行 在模拟器上的人来说,有一个解决方法至少可以 运行 编译并编译(虽然没有 Metal 功能)
对于基于 Metal 的 ImageView 的每个实现,我都面临着同样的问题
let targetTexture = currentDrawable?.texture else{ return }
Value of type 'MTLDrawable' has no member 'texture'
好像苹果换了一些金属api
这是我尝试使用的完整功能:
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()
}
我在执行系统和 xcode 更新后遇到了同样的问题。原来在更新过程中,xcode 将构建目标切换到了模拟器。一旦我将目标切换回设备,它就会再次编译。
Metal 不适用于模拟器,但如果您只想让构建通过并专注于应用程序的其他区域,您可以尝试执行与此类似的操作: 对于那些仍然想 运行 在模拟器上的人来说,有一个解决方法至少可以 运行 编译并编译(虽然没有 Metal 功能)