BsShaderManager.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsModule.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Interface that provides a method for finding a shader include resource
  8. * based on the name of the include that was provided in a shader file.
  9. */
  10. class BS_CORE_EXPORT IShaderIncludeHandler
  11. {
  12. public:
  13. virtual ~IShaderIncludeHandler() { }
  14. /**
  15. * @brief Attempts to find a shader include resource based on its name.
  16. */
  17. virtual HShaderInclude findInclude(const String& name) const = 0;
  18. };
  19. /**
  20. * @brief Implements shader include finding by converting the shader
  21. * include name into a path that the resource will be loaded from.
  22. */
  23. class BS_CORE_EXPORT DefaultShaderIncludeHandler : public IShaderIncludeHandler
  24. {
  25. public:
  26. /**
  27. * @copydoc IShaderIncludeHandler::findInclude
  28. */
  29. virtual HShaderInclude findInclude(const String& name) const override;
  30. };
  31. /**
  32. * @brief A global manager that handles various shader specific operations.
  33. */
  34. class BS_CORE_EXPORT ShaderManager : public Module <ShaderManager>
  35. {
  36. public:
  37. ShaderManager(const ShaderIncludeHandlerPtr& handler) { mIncludeHandler = handler; }
  38. /**
  39. * @brief Attempts to find a shader include based on the include name.
  40. *
  41. * @note The name is usually a path to the resource relative to the working folder,
  42. * but can be other things depending on active handler.
  43. */
  44. HShaderInclude findInclude(const String& name) const;
  45. /**
  46. * @brief Changes the active include handler that determines how is
  47. * a shader include name mapped to the actual resource.
  48. */
  49. void setIncludeHandler(const ShaderIncludeHandlerPtr& handler) { mIncludeHandler = handler; }
  50. private:
  51. ShaderIncludeHandlerPtr mIncludeHandler;
  52. };
  53. }