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.
| Constant | Value | Description |
|---|---|---|
QGLFunctions::Multitexture | 0x0001 | glActiveTexture() function is available. |
QGLFunctions::Shaders | 0x0002 | Shader functions are available. |
QGLFunctions::Buffers | 0x0004 | Vertex and index buffer functions are available. |
QGLFunctions::Framebuffers | 0x0008 | Framebuffer object functions are available. |
QGLFunctions::BlendColor | 0x0010 | glBlendColor() is available. |
QGLFunctions::BlendEquation | 0x0020 | glBlendEquation() is available. |
QGLFunctions::BlendEquationSeparate | 0x0040 | glBlendEquationSeparate() is available. |
QGLFunctions::BlendFuncSeparate | 0x0080 | glBlendFuncSeparate() is available. |
QGLFunctions::BlendSubtract | 0x0100 | Blend subtract mode is available. |
QGLFunctions::CompressedTextures | 0x0200 | Compressed texture functions are available. |
QGLFunctions::Multisample | 0x0400 | glSampleCoverage() function is available. |
QGLFunctions::StencilSeparate | 0x0800 | Separate stencil functions are available. |
QGLFunctions::NPOTTextures | 0x1000 | Non power of two textures are available. |