BsGpuProgramManager.h 4.3 KB

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