13
GLTimer::GLTimer(const std::string& name) : name(name) {
25
void GLTimer::unload() {
28
glDeleteQueries(1, &query_id);
31
query_start = query_stop = 0;
34
void GLTimer::start() {
35
if(query_start > 0) return;
37
query_start = SDL_GetTicks();
39
if(!query_id) glGenQueries( 1, &query_id );
41
glBeginQuery(GL_TIME_ELAPSED, query_id);
46
void GLTimer::stop() {
47
if(!query_start || query_stop > 0) return;
48
glEndQuery(GL_TIME_ELAPSED);
49
query_stop = SDL_GetTicks();
52
const std::string& GLTimer::getName() const {
56
GLuint64 GLTimer::getValue() const {
60
Uint32 GLTimer::getGLMillis() const {
61
return query_value / 1000000;
64
Uint32 GLTimer::getCPUMillis() const {
68
bool GLTimer::check() {
69
if(!query_start) return false;
74
glGetQueryObjectiv(query_id, GL_QUERY_RESULT_AVAILABLE, &available);
76
if(!available) return false;
78
glGetQueryObjectui64v(query_id, GL_QUERY_RESULT, &elapsed);
80
query_value = elapsed;
81
cpu_time = query_stop-query_start;
82
query_start = query_stop = 0;