Introduce chkgfx #3
No files matched your search
@@ -4,7 +4,6 @@ import RaylibBridge
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
final class RenderGLView: NSOpenGLView {
|
final class RenderGLView: NSOpenGLView {
|
||||||
private var ready = false
|
|
||||||
private var startTime: CFTimeInterval = 0
|
private var startTime: CFTimeInterval = 0
|
||||||
|
|
||||||
override init(frame frameRect: NSRect) {
|
override init(frame frameRect: NSRect) {
|
||||||
@@ -23,21 +22,10 @@ final class RenderGLView: NSOpenGLView {
|
|||||||
|
|
||||||
override func prepareOpenGL() {
|
override func prepareOpenGL() {
|
||||||
super.prepareOpenGL()
|
super.prepareOpenGL()
|
||||||
guard let context = openGLContext else { return }
|
|
||||||
|
|
||||||
context.makeCurrentContext()
|
|
||||||
|
|
||||||
var swapInterval: Int32 = 1
|
|
||||||
context.setValues(&swapInterval, for: .swapInterval)
|
|
||||||
|
|
||||||
sr_init(1, 1,
|
|
||||||
RENDER_SHADER_MAIN_VS, RENDER_SHADER_MAIN_FS,
|
|
||||||
RENDER_SHADER_SHADOW_VS, RENDER_SHADER_SHADOW_FS,
|
|
||||||
RENDER_CONFIG)
|
|
||||||
startTime = CACurrentMediaTime()
|
startTime = CACurrentMediaTime()
|
||||||
ready = true
|
|
||||||
|
|
||||||
renderSet(F.willPrepareGLContext, true)
|
renderSet(F.didPrepareGLContext, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func reshape() {
|
override func reshape() {
|
||||||
@@ -59,7 +47,12 @@ final class RenderGLView: NSOpenGLView {
|
|||||||
override func draw(_ dirtyRect: NSRect) {
|
override func draw(_ dirtyRect: NSRect) {
|
||||||
let vm = RenderVM.shared!
|
let vm = RenderVM.shared!
|
||||||
|
|
||||||
guard ready, let context = openGLContext else { return }
|
guard
|
||||||
|
vm.didPrepareGLContext,
|
||||||
|
let context = openGLContext
|
||||||
|
else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
context.makeCurrentContext()
|
context.makeCurrentContext()
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,25 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import RaylibBridge
|
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) {
|
func renderLoadCubeModel(_ vm: RenderVM) {
|
||||||
let path = Bundle.main.resourceURL!.path + RENDER_MODEL_CUBE
|
let path = Bundle.main.resourceURL!.path + RENDER_MODEL_CUBE
|
||||||
vm.glView.openGLContext?.makeCurrentContext()
|
vm.glView.openGLContext?.makeCurrentContext()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import Combine
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
final class RenderVM: ObservableObject {
|
final class RenderVM: ObservableObject {
|
||||||
|
var didPrepareGLContext = false
|
||||||
let glView = RenderGLView(frame: .zero)
|
let glView = RenderGLView(frame: .zero)
|
||||||
var pixelSize = [Int32]()
|
var pixelSize = [Int32]()
|
||||||
var timer: Timer?
|
var timer: Timer?
|
||||||
|
|||||||
+4
-2
@@ -10,18 +10,20 @@ RenderContext:
|
|||||||
backingPixelSize: [Int32]
|
backingPixelSize: [Int32]
|
||||||
didClickIncrement: Bool
|
didClickIncrement: Bool
|
||||||
didLaunch: Bool
|
didLaunch: Bool
|
||||||
|
didPrepareGLContext: Bool
|
||||||
didSetup: Bool
|
didSetup: Bool
|
||||||
isReadyToRender: Bool
|
isReadyToRender: Bool
|
||||||
pixelSize: [Int32]
|
pixelSize: [Int32]
|
||||||
reshapePixelSize: [Int32]
|
reshapePixelSize: [Int32]
|
||||||
willPrepareGLContext: Bool
|
|
||||||
|
|
||||||
RenderComponent:
|
RenderComponent:
|
||||||
type: component
|
type: component
|
||||||
oneliners:
|
oneliners:
|
||||||
- didClickIncrement: renderLoadCubeModel(RenderVM.shared!)
|
- didClickIncrement: renderLoadCubeModel(RenderVM.shared!)
|
||||||
- pixelSize: RenderVM.shared!.pixelSize = c.pixelSize
|
- pixelSize: RenderVM.shared!.pixelSize = c.pixelSize
|
||||||
- willPrepareGLContext: renderStartTimer(RenderVM.shared!)
|
- didPrepareGLContext: renderInit(RenderVM.shared!)
|
||||||
|
- didPrepareGLContext: RenderVM.shared!.didPrepareGLContext = true
|
||||||
|
- didPrepareGLContext: renderStartTimer(RenderVM.shared!)
|
||||||
shoulds:
|
shoulds:
|
||||||
didLaunch:
|
didLaunch:
|
||||||
1. Only once during the first setup:
|
1. Only once during the first setup:
|
||||||
|
|||||||
@@ -124,22 +124,22 @@ public struct F {
|
|||||||
public static let countText = "countText"
|
public static let countText = "countText"
|
||||||
public static let didClickIncrement = "didClickIncrement"
|
public static let didClickIncrement = "didClickIncrement"
|
||||||
public static let didLaunch = "didLaunch"
|
public static let didLaunch = "didLaunch"
|
||||||
|
public static let didPrepareGLContext = "didPrepareGLContext"
|
||||||
public static let didSetup = "didSetup"
|
public static let didSetup = "didSetup"
|
||||||
public static let isReadyToRender = "isReadyToRender"
|
public static let isReadyToRender = "isReadyToRender"
|
||||||
public static let pixelSize = "pixelSize"
|
public static let pixelSize = "pixelSize"
|
||||||
public static let reshapePixelSize = "reshapePixelSize"
|
public static let reshapePixelSize = "reshapePixelSize"
|
||||||
public static let willPrepareGLContext = "willPrepareGLContext"
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public struct RenderContext: DialectContext {
|
public struct RenderContext: DialectContext {
|
||||||
public var backingPixelSize = [Int32]()
|
public var backingPixelSize = [Int32]()
|
||||||
public var didClickIncrement = Bool()
|
public var didClickIncrement = Bool()
|
||||||
public var didLaunch = Bool()
|
public var didLaunch = Bool()
|
||||||
|
public var didPrepareGLContext = Bool()
|
||||||
public var didSetup = Bool()
|
public var didSetup = Bool()
|
||||||
public var isReadyToRender = Bool()
|
public var isReadyToRender = Bool()
|
||||||
public var pixelSize = [Int32]()
|
public var pixelSize = [Int32]()
|
||||||
public var reshapePixelSize = [Int32]()
|
public var reshapePixelSize = [Int32]()
|
||||||
public var willPrepareGLContext = Bool()
|
|
||||||
|
|
||||||
public var recentField = ""
|
public var recentField = ""
|
||||||
|
|
||||||
@@ -153,6 +153,9 @@ public struct RenderContext: DialectContext {
|
|||||||
else if (name == "didLaunch") {
|
else if (name == "didLaunch") {
|
||||||
return didLaunch as! T
|
return didLaunch as! T
|
||||||
}
|
}
|
||||||
|
else if (name == "didPrepareGLContext") {
|
||||||
|
return didPrepareGLContext as! T
|
||||||
|
}
|
||||||
else if (name == "didSetup") {
|
else if (name == "didSetup") {
|
||||||
return didSetup as! T
|
return didSetup as! T
|
||||||
}
|
}
|
||||||
@@ -165,9 +168,6 @@ public struct RenderContext: DialectContext {
|
|||||||
else if (name == "reshapePixelSize") {
|
else if (name == "reshapePixelSize") {
|
||||||
return reshapePixelSize as! T
|
return reshapePixelSize as! T
|
||||||
}
|
}
|
||||||
else if (name == "willPrepareGLContext") {
|
|
||||||
return willPrepareGLContext as! T
|
|
||||||
}
|
|
||||||
|
|
||||||
return "unknown-field-name" as! T
|
return "unknown-field-name" as! T
|
||||||
}
|
}
|
||||||
@@ -185,6 +185,9 @@ public struct RenderContext: DialectContext {
|
|||||||
else if (name == "didLaunch") {
|
else if (name == "didLaunch") {
|
||||||
didLaunch = value as! Bool
|
didLaunch = value as! Bool
|
||||||
}
|
}
|
||||||
|
else if (name == "didPrepareGLContext") {
|
||||||
|
didPrepareGLContext = value as! Bool
|
||||||
|
}
|
||||||
else if (name == "didSetup") {
|
else if (name == "didSetup") {
|
||||||
didSetup = value as! Bool
|
didSetup = value as! Bool
|
||||||
}
|
}
|
||||||
@@ -197,9 +200,6 @@ public struct RenderContext: DialectContext {
|
|||||||
else if (name == "reshapePixelSize") {
|
else if (name == "reshapePixelSize") {
|
||||||
reshapePixelSize = value as! [Int32]
|
reshapePixelSize = value as! [Int32]
|
||||||
}
|
}
|
||||||
else if (name == "willPrepareGLContext") {
|
|
||||||
willPrepareGLContext = value as! Bool
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -419,7 +419,9 @@ func renderRegisterEffects(_ ctrl: DialectController) {
|
|||||||
let _: RenderContext? = registerOneliners(ctrl, [
|
let _: RenderContext? = registerOneliners(ctrl, [
|
||||||
F.didClickIncrement, { (c: RenderContext) in renderLoadCubeModel(RenderVM.shared!) },
|
F.didClickIncrement, { (c: RenderContext) in renderLoadCubeModel(RenderVM.shared!) },
|
||||||
F.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize },
|
F.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize },
|
||||||
F.willPrepareGLContext, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) },
|
F.didPrepareGLContext, { (c: RenderContext) in renderInit(RenderVM.shared!) },
|
||||||
|
F.didPrepareGLContext, { (c: RenderContext) in RenderVM.shared!.didPrepareGLContext = true },
|
||||||
|
F.didPrepareGLContext, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) },
|
||||||
|
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user