BsGpuProgramManager.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 "Utility/BsModule.h"
  6. #include "Error/BsException.h"
  7. #include "RenderAPI/BsGpuProgram.h"
  8. namespace bs
  9. {
  10. /** @addtogroup RenderAPI-Internal
  11. * @{
  12. */
  13. /**
  14. * Manager responsible for creating GPU programs. It will automatically try to find the appropriate handler for a
  15. * specific GPU program language and create the program if possible.
  16. *
  17. * @note Sim thread only.
  18. */
  19. class BS_CORE_EXPORT GpuProgramManager : public Module<GpuProgramManager>
  20. {
  21. public:
  22. /** @copydoc GpuProgram::create */
  23. SPtr<GpuProgram> create(const GPU_PROGRAM_DESC& desc);
  24. /**
  25. * Creates a completely empty and uninitialized GpuProgram. Should only be used for specific purposes, like
  26. * deserialization, as it requires additional manual initialization that is not required normally.
  27. */
  28. SPtr<GpuProgram> createEmpty(const String& language, GpuProgramType type);
  29. };
  30. namespace ct
  31. {
  32. /** Factory responsible for creating GPU programs of a certain type. */
  33. class BS_CORE_EXPORT GpuProgramFactory
  34. {
  35. public:
  36. GpuProgramFactory() {}
  37. virtual ~GpuProgramFactory() { }
  38. /** Returns GPU program language this factory is capable creating GPU programs from. */
  39. virtual const String& getLanguage() const = 0;
  40. /** @copydoc GpuProgram::create */
  41. virtual SPtr<GpuProgram> create(const GPU_PROGRAM_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  42. /** @copydoc bs::GpuProgramManager::createEmpty */
  43. virtual SPtr<GpuProgram> create(GpuProgramType type, GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  44. };
  45. /**
  46. * Manager responsible for creating GPU programs. It will automatically try to find the appropriate handler for a
  47. * specific GPU program language and create the program if possible.
  48. *
  49. * @note Core thread only.
  50. */
  51. class BS_CORE_EXPORT GpuProgramManager : public Module<GpuProgramManager>
  52. {
  53. public:
  54. GpuProgramManager();
  55. virtual ~GpuProgramManager();
  56. /**
  57. * Registers a new factory that is able to create GPU programs for a certain language. If any other factory for the
  58. * same language exists, it will overwrite it.
  59. */
  60. void addFactory(GpuProgramFactory* factory);
  61. /**
  62. * Unregisters a GPU program factory, essentially making it not possible to create GPU programs using the language
  63. * the factory supported.
  64. */
  65. void removeFactory(GpuProgramFactory* factory);
  66. /** Query if a GPU program language is supported (for example "hlsl", "glsl"). */
  67. bool isLanguageSupported(const String& lang);
  68. /** @copydoc GpuProgram::create */
  69. SPtr<GpuProgram> create(const GPU_PROGRAM_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  70. protected:
  71. friend class bs::GpuProgram;
  72. /**
  73. * Creates a GPU program without initializing it.
  74. *
  75. * @see create
  76. */
  77. SPtr<GpuProgram> createInternal(const GPU_PROGRAM_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  78. /** Attempts to find a factory for the specified language. Returns null if it cannot find one. */
  79. GpuProgramFactory* getFactory(const String& language);
  80. protected:
  81. typedef Map<String, GpuProgramFactory*> FactoryMap;
  82. FactoryMap mFactories;
  83. GpuProgramFactory* mNullFactory; /**< Factory for dealing with GPU programs that can't be created. */
  84. };
  85. }
  86. /** @} */
  87. }