ImageAtlasResource.h 1.6 KB

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