|
@@ -1,6 +1,106 @@
|
|
#include "resource_importer_texture.h"
|
|
#include "resource_importer_texture.h"
|
|
#include "io/image_loader.h"
|
|
#include "io/image_loader.h"
|
|
#include "scene/resources/texture.h"
|
|
#include "scene/resources/texture.h"
|
|
|
|
+#include "tools/editor/editor_file_system.h"
|
|
|
|
+#include "io/config_file.h"
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+void ResourceImporterTexture::_texture_reimport_srgb(const Ref<StreamTexture>& p_tex) {
|
|
|
|
+
|
|
|
|
+ singleton->mutex->lock();
|
|
|
|
+ StringName path = p_tex->get_path();
|
|
|
|
+
|
|
|
|
+ if (!singleton->make_flags.has(path)) {
|
|
|
|
+ singleton->make_flags[path]=0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ singleton->make_flags[path]|=MAKE_SRGB_FLAG;
|
|
|
|
+
|
|
|
|
+ print_line("requesting srgb for "+String(path));
|
|
|
|
+
|
|
|
|
+ singleton->mutex->unlock();
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+void ResourceImporterTexture::_texture_reimport_3d(const Ref<StreamTexture>& p_tex) {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ singleton->mutex->lock();
|
|
|
|
+ StringName path = p_tex->get_path();
|
|
|
|
+
|
|
|
|
+ if (!singleton->make_flags.has(path)) {
|
|
|
|
+ singleton->make_flags[path]=0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ singleton->make_flags[path]|=MAKE_3D_FLAG;
|
|
|
|
+
|
|
|
|
+ print_line("requesting 3d for "+String(path));
|
|
|
|
+
|
|
|
|
+ singleton->mutex->unlock();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void ResourceImporterTexture::update_imports() {
|
|
|
|
+
|
|
|
|
+ if (EditorFileSystem::get_singleton()->is_scanning() || EditorFileSystem::get_singleton()->is_importing()) {
|
|
|
|
+ return; // do nothing for noe
|
|
|
|
+ }
|
|
|
|
+ mutex->lock();
|
|
|
|
+
|
|
|
|
+ if (make_flags.empty()) {
|
|
|
|
+ mutex->unlock();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Vector<String> to_reimport;
|
|
|
|
+ for (Map<StringName,int>::Element *E=make_flags.front();E;E=E->next()) {
|
|
|
|
+
|
|
|
|
+ print_line("checking for reimport "+String(E->key()));
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Ref<ConfigFile> cf;
|
|
|
|
+ cf.instance();
|
|
|
|
+ String src_path = String(E->key())+".import";
|
|
|
|
+
|
|
|
|
+ Error err = cf->load(src_path);
|
|
|
|
+ ERR_CONTINUE(err!=OK);
|
|
|
|
+
|
|
|
|
+ bool changed=false;
|
|
|
|
+ if (E->get()&MAKE_SRGB_FLAG && int(cf->get_value("params","flags/srgb"))==2) {
|
|
|
|
+ cf->set_value("params","flags/srgb",1);
|
|
|
|
+ changed=true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (E->get()&MAKE_3D_FLAG && bool(cf->get_value("params","detect_3d"))) {
|
|
|
|
+ cf->set_value("params","detect_3d",false);
|
|
|
|
+ cf->set_value("params","compress/mode",2);
|
|
|
|
+ cf->set_value("params","flags/repeat",true);
|
|
|
|
+ cf->set_value("params","flags/filter",true);
|
|
|
|
+ cf->set_value("params","flags/mipmaps",true);
|
|
|
|
+ changed=true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (changed) {
|
|
|
|
+ cf->save(src_path);
|
|
|
|
+ to_reimport.push_back(E->key());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ make_flags.clear();
|
|
|
|
+
|
|
|
|
+ mutex->unlock();
|
|
|
|
+
|
|
|
|
+ if (to_reimport.size()) {
|
|
|
|
+ EditorFileSystem::get_singleton()->reimport_files(to_reimport);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
String ResourceImporterTexture::get_importer_name() const {
|
|
String ResourceImporterTexture::get_importer_name() const {
|
|
|
|
|
|
@@ -57,7 +157,7 @@ void ResourceImporterTexture::get_import_options(List<ImportOption> *r_options,i
|
|
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"flags/filter"),p_preset==PRESET_2D_PIXEL?false:true));
|
|
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"flags/filter"),p_preset==PRESET_2D_PIXEL?false:true));
|
|
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"flags/mipmaps"),p_preset==PRESET_3D?true:false));
|
|
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"flags/mipmaps"),p_preset==PRESET_3D?true:false));
|
|
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"flags/anisotropic"),false));
|
|
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"flags/anisotropic"),false));
|
|
- r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"flags/srgb",PROPERTY_HINT_ENUM,"Disable,Enable,Detect"),2));
|
|
|
|
|
|
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"flags/srgb",PROPERTY_HINT_ENUM,"Disable,Enable,Detect"),2));
|
|
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"process/fix_alpha_border"),p_preset!=PRESET_3D?true:false));
|
|
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"process/fix_alpha_border"),p_preset!=PRESET_3D?true:false));
|
|
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"process/premult_alpha"),true));
|
|
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"process/premult_alpha"),true));
|
|
r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"stream"),false));
|
|
r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"stream"),false));
|
|
@@ -67,7 +167,7 @@ void ResourceImporterTexture::get_import_options(List<ImportOption> *r_options,i
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-void ResourceImporterTexture::_save_stex(const Image& p_image,const String& p_to_path,int p_compress_mode,float p_lossy_quality,Image::CompressMode p_vram_compression,bool p_mipmaps,int p_texture_flags,bool p_streamable) {
|
|
|
|
|
|
+void ResourceImporterTexture::_save_stex(const Image& p_image, const String& p_to_path, int p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags, bool p_streamable, bool p_detect_3d, bool p_detect_srgb) {
|
|
|
|
|
|
|
|
|
|
FileAccess *f = FileAccess::open(p_to_path,FileAccess::WRITE);
|
|
FileAccess *f = FileAccess::open(p_to_path,FileAccess::WRITE);
|
|
@@ -86,6 +186,11 @@ void ResourceImporterTexture::_save_stex(const Image& p_image,const String& p_to
|
|
format|=StreamTexture::FORMAT_BIT_STREAM;
|
|
format|=StreamTexture::FORMAT_BIT_STREAM;
|
|
if (p_mipmaps || p_compress_mode==COMPRESS_VIDEO_RAM) //VRAM always uses mipmaps
|
|
if (p_mipmaps || p_compress_mode==COMPRESS_VIDEO_RAM) //VRAM always uses mipmaps
|
|
format|=StreamTexture::FORMAT_BIT_HAS_MIPMAPS; //mipmaps bit
|
|
format|=StreamTexture::FORMAT_BIT_HAS_MIPMAPS; //mipmaps bit
|
|
|
|
+ if (p_detect_3d)
|
|
|
|
+ format|=StreamTexture::FORMAT_BIT_DETECT_3D;
|
|
|
|
+ if (p_detect_srgb)
|
|
|
|
+ format|=StreamTexture::FORMAT_BIT_DETECT_SRGB;
|
|
|
|
+
|
|
|
|
|
|
switch (p_compress_mode) {
|
|
switch (p_compress_mode) {
|
|
case COMPRESS_LOSSLESS: {
|
|
case COMPRESS_LOSSLESS: {
|
|
@@ -99,7 +204,7 @@ void ResourceImporterTexture::_save_stex(const Image& p_image,const String& p_to
|
|
|
|
|
|
int mmc = image.get_mipmap_count() + 1;
|
|
int mmc = image.get_mipmap_count() + 1;
|
|
|
|
|
|
- format=StreamTexture::FORMAT_BIT_LOSSLESS;
|
|
|
|
|
|
+ format|=StreamTexture::FORMAT_BIT_LOSSLESS;
|
|
f->store_32(format);
|
|
f->store_32(format);
|
|
f->store_32(mmc);
|
|
f->store_32(mmc);
|
|
|
|
|
|
@@ -130,7 +235,7 @@ void ResourceImporterTexture::_save_stex(const Image& p_image,const String& p_to
|
|
|
|
|
|
int mmc = image.get_mipmap_count() + 1;
|
|
int mmc = image.get_mipmap_count() + 1;
|
|
|
|
|
|
- format=StreamTexture::FORMAT_BIT_LOSSY;
|
|
|
|
|
|
+ format|=StreamTexture::FORMAT_BIT_LOSSY;
|
|
f->store_32(format);
|
|
f->store_32(format);
|
|
f->store_32(mmc);
|
|
f->store_32(mmc);
|
|
|
|
|
|
@@ -162,7 +267,6 @@ void ResourceImporterTexture::_save_stex(const Image& p_image,const String& p_to
|
|
PoolVector<uint8_t> data=image.get_data();
|
|
PoolVector<uint8_t> data=image.get_data();
|
|
int dl = data.size();
|
|
int dl = data.size();
|
|
PoolVector<uint8_t>::Read r = data.read();
|
|
PoolVector<uint8_t>::Read r = data.read();
|
|
-
|
|
|
|
f->store_buffer(r.ptr(),dl);
|
|
f->store_buffer(r.ptr(),dl);
|
|
|
|
|
|
} break;
|
|
} break;
|
|
@@ -198,7 +302,7 @@ Error ResourceImporterTexture::import(const String& p_source_file, const String&
|
|
bool filter= p_options["flags/filter"];
|
|
bool filter= p_options["flags/filter"];
|
|
bool mipmaps= p_options["flags/mipmaps"];
|
|
bool mipmaps= p_options["flags/mipmaps"];
|
|
bool anisotropic= p_options["flags/anisotropic"];
|
|
bool anisotropic= p_options["flags/anisotropic"];
|
|
- bool srgb= p_options["flags/srgb"];
|
|
|
|
|
|
+ int srgb= p_options["flags/srgb"];
|
|
bool fix_alpha_border= p_options["process/fix_alpha_border"];
|
|
bool fix_alpha_border= p_options["process/fix_alpha_border"];
|
|
bool premult_alpha= p_options["process/premult_alpha"];
|
|
bool premult_alpha= p_options["process/premult_alpha"];
|
|
bool stream = p_options["stream"];
|
|
bool stream = p_options["stream"];
|
|
@@ -222,7 +326,7 @@ Error ResourceImporterTexture::import(const String& p_source_file, const String&
|
|
tex_flags|=Texture::FLAG_MIPMAPS;
|
|
tex_flags|=Texture::FLAG_MIPMAPS;
|
|
if (anisotropic)
|
|
if (anisotropic)
|
|
tex_flags|=Texture::FLAG_ANISOTROPIC_FILTER;
|
|
tex_flags|=Texture::FLAG_ANISOTROPIC_FILTER;
|
|
- if (srgb)
|
|
|
|
|
|
+ if (srgb==1)
|
|
tex_flags|=Texture::FLAG_CONVERT_TO_LINEAR;
|
|
tex_flags|=Texture::FLAG_CONVERT_TO_LINEAR;
|
|
|
|
|
|
if (size_limit >0 && (image.get_width()>size_limit || image.get_height()>size_limit )) {
|
|
if (size_limit >0 && (image.get_width()>size_limit || image.get_height()>size_limit )) {
|
|
@@ -249,26 +353,41 @@ Error ResourceImporterTexture::import(const String& p_source_file, const String&
|
|
image.premultiply_alpha();
|
|
image.premultiply_alpha();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ bool detect_3d = p_options["detect_3d"];
|
|
|
|
+ bool detect_srgb = srgb==2;
|
|
|
|
|
|
if (compress_mode==COMPRESS_VIDEO_RAM) {
|
|
if (compress_mode==COMPRESS_VIDEO_RAM) {
|
|
//must import in all formats
|
|
//must import in all formats
|
|
//Android, GLES 2.x
|
|
//Android, GLES 2.x
|
|
- _save_stex(image,p_save_path+".etc.stex",compress_mode,lossy,Image::COMPRESS_ETC,mipmaps,tex_flags,stream);
|
|
|
|
|
|
+ _save_stex(image,p_save_path+".etc.stex",compress_mode,lossy,Image::COMPRESS_ETC,mipmaps,tex_flags,stream,detect_3d,detect_srgb);
|
|
r_platform_variants->push_back("etc");
|
|
r_platform_variants->push_back("etc");
|
|
//_save_stex(image,p_save_path+".etc2.stex",compress_mode,lossy,Image::COMPRESS_ETC2,mipmaps,tex_flags,stream);
|
|
//_save_stex(image,p_save_path+".etc2.stex",compress_mode,lossy,Image::COMPRESS_ETC2,mipmaps,tex_flags,stream);
|
|
//r_platform_variants->push_back("etc2");
|
|
//r_platform_variants->push_back("etc2");
|
|
- _save_stex(image,p_save_path+".s3tc.stex",compress_mode,lossy,Image::COMPRESS_S3TC,mipmaps,tex_flags,stream);
|
|
|
|
|
|
+ _save_stex(image,p_save_path+".s3tc.stex",compress_mode,lossy,Image::COMPRESS_S3TC,mipmaps,tex_flags,stream,detect_3d,detect_srgb);
|
|
r_platform_variants->push_back("s3tc");
|
|
r_platform_variants->push_back("s3tc");
|
|
|
|
|
|
} else {
|
|
} else {
|
|
//import normally
|
|
//import normally
|
|
- _save_stex(image,p_save_path+".stex",compress_mode,lossy,Image::COMPRESS_16BIT /*this is ignored */,mipmaps,tex_flags,stream);
|
|
|
|
|
|
+ _save_stex(image,p_save_path+".stex",compress_mode,lossy,Image::COMPRESS_16BIT /*this is ignored */,mipmaps,tex_flags,stream,detect_3d,detect_srgb);
|
|
}
|
|
}
|
|
|
|
|
|
return OK;
|
|
return OK;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ResourceImporterTexture *ResourceImporterTexture::singleton=NULL;
|
|
|
|
+
|
|
ResourceImporterTexture::ResourceImporterTexture()
|
|
ResourceImporterTexture::ResourceImporterTexture()
|
|
{
|
|
{
|
|
|
|
|
|
|
|
+ singleton=this;
|
|
|
|
+ StreamTexture::request_3d_callback=_texture_reimport_3d;
|
|
|
|
+ StreamTexture::request_srgb_callback=_texture_reimport_srgb;
|
|
|
|
+ mutex = Mutex::create();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ResourceImporterTexture::~ResourceImporterTexture()
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+ memdelete(mutex);
|
|
|
|
+}
|
|
|
|
+
|