QOpenGLFunctions、QOpenGLExtraFunctions

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 特性,它们的存在可能取决于实现。

  • MultitextureglActiveTexture() 函数可用。
  • Shaders:着色器函数可用。
  • Buffers:顶点和索引缓冲区函数可用。
  • Framebuffers:帧缓冲区对象函数可用。
  • BlendColorglBlendColor() 可用。
  • BlendEquationglBlendEquation() 可用。
  • BlendEquationSeparateglBlendEquationSeparate() 可用。
  • BlendEquationAdvanced:高级混合方程可用。
  • BlendFuncSeparateglBlendFuncSeparate() 可用。
  • BlendSubtract:混合减法模式可用。
  • CompressedTextures:压缩纹理函数可用。
  • MultisampleglSampleCoverage() 函数可用。
  • StencilSeparate:单独的模板函数可用。
  • NPOTTextures:两个纹理的非幂次可用。
  • NPOTTextureRepeat:两个纹理的非幂可以使用 GL_REPEAT 作为 wrap 参数。
  • FixedFunctionPipeline:固定函数管道可用。
  • TextureRGFormatsGL_RED GL_RG 纹理格式可用。
  • MultipleRenderTargets:帧缓冲区对象的多个颜色附件可用。

三、函数成员

略。


QOpenGLExtraFunctions

一、描述

QOpenGLExtraFunctions 类继承自 QOpenGLFunctions。提供对 OpenGL ES 3.0、3.1 和 3.2 API 的跨平台访问。

这个类不同于版本化的 OpenGL 包装器,例如 QOpenGLFunctions_3_2_Core。版本化的函数包装器针对给定的 OpenGL 版本和配置文件。 因此它们不适合跨 OpenGL-OpenGLES 开发。

二、成员函数

略。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值