BsSelectionRenderer.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 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 CameraHandlerPtr& 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. private:
  58. /**
  59. * @brief Initializes the selection renderer. Should be called right
  60. * after construction.
  61. *
  62. * @param mat Material used for selection rendering.
  63. */
  64. void initialize(const SPtr<MaterialCore>& mat);
  65. /**
  66. * @brief Triggered by the Renderer when the overlay should be rendered.
  67. */
  68. void render();
  69. /**
  70. * @brief Updates the internal data that determines what will be rendered on the next
  71. * ::render call.
  72. *
  73. * @param camera Camera to render the selection overlay in.
  74. * @param objects A set of objects to render with the selection overlay.
  75. */
  76. void updateData(const SPtr<CameraHandlerCore>& camera, const Vector<SelectionRenderer::ObjectData>& objects);
  77. Vector<SelectionRenderer::ObjectData> mObjects;
  78. SPtr<CameraHandlerCore> mCamera;
  79. // Immutable
  80. SPtr<MaterialCore> mMaterial;
  81. GpuParamMat4Core mMatWorldViewProj;
  82. GpuParamColorCore mColor;
  83. static const Color SELECTION_COLOR;
  84. };
  85. }