ImageResource.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (C) 2009-2021, 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. /// Image resource class.
  12. ///
  13. /// It loads or creates an image and then loads it in the GPU. It supports compressed and uncompressed TGAs, PNGs, JPEG
  14. /// and AnKi's image format.
  15. class ImageResource : public ResourceObject
  16. {
  17. public:
  18. ImageResource(ResourceManager* manager)
  19. : ResourceObject(manager)
  20. {
  21. }
  22. ~ImageResource();
  23. /// Load an image.
  24. ANKI_USE_RESULT Error load(const ResourceFilename& filename, Bool async);
  25. /// Get the texture.
  26. const TexturePtr& getTexture() const
  27. {
  28. return m_tex;
  29. }
  30. /// Get the texture view.
  31. const TextureViewPtr& getTextureView() const
  32. {
  33. return m_texView;
  34. }
  35. U32 getWidth() const
  36. {
  37. ANKI_ASSERT(m_size.x());
  38. return m_size.x();
  39. }
  40. U32 getHeight() const
  41. {
  42. ANKI_ASSERT(m_size.y());
  43. return m_size.y();
  44. }
  45. U32 getDepth() const
  46. {
  47. ANKI_ASSERT(m_size.z());
  48. return m_size.z();
  49. }
  50. U32 getLayerCount() const
  51. {
  52. ANKI_ASSERT(m_layerCount);
  53. return m_layerCount;
  54. }
  55. private:
  56. static constexpr U32 MAX_COPIES_BEFORE_FLUSH = 4;
  57. class TexUploadTask;
  58. class LoadingContext;
  59. TexturePtr m_tex;
  60. TextureViewPtr m_texView;
  61. UVec3 m_size = UVec3(0u);
  62. U32 m_layerCount = 0;
  63. ANKI_USE_RESULT static Error load(LoadingContext& ctx);
  64. };
  65. /// @}
  66. } // end namespace anki