CTexture.h 3.1 KB

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