ImageResource.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. Vec4 getAverageColor() const
  30. {
  31. return m_avgColor;
  32. }
  33. Bool isLoaded() const
  34. {
  35. return m_pendingLoadedMips.load() == 0;
  36. }
  37. private:
  38. static constexpr U32 kMaxCopiesBeforeFlush = 4;
  39. class TexUploadTask;
  40. class LoadingContext;
  41. TexturePtr m_tex;
  42. Vec4 m_avgColor = Vec4(0.0f);
  43. mutable Atomic<U32> m_pendingLoadedMips = {0};
  44. Error loadAsync(LoadingContext& ctx) const;
  45. };
  46. /// @}
  47. } // end namespace anki