This commit is contained in:
Михаил Капелько committed 2026-10-19 17:08:35 +03:00
1 parent 0da8bfcfa2
commit 30476a880d
5 files changed
+69 -25

No files matched your search

@@ -6,8 +6,8 @@ import SwiftUI
final class RenderGLView: NSOpenGLView {
private var renderTimer: Timer?
private var ready = false
private var pixelWidth: Int32 = 1
private var pixelHeight: Int32 = 1
//private var pixelWidth: Int32 = 1
//private var pixelHeight: Int32 = 1
private var startTime: CFTimeInterval = 0
override init(frame frameRect: NSRect) {
@@ -33,9 +33,7 @@ final class RenderGLView: NSOpenGLView {
var swapInterval: Int32 = 1
context.setValues(&swapInterval, for: .swapInterval)
otherPrintStderr("RenderGLView prepareOpenGL bounds \(bounds) backing \(convertToBacking(bounds))")
sr_init(pixelWidth, pixelHeight,
sr_init(1, 1,
RENDER_SHADER_MAIN_VS, RENDER_SHADER_MAIN_FS,
RENDER_SHADER_SHADOW_VS, RENDER_SHADER_SHADOW_FS,
RENDER_CONFIG)
@@ -84,12 +82,14 @@ final class RenderGLView: NSOpenGLView {
super.reshape()
otherPrintStderr("RenderGLView reshape bounds \(bounds) backing \(convertToBacking(bounds))")
needsDisplay = true
renderSet(F.didReshape, true)
}
override func viewDidChangeBackingProperties() {
super.viewDidChangeBackingProperties()
otherPrintStderr("RenderGLView viewDidChangeBackingProperties bounds \(bounds) backing \(convertToBacking(bounds))")
needsDisplay = true
renderSet(F.didChangeBacking, true)
}
override func draw(_ dirtyRect: NSRect) {
@@ -98,12 +98,14 @@ final class RenderGLView: NSOpenGLView {
context.makeCurrentContext()
// Update pixel size
let pixelSize = renderPixelSize(self)
/*
let backing = convertToBacking(bounds)
otherPrintStderr("RenderGLView draw bounds \(bounds) backing \(backing)")
pixelWidth = Int32(max(1, backing.width))
pixelHeight = Int32(max(1, backing.height))
*/
sr_resize(pixelWidth, pixelHeight)
sr_resize(pixelSize[0], pixelSize[1])
let t = Float(CACurrentMediaTime() - startTime)
+8
View File
@@ -0,0 +1,8 @@
import AppKit
func renderPixelSize(_ view: NSView) -> [Int32] {
let backing = view.convertToBacking(view.bounds)
let w = Int32(max(1, backing.width))
let h = Int32(max(1, backing.height))
return [w, h]
}
+9 -2
View File
@@ -7,11 +7,12 @@ output:
RenderContext:
type: context
fields:
didChangeBacking: Bool
didLaunch: Bool
didReshape: Bool
didSetup: Bool
isReadyToRender: Bool
pixelHeight: Int
pixelWidth: Int
pixelSize: [Int32]
RenderComponent:
type: component
@@ -25,6 +26,12 @@ RenderComponent:
c.didLaunch == false
then:
c.didLaunch = true
pixelSize:
1. Upon launch:
if:
c.recentField == F.didLaunch
then:
c.pixelSize = [1, 1]
RootComponent:
type: component
+42 -16
View File
@@ -121,38 +121,43 @@ func registerOneliners<T>(
public struct F {
public static let count = "count"
public static let countText = "countText"
public static let didChangeBacking = "didChangeBacking"
public static let didClickIncrement = "didClickIncrement"
public static let didLaunch = "didLaunch"
public static let didReshape = "didReshape"
public static let didSetup = "didSetup"
public static let isReadyToRender = "isReadyToRender"
public static let pixelHeight = "pixelHeight"
public static let pixelWidth = "pixelWidth"
public static let pixelSize = "pixelSize"
}
public struct RenderContext: DialectContext {
public var didChangeBacking = Bool()
public var didLaunch = Bool()
public var didReshape = Bool()
public var didSetup = Bool()
public var isReadyToRender = Bool()
public var pixelHeight = Int()
public var pixelWidth = Int()
public var pixelSize = [Int32]()
public var recentField = ""
public func field<T>(_ name: String) -> T {
if (name == "didLaunch") {
if (name == "didChangeBacking") {
return didChangeBacking as! T
}
else if (name == "didLaunch") {
return didLaunch as! T
}
else if (name == "didReshape") {
return didReshape as! T
}
else if (name == "didSetup") {
return didSetup as! T
}
else if (name == "isReadyToRender") {
return isReadyToRender as! T
}
else if (name == "pixelHeight") {
return pixelHeight as! T
}
else if (name == "pixelWidth") {
return pixelWidth as! T
else if (name == "pixelSize") {
return pixelSize as! T
}
return "unknown-field-name" as! T
@@ -162,20 +167,23 @@ public struct RenderContext: DialectContext {
_ name: String,
_ value: Any
) {
if (name == "didLaunch") {
if (name == "didChangeBacking") {
didChangeBacking = value as! Bool
}
else if (name == "didLaunch") {
didLaunch = value as! Bool
}
else if (name == "didReshape") {
didReshape = value as! Bool
}
else if (name == "didSetup") {
didSetup = value as! Bool
}
else if (name == "isReadyToRender") {
isReadyToRender = value as! Bool
}
else if (name == "pixelHeight") {
pixelHeight = value as! Int
}
else if (name == "pixelWidth") {
pixelWidth = value as! Int
else if (name == "pixelSize") {
pixelSize = value as! [Int32]
}
}
@@ -265,6 +273,23 @@ func renderShouldResetDidLaunch(_ c: RenderContext) -> RenderContext {
return c
}
func renderShouldResetPixelSize(_ c: RenderContext) -> RenderContext {
var c = c
/* 1. Upon launch */
if
c.recentField == F.didLaunch
{
c.pixelSize = [1, 1]
c.recentField = F.pixelSize
return c
}
c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE
return c
}
func rootShouldResetCount(_ c: RootContext) -> RootContext {
var c = c
@@ -339,6 +364,7 @@ func rootShouldResetDidLaunch(_ c: RootContext) -> RootContext {
func renderRegisterShoulds(_ ctrl: DialectController) {
[
renderShouldResetDidLaunch,
renderShouldResetPixelSize,
].forEach { f in
ctrl.registerFunction { c in f(c as! RenderContext) }
+1
View File
@@ -0,0 +1 @@
../../../../components/render/renderAux.swift