Files
__mahjong/components/render/renderEffect.swift
T
2026-10-20 06:31:26 +03:00

38 lines
1.0 KiB
Swift

import Foundation
import RaylibBridge
func renderInit(_ vm: RenderVM) {
vm.glView.openGLContext?.makeCurrentContext()
// Enable VSync
var swapInterval: Int32 = 1
vm.glView.openGLContext?.setValues(&swapInterval, for: .swapInterval)
// Init Raylib
sr_init(
1, // Default width
1, // Default height
RENDER_SHADER_MAIN_VS,
RENDER_SHADER_MAIN_FS,
RENDER_SHADER_SHADOW_VS,
RENDER_SHADER_SHADOW_FS,
RENDER_CONFIG
)
}
func renderLoadCubeModel(_ vm: RenderVM) {
let path = Bundle.main.resourceURL!.path + RENDER_MODEL_CUBE
vm.glView.openGLContext?.makeCurrentContext()
sr_load_model(path)
}
func renderStartTimer(_ vm: RenderVM) {
// Schedule repaints every once in FPS seconds
let timer = Timer(timeInterval: 1.0 / RENDER_FPS, repeats: true) { [weak vm] _ in
vm?.glView.needsDisplay = true
}
vm.timer = timer
// Use .common so that holding buttons in UI does not pause this rendering timer
RunLoop.main.add(timer, forMode: .common)
}