diff --git a/es-core/src/components/ImageComponent.cpp b/es-core/src/components/ImageComponent.cpp index a4c3c51d0..01a178136 100644 --- a/es-core/src/components/ImageComponent.cpp +++ b/es-core/src/components/ImageComponent.cpp @@ -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(mTexture->getSize().x); - mTileHeight = static_cast(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((mColorShift & 0xFF) * opacity)}; - const unsigned int colorEnd {(mColorShiftEnd & 0xFFFFFF00) | - static_cast((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& theme, const std::string& view, const std::string& element, @@ -779,3 +590,192 @@ std::vector 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(mTexture->getSize().x); + mTileHeight = static_cast(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((mColorShift & 0xFF) * opacity)}; + const unsigned int colorEnd {(mColorShiftEnd & 0xFFFFFF00) | + static_cast((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(); + } + } +} diff --git a/es-core/src/components/ImageComponent.h b/es-core/src/components/ImageComponent.h index fce79380a..e9401d5bc 100644 --- a/es-core/src/components/ImageComponent.h +++ b/es-core/src/components/ImageComponent.h @@ -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; } diff --git a/es-core/src/resources/ResourceManager.cpp b/es-core/src/resources/ResourceManager.cpp index 93a41be9e..b14e11a4f 100644 --- a/es-core/src/resources/ResourceManager.cpp +++ b/es-core/src/resources/ResourceManager.cpp @@ -16,8 +16,6 @@ #include -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(stream.tellg()); + size_t size {static_cast(stream.tellg())}; stream.seekg(0, stream.beg); // Supply custom deleter to properly free array. - std::shared_ptr data(new unsigned char[size], array_deleter); + std::shared_ptr data {new unsigned char[size], + [](unsigned char* p) { delete[] p; }}; stream.read(reinterpret_cast(data.get()), size); stream.close(); - ResourceData ret = {data, size}; + ResourceData ret {data, size}; return ret; } diff --git a/es-core/src/resources/TextureData.cpp b/es-core/src/resources/TextureData.cpp index fc7da571c..afad1fe2d 100644 --- a/es-core/src/resources/TextureData.cpp +++ b/es-core/src/resources/TextureData.cpp @@ -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 imageRGBA = ImageIO::loadFromMemoryRGBA32( - static_cast(fileData), length, width, height); + std::vector imageRGBA {ImageIO::loadFromMemoryRGBA32( + static_cast(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 lock(mMutex); + std::unique_lock 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 lock(mMutex); + std::unique_lock 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 lock(mMutex); + std::unique_lock lock {mMutex}; if (mTextureID != 0) { mRenderer->bindTexture(mTextureID); } @@ -250,7 +249,7 @@ bool TextureData::uploadAndBind() void TextureData::releaseVRAM() { - std::unique_lock lock(mMutex); + std::unique_lock lock {mMutex}; if (mTextureID != 0) { mRenderer->destroyTexture(mTextureID); mTextureID = 0; @@ -259,9 +258,9 @@ void TextureData::releaseVRAM() void TextureData::releaseRAM() { - std::unique_lock lock(mMutex); - std::vector swapVector; + std::unique_lock lock {mMutex}; if (!mDataRGBA.empty()) { + std::vector 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(static_cast(mWidth * mHeight * 4) * 1.33f)}; + return static_cast(static_cast(mWidth * mHeight * 4) * 1.33f); else return mWidth * mHeight * 4; } diff --git a/es-core/src/resources/TextureDataManager.cpp b/es-core/src/resources/TextureDataManager.cpp index b0dd8ac07..aff76e7f0 100644 --- a/es-core/src/resources/TextureDataManager.cpp +++ b/es-core/src/resources/TextureDataManager.cpp @@ -77,8 +77,8 @@ std::shared_ptr TextureDataManager::get(const TextureResource* key) bool TextureDataManager::bind(const TextureResource* key) { - std::shared_ptr tex = get(key); - bool bound = false; + std::shared_ptr 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 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; { // Wait for an event to say there is something in the queue. - std::unique_lock lock(mMutex); + std::unique_lock 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 lock(mMutex); + std::unique_lock lock {mMutex}; if (!mTextureDataQ.empty()) { textureData = mTextureDataQ.front(); mTextureDataQ.pop_front(); @@ -205,7 +205,7 @@ void TextureLoader::load(std::shared_ptr textureData) { // Make sure it's not already loaded. if (!textureData->isLoaded()) { - std::unique_lock lock(mMutex); + std::unique_lock 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) void TextureLoader::remove(std::shared_ptr textureData) { // Just remove it from the queue so we don't attempt to load it. - std::unique_lock lock(mMutex); + std::unique_lock 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 lock(mMutex); + size_t mem {0}; + std::unique_lock lock {mMutex}; for (auto tex : mTextureDataQ) mem += tex->width() * tex->height() * 4;