ImageResource.h 1.5 KB

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