36 lines
1.1 KiB
Swift
36 lines
1.1 KiB
Swift
import Foundation
|
|
import QuartzCore
|
|
import UIKit
|
|
|
|
// Bring up EGL/ANGLE on the view's layer. Returns false when the surface could
|
|
// not be created (the caller then leaves the timer stopped).
|
|
func renderInit(_ vm: RenderVM) -> Bool {
|
|
let size = renderPixelSize(vm.glView)
|
|
let layer = Unmanaged.passUnretained(vm.glView.layer).toOpaque()
|
|
let ok = raybri_ios_init(layer, size[0], size[1]) != 0
|
|
if !ok {
|
|
otherPrintStderr("ИГР renderInit: EGL/ANGLE initialization failed")
|
|
}
|
|
return ok
|
|
}
|
|
|
|
// Same shape as the macOS timer: a repeating timer on the main run loop, but
|
|
// here it calls the renderer directly instead of flagging the view for redraw.
|
|
func renderStartTimer(_ vm: RenderVM) {
|
|
vm.startTime = CACurrentMediaTime()
|
|
|
|
let timer = Timer(timeInterval: 1.0 / RENDER_FPS, repeats: true) { [weak vm] _ in
|
|
guard let vm else { return }
|
|
renderDraw(vm)
|
|
}
|
|
vm.timer = timer
|
|
// .common keeps rendering alive while the user holds a control.
|
|
RunLoop.main.add(timer, forMode: .common)
|
|
}
|
|
|
|
func renderDeinit(_ vm: RenderVM) {
|
|
vm.timer?.invalidate()
|
|
vm.timer = nil
|
|
raybri_ios_shutdown()
|
|
}
|