Ability to keep images in ImageTexture cached while using editor, fixes #25243

This commit is contained in:
Juan Linietsky 2019-01-25 13:39:43 -03:00
parent 3b2e854f4b
commit 32fa136cc7
3 changed files with 26 additions and 1 deletions

View File

@ -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) {

View File

@ -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 {

View File

@ -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);