BsRenderer.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 bs
  8. {
  9. class RendererExtension;
  10. struct PostProcessSettings;
  11. namespace ct
  12. {
  13. /** @addtogroup Renderer-Internal
  14. * @{
  15. */
  16. /** Technique tags. */
  17. static StringID RTag_Skinned = "Skinned";
  18. static StringID RTag_Morph = "Morph";
  19. static StringID RTag_SkinnedMorph = "SkinnedMorph";
  20. /** Set of options that can be used for controlling the renderer. */
  21. struct BS_CORE_EXPORT RendererOptions
  22. {
  23. virtual ~RendererOptions() { }
  24. };
  25. /**
  26. * Primarily rendering class that allows you to specify how to render objects that exist in the scene graph. You need
  27. * to provide your own implementation of your class.
  28. *
  29. * @note
  30. * Normally you would iterate over all cameras, find visible objects for each camera and render those objects in some
  31. * way.
  32. */
  33. class BS_CORE_EXPORT Renderer
  34. {
  35. public:
  36. Renderer();
  37. virtual ~Renderer() { }
  38. /** Initializes the renderer. Must be called before using the renderer. */
  39. virtual void initialize() { }
  40. /** Cleans up the renderer. Must be called before the renderer is deleted. */
  41. virtual void destroy() { }
  42. /** Name of the renderer. Used by materials to find an appropriate technique for this renderer. */
  43. virtual const StringID& getName() const = 0;
  44. /** Called in order to render all currently active cameras. */
  45. virtual void renderAll() = 0;
  46. /**
  47. * Called whenever a new camera is created.
  48. *
  49. * @note Core thread.
  50. */
  51. virtual void notifyCameraAdded(Camera* camera) { }
  52. /**
  53. * Called whenever a camera's position or rotation is updated.
  54. *
  55. * @param[in] camera Camera that was updated.
  56. * @param[in] updateFlag Optional flag that allows the camera to signal to the renderer exactly what was updated.
  57. *
  58. * @note Core thread.
  59. */
  60. virtual void notifyCameraUpdated(Camera* camera, UINT32 updateFlag) { }
  61. /**
  62. * Called whenever a camera is destroyed.
  63. *
  64. * @note Core thread.
  65. */
  66. virtual void notifyCameraRemoved(Camera* camera) { }
  67. /**
  68. * Called whenever a new renderable is created.
  69. *
  70. * @note Core thread.
  71. */
  72. virtual void notifyRenderableAdded(Renderable* renderable) { }
  73. /**
  74. * Called whenever a renderable is updated.
  75. *
  76. * @note Core thread.
  77. */
  78. virtual void notifyRenderableUpdated(Renderable* renderable) { }
  79. /**
  80. * Called whenever a renderable is destroyed.
  81. *
  82. * @note Core thread.
  83. */
  84. virtual void notifyRenderableRemoved(Renderable* renderable) { }
  85. /**
  86. * Called whenever a new light is created.
  87. *
  88. * @note Core thread.
  89. */
  90. virtual void notifyLightAdded(Light* light) { }
  91. /**
  92. * Called whenever a light is updated.
  93. *
  94. * @note Core thread.
  95. */
  96. virtual void notifyLightUpdated(Light* light) { }
  97. /**
  98. * Called whenever a light is destroyed.
  99. *
  100. * @note Core thread.
  101. */
  102. virtual void notifyLightRemoved(Light* light) { }
  103. /**
  104. * Called whenever a new reflection probe is created.
  105. *
  106. * @note Core thread.
  107. */
  108. virtual void notifyReflectionProbeAdded(ReflectionProbe* probe) { }
  109. /**
  110. * Called whenever a reflection probe is updated.
  111. *
  112. * @note Core thread.
  113. */
  114. virtual void notifyReflectionProbeUpdated(ReflectionProbe* probe) { }
  115. /**
  116. * Called whenever a reflection probe is destroyed.
  117. *
  118. * @note Core thread.
  119. */
  120. virtual void notifyReflectionProbeRemoved(ReflectionProbe* probe) { }
  121. /**
  122. * Called whenever a skybox is created.
  123. *
  124. * @note Core thread.
  125. */
  126. virtual void notifySkyboxAdded(Skybox* skybox) { }
  127. /**
  128. * Called whenever the texture assigned to a skybox is changed.
  129. *
  130. * @note Core thread.
  131. */
  132. virtual void notifySkyboxTextureChanged(Skybox* skybox) { }
  133. /**
  134. * Called whenever a skybox is destroyed.
  135. *
  136. * @note Core thread.
  137. */
  138. virtual void notifySkyboxRemoved(Skybox* skybox) { }
  139. /**
  140. * Creates a new empty renderer mesh data.
  141. *
  142. * @note Sim thread.
  143. *
  144. * @see RendererMeshData
  145. */
  146. virtual SPtr<RendererMeshData> _createMeshData(UINT32 numVertices, UINT32 numIndices, VertexLayout layout,
  147. IndexType indexType = IT_32BIT);
  148. /**
  149. * Creates a new renderer mesh data using an existing generic mesh data buffer.
  150. *
  151. * @note Sim thread.
  152. *
  153. * @see RendererMeshData
  154. */
  155. virtual SPtr<RendererMeshData> _createMeshData(const SPtr<MeshData>& meshData);
  156. /**
  157. * Registers an extension object that will be called every frame by the renderer. Allows external code to perform
  158. * custom rendering interleaved with the renderer's output.
  159. *
  160. * @note Core thread.
  161. */
  162. void addPlugin(RendererExtension* plugin) { mCallbacks.insert(plugin); }
  163. /**
  164. * Unregisters an extension registered with addPlugin().
  165. *
  166. * @note Core thread.
  167. */
  168. void removePlugin(RendererExtension* plugin) { mCallbacks.erase(plugin); }
  169. /** Sets options used for controlling the rendering. */
  170. virtual void setOptions(const SPtr<RendererOptions>& options) { }
  171. /** Returns current set of options used for controlling the rendering. */
  172. virtual SPtr<RendererOptions> getOptions() const { return SPtr<RendererOptions>(); }
  173. /** Creates post process settings that can be attached to a camera and processed by the active renderer. */
  174. virtual SPtr<PostProcessSettings> createPostProcessSettings() const = 0;
  175. protected:
  176. /** Contains information about a render callback. */
  177. struct RenderCallbackData
  178. {
  179. bool overlay;
  180. std::function<void()> callback;
  181. };
  182. /** Callback to trigger when comparing the order in which renderer extensions are called. */
  183. static bool compareCallback(const RendererExtension* a, const RendererExtension* b);
  184. Set<RendererExtension*, std::function<bool(const RendererExtension*, const RendererExtension*)>> mCallbacks;
  185. };
  186. /** Provides easy access to Renderer. */
  187. SPtr<Renderer> BS_CORE_EXPORT gRenderer();
  188. /** @} */
  189. }}