11/*
2- * Copyright 2019-2022 Diligent Graphics LLC
2+ * Copyright 2019-2025 Diligent Graphics LLC
33 * Copyright 2015-2019 Egor Yusov
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -41,15 +41,30 @@ namespace Diligent
4141{
4242
4343// / Dynamic 2D atlas manager
44+
45+ // / This class manages a 2D atlas of regions. It allows allocating and freeing
46+ // / rectangular regions of the atlas. The regions are represented by the
47+ // / Region structure, which contains the x and y coordinates of the top-left
48+ // / corner, as well as the width and height of the region.
49+ // /
50+ // / \warning The class is not thread-safe. All operations on the atlas must be
51+ // / must be protected by a mutex or other synchronization mechanism.
4452class DynamicAtlasManager
4553{
4654public:
55+ // / Structure representing a rectangular region in the atlas.
4756 struct Region
4857 {
58+ // / x coordinate of the top-left corner of the region
4959 Uint32 x = 0 ;
60+
61+ // / y coordinate of the top-left corner of the region
5062 Uint32 y = 0 ;
5163
52- Uint32 width = 0 ;
64+ // / width of the region
65+ Uint32 width = 0 ;
66+
67+ // / height of the region
5368 Uint32 height = 0 ;
5469
5570 Region () = default ;
@@ -70,6 +85,7 @@ class DynamicAtlasManager
7085 // clang-format on
7186 {}
7287
88+ // / Checks if the region is empty (width or height is zero).
7389 bool IsEmpty () const
7490 {
7591 return width == 0 || height == 0 ;
@@ -108,19 +124,43 @@ class DynamicAtlasManager
108124 DynamicAtlasManager& operator = ( DynamicAtlasManager&&) = delete ;
109125 // clang-format on
110126
127+
128+ // / Allocates a rectangular region in the atlas.
129+
130+ // / \param Width - Width of the region to allocate.
131+ // / \param Height - Height of the region to allocate.
132+ // / \return The allocated region.
133+ // /
134+ // / If the requested region cannot be allocated, an empty region is returned.
111135 Region Allocate (Uint32 Width, Uint32 Height);
112- void Free (Region&& R);
113136
137+
138+ // / Frees a previously allocated region in the atlas.
139+
140+ // / \param R - The region to free.
141+ void Free (Region&& R);
142+
143+
144+ // / Returns the number of free regions in the atlas.
114145 Uint32 GetFreeRegionCount () const
115146 {
116147 VERIFY_EXPR (m_FreeRegionsByWidth.size () == m_FreeRegionsByHeight.size ());
117148 return static_cast <Uint32>(m_FreeRegionsByWidth.size ());
118149 }
119150
151+ // / Returns the atlas width.
120152 Uint32 GetWidth () const { return m_Width; }
153+
154+ // / Returns the atlas height.
121155 Uint32 GetHeight () const { return m_Height; }
156+
157+ // / Returns the total free area of the atlas.
158+
159+ // / The total free area is the sum of the areas of all free regions in the atlas,
160+ // / and thus may be fragmented.
122161 Uint64 GetTotalFreeArea () const { return m_TotalFreeArea; }
123162
163+ // / Checks if the atlas is empty, i.e. if there are no allocated regions.
124164 bool IsEmpty () const
125165 {
126166 VERIFY_EXPR (m_AllocatedRegions.empty () && (m_TotalFreeArea == Uint64{m_Width} * Uint64{m_Height}) ||
0 commit comments