Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Metal 'texture' not found

With every Implementation of Metal based ImageView I'm facing the same problem

let targetTexture = currentDrawable?.texture else{ return }

Value of type 'MTLDrawable' has no member 'texture'

Seems like apple has changed some metal 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()
}
like image 469
Діма Комар Avatar asked Jan 29 '17 00:01

Діма Комар


1 Answers

I had the same problem after performing a system and xcode update. Turns out during the update process, xcode switched the build target to the simulator. Once I switched the target back to the device it all compiled again.

like image 120
xface Avatar answered Oct 15 '22 09:10

xface