-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPresenter.swift
43 lines (34 loc) · 1.15 KB
/
Presenter.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// Presenter.swift
// Pathtracer
//
// Created by Adellar Irankunda on 10/18/24.
//
import MetalKit
import Metal
class Presenter : NSObject
{
var metalView : MTKView
var viewController : ViewController?
init(_device : MTLDevice, size: MTLSize)
{
self.metalView = MTKView(frame: CGRect(x: 0, y: 0, width: size.width, height: size.height), device: _device)
super.init()
self.metalView.framebufferOnly = false
self.metalView.clearColor = MTLClearColor(red: 0, green: 0, blue: 0, alpha: 1)
}
func mtkView(_ view: MTKView, drawableSizeWillChange size: CGSize)
{
}
func draw(in view: MTKView)
{
guard let drawable = view.currentDrawable else { return }
viewController!.redraw()
let commandBuffer = viewController!.commandQueue.makeCommandBuffer()!
let swapchainBlit = commandBuffer.makeBlitCommandEncoder()!
swapchainBlit.copy(from: viewController!.texturePair!.destination, to: drawable.texture)
swapchainBlit.endEncoding()
commandBuffer.present(drawable)
commandBuffer.commit()
}
}