BsGpuProgramManager.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsModule.h"
  4. #include "BsException.h"
  5. #include "BsGpuProgram.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Factory responsible for creating GPU programs of a certain type.
  10. */
  11. class BS_CORE_EXPORT GpuProgramFactory
  12. {
  13. public:
  14. GpuProgramFactory() {}
  15. virtual ~GpuProgramFactory();
  16. /**
  17. * @brief Returns GPU program language this factory is capable creating GPU programs from.
  18. */
  19. virtual const String& getLanguage() const = 0;
  20. virtual GpuProgramPtr create(const String& source, const String& entryPoint, GpuProgramType gptype,
  21. GpuProgramProfile profile, const Vector<HGpuProgInclude>* includes, bool requiresAdjacencyInformation) = 0;
  22. /**
  23. * @copydoc GpuProgramManager::createEmpty
  24. */
  25. virtual GpuProgramPtr create(GpuProgramType type) = 0;
  26. };
  27. /**
  28. * @brief Manager responsible for creating GPU programs. It will automatically
  29. * try to find the approriate handler for a specific GPU program language
  30. * and create the program if possible.
  31. *
  32. * @note Sim thread only.
  33. */
  34. class BS_CORE_EXPORT GpuProgramManager : public Module<GpuProgramManager>
  35. {
  36. public:
  37. public:
  38. GpuProgramManager();
  39. ~GpuProgramManager();
  40. /**
  41. * @brief Registers a new factory that is able to create GPU programs for a certain language.
  42. * If any other factory for the same language exists, it will overwrite it.
  43. */
  44. void addFactory(GpuProgramFactory* factory);
  45. /**
  46. * @brief Unregisters a GPU program factory, essentially making it not possible to create GPU programs
  47. * using the language the factory supported.
  48. */
  49. void removeFactory(GpuProgramFactory* factory);
  50. /**
  51. * @brief Query if a GPU program language is supported. (.e.g. "hlsl", "glsl").
  52. */
  53. bool isLanguageSupported(const String& lang);
  54. /**
  55. * @brief Creates a new GPU program using the provided source code. If compilation fails or program is not supported
  56. * "isCompiled" method on the returned program will return false, and you will be able to retrieve the error message
  57. * via "getCompileErrorMessage".
  58. *
  59. * @param source Source code to compile the shader from.
  60. * @param entryPoint Name of the entry point function, e.g. "main".
  61. * @param language Language the source is written in, e.g. "hlsl" or "glsl".
  62. * @param gptype Type of the program, e.g. vertex or fragment.
  63. * @param profile Program profile specifying supported feature-set. Must match the type.
  64. * @param includes Optional includes to append to the source before compiling.
  65. * @param requiresAdjacency If true then adjacency information will be provided when rendering using this program.
  66. */
  67. GpuProgramPtr create(const String& source, const String& entryPoint, const String& language,
  68. GpuProgramType gptype, GpuProgramProfile profile, const Vector<HGpuProgInclude>* includes,
  69. bool requiresAdjacency = false);
  70. /**
  71. * @brief Creates a completely empty and uninitialized GpuProgram.
  72. * Should only be used for specific purposes, like deserialization,
  73. * as it requires additional manual initialization that is not required normally.
  74. */
  75. GpuProgramPtr createEmpty(const String& language, GpuProgramType type);
  76. protected:
  77. /**
  78. * @brief Attempts to find a factory for the specified language. Returns null if it cannot find one.
  79. */
  80. GpuProgramFactory* getFactory(const String& language);
  81. protected:
  82. typedef Map<String, GpuProgramFactory*> FactoryMap;
  83. FactoryMap mFactories;
  84. GpuProgramFactory* mNullFactory; /**< Factory for dealing with GPU programs that can't be created. */
  85. };
  86. }