From 967b98008b7900cb9ffca6a88d0f1a4ca7c1ce31 Mon Sep 17 00:00:00 2001
From: Leon Styhre <leon@leonstyhre.com>
Date: Tue, 16 Aug 2022 21:04:39 +0200
Subject: [PATCH] Fixed an issue where raster graphic images could get scaled
 incorrectly.

---
 es-core/src/resources/TextureData.h       | 3 ++-
 es-core/src/resources/TextureResource.cpp | 4 +++-
 es-core/src/resources/TextureResource.h   | 7 ++++++-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/es-core/src/resources/TextureData.h b/es-core/src/resources/TextureData.h
index ed04e5d85..6a58d0aa9 100644
--- a/es-core/src/resources/TextureData.h
+++ b/es-core/src/resources/TextureData.h
@@ -65,8 +65,9 @@ public:
     void setForceRasterization(bool setting) { mForceRasterization = setting; }
 
     // Has the image been loaded but not yet been rasterized as the size was not known?
-    bool getPendingRasterization() { return mPendingRasterization; }
+    const bool getPendingRasterization() { return mPendingRasterization; }
 
+    const bool getScalable() { return mScalable; }
     std::vector<unsigned char>& getRawRGBAData() { return mDataRGBA; }
     std::string getTextureFilePath() { return mPath; }
     bool tiled() { return mTile; }
diff --git a/es-core/src/resources/TextureResource.cpp b/es-core/src/resources/TextureResource.cpp
index ccff36c39..3ac592166 100644
--- a/es-core/src/resources/TextureResource.cpp
+++ b/es-core/src/resources/TextureResource.cpp
@@ -200,7 +200,9 @@ void TextureResource::rasterizeAt(float width, float height)
         data = mTextureData;
     else
         data = sTextureDataManager.get(this);
-    mSourceSize = glm::vec2 {static_cast<float>(width), static_cast<float>(height)};
+
+    if (mTextureData && mTextureData.get()->getScalable())
+        mSourceSize = glm::vec2 {static_cast<float>(width), static_cast<float>(height)};
     data->setSourceSize(static_cast<float>(width), static_cast<float>(height));
     if (mForceLoad || mTextureData != nullptr)
         data->load();
diff --git a/es-core/src/resources/TextureResource.h b/es-core/src/resources/TextureResource.h
index aed214aed..d5760af00 100644
--- a/es-core/src/resources/TextureResource.h
+++ b/es-core/src/resources/TextureResource.h
@@ -41,11 +41,16 @@ public:
     std::vector<unsigned char> getRawRGBAData();
 
     // Has the image been loaded but not yet been rasterized as the size was not known?
-    bool getPendingRasterization() const
+    const bool getPendingRasterization() const
     {
         return (mTextureData != nullptr ? mTextureData->getPendingRasterization() : false);
     }
 
+    const bool getScalable() const
+    {
+        return (mTextureData != nullptr ? mTextureData->getScalable() : false);
+    }
+
     void setLinearMagnify(bool setting) { mTextureData->setLinearMagnify(setting); }
 
     std::string getTextureFilePath();