BsCoreRenderer.h 5.8 KB

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