@@ -29,37 +29,46 @@ namespace Legacy {
2929 *
3030 * Note: This class is not thread-safe.
3131 */
32- class UboManager final
32+ class NODISCARD UboManager final
3333{
3434public:
35- using RebuildFunction = std::function<void (Legacy:: Functions &gl)>;
35+ using RebuildFunction = std::function<void (Functions &gl)>;
3636
37+ private:
38+ EnumIndexedArray<RebuildFunction, SharedVboEnum> m_rebuildFunctions;
39+ EnumIndexedArray<std::optional<GLuint>, SharedVboEnum> m_boundBuffers;
40+
41+ // Tuple of all block types for shadow storage.
42+ SharedVboBlocks m_shadowBlocks;
43+
44+ public:
3745 UboManager () { invalidateAll (); }
46+ ~UboManager () = default ;
3847 DELETE_CTORS_AND_ASSIGN_OPS (UboManager);
3948
4049public:
4150 /* *
4251 * @brief Accesses the CPU-side shadow copy of a UBO block by its enum.
4352 */
44- template <Legacy:: SharedVboEnum Block>
45- typename Legacy::BlockType <Block>::type &get ()
53+ template <SharedVboEnum Block>
54+ NODISCARD BlockType_t <Block> &get ()
4655 {
47- return std::get<typename Legacy::BlockType <Block>::type >(m_shadowBlocks);
56+ return std::get<BlockType_t <Block>>(m_shadowBlocks);
4857 }
4958
5059 /* *
5160 * @brief Accesses the CPU-side shadow copy of a UBO block by its enum (const).
5261 */
53- template <Legacy:: SharedVboEnum Block>
54- const typename Legacy::BlockType <Block>::type &get () const
62+ template <SharedVboEnum Block>
63+ NODISCARD const BlockType_t <Block> &get () const
5564 {
56- return std::get<typename Legacy::BlockType <Block>::type >(m_shadowBlocks);
65+ return std::get<BlockType_t <Block>>(m_shadowBlocks);
5766 }
5867
5968 /* *
6069 * @brief Marks a UBO block as dirty by resetting its bound state.
6170 */
62- void invalidate (Legacy:: SharedVboEnum block) { m_boundBuffers[block] = std::nullopt ; }
71+ void invalidate (const SharedVboEnum block) { m_boundBuffers[block] = std::nullopt ; }
6372
6473 /* *
6574 * @brief Marks all UBO blocks as dirty.
@@ -78,7 +87,7 @@ class UboManager final
7887 * will trigger a debug assertion. Set to true only when an
7988 * overwrite is intentional.
8089 */
81- void registerRebuildFunction (Legacy:: SharedVboEnum block,
90+ void registerRebuildFunction (const SharedVboEnum block,
8291 RebuildFunction func,
8392 bool allowOverwrite = false )
8493 {
@@ -93,29 +102,32 @@ class UboManager final
93102 /* *
94103 * @brief Unregisters a rebuild function for a UBO block.
95104 */
96- void unregisterRebuildFunction (Legacy:: SharedVboEnum block)
105+ void unregisterRebuildFunction (const SharedVboEnum block)
97106 {
98107 m_rebuildFunctions[block] = nullptr ;
99108 }
100109
101110 /* *
102111 * @brief Checks if a UBO block is currently dirty/invalid.
103112 */
104- bool isInvalid (Legacy::SharedVboEnum block) const { return !m_boundBuffers[block].has_value (); }
113+ NODISCARD bool isInvalid (const SharedVboEnum block) const
114+ {
115+ return !m_boundBuffers[block].has_value ();
116+ }
105117
106118 /* *
107119 * @brief Rebuilds the UBO if it's invalid using the registered rebuild function.
108120 * @return The bound buffer ID, or 0 if failed.
109121 */
110- GLuint updateIfInvalid (Legacy:: Functions &gl, Legacy:: SharedVboEnum block)
122+ ALLOW_DISCARD GLuint updateIfInvalid (Functions &gl, const SharedVboEnum block)
111123 {
112124 if (const auto bound = m_boundBuffers[block]) {
113125 return *bound;
114126 }
115127
116128 const auto &func = m_rebuildFunctions[block];
117129 if (!func) {
118- const char *name = Legacy:: Functions::getUniformBlockName (block);
130+ const char *name = Functions::getUniformBlockName (block);
119131 MMLOG_ERROR () << " UboManager::updateIfInvalid: UBO block '" << name
120132 << " ' is invalid and no rebuild function is registered" ;
121133 throw std::runtime_error (" UBO block '" + std::string (name)
@@ -128,7 +140,7 @@ class UboManager final
128140 return *bound;
129141 }
130142
131- const char *name = Legacy:: Functions::getUniformBlockName (block);
143+ const char *name = Functions::getUniformBlockName (block);
132144 MMLOG_ERROR () << " UboManager::updateIfInvalid: rebuild function failed to call "
133145 " update() for block '"
134146 << name << " '" ;
@@ -144,11 +156,12 @@ class UboManager final
144156 * Overload for bulk vector data.
145157 */
146158 template <typename T, typename A>
147- GLuint update (Legacy::Functions &gl, Legacy::SharedVboEnum block, const std::vector<T, A> &data)
159+ ALLOW_DISCARD GLuint update (Functions &gl,
160+ const SharedVboEnum block,
161+ const std::vector<T, A> &data)
148162 {
149- Legacy::VBO &vbo = getOrCreateVbo (gl, block);
150- static_cast <void >(
151- gl.setVbo (GL_UNIFORM_BUFFER , vbo.get (), data, BufferUsageEnum::DYNAMIC_DRAW ));
163+ VBO &vbo = getOrCreateVbo (gl, block);
164+ gl.setVbo (GL_UNIFORM_BUFFER , vbo.get (), data, BufferUsageEnum::DYNAMIC_DRAW );
152165 return bind_internal (gl, block, vbo.get ());
153166 }
154167
@@ -160,9 +173,9 @@ class UboManager final
160173 * Overload for single trivially-copyable objects.
161174 */
162175 template <typename T>
163- GLuint update (Legacy:: Functions &gl, Legacy:: SharedVboEnum block, const T &data)
176+ ALLOW_DISCARD GLuint update (Functions &gl, const SharedVboEnum block, const T &data)
164177 {
165- Legacy:: VBO &vbo = getOrCreateVbo (gl, block);
178+ VBO &vbo = getOrCreateVbo (gl, block);
166179 gl.setVbo (GL_UNIFORM_BUFFER , vbo.get (), data, BufferUsageEnum::DYNAMIC_DRAW );
167180 return bind_internal (gl, block, vbo.get ());
168181 }
@@ -172,8 +185,8 @@ class UboManager final
172185 * Enforces the correct data structure for the given block identifier.
173186 * Also updates the shadow copy.
174187 */
175- template <Legacy:: SharedVboEnum Block>
176- GLuint update (Legacy:: Functions &gl, const typename Legacy::BlockType <Block>::type &data)
188+ template <SharedVboEnum Block>
189+ ALLOW_DISCARD GLuint update (Functions &gl, const BlockType_t <Block> &data)
177190 {
178191 get<Block>() = data;
179192 return update (gl, Block, data);
@@ -182,8 +195,8 @@ class UboManager final
182195 /* *
183196 * @brief Syncs the entire shadow copy of a block to the GPU.
184197 */
185- template <Legacy:: SharedVboEnum Block>
186- GLuint sync (Legacy:: Functions &gl)
198+ template <SharedVboEnum Block>
199+ ALLOW_DISCARD GLuint sync (Functions &gl)
187200 {
188201 return update (gl, Block, get<Block>());
189202 }
@@ -193,10 +206,10 @@ class UboManager final
193206 * @param gl Legacy functions.
194207 * @param members Pointers to the members in the block struct.
195208 */
196- template <Legacy:: SharedVboEnum Block, typename T, typename ... Us>
197- void syncFields (Legacy:: Functions &gl, Us T::*...members)
209+ template <SharedVboEnum Block, typename T, typename ... Us>
210+ void syncFields (Functions &gl, Us T::*...members)
198211 {
199- using BlockType = typename Legacy::BlockType <Block>::type ;
212+ using BlockType = BlockType_t <Block>;
200213 static_assert (std::is_same_v<T, BlockType>, " Members must belong to the correct block type" );
201214 static_assert (std::is_standard_layout_v<BlockType>,
202215 " Block type must have standard layout for offset calculation" );
@@ -209,7 +222,7 @@ class UboManager final
209222 }
210223
211224 const auto &blockData = get<Block>();
212- Legacy:: VBO &vbo = getOrCreateVbo (gl, Block);
225+ VBO &vbo = getOrCreateVbo (gl, Block);
213226 gl.glBindBuffer (GL_UNIFORM_BUFFER , vbo.get ());
214227
215228 (gl.glBufferSubData (GL_UNIFORM_BUFFER ,
@@ -223,16 +236,16 @@ class UboManager final
223236 gl.glBindBuffer (GL_UNIFORM_BUFFER , 0 );
224237
225238 // Ensure it's bound to the correct point.
226- bind_internal (gl, Block, vbo.get ());
239+ std::ignore = bind_internal (gl, Block, vbo.get ());
227240 }
228241
229242 /* *
230243 * @brief Syncs a specific field of a block to the GPU.
231244 * @param gl Legacy functions.
232245 * @param member Pointer to the member in the block struct.
233246 */
234- template <Legacy:: SharedVboEnum Block, typename T, typename U>
235- void syncField (Legacy:: Functions &gl, U T::*member)
247+ template <SharedVboEnum Block, typename T, typename U>
248+ void syncField (Functions &gl, U T::*member)
236249 {
237250 syncFields<Block>(gl, member);
238251 }
@@ -241,7 +254,7 @@ class UboManager final
241254 * @brief Binds the UBO to its assigned point.
242255 * If invalid and a rebuild function is registered, it will be updated first.
243256 */
244- void bind (Legacy:: Functions &gl, Legacy:: SharedVboEnum block)
257+ void bind (Functions &gl, const SharedVboEnum block)
245258 {
246259 const GLuint buffer = updateIfInvalid (gl, block);
247260
@@ -259,10 +272,10 @@ class UboManager final
259272 }
260273
261274private:
262- Legacy:: VBO &getOrCreateVbo (Legacy:: Functions &gl, Legacy:: SharedVboEnum block)
275+ NODISCARD VBO &getOrCreateVbo (Functions &gl, const SharedVboEnum block)
263276 {
264277 const auto sharedVbo = gl.getSharedVbos ().get (block);
265- Legacy:: VBO &vbo = deref (sharedVbo);
278+ VBO &vbo = deref (sharedVbo);
266279
267280 if (!vbo) {
268281 vbo.emplace (gl.shared_from_this ());
@@ -275,13 +288,13 @@ class UboManager final
275288 * @brief Binds the UBO to its assigned point.
276289 * @return The bound buffer ID.
277290 *
278- * Note: This implementation explicitly assumes that Legacy:: SharedVboEnum values
291+ * Note: This implementation explicitly assumes that SharedVboEnum values
279292 * are 0-based, contiguous, and directly correspond to UBO binding indices in
280293 * shader blocks.
281294 */
282- GLuint bind_internal (Legacy:: Functions &gl, Legacy:: SharedVboEnum block, GLuint buffer)
295+ NODISCARD GLuint bind_internal (Functions &gl, const SharedVboEnum block, const GLuint buffer)
283296 {
284- const auto bindingIndex = Legacy:: getUboBindingIndex (block);
297+ const auto bindingIndex = getUboBindingIndex (block);
285298 assert (static_cast <std::size_t >(bindingIndex) < m_boundBuffers.size ());
286299
287300 auto &bound = m_boundBuffers[block];
@@ -291,13 +304,6 @@ class UboManager final
291304 }
292305 return buffer;
293306 }
294-
295- private:
296- EnumIndexedArray<RebuildFunction, Legacy::SharedVboEnum> m_rebuildFunctions;
297- EnumIndexedArray<std::optional<GLuint>, Legacy::SharedVboEnum> m_boundBuffers;
298-
299- // Tuple of all block types for shadow storage.
300- Legacy::SharedVboBlocks m_shadowBlocks;
301307};
302308
303309} // namespace Legacy
0 commit comments