GlQuery.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "anki/gl/Query.h"
  2. #include "anki/util/Exception.h"
  3. #include "anki/util/Assert.h"
  4. #include <GL/glew.h>
  5. namespace anki {
  6. //==============================================================================
  7. // QueryImpl =
  8. //==============================================================================
  9. /// XXX
  10. struct QueryImpl
  11. {
  12. GLuint glId;
  13. GLenum question;
  14. };
  15. //==============================================================================
  16. // Query =
  17. //==============================================================================
  18. //==============================================================================
  19. Query::Query(QueryQuestion q)
  20. {
  21. impl.reset(new QueryImpl);
  22. // question
  23. switch(q)
  24. {
  25. case QQ_SAMPLES_PASSED:
  26. impl->question = GL_SAMPLES_PASSED;
  27. break;
  28. default:
  29. ANKI_ASSERT(0);
  30. };
  31. // glId
  32. glGenQueries(1, &impl->glId);
  33. if(impl->glId == 0)
  34. {
  35. throw ANKI_EXCEPTION("Query generation failed");
  36. }
  37. }
  38. //==============================================================================
  39. Query::~Query()
  40. {
  41. glDeleteQueries(1, &impl->glId);
  42. }
  43. //==============================================================================
  44. void Query::beginQuery()
  45. {
  46. glBeginQuery(impl->question, impl->glId);
  47. }
  48. //==============================================================================
  49. void Query::endQuery()
  50. {
  51. glEndQuery(impl->question);
  52. }
  53. } // end namespace anki