BsCoreRenderer.h 5.1 KB

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