fix setting resolution

This commit is contained in:
Nordup 2024-07-20 18:41:35 +04:00
parent c545b69a0d
commit 12101025dc
4 changed files with 32 additions and 11 deletions

View file

@ -5,11 +5,13 @@ class_name RenderResult
@export var command_events: CommandEvents
@export var ui_events: UiEvents
const MAX_RESOLUTION_WIDTH = 1920 # TODO: move to settings
var ext_texure: ExternalTexture
var texture_rid: RID
@onready var width: int = get_viewport().size.x / (2 if Platform.is_macos() else 1)
@onready var height: int = get_viewport().size.y / (2 if Platform.is_macos() else 1)
var width: int
var height: int
func _ready() -> void:
@ -18,6 +20,21 @@ func _ready() -> void:
command_events.ext_texture_format.connect(ext_texture_format)
command_events.first_frame_drawn.connect(first_frame_drawn)
define_size()
resize_texture()
func define_size() -> void:
width = get_viewport().size.x
height = get_viewport().size.y
if width > MAX_RESOLUTION_WIDTH:
width = int(ui_events.current_ui_size.x)
height = int(ui_events.current_ui_size.y)
Debug.logclr("Max resolution applied", Color.DIM_GRAY)
func resize_texture() -> void:
# Create empty texture with window size
var image = Image.create(width, height, false, Image.FORMAT_RGBA8)
self.texture = ImageTexture.create_from_image(image)

View file

@ -38,9 +38,10 @@ func start_sandbox_linux(gate: Gate) -> void:
var args = [
snbx_env.start.get_base_dir(), # cd to dir
"--main-pack", snbx_env.main_pack,
"--resolution", "%dx%d" % [render_result.width, render_result.height],
"--verbose" if OS.is_stdout_verbose() else ""
"--resolution", "%dx%d" % [render_result.width, render_result.height]
]
if OS.is_stdout_verbose(): args.append(["--verbose"])
Debug.logclr(snbx_env.start + " " + " ".join(args), Color.DARK_VIOLET)
sandbox_pid = OS.create_process(snbx_env.start, args)
@ -57,10 +58,11 @@ func start_sandbox_windows(gate: Gate) -> void:
var shared_libs = ProjectSettings.globalize_path(gate.shared_libs_dir)
var args = [
"--main-pack", pack_file,
"--gdext-libs-dir", shared_libs,
"--resolution", "%dx%d" % [render_result.width, render_result.height],
"--verbose" if OS.is_stdout_verbose() else ""
"--resolution", "%dx%d" % [render_result.width, render_result.height]
]
if not shared_libs.is_empty(): args += ["--gdext-libs-dir", shared_libs]
if OS.is_stdout_verbose(): args += ["--verbose"]
Debug.logclr(snbx_executable.path + " " + " ".join(args), Color.DARK_VIOLET)
sandbox_pid = OS.create_process(snbx_executable.path, args)
@ -75,10 +77,11 @@ func start_sandbox_macos(gate: Gate) -> void:
var shared_libs = ProjectSettings.globalize_path(gate.shared_libs_dir)
var args = [
"--main-pack", pack_file,
"--gdext-libs-dir", shared_libs,
"--resolution", "%dx%d" % [render_result.width, render_result.height],
"--verbose" if OS.is_stdout_verbose() else ""
"--resolution", "%dx%d" % [render_result.width, render_result.height]
]
if not shared_libs.is_empty(): args += ["--gdext-libs-dir", shared_libs]
if OS.is_stdout_verbose(): args += ["--verbose"]
Debug.logclr(snbx_executable.path + " " + " ".join(args), Color.DARK_VIOLET)
sandbox_pid = OS.create_process(snbx_executable.path, args)