Support iOS for ogs-blue #7

Merged
kornerr merged 55 commits from iosblue into master 2026-10-30 14:17:25 +00:00
5 changed files with 35 additions and 9 deletions
Showing only changes of commit 1dc202b1af - Show all commits

No files matched your search

+4
View File
@@ -1,5 +1,9 @@
import UIKit import UIKit
func renderDraw(_ vm: RenderVM) {
raybriRender(vm.pixelSize[0], vm.pixelSize[1])
}
func renderPixelSize(_ view: UIView) -> [Int32] { func renderPixelSize(_ view: UIView) -> [Int32] {
let scale = view.contentScaleFactor let scale = view.contentScaleFactor
let w = Int32(max(1, (view.bounds.width * scale).rounded())) 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 Foundation
import QuartzCore
import UIKit
func renderDeinit(_ vm: RenderVM) {
vm.timer?.invalidate()
vm.timer = nil
raybriShutdown()
}
func renderInit(_ vm: RenderVM) { func renderInit(_ vm: RenderVM) {
vm.glView.openGLContext?.makeCurrentContext() // 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.
// Enable VSync let layer = Unmanaged.passUnretained(vm.glView.layer).toOpaque()
var swapInterval: Int32 = 1 raybriInit(layer)
vm.glView.openGLContext?.setValues(&swapInterval, for: .swapInterval) }
raybriInit(nil) 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) { }