Respect texture .flags files on export

(cherry picked from commit 11cbbeb17e)
This commit is contained in:
Pedro J. Estébanez 2016-09-30 10:49:55 +02:00 committed by Rémi Verschelde
parent 73e7ccabf5
commit de13e52b9b
4 changed files with 100 additions and 75 deletions

View file

@ -136,61 +136,7 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_origin
#endif
uint32_t flags=0;
FileAccess *f2 = FileAccess::open(p_path+".flags",FileAccess::READ);
Map<String,bool> flags_found;
if (f2) {
while(!f2->eof_reached()) {
String l2 = f2->get_line();
int eqpos = l2.find("=");
if (eqpos!=-1) {
String flag=l2.substr(0,eqpos).strip_edges();
String val=l2.substr(eqpos+1,l2.length()).strip_edges().to_lower();
flags_found[flag]=(val=="true" || val=="1")?true:false;
}
}
memdelete(f2);
}
if (flags_found.has("filter")) {
if (flags_found["filter"])
flags|=Texture::FLAG_FILTER;
} else if (bool(GLOBAL_DEF("image_loader/filter",true))) {
flags|=Texture::FLAG_FILTER;
}
if (flags_found.has("gen_mipmaps")) {
if (flags_found["gen_mipmaps"])
flags|=Texture::FLAG_MIPMAPS;
} else if (bool(GLOBAL_DEF("image_loader/gen_mipmaps",true))) {
flags|=Texture::FLAG_MIPMAPS;
}
if (flags_found.has("repeat")) {
if (flags_found["repeat"])
flags|=Texture::FLAG_REPEAT;
} else if (bool(GLOBAL_DEF("image_loader/repeat",true))) {
flags|=Texture::FLAG_REPEAT;
}
if (flags_found.has("anisotropic")) {
if (flags_found["anisotropic"])
flags|=Texture::FLAG_ANISOTROPIC_FILTER;
}
if (flags_found.has("tolinear")) {
if (flags_found["tolinear"])
flags|=Texture::FLAG_CONVERT_TO_LINEAR;
}
if (flags_found.has("mirroredrepeat")) {
if (flags_found["mirroredrepeat"])
flags|=Texture::FLAG_MIRRORED_REPEAT;
}
uint32_t flags=load_image_flags(p_path);
if (debug_load_times)
begtime=OS::get_singleton()->get_ticks_usec();
@ -214,6 +160,68 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_origin
}
uint32_t ResourceFormatLoaderImage::load_image_flags(const String &p_path) {
FileAccess *f2 = FileAccess::open(p_path+".flags",FileAccess::READ);
Map<String,bool> flags_found;
if (f2) {
while(!f2->eof_reached()) {
String l2 = f2->get_line();
int eqpos = l2.find("=");
if (eqpos!=-1) {
String flag=l2.substr(0,eqpos).strip_edges();
String val=l2.substr(eqpos+1,l2.length()).strip_edges().to_lower();
flags_found[flag]=(val=="true" || val=="1")?true:false;
}
}
memdelete(f2);
}
uint32_t flags=0;
if (flags_found.has("filter")) {
if (flags_found["filter"])
flags|=Texture::FLAG_FILTER;
} else if (bool(GLOBAL_DEF("image_loader/filter",true))) {
flags|=Texture::FLAG_FILTER;
}
if (flags_found.has("gen_mipmaps")) {
if (flags_found["gen_mipmaps"])
flags|=Texture::FLAG_MIPMAPS;
} else if (bool(GLOBAL_DEF("image_loader/gen_mipmaps",true))) {
flags|=Texture::FLAG_MIPMAPS;
}
if (flags_found.has("repeat")) {
if (flags_found["repeat"])
flags|=Texture::FLAG_REPEAT;
} else if (bool(GLOBAL_DEF("image_loader/repeat",true))) {
flags|=Texture::FLAG_REPEAT;
}
if (flags_found.has("anisotropic")) {
if (flags_found["anisotropic"])
flags|=Texture::FLAG_ANISOTROPIC_FILTER;
}
if (flags_found.has("tolinear")) {
if (flags_found["tolinear"])
flags|=Texture::FLAG_CONVERT_TO_LINEAR;
}
if (flags_found.has("mirroredrepeat")) {
if (flags_found["mirroredrepeat"])
flags|=Texture::FLAG_MIRRORED_REPEAT;
}
return flags;
}
bool ResourceFormatLoaderImage::handles_type(const String& p_type) const {
return ObjectTypeDB::is_type(p_type,"Texture") || ObjectTypeDB::is_type(p_type,"CubeMap");

View file

@ -39,8 +39,8 @@ class ResourceFormatLoaderImage : public ResourceFormatLoader {
bool debug_load_times;
int max_texture_size;
public:
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 bool handles_type(const String& p_type) const;
virtual String get_resource_type(const String &p_path) const;

View file

@ -38,6 +38,7 @@
#include "scene/gui/check_button.h"
#include "scene/gui/button_group.h"
#include "scene/gui/margin_container.h"
#include "scene/io/resource_format_image.h"
static const char *flag_names[]={
("Streaming Format"),
@ -1589,16 +1590,9 @@ Vector<uint8_t> EditorTextureImportPlugin::custom_export(const String& p_path, c
} break; //use default
}
String validated_path=EditorImportPlugin::validate_source_path(p_path);
int flags=0;
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;
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("atlas",false);
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) {
//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;
}
int flags=0;
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;
String validated_path=EditorImportPlugin::validate_source_path(p_path);
int flags=texture_flags_to_export_flags(ResourceFormatLoaderImage::load_image_flags(validated_path));
flags|=IMAGE_FLAG_FIX_BORDER_ALPHA;
rimd->set_option("shrink",EditorImportExport::get_singleton()->get_export_image_shrink());
rimd->set_option("flags",flags);
rimd->set_option("quality",EditorImportExport::get_singleton()->get_export_image_quality());
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 {
return Vector<uint8_t>();
@ -1726,6 +1714,33 @@ Vector<uint8_t> EditorTextureImportPlugin::custom_export(const String& p_path, c
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) {
Vector<String> valid;

View file

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