BsShaderManager.h 1.8 KB

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