QGLFunctions Class

The QGLFunctions class provides cross-platform access to the OpenGL ES 2.0 API. More...

Header: #include <QGLFunctions>
qmake: QT += opengl
Since: Qt 4.8

This class is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This class was introduced in Qt 4.8.

Public Types

enum OpenGLFeature { Multitexture, Shaders, Buffers, Framebuffers, BlendColor, …, NPOTTextures }

Detailed Description

OpenGL ES 2.0 defines a subset of the OpenGL specification that is common across many desktop and embedded OpenGL implementations. However, it can be difficult to use the functions from that subset because they need to be resolved manually on desktop systems.

QGLFunctions provides a guaranteed API that is available on all OpenGL systems and takes care of function resolution on systems that need it. The recommended way to use QGLFunctions is by direct inheritance:

     class MyGLWidget : public QGLWidget, protected QGLFunctions
     {
         Q_OBJECT
     public:
         MyGLWidget(QWidget *parent = 0) : QGLWidget(parent) {}

     protected:
         void initializeGL();
         void paintGL();
     };

     void MyGLWidget::initializeGL()
     {
         initializeGLFunctions();
     }

The paintGL() function can then use any of the OpenGL ES 2.0 functions without explicit resolution, such as glActiveTexture() in the following example:

     void MyGLWidget::paintGL()
     {
         glActiveTexture(GL_TEXTURE1);
         glBindTexture(GL_TEXTURE_2D, textureId);
         ...
     }

QGLFunctions can also be used directly for ad-hoc invocation of OpenGL ES 2.0 functions on all platforms:

     QGLFunctions glFuncs(QGLContext::currentContext());
     glFuncs.glActiveTexture(GL_TEXTURE1);

QGLFunctions provides wrappers for all OpenGL ES 2.0 functions, except those like glDrawArrays(), glViewport(), and glBindTexture() that don't have portability issues.

Including the header for QGLFunctions will also define all of the OpenGL ES 2.0 macro constants that are not already defined by the system's OpenGL headers, such as GL_TEXTURE1 above.

The hasOpenGLFeature() and openGLFeatures() functions can be used to determine if the OpenGL implementation has a major OpenGL ES 2.0 feature. For example, the following checks if non power of two textures are available:

     QGLFunctions funcs(QGLContext::currentContext());
     bool npot = funcs.hasOpenGLFeature(QGLFunctions::NPOTTextures);

Note: This class has been deprecated in favor of QOpenGLFunctions.

Member Type Documentation

enum QGLFunctions::OpenGLFeature

This enum defines OpenGL ES 2.0 features that may be optional on other platforms.

ConstantValueDescription
QGLFunctions::Multitexture0x0001glActiveTexture() function is available.
QGLFunctions::Shaders0x0002Shader functions are available.
QGLFunctions::Buffers0x0004Vertex and index buffer functions are available.
QGLFunctions::Framebuffers0x0008Framebuffer object functions are available.
QGLFunctions::BlendColor0x0010glBlendColor() is available.
QGLFunctions::BlendEquation0x0020glBlendEquation() is available.
QGLFunctions::BlendEquationSeparate0x0040glBlendEquationSeparate() is available.
QGLFunctions::BlendFuncSeparate0x0080glBlendFuncSeparate() is available.
QGLFunctions::BlendSubtract0x0100Blend subtract mode is available.
QGLFunctions::CompressedTextures0x0200Compressed texture functions are available.
QGLFunctions::Multisample0x0400glSampleCoverage() function is available.
QGLFunctions::StencilSeparate0x0800Separate stencil functions are available.
QGLFunctions::NPOTTextures0x1000Non power of two textures are available.