- Qt 6.5
- Qt OpenGL
- C++ Classes
- QOpenGLVersionFunctionsFactory
- Qt 6.5.0 Reference Documentation

# QOpenGLVersionFunctionsFactory Class

Provides access to OpenGL functions for a specified version and profile. More...

Header: | #include <QOpenGLVersionFunctionsFactory>
CMake: | find_package(Qt6 REQUIRED COMPONENTS OpenGL) target_link_libraries(mytarget PRIVATE Qt6::OpenGL)
qmake: | QT += opengl
Since: | Qt 6.0

- List of all members, including inherited members

## Static Public Members

QAbstractOpenGLFunctions * | get(const QOpenGLVersionProfile &versionProfile = QOpenGLVersionProfile(), QOpenGLContext *context = nullptr)
TYPE * | get(QOpenGLContext *context = nullptr)

## Detailed Description

## Member Function Documentation

### `[static]` QAbstractOpenGLFunctions *QOpenGLVersionFunctionsFactory::get(const QOpenGLVersionProfile &versionProfile = QOpenGLVersionProfile(), QOpenGLContext *context = nullptr)

Returns a pointer to an object that provides access to all functions for the versionProfile of the context. There is no need to call QAbstractOpenGLFunctions::initializeOpenGLFunctions() as long as the context is current. It is also possible to call this function when the context is not current, but in that case it is the caller's responsibility to ensure proper initialization by calling QAbstractOpenGLFunctions::initializeOpenGLFunctions() afterwards.

Usually one would use the template version of this function to automatically have the result cast to the correct type.

### `[static]` template <typename TYPE> TYPE *QOpenGLVersionFunctionsFactory::get(QOpenGLContext *context = nullptr)

This function overloads get().

Returns a pointer to an object that provides access to all functions for the version and profile of this context. There is no need to call QAbstractOpenGLFunctions::initializeOpenGLFunctions() as long as the context is current. It is also possible to call this function when the context is not current, but in that case it is the caller's responsibility to ensure proper initialization by calling QAbstractOpenGLFunctions::initializeOpenGLFunctions() afterwards.

Usually one would use the template version of this function to automatically have the result cast to the correct type.

     auto funcs = QOpenGLVersionFunctionsFactory::get<QOpenGLFunctions_3_3_Core>(context);
     if (!funcs) {
         qFatal("Could not obtain required OpenGL context version");
     }

It is possible to request a functions object for a different version and profile than that for which the context was created. To do this either use the template version of this function specifying the desired functions object type as the template parameter or by passing in a QOpenGLVersionProfile object as an argument to the non-template function.

Note that requests for function objects of other versions or profiles can fail and in doing so will return `nullptr`. Situations in which creation of the functions object can fail are if the request cannot be satisfied due to asking for functions that are not in the version or profile of this context. For example:

- Requesting a 3.3 core profile functions object would succeed.
- Requesting a 3.3 compatibility profile functions object would fail. We would fail to resolve the deprecated functions.
- Requesting a 4.3 core profile functions object would fail. We would fail to resolve the new core functions introduced in versions 4.0-4.3.
- Requesting a 3.1 functions object would succeed. There is nothing in 3.1 that is not also in 3.3 core.

Note that if creating a functions object via this method that the QOpenGLContext retains ownership of the object. This is to allow the object to be cached and shared.