TextRenderPrototype Class
Immutable, shared prototype for text rendering configuration. More...
Declaration
Public Constructors Index
| TextRenderPrototype (std::shared_ptr< const helios::rendering::shader::Shader > shader, std::shared_ptr< const helios::rendering::text::TextShaderProperties > textProperties, helios::rendering::text::FontResourceProvider *fontResourceProvider) | |
|
Constructs a text render prototype. More... | |
Public Member Functions Index
| const helios::rendering::shader::Shader & | shader () const noexcept |
|
Returns the shader. More... | |
| helios::rendering::text::FontResourceProvider & | fontResourceProvider () const noexcept |
|
Returns the font resource provider. More... | |
| const helios::rendering::text::TextShaderProperties & | textProperties () const noexcept |
|
Returns the text shader properties. More... | |
Private Member Attributes Index
| std::shared_ptr< const helios::rendering::shader::Shader > | shader_ |
|
The shader used for rendering text. More... | |
| std::shared_ptr< const helios::rendering::text::TextShaderProperties > | textProperties_ |
|
Text-specific shader properties (e.g., color). More... | |
| helios::rendering::text::FontResourceProvider * | fontResourceProvider_ |
|
Provider for loading fonts and retrieving glyph data. More... | |
Description
Immutable, shared prototype for text rendering configuration.
`TextRenderPrototype` holds the shader and text properties that are shared across multiple `TextRenderable` instances. This reduces memory usage and allows efficient batching of text with the same configuration.
## Design
- **Immutable:** Configuration cannot be changed after construction.
- **Shared:** Multiple `TextRenderable` objects can reference the same prototype.
- **Reduced Duplication:** Avoids redundant storage of shader and property data.
## Usage
```cpp auto shader = std::make_shared<LegacyOpenGLShader>(...); auto textProps = std::make_shared<TextShaderProperties>(textColor);
// Get font provider from rendering device auto& fontProvider = device.fontResourceProvider(); fontProvider.loadFont(FontId{"roboto"}, "fonts/Roboto.ttf");
auto prototype = std::make_shared<TextRenderPrototype>(shader, textProps, &fontProvider);
// Share prototype across multiple renderables TextRenderable title(std::make_unique<TextMesh>("Title", fontId), prototype); TextRenderable score(std::make_unique<TextMesh>("Score: 0", fontId), prototype); ```
## Performance Considerations
**PERF-NOTE: shared_ptr for shader and properties**
The `shader_` and `textProperties_` members use `std::shared_ptr`. Since prototypes are typically long-lived and shared across many renderables, the ref-counting overhead is amortized. However:
- Avoid copying `TextRenderPrototype` shared_ptrs in tight loops. The prototype getters return references, which is the correct pattern.
- The `fontResourceProvider_` uses a raw pointer intentionally to avoid circular references and unnecessary ref-counting-this is the preferred pattern for service-like dependencies with well-defined lifetimes.
- See Also
- See Also
- See Also
- See Also
Shader
Definition at line 71 of file TextRenderPrototype.ixx.
Public Constructors
TextRenderPrototype()
| inline explicit |
Constructs a text render prototype.
- Parameters
-
shader The shader to use for text rendering.
textProperties Text-specific shader properties.
fontResourceProvider Raw pointer to the font resource provider (must remain valid for the lifetime of this prototype).
- Exceptions
-
std::invalid_argument If `shader`, `textProperties`, or `fontResourceProvider` is null.
Definition at line 105 of file TextRenderPrototype.ixx.
References fontResourceProvider, shader and textProperties.
Public Member Functions
fontResourceProvider()
| inline nodiscard noexcept |
Returns the font resource provider.
The font resource provider is used to load fonts and retrieve glyph data for text layout and rendering.
- Returns
Reference to the font resource provider.
Definition at line 146 of file TextRenderPrototype.ixx.
Referenced by TextRenderPrototype.
shader()
| inline nodiscard noexcept |
Returns the shader.
- Returns
Reference to the shader used for text rendering.
Definition at line 134 of file TextRenderPrototype.ixx.
Referenced by TextRenderPrototype.
textProperties()
| inline nodiscard noexcept |
Returns the text shader properties.
- Returns
Reference to the text-specific properties.
Definition at line 155 of file TextRenderPrototype.ixx.
Referenced by TextRenderPrototype.
Private Member Attributes
fontResourceProvider_
|
Provider for loading fonts and retrieving glyph data.
Non-owning raw pointer. The font resource provider must remain valid for the lifetime of this prototype.
Definition at line 91 of file TextRenderPrototype.ixx.
shader_
|
The shader used for rendering text.
Definition at line 78 of file TextRenderPrototype.ixx.
textProperties_
|
Text-specific shader properties (e.g., color).
Definition at line 83 of file TextRenderPrototype.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.