Respect texture .flags files on export
(cherry picked from commit 11cbbeb17e
)
This commit is contained in:
parent
73e7ccabf5
commit
de13e52b9b
4 changed files with 100 additions and 75 deletions
|
@ -136,7 +136,32 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_origin
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
uint32_t flags=0;
|
uint32_t flags=load_image_flags(p_path);
|
||||||
|
|
||||||
|
if (debug_load_times)
|
||||||
|
begtime=OS::get_singleton()->get_ticks_usec();
|
||||||
|
|
||||||
|
//print_line("img: "+p_path+" flags: "+itos(flags));
|
||||||
|
texture->create_from_image( image,flags );
|
||||||
|
texture->set_name(p_path.get_file());
|
||||||
|
|
||||||
|
|
||||||
|
if (debug_load_times) {
|
||||||
|
total=USEC_TO_SEC(OS::get_singleton()->get_ticks_usec()-begtime);
|
||||||
|
print_line(" -make texture: "+rtos(total));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r_error)
|
||||||
|
*r_error=OK;
|
||||||
|
|
||||||
|
return RES( texture );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ResourceFormatLoaderImage::load_image_flags(const String &p_path) {
|
||||||
|
|
||||||
|
|
||||||
FileAccess *f2 = FileAccess::open(p_path+".flags",FileAccess::READ);
|
FileAccess *f2 = FileAccess::open(p_path+".flags",FileAccess::READ);
|
||||||
Map<String,bool> flags_found;
|
Map<String,bool> flags_found;
|
||||||
|
@ -155,6 +180,8 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_origin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t flags=0;
|
||||||
|
|
||||||
if (flags_found.has("filter")) {
|
if (flags_found.has("filter")) {
|
||||||
if (flags_found["filter"])
|
if (flags_found["filter"])
|
||||||
flags|=Texture::FLAG_FILTER;
|
flags|=Texture::FLAG_FILTER;
|
||||||
|
@ -192,26 +219,7 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_origin
|
||||||
flags|=Texture::FLAG_MIRRORED_REPEAT;
|
flags|=Texture::FLAG_MIRRORED_REPEAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug_load_times)
|
return flags;
|
||||||
begtime=OS::get_singleton()->get_ticks_usec();
|
|
||||||
|
|
||||||
//print_line("img: "+p_path+" flags: "+itos(flags));
|
|
||||||
texture->create_from_image( image,flags );
|
|
||||||
texture->set_name(p_path.get_file());
|
|
||||||
|
|
||||||
|
|
||||||
if (debug_load_times) {
|
|
||||||
total=USEC_TO_SEC(OS::get_singleton()->get_ticks_usec()-begtime);
|
|
||||||
print_line(" -make texture: "+rtos(total));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r_error)
|
|
||||||
*r_error=OK;
|
|
||||||
|
|
||||||
return RES( texture );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ResourceFormatLoaderImage::handles_type(const String& p_type) const {
|
bool ResourceFormatLoaderImage::handles_type(const String& p_type) const {
|
||||||
|
|
|
@ -39,8 +39,8 @@ class ResourceFormatLoaderImage : public ResourceFormatLoader {
|
||||||
bool debug_load_times;
|
bool debug_load_times;
|
||||||
int max_texture_size;
|
int max_texture_size;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
|
virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
|
||||||
|
static uint32_t load_image_flags(const String &p_path);
|
||||||
virtual void get_recognized_extensions(List<String> *p_extensions) const;
|
virtual void get_recognized_extensions(List<String> *p_extensions) const;
|
||||||
virtual bool handles_type(const String& p_type) const;
|
virtual bool handles_type(const String& p_type) const;
|
||||||
virtual String get_resource_type(const String &p_path) const;
|
virtual String get_resource_type(const String &p_path) const;
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include "scene/gui/check_button.h"
|
#include "scene/gui/check_button.h"
|
||||||
#include "scene/gui/button_group.h"
|
#include "scene/gui/button_group.h"
|
||||||
#include "scene/gui/margin_container.h"
|
#include "scene/gui/margin_container.h"
|
||||||
|
#include "scene/io/resource_format_image.h"
|
||||||
|
|
||||||
static const char *flag_names[]={
|
static const char *flag_names[]={
|
||||||
("Streaming Format"),
|
("Streaming Format"),
|
||||||
|
@ -1589,16 +1590,9 @@ Vector<uint8_t> EditorTextureImportPlugin::custom_export(const String& p_path, c
|
||||||
} break; //use default
|
} break; //use default
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String validated_path=EditorImportPlugin::validate_source_path(p_path);
|
||||||
|
|
||||||
int flags=0;
|
int flags=texture_flags_to_export_flags(ResourceFormatLoaderImage::load_image_flags(validated_path));
|
||||||
|
|
||||||
if (Globals::get_singleton()->get("image_loader/filter"))
|
|
||||||
flags|=IMAGE_FLAG_FILTER;
|
|
||||||
if (!Globals::get_singleton()->get("image_loader/gen_mipmaps"))
|
|
||||||
flags|=IMAGE_FLAG_NO_MIPMAPS;
|
|
||||||
if (!Globals::get_singleton()->get("image_loader/repeat"))
|
|
||||||
flags|=IMAGE_FLAG_REPEAT;
|
|
||||||
|
|
||||||
flags|=IMAGE_FLAG_FIX_BORDER_ALPHA;
|
flags|=IMAGE_FLAG_FIX_BORDER_ALPHA;
|
||||||
|
|
||||||
print_line("group format"+itos(group_format));
|
print_line("group format"+itos(group_format));
|
||||||
|
@ -1607,7 +1601,7 @@ Vector<uint8_t> EditorTextureImportPlugin::custom_export(const String& p_path, c
|
||||||
rimd->set_option("quality",group_lossy_quality);
|
rimd->set_option("quality",group_lossy_quality);
|
||||||
rimd->set_option("atlas",false);
|
rimd->set_option("atlas",false);
|
||||||
rimd->set_option("shrink",group_shrink);
|
rimd->set_option("shrink",group_shrink);
|
||||||
rimd->add_source(EditorImportPlugin::validate_source_path(p_path),FileAccess::get_md5(p_path));
|
rimd->add_source(validated_path,FileAccess::get_md5(p_path));
|
||||||
|
|
||||||
} else if (EditorImportExport::get_singleton()->get_image_formats().has(p_path.extension().to_lower()) && EditorImportExport::get_singleton()->get_export_image_action()!=EditorImportExport::IMAGE_ACTION_NONE) {
|
} else if (EditorImportExport::get_singleton()->get_image_formats().has(p_path.extension().to_lower()) && EditorImportExport::get_singleton()->get_export_image_action()!=EditorImportExport::IMAGE_ACTION_NONE) {
|
||||||
//handled by general image export settings
|
//handled by general image export settings
|
||||||
|
@ -1619,22 +1613,16 @@ Vector<uint8_t> EditorTextureImportPlugin::custom_export(const String& p_path, c
|
||||||
case EditorImportExport::IMAGE_ACTION_COMPRESS_RAM: rimd->set_option("format",IMAGE_FORMAT_COMPRESS_RAM); break;
|
case EditorImportExport::IMAGE_ACTION_COMPRESS_RAM: rimd->set_option("format",IMAGE_FORMAT_COMPRESS_RAM); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int flags=0;
|
String validated_path=EditorImportPlugin::validate_source_path(p_path);
|
||||||
|
|
||||||
if (Globals::get_singleton()->get("image_loader/filter"))
|
|
||||||
flags|=IMAGE_FLAG_FILTER;
|
|
||||||
if (!Globals::get_singleton()->get("image_loader/gen_mipmaps"))
|
|
||||||
flags|=IMAGE_FLAG_NO_MIPMAPS;
|
|
||||||
if (!Globals::get_singleton()->get("image_loader/repeat"))
|
|
||||||
flags|=IMAGE_FLAG_REPEAT;
|
|
||||||
|
|
||||||
|
int flags=texture_flags_to_export_flags(ResourceFormatLoaderImage::load_image_flags(validated_path));
|
||||||
flags|=IMAGE_FLAG_FIX_BORDER_ALPHA;
|
flags|=IMAGE_FLAG_FIX_BORDER_ALPHA;
|
||||||
|
|
||||||
rimd->set_option("shrink",EditorImportExport::get_singleton()->get_export_image_shrink());
|
rimd->set_option("shrink",EditorImportExport::get_singleton()->get_export_image_shrink());
|
||||||
rimd->set_option("flags",flags);
|
rimd->set_option("flags",flags);
|
||||||
rimd->set_option("quality",EditorImportExport::get_singleton()->get_export_image_quality());
|
rimd->set_option("quality",EditorImportExport::get_singleton()->get_export_image_quality());
|
||||||
rimd->set_option("atlas",false);
|
rimd->set_option("atlas",false);
|
||||||
rimd->add_source(EditorImportPlugin::validate_source_path(p_path),FileAccess::get_md5(p_path));
|
rimd->add_source(validated_path,FileAccess::get_md5(p_path));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return Vector<uint8_t>();
|
return Vector<uint8_t>();
|
||||||
|
@ -1726,6 +1714,33 @@ Vector<uint8_t> EditorTextureImportPlugin::custom_export(const String& p_path, c
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t EditorTextureImportPlugin::texture_flags_to_export_flags(uint32_t p_tex_flags) const {
|
||||||
|
|
||||||
|
uint32_t flags=0;
|
||||||
|
|
||||||
|
if (!(p_tex_flags&Texture::FLAG_MIPMAPS)) {
|
||||||
|
flags|=IMAGE_FLAG_NO_MIPMAPS;
|
||||||
|
}
|
||||||
|
if (p_tex_flags&Texture::FLAG_REPEAT) {
|
||||||
|
flags|=IMAGE_FLAG_REPEAT;
|
||||||
|
}
|
||||||
|
if (p_tex_flags&Texture::FLAG_FILTER) {
|
||||||
|
flags|=IMAGE_FLAG_FILTER;
|
||||||
|
}
|
||||||
|
if (p_tex_flags&Texture::FLAG_ANISOTROPIC_FILTER) {
|
||||||
|
flags|=IMAGE_FLAG_USE_ANISOTROPY;
|
||||||
|
}
|
||||||
|
if (p_tex_flags&Texture::FLAG_CONVERT_TO_LINEAR) {
|
||||||
|
flags|=IMAGE_FLAG_CONVERT_TO_LINEAR;
|
||||||
|
}
|
||||||
|
/* // no correspondence yet
|
||||||
|
if (p_tex_flags&Texture::TEXTURE_FLAG_MIRRORED_REPEAT) {
|
||||||
|
flags|=;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
void EditorTextureImportPlugin::import_from_drop(const Vector<String>& p_drop,const String& p_dest_path) {
|
void EditorTextureImportPlugin::import_from_drop(const Vector<String>& p_drop,const String& p_dest_path) {
|
||||||
|
|
||||||
Vector<String> valid;
|
Vector<String> valid;
|
||||||
|
|
|
@ -72,6 +72,8 @@ private:
|
||||||
|
|
||||||
Error _process_texture_data(Ref<ImageTexture> &texture, int format, float quality, int flags,EditorExportPlatform::ImageCompression p_compr,int tex_flags,float shrink);
|
Error _process_texture_data(Ref<ImageTexture> &texture, int format, float quality, int flags,EditorExportPlatform::ImageCompression p_compr,int tex_flags,float shrink);
|
||||||
void compress_image(EditorExportPlatform::ImageCompression p_mode,Image& image,bool p_smaller);
|
void compress_image(EditorExportPlatform::ImageCompression p_mode,Image& image,bool p_smaller);
|
||||||
|
|
||||||
|
uint32_t texture_flags_to_export_flags(uint32_t p_tex_flags) const;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue