ImageAtlasResource.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/Resource/ImageResource.h>
  8. #include <AnKi/Gr.h>
  9. namespace anki {
  10. /// @addtogroup resource
  11. /// @{
  12. /// Image atlas resource class.
  13. ///
  14. /// XML format:
  15. /// @code
  16. /// <imageAtlas>
  17. /// <image>path/to/tex.ankitex</image>
  18. /// <subImageMargin>N</subImageMargin>
  19. /// <subImages>
  20. /// <subImage>
  21. /// <name>name</name>
  22. /// <uv>0.1 0.2 0.5 0.6</uv>
  23. /// </subImage>
  24. /// <subImage>...</subImage>
  25. /// ...
  26. /// </subImages>
  27. /// </imageAtlas>
  28. /// @endcode
  29. class ImageAtlasResource : public ResourceObject
  30. {
  31. public:
  32. ImageAtlasResource(ResourceManager* manager);
  33. ~ImageAtlasResource();
  34. /// Load the atlas.
  35. ANKI_USE_RESULT Error load(const ResourceFilename& filename, Bool async);
  36. TexturePtr getTexture() const
  37. {
  38. return m_image->getTexture();
  39. }
  40. TextureViewPtr getTextureView() const
  41. {
  42. return m_image->getTextureView();
  43. }
  44. U32 getWidth() const
  45. {
  46. return m_size[0];
  47. }
  48. U32 getHeight() const
  49. {
  50. return m_size[1];
  51. }
  52. U32 getSubImageMargin() const
  53. {
  54. return m_margin;
  55. }
  56. /// Get the UV coordinates of a sub image.
  57. ANKI_USE_RESULT Error getSubImageInfo(CString name, F32 uv[4]) const;
  58. private:
  59. class SubTex
  60. {
  61. public:
  62. CString m_name; ///< Points to ImageAtlas::m_subTexNames.
  63. Array<F32, 4> m_uv;
  64. };
  65. ImageResourcePtr m_image;
  66. DynamicArray<char> m_subTexNames;
  67. DynamicArray<SubTex> m_subTexes;
  68. Array<U32, 2> m_size;
  69. U32 m_margin = 0;
  70. };
  71. /// @}
  72. } // end namespace anki