OpenGLMeshRenderer Class
OpenGL implementation of the MeshRenderer interface. More...
Declaration
Base class
| class | MeshRenderer |
|
Abstract base class for mesh rendering operations. More... | |
Friends Index
| class | OpenGLDevice |
Public Destructor Index
| ~OpenGLMeshRenderer () override | |
|
Destructor that unbinds any currently bound VAO. More... | |
Public Member Functions Index
| void | render (const helios::rendering::mesh::MeshRenderCommand &command, const helios::rendering::shader::UniformValueMap &frameUniformValues) noexcept |
|
Renders a mesh using the provided render command and frame-level uniforms. More... | |
Private Member Functions Index
| void | init () |
|
Initializes the renderer. More... | |
| void | beginRenderPass (helios::rendering::RenderPass &renderPass) const noexcept |
|
Resets cached rendering state at the beginning of a render pass. More... | |
Private Member Attributes Index
| const helios::ext::opengl::rendering::shader::OpenGLShader * | lastShader_ = nullptr |
|
Cached pointer to the last used shader for state optimization. More... | |
| unsigned int | lastVao_ = 0 |
|
Cached VAO ID for state optimization. More... | |
Description
OpenGL implementation of the MeshRenderer interface.
`OpenGLMeshRenderer` provides the concrete rendering logic for mesh geometry using the OpenGL graphics API. It translates abstract `MeshRenderCommand` objects into OpenGL-specific draw calls, handling shader binding, uniform application, and VAO state management.
## State Caching
This class implements state caching to minimize redundant OpenGL state changes:
- Shader programs are only activated when they differ from the previously used shader.
- VAO bindings are only updated when rendering a mesh with a different VAO.
## Usage
```cpp OpenGLMeshRenderer renderer; MeshRenderCommand command = createRenderCommand(); UniformValueMap frameUniforms = {{"viewMatrix", viewMat}, {"projMatrix", projMat}}; renderer.render(command, frameUniforms); ```
## Ownership
This class is typically owned by `OpenGLDevice` and should not be instantiated directly in most use cases.
The renderer expects all shaders and meshes to be OpenGL-specific implementations (`OpenGLShader` and `OpenGLMesh`). Using incompatible types will trigger assertions.
- See Also
Definition at line 60 of file OpenGLMeshRenderer.ixx.
Friends
OpenGLDevice
|
Definition at line 64 of file OpenGLMeshRenderer.ixx.
Reference OpenGLDevice.
Referenced by OpenGLDevice.
Public Destructor
~OpenGLMeshRenderer()
| inline |
Destructor that unbinds any currently bound VAO.
Ensures clean OpenGL state upon destruction.
Definition at line 116 of file OpenGLMeshRenderer.ixx.
Public Member Functions
render()
| inline noexcept virtual |
Renders a mesh using the provided render command and frame-level uniforms.
This method performs the following steps: 1. Extracts the shader and mesh from the render command's prototype. 2. Activates the shader if it differs from the previously used shader (state caching). 3. Applies frame-level, object-level, and material-level uniform values. 4. Binds the mesh's VAO if it differs from the previously bound VAO (state caching). 5. Issues a `glDrawElements` call with the appropriate primitive type.
- Parameters
-
command The render command containing the render prototype with mesh, material, and per-object uniform data.
frameUniformValues Frame-level uniform values shared across all objects (e.g., view and projection matrices).
If the render command does not contain a valid render prototype, the method returns without issuing any draw calls.
- See Also
MeshRenderCommand
- See Also
UniformValueMap
Definition at line 143 of file OpenGLMeshRenderer.ixx.
Reference helios::ext::opengl::rendering::OpenGLEnumMapper::toOpenGL.
Private Member Functions
beginRenderPass()
| inline noexcept |
Resets cached rendering state at the beginning of a render pass.
This ensures proper shader and VAO binding even when the render queue contents change between frames. Called internally by `OpenGLDevice` before processing the render queue.
- Parameters
-
renderPass The render pass being started (currently unused, reserved for future use).
Definition at line 100 of file OpenGLMeshRenderer.ixx.
init()
| inline |
Initializes the renderer.
Currently a no-op placeholder for future initialization logic.
Definition at line 86 of file OpenGLMeshRenderer.ixx.
Private Member Attributes
lastShader_
| mutable |
Cached pointer to the last used shader for state optimization.
Used to avoid redundant shader program activations. Reset at the beginning of each render pass.
Definition at line 72 of file OpenGLMeshRenderer.ixx.
lastVao_
| mutable |
Cached VAO ID for state optimization.
Used to avoid redundant VAO bindings. Reset at the beginning of each render pass.
Definition at line 79 of file OpenGLMeshRenderer.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.