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;
|
mSourceHeight = svgImage->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
mWidth = static_cast<size_t>(std::round(mSourceWidth * mScaleDuringLoad));
|
mWidth = static_cast<size_t>(floorf(floorf(mSourceWidth) * mScaleDuringLoad));
|
||||||
mHeight = static_cast<size_t>(std::round(mSourceHeight * mScaleDuringLoad));
|
mHeight = static_cast<size_t>(floorf(floorf(mSourceHeight) * mScaleDuringLoad));
|
||||||
|
|
||||||
if (mWidth == 0) {
|
if (mWidth == 0) {
|
||||||
// Auto scale width to keep aspect ratio.
|
// Auto scale width to keep aspect ratio.
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
#ifndef ES_CORE_RESOURCES_TEXTURE_DATA_H
|
#ifndef ES_CORE_RESOURCES_TEXTURE_DATA_H
|
||||||
#define ES_CORE_RESOURCES_TEXTURE_DATA_H
|
#define ES_CORE_RESOURCES_TEXTURE_DATA_H
|
||||||
|
|
||||||
|
#include "utils/MathUtil.h"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -53,6 +55,7 @@ public:
|
||||||
float sourceWidth();
|
float sourceWidth();
|
||||||
float sourceHeight();
|
float sourceHeight();
|
||||||
void setSourceSize(float width, float height);
|
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).
|
// Define a factor for scaling the file when loading it (1.0f = no scaling).
|
||||||
void setScaleDuringLoad(float scale) { mScaleDuringLoad = scale; }
|
void setScaleDuringLoad(float scale) { mScaleDuringLoad = scale; }
|
||||||
|
|
|
@ -194,9 +194,14 @@ std::shared_ptr<TextureResource> TextureResource::get(const std::string& path,
|
||||||
return tex;
|
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)
|
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;
|
std::shared_ptr<TextureData> data;
|
||||||
if (mTextureData != nullptr)
|
if (mTextureData != nullptr)
|
||||||
data = mTextureData;
|
data = mTextureData;
|
||||||
|
|
Loading…
Reference in a new issue