cgv
Loading...
Searching...
No Matches
gl_time_query.cxx
1#include "gl_time_query.h"
2
3#include <cgv_gl/gl/gl.h>
4
5namespace cgv {
6 namespace render {
7 namespace gl {
8
12
14{
15 if(is_initialized())
16 destruct(*ctx_ptr);
17}
18
20{
22 last_error = "could not initialize glew";
23 return false;
24 }
25 if(!GLEW_ARB_timer_query) {
26 last_error = "missing ARB timer query extension";
27 return false;
28 }
29
30 glGenQueries(1, &query);
31
32 ctx_ptr = &ctx;
33 return query != 0;
34}
35
37{
38 glDeleteQueries(1, &query);
39 query = 0;
40
41 ctx_ptr = nullptr;
42}
43
45{
46 return ctx_ptr != nullptr;
47}
48
50{
51 glBeginQuery(GL_TIME_ELAPSED, query);
52}
53
55{
56 glEndQuery(GL_TIME_ELAPSED);
57}
58
60{
61 GLint done = false;
62 while(!done)
63 glGetQueryObjectiv(query, GL_QUERY_RESULT_AVAILABLE, &done);
64
65 GLuint64 elapsed_time = 0;
66 glGetQueryObjectui64v(query, GL_QUERY_RESULT, &elapsed_time);
67
68 return double(elapsed_time);
69}
70
72{
73 glBeginQuery(GL_TIME_ELAPSED, query);
74}
75
76double gl_time_query::end() const
77{
78 glEndQuery(GL_TIME_ELAPSED);
79
80 GLint done = false;
81 while(!done)
82 glGetQueryObjectiv(query, GL_QUERY_RESULT_AVAILABLE, &done);
83
84 GLuint64 elapsed_time = 0;
85 glGetQueryObjectui64v(query, GL_QUERY_RESULT, &elapsed_time);
86
87 return double(elapsed_time);
88}
89
90 } // namespace cgv
91 } // namespace render
92} // namespace gl
base class for all drawables, which is independent of the used rendering API.
Definition context.h:626
double collect() const
collect the measured time, blocking until the query object is ready and the time can be retrieved ela...
void begin() const
begin the time measurement
void end_scope() const
close the scope of OpenGL commands included in the time measurement
double end() const
end the time measurement and return elapsed time in nanoseconds (1 second = 10^9 nanoseconds)
void destruct(context &ctx)
deinitialize the query
bool init(context &ctx)
initialize the time query by generating the query object, return success
~gl_time_query()
destruct the query
void begin_scope() const
start scoping OpenGL commands for time measurement
bool is_initialized() const
check whether the time query has been initialized, i.e. the init method has been called successfully ...
gl_time_query()
construct an uninitialized time query
std::string last_error
a string that contains the last error, which is only set by the init method
bool ensure_glew_initialized()
initialize glew in the first call to this function and always return whether this was successful
Definition gl.cxx:19
the cgv namespace
Definition print.h:11