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