~ubuntu-branches/debian/stretch/gource/stretch

« back to all changes in this revision

Viewing changes to src/core/timer.cpp

  • Committer: Package Import Robot
  • Author(s): Andrew Caudwell
  • Date: 2013-05-13 09:58:33 UTC
  • mfrom: (1.2.14)
  • Revision ID: package-import@ubuntu.com-20130513095833-1r8t89oflvhqxwny
Tags: 0.40-1
* New upstream release.
* Added dpkg-buildflags.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "timer.h"
 
2
 
 
3
// GLTimer
 
4
 
 
5
GLTimer::GLTimer() {
 
6
    query_id      = 0;
 
7
    query_value   = 0;
 
8
    query_start   = 0;
 
9
    query_stop    = 0;
 
10
    cpu_time      = 0;
 
11
}
 
12
 
 
13
GLTimer::GLTimer(const std::string& name) : name(name) {
 
14
    query_id      = 0;
 
15
    query_value   = 0;
 
16
    query_start   = 0;
 
17
    query_stop    = 0;
 
18
    cpu_time      = 0;
 
19
}
 
20
 
 
21
GLTimer::~GLTimer() {
 
22
    unload();
 
23
}
 
24
 
 
25
void GLTimer::unload() {
 
26
    query_value = 0;
 
27
    if(query_id) {
 
28
        glDeleteQueries(1, &query_id);
 
29
        query_id = 0;
 
30
    }
 
31
    query_start = query_stop = 0; 
 
32
}
 
33
 
 
34
void GLTimer::start() {
 
35
    if(query_start > 0) return;
 
36
    
 
37
    query_start = SDL_GetTicks();
 
38
    
 
39
    if(!query_id) glGenQueries( 1, &query_id );
 
40
    
 
41
    glBeginQuery(GL_TIME_ELAPSED, query_id);
 
42
 
 
43
    query_stop = 0;
 
44
}
 
45
 
 
46
void GLTimer::stop() {
 
47
    if(!query_start || query_stop > 0) return;
 
48
    glEndQuery(GL_TIME_ELAPSED);
 
49
    query_stop = SDL_GetTicks();
 
50
}
 
51
 
 
52
const std::string& GLTimer::getName() const {
 
53
    return name;
 
54
}
 
55
 
 
56
GLuint64 GLTimer::getValue() const {
 
57
    return query_value;
 
58
}
 
59
 
 
60
Uint32 GLTimer::getGLMillis() const {
 
61
    return query_value / 1000000;
 
62
}
 
63
 
 
64
Uint32 GLTimer::getCPUMillis() const {
 
65
    return cpu_time;
 
66
}
 
67
 
 
68
bool GLTimer::check() {
 
69
    if(!query_start) return false;
 
70
    
 
71
    GLuint64 elapsed;
 
72
    GLint    available = 0;
 
73
 
 
74
    glGetQueryObjectiv(query_id, GL_QUERY_RESULT_AVAILABLE, &available);
 
75
 
 
76
    if(!available) return false;
 
77
    
 
78
    glGetQueryObjectui64v(query_id, GL_QUERY_RESULT, &elapsed);
 
79
 
 
80
    query_value = elapsed;
 
81
    cpu_time    = query_stop-query_start;
 
82
    query_start = query_stop = 0;
 
83
    
 
84
    return true;
 
85
}