BsSelectionRenderer.h 2.7 KB

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