[colobot] 69/145: Fixed non-power-of-2 images in SatCom (closes #634); fixed not unloading textures on SatCom close

Didier Raboud odyx at moszumanska.debian.org
Mon Jul 11 12:56:18 UTC 2016


This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch debian/master
in repository colobot.

commit 952a5423fd598413fcae08e4f21a77c0e020e706
Author: krzys-h <krzys_h at interia.pl>
Date:   Sun Apr 10 13:53:34 2016 +0200

    Fixed non-power-of-2 images in SatCom (closes #634); fixed not unloading textures on SatCom close
---
 src/ui/controls/edit.cpp | 42 +++++++++++++++++++++++-------------------
 src/ui/controls/edit.h   |  1 -
 2 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/src/ui/controls/edit.cpp b/src/ui/controls/edit.cpp
index c881aa7..0cb3763 100644
--- a/src/ui/controls/edit.cpp
+++ b/src/ui/controls/edit.cpp
@@ -1127,25 +1127,41 @@ void CEdit::Draw()
 
 // Draw an image part.
 
+std::string PrepareImageFilename(std::string name)
+{
+    std::string filename;
+    filename = name + ".png";
+    filename = InjectLevelPathsForCurrentLevel(filename, "icons");
+    boost::replace_all(filename, "\\", "/"); // TODO: Fix this in files
+    return filename;
+}
+
 void CEdit::DrawImage(Math::Point pos, std::string name, float width,
                       float offset, float height, int nbLine)
 {
     Math::Point uv1, uv2, dim;
     float dp;
-    std::string filename;
-
-    filename = name + ".png";
-    filename = InjectLevelPathsForCurrentLevel(filename, "icons");
-    boost::replace_all(filename, "\\", "/"); //TODO: Fix this in files
 
-    m_engine->SetTexture(filename);
     m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
 
+    Gfx::TextureCreateParams params;
+    params.format = Gfx::TEX_IMG_AUTO;
+    params.filter = Gfx::TEX_FILTER_BILINEAR;
+    params.padToNearestPowerOfTwo = true;
+    Gfx::Texture tex = m_engine->LoadTexture(PrepareImageFilename(name), params);
+
+    m_engine->SetTexture(tex);
+
     uv1.x = 0.0f;
     uv2.x = 1.0f;
     uv1.y = offset;
     uv2.y = offset+height;
 
+    uv1.x *= static_cast<float>(tex.originalSize.x) / static_cast<float>(tex.size.x);
+    uv2.x *= static_cast<float>(tex.originalSize.x) / static_cast<float>(tex.size.x);
+    uv1.y *= static_cast<float>(tex.originalSize.y) / static_cast<float>(tex.size.y);
+    uv2.y *= static_cast<float>(tex.originalSize.y) / static_cast<float>(tex.size.y);
+
     dp = 0.5f/256.0f;
     uv1.x += dp;
     uv1.y += dp;
@@ -1415,21 +1431,10 @@ void CEdit::FreeImage()
 {
     for (auto& image : m_image)
     {
-        m_engine->DeleteTexture(image.name + ".png");
+        m_engine->DeleteTexture(PrepareImageFilename(image.name));
     }
 }
 
-// Reads the texture of an image.
-
-void CEdit::LoadImage(std::string name)
-{
-    std::string filename;
-    filename = name + ".png";
-    filename = InjectLevelPathsForCurrentLevel(filename, "icons");
-    boost::replace_all(filename, "\\", "/"); //TODO: Fix this in files
-    m_engine->LoadTexture(filename);
-}
-
 // Read from a text file.
 
 bool CEdit::ReadText(std::string filename, int addSize)
@@ -1632,7 +1637,6 @@ bool CEdit::ReadText(std::string filename, int addSize)
                 iWidth = static_cast<float>(GetValueParam(buffer.data()+i+7, 1));
                 iWidth *= m_engine->GetText()->GetHeight(Gfx::FONT_COLOBOT, Gfx::FONT_SIZE_SMALL);
                 iLines = GetValueParam(buffer.data()+i+7, 2);
-                LoadImage(std::string(iName));
 
                 // A part of image per line of text.
                 for ( iCount=0 ; iCount<iLines ; iCount++ )
diff --git a/src/ui/controls/edit.h b/src/ui/controls/edit.h
index 6418a19..bb7b5e3 100644
--- a/src/ui/controls/edit.h
+++ b/src/ui/controls/edit.h
@@ -201,7 +201,6 @@ protected:
     void        DrawColor(Math::Point pos, Math::Point dim, Gfx::Color color);
 
     void        FreeImage();
-    void        LoadImage(std::string name);
     void        Scroll(int pos, bool bAdjustCursor);
     void        Scroll();
     void        MoveChar(int move, bool bWord, bool bSelect);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git



More information about the Pkg-games-commits mailing list