Skip to content

Releases: 0xLet/MetalUI

Rendering & Presenting

09 Dec 01:50
Compare
Choose a tag to compare

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
}