BsGpuProgramManager.h 3.5 KB

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