summaryrefslogtreecommitdiff
path: root/editor/import/resource_importer_texture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/import/resource_importer_texture.cpp')
-rw-r--r--editor/import/resource_importer_texture.cpp51
1 files changed, 15 insertions, 36 deletions
diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp
index 111eab78b4..a13324f0fc 100644
--- a/editor/import/resource_importer_texture.cpp
+++ b/editor/import/resource_importer_texture.cpp
@@ -37,7 +37,6 @@
#include "editor/editor_node.h"
void ResourceImporterTexture::_texture_reimport_roughness(const Ref<StreamTexture2D> &p_tex, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_channel) {
-
MutexLock lock(singleton->mutex);
StringName path = p_tex->get_path();
@@ -52,7 +51,6 @@ void ResourceImporterTexture::_texture_reimport_roughness(const Ref<StreamTextur
}
void ResourceImporterTexture::_texture_reimport_3d(const Ref<StreamTexture2D> &p_tex) {
-
MutexLock lock(singleton->mutex);
StringName path = p_tex->get_path();
@@ -65,7 +63,6 @@ void ResourceImporterTexture::_texture_reimport_3d(const Ref<StreamTexture2D> &p
}
void ResourceImporterTexture::_texture_reimport_normal(const Ref<StreamTexture2D> &p_tex) {
-
MutexLock lock(singleton->mutex);
StringName path = p_tex->get_path();
@@ -78,7 +75,6 @@ void ResourceImporterTexture::_texture_reimport_normal(const Ref<StreamTexture2D
}
void ResourceImporterTexture::update_imports() {
-
if (EditorFileSystem::get_singleton()->is_scanning() || EditorFileSystem::get_singleton()->is_importing()) {
return; // do nothing for now
}
@@ -91,7 +87,6 @@ void ResourceImporterTexture::update_imports() {
}
for (Map<StringName, MakeInfo>::Element *E = make_flags.front(); E; E = E->next()) {
-
Ref<ConfigFile> cf;
cf.instance();
String src_path = String(E->key()) + ".import";
@@ -139,29 +134,26 @@ void ResourceImporterTexture::update_imports() {
}
String ResourceImporterTexture::get_importer_name() const {
-
return "texture";
}
String ResourceImporterTexture::get_visible_name() const {
-
return "Texture2D";
}
-void ResourceImporterTexture::get_recognized_extensions(List<String> *p_extensions) const {
+void ResourceImporterTexture::get_recognized_extensions(List<String> *p_extensions) const {
ImageLoader::get_recognized_extensions(p_extensions);
}
+
String ResourceImporterTexture::get_save_extension() const {
return "stex";
}
String ResourceImporterTexture::get_resource_type() const {
-
return "StreamTexture2D";
}
bool ResourceImporterTexture::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
-
if (p_option == "compress/lossy_quality") {
int compress_mode = int(p_options["compress/mode"]);
if (compress_mode != COMPRESS_LOSSY && compress_mode != COMPRESS_VRAM_COMPRESSED) {
@@ -191,8 +183,8 @@ bool ResourceImporterTexture::get_option_visibility(const String &p_option, cons
int ResourceImporterTexture::get_preset_count() const {
return 4;
}
-String ResourceImporterTexture::get_preset_name(int p_idx) const {
+String ResourceImporterTexture::get_preset_name(int p_idx) const {
static const char *preset_names[] = {
"2D, Detect 3D",
"2D",
@@ -204,7 +196,6 @@ String ResourceImporterTexture::get_preset_name(int p_idx) const {
}
void ResourceImporterTexture::get_import_options(List<ImportOption> *r_options, int p_preset) const {
-
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/mode", PROPERTY_HINT_ENUM, "Lossless,Lossy,VRAM Compressed,VRAM Uncompressed,Basis Universal", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), p_preset == PRESET_3D ? 2 : 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "compress/lossy_quality", PROPERTY_HINT_RANGE, "0,1,0.01"), 0.7));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/hdr_compression", PROPERTY_HINT_ENUM, "Disabled,Opaque Only,Always"), 1));
@@ -226,10 +217,8 @@ void ResourceImporterTexture::get_import_options(List<ImportOption> *r_options,
}
void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Ref<Image> &p_image, CompressMode p_compress_mode, Image::UsedChannels p_channels, Image::CompressMode p_compress_format, float p_lossy_quality) {
-
switch (p_compress_mode) {
case COMPRESS_LOSSLESS: {
-
f->store_32(StreamTexture2D::DATA_FORMAT_LOSSLESS);
f->store_16(p_image->get_width());
f->store_16(p_image->get_height());
@@ -237,7 +226,6 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Ref<Image
f->store_32(p_image->get_format());
for (int i = 0; i < p_image->get_mipmap_count() + 1; i++) {
-
Vector<uint8_t> data = Image::lossless_packer(p_image->get_image_from_mipmap(i));
int data_len = data.size();
f->store_32(data_len);
@@ -248,7 +236,6 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Ref<Image
} break;
case COMPRESS_LOSSY: {
-
f->store_32(StreamTexture2D::DATA_FORMAT_LOSSY);
f->store_16(p_image->get_width());
f->store_16(p_image->get_height());
@@ -256,7 +243,6 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Ref<Image
f->store_32(p_image->get_format());
for (int i = 0; i < p_image->get_mipmap_count() + 1; i++) {
-
Vector<uint8_t> data = Image::lossy_packer(p_image->get_image_from_mipmap(i), p_lossy_quality);
int data_len = data.size();
f->store_32(data_len);
@@ -266,7 +252,6 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Ref<Image
}
} break;
case COMPRESS_VRAM_COMPRESSED: {
-
Ref<Image> image = p_image->duplicate();
image->compress_from_channels(p_compress_format, p_channels, p_lossy_quality);
@@ -283,7 +268,6 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Ref<Image
f->store_buffer(r, dl);
} break;
case COMPRESS_VRAM_UNCOMPRESSED: {
-
f->store_32(StreamTexture2D::DATA_FORMAT_IMAGE);
f->store_16(p_image->get_width());
f->store_16(p_image->get_height());
@@ -298,7 +282,6 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Ref<Image
} break;
case COMPRESS_BASIS_UNIVERSAL: {
-
f->store_32(StreamTexture2D::DATA_FORMAT_BASIS_UNIVERSAL);
f->store_16(p_image->get_width());
f->store_16(p_image->get_height());
@@ -306,7 +289,6 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Ref<Image
f->store_32(p_image->get_format());
for (int i = 0; i < p_image->get_mipmap_count() + 1; i++) {
-
Vector<uint8_t> data = Image::basis_universal_packer(p_image->get_image_from_mipmap(i), p_channels);
int data_len = data.size();
f->store_32(data_len);
@@ -319,7 +301,6 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Ref<Image
}
void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String &p_to_path, CompressMode p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, bool p_streamable, bool p_detect_3d, bool p_detect_roughness, bool p_detect_normal, bool p_force_normal, bool p_srgb_friendly, bool p_force_po2_for_compressed, uint32_t p_limit_mipmap, const Ref<Image> &p_normal, Image::RoughnessChannel p_roughness_channel) {
-
FileAccess *f = FileAccess::open(p_to_path, FileAccess::WRITE);
f->store_8('G');
f->store_8('S');
@@ -333,16 +314,21 @@ void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String
f->store_32(p_image->get_height());
uint32_t flags = 0;
- if (p_streamable)
+ if (p_streamable) {
flags |= StreamTexture2D::FORMAT_BIT_STREAM;
- if (p_mipmaps)
+ }
+ if (p_mipmaps) {
flags |= StreamTexture2D::FORMAT_BIT_HAS_MIPMAPS; //mipmaps bit
- if (p_detect_3d)
+ }
+ if (p_detect_3d) {
flags |= StreamTexture2D::FORMAT_BIT_DETECT_3D;
- if (p_detect_roughness)
+ }
+ if (p_detect_roughness) {
flags |= StreamTexture2D::FORMAT_BIT_DETECT_ROUGNESS;
- if (p_detect_normal)
+ }
+ if (p_detect_normal) {
flags |= StreamTexture2D::FORMAT_BIT_DETECT_NORMAL;
+ }
f->store_32(flags);
f->store_32(p_limit_mipmap);
@@ -396,7 +382,6 @@ void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String
}
Error ResourceImporterTexture::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
-
CompressMode compress_mode = CompressMode(int(p_options["compress/mode"]));
float lossy = p_options["compress/lossy_quality"];
int pack_channels = p_options["compress/channel_pack"];
@@ -427,8 +412,9 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
Ref<Image> image;
image.instance();
Error err = ImageLoader::load_image(p_source_file, image, nullptr, hdr_as_srgb, scale);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
Array formats_imported;
@@ -440,7 +426,6 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
image->resize(new_width, new_height, Image::INTERPOLATE_CUBIC);
} else {
-
int new_height = size_limit;
int new_width = image->get_width() * new_height / image->get_height();
@@ -501,7 +486,6 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
bool has_alpha = image->detect_alpha() != Image::ALPHA_NONE;
if (is_hdr && can_compress_hdr) {
-
if (has_alpha) {
//can compress hdr, but hdr with alpha is not compressible
if (hdr_compression == 2) {
@@ -542,7 +526,6 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
}
if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc2")) {
-
_save_stex(image, p_save_path + ".etc2.stex", compress_mode, lossy, Image::COMPRESS_ETC2, mipmaps, stream, detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, true, mipmap_limit, normal_image, roughness_channel);
r_platform_variants->push_back("etc2");
formats_imported.push_back("etc2");
@@ -555,7 +538,6 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
}
if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_pvrtc")) {
-
_save_stex(image, p_save_path + ".pvrtc.stex", compress_mode, lossy, Image::COMPRESS_PVRTC4, mipmaps, stream, detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, true, mipmap_limit, normal_image, roughness_channel);
r_platform_variants->push_back("pvrtc");
formats_imported.push_back("pvrtc");
@@ -589,7 +571,6 @@ const char *ResourceImporterTexture::compression_formats[] = {
nullptr
};
String ResourceImporterTexture::get_import_settings_string() const {
-
String s;
int index = 0;
@@ -606,7 +587,6 @@ String ResourceImporterTexture::get_import_settings_string() const {
}
bool ResourceImporterTexture::are_import_settings_valid(const String &p_path) const {
-
//will become invalid if formats are missing to import
Dictionary metadata = ResourceFormatImporter::get_singleton()->get_resource_metadata(p_path);
@@ -644,7 +624,6 @@ bool ResourceImporterTexture::are_import_settings_valid(const String &p_path) co
ResourceImporterTexture *ResourceImporterTexture::singleton = nullptr;
ResourceImporterTexture::ResourceImporterTexture() {
-
singleton = this;
StreamTexture2D::request_3d_callback = _texture_reimport_3d;
StreamTexture2D::request_roughness_callback = _texture_reimport_roughness;