BsCoreRenderer.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 CoreRendererOptions
  45. {
  46. virtual ~CoreRendererOptions() { }
  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 way.
  54. */
  55. class BS_CORE_EXPORT CoreRenderer
  56. {
  57. public:
  58. CoreRenderer();
  59. virtual ~CoreRenderer() { }
  60. /** Initializes the renderer. Must be called before using the renderer. */
  61. virtual void initialize() { }
  62. /** Cleans up the renderer. Must be called before the renderer is deleted. */
  63. virtual void destroy() { }
  64. /** Name of the renderer. Used by materials to find an appropriate technique for this renderer. */
  65. virtual const StringID& getName() const = 0;
  66. /** Called in order to render all currently active cameras. */
  67. virtual void renderAll() = 0;
  68. /**
  69. * Called whenever a new camera is created.
  70. *
  71. * @note Core thread.
  72. */
  73. virtual void notifyCameraAdded(const ct::Camera* camera) { }
  74. /**
  75. * Called whenever a camera's position or rotation is updated.
  76. *
  77. * @param[in] camera Camera that was updated.
  78. * @param[in] updateFlag Optional flag that allows the camera to signal to the renderer exactly what was updated.
  79. *
  80. * @note Core thread.
  81. */
  82. virtual void notifyCameraUpdated(const ct::Camera* camera, UINT32 updateFlag) { }
  83. /**
  84. * Called whenever a camera is destroyed.
  85. *
  86. * @note Core thread.
  87. */
  88. virtual void notifyCameraRemoved(const ct::Camera* camera) { }
  89. /**
  90. * Creates a new empty renderer mesh data.
  91. *
  92. * @note Sim thread.
  93. *
  94. * @see RendererMeshData
  95. */
  96. virtual SPtr<RendererMeshData> _createMeshData(UINT32 numVertices, UINT32 numIndices, VertexLayout layout, IndexType indexType = IT_32BIT);
  97. /**
  98. * Creates a new renderer mesh data using an existing generic mesh data buffer.
  99. *
  100. * @note Sim thread.
  101. *
  102. * @see RendererMeshData
  103. */
  104. virtual SPtr<RendererMeshData> _createMeshData(const SPtr<MeshData>& meshData);
  105. /**
  106. * Registers an extension object that will be called every frame by the renderer. Allows external code to perform
  107. * custom rendering interleaved with the renderer's output.
  108. *
  109. * @note Core thread.
  110. */
  111. void addPlugin(RendererExtension* plugin) { mCallbacks.insert(plugin); }
  112. /**
  113. * Unregisters an extension registered with addPlugin().
  114. *
  115. * @note Core thread.
  116. */
  117. void removePlugin(RendererExtension* plugin) { mCallbacks.erase(plugin); }
  118. /** Sets options used for controlling the rendering. */
  119. virtual void setOptions(const SPtr<CoreRendererOptions>& options) { }
  120. /** Returns current set of options used for controlling the rendering. */
  121. virtual SPtr<CoreRendererOptions> getOptions() const { return SPtr<CoreRendererOptions>(); }
  122. /** Creates post process settings that can be attached to a camera and processed by the active renderer. */
  123. virtual SPtr<PostProcessSettings> createPostProcessSettings() const = 0;
  124. protected:
  125. /** Contains information about a render callback. */
  126. struct RenderCallbackData
  127. {
  128. bool overlay;
  129. std::function<void()> callback;
  130. };
  131. /** Callback to trigger when comparing the order in which renderer extensions are called. */
  132. static bool compareCallback(const RendererExtension* a, const RendererExtension* b);
  133. Set<RendererExtension*, std::function<bool(const RendererExtension*, const RendererExtension*)>> mCallbacks;
  134. };
  135. /** @} */
  136. }}