Skip to main content

RenderPassFactory.ixx File

Factory for creating LegacyRenderPass objects from scene snapshots. More...

Included Headers

Namespaces Index

namespacehelios
namespacerendering

Graphics rendering infrastructure. More...

Classes Index

classRenderPassFactory

Factory for constructing `LegacyRenderPass` objects from scene snapshots. More...

Macro Definitions Index

#defineHELIOS_LOG_SCOPE   "helios::rendering::RenderPassFactory"

Description

Factory for creating LegacyRenderPass objects from scene snapshots.

Macro Definitions

HELIOS_LOG_SCOPE

#define HELIOS_LOG_SCOPE   "helios::rendering::RenderPassFactory"

Definition at line 24 of file RenderPassFactory.ixx.

24#define HELIOS_LOG_SCOPE "helios::rendering::RenderPassFactory"

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file RenderPassFactory.ixx
3 * @brief Factory for creating LegacyRenderPass objects from scene snapshots.
4 */
5module;
6
7#include <memory>
8#include <ostream>
9
10export module helios.rendering.RenderPassFactory;
11
12import helios.scene.Snapshot;
13import helios.scene.SnapshotItem;
14
15import helios.rendering.LegacyRenderPass;
16import helios.rendering.RenderQueue;
17
18import helios.rendering.shader.UniformSemantics;
19import helios.rendering.shader.UniformValueMap;
20
21import helios.util.log.Logger;
22import helios.util.log.LogManager;
23
24#define HELIOS_LOG_SCOPE "helios::rendering::RenderPassFactory"
25export namespace helios::rendering {
26
27 /**
28 * @brief Factory for constructing `LegacyRenderPass` objects from scene snapshots.
29 *
30 * `RenderPassFactory` transforms high-level scene data (`Snapshot` and `SnapshotItem`)
31 * into low-level rendering commands suitable for the rendering device. It creates
32 * `LegacyRenderPass` objects with populated `RenderQueue`s and configured frame uniforms.
33 *
34 * ## Responsibilities
35 *
36 * - Build `LegacyRenderPass` objects from `Snapshot` data.
37 * - Populate `RenderQueue` with `MeshRenderCommand` and `TextRenderCommand` objects.
38 * - Configure frame-level uniforms (view/projection matrices).
39 *
40 * ## Usage
41 *
42 * ```cpp
43 * auto& factory = RenderPassFactory::getInstance();
44 * auto snapshot = sceneGraph.createSnapshot(viewport);
45 * auto renderPass = factory.buildRenderPass(snapshot);
46 *
47 * device.beginRenderPass(renderPass);
48 * device.doRender(renderPass);
49 * device.endRenderPass(renderPass);
50 * ```
51 *
52 * @note This class implements a singleton pattern. In the future, the conversion
53 * of high-level scene data into lower-level rendering commands might be
54 * realized with strategies and/or separate factories.
55 *
56 * @see LegacyRenderPass
57 * @see Snapshot
58 * @see SnapshotItem
59 * @see RenderQueue
60 */
62
63 protected:
64 /**
65 * @brief Shared logger instance for all RenderPassFactory objects.
66 */
69 );
70
71 public:
72 /**
73 * @brief Returns the singleton instance of `RenderPassFactory`.
74 *
75 * @return A reference to the single `RenderPassFactory` instance.
76 */
78 static RenderPassFactory instance;
79
80 return instance;
81 }
82
83 /**
84 * @brief Builds a `LegacyRenderPass` from a given `Snapshot`.
85 *
86 * This method orchestrates the creation of a `RenderQueue` and populates it
87 * with render commands derived from the `SnapshotItem`s within the snapshot.
88 * It also sets up frame-specific uniform values (view and projection matrices)
89 * for the `LegacyRenderPass`.
90 *
91 * @param snapshot A const reference to the snapshot containing the scene data
92 * for which the `LegacyRenderPass` is to be built.
93 *
94 * @return A fully constructed `LegacyRenderPass` object containing the render queue
95 * and frame-specific uniforms.
96 *
97 * @see populateRenderQueue()
98 */
99 [[nodiscard]] LegacyRenderPass buildRenderPass(const helios::scene::Snapshot& snapshot) const {
100
101 auto renderQueue = RenderQueue();
102
103 populateRenderQueue(snapshot, renderQueue);
104
105 const auto& projectionMatrix = snapshot.projectionMatrix();
106 const auto& viewMatrix = snapshot.viewMatrix();
107
108 auto frameUniformValues = helios::rendering::shader::UniformValueMap();
109 frameUniformValues.set(helios::rendering::shader::UniformSemantics::ProjectionMatrix, projectionMatrix);
110 frameUniformValues.set(helios::rendering::shader::UniformSemantics::ViewMatrix, viewMatrix);
111
112 return LegacyRenderPass(
113 &snapshot.viewport(),
114 std::move(renderQueue),
115 frameUniformValues
116 );
117 }
118
119 /**
120 * @brief Populates an existing `RenderQueue` with render commands based on a `Snapshot`.
121 *
122 * This method clears the specified `RenderQueue` before adding new commands.
123 * Each `SnapshotItem` in the snapshot is processed via `makeRenderCommand()`.
124 *
125 * @param snapshot A const reference to the `Snapshot` providing scene data.
126 * @param renderQueue A reference to the `RenderQueue` to be filled. This queue
127 * will be cleared before new commands are added.
128 *
129 * @see makeRenderCommand()
130 */
132 const helios::scene::Snapshot& snapshot, helios::rendering::RenderQueue& renderQueue) const {
133
134 // clear the queue
135 renderQueue.clear();
136
137 auto snapshotItems = snapshot.snapshotItems();
138
139 for (const auto& item : snapshotItems) {
140 makeRenderCommand(item, renderQueue);
141 }
142 }
143
144 /**
145 * @brief Emits render commands from a `SnapshotItem` to the render queue.
146 *
147 * This method extracts necessary data from the `SnapshotItem`, sets up the object
148 * uniform values (e.g., model matrix), and delegates to the `Renderable` to emit
149 * its render commands to the queue.
150 *
151 * @param snapshotItem A const reference to the `SnapshotItem` from which to create
152 * render commands.
153 * @param renderQueue A reference to the `RenderQueue` to emit commands to.
154 *
155 * @note If the `Renderable` pointer in the `SnapshotItem` is `nullptr`, a warning
156 * is logged and no commands are emitted.
157 */
159 const helios::scene::SnapshotItem& snapshotItem,
160 helios::rendering::RenderQueue& renderQueue) const noexcept {
161
162 const auto* renderable = snapshotItem.renderable();
163
164 if (renderable == nullptr) {
165 logger_.warn("Renderable no longer available");
166 return;
167 }
168
169 auto objectUniformValues = helios::rendering::shader::UniformValueMap();
170 auto materialUniformValues = helios::rendering::shader::UniformValueMap();
171 objectUniformValues.set(
173 snapshotItem.worldMatrix()
174 );
175
176 renderable->emit(
177 renderQueue,
178 objectUniformValues,
179 materialUniformValues
180 );
181
182 }
183
184 };
185
186}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.