From fa0b1f561a5ff14dfac73ce861354c987be4b216 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 88495b573..bc2cb3d71 100644
--- a/doc/classes/VisualServer.xml
+++ b/doc/classes/VisualServer.xml
@@ -2343,6 +2343,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 ce39ffd6a..26f1a180a 100644
--- a/servers/visual_server.cpp
+++ b/servers/visual_server.cpp
@@ -1861,6 +1861,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);