Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Fix CompressedTexture2D mipmap reporting

Johanna Lindquistb27ecd7b21c9
diff --git a/scene/resources/compressed_texture.cpp b/scene/resources/compressed_texture.cpp
index 40f673f4edf..5db54a3f335 100644
--- a/scene/resources/compressed_texture.cpp
+++ b/scene/resources/compressed_texture.cpp
@@ -132,6 +132,14 @@ Image::Format CompressedTexture2D::get_format() const {
return format;
}
+int CompressedTexture2D::get_mipmap_count() const {
+ return mipmaps ? Image::get_image_required_mipmaps(w, h, format) : 0;
+}
+
+bool CompressedTexture2D::has_mipmaps() const {
+ return mipmaps;
+}
+
Error CompressedTexture2D::load(const String &p_path) {
int lw, lh;
Ref<Image> image;
@@ -158,6 +166,7 @@ Error CompressedTexture2D::load(const String &p_path) {
h = lh;
path_to_file = p_path;
format = image->get_format();
+ mipmaps = image->has_mipmaps();
if (get_path().is_empty()) {
//temporarily set path if no path set for resource, helps find errors
diff --git a/scene/resources/compressed_texture.h b/scene/resources/compressed_texture.h
index 099b09fbb26..688593b4bf7 100644
--- a/scene/resources/compressed_texture.h
+++ b/scene/resources/compressed_texture.h
@@ -64,6 +64,7 @@ private:
Image::Format format = Image::FORMAT_L8;
int w = 0;
int h = 0;
+ bool mipmaps = false;
mutable Ref<BitMap> alpha_cache;
Error _load_data(const String &p_path, int &r_width, int &r_height, Ref<Image> &image, bool &r_request_3d, bool &r_request_normal, bool &r_request_roughness, int &mipmap_limit);
@@ -87,6 +88,8 @@ public:
static TextureFormatRequestCallback request_normal_callback;
virtual Image::Format get_format() const override;
+ virtual int get_mipmap_count() const override;
+ virtual bool has_mipmaps() const override;
Error load(const String &p_path);
String get_load_path() const;