BsCoreRenderer.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 Activates the specified pass on the pipeline.
  87. *
  88. * @param material Parent material of the pass.
  89. * @param passIdx Index of the pass in the parent material.
  90. *
  91. * @note Core thread only.
  92. */
  93. static void setPass(const SPtr<MaterialCore>& material, UINT32 passIdx);
  94. /**
  95. * @brief Draws the specified mesh proxy with last set pass.
  96. *
  97. * @note Core thread only.
  98. */
  99. static void draw(const SPtr<MeshCoreBase>& mesh, const SubMesh& subMesh);
  100. /**
  101. * @brief Callback that gets triggered before a viewport gets rendered.
  102. *
  103. * @note Sim thread only
  104. */
  105. Event<void(const Viewport*, DrawList&)> onRenderViewport;
  106. /**
  107. * @brief Callback that gets triggered before main render queue items are rendered
  108. * to the provided viewport, called from the core thread directly.
  109. *
  110. * @note Core thread only.
  111. */
  112. Event<void(const CameraHandlerCore&)> onCorePreRenderViewport;
  113. /**
  114. * @brief Callback that gets triggered after main render queue items are rendered,
  115. * to the provided viewport, called from the core thread directly.
  116. *
  117. * @note Core thread only.
  118. */
  119. Event<void(const CameraHandlerCore&)> onCorePostRenderViewport;
  120. };
  121. }