CTexture.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #pragma once
  2. #include <string>
  3. #include <vector>
  4. #include <stdexcept>
  5. #include <GL/glew.h>
  6. #include <glm/vec4.hpp>
  7. #include <FreeImage.h>
  8. namespace WallpaperEngine::Assets
  9. {
  10. class CTexture
  11. {
  12. struct TextureHeader;
  13. public:
  14. CTexture (void* fileData);
  15. ~CTexture ();
  16. const GLuint getTextureID () const;
  17. const TextureHeader* getHeader () const;
  18. const glm::vec4* getResolution () const;
  19. enum TextureFormat : uint32_t
  20. {
  21. ARGB8888 = 0,
  22. DXT5 = 4,
  23. DXT3 = 6,
  24. DXT1 = 7,
  25. RG88 = 8,
  26. R8 = 9,
  27. };
  28. private:
  29. enum ContainerVersion : int
  30. {
  31. UNKNOWN = -1,
  32. TEXB0003 = 3,
  33. TEXB0002 = 2,
  34. TEXB0001 = 1
  35. };
  36. class TextureMipmap
  37. {
  38. public:
  39. TextureMipmap ();
  40. ~TextureMipmap ();
  41. /** Width of the mipmap */
  42. uint32_t width = 0;
  43. /** Height of the mipmap */
  44. uint32_t height = 0;
  45. /** If the mipmap data is compressed */
  46. uint32_t compression = 0;
  47. /** Uncompressed size of the mipmap */
  48. uint32_t uncompressedSize = 0;
  49. /** Compress size of the mipmap */
  50. uint32_t compressedSize = 0;
  51. /** Pointer to the compressed data */
  52. char* compressedData = nullptr;
  53. /** Pointer to the uncompressed data */
  54. char* uncompressedData = nullptr;
  55. /**
  56. * Performs actual decompression of the compressed data
  57. */
  58. void decompressData ();
  59. };
  60. /**
  61. * Configures how the texture will be handled by the background
  62. */
  63. enum TextureFlags : uint32_t
  64. {
  65. None = 0,
  66. NoInterpolation = 1,
  67. ClampUVs = 2,
  68. IsGif = 4,
  69. };
  70. class TextureHeader
  71. {
  72. public:
  73. TextureHeader ();
  74. ~TextureHeader ();
  75. /** The version of the texture container */
  76. ContainerVersion containerVersion = ContainerVersion::UNKNOWN;
  77. /** Flags with extra texture information */
  78. TextureFlags flags;
  79. /** Real width of the texture */
  80. uint32_t width;
  81. /** Real height of the texture */
  82. uint32_t height;
  83. /** Texture width in memory (power of 2) */
  84. uint32_t textureWidth;
  85. /** Texture height in memory (power of 2) */
  86. uint32_t textureHeight;
  87. /** Texture data format */
  88. TextureFormat format;
  89. /** Free Image format */
  90. FREE_IMAGE_FORMAT freeImageFormat = FREE_IMAGE_FORMAT::FIF_UNKNOWN;
  91. /** Number of mipmap levels on the texture */
  92. uint32_t mipmapCount;
  93. /** List of mipmaps */
  94. std::vector <TextureMipmap*> mipmaps;
  95. };
  96. private:
  97. void parseHeader (char* fileData);
  98. TextureMipmap* parseMipmap (TextureHeader* header, char** fileData);
  99. TextureHeader* m_header;
  100. GLuint m_textureID;
  101. glm::vec4 m_resolution;
  102. };
  103. }