QtBase  v6.3.1
Public Member Functions | List of all members
QOpenGLTimerQuery Class Reference

The QOpenGLTimerQuery class wraps an OpenGL timer query object. \inmodule QtOpenGL. More...

#include <qopengltimerquery.h>

Inheritance diagram for QOpenGLTimerQuery:
Inheritance graph
[legend]
Collaboration diagram for QOpenGLTimerQuery:
Collaboration graph
[legend]

Public Member Functions

 QOpenGLTimerQuery (QObject *parent=nullptr)
 
 ~QOpenGLTimerQuery ()
 
bool create ()
 
void destroy ()
 
bool isCreated () const
 
GLuint objectId () const
 
void begin ()
 
void end ()
 
GLuint64 waitForTimestamp () const
 
void recordTimestamp ()
 
bool isResultAvailable () const
 
GLuint64 waitForResult () const
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 
virtual ~QObject ()
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const
 
void setObjectName (const QString &name)
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 
bool isWindowType () const
 
bool signalsBlocked () const noexcept
 
bool blockSignals (bool b) noexcept
 
QThreadthread () const
 
void moveToThread (QThread *thread)
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 
template<typename T >
T findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
const QObjectListchildren () const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 
void dumpObjectInfo () const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 
bool inherits (const char *classname) const
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 
- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Properties inherited from QObject
QString objectName
 the name of this object More...
 

Detailed Description

The QOpenGLTimerQuery class wraps an OpenGL timer query object. \inmodule QtOpenGL.

Since
5.1

OpenGL timer query objects are OpenGL managed resources to measure the execution times of sequences of OpenGL commands on the GPU.

OpenGL offers various levels of support for timer queries, depending on the version of OpenGL you have and the presence of the ARB_timer_query or EXT_timer_query extensions. The support can be summarized as:

\list

OpenGL represents time with a granularity of 1 nanosecond (1e-9 seconds). As a consequence of this, 32-bit integers would only give a total possible duration of approximately 4 seconds, which would not be difficult to exceed in poorly performing or lengthy operations. OpenGL therefore uses 64 bit integer types to represent times. A GLuint64 variable has enough width to contain a duration of hundreds of years, which is plenty for real-time rendering needs.

As with the other Qt OpenGL classes, QOpenGLTimerQuery has a create() function to create the underlying OpenGL object. This is to allow the developer to ensure that there is a valid current OpenGL context at the time.

Once created, timer queries can be issued in one of several ways. The simplest method is to delimit a block of commands with calls to begin() and end(). This instructs OpenGL to measure the time taken from completing all commands issued prior to begin() until the completion of all commands issued prior to end().

At the end of a frame we can retrieve the results by calling waitForResult(). As this function's name implies, it blocks CPU execution until OpenGL notifies that the timer query result is available. To avoid blocking, you can check if the query result is available by calling isResultAvailable(). Note that modern GPUs are deeply pipelined and query results may not become available for between 1-5 frames after they were issued.

Note that OpenGL does not permit nesting or interleaving of multiple timer queries using begin() and end(). Using multiple timer queries and recordTimestamp() avoids this limitation. When using recordTimestamp() the result can be obtained at some later time using isResultAvailable() and waitForResult(). Qt provides the convenience class QOpenGLTimeMonitor that helps with using multiple query objects.

See also
QOpenGLTimeMonitor

Definition at line 54 of file qopengltimerquery.h.

Constructor & Destructor Documentation

◆ QOpenGLTimerQuery()

QOpenGLTimerQuery::QOpenGLTimerQuery ( QObject parent = nullptr)
explicit

Creates a QOpenGLTimerQuery instance with the given parent. You must call create() with a valid OpenGL context before using.

Definition at line 300 of file qopengltimerquery.cpp.

◆ ~QOpenGLTimerQuery()

QOpenGLTimerQuery::~QOpenGLTimerQuery ( )

Destroys the QOpenGLTimerQuery and the underlying OpenGL resource.

Definition at line 308 of file qopengltimerquery.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ begin()

void QOpenGLTimerQuery::begin ( )

Marks the start point in the OpenGL command queue for a sequence of commands to be timed by this query object.

This is useful for simple use-cases. Usually it is better to use recordTimestamp().

See also
end(), isResultAvailable(), waitForResult(), recordTimestamp()

Definition at line 383 of file qopengltimerquery.cpp.

◆ create()

bool QOpenGLTimerQuery::create ( )

Creates the underlying OpenGL timer query object. There must be a valid OpenGL context that supports query objects current for this function to succeed.

Returns true if the OpenGL timer query object was successfully created.

Definition at line 339 of file qopengltimerquery.cpp.

◆ destroy()

void QOpenGLTimerQuery::destroy ( )

Destroys the underlying OpenGL timer query object. The context that was current when create() was called must be current when calling this function.

Definition at line 349 of file qopengltimerquery.cpp.

Here is the caller graph for this function:

◆ end()

void QOpenGLTimerQuery::end ( )

Marks the end point in the OpenGL command queue for a sequence of commands to be timed by this query object.

This is useful for simple use-cases. Usually it is better to use recordTimestamp().

See also
begin(), isResultAvailable(), waitForResult(), recordTimestamp()

Definition at line 397 of file qopengltimerquery.cpp.

◆ isCreated()

bool QOpenGLTimerQuery::isCreated ( ) const

Returns true if the underlying OpenGL query object has been created. If this returns true and the associated OpenGL context is current, then you are able to issue queries with this object.

Definition at line 360 of file qopengltimerquery.cpp.

◆ isResultAvailable()

bool QOpenGLTimerQuery::isResultAvailable ( ) const

Returns true if the OpenGL timer query result is available.

This function is non-blocking and ideally should be used to check for the availability of the query result before calling waitForResult().

See also
waitForResult()

Definition at line 442 of file qopengltimerquery.cpp.

◆ objectId()

GLuint QOpenGLTimerQuery::objectId ( ) const

Returns the id of the underlying OpenGL query object.

Definition at line 369 of file qopengltimerquery.cpp.

◆ recordTimestamp()

void QOpenGLTimerQuery::recordTimestamp ( )

Places a marker in the OpenGL command queue for the GPU to record the timestamp when this marker is reached by the GPU. This function is non-blocking and the result will become available at some later time.

The availability of the result can be checked with isResultAvailable(). The result can be fetched with waitForResult() which will block if the result is not yet available.

See also
waitForResult(), isResultAvailable(), begin(), end()

Definition at line 414 of file qopengltimerquery.cpp.

◆ waitForResult()

GLuint64 QOpenGLTimerQuery::waitForResult ( ) const

Returns the result of the OpenGL timer query.

This function will block until the result is made available by OpenGL. It is recommended to call isResultAvailable() to ensure that the result is available to avoid unnecessary blocking and stalling.

See also
isResultAvailable()

Definition at line 457 of file qopengltimerquery.cpp.

◆ waitForTimestamp()

GLuint64 QOpenGLTimerQuery::waitForTimestamp ( ) const

Returns the current timestamp of the GPU when all previously issued OpenGL commands have been received but not necessarily executed by the GPU.

This function blocks until the result is returned.

See also
recordTimestamp()

Definition at line 428 of file qopengltimerquery.cpp.


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