OcclusionQueryImpl.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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/gl/OcclusionQueryImpl.h>
  6. namespace anki
  7. {
  8. void OcclusionQueryImpl::init()
  9. {
  10. glGenQueries(1, &m_glName);
  11. ANKI_ASSERT(m_glName != 0);
  12. }
  13. void OcclusionQueryImpl::begin()
  14. {
  15. ANKI_ASSERT(isCreated());
  16. glBeginQuery(GL_ANY_SAMPLES_PASSED_CONSERVATIVE, m_glName);
  17. }
  18. void OcclusionQueryImpl::end()
  19. {
  20. ANKI_ASSERT(isCreated());
  21. glEndQuery(GL_ANY_SAMPLES_PASSED_CONSERVATIVE);
  22. }
  23. OcclusionQueryResult OcclusionQueryImpl::getResult() const
  24. {
  25. ANKI_ASSERT(isCreated());
  26. OcclusionQueryResult result = OcclusionQueryResult::NOT_AVAILABLE;
  27. GLuint params;
  28. glGetQueryObjectuiv(m_glName, GL_QUERY_RESULT_AVAILABLE, &params);
  29. if(params != 0)
  30. {
  31. glGetQueryObjectuiv(m_glName, GL_QUERY_RESULT, &params);
  32. result = (params == 1) ? OcclusionQueryResult::VISIBLE : OcclusionQueryResult::NOT_VISIBLE;
  33. }
  34. return result;
  35. }
  36. } // end namespace anki