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)

该函数重载了 get()。

返回指向一个对象的指针,该对象可访问此上下文的版本和配置文件的所有函数。只要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 将保留该对象的所有权。这是为了允许对象被缓存和共享。

© 2025 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.