0

I am adding a UIView to a MTKView and animating the UIView in the DRAW delegate method of the MTKViewDelegate.

Will this animation be handled by the GPU / Metal? Should the animation be smoother or the same as if I were using UIView.animate?

     func draw(in view: MTKView) {

      let newdescriptor = self.metalview.currentRenderPassDescriptor
      let commandbuffer = self.metalqueue.makeCommandBuffer()
      let commandencoder = commandbuffer?.makeRenderCommandEncoder(descriptor: newdescriptor!)



      // //////////////////////////// //
      timer += 0.01
      var currenttime = sin(timer)
      uiviewbox.transform = CGAffineTransform(rotationAngle: CGFloat(sin(timer)))
      // //////////////////////////// //




      commandencoder?.endEncoding()
      let thedrawable = self.metalview.currentDrawable
      commandbuffer?.present(thedrawable!)
      commandbuffer?.commit()
 }
  • "animating the UIView in the DRAW delegate method of the MTKViewDelegate" What does that mean? Can you show the code, please? – matt Feb 02 '20 at 19:05
  • The draw method gets called every frame and I think is the connection between the iPhone display and GPU. I could definitely be wrong, since shaders I think are the actual functions running on the GPU and the draw method is not a shader. Posting code now. – SkankHunt42 Feb 02 '20 at 19:08
  • Yeah, that's what I thought you meant. :) – matt Feb 02 '20 at 19:13

1 Answers1

0

Short answer: no, and no. In effect, the fact that this view is a subview of the MTKView and that you are using the draw method as a clock is completely irrelevant. What you're doing is no different from changing something about the view on every callback from a CADisplayLink — and you would never ask whether that was more efficient or on the GPU. In fact, because this is done on the main thread, this is arguably less efficient than normal view animation (in the same way as UIKit Dynamics which uses the CADisplayLink technique as well).

matt
  • 515,959
  • 87
  • 875
  • 1,141