OcclusionQueryImpl.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <AnKi/Gr/Vulkan/OcclusionQueryImpl.h>
  6. #include <AnKi/Gr/Vulkan/GrManagerImpl.h>
  7. namespace anki {
  8. OcclusionQueryImpl::~OcclusionQueryImpl()
  9. {
  10. if(m_handle)
  11. {
  12. getGrManagerImpl().getOcclusionQueryFactory().deleteQuery(m_handle);
  13. }
  14. }
  15. Error OcclusionQueryImpl::init()
  16. {
  17. ANKI_CHECK(getGrManagerImpl().getOcclusionQueryFactory().newQuery(m_handle));
  18. return Error::NONE;
  19. }
  20. OcclusionQueryResult OcclusionQueryImpl::getResultInternal() const
  21. {
  22. ANKI_ASSERT(m_handle);
  23. U64 out = 0;
  24. VkResult res;
  25. ANKI_VK_CHECKF(res = vkGetQueryPoolResults(getDevice(), m_handle.getQueryPool(), m_handle.getQueryIndex(), 1,
  26. sizeof(out), &out, sizeof(out),
  27. VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT
  28. | VK_QUERY_RESULT_PARTIAL_BIT));
  29. OcclusionQueryResult qout = OcclusionQueryResult::NOT_AVAILABLE;
  30. if(res == VK_SUCCESS)
  31. {
  32. qout = (out) ? OcclusionQueryResult::VISIBLE : OcclusionQueryResult::NOT_VISIBLE;
  33. }
  34. else if(res == VK_NOT_READY)
  35. {
  36. qout = OcclusionQueryResult::NOT_AVAILABLE;
  37. }
  38. else
  39. {
  40. ANKI_ASSERT(0);
  41. }
  42. return qout;
  43. }
  44. } // end namespace anki