BsSelectionRenderer.h 2.6 KB

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