Provides access to OpenGL functions for a specified version and profile. 更多...
头: | #include <QOpenGLVersionFunctionsFactory> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS OpenGL)
target_link_libraries(mytarget PRIVATE Qt6::OpenGL) |
qmake: | QT += opengl |
Since: | Qt 6.0 |
QAbstractOpenGLFunctions * | get (const QOpenGLVersionProfile & versionProfile = QOpenGLVersionProfile(), QOpenGLContext * context = nullptr) |
TYPE * | get (QOpenGLContext * context = nullptr) |
[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 的 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:
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.