QOpenGLVersionFunctionsFactory Class
提供指定版本和配置文件的 OpenGL 函数调用。更多内容...
| 头文件: | #include <QOpenGLVersionFunctionsFactory> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS OpenGL) target_link_libraries(mytarget PRIVATE Qt6::OpenGL) |
| qmake: | QT += opengl |
| 自: | 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)
返回一个对象的指针,该对象提供了对context 的versionProfile 的所有函数的访问权限。只要context 处于活动状态,就无需调用QAbstractOpenGLFunctions::initializeOpenGLFunctions()。 即使context 当前未被选中,也可以调用此函数,但在这种情况下,调用方有责任通过随后调用QAbstractOpenGLFunctions::initializeOpenGLFunctions()来确保正确初始化。
通常,人们会使用该函数的模板版本,以便自动将结果转换为正确的类型。
[static] template <typename TYPE> TYPE *QOpenGLVersionFunctionsFactory::get(QOpenGLContext *context = nullptr)
返回一个对象的指针,该对象提供对本上下文所属版本和配置文件下所有函数的访问。只要context 处于最新状态,就无需调用QAbstractOpenGLFunctions::initializeOpenGLFunctions()。 即使context 不是当前的,也可以调用此函数,但在这种情况下,调用方有责任通过随后调用QAbstractOpenGLFunctions::initializeOpenGLFunctions()来确保正确初始化。
通常会使用该函数的模板版本,以便自动将结果转换为正确的类型。
autofuncs=QOpenGLVersionFunctionsFactory::get<QOpenGLFunctions_3_3_Core>(context);
if(!funcs) {
qFatal("Could not obtain required OpenGL context version");
}可以请求一个与创建上下文时所用版本和配置不同的函数对象。要实现这一点,可以使用该函数的模板版本,将所需的函数对象类型指定为模板参数;或者将一个QOpenGLVersionProfile 对象作为参数传递给非模板函数。
请注意,请求其他版本或配置文件的功能对象可能会失败,此时将返回nullptr 。功能对象的创建可能失败的情况包括:由于请求的功能不在当前上下文的版本或配置文件中,导致请求无法满足。例如:
- 请求 3.3 核心配置文件函数对象将成功。
- 请求 3.3 兼容配置文件函数对象将失败。我们将无法解析已弃用的函数。
- 请求 4.3 核心配置文件函数对象将失败。我们将无法解析 4.0-4.3 版本中引入的新核心函数。
- 请求 3.1 函数对象将成功。因为 3.1 中包含的所有内容在 3.3 核心配置文件中也都存在。
请注意,如果通过此方法创建函数对象,QOpenGLContext 将保留该对象的所有权。这是为了允许该对象被缓存和共享。
此函数重载了QOpenGLVersionFunctionsFactory::get() 方法。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.