CmGUIMaterialManager.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmModule.h"
  4. namespace CamelotEngine
  5. {
  6. /**
  7. * @brief Manages the materials used by the GUI system. Ensures that the GUI system doesn't
  8. * create an unnecessarily large amount of equivalent materials.
  9. */
  10. class CM_EXPORT GUIMaterialManager : public Module<GUIMaterialManager>
  11. {
  12. public:
  13. /**
  14. * @brief Creates a new material, or returns a reference to an existing one based on
  15. * the provided primary texture.
  16. *
  17. * Returned material can be used for text rendering.
  18. *
  19. * Make sure to release all materials with a call to "releaseMaterial()".
  20. */
  21. const HMaterial& requestTextMaterial(const HTexture& texture) const;
  22. /**
  23. * @brief Creates a new material, or returns a reference to an existing one based on
  24. * the provided primary texture.
  25. *
  26. * Returned material can be used for normal image rendering.
  27. *
  28. * Make sure to release all materials with a call to "releaseMaterial()".
  29. */
  30. const HMaterial& requestImageMaterial(const HTexture& texture) const;
  31. /**
  32. * @brief Releases the held reference to the material. This allows us to fully unload a material
  33. * and their textures when they are no longer being used.
  34. */
  35. void releaseMaterial(const HMaterial& material) const;
  36. private:
  37. struct GUIMaterial
  38. {
  39. GUIMaterial()
  40. :refCount(0)
  41. { }
  42. HMaterial handle;
  43. UINT32 refCount;
  44. };
  45. mutable vector<GUIMaterial>::type mTextMaterials;
  46. mutable vector<GUIMaterial>::type mImageMaterials;
  47. };
  48. }