BsRenderer.h 7.0 KB

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