| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #include "anki/gl/Query.h"
- #include "anki/util/Exception.h"
- #include "anki/util/Assert.h"
- namespace anki {
- //==============================================================================
- Query::Query(GLenum q)
- {
- question = q;
- // glId
- glGenQueries(1, &glId);
- if(glId == 0)
- {
- throw ANKI_EXCEPTION("Query generation failed");
- }
- }
- //==============================================================================
- Query::~Query()
- {
- glDeleteQueries(1, &glId);
- }
- //==============================================================================
- void Query::beginQuery()
- {
- glBeginQuery(question, glId);
- }
- //==============================================================================
- void Query::endQuery()
- {
- glEndQuery(question);
- }
- //==============================================================================
- uint64_t Query::getResult()
- {
- GLuint64 result;
- glGetQueryObjectui64v(glId, GL_QUERY_RESULT, &result);
- return result;
- }
- //==============================================================================
- uint64_t Query::getResultNoWait(bool& finished)
- {
- GLuint resi;
- glGetQueryObjectuiv(glId, GL_QUERY_RESULT_AVAILABLE, &resi);
- GLuint64 result;
- if(resi)
- {
- glGetQueryObjectui64v(glId, GL_QUERY_RESULT, &result);
- finished = true;
- }
- else
- {
- finished = false;
- result = 0;
- }
- return result;
- }
- } // end namespace anki
|