BsGpuProgramManager.h 5.7 KB

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