Browse Source

Add functions for mipmap manipulation to Image.

Eugene Kozlov 9 years ago
parent
commit
d4039d5bc6
2 changed files with 35 additions and 0 deletions
  1. 29 0
      Source/Urho3D/Resource/Image.cpp
  2. 6 0
      Source/Urho3D/Resource/Image.h

+ 29 - 0
Source/Urho3D/Resource/Image.cpp

@@ -2029,6 +2029,35 @@ void Image::PrecalculateLevels()
     }
 }
 
+void Image::CleanupLevels()
+{
+    nextLevel_.Reset();
+}
+
+void Image::GetLevels(PODVector<Image*>& levels)
+{
+    levels.Clear();
+
+    Image* image = this;
+    while (image)
+    {
+        levels.Push(image);
+        image = image->nextLevel_;
+    }
+}
+
+void Image::GetLevels(PODVector<const Image*>& levels) const
+{
+    levels.Clear();
+
+    const Image* image = this;
+    while (image)
+    {
+        levels.Push(image);
+        image = image->nextLevel_;
+    }
+}
+
 unsigned char* Image::GetImageData(Deserializer& source, int& width, int& height, unsigned& components)
 {
     unsigned dataSize = source.GetSize();

+ 6 - 0
Source/Urho3D/Resource/Image.h

@@ -197,6 +197,12 @@ public:
     SDL_Surface* GetSDLSurface(const IntRect& rect = IntRect::ZERO) const;
     /// Precalculate the mip levels. Used by asynchronous texture loading.
     void PrecalculateLevels();
+    /// Clean up the mip levels.
+    void CleanupLevels();
+    /// Get all stored mip levels starting from this.
+    void GetLevels(PODVector<Image*>& levels);
+    /// Get all stored mip levels starting from this.
+    void GetLevels(PODVector<const Image*>& levels) const;
 
 private:
     /// Decode an image using stb_image.