diff options
author | Juan Linietsky <reduzio@gmail.com> | 2019-01-25 13:39:43 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2019-01-25 13:40:23 -0300 |
commit | 32fa136cc7db029fbe4656a89d51d2b97b4bc199 (patch) | |
tree | 6511ce3288de45bfc85baaf85e06e82335936b75 | |
parent | 3b2e854f4bbcac2f5ed752c95a7d2dbcd5f5f915 (diff) |
Ability to keep images in ImageTexture cached while using editor, fixes #25243
-rw-r--r-- | editor/editor_node.cpp | 2 | ||||
-rw-r--r-- | scene/resources/texture.cpp | 20 | ||||
-rw-r--r-- | scene/resources/texture.h | 5 |
3 files changed, 26 insertions, 1 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 719130621e..75f01ef055 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -4760,6 +4760,8 @@ EditorNode::EditorNode() { ResourceLoader::clear_translation_remaps(); //no remaps using during editor ResourceLoader::clear_path_remaps(); + ImageTexture::set_keep_images_cached(true); + InputDefault *id = Object::cast_to<InputDefault>(Input::get_singleton()); if (id) { diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 3870916779..26036c08a9 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -178,6 +178,12 @@ void ImageTexture::_reload_hook(const RID &p_hook) { _change_notify(); } +bool ImageTexture::keep_images_cached = false; + +void ImageTexture::set_keep_images_cached(bool p_enable) { + keep_images_cached = p_enable; +} + void ImageTexture::create(int p_width, int p_height, Image::Format p_format, uint32_t p_flags) { flags = p_flags; @@ -198,6 +204,10 @@ void ImageTexture::create_from_image(const Ref<Image> &p_image, uint32_t p_flags VisualServer::get_singleton()->texture_allocate(texture, p_image->get_width(), p_image->get_height(), 0, p_image->get_format(), VS::TEXTURE_TYPE_2D, p_flags); VisualServer::get_singleton()->texture_set_data(texture, p_image); _change_notify(); + + if (keep_images_cached) { + image_cache = p_image; + } } void ImageTexture::set_flags(uint32_t p_flags) { @@ -245,6 +255,10 @@ void ImageTexture::set_data(const Ref<Image> &p_image) { _change_notify(); alpha_cache.unref(); + + if (keep_images_cached) { + image_cache = p_image; + } } void ImageTexture::_resource_path_changed() { @@ -254,7 +268,11 @@ void ImageTexture::_resource_path_changed() { Ref<Image> ImageTexture::get_data() const { - return VisualServer::get_singleton()->texture_get_data(texture); + if (image_cache.is_valid()) { + return image_cache; + } else { + return VisualServer::get_singleton()->texture_get_data(texture); + } } int ImageTexture::get_width() const { diff --git a/scene/resources/texture.h b/scene/resources/texture.h index 2b67ebec62..a6b4c763e9 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -111,6 +111,7 @@ private: Size2 size_override; float lossy_storage_quality; mutable Ref<BitMap> alpha_cache; + Ref<ImageTexture> image_cache; protected: virtual void reload_from_file(); @@ -125,7 +126,11 @@ protected: void _set_data(Dictionary p_data); + static bool keep_images_cached; + public: + static void set_keep_images_cached(bool p_enable); + void create(int p_width, int p_height, Image::Format p_format, uint32_t p_flags = FLAGS_DEFAULT); void create_from_image(const Ref<Image> &p_image, uint32_t p_flags = FLAGS_DEFAULT); |