Skip to main content

TextRenderPrototype Class

Immutable, shared prototype for text rendering configuration. More...

Declaration

class helios::rendering::text::TextRenderPrototype { ... }

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

TextRenderable

See Also

TextShaderProperties

See Also

FontResourceProvider

See Also

Shader

Definition at line 71 of file TextRenderPrototype.ixx.

Public Constructors

TextRenderPrototype()

helios::rendering::text::TextRenderPrototype::TextRenderPrototype (std::shared_ptr< const helios::rendering::shader::Shader > shader, std::shared_ptr< const helios::rendering::text::TextShaderProperties > textProperties, helios::rendering::text::FontResourceProvider * fontResourceProvider)
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.

106 std::shared_ptr<const helios::rendering::shader::Shader> shader,
107 std::shared_ptr<const helios::rendering::text::TextShaderProperties> textProperties,
109
110 ) :
111 shader_(std::move(shader)),
112 textProperties_(std::move(textProperties)),
113 fontResourceProvider_(fontResourceProvider) {
114
115 if (!shader_) {
116 throw std::invalid_argument("RenderPrototype received null shader");
117 }
118
119 if (!fontResourceProvider_) {
120 throw std::invalid_argument("RenderPrototype received null fontResourceProvider");
121 }
122
123 if (!textProperties_) {
124 throw std::invalid_argument("RenderPrototype received null textProperties");
125 }
126
127 }

References fontResourceProvider, shader and textProperties.

Public Member Functions

fontResourceProvider()

helios::rendering::text::FontResourceProvider & helios::rendering::text::TextRenderPrototype::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.

147 return *fontResourceProvider_;
148 }

Referenced by TextRenderPrototype.

shader()

const helios::rendering::shader::Shader & helios::rendering::text::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.

134 [[nodiscard]] const helios::rendering::shader::Shader& shader() const noexcept {
135 return *shader_;
136 }

Referenced by TextRenderPrototype.

textProperties()

const helios::rendering::text::TextShaderProperties & helios::rendering::text::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.

155 [[nodiscard]] const helios::rendering::text::TextShaderProperties& textProperties() const noexcept {
156 return *textProperties_;
157 }

Referenced by TextRenderPrototype.

Private Member Attributes

fontResourceProvider_

helios::rendering::text::FontResourceProvider* helios::rendering::text::TextRenderPrototype::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_

std::shared_ptr<const helios::rendering::shader::Shader> helios::rendering::text::TextRenderPrototype::shader_

The shader used for rendering text.

Definition at line 78 of file TextRenderPrototype.ixx.

78 std::shared_ptr <const helios::rendering::shader::Shader> shader_;

textProperties_

std::shared_ptr<const helios::rendering::text::TextShaderProperties> helios::rendering::text::TextRenderPrototype::textProperties_

Text-specific shader properties (e.g., color).

Definition at line 83 of file TextRenderPrototype.ixx.

83 std::shared_ptr <const helios::rendering::text::TextShaderProperties> textProperties_;

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.