BsShaderManager.h 2.0 KB

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