BsRendererExtension.h 3.9 KB

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