QOpenGLFunctions
一、描述
QOpenGLFunctions 类提供对 OpenGL ES 2.0 API 的跨平台访问。
OpenGL ES 2.0 定义了在许多桌面和嵌入式 OpenGL 实现中通用的 OpenGL 规范子集。
QOpenGLFunctions 提供了一个有保证的 API,它在所有 OpenGL 系统上都可用,并负责处理需要它的系统上的函数解析。使用 QOpenGLFunctions 的推荐方法是直接继承:
class MyGLWindow : public QWindow, protected QOpenGLFunctions
{
Q_OBJECT
public:
explicit MyGLWindow(QScreen *screen = nullptr);
protected:
void initializeGL();
void paintGL();
QOpenGLContext *m_context;
};
MyGLWindow::MyGLWindow(QScreen *screen)
: QWindow(screen)
{
setSurfaceType(OpenGLSurface);
create();
// Create an OpenGL context
m_context = new QOpenGLContext;
m_context->create();
// Setup scene and render it
initializeGL();
paintGL();
};
void MyGLWindow::initializeGL()
{
m_context->makeCurrent(this);
initializeOpenGLFunctions();
}
然后,paintGL() 函数可以使用任何 OpenGL ES 2.0 函数而无需显式解析,例如:
void MyGLWindow::paintGL()
{
m_context->makeCurrent(this);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, textureId);
// ...
m_context->swapBuffers(this);
m_context->doneCurrent();
}
QOpenGLFunctions 也可以直接用于所有平台上 OpenGL ES 2.0 函数的临时调用:
QOpenGLFunctions glFuncs(QOpenGLContext::currentContext());
glFuncs.glActiveTexture(GL_TEXTURE1);
另一种方法是查询上下文关联的 QOpenGLFunctions 实例。由于避免了创建新实例,这比以前的方法要快一些,但是差异相当小,因为内部数据结构是共享的,并且对于给定的上下文,函数解析只发生一次,而与 QOpenGLFunctions 实例的数量无关。
QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions();
glFuncs->glActiveTexture(GL_TEXTURE1);
二、类型成员
1、enum QOpenGLFunctions::OpenGLFeature:此枚举定义了 OpenGL 和 OpenGL ES 特性,它们的存在可能取决于实现。
- Multitexture:glActiveTexture() 函数可用。
- Shaders:着色器函数可用。
- Buffers:顶点和索引缓冲区函数可用。
- Framebuffers:帧缓冲区对象函数可用。
- BlendColor:glBlendColor() 可用。
- BlendEquation:glBlendEquation() 可用。
- BlendEquationSeparate:glBlendEquationSeparate() 可用。
- BlendEquationAdvanced:高级混合方程可用。
- BlendFuncSeparate:glBlendFuncSeparate() 可用。
- BlendSubtract:混合减法模式可用。
- CompressedTextures:压缩纹理函数可用。
- Multisample:glSampleCoverage() 函数可用。
- StencilSeparate:单独的模板函数可用。
- NPOTTextures:两个纹理的非幂次可用。
- NPOTTextureRepeat:两个纹理的非幂可以使用 GL_REPEAT 作为 wrap 参数。
- FixedFunctionPipeline:固定函数管道可用。
- TextureRGFormats:GL_RED 和 GL_RG 纹理格式可用。
- MultipleRenderTargets:帧缓冲区对象的多个颜色附件可用。
三、函数成员
略。
QOpenGLExtraFunctions
一、描述
QOpenGLExtraFunctions 类继承自 QOpenGLFunctions。提供对 OpenGL ES 3.0、3.1 和 3.2 API 的跨平台访问。
这个类不同于版本化的 OpenGL 包装器,例如 QOpenGLFunctions_3_2_Core。版本化的函数包装器针对给定的 OpenGL 版本和配置文件。 因此它们不适合跨 OpenGL-OpenGLES 开发。
二、成员函数
略。