Detailed Description
The QGLAbstractEffect class provides a standard interface for rendering surface material effects with GL.
Vertex attributes
Vertex attributes for the effect are specified using QGLPainter::setVertexAttribute() and QGLPainter::setVertexBundle(), and may be independent of the effect itself. Those functions will bind standard attributes to specific indexes within the GL state. For example, the QGL::Position will be bound to index 0, QGL::TextureCoord0 will be bound to index 3, etc.
Effect subclasses that use vertex shaders should bind their attributes to these indexes using QGLShaderProgram::bindAttributeLocation() just before the program is linked. For example:
QGLShaderProgram *program = new QGLShaderProgram();
program->addShaderFromSourceCode(QGLShader::Vertex, vshaderSource);
program->addShaderFromSourceCode(QGLShader::Fragment, fshaderSource);
program->bindAttributeLocation("vertex", QGL::Position);
program->bindAttributeLocation("normal", QGL::Normal);
program->bindAttributeLocation("texcoord", QGL::TextureCoord0);
program->link();
The QGLShaderProgramEffect class can assist with writing shader-based effects. It will automatically bind special variable names, such as qt_Vertex, qt_MultiTexCoord0, etc, to the standard indexes. This alleviates the need for the application to bind the names itself.
Member Function Documentation
QGLAbstractEffect::QGLAbstractEffect()
Constructs a new effect object.
QGLAbstractEffect::~QGLAbstractEffect() [virtual]
Destroys this effect object.
void QGLAbstractEffect::setActive(QGLPainter * painter, bool flag) [pure virtual]
Activates or deactivates this effect on painter, according to flag, on the current GL context by selecting shader programs, setting lighting and material parameters, etc.
See also update().
bool QGLAbstractEffect::supportsPicking() const [virtual]
Returns true if this effect supports object picking; false otherwise. The default implementation returns false, which causes QGLPainter to use the effect associated with QGL::FlatColor to perform object picking.
Effects that support object picking render fragments with QGLPainter::pickColor() when QGLPainter::isPicking() returns true. By default, only the effect associated with QGL::FlatColor does this, rendering the entire fragment with the flat pick color.
In some cases, rendering the entire fragment with the pick color may not be appropriate. An alpha-blended icon texture that is drawn to the screen as a quad may have an irregular shape smaller than the quad. For picking, the application may not want the entire quad to be "active" for object selection as it would appear to allow the user to click off the icon to select it.
This situation can be handled by implementing an icon rendering effect that draws the icon normally when QGLPainter::isPicking() is false, and draws a mask texture defining the outline of the icon with QGLPainter::pickColor() when QGLPainter::isPicking() is true.
See also QGLPainter::setPicking().
void QGLAbstractEffect::update(QGLPainter * painter, QGLPainter::Updates updates) [pure virtual]
Updates the current GL context with information from painter just prior to the drawing of triangles, quads, etc.
The updates parameter specifies the properties on painter that have changed since the last call to update() or setActive().
See also setActive().