2
0

BsCoreRenderer.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsStringID.h"
  4. #include "BsRendererMeshData.h"
  5. namespace BansheeEngine
  6. {
  7. /** @cond INTERNAL */
  8. /** @addtogroup Renderer
  9. * @{
  10. */
  11. /**
  12. * Available parameter block semantics that allow the renderer to identify the use of a GPU program parameter block
  13. * specified in a shader.
  14. */
  15. static StringID RBS_Static = "Static";
  16. static StringID RBS_PerCamera = "PerCamera";
  17. static StringID RBS_PerFrame = "PerFrame";
  18. static StringID RBS_PerObject = "PerObject";
  19. /**
  20. * Available parameter semantics that allow the renderer to identify the use of a GPU parameter specified in a shader.
  21. */
  22. static StringID RPS_WorldViewProjTfrm = "WVP";
  23. static StringID RPS_ViewProjTfrm = "VP";
  24. static StringID RPS_ProjTfrm = "P";
  25. static StringID RPS_ViewTfrm = "V";
  26. static StringID RPS_WorldTfrm = "W";
  27. static StringID RPS_InvWorldTfrm = "IW";
  28. static StringID RPS_WorldNoScaleTfrm = "WNoScale";
  29. static StringID RPS_InvWorldNoScaleTfrm = "IWNoScale";
  30. static StringID RPS_WorldDeterminantSign = "WorldDeterminantSign";
  31. static StringID RPS_Diffuse = "Diffuse";
  32. static StringID RPS_ViewDir = "ViewDir";
  33. /** Set of options that can be used for controlling the renderer. */
  34. struct BS_CORE_EXPORT CoreRendererOptions
  35. {
  36. virtual ~CoreRendererOptions() { }
  37. };
  38. /**
  39. * Primarily rendering class that allows you to specify how to render objects that exist in the scene graph. You need
  40. * to provide your own implementation of your class.
  41. *
  42. * @note
  43. * Normally you would iterate over all cameras, find visible objects for each camera and render those objects in some way.
  44. */
  45. class BS_CORE_EXPORT CoreRenderer
  46. {
  47. public:
  48. CoreRenderer();
  49. virtual ~CoreRenderer() { }
  50. /** Initializes the renderer. Must be called before using the renderer. */
  51. virtual void initialize() { }
  52. /** Cleans up the renderer. Must be called before the renderer is deleted. */
  53. virtual void destroy() { }
  54. /** Name of the renderer. Used by materials to find an appropriate technique for this renderer. */
  55. virtual const StringID& getName() const = 0;
  56. /** Called in order to render all currently active cameras. */
  57. virtual void renderAll() = 0;
  58. /**
  59. * Called whenever a new camera is created.
  60. *
  61. * @note Core thread.
  62. */
  63. virtual void _notifyCameraAdded(const CameraCore* camera) { }
  64. /**
  65. * Called whenever a camera is destroyed.
  66. *
  67. * @note Core thread.
  68. */
  69. virtual void _notifyCameraRemoved(const CameraCore* camera) { }
  70. /**
  71. * Creates a new empty renderer mesh data.
  72. *
  73. * @note Sim thread.
  74. *
  75. * @see RendererMeshData
  76. */
  77. virtual RendererMeshDataPtr _createMeshData(UINT32 numVertices, UINT32 numIndices, VertexLayout layout, IndexType indexType = IT_32BIT);
  78. /**
  79. * Creates a new renderer mesh data using an existing generic mesh data buffer.
  80. *
  81. * @note Sim thread.
  82. *
  83. * @see RendererMeshData
  84. */
  85. virtual RendererMeshDataPtr _createMeshData(const MeshDataPtr& meshData);
  86. /**
  87. * Registers a new callback that will be executed when the the specify camera is being rendered.
  88. *
  89. * @param[in] camera Camera for which to trigger the callback.
  90. * @param[in] index Index that determines the order of rendering when there are multiple registered
  91. * callbacks. This must be unique. Lower indices get rendered sooner. Indices below 0 get
  92. * rendered before the main viewport elements, while indices equal or greater to zero after.
  93. * @param[in] callback Callback to trigger when the specified camera is being rendered.
  94. * @param[in] isOverlay If true the render callback guarantees that it will only render overlay data. Overlay
  95. * data doesn't require a depth buffer, a multisampled render target and is usually cheaper
  96. * to render (although this depends on the exact renderer).
  97. * Overlay callbacks are always rendered after all other callbacks, even if their index is negative.
  98. *
  99. * @note Core thread.
  100. */
  101. void _registerRenderCallback(const CameraCore* camera, INT32 index, const std::function<void()>& callback, bool isOverlay = false);
  102. /** Removes a previously registered callback registered with _registerRenderCallback(). */
  103. void _unregisterRenderCallback(const CameraCore* camera, INT32 index);
  104. /** Sets options used for controlling the rendering. */
  105. virtual void setOptions(const SPtr<CoreRendererOptions>& options) { }
  106. /** Returns current set of options used for controlling the rendering. */
  107. virtual SPtr<CoreRendererOptions> getOptions() const { return SPtr<CoreRendererOptions>(); }
  108. protected:
  109. /** Contains information about a render callback. */
  110. struct RenderCallbackData
  111. {
  112. bool overlay;
  113. std::function<void()> callback;
  114. };
  115. UnorderedMap<const CameraCore*, Map<INT32, RenderCallbackData>> mRenderCallbacks;
  116. };
  117. /** @} */
  118. /** @endcond */
  119. }