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

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