From ca1216fcefc4e0ff4d4a5895f0406475f62f019f Mon Sep 17 00:00:00 2001
From: smix8 <52464204+smix8@users.noreply.github.com>
Date: Sat, 6 Nov 2021 20:45:26 +0100
Subject: [PATCH] Expose VisualServer.texture_set_proxy() to GDScript
Expose VisualServer.texture_set_proxy() to GDScript
---
doc/classes/VisualServer.xml | 23 +++++++++++++++++++++++
servers/visual_server.cpp | 1 +
2 files changed, 24 insertions(+)
diff --git a/doc/classes/VisualServer.xml b/doc/classes/VisualServer.xml
index f8cfe042819..06751e27950 100644
--- a/doc/classes/VisualServer.xml
+++ b/doc/classes/VisualServer.xml
@@ -2820,6 +2820,29 @@
Sets the texture's path.
+
+
+
+
+
+ Creates an update link between two textures, similar to how [ViewportTexture]s operate. When the base texture is the texture of a [Viewport], every time the viewport renders a new frame, the proxy texture automatically receives an update.
+ For example, this code links a generic [ImageTexture] to the texture output of the [Viewport] using the VisualServer API:
+ [codeblock]
+ func _ready():
+ var viewport_rid = get_viewport().get_viewport_rid()
+ var viewport_texture_rid = VisualServer.viewport_get_texture(viewport_rid)
+
+ var proxy_texture = ImageTexture.new()
+ var viewport_texture_image_data = VisualServer.texture_get_data(viewport_texture_rid)
+
+ proxy_texture.create_from_image(viewport_texture_image_data)
+ var proxy_texture_rid = proxy_texture.get_rid()
+ VisualServer.texture_set_proxy(proxy_texture_rid, viewport_texture_rid)
+
+ $TextureRect.texture = proxy_texture
+ [/codeblock]
+
+
diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp
index 2f960f5ef37..ae96d3752f6 100644
--- a/servers/visual_server.cpp
+++ b/servers/visual_server.cpp
@@ -1854,6 +1854,7 @@ void VisualServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("texture_set_path", "texture", "path"), &VisualServer::texture_set_path);
ClassDB::bind_method(D_METHOD("texture_get_path", "texture"), &VisualServer::texture_get_path);
ClassDB::bind_method(D_METHOD("texture_set_shrink_all_x2_on_set_data", "shrink"), &VisualServer::texture_set_shrink_all_x2_on_set_data);
+ ClassDB::bind_method(D_METHOD("texture_set_proxy", "proxy", "base"), &VisualServer::texture_set_proxy);
ClassDB::bind_method(D_METHOD("texture_bind", "texture", "number"), &VisualServer::texture_bind);
ClassDB::bind_method(D_METHOD("texture_debug_usage"), &VisualServer::_texture_debug_usage_bind);