BsGpuProgramManager.h 5.8 KB

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