Skip to main content

RenderPrototype.ixx File

An immutable, shared prototype of a renderable object. More...

Included Headers

#include <memory> #include <stdexcept> #include <string> #include <helios.rendering.mesh.Mesh> #include <helios.rendering.material.Material>

Namespaces Index

namespacehelios
namespacerendering

Graphics rendering infrastructure. More...

Classes Index

classRenderPrototype

An immutable, shared prototype of a renderable object. More...

Description

An immutable, shared prototype of a renderable object.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file RenderPrototype.ixx
3 * @brief An immutable, shared prototype of a renderable object.
4 */
5module;
6
7#include <memory>
8#include <stdexcept>
9#include <string>
10
11export module helios.rendering.RenderPrototype;
12
13import helios.rendering.material.Material;
14import helios.rendering.mesh.Mesh;
15
16
17
18export namespace helios::rendering {
19
20
21 /**
22 * @brief An immutable, shared prototype of a renderable object.
23 *
24 * A `RenderPrototype` bundles a specific `Mesh` (geometry) with a specific `Material` (shader and
25 * default properties). It acts as a shared asset definition, serving as a key for efficient
26 * batching and instancing in the rendering pipeline.
27 *
28 * ## Design
29 *
30 * - **Immutable:** Instances are immutable once created, ensuring consistent behavior for all references.
31 * - **Shared:** Designed to be shared across multiple `Renderable` objects via `std::shared_ptr`.
32 * - **Batching Key:** Provides a stable base for per-instance overrides and efficient draw call batching.
33 *
34 * ## Ownership Model
35 *
36 * Both `material_` and `mesh_` use `std::shared_ptr<const T>` to enable safe sharing across
37 * multiple prototypes and renderables. The const qualifier ensures immutability of the
38 * referenced assets.
39 *
40 * ## Usage
41 *
42 * ```cpp
43 * auto material = std::make_shared<Material>(shader, properties);
44 * auto mesh = std::make_shared<OpenGLMesh>(vertices, indices);
45 *
46 * auto prototype = std::make_shared<RenderPrototype>(material, mesh);
47 *
48 * // Share across multiple renderables
49 * MeshRenderable obj1(prototype);
50 * MeshRenderable obj2(prototype, colorOverride);
51 * ```
52 *
53 * @see MeshRenderable
54 * @see Material
55 * @see Mesh
56 */
57 class RenderPrototype final {
58
59 private:
60 /**
61 * @brief A shared pointer to the base Material definition for this prototype.
62 * The Material contains shader information, default uniform values, and render states.
63 * It is shared and immutable.
64 */
65 std::shared_ptr <const helios::rendering::material::Material> material_;
66
67 /**
68 * @brief A shared pointer to the Mesh (geometry) used by this prototype.
69 * The Mesh defines the geometric shape of the object. It is shared and immutable.
70 */
71 std::shared_ptr<const helios::rendering::mesh::Mesh> mesh_;
72
73
74 public:
75
76 ~RenderPrototype() = default;
77
78 /**
79 * @brief Creates a new RenderPrototype using the specified Material and Mesh.
80 *
81 * Both parameters are moved into the prototype to avoid unnecessary reference
82 * count increments. The prototype takes shared ownership of both assets.
83 *
84 * @param material A shared pointer to the immutable Material this RenderPrototype uses.
85 * @param mesh A shared pointer to the immutable Mesh this RenderPrototype uses.
86 *
87 * @throws std::invalid_argument If either material or mesh represent a nullptr.
88 */
90 std::shared_ptr<const helios::rendering::material::Material> material,
91 std::shared_ptr<const helios::rendering::mesh::Mesh> mesh
92 ) :
93 material_(std::move(material)),
94 mesh_(std::move(mesh)) {
95
96 if (!material_) {
97 throw std::invalid_argument("RenderPrototype received material nullptr");
98 }
99 if (!mesh_) {
100 throw std::invalid_argument("RenderPrototype received mesh nullptr");
101 }
102
103 }
104
105 /**
106 * @brief Returns a const reference to the immutable Mesh used by this RenderPrototype.
107 *
108 * The Mesh contains geometric data such as vertices and indices used for rendering.
109 * This method returns a reference to avoid shared_ptr copy overhead.
110 *
111 * @return A const reference to the Mesh object.
112 */
113 [[nodiscard]] const helios::rendering::mesh::Mesh& mesh() const noexcept {
114 return *mesh_;
115 }
116
117
118 /**
119 * @brief Returns a const reference to the immutable Material used by this RenderPrototype.
120 *
121 * The Material contains shader information and default properties. It is guaranteed
122 * to exist and be valid. This method returns a reference to avoid shared_ptr copy overhead.
123 *
124 * @return A const reference to the Material object.
125 */
126 [[nodiscard]] const helios::rendering::material::Material& material() const noexcept {
127 return *material_;
128 }
129
130 };
131
132
133}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.