OcclusionQueryImpl.cpp 1.0 KB

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