BsGpuProgramManager.h 6.2 KB

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