BsCoreRenderer.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsStringID.h"
  6. #include "BsRendererMeshData.h"
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup Renderer-Internal
  10. * @{
  11. */
  12. /**
  13. * Available parameter block semantics that allow the renderer to identify the use of a GPU program parameter block
  14. * specified in a shader.
  15. */
  16. static StringID RBS_Static = "Static";
  17. static StringID RBS_PerCamera = "PerCamera";
  18. static StringID RBS_PerFrame = "PerFrame";
  19. static StringID RBS_PerObject = "PerObject";
  20. /**
  21. * Available parameter semantics that allow the renderer to identify the use of a GPU parameter specified in a shader.
  22. */
  23. static StringID RPS_WorldViewProjTfrm = "WVP";
  24. static StringID RPS_ViewProjTfrm = "VP";
  25. static StringID RPS_ProjTfrm = "P";
  26. static StringID RPS_ViewTfrm = "V";
  27. static StringID RPS_WorldTfrm = "W";
  28. static StringID RPS_InvWorldTfrm = "IW";
  29. static StringID RPS_WorldNoScaleTfrm = "WNoScale";
  30. static StringID RPS_InvWorldNoScaleTfrm = "IWNoScale";
  31. static StringID RPS_WorldDeterminantSign = "WorldDeterminantSign";
  32. static StringID RPS_Diffuse = "Diffuse";
  33. static StringID RPS_ViewDir = "ViewDir";
  34. /** Set of options that can be used for controlling the renderer. */
  35. struct BS_CORE_EXPORT CoreRendererOptions
  36. {
  37. virtual ~CoreRendererOptions() { }
  38. };
  39. /**
  40. * Primarily rendering class that allows you to specify how to render objects that exist in the scene graph. You need
  41. * to provide your own implementation of your class.
  42. *
  43. * @note
  44. * Normally you would iterate over all cameras, find visible objects for each camera and render those objects in some way.
  45. */
  46. class BS_CORE_EXPORT CoreRenderer
  47. {
  48. public:
  49. CoreRenderer();
  50. virtual ~CoreRenderer() { }
  51. /** Initializes the renderer. Must be called before using the renderer. */
  52. virtual void initialize() { }
  53. /** Cleans up the renderer. Must be called before the renderer is deleted. */
  54. virtual void destroy() { }
  55. /** Name of the renderer. Used by materials to find an appropriate technique for this renderer. */
  56. virtual const StringID& getName() const = 0;
  57. /** Called in order to render all currently active cameras. */
  58. virtual void renderAll() = 0;
  59. /**
  60. * Called whenever a new camera is created.
  61. *
  62. * @note Core thread.
  63. */
  64. virtual void _notifyCameraAdded(const CameraCore* camera) { }
  65. /**
  66. * Called whenever a camera is destroyed.
  67. *
  68. * @note Core thread.
  69. */
  70. virtual void _notifyCameraRemoved(const CameraCore* camera) { }
  71. /**
  72. * Creates a new empty renderer mesh data.
  73. *
  74. * @note Sim thread.
  75. *
  76. * @see RendererMeshData
  77. */
  78. virtual RendererMeshDataPtr _createMeshData(UINT32 numVertices, UINT32 numIndices, VertexLayout layout, IndexType indexType = IT_32BIT);
  79. /**
  80. * Creates a new renderer mesh data using an existing generic mesh data buffer.
  81. *
  82. * @note Sim thread.
  83. *
  84. * @see RendererMeshData
  85. */
  86. virtual RendererMeshDataPtr _createMeshData(const MeshDataPtr& meshData);
  87. /**
  88. * Registers a new callback that will be executed when the the specify camera is being rendered.
  89. *
  90. * @param[in] camera Camera for which to trigger the callback.
  91. * @param[in] index Index that determines the order of rendering when there are multiple registered
  92. * callbacks. This must be unique. Lower indices get rendered sooner. Indices below 0 get
  93. * rendered before the main viewport elements, while indices equal or greater to zero after.
  94. * @param[in] callback Callback to trigger when the specified camera is being rendered.
  95. * @param[in] isOverlay If true the render callback guarantees that it will only render overlay data. Overlay
  96. * data doesn't require a depth buffer, a multisampled render target and is usually cheaper
  97. * to render (although this depends on the exact renderer).
  98. * Overlay callbacks are always rendered after all other callbacks, even if their index is negative.
  99. *
  100. * @note Core thread.
  101. */
  102. void _registerRenderCallback(const CameraCore* camera, INT32 index, const std::function<void()>& callback, bool isOverlay = false);
  103. /** Removes a previously registered callback registered with _registerRenderCallback(). */
  104. void _unregisterRenderCallback(const CameraCore* camera, INT32 index);
  105. /** Sets options used for controlling the rendering. */
  106. virtual void setOptions(const SPtr<CoreRendererOptions>& options) { }
  107. /** Returns current set of options used for controlling the rendering. */
  108. virtual SPtr<CoreRendererOptions> getOptions() const { return SPtr<CoreRendererOptions>(); }
  109. protected:
  110. /** Contains information about a render callback. */
  111. struct RenderCallbackData
  112. {
  113. bool overlay;
  114. std::function<void()> callback;
  115. };
  116. UnorderedMap<const CameraCore*, Map<INT32, RenderCallbackData>> mRenderCallbacks;
  117. };
  118. /** @} */
  119. }