BsCoreRenderer.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsGameObject.h"
  4. #include "BsEvent.h"
  5. #include "BsStringID.h"
  6. #include "BsRendererMeshData.h"
  7. namespace BansheeEngine
  8. {
  9. /**
  10. * Available parameter block semantics that allow the renderer to identify
  11. * the use of a GPU program parameter block specified in a shader.
  12. */
  13. static StringID RBS_Static = "Static";
  14. static StringID RBS_PerCamera = "PerCamera";
  15. static StringID RBS_PerFrame = "PerFrame";
  16. static StringID RBS_PerObject = "PerObject";
  17. /**
  18. * Available parameter semantics that allow the renderer to identify
  19. * the use of a GPU parameter specified in a shader.
  20. */
  21. static StringID RPS_WorldViewProjTfrm = "WVP";
  22. static StringID RPS_ViewProjTfrm = "VP";
  23. static StringID RPS_ProjTfrm = "P";
  24. static StringID RPS_ViewTfrm = "V";
  25. static StringID RPS_WorldTfrm = "W";
  26. static StringID RPS_Diffuse = "Diffuse";
  27. static StringID RPS_ViewDir = "ViewDir";
  28. /**
  29. * @brief Set of options that can be used for controlling the renderer.
  30. */
  31. struct BS_CORE_EXPORT CoreRendererOptions
  32. {
  33. virtual ~CoreRendererOptions() { }
  34. };
  35. /**
  36. * @brief Primarily rendering class that allows you to specify how to render objects that exist
  37. * in the scene graph. You need to provide your own implementation of your class.
  38. *
  39. * @note Normally you would iterate over all cameras, find visible objects for each camera and render
  40. * those objects in some way.
  41. */
  42. class BS_CORE_EXPORT CoreRenderer
  43. {
  44. public:
  45. CoreRenderer();
  46. virtual ~CoreRenderer() { }
  47. /**
  48. * @brief Called after the renderer has been activated.
  49. *
  50. * @note Internal method.
  51. */
  52. virtual void _onActivated() { }
  53. /**
  54. * @brief Called just before the renderer is deactivated.
  55. *
  56. * @note Internal method.
  57. */
  58. virtual void _onDeactivated() { }
  59. /**
  60. * @brief Name of the renderer. Used by materials to find
  61. * an appropriate technique for this renderer.
  62. */
  63. virtual const StringID& getName() const = 0;
  64. /**
  65. * @brief Called in order to render all currently active cameras.
  66. */
  67. virtual void renderAll() = 0;
  68. /**
  69. * @brief Called whenever a new camera is created.
  70. *
  71. * @note Core thread.
  72. * Internal method.
  73. */
  74. virtual void _notifyCameraAdded(const CameraCore* camera) { }
  75. /**
  76. * @brief Called whenever a camera is destroyed.
  77. *
  78. * @note Core thread.
  79. * Internal method.
  80. */
  81. virtual void _notifyCameraRemoved(const CameraCore* camera) { }
  82. /**
  83. * @brief Creates a new empty renderer mesh data.
  84. *
  85. * @note Sim thread.
  86. * Internal method.
  87. */
  88. virtual RendererMeshDataPtr _createMeshData(UINT32 numVertices, UINT32 numIndices, VertexLayout layout, IndexType indexType = IT_32BIT);
  89. /**
  90. * @brief Creates a new renderer mesh data using an existing generic mesh data buffer.
  91. *
  92. * @note Sim thread.
  93. * Internal method.
  94. */
  95. virtual RendererMeshDataPtr _createMeshData(const MeshDataPtr& meshData);
  96. /**
  97. * @brief Registers a new callback that will be executed when the the specify camera is being rendered.
  98. *
  99. * @param camera Camera for which to trigger the callback.
  100. * @param index Index that determines the order of rendering when there are multiple registered callbacks.
  101. * This must be unique. Lower indices get rendered sooner. Indices below 0 get rendered before the
  102. * main viewport elements, while indices equal or greater to zero, after.
  103. * @param callback Callback to trigger when the specified camera is being rendered.
  104. *
  105. * @note Core thread.
  106. * Internal method.
  107. */
  108. void _registerRenderCallback(const CameraCore* camera, INT32 index, const std::function<void()>& callback);
  109. /**
  110. * @brief Removes a previously registered callback registered with "_registerRenderCallback".
  111. */
  112. void _unregisterRenderCallback(const CameraCore* camera, INT32 index);
  113. /**
  114. * @brief Sets options used for controlling the rendering.
  115. */
  116. virtual void setOptions(const SPtr<CoreRendererOptions>& options) { }
  117. /**
  118. * @brief Returns current set of options used for controlling the rendering.
  119. */
  120. virtual SPtr<CoreRendererOptions> getOptions() const { return SPtr<CoreRendererOptions>(); }
  121. /**
  122. * @brief Activates the specified pass on the pipeline.
  123. *
  124. * @param material Parent material of the pass.
  125. * @param passIdx Index of the pass in the parent material.
  126. *
  127. * @note Core thread.
  128. */
  129. static void setPass(const SPtr<MaterialCore>& material, UINT32 passIdx);
  130. /**
  131. * @brief Draws the specified mesh proxy with last set pass.
  132. *
  133. * @note Core thread.
  134. */
  135. static void draw(const SPtr<MeshCoreBase>& mesh, const SubMesh& subMesh);
  136. protected:
  137. UnorderedMap<const CameraCore*, Map<UINT32, std::function<void()>>> mRenderCallbacks;
  138. };
  139. }