| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- #pragma once
- #include "ITexture.h"
- #include <GL/glew.h>
- #include <glm/vec4.hpp>
- #include <map>
- #include <stdexcept>
- #include <string>
- #include <vector>
- namespace WallpaperEngine::Assets {
- /**
- * A normal texture file in WallpaperEngine's format
- */
- class CTexture final : public ITexture {
- /**
- * Different texture container versions supported
- */
- enum ContainerVersion : int {
- UNKNOWN = -1,
- TEXB0003 = 3,
- TEXB0002 = 2,
- TEXB0001 = 1
- };
- /**
- * Different texture animation versions supported
- */
- enum AnimatedVersion : int {
- TEXSUNKN = -1,
- TEXS0002 = 0,
- TEXS0003 = 1,
- };
- enum FreeImageFormat : int {
- FIF_UNKNOWN = -1,
- FIF_BMP = 0,
- FIF_ICO = 1,
- FIF_JPEG = 2,
- FIF_JNG = 3,
- FIF_KOALA = 4,
- FIF_LBM = 5,
- FIF_IFF = FIF_LBM,
- FIF_MNG = 6,
- FIF_PBM = 7,
- FIF_PBMRAW = 8,
- FIF_PCD = 9,
- FIF_PCX = 10,
- FIF_PGM = 11,
- FIF_PGMRAW = 12,
- FIF_PNG = 13,
- FIF_PPM = 14,
- FIF_PPMRAW = 15,
- FIF_RAS = 16,
- FIF_TARGA = 17,
- FIF_TIFF = 18,
- FIF_WBMP = 19,
- FIF_PSD = 20,
- FIF_CUT = 21,
- FIF_XBM = 22,
- FIF_XPM = 23,
- FIF_DDS = 24,
- FIF_GIF = 25,
- FIF_HDR = 26,
- FIF_FAXG3 = 27,
- FIF_SGI = 28,
- FIF_EXR = 29,
- FIF_J2K = 30,
- FIF_JP2 = 31,
- FIF_PFM = 32,
- FIF_PICT = 33,
- FIF_RAW = 34,
- FIF_WEBP = 35,
- FIF_JXR = 36
- };
- /**
- * Texture mipmap data
- */
- class TextureMipmap {
- public:
- TextureMipmap ();
- ~TextureMipmap ();
- /** Width of the mipmap */
- uint32_t width = 0;
- /** Height of the mipmap */
- uint32_t height = 0;
- /** If the mipmap data is compressed */
- uint32_t compression = 0;
- /** Uncompressed size of the mipmap */
- uint32_t uncompressedSize = 0;
- /** Compress size of the mipmap */
- uint32_t compressedSize = 0;
- /** Pointer to the compressed data */
- char* compressedData = nullptr;
- /** Pointer to the uncompressed data */
- char* uncompressedData = nullptr;
- /**
- * Performs actual decompression of the compressed data
- */
- void decompressData ();
- };
- /**
- * Texture header data
- */
- class TextureHeader {
- public:
- TextureHeader ();
- ~TextureHeader ();
- [[nodiscard]] bool isAnimated () const;
- /** The version of the texture container */
- ContainerVersion containerVersion = ContainerVersion::UNKNOWN;
- /** The version of the animated data */
- AnimatedVersion animatedVersion = AnimatedVersion::TEXSUNKN;
- /** Flags with extra texture information */
- TextureFlags flags;
- /** Real width of the texture */
- uint32_t width;
- /** Real height of the texture */
- uint32_t height;
- /** Texture width in memory (power of 2) */
- uint32_t textureWidth;
- /** Texture height in memory (power of 2) */
- uint32_t textureHeight;
- /** Gif width */
- uint32_t gifWidth;
- /** Gif height */
- uint32_t gifHeight;
- /** Texture data format */
- TextureFormat format;
- /** Free Image format */
- FreeImageFormat freeImageFormat = FreeImageFormat::FIF_UNKNOWN;
- /** The amount of images in the texture file */
- uint32_t imageCount;
- /** Number of mipmap levels on the texture */
- uint32_t mipmapCount;
- /** List of mipmaps */
- std::map<uint32_t, std::vector<TextureMipmap*>> images;
- /** List of animation frames */
- std::vector<TextureFrame*> frames;
- };
- public:
- explicit CTexture (const void* fileData);
- ~CTexture () override;
- /** @inheritdoc */
- [[nodiscard]] const GLuint getTextureID (uint32_t imageIndex = 0) const override;
- /** @inheritdoc */
- [[nodiscard]] const uint32_t getTextureWidth (uint32_t imageIndex = 0) const override;
- /** @inheritdoc */
- [[nodiscard]] const uint32_t getTextureHeight (uint32_t imageIndex = 0) const override;
- /** @inheritdoc */
- [[nodiscard]] const uint32_t getRealWidth () const override;
- /** @inheritdoc */
- [[nodiscard]] const uint32_t getRealHeight () const override;
- /** @inheritdoc */
- [[nodiscard]] const TextureFormat getFormat () const override;
- /** @inheritdoc */
- [[nodiscard]] const TextureFlags getFlags () const override;
- /** @inheritdoc */
- [[nodiscard]] const glm::vec4* getResolution () const override;
- /** @inheritdoc */
- [[nodiscard]] const std::vector<TextureFrame*>& getFrames () const override;
- /** @inheritdoc */
- [[nodiscard]] const bool isAnimated () const override;
- private:
- /**
- * @return The texture header
- */
- [[nodiscard]] const TextureHeader* getHeader () const;
- /**
- * Tries to parse a header off the given data pointer
- *
- * @param fileData The point at which to start reading data off from
- * @return
- */
- static TextureHeader* parseHeader (const char* fileData);
- /**
- * Tries to parse an animation frame off the given data pointer
- *
- * @param originalFileData The point at which to start reading data off from
- * @return
- */
- static TextureFrame* parseAnimation (const char** originalFileData);
- /**
- * Tries to parse mipmap information off the given data pointer
- *
- * @param header The file header
- * @param fileData The point at which to start reading data off from
- * @return
- */
- static TextureMipmap* parseMipmap (const TextureHeader* header, const char** fileData);
- /** The texture header */
- TextureHeader* m_header;
- /** OpenGL's texture ID */
- GLuint* m_textureID;
- /** Resolution vector of the texture */
- glm::vec4 m_resolution;
- };
- } // namespace WallpaperEngine::Assets
|