BsCoreRenderer.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. /** Technique tags. */
  36. static StringID RTag_Skinned = "Skinned";
  37. static StringID RTag_Morph = "Morph";
  38. static StringID RTag_SkinnedMorph = "SkinnedMorph";
  39. /** Set of options that can be used for controlling the renderer. */
  40. struct BS_CORE_EXPORT CoreRendererOptions
  41. {
  42. virtual ~CoreRendererOptions() { }
  43. };
  44. /**
  45. * Primarily rendering class that allows you to specify how to render objects that exist in the scene graph. You need
  46. * to provide your own implementation of your class.
  47. *
  48. * @note
  49. * Normally you would iterate over all cameras, find visible objects for each camera and render those objects in some way.
  50. */
  51. class BS_CORE_EXPORT CoreRenderer
  52. {
  53. public:
  54. CoreRenderer();
  55. virtual ~CoreRenderer() { }
  56. /** Initializes the renderer. Must be called before using the renderer. */
  57. virtual void initialize() { }
  58. /** Cleans up the renderer. Must be called before the renderer is deleted. */
  59. virtual void destroy() { }
  60. /** Name of the renderer. Used by materials to find an appropriate technique for this renderer. */
  61. virtual const StringID& getName() const = 0;
  62. /** Called in order to render all currently active cameras. */
  63. virtual void renderAll() = 0;
  64. /**
  65. * Called whenever a new camera is created.
  66. *
  67. * @note Core thread.
  68. */
  69. virtual void notifyCameraAdded(const CameraCore* camera) { }
  70. /**
  71. * Called whenever a camera's position or rotation is updated.
  72. *
  73. * @param[in] camera Camera that was updated.
  74. * @param[in] updateFlag Optional flag that allows the camera to signal to the renderer exactly what was updated.
  75. *
  76. * @note Core thread.
  77. */
  78. virtual void notifyCameraUpdated(const CameraCore* camera, UINT32 updateFlag) { }
  79. /**
  80. * Called whenever a camera is destroyed.
  81. *
  82. * @note Core thread.
  83. */
  84. virtual void notifyCameraRemoved(const CameraCore* camera) { }
  85. /**
  86. * Creates a new empty renderer mesh data.
  87. *
  88. * @note Sim thread.
  89. *
  90. * @see RendererMeshData
  91. */
  92. virtual SPtr<RendererMeshData> _createMeshData(UINT32 numVertices, UINT32 numIndices, VertexLayout layout, IndexType indexType = IT_32BIT);
  93. /**
  94. * Creates a new renderer mesh data using an existing generic mesh data buffer.
  95. *
  96. * @note Sim thread.
  97. *
  98. * @see RendererMeshData
  99. */
  100. virtual SPtr<RendererMeshData> _createMeshData(const SPtr<MeshData>& meshData);
  101. /**
  102. * Registers a new callback that will be executed when the the specify camera is being rendered.
  103. *
  104. * @param[in] camera Camera for which to trigger the callback.
  105. * @param[in] index Index that determines the order of rendering when there are multiple registered
  106. * callbacks. This must be unique. Lower indices get rendered sooner. Indices below 0 get
  107. * rendered before the main viewport elements, while indices equal or greater to zero after.
  108. * @param[in] callback Callback to trigger when the specified camera is being rendered.
  109. * @param[in] isOverlay If true the render callback guarantees that it will only render overlay data. Overlay
  110. * data doesn't require a depth buffer, a multisampled render target and is usually cheaper
  111. * to render (although this depends on the exact renderer).
  112. * Overlay callbacks are always rendered after all other callbacks, even if their index is negative.
  113. *
  114. * @note Core thread.
  115. */
  116. void registerRenderCallback(const CameraCore* camera, INT32 index, const std::function<void()>& callback, bool isOverlay = false);
  117. /** Removes a previously registered callback registered with _registerRenderCallback(). */
  118. void unregisterRenderCallback(const CameraCore* camera, INT32 index);
  119. /** Sets options used for controlling the rendering. */
  120. virtual void setOptions(const SPtr<CoreRendererOptions>& options) { }
  121. /** Returns current set of options used for controlling the rendering. */
  122. virtual SPtr<CoreRendererOptions> getOptions() const { return SPtr<CoreRendererOptions>(); }
  123. /** Creates post process settings that can be attached to a camera and processed by the active renderer. */
  124. virtual SPtr<PostProcessSettings> createPostProcessSettings() const = 0;
  125. protected:
  126. /** Contains information about a render callback. */
  127. struct RenderCallbackData
  128. {
  129. bool overlay;
  130. std::function<void()> callback;
  131. };
  132. UnorderedMap<const CameraCore*, Map<INT32, RenderCallbackData>> mRenderCallbacks;
  133. };
  134. /** @} */
  135. }