From e8288ac9ab854da0efc147815cff798ac59c1504 Mon Sep 17 00:00:00 2001 From: kobewi Date: Sun, 17 Jul 2022 23:55:46 +0200 Subject: [PATCH] Clarify create_from_image() usage --- doc/classes/ImageTexture.xml | 12 ++++++++++-- scene/resources/texture.cpp | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/classes/ImageTexture.xml b/doc/classes/ImageTexture.xml index e668e2e7fd6a..1ec5d19bb895 100644 --- a/doc/classes/ImageTexture.xml +++ b/doc/classes/ImageTexture.xml @@ -42,6 +42,14 @@ Returns the format of the texture, one of [enum Image.Format]. + + + + + Replaces the texture's data with a new [Image]. This will re-allocate new memory for the texture. + If you want to update the image, but don't need to change its paramters (format, size), use [method update] instead for better performance. + + @@ -54,8 +62,8 @@ Replaces the texture's data with a new [Image]. - [b]Note:[/b] The texture has to be initialized first with the [method create_from_image] method before it can be updated. The new image dimensions, format, and mipmaps configuration should match the existing texture's image configuration, otherwise it has to be re-created with the [method create_from_image] method. - Use this method over [method create_from_image] if you need to update the texture frequently, which is faster than allocating additional memory for a new texture each time. + [b]Note:[/b] The texture has to be created using [method create_from_image] or initialized first with the [method set_image] method before it can be updated. The new image dimensions, format, and mipmaps configuration should match the existing texture's image configuration. + Use this method over [method set_image] if you need to update the texture frequently, which is faster than allocating additional memory for a new texture each time. diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 3a8f50c3c3a3..7f1e01e245cc 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -323,6 +323,7 @@ void ImageTexture::_bind_methods() { ClassDB::bind_static_method("ImageTexture", D_METHOD("create_from_image", "image"), &ImageTexture::create_from_image); ClassDB::bind_method(D_METHOD("get_format"), &ImageTexture::get_format); + ClassDB::bind_method(D_METHOD("set_image", "image"), &ImageTexture::set_image); ClassDB::bind_method(D_METHOD("update", "image"), &ImageTexture::update); ClassDB::bind_method(D_METHOD("set_size_override", "size"), &ImageTexture::set_size_override); }