Some general code cleanup.

This commit is contained in:
Leon Styhre 2022-09-08 18:56:02 +02:00
parent a2769b98d4
commit 2742424ca2
5 changed files with 246 additions and 251 deletions

View file

@ -16,19 +16,6 @@
#include "utils/CImgUtil.h"
#include "utils/StringUtil.h"
glm::ivec2 ImageComponent::getTextureSize() const
{
if (mTexture)
return mTexture->getSize();
else
return glm::ivec2 {0, 0};
}
glm::vec2 ImageComponent::getSize() const
{
return GuiComponent::getSize() * (mBottomRightCrop - mTopLeftCrop);
}
ImageComponent::ImageComponent(bool forceLoad, bool dynamic)
: mRenderer {Renderer::getInstance()}
, mTargetSize {0, 0}
@ -58,80 +45,6 @@ ImageComponent::ImageComponent(bool forceLoad, bool dynamic)
updateColors();
}
void ImageComponent::resize(bool rasterize)
{
if (!mTexture)
return;
const glm::vec2 textureSize {mTexture->getSourceImageSize()};
if (textureSize == glm::vec2 {0.0f, 0.0f})
return;
if (mTexture->isTiled()) {
mSize = mTargetSize;
}
else {
if (mTargetIsMax) {
// Maintain image aspect ratio.
mSize = textureSize;
glm::vec2 resizeScale {mTargetSize.x / mSize.x, mTargetSize.y / mSize.y};
if (resizeScale.x < resizeScale.y) {
// SVG rasterization is determined by height and rasterization is done in terms of
// pixels. If rounding is off enough in the rasterization step (for images with
// extreme aspect ratios), it can cause cutoff when the aspect ratio breaks.
// So we always make sure to round accordingly to avoid such issues.
mSize.x *= resizeScale.x;
mSize.y = floorf(std::min(mSize.y * resizeScale.x, mTargetSize.y));
}
else {
// This will be mTargetSize.y(). We can't exceed it.
mSize.y *= resizeScale.y;
mSize.x = std::min((mSize.y / textureSize.y) * textureSize.x, mTargetSize.x);
}
}
else {
// If both axes are set we just stretch or squash, if no axes are set we do nothing.
mSize = mTargetSize == glm::vec2 {0.0f, 0.0f} ? textureSize : mTargetSize;
// If only one axis is set, we resize in a way that maintains aspect ratio.
if (!mTargetSize.x && mTargetSize.y) {
mSize.y = mTargetSize.y;
mSize.x = (mSize.y / textureSize.y) * textureSize.x;
}
else if (mTargetSize.x && !mTargetSize.y) {
mSize.y = (mTargetSize.x / textureSize.x) * textureSize.y;
mSize.x = (mSize.y / textureSize.y) * textureSize.x;
}
}
}
// Make sure sub-pixel values are not rounded to zero and that the size is not unreasonably
// large (which may be caused by a mistake in the theme configuration).
mSize.x = glm::clamp(mSize.x, 1.0f, mRenderer->getScreenWidth() * 3.0f);
mSize.y = glm::clamp(mSize.y, 1.0f, mRenderer->getScreenHeight() * 3.0f);
if (rasterize) {
mTexture->rasterizeAt(mSize.x, mSize.y);
onSizeChanged();
}
}
void ImageComponent::setTileAxes()
{
if (mTileWidth == 0.0f && mTileHeight == 0.0f) {
mTileWidth = static_cast<float>(mTexture->getSize().x);
mTileHeight = static_cast<float>(mTexture->getSize().y);
return;
}
const float ratio {mTexture->getSourceImageSize().x / mTexture->getSourceImageSize().y};
if (mTileWidth == 0.0f)
mTileWidth = std::round(mTileHeight * ratio);
else if (mTileHeight == 0.0f)
mTileHeight = std::round(mTileWidth / ratio);
}
void ImageComponent::setImage(const std::string& path, bool tile)
{
// Always load bundled graphic resources statically, unless mForceLoad has been set.
@ -320,18 +233,6 @@ void ImageComponent::cropTransparentPadding(const float maxSizeX, const float ma
updateVertices();
}
void ImageComponent::setFlipX(bool flip)
{
mFlipX = flip;
updateVertices();
}
void ImageComponent::setFlipY(bool flip)
{
mFlipY = flip;
updateVertices();
}
void ImageComponent::setColorShift(unsigned int color)
{
mColorShift = color;
@ -397,89 +298,29 @@ void ImageComponent::setClipRegion(const glm::vec4& clipRegion)
mVertices[3].clipregion = clipRegion;
}
void ImageComponent::updateVertices()
void ImageComponent::setFlipX(bool state)
{
if (!mTexture)
return;
const glm::vec2 topLeft {0.0f, 0.0f};
const glm::vec2 bottomRight {mSize};
const float px {mTexture->isTiled() ? mSize.x / getTextureSize().x : 1.0f};
const float py {mTexture->isTiled() ? mSize.y / getTextureSize().y : 1.0f};
if (mTileHeight == 0.0f) {
// clang-format off
mVertices[0] = {{topLeft.x, topLeft.y }, {mTopLeftCrop.x, py - mTopLeftCrop.y }, 0};
mVertices[1] = {{topLeft.x, bottomRight.y}, {mTopLeftCrop.x, 1.0f - mBottomRightCrop.y}, 0};
mVertices[2] = {{bottomRight.x, topLeft.y }, {mBottomRightCrop.x * px, py - mTopLeftCrop.y }, 0};
mVertices[3] = {{bottomRight.x, bottomRight.y}, {mBottomRightCrop.x * px, 1.0f - mBottomRightCrop.y}, 0};
// clang-format on
}
else {
// Resize and align tiled textures.
glm::vec2 topLeftAlign {mTopLeftCrop};
glm::vec2 bottomRightAlign {mBottomRightCrop};
const float pxA {mSize.x / mTileWidth};
const float pyA {mSize.y / mTileHeight};
if (mTileHorizontalAlignment == Alignment::ALIGN_RIGHT) {
float offsetX {pxA - std::floor(pxA)};
if (offsetX != 0.0f) {
const float moveX {(mTileWidth * offsetX) / mSize.x};
topLeftAlign.x -= moveX * pxA;
bottomRightAlign.x -= moveX;
}
}
if (mTileVerticalAlignment == Alignment::ALIGN_TOP) {
float offsetY {pyA - std::floor(pyA)};
if (offsetY != 0.0f) {
const float moveY {(mTileHeight * offsetY) / mSize.y};
topLeftAlign.y += moveY * pyA;
bottomRightAlign.y += moveY * pyA;
}
}
// clang-format off
mVertices[0] = {{topLeft.x, topLeft.y }, {topLeftAlign.x, pyA - topLeftAlign.y }, 0};
mVertices[1] = {{topLeft.x, bottomRight.y}, {topLeftAlign.x, 1.0f - bottomRightAlign.y}, 0};
mVertices[2] = {{bottomRight.x, topLeft.y }, {bottomRightAlign.x * pxA, pyA - topLeftAlign.y }, 0};
mVertices[3] = {{bottomRight.x, bottomRight.y}, {bottomRightAlign.x * pxA, 1.0f - bottomRightAlign.y}, 0};
// clang-format on
}
updateColors();
// We round the vertices already here in this component as we may otherwise end up with edge
// cases at sizes near 0.5.
for (int i = 0; i < 4; ++i)
mVertices[i].position = glm::round(mVertices[i].position);
if (mFlipX) {
for (int i = 0; i < 4; ++i)
mVertices[i].texcoord[0] = px - mVertices[i].texcoord[0];
}
if (mFlipY) {
for (int i = 0; i < 4; ++i)
mVertices[i].texcoord[1] = py - mVertices[i].texcoord[1];
}
setClipRegion(mClipRegion);
mFlipX = state;
updateVertices();
}
void ImageComponent::updateColors()
void ImageComponent::setFlipY(bool state)
{
const float opacity {mOpacity * (mFading ? mFadeOpacity : 1.0f)};
const unsigned int color {(mColorShift & 0xFFFFFF00) |
static_cast<unsigned char>((mColorShift & 0xFF) * opacity)};
const unsigned int colorEnd {(mColorShiftEnd & 0xFFFFFF00) |
static_cast<unsigned char>((mColorShiftEnd & 0xFF) * opacity)};
mFlipY = state;
updateVertices();
}
mVertices[0].color = color;
mVertices[1].color = mColorGradientHorizontal ? color : colorEnd;
mVertices[2].color = mColorGradientHorizontal ? colorEnd : color;
mVertices[3].color = colorEnd;
glm::ivec2 ImageComponent::getTextureSize() const
{
if (mTexture)
return mTexture->getSize();
else
return glm::ivec2 {0, 0};
}
glm::vec2 ImageComponent::getSize() const
{
return GuiComponent::getSize() * (mBottomRightCrop - mTopLeftCrop);
}
void ImageComponent::render(const glm::mat4& parentTrans)
@ -543,36 +384,6 @@ void ImageComponent::render(const glm::mat4& parentTrans)
GuiComponent::renderChildren(trans);
}
void ImageComponent::fadeIn(bool textureLoaded)
{
if (!mForceLoad) {
if (!textureLoaded) {
// Start the fade if this is the first time we've encountered the unloaded texture.
if (!mFading) {
// Start with a zero opacity and flag it as fading.
mFadeOpacity = 0.0f;
mFading = true;
updateColors();
}
}
else if (mFading) {
// The texture is loaded and we need to fade it in. The fade is based on the frame
// rate and is 1/4 second if running at 60 frames per second although the actual
// value is not that important.
float opacity {mFadeOpacity + 1.0f / 15.0f};
// See if we've finished fading.
if (opacity >= 1.0f) {
mFadeOpacity = 1.0f;
mFading = false;
}
else {
mFadeOpacity = opacity;
}
updateColors();
}
}
}
void ImageComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
const std::string& view,
const std::string& element,
@ -779,3 +590,192 @@ std::vector<HelpPrompt> ImageComponent::getHelpPrompts()
ret.push_back(HelpPrompt("a", "select"));
return ret;
}
void ImageComponent::resize(bool rasterize)
{
if (!mTexture)
return;
const glm::vec2 textureSize {mTexture->getSourceImageSize()};
if (textureSize == glm::vec2 {0.0f, 0.0f})
return;
if (mTexture->isTiled()) {
mSize = mTargetSize;
}
else {
if (mTargetIsMax) {
// Maintain image aspect ratio.
mSize = textureSize;
glm::vec2 resizeScale {mTargetSize.x / mSize.x, mTargetSize.y / mSize.y};
if (resizeScale.x < resizeScale.y) {
// SVG rasterization is determined by height and rasterization is done in terms of
// pixels. If rounding is off enough in the rasterization step (for images with
// extreme aspect ratios), it can cause cutoff when the aspect ratio breaks.
// So we always make sure to round accordingly to avoid such issues.
mSize.x *= resizeScale.x;
mSize.y = floorf(std::min(mSize.y * resizeScale.x, mTargetSize.y));
}
else {
// This will be mTargetSize.y(). We can't exceed it.
mSize.y *= resizeScale.y;
mSize.x = std::min((mSize.y / textureSize.y) * textureSize.x, mTargetSize.x);
}
}
else {
// If both axes are set we just stretch or squash, if no axes are set we do nothing.
mSize = mTargetSize == glm::vec2 {0.0f, 0.0f} ? textureSize : mTargetSize;
// If only one axis is set, we resize in a way that maintains aspect ratio.
if (!mTargetSize.x && mTargetSize.y) {
mSize.y = mTargetSize.y;
mSize.x = (mSize.y / textureSize.y) * textureSize.x;
}
else if (mTargetSize.x && !mTargetSize.y) {
mSize.y = (mTargetSize.x / textureSize.x) * textureSize.y;
mSize.x = (mSize.y / textureSize.y) * textureSize.x;
}
}
}
// Make sure sub-pixel values are not rounded to zero and that the size is not unreasonably
// large (which may be caused by a mistake in the theme configuration).
mSize.x = glm::clamp(mSize.x, 1.0f, mRenderer->getScreenWidth() * 3.0f);
mSize.y = glm::clamp(mSize.y, 1.0f, mRenderer->getScreenHeight() * 3.0f);
if (rasterize) {
mTexture->rasterizeAt(mSize.x, mSize.y);
onSizeChanged();
}
}
void ImageComponent::setTileAxes()
{
if (mTileWidth == 0.0f && mTileHeight == 0.0f) {
mTileWidth = static_cast<float>(mTexture->getSize().x);
mTileHeight = static_cast<float>(mTexture->getSize().y);
return;
}
const float ratio {mTexture->getSourceImageSize().x / mTexture->getSourceImageSize().y};
if (mTileWidth == 0.0f)
mTileWidth = std::round(mTileHeight * ratio);
else if (mTileHeight == 0.0f)
mTileHeight = std::round(mTileWidth / ratio);
}
void ImageComponent::updateVertices()
{
if (!mTexture)
return;
const glm::vec2 topLeft {0.0f, 0.0f};
const glm::vec2 bottomRight {mSize};
const float px {mTexture->isTiled() ? mSize.x / getTextureSize().x : 1.0f};
const float py {mTexture->isTiled() ? mSize.y / getTextureSize().y : 1.0f};
if (mTileHeight == 0.0f) {
// clang-format off
mVertices[0] = {{topLeft.x, topLeft.y }, {mTopLeftCrop.x, py - mTopLeftCrop.y }, 0};
mVertices[1] = {{topLeft.x, bottomRight.y}, {mTopLeftCrop.x, 1.0f - mBottomRightCrop.y}, 0};
mVertices[2] = {{bottomRight.x, topLeft.y }, {mBottomRightCrop.x * px, py - mTopLeftCrop.y }, 0};
mVertices[3] = {{bottomRight.x, bottomRight.y}, {mBottomRightCrop.x * px, 1.0f - mBottomRightCrop.y}, 0};
// clang-format on
}
else {
// Resize and align tiled textures.
glm::vec2 topLeftAlign {mTopLeftCrop};
glm::vec2 bottomRightAlign {mBottomRightCrop};
const float pxA {mSize.x / mTileWidth};
const float pyA {mSize.y / mTileHeight};
if (mTileHorizontalAlignment == Alignment::ALIGN_RIGHT) {
float offsetX {pxA - std::floor(pxA)};
if (offsetX != 0.0f) {
const float moveX {(mTileWidth * offsetX) / mSize.x};
topLeftAlign.x -= moveX * pxA;
bottomRightAlign.x -= moveX;
}
}
if (mTileVerticalAlignment == Alignment::ALIGN_TOP) {
float offsetY {pyA - std::floor(pyA)};
if (offsetY != 0.0f) {
const float moveY {(mTileHeight * offsetY) / mSize.y};
topLeftAlign.y += moveY * pyA;
bottomRightAlign.y += moveY * pyA;
}
}
// clang-format off
mVertices[0] = {{topLeft.x, topLeft.y }, {topLeftAlign.x, pyA - topLeftAlign.y }, 0};
mVertices[1] = {{topLeft.x, bottomRight.y}, {topLeftAlign.x, 1.0f - bottomRightAlign.y}, 0};
mVertices[2] = {{bottomRight.x, topLeft.y }, {bottomRightAlign.x * pxA, pyA - topLeftAlign.y }, 0};
mVertices[3] = {{bottomRight.x, bottomRight.y}, {bottomRightAlign.x * pxA, 1.0f - bottomRightAlign.y}, 0};
// clang-format on
}
updateColors();
// We round the vertices already here in this component as we may otherwise end up with edge
// cases at sizes near 0.5.
for (int i = 0; i < 4; ++i)
mVertices[i].position = glm::round(mVertices[i].position);
if (mFlipX) {
for (int i = 0; i < 4; ++i)
mVertices[i].texcoord[0] = px - mVertices[i].texcoord[0];
}
if (mFlipY) {
for (int i = 0; i < 4; ++i)
mVertices[i].texcoord[1] = py - mVertices[i].texcoord[1];
}
setClipRegion(mClipRegion);
}
void ImageComponent::updateColors()
{
const float opacity {mOpacity * (mFading ? mFadeOpacity : 1.0f)};
const unsigned int color {(mColorShift & 0xFFFFFF00) |
static_cast<unsigned char>((mColorShift & 0xFF) * opacity)};
const unsigned int colorEnd {(mColorShiftEnd & 0xFFFFFF00) |
static_cast<unsigned char>((mColorShiftEnd & 0xFF) * opacity)};
mVertices[0].color = color;
mVertices[1].color = mColorGradientHorizontal ? color : colorEnd;
mVertices[2].color = mColorGradientHorizontal ? colorEnd : color;
mVertices[3].color = colorEnd;
}
void ImageComponent::fadeIn(bool textureLoaded)
{
if (!mForceLoad) {
if (!textureLoaded) {
// Start the fade if this is the first time we've encountered the unloaded texture.
if (!mFading) {
// Start with a zero opacity and flag it as fading.
mFadeOpacity = 0.0f;
mFading = true;
updateColors();
}
}
else if (mFading) {
// The texture is loaded and we need to fade it in. The fade is based on the frame
// rate and is 1/4 second if running at 60 frames per second although the actual
// value is not that important.
float opacity {mFadeOpacity + 1.0f / 15.0f};
// See if we've finished fading.
if (opacity >= 1.0f) {
mFadeOpacity = 1.0f;
mFading = false;
}
else {
mFadeOpacity = opacity;
}
updateColors();
}
}
}

View file

@ -85,8 +85,8 @@ public:
void setClipRegion(const glm::vec4& clipRegion);
void setReflectionsFalloff(float falloff) override { mReflectionsFalloff = falloff; }
void setFlipX(bool flip) override; // Mirror on the X axis.
void setFlipY(bool flip) override; // Mirror on the Y axis.
void setFlipX(bool state) override; // Mirror on the X axis.
void setFlipY(bool state) override; // Mirror on the Y axis.
// Flag indicating if rotation should be based on target size vs. actual size.
void setRotateByTargetSize(bool rotate) { mRotateByTargetSize = rotate; }

View file

@ -16,8 +16,6 @@
#include <fstream>
auto array_deleter = [](unsigned char* p) { delete[] p; };
ResourceManager& ResourceManager::getInstance()
{
static ResourceManager instance;
@ -30,33 +28,30 @@ std::string ResourceManager::getResourcePath(const std::string& path, bool termi
if ((path[0] == ':') && (path[1] == '/')) {
// Check under the home directory.
std::string testHome =
Utils::FileSystem::getHomePath() + "/.emulationstation/resources/" + &path[2];
std::string testHome {Utils::FileSystem::getHomePath() + "/.emulationstation/resources/" +
&path[2]};
if (Utils::FileSystem::exists(testHome))
return testHome;
#if defined(__APPLE__)
// For macOS, check in the ../Resources directory relative to the executable directory.
std::string applePackagePath =
Utils::FileSystem::getExePath() + "/../Resources/resources/" + &path[2];
std::string applePackagePath {Utils::FileSystem::getExePath() + "/../Resources/resources/" +
&path[2]};
if (Utils::FileSystem::exists(applePackagePath)) {
return applePackagePath;
}
#elif defined(__unix__) && !defined(APPIMAGE_BUILD)
// Check under the data installation directory (Unix only).
std::string testDataPath;
testDataPath = Utils::FileSystem::getProgramDataPath() + "/resources/" + &path[2];
std::string testDataPath {Utils::FileSystem::getProgramDataPath() + "/resources/" +
&path[2]};
if (Utils::FileSystem::exists(testDataPath)) {
return testDataPath;
}
#endif
// Check under the ES executable directory.
std::string testExePath = Utils::FileSystem::getExePath() + "/resources/" + &path[2];
std::string testExePath {Utils::FileSystem::getExePath() + "/resources/" + &path[2]};
if (Utils::FileSystem::exists(testExePath)) {
return testExePath;
@ -91,36 +86,37 @@ std::string ResourceManager::getResourcePath(const std::string& path, bool termi
const ResourceData ResourceManager::getFileData(const std::string& path) const
{
// Check if its a resource.
const std::string respath = getResourcePath(path);
const std::string respath {getResourcePath(path)};
if (Utils::FileSystem::exists(respath)) {
ResourceData data = loadFile(respath);
ResourceData data {loadFile(respath)};
return data;
}
// If the file doesn't exist, return an "empty" ResourceData.
ResourceData data = {nullptr, 0};
ResourceData data {nullptr, 0};
return data;
}
ResourceData ResourceManager::loadFile(const std::string& path) const
{
#if defined(_WIN64)
std::ifstream stream(Utils::String::stringToWideString(path).c_str(), std::ios::binary);
std::ifstream stream {Utils::String::stringToWideString(path).c_str(), std::ios::binary};
#else
std::ifstream stream(path, std::ios::binary);
std::ifstream stream {path, std::ios::binary};
#endif
stream.seekg(0, stream.end);
size_t size = static_cast<size_t>(stream.tellg());
size_t size {static_cast<size_t>(stream.tellg())};
stream.seekg(0, stream.beg);
// Supply custom deleter to properly free array.
std::shared_ptr<unsigned char> data(new unsigned char[size], array_deleter);
std::shared_ptr<unsigned char> data {new unsigned char[size],
[](unsigned char* p) { delete[] p; }};
stream.read(reinterpret_cast<char*>(data.get()), size);
stream.close();
ResourceData ret = {data, size};
ResourceData ret {data, size};
return ret;
}

View file

@ -27,7 +27,6 @@ TextureData::TextureData(bool tile)
: mRenderer {Renderer::getInstance()}
, mTile {tile}
, mTextureID {0}
, mDataRGBA {}
, mWidth {0}
, mHeight {0}
, mTileWidth {0.0f}
@ -159,8 +158,8 @@ bool TextureData::initImageFromMemory(const unsigned char* fileData, size_t leng
size_t width;
size_t height;
std::vector<unsigned char> imageRGBA = ImageIO::loadFromMemoryRGBA32(
static_cast<const unsigned char*>(fileData), length, width, height);
std::vector<unsigned char> imageRGBA {ImageIO::loadFromMemoryRGBA32(
static_cast<const unsigned char*>(fileData), length, width, height)};
if (imageRGBA.size() == 0) {
LOG(LogError) << "Couldn't initialize texture from memory, invalid data ("
@ -180,7 +179,7 @@ bool TextureData::initImageFromMemory(const unsigned char* fileData, size_t leng
bool TextureData::initFromRGBA(const unsigned char* dataRGBA, size_t width, size_t height)
{
// If already initialized then don't process it again.
std::unique_lock<std::mutex> lock(mMutex);
std::unique_lock<std::mutex> lock {mMutex};
if (!mDataRGBA.empty())
return true;
@ -197,7 +196,7 @@ bool TextureData::initFromRGBA(const unsigned char* dataRGBA, size_t width, size
bool TextureData::load()
{
bool retval = false;
bool retval {false};
// Need to load. See if there is a file.
if (!mPath.empty()) {
@ -219,7 +218,7 @@ bool TextureData::load()
bool TextureData::isLoaded()
{
std::unique_lock<std::mutex> lock(mMutex);
std::unique_lock<std::mutex> lock {mMutex};
if (!mDataRGBA.empty() || mTextureID != 0)
if (mHasRGBAData || mPendingRasterization || mTextureID != 0)
return true;
@ -230,7 +229,7 @@ bool TextureData::isLoaded()
bool TextureData::uploadAndBind()
{
// Check if it has already been uploaded.
std::unique_lock<std::mutex> lock(mMutex);
std::unique_lock<std::mutex> lock {mMutex};
if (mTextureID != 0) {
mRenderer->bindTexture(mTextureID);
}
@ -250,7 +249,7 @@ bool TextureData::uploadAndBind()
void TextureData::releaseVRAM()
{
std::unique_lock<std::mutex> lock(mMutex);
std::unique_lock<std::mutex> lock {mMutex};
if (mTextureID != 0) {
mRenderer->destroyTexture(mTextureID);
mTextureID = 0;
@ -259,9 +258,9 @@ void TextureData::releaseVRAM()
void TextureData::releaseRAM()
{
std::unique_lock<std::mutex> lock(mMutex);
std::vector<unsigned char> swapVector;
std::unique_lock<std::mutex> lock {mMutex};
if (!mDataRGBA.empty()) {
std::vector<unsigned char> swapVector;
mDataRGBA.clear();
mDataRGBA.swap(swapVector);
mHasRGBAData = false;
@ -317,7 +316,7 @@ size_t TextureData::getVRAMUsage()
if (mHasRGBAData || mTextureID != 0) {
// The estimated increase in VRAM usage with mipmapping enabled is 33%
if (mMipmapping)
return {static_cast<size_t>(static_cast<float>(mWidth * mHeight * 4) * 1.33f)};
return static_cast<size_t>(static_cast<float>(mWidth * mHeight * 4) * 1.33f);
else
return mWidth * mHeight * 4;
}

View file

@ -77,8 +77,8 @@ std::shared_ptr<TextureData> TextureDataManager::get(const TextureResource* key)
bool TextureDataManager::bind(const TextureResource* key)
{
std::shared_ptr<TextureData> tex = get(key);
bool bound = false;
std::shared_ptr<TextureData> tex {get(key)};
bool bound {false};
if (tex != nullptr)
bound = tex->uploadAndBind();
if (!bound)
@ -88,7 +88,7 @@ bool TextureDataManager::bind(const TextureResource* key)
size_t TextureDataManager::getTotalSize()
{
size_t total = 0;
size_t total {0};
for (auto tex : mTextures)
total += tex->width() * tex->height() * 4;
return total;
@ -96,7 +96,7 @@ size_t TextureDataManager::getTotalSize()
size_t TextureDataManager::getCommittedSize()
{
size_t total = 0;
size_t total {0};
for (auto tex : mTextures)
total += tex->getVRAMUsage();
return total;
@ -130,7 +130,7 @@ void TextureDataManager::load(std::shared_ptr<TextureData> tex, bool block)
settingVRAM = 1024;
}
size_t max_texture = settingVRAM * 1024 * 1024;
size_t max_texture {settingVRAM * 1024 * 1024};
for (auto it = mTextures.crbegin(); it != mTextures.crend(); ++it) {
if (size < max_texture)
@ -177,7 +177,7 @@ void TextureLoader::threadProc()
std::shared_ptr<TextureData> textureData;
{
// Wait for an event to say there is something in the queue.
std::unique_lock<std::mutex> lock(mMutex);
std::unique_lock<std::mutex> lock {mMutex};
mEvent.wait(lock);
if (!mTextureDataQ.empty()) {
textureData = mTextureDataQ.front();
@ -191,7 +191,7 @@ void TextureLoader::threadProc()
// See if there is another item in the queue.
textureData = nullptr;
std::unique_lock<std::mutex> lock(mMutex);
std::unique_lock<std::mutex> lock {mMutex};
if (!mTextureDataQ.empty()) {
textureData = mTextureDataQ.front();
mTextureDataQ.pop_front();
@ -205,7 +205,7 @@ void TextureLoader::load(std::shared_ptr<TextureData> textureData)
{
// Make sure it's not already loaded.
if (!textureData->isLoaded()) {
std::unique_lock<std::mutex> lock(mMutex);
std::unique_lock<std::mutex> lock {mMutex};
// Remove it from the queue if it is already there.
auto td = mTextureDataLookup.find(textureData.get());
if (td != mTextureDataLookup.cend()) {
@ -223,7 +223,7 @@ void TextureLoader::load(std::shared_ptr<TextureData> textureData)
void TextureLoader::remove(std::shared_ptr<TextureData> textureData)
{
// Just remove it from the queue so we don't attempt to load it.
std::unique_lock<std::mutex> lock(mMutex);
std::unique_lock<std::mutex> lock {mMutex};
auto td = mTextureDataLookup.find(textureData.get());
if (td != mTextureDataLookup.cend()) {
mTextureDataQ.erase((*td).second);
@ -235,8 +235,8 @@ size_t TextureLoader::getQueueSize()
{
// Get the amount of video memory that will be used once all textures in
// the queue are loaded.
size_t mem = 0;
std::unique_lock<std::mutex> lock(mMutex);
size_t mem {0};
std::unique_lock<std::mutex> lock {mMutex};
for (auto tex : mTextureDataQ)
mem += tex->width() * tex->height() * 4;