BsGpuProgramManager.h 5.9 KB

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