BsCoreRenderer.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. struct PostProcessSettings;
  10. /** @addtogroup Renderer-Internal
  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's position or rotation is updated.
  68. *
  69. * @param[in] camera Camera that was updated.
  70. * @param[in] updateFlag Optional flag that allows the camera to signal to the renderer exactly what was updated.
  71. *
  72. * @note Core thread.
  73. */
  74. virtual void notifyCameraUpdated(const CameraCore* camera, UINT32 updateFlag) { }
  75. /**
  76. * Called whenever a camera is destroyed.
  77. *
  78. * @note Core thread.
  79. */
  80. virtual void notifyCameraRemoved(const CameraCore* camera) { }
  81. /**
  82. * Creates a new empty renderer mesh data.
  83. *
  84. * @note Sim thread.
  85. *
  86. * @see RendererMeshData
  87. */
  88. virtual SPtr<RendererMeshData> _createMeshData(UINT32 numVertices, UINT32 numIndices, VertexLayout layout, IndexType indexType = IT_32BIT);
  89. /**
  90. * Creates a new renderer mesh data using an existing generic mesh data buffer.
  91. *
  92. * @note Sim thread.
  93. *
  94. * @see RendererMeshData
  95. */
  96. virtual SPtr<RendererMeshData> _createMeshData(const SPtr<MeshData>& meshData);
  97. /**
  98. * Registers a new callback that will be executed when the the specify camera is being rendered.
  99. *
  100. * @param[in] camera Camera for which to trigger the callback.
  101. * @param[in] index Index that determines the order of rendering when there are multiple registered
  102. * callbacks. This must be unique. Lower indices get rendered sooner. Indices below 0 get
  103. * rendered before the main viewport elements, while indices equal or greater to zero after.
  104. * @param[in] callback Callback to trigger when the specified camera is being rendered.
  105. * @param[in] isOverlay If true the render callback guarantees that it will only render overlay data. Overlay
  106. * data doesn't require a depth buffer, a multisampled render target and is usually cheaper
  107. * to render (although this depends on the exact renderer).
  108. * Overlay callbacks are always rendered after all other callbacks, even if their index is negative.
  109. *
  110. * @note Core thread.
  111. */
  112. void registerRenderCallback(const CameraCore* camera, INT32 index, const std::function<void()>& callback, bool isOverlay = false);
  113. /** Removes a previously registered callback registered with _registerRenderCallback(). */
  114. void unregisterRenderCallback(const CameraCore* camera, INT32 index);
  115. /** Sets options used for controlling the rendering. */
  116. virtual void setOptions(const SPtr<CoreRendererOptions>& options) { }
  117. /** Returns current set of options used for controlling the rendering. */
  118. virtual SPtr<CoreRendererOptions> getOptions() const { return SPtr<CoreRendererOptions>(); }
  119. /** Creates post process settings that can be attached to a camera and processed by the active renderer. */
  120. virtual SPtr<PostProcessSettings> createPostProcessSettings() const = 0;
  121. protected:
  122. /** Contains information about a render callback. */
  123. struct RenderCallbackData
  124. {
  125. bool overlay;
  126. std::function<void()> callback;
  127. };
  128. UnorderedMap<const CameraCore*, Map<INT32, RenderCallbackData>> mRenderCallbacks;
  129. };
  130. /** @} */
  131. }