This commit is contained in:
Михаил Капелько committed 2026-10-28 17:10:05 +03:00
1 parent aa541a8e23
commit 1dc202b1af
5 files changed
+35 -9

No files matched your search

+4
View File
@@ -1,5 +1,9 @@
import UIKit
func renderDraw(_ vm: RenderVM) {
raybriRender(vm.pixelSize[0], vm.pixelSize[1])
}
func renderPixelSize(_ view: UIView) -> [Int32] {
let scale = view.contentScaleFactor
let w = Int32(max(1, (view.bounds.width * scale).rounded()))
+3
View File
@@ -0,0 +1,3 @@
// iOS render constants. The macOS renderConst.swift depends on AppKit, so the
// two platforms keep separate files.
let RENDER_FPS = 60.0
+27 -7
View File
@@ -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)
}
+1
View File
@@ -0,0 +1 @@
../../../../components/render/ios/renderConst.swift
@@ -1,2 +0,0 @@
func renderDeinit(_ vm: RenderVM) { }
func renderStartTimer(_ vm: RenderVM) { }