| 1 | /**************************************************************************/ |
| 2 | /* resource_importer_layered_texture.h */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #ifndef RESOURCE_IMPORTER_LAYERED_TEXTURE_H |
| 32 | #define RESOURCE_IMPORTER_LAYERED_TEXTURE_H |
| 33 | |
| 34 | #include "core/io/image.h" |
| 35 | #include "core/io/resource_importer.h" |
| 36 | #include "core/object/ref_counted.h" |
| 37 | |
| 38 | class CompressedTexture2D; |
| 39 | |
| 40 | class LayeredTextureImport : public RefCounted { |
| 41 | GDCLASS(LayeredTextureImport, RefCounted); |
| 42 | |
| 43 | public: |
| 44 | Image::CompressSource *csource = nullptr; |
| 45 | String save_path; |
| 46 | HashMap<StringName, Variant> options; |
| 47 | List<String> *platform_variants = nullptr; |
| 48 | Ref<Image> image = nullptr; |
| 49 | Array formats_imported; |
| 50 | Vector<Ref<Image>> *slices = nullptr; |
| 51 | int compress_mode = 0; |
| 52 | float lossy = 1.0; |
| 53 | int hdr_compression = 0; |
| 54 | bool mipmaps = true; |
| 55 | bool high_quality = false; |
| 56 | Image::UsedChannels used_channels = Image::USED_CHANNELS_RGBA; |
| 57 | virtual ~LayeredTextureImport() {} |
| 58 | }; |
| 59 | |
| 60 | class ResourceImporterLayeredTexture : public ResourceImporter { |
| 61 | GDCLASS(ResourceImporterLayeredTexture, ResourceImporter); |
| 62 | |
| 63 | public: |
| 64 | enum Mode { |
| 65 | MODE_2D_ARRAY, |
| 66 | MODE_CUBEMAP, |
| 67 | MODE_CUBEMAP_ARRAY, |
| 68 | MODE_3D, |
| 69 | }; |
| 70 | |
| 71 | enum CubemapFormat { |
| 72 | CUBEMAP_FORMAT_1X6, |
| 73 | CUBEMAP_FORMAT_2X3, |
| 74 | CUBEMAP_FORMAT_3X2, |
| 75 | CUBEMAP_FORMAT_6X1, |
| 76 | }; |
| 77 | |
| 78 | enum TextureFlags { |
| 79 | TEXTURE_FLAGS_MIPMAPS = 1 |
| 80 | }; |
| 81 | |
| 82 | private: |
| 83 | Mode mode; |
| 84 | static const char *compression_formats[]; |
| 85 | |
| 86 | protected: |
| 87 | static ResourceImporterLayeredTexture *singleton; |
| 88 | |
| 89 | public: |
| 90 | void _check_compress_ctex(const String &p_source_file, Ref<LayeredTextureImport> r_texture_import); |
| 91 | |
| 92 | static ResourceImporterLayeredTexture *get_singleton() { return singleton; } |
| 93 | virtual String get_importer_name() const override; |
| 94 | virtual String get_visible_name() const override; |
| 95 | virtual void get_recognized_extensions(List<String> *p_extensions) const override; |
| 96 | virtual String get_save_extension() const override; |
| 97 | virtual String get_resource_type() const override; |
| 98 | |
| 99 | enum CompressMode { |
| 100 | COMPRESS_LOSSLESS, |
| 101 | COMPRESS_LOSSY, |
| 102 | COMPRESS_VRAM_COMPRESSED, |
| 103 | COMPRESS_VRAM_UNCOMPRESSED, |
| 104 | COMPRESS_BASIS_UNIVERSAL |
| 105 | }; |
| 106 | |
| 107 | virtual int get_preset_count() const override; |
| 108 | virtual String get_preset_name(int p_idx) const override; |
| 109 | |
| 110 | virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override; |
| 111 | virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override; |
| 112 | |
| 113 | void _save_tex(Vector<Ref<Image>> p_images, const String &p_to_path, int p_compress_mode, float p_lossy, Image::CompressMode p_vram_compression, Image::CompressSource p_csource, Image::UsedChannels used_channels, bool p_mipmaps, bool p_force_po2); |
| 114 | |
| 115 | virtual Error import(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; |
| 116 | |
| 117 | virtual bool are_import_settings_valid(const String &p_path) const override; |
| 118 | virtual String get_import_settings_string() const override; |
| 119 | |
| 120 | void set_mode(Mode p_mode) { mode = p_mode; } |
| 121 | |
| 122 | ResourceImporterLayeredTexture(bool p_singleton = false); |
| 123 | ~ResourceImporterLayeredTexture(); |
| 124 | }; |
| 125 | |
| 126 | #endif // RESOURCE_IMPORTER_LAYERED_TEXTURE_H |
| 127 | |