BsSelectionRenderer.h 2.6 KB

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