JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
GpuTimer Class Reference

Measures how long the GPU takes for what's drawn between start() and stop(), e.g. More...

#include <jngl/GpuTimer.hpp>

Public Member Functions

 GpuTimer (const GpuTimer &)=delete
 
GpuTimer & operator= (const GpuTimer &)=delete
 
 GpuTimer (GpuTimer &&) noexcept
 
GpuTimer & operator= (GpuTimer &&) noexcept
 
void start ()
 Starts measuring what's drawn from now on.
 
void stop ()
 Stops measuring, for poll() to return how long the GPU took once that's known.
 
std::optional< std::chrono::nanoseconds > poll ()
 The oldest measurement that has come in since the last call, in the order of stop(), or nullopt if there's none (yet)
 

Static Public Member Functions

static bool isSupported ()
 Whether the GPU's time can be measured here.
 

Detailed Description

Measures how long the GPU takes for what's drawn between start() and stop(), e.g.

a frame, without waiting for it to finish: a measurement comes in a few frames later, see poll().

Needs OpenGL 3.3's timer queries, which OpenGL ES and WebGL don't have. Without them, see isSupported(), start() and stop() do nothing and poll() never returns anything.

Example:

timer.start();
scene.draw();
timer.stop();
while (const auto duration = timer.poll()) {
// a frame some time ago took *duration on the GPU
}

Definition at line 28 of file GpuTimer.hpp.

Member Function Documentation

◆ start()

void start ( )

Starts measuring what's drawn from now on.

Only one GpuTimer can measure at a time, and only once until stop().


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