BsRendererExtension.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. namespace bs
  6. {
  7. /** @addtogroup Renderer-Internal
  8. * @{
  9. */
  10. /** A set of available locations at which the renderer can call RendererExtension's render() method. */
  11. enum class RenderLocation
  12. {
  13. /**
  14. * Rendering happens before any scene objects are rendered and before the render target for scene objects is
  15. * bound (e.g. GBuffer).
  16. */
  17. Prepare,
  18. /**
  19. * Rendering happens before any scene objects are rendered. The renderer guarantees the render targets used for
  20. * rendering scene objects will be bound (e.g. GBuffer).
  21. */
  22. PreBasePass,
  23. /**
  24. * Rendering happens after all scene objects are rendered. The renderer guarantees the render targets used for
  25. * rendering scene objects will be bound (e.g. GBuffer).
  26. */
  27. PostBasePass,
  28. /**
  29. * Rendering happens after all scene objects have been rendered and their final information has been written to
  30. * the final scene color buffer, without any post-processing. The renderer guarantees the final scene color render
  31. * target will be bound.
  32. */
  33. PostLightPass,
  34. /**
  35. * Rendering happens after all scene objects have been rendered and their final information has been written to
  36. * the final scene color buffer, with post-processing. The renderer guarantees the final scene color render target
  37. * will be bound.
  38. */
  39. Overlay
  40. };
  41. /**
  42. * Interface that can be implemented in order to provide custom rendering code to the renderer.
  43. * See Renderer::addPlugin().
  44. *
  45. * @note Core thread.
  46. */
  47. class BS_CORE_EXPORT RendererExtension
  48. {
  49. public:
  50. /**
  51. * Creates a brand new instance of a specific implementation of a renderer extension. Queues initialization of the
  52. * object on the core thread and registers it with the renderer. Destruction will be queued on the core thread when
  53. * the object goes out of scope.
  54. *
  55. * @note Sim thread.
  56. */
  57. template<class T>
  58. static SPtr<T> create(const Any& data)
  59. {
  60. T* ext = new (bs_alloc<T>()) T();
  61. _initializer(ext, data);
  62. return SPtr<T>(ext, &RendererExtension::_deleter);
  63. }
  64. /** Called when the renderer extension is first initialized. */
  65. virtual void initialize(const Any& data) {}
  66. /** Called just before the renderer extension is destroyed. */
  67. virtual void destroy() {}
  68. /** Returns true if the render() method should be called for the provided camera. */
  69. virtual bool check(const ct::Camera& camera) = 0;
  70. /**
  71. * Called at the point at which rendering should be performed for the provided camera. Relevant render targets
  72. * are guaranteed to be already bound to the render API, depending on the RenderLocation. Note that actual structure
  73. * of the render targets depends on the active renderer.
  74. */
  75. virtual void render(const ct::Camera& camera) = 0;
  76. /**
  77. * Determines when will the render() method execute, compared to other plugins using the same RenderLocation.
  78. * Higher number means the extension will execute before extensions with lower numbers. Priorities only matter for
  79. * extensions that share the same RenderLocation.
  80. */
  81. UINT32 getPriority() const { return mPriority; }
  82. /**
  83. * Returns a location that determines at which point in rendering should the system call the render() method. See
  84. * RenderLocation.
  85. */
  86. RenderLocation getLocation() const { return mLocation; }
  87. protected:
  88. RendererExtension(RenderLocation location, UINT32 priority)
  89. :mLocation(location), mPriority(priority)
  90. { }
  91. virtual ~RendererExtension() {}
  92. private:
  93. /** Initializer that triggers when a renderer extension is first constructed. */
  94. static void _initializer(RendererExtension* obj, const Any& data);
  95. /** Deleter that triggers when a renderer extension object goes out of scope. */
  96. static void _deleter(RendererExtension* obj);
  97. RenderLocation mLocation;
  98. UINT32 mPriority;
  99. };
  100. /** @} */
  101. }