BsCoreRenderer.h 4.3 KB

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