mirror of
https://github.com/thegatesbrowser/thegates.git
synced 2025-08-23 17:17:31 -04:00
gd: create_external_texture -> texture_copy
This commit is contained in:
parent
cfd2e72331
commit
4a66f5f628
3 changed files with 60 additions and 57 deletions
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=33 format=3 uid="uid://dagj0celx6tjq"]
|
||||
[gd_scene load_steps=31 format=3 uid="uid://dagj0celx6tjq"]
|
||||
|
||||
[ext_resource type="Script" path="res://the_gates/scripts/loading/pack_loader.gd" id="1_5swiq"]
|
||||
[ext_resource type="Script" path="res://the_gates/scripts/loading/gate_loader.gd" id="1_coscx"]
|
||||
|
@ -17,7 +17,6 @@
|
|||
[ext_resource type="Script" path="res://the_gates/scripts/ui/world/release_focus.gd" id="10_6a8ws"]
|
||||
[ext_resource type="Texture2D" uid="uid://bj8xlyxihfske" path="res://the_gates/textures/background.jpg" id="10_v058a"]
|
||||
[ext_resource type="PackedScene" path="res://the_gates/scenes/components/hint.tscn" id="11_cltj4"]
|
||||
[ext_resource type="Script" path="res://the_gates/scripts/gate_jump.gd" id="16_ltdw2"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_shmbc"]
|
||||
bg_color = Color(0.3384, 0.188, 0.47, 1)
|
||||
|
@ -68,8 +67,6 @@ border_color = Color(0.231373, 0.184314, 0.541176, 1)
|
|||
[sub_resource type="LabelSettings" id="LabelSettings_5jdc5"]
|
||||
font_size = 27
|
||||
|
||||
[sub_resource type="World3D" id="World3D_k4sim"]
|
||||
|
||||
[node name="World" type="Node"]
|
||||
|
||||
[node name="Loaders" type="Node" parent="."]
|
||||
|
@ -78,10 +75,10 @@ font_size = 27
|
|||
script = ExtResource("1_coscx")
|
||||
gate_events = ExtResource("2_ot8b0")
|
||||
|
||||
[node name="PackLoader" type="Node" parent="Loaders" node_paths=PackedStringArray("scenes_parent")]
|
||||
[node name="PackLoader" type="Node" parent="Loaders" node_paths=PackedStringArray("render_result")]
|
||||
script = ExtResource("1_5swiq")
|
||||
gate_events = ExtResource("2_ot8b0")
|
||||
scenes_parent = NodePath("../../SubViewportContainer/WorldViewport")
|
||||
render_result = NodePath("../../WorldCanvas/RenderResult")
|
||||
|
||||
[node name="UICanvas" type="CanvasLayer" parent="."]
|
||||
follow_viewport_enabled = true
|
||||
|
@ -160,7 +157,7 @@ label_settings = SubResource("LabelSettings_fcbo7")
|
|||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="UI" type="Control" parent="UICanvas" node_paths=PackedStringArray("world_viewport")]
|
||||
[node name="UI" type="Control" parent="UICanvas"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
|
@ -168,7 +165,6 @@ anchor_bottom = 1.0
|
|||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("4_xatjs")
|
||||
world_viewport = NodePath("../../SubViewportContainer/WorldViewport")
|
||||
|
||||
[node name="Blur" type="Panel" parent="UICanvas/UI"]
|
||||
material = SubResource("ShaderMaterial_kc7rv")
|
||||
|
@ -703,22 +699,22 @@ layout_mode = 2
|
|||
texture = ExtResource("4_x2j1m")
|
||||
expand_mode = 1
|
||||
|
||||
[node name="SubViewportContainer" type="SubViewportContainer" parent="."]
|
||||
[node name="WorldCanvas" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
stretch = true
|
||||
metadata/_edit_lock_ = true
|
||||
|
||||
[node name="WorldViewport" type="SubViewport" parent="SubViewportContainer"]
|
||||
world_3d = SubResource("World3D_k4sim")
|
||||
handle_input_locally = false
|
||||
size = Vector2i(1920, 1080)
|
||||
render_target_update_mode = 4
|
||||
script = ExtResource("16_ltdw2")
|
||||
gate_events = ExtResource("2_ot8b0")
|
||||
[node name="RenderResult" type="TextureRect" parent="WorldCanvas"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[connection signal="pressed" from="UICanvas/UI/Blur/HideOnPress" to="UICanvas/UI" method="hide_ui"]
|
||||
[connection signal="pressed" from="UICanvas/UI/GateInfo/Bookmark/Star" to="UICanvas/UI/GateInfo" method="_on_star_pressed"]
|
||||
|
|
|
@ -2,68 +2,79 @@ extends Node
|
|||
class_name PackLoader
|
||||
|
||||
@export var gate_events: GateEvents
|
||||
@export var scenes_parent: Node
|
||||
@export var render_result: TextureRect
|
||||
|
||||
var gate: Gate
|
||||
var c_g_script: ConfigGlobalScript
|
||||
var c_godot: ConfigGodot
|
||||
|
||||
var pid: int
|
||||
|
||||
@onready var width = get_viewport().size.x
|
||||
@onready var height = get_viewport().size.y
|
||||
|
||||
var rd: RenderingDevice
|
||||
var ext_texure_rid: RID
|
||||
var result_texture_rid: RID
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
# gate_events.gate_loaded.connect(load_pack)
|
||||
gate_events.gate_loaded.connect(create_process)
|
||||
initialize()
|
||||
|
||||
|
||||
func load_pack(_gate: Gate) -> void:
|
||||
gate = _gate
|
||||
var success = ProjectSettings.load_resource_pack(gate.resource_pack)
|
||||
if not success: Debug.logerr("cannot load pck"); return
|
||||
|
||||
c_g_script = ConfigGlobalScript.new(gate.global_script_class)
|
||||
c_godot = ConfigGodot.new(gate.godot_config)
|
||||
|
||||
c_g_script.load_config() # Loading order is important
|
||||
c_godot.load_config()
|
||||
|
||||
var scene = load(c_godot.scene_path)
|
||||
scenes_parent.add_child(scene.instantiate())
|
||||
|
||||
gate_events.gate_entered_emit()
|
||||
func _process(_delta: float) -> void:
|
||||
texture_update()
|
||||
|
||||
|
||||
func unload_pack() -> void:
|
||||
if gate == null: return
|
||||
var success = ProjectSettings.unload_resource_pack(gate.resource_pack)
|
||||
if not success: Debug.logerr("cannot unload pck")
|
||||
else: Debug.logr("\nunloaded " + gate.resource_pack + "\n")
|
||||
func initialize() -> void:
|
||||
rd = RenderingServer.get_rendering_device()
|
||||
|
||||
if c_godot != null: c_godot.unload_config()
|
||||
if c_g_script != null: c_g_script.unload_config()
|
||||
var image = Image.create(width, height, false, Image.FORMAT_RGBA8)
|
||||
render_result.texture = ImageTexture.create_from_image(image)
|
||||
result_texture_rid = RenderingServer.texture_get_rd_texture(render_result.texture.get_rid())
|
||||
if not result_texture_rid.is_valid(): Debug.logerr("Cannot create ImageTexture")
|
||||
else: Debug.logclr("Render result texture created", Color.AQUAMARINE)
|
||||
|
||||
|
||||
func create_process(_gate: Gate) -> void:
|
||||
gate = _gate
|
||||
|
||||
var rd = RenderingServer.get_rendering_device() as RenderingDevice
|
||||
var width = get_viewport().size.x
|
||||
var height = get_viewport().size.y
|
||||
var fd = rd.create_external_texture(width, height)
|
||||
|
||||
var main_pid = OS.get_process_id()
|
||||
|
||||
var pack_file = ProjectSettings.globalize_path(gate.resource_pack)
|
||||
var sandbox_path = "/home/nordup/projects/godot/the-gates-folder/the-gates/bin/godot.linuxbsd.editor.dev.sandbox.x86_64.llvm"
|
||||
var pack_file = ProjectSettings.globalize_path(gate.resource_pack)
|
||||
var main_pid = OS.get_process_id()
|
||||
var fd = create_external_texture()
|
||||
if fd == -1: Debug.logerr("Cannot create external texture"); return
|
||||
else: Debug.logclr("External texture created " + str(fd), Color.AQUAMARINE)
|
||||
|
||||
var args = [
|
||||
"--main-pack", pack_file,
|
||||
"--resolution", "%dx%d" % [width, height],
|
||||
"--external-image", fd,
|
||||
"--main-pid", main_pid
|
||||
]
|
||||
print(sandbox_path + " " + " ".join(args))
|
||||
Debug.logclr(sandbox_path + " " + " ".join(args), Color.DARK_VIOLET)
|
||||
pid = OS.create_process(sandbox_path, args)
|
||||
|
||||
gate_events.gate_entered_emit()
|
||||
|
||||
|
||||
func create_external_texture() -> int:
|
||||
var t_format: RDTextureFormat = RDTextureFormat.new()
|
||||
t_format.format = RenderingDevice.DATA_FORMAT_R8G8B8A8_UNORM
|
||||
t_format.usage_bits = RenderingDevice.TEXTURE_USAGE_CAN_COPY_FROM_BIT
|
||||
t_format.width = width
|
||||
t_format.height = height
|
||||
t_format.depth = 1
|
||||
var t_view: RDTextureView = RDTextureView.new()
|
||||
|
||||
ext_texure_rid = rd.create_external_texture(t_format, t_view)
|
||||
return rd.get_external_texture_fd(ext_texure_rid)
|
||||
|
||||
|
||||
func texture_update() -> void:
|
||||
if not ext_texure_rid.is_valid() or not result_texture_rid.is_valid(): return
|
||||
|
||||
rd.texture_copy(ext_texure_rid, result_texture_rid, Vector3.ZERO, Vector3.ZERO,
|
||||
Vector3(width, height, 1), 0, 0, 0, 0)
|
||||
|
||||
|
||||
func kill_process() -> void:
|
||||
if OS.is_process_running(pid):
|
||||
|
@ -71,5 +82,4 @@ func kill_process() -> void:
|
|||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
# unload_pack()
|
||||
kill_process()
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
extends Control
|
||||
|
||||
@export var world_viewport: SubViewport
|
||||
var mouse_mode: int = Input.MOUSE_MODE_VISIBLE
|
||||
|
||||
|
||||
|
@ -19,7 +18,6 @@ func _input(event: InputEvent) -> void:
|
|||
|
||||
func show_ui() -> void:
|
||||
visible = true
|
||||
world_viewport.gui_disable_input = true
|
||||
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
||||
mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
|
@ -29,6 +27,5 @@ func show_ui() -> void:
|
|||
|
||||
func hide_ui() -> void:
|
||||
visible = false
|
||||
world_viewport.gui_disable_input = false
|
||||
if mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue