BsGpuProgramManager.h 4.6 KB

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