Metal with SwiftUI
What's New
Rendering & Presenting
2020-12-09T01:50:17Z
MetalView
#if os(iOS)
public struct MetalView<Content>: UIViewRepresentable where Content: MetalPresenting
#elseif os(macOS)
public struct MetalView<Content>: NSViewRepresentable where Content: MetalPresenting
#endif
Rendering
public protocol MetalRendering: NSObject, MTKViewDelegate {
var commandQueue: MTLCommandQueue? { get set }
var renderPipelineState: MTLRenderPipelineState? { get set }
var vertexBuffer: MTLBuffer? { get set }
var vertices: [MetalRenderingVertex] { get set }
init()
init(
vertices: [MetalRenderingVertex],
device: MTLDevice
)
func createCommandQueue(device: MTLDevice)
func createPipelineState(
withLibrary library: MTLLibrary?,
forDevice device: MTLDevice
)
func createBuffers(device: MTLDevice)
// MARK: MTKViewDelegate
func mtkView(_ view: MTKView, drawableSizeWillChange size: CGSize)
func draw(in view: MTKView)
}
Presenting
public protocol MetalPresenting: MTKView {
var renderer: MetalRendering! { get set }
init()
func configure(device: MTLDevice?)
func configureMTKView()
func renderer(forDevice device: MTLDevice) -> MetalRendering
}