BsSpriteTexture.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #include "BsPrerequisites.h"
  3. #include "BsResource.h"
  4. #include "BsVector2.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Texture interface that encapsulates underlying texture which allows us
  9. * to create a sprite texture atlas (e.g. multiple SpriteTextures referencing
  10. * different parts of a single Texture).
  11. */
  12. class BS_EXPORT SpriteTexture : public Resource
  13. {
  14. public:
  15. /**
  16. * @brief Returns internal Texture that the sprite texture references.
  17. */
  18. const HTexture& getTexture() const;
  19. /**
  20. * @brief Transforms wanted UV coordinates into coordinates you
  21. * can use for sampling the internal texture.
  22. */
  23. Vector2 transformUV(const Vector2& uv) const;
  24. /**
  25. * @brief Returns a dummy sprite texture.
  26. */
  27. static const HSpriteTexture& dummy();
  28. /**
  29. * @brief Returns width of the sprite texture in pixels.
  30. */
  31. UINT32 getWidth() const;
  32. /**
  33. * @brief Returns height of the sprite texture in pixels.
  34. */
  35. UINT32 getHeight() const;
  36. /**
  37. * @brief Creates a new sprite texture that references the entire area of the provided
  38. * texture.
  39. */
  40. static HSpriteTexture create(const HTexture& texture);
  41. /**
  42. * @brief Creates a new sprite texture that references a sub-area of the provided
  43. * texture.
  44. */
  45. static HSpriteTexture create(const Vector2& uvOffset, const Vector2& uvScale, const HTexture& texture);
  46. /**
  47. * @brief Checks if the sprite texture and its internal texture have been loaded.
  48. */
  49. static bool checkIsLoaded(const HSpriteTexture& tex);
  50. private:
  51. friend class SpriteTextureRTTI;
  52. /**
  53. * @copydoc create(const Vector2&, const Vector2&, const HTexture&)
  54. */
  55. SpriteTexture(const Vector2& uvOffset, const Vector2& uvScale, const HTexture& texture);
  56. /**
  57. * @copydoc Resource::getResourceDependencies
  58. */
  59. void getResourceDependencies(Vector<HResource>& dependencies) const;
  60. /**
  61. * @copydoc CoreObject::getCoreDependencies
  62. */
  63. void getCoreDependencies(Vector<SPtr<CoreObject>>& dependencies);
  64. HTexture mAtlasTexture;
  65. Vector2 mUVOffset;
  66. Vector2 mUVScale;
  67. /************************************************************************/
  68. /* RTTI */
  69. /************************************************************************/
  70. /**
  71. * @brief Creates a new empty and uninitialized sprite texture. To be used by factory methods.
  72. */
  73. static SpriteTexturePtr createEmpty();
  74. public:
  75. friend class SpriteTextureRTTI;
  76. static RTTITypeBase* getRTTIStatic();
  77. virtual RTTITypeBase* getRTTI() const;
  78. };
  79. }