mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 15:45:38 +00:00
Made an optimization for SVG graphics to avoid a lot of unnecessary re-rasterizations.
This commit is contained in:
parent
ba07a0b24c
commit
081fbc5665
|
@ -72,8 +72,8 @@ bool TextureData::initSVGFromMemory(const std::string& fileData)
|
|||
mSourceHeight = svgImage->height;
|
||||
}
|
||||
|
||||
mWidth = static_cast<size_t>(std::round(mSourceWidth * mScaleDuringLoad));
|
||||
mHeight = static_cast<size_t>(std::round(mSourceHeight * mScaleDuringLoad));
|
||||
mWidth = static_cast<size_t>(floorf(floorf(mSourceWidth) * mScaleDuringLoad));
|
||||
mHeight = static_cast<size_t>(floorf(floorf(mSourceHeight) * mScaleDuringLoad));
|
||||
|
||||
if (mWidth == 0) {
|
||||
// Auto scale width to keep aspect ratio.
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
#ifndef ES_CORE_RESOURCES_TEXTURE_DATA_H
|
||||
#define ES_CORE_RESOURCES_TEXTURE_DATA_H
|
||||
|
||||
#include "utils/MathUtil.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
@ -53,6 +55,7 @@ public:
|
|||
float sourceWidth();
|
||||
float sourceHeight();
|
||||
void setSourceSize(float width, float height);
|
||||
glm::vec2 getSize() { return glm::vec2{mWidth, mHeight}; }
|
||||
|
||||
// Define a factor for scaling the file when loading it (1.0f = no scaling).
|
||||
void setScaleDuringLoad(float scale) { mScaleDuringLoad = scale; }
|
||||
|
|
|
@ -194,9 +194,14 @@ std::shared_ptr<TextureResource> TextureResource::get(const std::string& path,
|
|||
return tex;
|
||||
}
|
||||
|
||||
// For scalable source images in textures we want to set the resolution to rasterize at.
|
||||
void TextureResource::rasterizeAt(size_t width, size_t height)
|
||||
{
|
||||
if (mTextureData != nullptr) {
|
||||
glm::vec2 textureSize = mTextureData.get()->getSize();
|
||||
if (textureSize.x == width && textureSize.y == height)
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<TextureData> data;
|
||||
if (mTextureData != nullptr)
|
||||
data = mTextureData;
|
||||
|
|
Loading…
Reference in a new issue