Easy3D 2.6.1
Loading...
Searching...
No Matches
OpenGLTimer Class Reference

Accurate timing of GPU operations. More...

#include <easy3d/renderer/opengl_timer.h>

Public Member Functions

 OpenGLTimer (bool start_timing=true)
 Constructor.
 
virtual ~OpenGLTimer ()
 Destructor.
 
void start ()
 Start the timer. The next OpenGL call will be the first timed.
 
bool is_running () const
 Check if the timer is running.
 
void stop ()
 Stop the timer. The previous OpenGL call will be the last timed.
 
double time ()
 Get the GPU time consumed since the last start.
 

Detailed Description

Accurate timing of GPU operations.

Because the GPU is based on an asynchronously processed command stream that is implicitly generated by OpenGL calls, it is not possible to determine the amount of time spent processing a set of OpenGL calls by timing the calls themselves at the application level. Instead, the timing must be done via an asynchronous timer system. This timer is started and stopped at the beginning and end of the OpenGL commands of interest. However, the timing results must be queried at some point later, as the pipeline must complete before the timer values are known. This class implements such a timer that behaves like a CPU timer (See StopWatch).

Usage example:

// opengl calls ...
draw();
fprintf(stdout, "\rTime: %2.4f ms ", t.time());
double time()
Get the GPU time consumed since the last start.
Definition opengl_timer.cpp:68
OpenGLTimer(bool start_timing=true)
Constructor.
Definition opengl_timer.cpp:37

Constructor & Destructor Documentation

◆ OpenGLTimer()

OpenGLTimer ( bool start_timing = true)
explicit

Constructor.

Parameters
start_timingWhether to start the timer immediately.

Member Function Documentation

◆ is_running()

bool is_running ( ) const
inline

Check if the timer is running.

Returns
true if the timer is running, false otherwise.

◆ start()

void start ( )

Start the timer. The next OpenGL call will be the first timed.

Note
This must be called from a thread with the OpenGL context bound.

◆ stop()

void stop ( )

Stop the timer. The previous OpenGL call will be the last timed.

Note
This must be called from a thread with the OpenGL context bound.

◆ time()

double time ( )

Get the GPU time consumed since the last start.

Returns
The GPU time in milliseconds.

The documentation for this class was generated from the following files: