diff --git a/src/WallpaperEngine/Assets/CContainer.cpp b/src/WallpaperEngine/Assets/CContainer.cpp index e8627a5..68030d6 100644 --- a/src/WallpaperEngine/Assets/CContainer.cpp +++ b/src/WallpaperEngine/Assets/CContainer.cpp @@ -22,7 +22,7 @@ const ITexture* CContainer::readTexture (const std::string& filename) const { const ITexture* result = new CTexture (textureContents); #if !NDEBUG - glObjectLabel (GL_TEXTURE, result->getTextureID (), -1, texture.c_str ()); + glObjectLabel (GL_TEXTURE, result->getTextureID (0), -1, texture.c_str ()); #endif /* NDEBUG */ delete textureContents; diff --git a/src/WallpaperEngine/Assets/CDirectory.cpp b/src/WallpaperEngine/Assets/CDirectory.cpp index 0199e2f..9cb6a68 100644 --- a/src/WallpaperEngine/Assets/CDirectory.cpp +++ b/src/WallpaperEngine/Assets/CDirectory.cpp @@ -1,99 +1,95 @@ -#include - -#include -#include - #include "CAssetLoadException.h" #include "CDirectory.h" using namespace WallpaperEngine::Assets; CDirectory::CDirectory (const std::filesystem::path& basepath) { - // ensure the specified path exists - struct stat buffer {}; + try { + // resolve the path to it's real location + std::filesystem::path finalpath = std::filesystem::canonical(basepath); + std::filesystem::file_status status = std::filesystem::status (finalpath); - // resolve the path to it's real location - char* finalpath = realpath (basepath.c_str (), nullptr); + if (!std::filesystem::exists (finalpath)) { + throw CAssetLoadException (basepath, "Cannot find directory"); + } - if (finalpath == nullptr) { - throw CAssetLoadException (basepath, "Cannot resolve to real path in the filesystem"); + if (!std::filesystem::is_directory(status)) { + throw CAssetLoadException (basepath, "Expected directory but found a file"); + } + + this->m_basepath = finalpath; + } catch (std::bad_alloc&) { + throw CAssetLoadException (basepath, "Cannot allocate memory"); + } catch (std::filesystem::filesystem_error& e) { + throw CAssetLoadException (basepath, e.what ()); } - - if (stat (finalpath, &buffer) != 0) { - throw CAssetLoadException (basepath, "Cannot find directory"); - } - - if (!S_ISDIR (buffer.st_mode)) { - throw CAssetLoadException (basepath, "Expected directory but found a file"); - } - - this->m_basepath = finalpath; - // the value returned from realpath has to be free'd - free (finalpath); } std::filesystem::path CDirectory::resolveRealFile (const std::string& filename) const { - return std::filesystem::path (this->m_basepath) / filename; + try { + std::filesystem::path path = this->m_basepath / filename; + std::filesystem::path final = std::filesystem::canonical (path); + + // first validate the path, so the message doesn't reflect if the file exists or not unless it's under the actual directory + if (this->m_basepath.string ().find (final.string ()) != 0) { + throw CAssetLoadException (filename, "File is not a child of the given directory"); + } + + std::filesystem::file_status status = std::filesystem::status (final); + + if (!std::filesystem::exists (final)) { + throw CAssetLoadException (filename, "Cannot find file"); + } + + if (!std::filesystem::is_regular_file (status)) { + throw CAssetLoadException (filename, "Expected file but found a directory"); + } + + return final; + } catch (std::filesystem::filesystem_error& e) { + throw CAssetLoadException (filename, e.what ()); + } } const uint8_t* CDirectory::readFile (const std::string& filename, uint32_t* length) const { - const std::filesystem::path final = std::filesystem::path (this->m_basepath) / filename; + try { + std::filesystem::path final = this->resolveRealFile (filename); - // resolve real path and ensure it's within the bounds - char* finalpath = realpath (final.c_str (), nullptr); + // first check the cache, if the file is there already just return the data in there + const auto it = this->m_cache.find (final); - if (finalpath == nullptr) { - throw CAssetLoadException (filename, "Cannot find file"); + if (it != this->m_cache.end ()) { + if (length != nullptr) + *length = it->second.length; + + return it->second.address; + } + + FILE* fp = fopen (final.c_str (), "rb"); + + if (fp == nullptr) { + throw CAssetLoadException (filename, "Cannot open file for reading"); + } + + // go to the end, get the position and return to the beginning + fseek (fp, 0, SEEK_END); + const long size = ftell (fp); + fseek (fp, 0, SEEK_SET); + + // now read the whole file + auto* contents = new uint8_t [size]; + + if (fread (contents, size, 1, fp) != 1) { + delete [] contents; + throw CAssetLoadException (filename, "Unexpected error when reading the file"); + } + + if (length != nullptr) { + *length = size; + } + + return contents; + } catch (std::filesystem::filesystem_error& e) { + throw CAssetLoadException (filename, e.what ()); } - - // ensure it's within the basepath - size_t baseLength = strlen (finalpath); - - if (baseLength < this->m_basepath.string ().size()) { - free (finalpath); - throw CAssetLoadException (filename, "File is not a child of the given directory"); - } - - if (strncmp (this->m_basepath.c_str (), finalpath, this->m_basepath.string ().size ()) != 0) { - free (finalpath); - throw CAssetLoadException (filename, "File is not a child of the given directory"); - } - - // first check the cache, if the file is there already just return the data in there - const auto it = this->m_cache.find (finalpath); - - if (it != this->m_cache.end ()) { - if (length != nullptr) - *length = it->second.length; - - return it->second.address; - } - - FILE* fp = fopen (finalpath, "rb"); - - if (fp == nullptr) { - free (finalpath); - throw CAssetLoadException (filename, "Cannot open file for reading"); - } - - // go to the end, get the position and return to the beginning - fseek (fp, 0, SEEK_END); - const long size = ftell (fp); - fseek (fp, 0, SEEK_SET); - - // now read the whole file - auto* contents = new uint8_t [size]; - - if (fread (contents, size, 1, fp) != 1) { - delete [] contents; - throw CAssetLoadException (filename, "Unexpected error when reading the file"); - } - - if (length != nullptr) { - *length = size; - } - - free (finalpath); - - return contents; } \ No newline at end of file diff --git a/src/WallpaperEngine/Assets/CDirectory.h b/src/WallpaperEngine/Assets/CDirectory.h index f53d543..c49581a 100644 --- a/src/WallpaperEngine/Assets/CDirectory.h +++ b/src/WallpaperEngine/Assets/CDirectory.h @@ -25,6 +25,6 @@ class CDirectory final : public CContainer { /** The basepath for the directory */ std::filesystem::path m_basepath; /** File cache to simplify access to data */ - std::map m_cache; + std::map m_cache; }; } // namespace WallpaperEngine::Assets \ No newline at end of file diff --git a/src/WallpaperEngine/Assets/CTexture.cpp b/src/WallpaperEngine/Assets/CTexture.cpp index ba22b10..b909a91 100644 --- a/src/WallpaperEngine/Assets/CTexture.cpp +++ b/src/WallpaperEngine/Assets/CTexture.cpp @@ -13,48 +13,8 @@ using namespace WallpaperEngine::Assets; CTexture::CTexture (const void* fileData) : m_resolution () { // ensure the header is parsed this->m_header = parseHeader (static_cast (fileData)); - - GLint internalFormat; - - if (this->isAnimated ()) { - this->m_resolution = {this->m_header->textureWidth, this->m_header->textureHeight, this->m_header->gifWidth, - this->m_header->gifHeight}; - } else { - if (this->m_header->freeImageFormat != FreeImageFormat::FIF_UNKNOWN) { - // wpengine-texture format always has one mipmap - // get first image size - auto element = this->m_header->images.find (0)->second.begin (); - - // set the texture resolution - this->m_resolution = {(*element)->width, (*element)->height, this->m_header->width, this->m_header->height}; - } else { - // set the texture resolution - this->m_resolution = {this->m_header->textureWidth, this->m_header->textureHeight, this->m_header->width, - this->m_header->height}; - } - } - - if (this->m_header->freeImageFormat != FreeImageFormat::FIF_UNKNOWN) { - internalFormat = GL_RGBA8; - // set some extra information too as it's used for image sizing - // this ensures that a_TexCoord uses the full image instead of just part of it - // TODO: MAYBE IT'S BETTER TO CREATE A TEXTURE OF THE GIVEN SIZE AND COPY OVER WHAT WE READ FROM THE FILE? - /*this->m_header->width = this->m_header->mipmaps [0]->width; - this->m_header->height = this->m_header->mipmaps [0]->height; - this->m_header->textureWidth = this->m_header->mipmaps [0]->width; - this->m_header->textureHeight = this->m_header->mipmaps [0]->height;*/ - } else { - // detect the image format and hand it to openGL to be used - switch (this->m_header->format) { - case TextureFormat::DXT5: internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break; - case TextureFormat::DXT3: internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break; - case TextureFormat::DXT1: internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break; - case TextureFormat::ARGB8888: internalFormat = GL_RGBA8; break; - case TextureFormat::R8: internalFormat = GL_R8; break; - case TextureFormat::RG88: internalFormat = GL_RG8; break; - default: delete this->m_header; sLog.exception ("Cannot determine texture format"); - } - } + this->setupResolution (); + GLint internalFormat = this->setupInternalFormat(); // allocate texture ids list this->m_textureID = new GLuint [this->m_header->imageCount]; @@ -65,31 +25,7 @@ CTexture::CTexture (const void* fileData) : m_resolution () { auto imgEnd = this->m_header->images.end (); for (int index = 0; imgCur != imgEnd; ++imgCur, index++) { - // bind the texture to assign information to it - glBindTexture (GL_TEXTURE_2D, this->m_textureID [index]); - - // set mipmap levels - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, this->m_header->mipmapCount - 1); - - // setup texture wrapping and filtering - if (this->m_header->flags & TextureFlags::ClampUVs) { - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - } else { - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - } - - if (this->m_header->flags & TextureFlags::NoInterpolation) { - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); - } else { - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - } - - glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY, 8.0f); + this->setupOpenGLParameters (index); auto cur = imgCur->second.begin (); auto end = imgCur->second.end (); @@ -146,6 +82,78 @@ CTexture::CTexture (const void* fileData) : m_resolution () { } } +void CTexture::setupResolution () { + if (this->isAnimated ()) { + this->m_resolution = {this->m_header->textureWidth, this->m_header->textureHeight, this->m_header->gifWidth, + this->m_header->gifHeight}; + } else { + if (this->m_header->freeImageFormat != FreeImageFormat::FIF_UNKNOWN) { + // wpengine-texture format always has one mipmap + // get first image size + auto element = this->m_header->images.find (0)->second.begin (); + + // set the texture resolution + this->m_resolution = {(*element)->width, (*element)->height, this->m_header->width, this->m_header->height}; + } else { + // set the texture resolution + this->m_resolution = {this->m_header->textureWidth, this->m_header->textureHeight, this->m_header->width, + this->m_header->height}; + } + } +} + +GLint CTexture::setupInternalFormat () { + if (this->m_header->freeImageFormat != FreeImageFormat::FIF_UNKNOWN) { + return GL_RGBA8; + // set some extra information too as it's used for image sizing + // this ensures that a_TexCoord uses the full image instead of just part of it + // TODO: MAYBE IT'S BETTER TO CREATE A TEXTURE OF THE GIVEN SIZE AND COPY OVER WHAT WE READ FROM THE FILE? + /*this->m_header->width = this->m_header->mipmaps [0]->width; + this->m_header->height = this->m_header->mipmaps [0]->height; + this->m_header->textureWidth = this->m_header->mipmaps [0]->width; + this->m_header->textureHeight = this->m_header->mipmaps [0]->height;*/ + } else { + // detect the image format and hand it to openGL to be used + switch (this->m_header->format) { + case TextureFormat::DXT5: return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break; + case TextureFormat::DXT3: return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break; + case TextureFormat::DXT1: return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break; + case TextureFormat::ARGB8888: return GL_RGBA8; break; + case TextureFormat::R8: return GL_R8; break; + case TextureFormat::RG88: return GL_RG8; break; + default: delete this->m_header; sLog.exception ("Cannot determine texture format"); + } + } +} + +void CTexture::setupOpenGLParameters (uint32_t textureID) { + // bind the texture to assign information to it + glBindTexture (GL_TEXTURE_2D, this->m_textureID [textureID]); + + // set mipmap levels + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, this->m_header->mipmapCount - 1); + + // setup texture wrapping and filtering + if (this->m_header->flags & TextureFlags::ClampUVs) { + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + } else { + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + } + + if (this->m_header->flags & TextureFlags::NoInterpolation) { + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); + } else { + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + } + + glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY, 8.0f); +} + CTexture::~CTexture () { if (this->getHeader () == nullptr) return; @@ -154,7 +162,7 @@ CTexture::~CTexture () { delete this->getHeader (); } -const GLuint CTexture::getTextureID (uint32_t imageIndex) const { +GLuint CTexture::getTextureID (uint32_t imageIndex) const { // ensure we do not go out of bounds if (imageIndex > this->m_header->imageCount) return this->m_textureID [0]; @@ -162,33 +170,33 @@ const GLuint CTexture::getTextureID (uint32_t imageIndex) const { return this->m_textureID [imageIndex]; } -const uint32_t CTexture::getTextureWidth (uint32_t imageIndex) const { +uint32_t CTexture::getTextureWidth (uint32_t imageIndex) const { if (imageIndex > this->m_header->imageCount) return this->getHeader ()->textureWidth; return (*this->m_header->images [imageIndex].begin ())->width; } -const uint32_t CTexture::getTextureHeight (uint32_t imageIndex) const { +uint32_t CTexture::getTextureHeight (uint32_t imageIndex) const { if (imageIndex > this->m_header->imageCount) return this->getHeader ()->textureHeight; return (*this->m_header->images [imageIndex].begin ())->height; } -const uint32_t CTexture::getRealWidth () const { +uint32_t CTexture::getRealWidth () const { return this->isAnimated () ? this->getHeader ()->gifWidth : this->getHeader ()->width; } -const uint32_t CTexture::getRealHeight () const { +uint32_t CTexture::getRealHeight () const { return this->isAnimated () ? this->getHeader ()->gifHeight : this->getHeader ()->height; } -const ITexture::TextureFormat CTexture::getFormat () const { +ITexture::TextureFormat CTexture::getFormat () const { return this->getHeader ()->format; } -const ITexture::TextureFlags CTexture::getFlags () const { +ITexture::TextureFlags CTexture::getFlags () const { return this->getHeader ()->flags; } @@ -204,7 +212,7 @@ const std::vector& CTexture::getFrames () const { return this->getHeader ()->frames; } -const bool CTexture::isAnimated () const { +bool CTexture::isAnimated () const { return this->getHeader ()->isAnimated (); } @@ -257,6 +265,9 @@ CTexture::TextureHeader::~TextureHeader () { for (const auto& [index, mipmaps] : this->images) for (const auto cur : mipmaps) delete cur; + + for (const auto& frame : this->frames) + delete frame; } CTexture::TextureHeader* CTexture::parseHeader (const char* fileData) { diff --git a/src/WallpaperEngine/Assets/CTexture.h b/src/WallpaperEngine/Assets/CTexture.h index 0f93292..1e6e6f1 100644 --- a/src/WallpaperEngine/Assets/CTexture.h +++ b/src/WallpaperEngine/Assets/CTexture.h @@ -156,25 +156,25 @@ class CTexture final : public ITexture { ~CTexture () override; /** @inheritdoc */ - [[nodiscard]] const GLuint getTextureID (uint32_t imageIndex = 0) const override; + [[nodiscard]] GLuint getTextureID (uint32_t imageIndex) const override; /** @inheritdoc */ - [[nodiscard]] const uint32_t getTextureWidth (uint32_t imageIndex = 0) const override; + [[nodiscard]] uint32_t getTextureWidth (uint32_t imageIndex) const override; /** @inheritdoc */ - [[nodiscard]] const uint32_t getTextureHeight (uint32_t imageIndex = 0) const override; + [[nodiscard]] uint32_t getTextureHeight (uint32_t imageIndex) const override; /** @inheritdoc */ - [[nodiscard]] const uint32_t getRealWidth () const override; + [[nodiscard]] uint32_t getRealWidth () const override; /** @inheritdoc */ - [[nodiscard]] const uint32_t getRealHeight () const override; + [[nodiscard]] uint32_t getRealHeight () const override; /** @inheritdoc */ - [[nodiscard]] const TextureFormat getFormat () const override; + [[nodiscard]] TextureFormat getFormat () const override; /** @inheritdoc */ - [[nodiscard]] const TextureFlags getFlags () const override; + [[nodiscard]] TextureFlags getFlags () const override; /** @inheritdoc */ [[nodiscard]] const glm::vec4* getResolution () const override; /** @inheritdoc */ [[nodiscard]] const std::vector& getFrames () const override; /** @inheritdoc */ - [[nodiscard]] const bool isAnimated () const override; + [[nodiscard]] bool isAnimated () const override; private: /** @@ -205,6 +205,19 @@ class CTexture final : public ITexture { */ static TextureMipmap* parseMipmap (const TextureHeader* header, const char** fileData); + /** + * Calculate's texture's resolution vec4 + */ + void setupResolution (); + /** + * Determines the texture's internal storage format + */ + GLint setupInternalFormat (); + /** + * Prepares openGL parameters for loading texture data + */ + void setupOpenGLParameters (uint32_t textureID); + /** The texture header */ TextureHeader* m_header; /** OpenGL's texture ID */ diff --git a/src/WallpaperEngine/Assets/ITexture.h b/src/WallpaperEngine/Assets/ITexture.h index 3131b43..4f57b9a 100644 --- a/src/WallpaperEngine/Assets/ITexture.h +++ b/src/WallpaperEngine/Assets/ITexture.h @@ -73,33 +73,33 @@ class ITexture { * @param imageIndex For animated textures, the frame to get the ID of * @return The OpenGL texture to use when rendering */ - [[nodiscard]] virtual const GLuint getTextureID (uint32_t imageIndex = 0) const = 0; + [[nodiscard]] virtual GLuint getTextureID (uint32_t imageIndex) const = 0; /** * @param imageIndex For animated textures, the frame to get the ID of * @return The texture's width */ - [[nodiscard]] virtual const uint32_t getTextureWidth (uint32_t imageIndex = 0) const = 0; + [[nodiscard]] virtual uint32_t getTextureWidth (uint32_t imageIndex) const = 0; /** * @param imageIndex For animated textures, the frame to get the ID of * @return The texture's height */ - [[nodiscard]] virtual const uint32_t getTextureHeight (uint32_t imageIndex = 0) const = 0; + [[nodiscard]] virtual uint32_t getTextureHeight (uint32_t imageIndex) const = 0; /** * @return The textures real width */ - [[nodiscard]] virtual const uint32_t getRealWidth () const = 0; + [[nodiscard]] virtual uint32_t getRealWidth () const = 0; /** * @return The textures real height */ - [[nodiscard]] virtual const uint32_t getRealHeight () const = 0; + [[nodiscard]] virtual uint32_t getRealHeight () const = 0; /** * @return The texture's memory format */ - [[nodiscard]] virtual const TextureFormat getFormat () const = 0; + [[nodiscard]] virtual TextureFormat getFormat () const = 0; /** * @return The texture's settings */ - [[nodiscard]] virtual const TextureFlags getFlags () const = 0; + [[nodiscard]] virtual TextureFlags getFlags () const = 0; /** * @return The list of frames this texture has */ @@ -111,6 +111,6 @@ class ITexture { /** * @return If the texture is animated or not */ - [[nodiscard]] virtual const bool isAnimated () const = 0; + [[nodiscard]] virtual bool isAnimated () const = 0; }; } // namespace WallpaperEngine::Assets \ No newline at end of file diff --git a/src/WallpaperEngine/Render/CFBO.cpp b/src/WallpaperEngine/Render/CFBO.cpp index 4361177..0e972ca 100644 --- a/src/WallpaperEngine/Render/CFBO.cpp +++ b/src/WallpaperEngine/Render/CFBO.cpp @@ -97,11 +97,11 @@ const float& CFBO::getScale () const { return this->m_scale; } -const ITexture::TextureFormat CFBO::getFormat () const { +ITexture::TextureFormat CFBO::getFormat () const { return this->m_format; } -const ITexture::TextureFlags CFBO::getFlags () const { +ITexture::TextureFlags CFBO::getFlags () const { return this->m_flags; } @@ -113,23 +113,23 @@ GLuint CFBO::getDepthbuffer () const { return this->m_depthbuffer; } -const GLuint CFBO::getTextureID (uint32_t imageIndex) const { +GLuint CFBO::getTextureID (uint32_t imageIndex) const { return this->m_texture; } -const uint32_t CFBO::getTextureWidth (uint32_t imageIndex) const { +uint32_t CFBO::getTextureWidth (uint32_t imageIndex) const { return this->m_resolution.x; } -const uint32_t CFBO::getTextureHeight (uint32_t imageIndex) const { +uint32_t CFBO::getTextureHeight (uint32_t imageIndex) const { return this->m_resolution.y; } -const uint32_t CFBO::getRealWidth () const { +uint32_t CFBO::getRealWidth () const { return this->m_resolution.z; } -const uint32_t CFBO::getRealHeight () const { +uint32_t CFBO::getRealHeight () const { return this->m_resolution.w; } @@ -141,6 +141,6 @@ const glm::vec4* CFBO::getResolution () const { return &this->m_resolution; } -const bool CFBO::isAnimated () const { +bool CFBO::isAnimated () const { return false; } \ No newline at end of file diff --git a/src/WallpaperEngine/Render/CFBO.h b/src/WallpaperEngine/Render/CFBO.h index 19be83b..3cd7944 100644 --- a/src/WallpaperEngine/Render/CFBO.h +++ b/src/WallpaperEngine/Render/CFBO.h @@ -15,20 +15,20 @@ class CFBO final : public ITexture { // TODO: ADD DESTRUCTOR TO FREE RESOURCES - const std::string& getName () const; - const float& getScale () const; - const ITexture::TextureFormat getFormat () const override; - const ITexture::TextureFlags getFlags () const override; - GLuint getFramebuffer () const; - GLuint getDepthbuffer () const; - const GLuint getTextureID (uint32_t imageIndex = 0) const override; - const uint32_t getTextureWidth (uint32_t imageIndex = 0) const override; - const uint32_t getTextureHeight (uint32_t imageIndex = 0) const override; - const uint32_t getRealWidth () const override; - const uint32_t getRealHeight () const override; - const std::vector& getFrames () const override; - const glm::vec4* getResolution () const override; - const bool isAnimated () const override; + [[nodiscard]] const std::string& getName () const; + [[nodiscard]] const float& getScale () const; + [[nodiscard]] ITexture::TextureFormat getFormat () const override; + [[nodiscard]] ITexture::TextureFlags getFlags () const override; + [[nodiscard]] GLuint getFramebuffer () const; + [[nodiscard]] GLuint getDepthbuffer () const; + [[nodiscard]] GLuint getTextureID (uint32_t imageIndex) const override; + [[nodiscard]] uint32_t getTextureWidth (uint32_t imageIndex) const override; + [[nodiscard]] uint32_t getTextureHeight (uint32_t imageIndex) const override; + [[nodiscard]] uint32_t getRealWidth () const override; + [[nodiscard]] uint32_t getRealHeight () const override; + [[nodiscard]] const std::vector& getFrames () const override; + [[nodiscard]] const glm::vec4* getResolution () const override; + [[nodiscard]] bool isAnimated () const override; private: GLuint m_framebuffer; diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index 08086f6..e711f43 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -121,14 +121,14 @@ CImage::CImage (Wallpapers::CScene* scene, Core::Objects::CImage* image) : if (this->getTexture ()->isAnimated ()) { // animated images use different coordinates as they're essentially a texture atlas width = static_cast (this->getTexture ()->getRealWidth ()) / - static_cast (this->getTexture ()->getTextureWidth ()); + static_cast (this->getTexture ()->getTextureWidth (0)); height = static_cast (this->getTexture ()->getRealHeight ()) / - static_cast (this->getTexture ()->getTextureHeight ()); + static_cast (this->getTexture ()->getTextureHeight (0)); } // calculate the correct texCoord limits for the texture based on the texture screen size and real size else if (this->getTexture () != nullptr && - (this->getTexture ()->getTextureWidth () != this->getTexture ()->getRealWidth () || - this->getTexture ()->getTextureHeight () != this->getTexture ()->getRealHeight ())) { + (this->getTexture ()->getTextureWidth (0) != this->getTexture ()->getRealWidth () || + this->getTexture ()->getTextureHeight (0) != this->getTexture ()->getRealHeight ())) { uint32_t x = 1; uint32_t y = 1;