BsSelectionRenderer.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsColor.h"
  4. #include "BsMatrix4.h"
  5. #include "BsGpuParam.h"
  6. namespace BansheeEngine
  7. {
  8. class SelectionRendererCore;
  9. /**
  10. * @brief Handles rendering of the selected SceneObject%s overlay.
  11. */
  12. class BS_ED_EXPORT SelectionRenderer
  13. {
  14. /**
  15. * @brief Contains data about a selected mesh.
  16. */
  17. struct ObjectData
  18. {
  19. SPtr<MeshCoreBase> mesh;
  20. Matrix4 worldTfrm;
  21. };
  22. public:
  23. SelectionRenderer();
  24. ~SelectionRenderer();
  25. /**
  26. * @brief Called once per frame. Updates the overlay depending on current selection.
  27. *
  28. * @note Internal method.
  29. */
  30. void update(const CameraPtr& camera);
  31. private:
  32. friend class SelectionRendererCore;
  33. /**
  34. * @brief Initializes the core thread counterpart of the selection renderer.
  35. *
  36. * @param mat Material used for selection rendering.
  37. */
  38. void initializeCore(const SPtr<MaterialCore>& mat);
  39. /**
  40. * @brief Destroys the core thread counterpart of the selection renderer.
  41. *
  42. * @param core Previously constructed core thread selection renderer instance.
  43. */
  44. void destroyCore(SelectionRendererCore* core);
  45. std::atomic<SelectionRendererCore*> mCore;
  46. };
  47. /**
  48. * @brief Core thread version of the selection renderer, that handles
  49. * actual rendering.
  50. */
  51. class SelectionRendererCore
  52. {
  53. friend class SelectionRenderer;
  54. struct PrivatelyConstuct { };
  55. public:
  56. SelectionRendererCore(const PrivatelyConstuct& dummy);
  57. ~SelectionRendererCore();
  58. private:
  59. /**
  60. * @brief Initializes the selection renderer. Should be called right
  61. * after construction.
  62. *
  63. * @param mat Material used for selection rendering.
  64. */
  65. void initialize(const SPtr<MaterialCore>& mat);
  66. /**
  67. * @brief Triggered by the Renderer when the overlay should be rendered.
  68. */
  69. void render();
  70. /**
  71. * @brief Updates the internal data that determines what will be rendered on the next
  72. * ::render call.
  73. *
  74. * @param camera Camera to render the selection overlay in.
  75. * @param objects A set of objects to render with the selection overlay.
  76. */
  77. void updateData(const SPtr<CameraCore>& camera, const Vector<SelectionRenderer::ObjectData>& objects);
  78. Vector<SelectionRenderer::ObjectData> mObjects;
  79. SPtr<CameraCore> mCamera;
  80. // Immutable
  81. SPtr<MaterialCore> mMaterial;
  82. GpuParamMat4Core mMatWorldViewProj;
  83. GpuParamColorCore mColor;
  84. static const Color SELECTION_COLOR;
  85. };
  86. }