2
0

BsGpuProgramManager.h 6.2 KB

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