chore: make use of std::filesystem::canonical instead of basepath and slight typing changes on texture objects

This commit is contained in:
Almamu 2025-04-11 23:43:07 +02:00
parent d8ddc899fb
commit 079dbd6e74
9 changed files with 219 additions and 199 deletions

View File

@ -22,7 +22,7 @@ const ITexture* CContainer::readTexture (const std::string& filename) const {
const ITexture* result = new CTexture (textureContents); const ITexture* result = new CTexture (textureContents);
#if !NDEBUG #if !NDEBUG
glObjectLabel (GL_TEXTURE, result->getTextureID (), -1, texture.c_str ()); glObjectLabel (GL_TEXTURE, result->getTextureID (0), -1, texture.c_str ());
#endif /* NDEBUG */ #endif /* NDEBUG */
delete textureContents; delete textureContents;

View File

@ -1,99 +1,95 @@
#include <sys/stat.h>
#include <cstring>
#include <utility>
#include "CAssetLoadException.h" #include "CAssetLoadException.h"
#include "CDirectory.h" #include "CDirectory.h"
using namespace WallpaperEngine::Assets; using namespace WallpaperEngine::Assets;
CDirectory::CDirectory (const std::filesystem::path& basepath) { CDirectory::CDirectory (const std::filesystem::path& basepath) {
// ensure the specified path exists try {
struct stat buffer {}; // 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 if (!std::filesystem::exists (finalpath)) {
char* finalpath = realpath (basepath.c_str (), nullptr); throw CAssetLoadException (basepath, "Cannot find directory");
}
if (finalpath == nullptr) { if (!std::filesystem::is_directory(status)) {
throw CAssetLoadException (basepath, "Cannot resolve to real path in the filesystem"); 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 { 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 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 // first check the cache, if the file is there already just return the data in there
char* finalpath = realpath (final.c_str (), nullptr); const auto it = this->m_cache.find (final);
if (finalpath == nullptr) { if (it != this->m_cache.end ()) {
throw CAssetLoadException (filename, "Cannot find file"); 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;
} }

View File

@ -25,6 +25,6 @@ class CDirectory final : public CContainer {
/** The basepath for the directory */ /** The basepath for the directory */
std::filesystem::path m_basepath; std::filesystem::path m_basepath;
/** File cache to simplify access to data */ /** File cache to simplify access to data */
std::map<std::string, CFileEntry> m_cache; std::map<std::filesystem::path, CFileEntry> m_cache;
}; };
} // namespace WallpaperEngine::Assets } // namespace WallpaperEngine::Assets

View File

@ -13,48 +13,8 @@ using namespace WallpaperEngine::Assets;
CTexture::CTexture (const void* fileData) : m_resolution () { CTexture::CTexture (const void* fileData) : m_resolution () {
// ensure the header is parsed // ensure the header is parsed
this->m_header = parseHeader (static_cast<const char*> (fileData)); this->m_header = parseHeader (static_cast<const char*> (fileData));
this->setupResolution ();
GLint internalFormat; GLint internalFormat = this->setupInternalFormat();
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");
}
}
// allocate texture ids list // allocate texture ids list
this->m_textureID = new GLuint [this->m_header->imageCount]; 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 (); auto imgEnd = this->m_header->images.end ();
for (int index = 0; imgCur != imgEnd; ++imgCur, index++) { for (int index = 0; imgCur != imgEnd; ++imgCur, index++) {
// bind the texture to assign information to it this->setupOpenGLParameters (index);
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);
auto cur = imgCur->second.begin (); auto cur = imgCur->second.begin ();
auto end = imgCur->second.end (); 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 () { CTexture::~CTexture () {
if (this->getHeader () == nullptr) if (this->getHeader () == nullptr)
return; return;
@ -154,7 +162,7 @@ CTexture::~CTexture () {
delete this->getHeader (); 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 // ensure we do not go out of bounds
if (imageIndex > this->m_header->imageCount) if (imageIndex > this->m_header->imageCount)
return this->m_textureID [0]; return this->m_textureID [0];
@ -162,33 +170,33 @@ const GLuint CTexture::getTextureID (uint32_t imageIndex) const {
return this->m_textureID [imageIndex]; 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) if (imageIndex > this->m_header->imageCount)
return this->getHeader ()->textureWidth; return this->getHeader ()->textureWidth;
return (*this->m_header->images [imageIndex].begin ())->width; 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) if (imageIndex > this->m_header->imageCount)
return this->getHeader ()->textureHeight; return this->getHeader ()->textureHeight;
return (*this->m_header->images [imageIndex].begin ())->height; 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; 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; return this->isAnimated () ? this->getHeader ()->gifHeight : this->getHeader ()->height;
} }
const ITexture::TextureFormat CTexture::getFormat () const { ITexture::TextureFormat CTexture::getFormat () const {
return this->getHeader ()->format; return this->getHeader ()->format;
} }
const ITexture::TextureFlags CTexture::getFlags () const { ITexture::TextureFlags CTexture::getFlags () const {
return this->getHeader ()->flags; return this->getHeader ()->flags;
} }
@ -204,7 +212,7 @@ const std::vector<ITexture::TextureFrame*>& CTexture::getFrames () const {
return this->getHeader ()->frames; return this->getHeader ()->frames;
} }
const bool CTexture::isAnimated () const { bool CTexture::isAnimated () const {
return this->getHeader ()->isAnimated (); return this->getHeader ()->isAnimated ();
} }
@ -257,6 +265,9 @@ CTexture::TextureHeader::~TextureHeader () {
for (const auto& [index, mipmaps] : this->images) for (const auto& [index, mipmaps] : this->images)
for (const auto cur : mipmaps) for (const auto cur : mipmaps)
delete cur; delete cur;
for (const auto& frame : this->frames)
delete frame;
} }
CTexture::TextureHeader* CTexture::parseHeader (const char* fileData) { CTexture::TextureHeader* CTexture::parseHeader (const char* fileData) {

View File

@ -156,25 +156,25 @@ class CTexture final : public ITexture {
~CTexture () override; ~CTexture () override;
/** @inheritdoc */ /** @inheritdoc */
[[nodiscard]] const GLuint getTextureID (uint32_t imageIndex = 0) const override; [[nodiscard]] GLuint getTextureID (uint32_t imageIndex) const override;
/** @inheritdoc */ /** @inheritdoc */
[[nodiscard]] const uint32_t getTextureWidth (uint32_t imageIndex = 0) const override; [[nodiscard]] uint32_t getTextureWidth (uint32_t imageIndex) const override;
/** @inheritdoc */ /** @inheritdoc */
[[nodiscard]] const uint32_t getTextureHeight (uint32_t imageIndex = 0) const override; [[nodiscard]] uint32_t getTextureHeight (uint32_t imageIndex) const override;
/** @inheritdoc */ /** @inheritdoc */
[[nodiscard]] const uint32_t getRealWidth () const override; [[nodiscard]] uint32_t getRealWidth () const override;
/** @inheritdoc */ /** @inheritdoc */
[[nodiscard]] const uint32_t getRealHeight () const override; [[nodiscard]] uint32_t getRealHeight () const override;
/** @inheritdoc */ /** @inheritdoc */
[[nodiscard]] const TextureFormat getFormat () const override; [[nodiscard]] TextureFormat getFormat () const override;
/** @inheritdoc */ /** @inheritdoc */
[[nodiscard]] const TextureFlags getFlags () const override; [[nodiscard]] TextureFlags getFlags () const override;
/** @inheritdoc */ /** @inheritdoc */
[[nodiscard]] const glm::vec4* getResolution () const override; [[nodiscard]] const glm::vec4* getResolution () const override;
/** @inheritdoc */ /** @inheritdoc */
[[nodiscard]] const std::vector<TextureFrame*>& getFrames () const override; [[nodiscard]] const std::vector<TextureFrame*>& getFrames () const override;
/** @inheritdoc */ /** @inheritdoc */
[[nodiscard]] const bool isAnimated () const override; [[nodiscard]] bool isAnimated () const override;
private: private:
/** /**
@ -205,6 +205,19 @@ class CTexture final : public ITexture {
*/ */
static TextureMipmap* parseMipmap (const TextureHeader* header, const char** fileData); 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 */ /** The texture header */
TextureHeader* m_header; TextureHeader* m_header;
/** OpenGL's texture ID */ /** OpenGL's texture ID */

View File

@ -73,33 +73,33 @@ class ITexture {
* @param imageIndex For animated textures, the frame to get the ID of * @param imageIndex For animated textures, the frame to get the ID of
* @return The OpenGL texture to use when rendering * @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 * @param imageIndex For animated textures, the frame to get the ID of
* @return The texture's width * @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 * @param imageIndex For animated textures, the frame to get the ID of
* @return The texture's height * @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 * @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 * @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 * @return The texture's memory format
*/ */
[[nodiscard]] virtual const TextureFormat getFormat () const = 0; [[nodiscard]] virtual TextureFormat getFormat () const = 0;
/** /**
* @return The texture's settings * @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 * @return The list of frames this texture has
*/ */
@ -111,6 +111,6 @@ class ITexture {
/** /**
* @return If the texture is animated or not * @return If the texture is animated or not
*/ */
[[nodiscard]] virtual const bool isAnimated () const = 0; [[nodiscard]] virtual bool isAnimated () const = 0;
}; };
} // namespace WallpaperEngine::Assets } // namespace WallpaperEngine::Assets

View File

@ -97,11 +97,11 @@ const float& CFBO::getScale () const {
return this->m_scale; return this->m_scale;
} }
const ITexture::TextureFormat CFBO::getFormat () const { ITexture::TextureFormat CFBO::getFormat () const {
return this->m_format; return this->m_format;
} }
const ITexture::TextureFlags CFBO::getFlags () const { ITexture::TextureFlags CFBO::getFlags () const {
return this->m_flags; return this->m_flags;
} }
@ -113,23 +113,23 @@ GLuint CFBO::getDepthbuffer () const {
return this->m_depthbuffer; return this->m_depthbuffer;
} }
const GLuint CFBO::getTextureID (uint32_t imageIndex) const { GLuint CFBO::getTextureID (uint32_t imageIndex) const {
return this->m_texture; 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; 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; return this->m_resolution.y;
} }
const uint32_t CFBO::getRealWidth () const { uint32_t CFBO::getRealWidth () const {
return this->m_resolution.z; return this->m_resolution.z;
} }
const uint32_t CFBO::getRealHeight () const { uint32_t CFBO::getRealHeight () const {
return this->m_resolution.w; return this->m_resolution.w;
} }
@ -141,6 +141,6 @@ const glm::vec4* CFBO::getResolution () const {
return &this->m_resolution; return &this->m_resolution;
} }
const bool CFBO::isAnimated () const { bool CFBO::isAnimated () const {
return false; return false;
} }

View File

@ -15,20 +15,20 @@ class CFBO final : public ITexture {
// TODO: ADD DESTRUCTOR TO FREE RESOURCES // TODO: ADD DESTRUCTOR TO FREE RESOURCES
const std::string& getName () const; [[nodiscard]] const std::string& getName () const;
const float& getScale () const; [[nodiscard]] const float& getScale () const;
const ITexture::TextureFormat getFormat () const override; [[nodiscard]] ITexture::TextureFormat getFormat () const override;
const ITexture::TextureFlags getFlags () const override; [[nodiscard]] ITexture::TextureFlags getFlags () const override;
GLuint getFramebuffer () const; [[nodiscard]] GLuint getFramebuffer () const;
GLuint getDepthbuffer () const; [[nodiscard]] GLuint getDepthbuffer () const;
const GLuint getTextureID (uint32_t imageIndex = 0) const override; [[nodiscard]] GLuint getTextureID (uint32_t imageIndex) const override;
const uint32_t getTextureWidth (uint32_t imageIndex = 0) const override; [[nodiscard]] uint32_t getTextureWidth (uint32_t imageIndex) const override;
const uint32_t getTextureHeight (uint32_t imageIndex = 0) const override; [[nodiscard]] uint32_t getTextureHeight (uint32_t imageIndex) const override;
const uint32_t getRealWidth () const override; [[nodiscard]] uint32_t getRealWidth () const override;
const uint32_t getRealHeight () const override; [[nodiscard]] uint32_t getRealHeight () const override;
const std::vector<TextureFrame*>& getFrames () const override; [[nodiscard]] const std::vector<TextureFrame*>& getFrames () const override;
const glm::vec4* getResolution () const override; [[nodiscard]] const glm::vec4* getResolution () const override;
const bool isAnimated () const override; [[nodiscard]] bool isAnimated () const override;
private: private:
GLuint m_framebuffer; GLuint m_framebuffer;

View File

@ -121,14 +121,14 @@ CImage::CImage (Wallpapers::CScene* scene, Core::Objects::CImage* image) :
if (this->getTexture ()->isAnimated ()) { if (this->getTexture ()->isAnimated ()) {
// animated images use different coordinates as they're essentially a texture atlas // animated images use different coordinates as they're essentially a texture atlas
width = static_cast<float> (this->getTexture ()->getRealWidth ()) / width = static_cast<float> (this->getTexture ()->getRealWidth ()) /
static_cast<float> (this->getTexture ()->getTextureWidth ()); static_cast<float> (this->getTexture ()->getTextureWidth (0));
height = static_cast<float> (this->getTexture ()->getRealHeight ()) / height = static_cast<float> (this->getTexture ()->getRealHeight ()) /
static_cast<float> (this->getTexture ()->getTextureHeight ()); static_cast<float> (this->getTexture ()->getTextureHeight (0));
} }
// calculate the correct texCoord limits for the texture based on the texture screen size and real size // calculate the correct texCoord limits for the texture based on the texture screen size and real size
else if (this->getTexture () != nullptr && else if (this->getTexture () != nullptr &&
(this->getTexture ()->getTextureWidth () != this->getTexture ()->getRealWidth () || (this->getTexture ()->getTextureWidth (0) != this->getTexture ()->getRealWidth () ||
this->getTexture ()->getTextureHeight () != this->getTexture ()->getRealHeight ())) { this->getTexture ()->getTextureHeight (0) != this->getTexture ()->getRealHeight ())) {
uint32_t x = 1; uint32_t x = 1;
uint32_t y = 1; uint32_t y = 1;