BsCoreRenderer.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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_WorldTfrm = "World";
  24. static StringID RPS_Diffuse = "Diffuse";
  25. static StringID RPS_ViewDir = "ViewDir";
  26. /**
  27. * @brief Primarily rendering class that allows you to specify how to render objects that exist
  28. * in the scene graph. You need to provide your own implementation of your class.
  29. *
  30. * @note Normally you would iterate over all cameras, find visible objects for each camera and render
  31. * those objects in some way.
  32. */
  33. class BS_CORE_EXPORT CoreRenderer
  34. {
  35. public:
  36. virtual ~CoreRenderer() { }
  37. /**
  38. * @brief Called after the renderer has been activated.
  39. *
  40. * @note Internal method.
  41. */
  42. virtual void _onActivated() { }
  43. /**
  44. * @brief Called just before the renderer is deactivated.
  45. *
  46. * @note Internal method.
  47. */
  48. virtual void _onDeactivated() { }
  49. /**
  50. * @brief Name of the renderer. Used by materials to find
  51. * an appropriate technique for this renderer.
  52. */
  53. virtual const StringID& getName() const = 0;
  54. /**
  55. * @brief Called in order to render all currently active cameras.
  56. */
  57. virtual void renderAll() = 0;
  58. /**
  59. * @brief Called whenever a new camera is created.
  60. *
  61. * @note Core thread.
  62. * Internal method.
  63. */
  64. virtual void _notifyCameraAdded(const CameraHandlerCore* camera) { }
  65. /**
  66. * @brief Called whenever a camera is destroyed.
  67. *
  68. * @note Core thread.
  69. * Internal method.
  70. */
  71. virtual void _notifyCameraRemoved(const CameraHandlerCore* camera) { }
  72. /**
  73. * @brief Creates a new empty renderer mesh data.
  74. *
  75. * @note Sim thread.
  76. * Internal method.
  77. */
  78. virtual RendererMeshDataPtr _createMeshData(UINT32 numVertices, UINT32 numIndices, VertexLayout layout, IndexType indexType = IT_32BIT);
  79. /**
  80. * @brief Creates a new renderer mesh data using an existing generic mesh data buffer.
  81. *
  82. * @note Sim thread.
  83. * Internal method.
  84. */
  85. virtual RendererMeshDataPtr _createMeshData(const MeshDataPtr& meshData);
  86. /**
  87. * @brief Registers a new callback that will be executed when the the specify camera is being rendered.
  88. *
  89. * @param camera Camera for which to trigger the callback.
  90. * @param index Index that determines the order of rendering when there are multiple registered callbacks.
  91. * This must be unique. Lower indices get rendered sooner. Indices below 0 get rendered before the
  92. * main viewport elements, while indices equal to greater to zero, after.
  93. * @param callback Callback to trigger when the specified camera is being rendered.
  94. *
  95. * @note Core thread.
  96. * Internal method.
  97. */
  98. void _registerRenderCallback(const CameraHandlerCore* camera, INT32 index, const std::function<void()>& callback);
  99. /**
  100. * @brief Removes a previously registered callback registered with "_registerRenderCallback".
  101. */
  102. void _unregisterRenderCallback(const CameraHandlerCore* camera, INT32 index);
  103. /**
  104. * @brief Activates the specified pass on the pipeline.
  105. *
  106. * @param material Parent material of the pass.
  107. * @param passIdx Index of the pass in the parent material.
  108. *
  109. * @note Core thread.
  110. */
  111. static void setPass(const SPtr<MaterialCore>& material, UINT32 passIdx);
  112. /**
  113. * @brief Draws the specified mesh proxy with last set pass.
  114. *
  115. * @note Core thread.
  116. */
  117. static void draw(const SPtr<MeshCoreBase>& mesh, const SubMesh& subMesh);
  118. /**
  119. * @brief Callback that gets triggered before a viewport gets rendered.
  120. *
  121. * @note Sim thread.
  122. */
  123. Event<void(const Viewport*, DrawList&)> onRenderViewport;
  124. protected:
  125. UnorderedMap<const CameraHandlerCore*, Map<UINT32, std::function<void()>>> mRenderCallbacks;
  126. };
  127. }