mirror of
https://github.com/thegatesbrowser/thegates.git
synced 2025-08-22 23:17:26 -04:00
ext_texture_format and first_frame_drawn for swapchaing copying
This commit is contained in:
parent
644a8bb969
commit
78ad658f06
7 changed files with 151 additions and 49 deletions
|
@ -17,15 +17,37 @@ func _execute_function(command: Command) -> Variant:
|
|||
Debug.logclr("Recieved command: " + command.name + ". Args: " + str(command.args), Color.SANDY_BROWN)
|
||||
match command.name:
|
||||
"send_filehandle":
|
||||
if command.args.size() != 1: Debug.logerr("Arg count should be 1"); return ""
|
||||
if wrong_args_count(command, 1): return ERR_INVALID_PARAMETER
|
||||
command_events.send_filehandle_emit(command.args[0])
|
||||
|
||||
"ext_texture_format":
|
||||
if wrong_args_count(command, 1): return ERR_INVALID_PARAMETER
|
||||
command_events.ext_texture_format_emit(command.args[0])
|
||||
|
||||
"first_frame_drawn":
|
||||
if wrong_args_count(command, 0): return ERR_INVALID_PARAMETER
|
||||
command_events.first_frame_drawn_emit()
|
||||
|
||||
"set_mouse_mode":
|
||||
if command.args.size() != 1: Debug.logerr("Arg count should be 1"); return ""
|
||||
if wrong_args_count(command, 1): return ERR_INVALID_PARAMETER
|
||||
command_events.set_mouse_mode_emit(command.args[0])
|
||||
|
||||
"open_gate":
|
||||
if command.args.size() != 1: Debug.logerr("Arg count should be 1"); return ""
|
||||
if wrong_args_count(command, 1): return ERR_INVALID_PARAMETER
|
||||
var url = Url.join(gate_events.current_gate_url, command.args[0])
|
||||
gate_events.open_gate_emit(url)
|
||||
|
||||
_:
|
||||
Debug.logerr("Command %s not implemented" % [command.name])
|
||||
return ""
|
||||
return ERR_METHOD_NOT_FOUND
|
||||
|
||||
return OK
|
||||
|
||||
|
||||
func wrong_args_count(command: Command, right_count: int) -> bool:
|
||||
var count = command.args.size()
|
||||
if count != right_count:
|
||||
Debug.logerr("Command %s args count should be %d but it's %d" % [command.name, right_count, count])
|
||||
return true
|
||||
|
||||
return false
|
||||
|
|
|
@ -4,9 +4,7 @@ class_name RenderResult
|
|||
@export var gate_events: GateEvents
|
||||
@export var command_events: CommandEvents
|
||||
@export var ui_events: UiEvents
|
||||
@export var splash_screen: Texture2D
|
||||
|
||||
var rd: RenderingDevice
|
||||
var ext_texure: ExternalTexture
|
||||
var texture_rid: RID
|
||||
|
||||
|
@ -15,40 +13,24 @@ var texture_rid: RID
|
|||
|
||||
|
||||
func _ready() -> void:
|
||||
gate_events.gate_info_loaded.connect(initialize)
|
||||
gate_events.gate_entered.connect(create_external_texture)
|
||||
command_events.send_filehandle.connect(send_filehandle)
|
||||
command_events.ext_texture_format.connect(ext_texture_format)
|
||||
command_events.first_frame_drawn.connect(first_frame_drawn)
|
||||
|
||||
# Change size
|
||||
var image = resize_and_convert(splash_screen.get_image(), Image.FORMAT_RGB8)
|
||||
# Create empty texture with window size
|
||||
var image = Image.create(width, height, false, Image.FORMAT_RGBA8)
|
||||
self.texture = ImageTexture.create_from_image(image)
|
||||
|
||||
|
||||
func initialize(gate: Gate, is_cached: bool) -> void:
|
||||
rd = RenderingServer.get_rendering_device()
|
||||
|
||||
if not is_cached: # Show thumbnail image
|
||||
self.texture = create_gate_image(gate)
|
||||
|
||||
texture_rid = RenderingServer.texture_get_rd_texture(self.texture.get_rid())
|
||||
if not texture_rid.is_valid(): Debug.logerr("Cannot create ImageTexture")
|
||||
|
||||
|
||||
func create_gate_image(gate: Gate) -> ImageTexture:
|
||||
var tex = FileTools.load_external_tex(gate.image)
|
||||
|
||||
var image: Image
|
||||
if tex != null: image = resize_and_convert(tex.get_image(), Image.FORMAT_RGB8)
|
||||
else: image = Image.create(width, height, false, Image.FORMAT_RGB8)
|
||||
|
||||
return ImageTexture.create_from_image(image)
|
||||
|
||||
|
||||
func create_external_texture() -> void:
|
||||
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 | \
|
||||
RenderingDevice.TEXTURE_USAGE_CAN_UPDATE_BIT
|
||||
RenderingDevice.TEXTURE_USAGE_CAN_UPDATE_BIT
|
||||
t_format.width = width
|
||||
t_format.height = height
|
||||
t_format.depth = 1
|
||||
|
@ -61,26 +43,38 @@ func create_external_texture() -> void:
|
|||
await get_tree().process_frame
|
||||
|
||||
ext_texure = ExternalTexture.new()
|
||||
var image = resize_and_convert(splash_screen.get_image(), Image.FORMAT_RGBA8)
|
||||
var err = ext_texure.create(t_format, t_view, [image.get_data()])
|
||||
var err = ext_texure.create(t_format, t_view)
|
||||
if err: Debug.logerr("Cannot create external texture")
|
||||
else: Debug.logclr("External texture created", Color.AQUAMARINE)
|
||||
|
||||
|
||||
func resize_and_convert(image: Image, format: Image.Format) -> Image:
|
||||
image.resize(width, height)
|
||||
image.convert(format)
|
||||
image.clear_mipmaps()
|
||||
return image
|
||||
|
||||
|
||||
func send_filehandle(filehandle_path: String) -> void:
|
||||
Debug.logr("Sending filehandle...")
|
||||
Debug.logclr("Sending filehandle...", Color.DIM_GRAY)
|
||||
var sent = false
|
||||
while not sent:
|
||||
sent = ext_texure.send_filehandle(filehandle_path)
|
||||
await get_tree().create_timer(0.1).timeout
|
||||
Debug.logr("filehandle was sent")
|
||||
await get_tree().process_frame
|
||||
Debug.logclr("filehandle was sent", Color.DIM_GRAY)
|
||||
|
||||
|
||||
func ext_texture_format(format: RenderingDevice.DataFormat) -> void:
|
||||
match format:
|
||||
RenderingDevice.DATA_FORMAT_R8G8B8A8_UNORM:
|
||||
set_param("ext_texture_is_bgra", false)
|
||||
Debug.logclr("External texture format is set to RGBA8", Color.DIM_GRAY)
|
||||
RenderingDevice.DATA_FORMAT_B8G8R8A8_UNORM:
|
||||
set_param("ext_texture_is_bgra", true)
|
||||
Debug.logclr("External texture format is set to BGRA8", Color.DIM_GRAY)
|
||||
_:
|
||||
Debug.logerr("Texture format %d is not supported" % [format])
|
||||
|
||||
|
||||
func first_frame_drawn() -> void:
|
||||
set_param("fill_alpha", true)
|
||||
|
||||
|
||||
func set_param(param: StringName, value: Variant) -> void:
|
||||
(material as ShaderMaterial).set_shader_parameter(param, value)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue