Convenience class for a shader implementing a basic fixed function rendering pipeline.
More...
Convenience class for a shader implementing a basic fixed function rendering pipeline.
FixedFunctionPipeline is a stateful object similar to an OpenGL context. Changes to any of its properties (e.g. matrices, default color, ...) apply to any subsequent draw call while the pipeline is enabled. Any call to enable() will automatically reset the state to its defaults.
For desktop OpenGL this class supports different shader variants (default general purpose shader, wide and stippled line rendering shader). You select the shader to use during enable(). In OpenGL ES contexts the line rendering shaders are not available due to the lack of geometry shader support. Use GL::LineRenderer as alternative.
The default state of the rendering shader is as follows:
- Projection matrix: as specified in the GL::ViewState given on enable()
- View matrix: as specified in the GL::ViewState given on enable()
- Model matrix: identity
- Default color: black (0, 0, 0, 1)
- Texturing: disabled
- Texture Coordinate Transformation: 1.0 scaling, 0.0 offset
- Point smoothing: disabled
- Line width: 1px (only for the
LineRendering
shader)
- Stipple pattern: 0xFFFF (only for the
LineRendering
shader)
- Stipple factor: 1.0 (only for the
LineRendering
shader)
The shader expects the following inputs/vertex attributes during rendering
- Attribute 0 (mandatory): Vertex positions
- Attribute 1 (optional): Per-vertex texture coordinates to be used when texturing is enabled.
- Attribute 2 (optional): Per-vertex colors. FixedFunctionPipeline will use the configured default color if no per-vertex colors are specified.
You can use the makeVertexData() helper function to create a GL::VertexBuffer with the correct attribute bindings. Also, FixedFunctionPipeline inherits from GL::InstanceManager so that you can request a cached instance of this class from any valid OpenGL context.
Example usage for rendering a textured quad:
ffp.enable(state);
ffp.setModelMatrix(matrix);
ffp.enableTexturing(*texture);
vbo->draw(GL::VertexBuffer::Triangles);
ffp.disable();
static VertexData< T > makeVertexData(const std::vector< T > &vertexPositions)
Factory function to create a VertexData object without the need to explicitly specify the template ty...
static FixedFunctionPipeline & cachedInstance()
Definition InstanceManager.h:80
- Note
- When trying to render pixel-perfect 2D lines, remember that the coordinates specify the center of the line while a standard orthographic projection (e.g. GL::createOrtho2d()) refers to the corner of a pixel. Thus, when using an odd line width you might need to offset the pixel location by half a pixel depending on your view state.
- Note
- The functionality partially overlaps with LineRenderer since both can render thick and stippled lines:
- FixedFunctionPipeline is general purpose and allows for directly rendering any vertex buffer. However, it requires geometry shader support which is absent in OpenGL ES environments.
- LineRenderer also works in OpenGL ES contexts as it only uses basic vertex and fragment shaders. However, it therefore requires some preprocessing of the input vertices on the CPU.
- See also
- GL::VertexBuffer, GL::LineRenderer, Rendering Custom Graphics
- Examples
- MyCustomGlObject.cpp.
|
| FixedFunctionPipeline () |
| Instantiates the rendering shader.
|
|
void | enable (const ViewState &state, ShaderSelection shaderSelection=ShaderSelection::Default, const OrderIndependentTransparency *oit=nullptr) |
| Enables the rendering shader and resets all state to the default settings.
|
|
void | enableWithoutReset (ShaderSelection shaderSelection, const OrderIndependentTransparency *oit=nullptr) |
| Enables the rendering shader without resetting all state to the default.
|
|
void | disable () |
| Disables the rendering shader.
|
|
void | reset (const ViewState &state) |
| Resets the rendering shader to the default settings.
|
|
void | setProjectionMatrix (const mat4 &matrix) |
| Sets the projection matrix.
|
|
void | setViewMatrix (const mat4 &matrix) |
| Sets the view matrix.
|
|
void | setModelMatrix (const mat4 &matrix) |
| Sets the model matrix.
|
|
void | setDefaultColor (const vec3 &color) |
| Sets the default color with full opacity to use in case no per-vertex colors are specified.
|
|
void | setDefaultColor (const vec4 &color) |
| Sets the default color to use in case no per-vertex colors are specified.
|
|
void | enableTexturing (const Texture &texture) |
| Enables texturing using the given texture.
|
|
void | enableTexturing (const Texture &texture, const Sampler &samplingParameters) |
| Enables texturing using the given texture and sampling parameters.
|
|
void | setTexCoordTransform (const vec3 &scaling, const vec3 &offset) |
| Configure an optional linear texture coordinate transformation to apply before texture lookup.
|
|
void | disableTexturing () |
| Disables texturing.
|
|
void | setPointSize (double widthPx) |
| Sets the diameter of the rendered points in px, will incorporate the GL::dpiScale().
|
|
void | enablePointSmoothing () |
| Enables point smoothing.
|
|
void | disablePointSmoothing () |
| Disables point smoothing.
|
|
void | setLineWidth (double lineWidth) |
| Sets the width of the rendered lines in px, will incorporate the GL::dpiScale().
|
|
void | setStipplePattern (uint16_t stipplePattern) |
| Sets the stipple pattern of the rendered lines.
|
|
void | setStippleFactor (double stippleFactor) |
| Sets the factor determining the length of the rendered stipple pattern.
|
|