Image.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #ifndef ANKI_RESOURCE_IMAGE_H
  2. #define ANKI_RESOURCE_IMAGE_H
  3. #include "anki/util/Functions.h"
  4. #include "anki/util/Vector.h"
  5. #include <iosfwd>
  6. #include <cstdint>
  7. #include <limits>
  8. namespace anki {
  9. /// Image class.
  10. /// Used in Texture::load. Supported types: TGA and PNG
  11. class Image
  12. {
  13. public:
  14. /// Texture type
  15. enum TextureType
  16. {
  17. TT_NONE,
  18. TT_2D,
  19. TT_CUBE,
  20. TT_3D,
  21. TT_2D_ARRAY
  22. };
  23. /// The acceptable color types of AnKi
  24. enum ColorFormat
  25. {
  26. CF_NONE,
  27. CF_RGB8, ///< RGB
  28. CF_RGBA8 ///< RGB plus alpha
  29. };
  30. /// The data compression
  31. enum DataCompression
  32. {
  33. DC_NONE,
  34. DC_RAW = 1 << 0,
  35. DC_S3TC = 1 << 1,
  36. DC_ETC = 1 << 2
  37. };
  38. /// An image surface
  39. struct Surface
  40. {
  41. U32 width;
  42. U32 height;
  43. U32 mipLevel;
  44. Vector<U8> data;
  45. };
  46. /// Do nothing
  47. Image()
  48. {}
  49. /// Do nothing
  50. ~Image()
  51. {}
  52. /// @name Accessors
  53. /// @{
  54. ColorFormat getColorFormat() const
  55. {
  56. ANKI_ASSERT(colorFormat != CF_NONE);
  57. return colorFormat;
  58. }
  59. DataCompression getCompression() const
  60. {
  61. ANKI_ASSERT(compression != DC_NONE);
  62. return compression;
  63. }
  64. U getMipLevelsCount() const
  65. {
  66. ANKI_ASSERT(mipLevels != 0);
  67. return mipLevels;
  68. }
  69. U getDepth() const
  70. {
  71. ANKI_ASSERT(depth != 0);
  72. return depth;
  73. }
  74. TextureType getTextureType() const
  75. {
  76. ANKI_ASSERT(textureType != TT_NONE);
  77. return textureType;
  78. }
  79. const Surface& getSurface(U mipLevel, U layer) const;
  80. /// @}
  81. /// Load an image file
  82. /// @param[in] filename The file to load
  83. /// @param[in] maxTextureSize Only load mipmaps less or equal to that. Used
  84. /// with AnKi textures
  85. void load(const char* filename,
  86. U32 maxTextureSize = std::numeric_limits<U32>::max());
  87. /// Load an image file
  88. /// @param[in] filenames The 6 files to load
  89. void loadCube(const char* filenames[6]);
  90. private:
  91. /// [mip][depthFace]
  92. Vector<Surface> surfaces;
  93. U8 mipLevels = 0;
  94. U8 depth = 0;
  95. DataCompression compression = DC_NONE;
  96. ColorFormat colorFormat = CF_NONE;
  97. TextureType textureType = TT_NONE;
  98. };
  99. } // end namespace anki
  100. #endif