ImageAtlasResource.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/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(CString fname, U32 uuid)
  33. : ResourceObject(fname, uuid)
  34. {
  35. }
  36. ~ImageAtlasResource() = default;
  37. /// Load the atlas.
  38. Error load(const ResourceFilename& filename, Bool async);
  39. const Texture& getTexture() const
  40. {
  41. return m_image->getTexture();
  42. }
  43. U32 getWidth() const
  44. {
  45. return m_size[0];
  46. }
  47. U32 getHeight() const
  48. {
  49. return m_size[1];
  50. }
  51. U32 getSubImageMargin() const
  52. {
  53. return m_margin;
  54. }
  55. /// Get the UV coordinates of a sub image.
  56. Error getSubImageInfo(CString name, F32 uv[4]) const;
  57. private:
  58. class SubTex
  59. {
  60. public:
  61. CString m_name; ///< Points to ImageAtlas::m_subTexNames.
  62. Array<F32, 4> m_uv;
  63. };
  64. ImageResourcePtr m_image;
  65. ResourceDynamicArray<char> m_subTexNames;
  66. ResourceDynamicArray<SubTex> m_subTexes;
  67. Array<U32, 2> m_size;
  68. U32 m_margin = 0;
  69. };
  70. /// @}
  71. } // end namespace anki