Query.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "anki/gl/Query.h"
  2. #include "anki/util/Exception.h"
  3. #include "anki/util/Assert.h"
  4. namespace anki {
  5. //==============================================================================
  6. Query::Query(GLenum q)
  7. {
  8. question = q;
  9. // glId
  10. glGenQueries(1, &glId);
  11. if(glId == 0)
  12. {
  13. throw ANKI_EXCEPTION("Query generation failed");
  14. }
  15. }
  16. //==============================================================================
  17. Query::~Query()
  18. {
  19. glDeleteQueries(1, &glId);
  20. }
  21. //==============================================================================
  22. void Query::beginQuery()
  23. {
  24. glBeginQuery(question, glId);
  25. }
  26. //==============================================================================
  27. void Query::endQuery()
  28. {
  29. glEndQuery(question);
  30. }
  31. //==============================================================================
  32. uint64_t Query::getResult()
  33. {
  34. GLuint64 result;
  35. glGetQueryObjectui64v(glId, GL_QUERY_RESULT, &result);
  36. return result;
  37. }
  38. //==============================================================================
  39. uint64_t Query::getResultNoWait(bool& finished)
  40. {
  41. GLuint resi;
  42. glGetQueryObjectuiv(glId, GL_QUERY_RESULT_AVAILABLE, &resi);
  43. GLuint64 result;
  44. if(resi)
  45. {
  46. glGetQueryObjectui64v(glId, GL_QUERY_RESULT, &result);
  47. finished = true;
  48. }
  49. else
  50. {
  51. finished = false;
  52. result = 0;
  53. }
  54. return result;
  55. }
  56. } // end namespace anki