BsShaderManager.h 2.0 KB

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