BsSelectionRenderer.h 2.7 KB

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