ImageResource.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Resource/ResourceObject.h>
  7. #include <AnKi/Gr.h>
  8. namespace anki {
  9. /// @addtogroup resource
  10. /// @{
  11. ANKI_CVAR(NumericCVar<U32>, Rsrc, MaxImageSize, 1024u * 1024u, 4u, kMaxU32, "Max image size to load")
  12. /// Image resource class. It loads or creates an image and then loads it in the GPU. It supports compressed and uncompressed TGAs, PNGs, JPEG and
  13. /// AnKi's image format.
  14. class ImageResource : public ResourceObject
  15. {
  16. public:
  17. ImageResource(CString fname, U32 uuid)
  18. : ResourceObject(fname, uuid)
  19. {
  20. }
  21. ~ImageResource();
  22. /// Load an image.
  23. Error load(const ResourceFilename& filename, Bool async);
  24. /// Get the texture.
  25. Texture& getTexture() const
  26. {
  27. return *m_tex;
  28. }
  29. U32 getWidth() const
  30. {
  31. ANKI_ASSERT(m_size.x());
  32. return m_size.x();
  33. }
  34. U32 getHeight() const
  35. {
  36. ANKI_ASSERT(m_size.y());
  37. return m_size.y();
  38. }
  39. U32 getDepth() const
  40. {
  41. ANKI_ASSERT(m_size.z());
  42. return m_size.z();
  43. }
  44. U32 getLayerCount() const
  45. {
  46. ANKI_ASSERT(m_layerCount);
  47. return m_layerCount;
  48. }
  49. Vec4 getAverageColor() const
  50. {
  51. return m_avgColor;
  52. }
  53. private:
  54. static constexpr U32 kMaxCopiesBeforeFlush = 4;
  55. class TexUploadTask;
  56. class LoadingContext;
  57. TexturePtr m_tex;
  58. UVec3 m_size = UVec3(0u);
  59. U32 m_layerCount = 0;
  60. Vec4 m_avgColor = Vec4(0.0f);
  61. [[nodiscard]] static Error load(LoadingContext& ctx);
  62. };
  63. /// @}
  64. } // end namespace anki