EditorStateMaskRenderer.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Draw/EditorStateMaskRenderer.h>
  9. namespace AZ::Render
  10. {
  11. EditorStateMaskRenderer::EditorStateMaskRenderer(const Name& name)
  12. : m_drawTag(name)
  13. {
  14. }
  15. void EditorStateMaskRenderer::RenderMaskEntities(
  16. Data::Instance<RPI::Material> maskMaterial, const AzToolsFramework::EntityIdSet& entityIds)
  17. {
  18. if (entityIds.empty())
  19. {
  20. m_drawableEntities.clear();
  21. return;
  22. }
  23. // Erase any drawable entity meshes not in the provided list of entities
  24. erase_if(m_drawableEntities, [&entityIds](const auto& elem) { return !entityIds.contains(elem.first); });
  25. // Construct the drawable entity meshes for entities not in the drawable entity cache
  26. for (const auto& entityId : entityIds)
  27. {
  28. if (m_drawableEntities.find(entityId) == m_drawableEntities.end())
  29. {
  30. m_drawableEntities.emplace(
  31. AZStd::piecewise_construct, AZStd::forward_as_tuple(entityId),
  32. AZStd::forward_as_tuple(entityId, maskMaterial, m_drawTag));
  33. }
  34. }
  35. // Render all of the drawable entities that can draw (not being able to draw is not a failure)
  36. for (auto& [entityId, drawable] : m_drawableEntities)
  37. {
  38. if (drawable.CanDraw())
  39. {
  40. drawable.Draw();
  41. }
  42. }
  43. }
  44. } // namespace AZ::Render