| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/io/file_access.h" |
| 34 |
#include "core/io/image.h" |
| 35 |
#include "core/io/resource_importer.h" |
| 36 |
#include "servers/rendering/rendering_server.h" |
| 37 |
|
| 38 |
class CompressedTexture2D; |
| 39 |
|
| 40 |
class ResourceImporterTexture : public ResourceImporter { |
| 41 |
GDCLASS(ResourceImporterTexture, ResourceImporter); |
| 42 |
|
| 43 |
public: |
| 44 |
enum CompressMode { |
| 45 |
COMPRESS_LOSSLESS, |
| 46 |
COMPRESS_LOSSY, |
| 47 |
COMPRESS_VRAM_COMPRESSED, |
| 48 |
COMPRESS_VRAM_UNCOMPRESSED, |
| 49 |
COMPRESS_BASIS_UNIVERSAL |
| 50 |
}; |
| 51 |
|
| 52 |
enum ChannelRemap { |
| 53 |
REMAP_R, |
| 54 |
REMAP_G, |
| 55 |
REMAP_B, |
| 56 |
REMAP_A, |
| 57 |
REMAP_INV_R, |
| 58 |
REMAP_INV_G, |
| 59 |
REMAP_INV_B, |
| 60 |
REMAP_INV_A, |
| 61 |
REMAP_UNUSED, |
| 62 |
REMAP_0, |
| 63 |
REMAP_1, |
| 64 |
}; |
| 65 |
|
| 66 |
protected: |
| 67 |
enum { |
| 68 |
MAKE_3D_FLAG = 1, |
| 69 |
MAKE_ROUGHNESS_FLAG = 2, |
| 70 |
MAKE_NORMAL_FLAG = 4 |
| 71 |
}; |
| 72 |
|
| 73 |
Mutex mutex; |
| 74 |
struct MakeInfo { |
| 75 |
int flags = 0; |
| 76 |
String normal_path_for_roughness; |
| 77 |
RS::TextureDetectRoughnessChannel channel_for_roughness = RS::TEXTURE_DETECT_ROUGHNESS_R; |
| 78 |
}; |
| 79 |
|
| 80 |
HashMap<StringName, MakeInfo> make_flags; |
| 81 |
|
| 82 |
static void _texture_reimport_roughness(const Ref<CompressedTexture2D> &p_tex, const String &p_normal_path, RenderingServer::TextureDetectRoughnessChannel p_channel); |
| 83 |
static void _texture_reimport_3d(const Ref<CompressedTexture2D> &p_tex); |
| 84 |
static void _texture_reimport_normal(const Ref<CompressedTexture2D> &p_tex); |
| 85 |
|
| 86 |
static ResourceImporterTexture *singleton; |
| 87 |
static const char *compression_formats[]; |
| 88 |
|
| 89 |
void _save_ctex(const Ref<Image> &p_image, const String &p_to_path, CompressMode p_compress_mode, float p_lossy_quality, const Image::BasisUniversalPackerParams &p_basisu_params, Image::CompressMode p_vram_compression, bool p_mipmaps, bool p_streamable, bool p_detect_3d, bool p_detect_srgb, 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); |
| 90 |
void _save_editor_meta(const Dictionary &p_metadata, const String &p_to_path); |
| 91 |
Dictionary _load_editor_meta(const String &p_to_path) const; |
| 92 |
|
| 93 |
static inline void _remap_channels(Ref<Image> &r_image, ChannelRemap p_options[4]); |
| 94 |
static inline void _clamp_hdr_exposure(Ref<Image> &r_image); |
| 95 |
static inline void _invert_y_channel(Ref<Image> &r_image); |
| 96 |
|
| 97 |
public: |
| 98 |
static void save_to_ctex_format(Ref<FileAccess> f, const Ref<Image> &p_image, CompressMode p_compress_mode, Image::UsedChannels p_channels, Image::CompressMode p_compress_format, float p_lossy_quality, const Image::BasisUniversalPackerParams &p_basisu_params); |
| 99 |
|
| 100 |
static ResourceImporterTexture *get_singleton() { return singleton; } |
| 101 |
virtual String get_importer_name() const override; |
| 102 |
virtual String get_visible_name() const override; |
| 103 |
virtual void get_recognized_extensions(List<String> *p_extensions) const override; |
| 104 |
virtual String get_save_extension() const override; |
| 105 |
virtual String get_resource_type() const override; |
| 106 |
|
| 107 |
enum Preset { |
| 108 |
PRESET_DETECT, |
| 109 |
PRESET_2D, |
| 110 |
PRESET_3D, |
| 111 |
}; |
| 112 |
|
| 113 |
virtual int get_preset_count() const override; |
| 114 |
virtual String get_preset_name(int p_idx) const override; |
| 115 |
|
| 116 |
virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override; |
| 117 |
virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override; |
| 118 |
|
| 119 |
virtual Error import(ResourceUID::ID p_source_id, const String &p_source_file, const String &p_save_path, const HashMap<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override; |
| 120 |
|
| 121 |
virtual bool can_import_threaded() const override { return true; } |
| 122 |
|
| 123 |
void update_imports(); |
| 124 |
|
| 125 |
virtual bool are_import_settings_valid(const String &p_path, const Dictionary &p_meta) const override; |
| 126 |
virtual String get_import_settings_string() const override; |
| 127 |
|
| 128 |
ResourceImporterTexture(bool p_singleton = false); |
| 129 |
~ResourceImporterTexture(); |
| 130 |
}; |