some
This commit is contained in:
1 parent
aa541a8e23
commit
1dc202b1af
5 files changed
+35
-9
No files matched your search
@@ -1,11 +1,31 @@
|
||||
import Foundation
|
||||
import QuartzCore
|
||||
import UIKit
|
||||
|
||||
func renderDeinit(_ vm: RenderVM) {
|
||||
vm.timer?.invalidate()
|
||||
vm.timer = nil
|
||||
raybriShutdown()
|
||||
}
|
||||
|
||||
func renderInit(_ vm: RenderVM) {
|
||||
vm.glView.openGLContext?.makeCurrentContext()
|
||||
|
||||
// Enable VSync
|
||||
var swapInterval: Int32 = 1
|
||||
vm.glView.openGLContext?.setValues(&swapInterval, for: .swapInterval)
|
||||
|
||||
raybriInit(nil)
|
||||
// UIKit has no NSOpenGLContext: EGL/ANGLE renders into the view's layer,
|
||||
// so the layer is what the bridge needs to create its surface from.
|
||||
let layer = Unmanaged.passUnretained(vm.glView.layer).toOpaque()
|
||||
raybriInit(layer)
|
||||
}
|
||||
|
||||
func renderStartTimer(_ vm: RenderVM) {
|
||||
// Make a time mark for calculating time delta
|
||||
vm.startTime = CACurrentMediaTime()
|
||||
|
||||
// Unlike macOS, UIKit never calls draw(_:) on the view, so the timer
|
||||
// renders each frame itself.
|
||||
let timer = Timer(timeInterval: 1.0 / RENDER_FPS, repeats: true) { [weak vm] _ in
|
||||
guard let vm else { return }
|
||||
renderDraw(vm)
|
||||
}
|
||||
vm.timer = timer
|
||||
// .common means holding buttons in UI does not pause this rendering timer
|
||||
RunLoop.main.add(timer, forMode: .common)
|
||||
}
|
||||
Reference in new issue
Block a user