GPUTimer
Concrete implementation of the Timer class for GPU-based timing using OpenGL queries. More...
#include "Utils/Timers.h"
Inherits from Timer
Public Functions
Name | |
---|---|
GPUTimer(std::string name)<br>Constructor. | |
~GPUTimer() override<br>Destructor. | |
virtual double | get() override<br>Retrieves the elapsed GPU time for the most recent interval. |
virtual double | getAverage() override<br>Retrieves the average GPU time over all measured intervals. |
virtual unsigned int | getCounter() const override<br>Retrieves the number of recorded intervals. |
GLuint | getId(bool start) const<br>Returns the OpenGL query ID for start or stop query. |
virtual void | reset() override<br>Resets the GPU timer, clearing all recorded data. |
virtual void | start(bool sync =false) override<br>Starts the GPU timer. |
virtual void | stop(bool sync =false) override<br>Stops the GPU timer. |
Additional inherited members
Public Functions inherited from Timer
Name | |
---|---|
Timer() =default | |
Timer(double intervalSeconds, sol::protected_function callback, bool oneShot =false) | |
Timer(std::string name)<br>Constructor. | |
virtual | ~Timer() =default<br>Virtual destructor. |
const std::string & | getName() const<br>Retrieves the name of the timer. |
void | tick(double dt) |
Protected Attributes inherited from Timer
Name | |
---|---|
unsigned int | counter <br>Number of recorded intervals. |
std::string | name <br>Name of the timer. |
GLuint64 | previousFrameQueryStart |
double | previousFrameTimeStart <br>Start time of the previous frame. |
GLuint | query <br>OpenGL query object for timing. |
GLuint | queryStart |
GLuint | queryStop <br>OpenGL query objects for timing. |
double | time <br>Time elapsed for the current interval. |
double | timeStart <br>Start time of the current interval. |
double | timeStop <br>Stop time of the current interval. |
double | timeTotal <br>Total accumulated time. |
Friends inherited from Timer
Name | |
---|---|
class | Chronos |
Detailed Description
class GPUTimer;
class GPUTimer;
Concrete implementation of the Timer class for GPU-based timing using OpenGL queries.
The GPUTimer class uses OpenGL timestamp queries to measure the time spent on the GPU. It creates query objects for start and stop timestamps and calculates elapsed time based on them.
Public Functions Documentation
function GPUTimer
inline GPUTimer(
std::string name
)
inline GPUTimer(
std::string name
)
Constructor.
Parameters:
- name Name of the timer.
function ~GPUTimer
inline ~GPUTimer() override
inline ~GPUTimer() override
Destructor.
Deletes the created query objects (if any).
function get
inline virtual double get() override
inline virtual double get() override
Retrieves the elapsed GPU time for the most recent interval.
Return: The elapsed time in seconds.
Reimplements: Timer::get
Reads back timestamp query results to compute elapsed GPU time. Accumulates this time into timeTotal
and increments counter
. The returned value is converted to seconds (1e-9 for nanoseconds).
function getAverage
inline virtual double getAverage() override
inline virtual double getAverage() override
Retrieves the average GPU time over all measured intervals.
Return: The average time in seconds.
Reimplements: Timer::getAverage
Uses [get()](/cpp-api-reference/classes/classGPUTimer#function-get)
to ensure the last interval is accounted for, then returns timeTotal / counter (converted to seconds).
function getCounter
inline virtual unsigned int getCounter() const override
inline virtual unsigned int getCounter() const override
Retrieves the number of recorded intervals.
Return: The interval count.
Reimplements: Timer::getCounter
function getId
inline GLuint getId(
bool start
) const
inline GLuint getId(
bool start
) const
Returns the OpenGL query ID for start or stop query.
Parameters:
- start If true, returns
queryStart
; otherwise returnsqueryStop
.
Return: The OpenGL query object ID.
function reset
inline virtual void reset() override
inline virtual void reset() override
Resets the GPU timer, clearing all recorded data.
Reimplements: Timer::reset
function start
inline virtual void start(
bool sync =false
) override
inline virtual void start(
bool sync =false
) override
Starts the GPU timer.
Parameters:
- sync Whether to synchronize with external operations before starting.
Reimplements: Timer::start
Creates query objects if not already created. Optionally calls glFinish() if sync
is true. Places a timestamp query to mark the start of the measurement.
function stop
inline virtual void stop(
bool sync =false
) override
inline virtual void stop(
bool sync =false
) override
Stops the GPU timer.
Parameters:
- sync Whether to synchronize with external operations before stopping.
Reimplements: Timer::stop
Optionally calls glFinish() if sync
is true. Places a timestamp query to mark the end of the measurement.
Updated on 2025-05-31 at 12:55:30 +0000