Post

Replies

Boosts

Views

Activity

Correctly acquire and release Drawables for paused MTKView
I am trying to push content to an MTKView in SwiftUI, wrapped in a UIViewRepresentable by manually calling draw(in: MTKView) on the MTKViewDelegate. My question is how to obtain and release the correct drawable from the 3 available. As I only want to push draw calls from an external source, the view settings are: mtkView.isPaused = true // only push data mtkView.enableSetNeedsDisplay = false // only push data from our single source mtkView.framebufferOnly = true // we don't render to anything but the screen The MTKViewDelegate draw call is as follows: func draw(in view: MTKView) { autoreleasepool() { let passDescriptor = view.currentRenderPassDescriptor! // make command buffer, encoder from descriptor // encode data let drawable = view.currentDrawable! commandBuffer.present(drawable) commandBuffer.commit() } } This works fine for the first trigger of draw and on the second draw call raises [CAMetalLayerDrawable texture] should not be called after already presenting this drawable. Get a nextDrawable instead. and Each CAMetalLayerDrawable can only be presented once! Setting mtkView.isPaused = false renders fine, so I suppose whatever internal loop is handling calling nextDrawable(). How should I go about ensuring that I am getting the next drawable and releasing the current one when I assume control of drawing? Best regards,
3
0
2.0k
Sep ’21