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