5#include <unordered_map>
15 int x = 0,
y = 0,
w = 0,
h = 0;
19 : width_(
width), height_(
height), shelf_y_(0), shelf_h_(0), shelf_x_(0) {}
24 void reset() { shelf_y_ = 0; shelf_h_ = 0; shelf_x_ = 0; }
25 int width()
const {
return width_; }
26 int height()
const {
return height_; }
31 if (width_ <= 0 || height_ <= 0)
return 0;
32 return static_cast<std::size_t
>(width_) *
33 static_cast<std::size_t
>(height_);
43 if (width_ <= 0 || height_ <= 0 ||
44 (shelf_y_ <= 0 && shelf_x_ <= 0)) {
47 const std::size_t completed =
48 static_cast<std::size_t
>(shelf_y_) *
49 static_cast<std::size_t
>(width_);
50 const std::size_t in_progress =
51 static_cast<std::size_t
>(shelf_x_) *
52 static_cast<std::size_t
>(shelf_h_);
53 return completed + in_progress;
60 if (cap == 0)
return 0.0f;
61 return static_cast<float>(
used_area()) /
static_cast<float>(cap);
66 int shelf_y_, shelf_h_, shelf_x_;
73 explicit ImageAtlas(
int size = 2048) : packer_(size, size) {}
87 size_t evict_stale(uint64_t current_frame, uint64_t max_age = 120);
94 int width()
const {
return packer_.width(); }
95 int height()
const {
return packer_.height(); }
96 float occupancy()
const {
return packer_.occupancy(); }
100 std::unordered_map<uint64_t, Entry> entries_;
112 bool has(uint64_t key)
const {
return entries_.find(key) != entries_.end(); }
118 size_t evict_stale(uint64_t current_frame, uint64_t max_age = 120);
129 if (max_rows_ <= 0)
return 0.0f;
130 return static_cast<float>(next_row_) /
static_cast<float>(max_rows_);
134 std::unordered_map<uint64_t, Entry> entries_;
149 explicit GlyphAtlas(
int size = 1024) : packer_(size, size) {}
155 size_t evict_stale(uint64_t current_frame, uint64_t max_age = 300);
160 int width()
const {
return packer_.width(); }
161 int height()
const {
return packer_.height(); }
166 std::unordered_map<uint64_t, Entry> entries_;
178 explicit PathAtlas(
int size = 2048) : packer_(size, size) {}
184 size_t evict_stale(uint64_t current_frame, uint64_t max_age = 600);
189 int width()
const {
return packer_.width(); }
190 int height()
const {
return packer_.height(); }
195 std::unordered_map<uint64_t, Entry> entries_;
203 if (!pool_.empty()) {
204 auto v = std::move(pool_.back());
213 if (pool_.size() < max_pool_size_) {
214 pool_.push_back(std::move(v));
221 std::vector<std::vector<T>> pool_;
222 size_t max_pool_size_ = 32;
Simple rectangle packer for atlas allocation.
Definition texture_atlas.hpp:12
std::size_t used_area() const
Texels consumed by the shelf allocator so far.
Definition texture_atlas.hpp:42
std::size_t capacity() const
Area of the atlas surface (width × height), in texels.
Definition texture_atlas.hpp:30
AtlasPacker(int width, int height)
Definition texture_atlas.hpp:18
void reset()
Definition texture_atlas.hpp:24
int width() const
Definition texture_atlas.hpp:25
float occupancy() const
Fraction of the atlas the shelf allocator has consumed, in [0, 1].
Definition texture_atlas.hpp:58
int height() const
Definition texture_atlas.hpp:26
bool allocate(int w, int h, Region &out)
Try to allocate a region of the given size. Returns false if full.
Buffer pool — reuses std::vector allocations in hot rendering paths.
Definition texture_atlas.hpp:200
std::vector< T > acquire()
Definition texture_atlas.hpp:202
void release(std::vector< T > v)
Definition texture_atlas.hpp:212
size_t pool_size() const
Definition texture_atlas.hpp:218
int height() const
Definition texture_atlas.hpp:161
float occupancy() const
Definition texture_atlas.hpp:162
GlyphAtlas(int size=1024)
Definition texture_atlas.hpp:149
bool allocate(uint64_t glyph_key, int w, int h, AtlasPacker::Region &out)
int width() const
Read-only introspection for the inspector's atlas viewer.
Definition texture_atlas.hpp:160
size_t entry_count() const
Definition texture_atlas.hpp:157
size_t evict_stale(uint64_t current_frame, uint64_t max_age=300)
void mark_used(uint64_t key, uint64_t frame)
Gradient atlas — caches evaluated gradient ramps as GPU textures.
Definition texture_atlas.hpp:105
void mark_used(uint64_t key, uint64_t frame)
size_t entry_count() const
Definition texture_atlas.hpp:120
float occupancy() const
Definition texture_atlas.hpp:128
int row_capacity() const
Read-only introspection for the inspector's atlas viewer.
Definition texture_atlas.hpp:126
bool allocate(uint64_t key, int &row)
bool has(uint64_t key) const
Definition texture_atlas.hpp:112
size_t evict_stale(uint64_t current_frame, uint64_t max_age=120)
int rows_used() const
Definition texture_atlas.hpp:127
bool allocate(uint64_t key, int w, int h, AtlasPacker::Region &out)
Try to allocate space for an image. Returns the region, or empty on failure.
float occupancy() const
Definition texture_atlas.hpp:96
void mark_used(uint64_t key, uint64_t frame)
int width() const
Read-only introspection for the inspector's atlas viewer.
Definition texture_atlas.hpp:94
void release(uint64_t key)
size_t evict_stale(uint64_t current_frame, uint64_t max_age=120)
Evict entries not used since the given frame.
size_t entry_count() const
Definition texture_atlas.hpp:91
ImageAtlas(int size=2048)
Definition texture_atlas.hpp:73
int height() const
Definition texture_atlas.hpp:95
size_t entry_count() const
Definition texture_atlas.hpp:186
size_t evict_stale(uint64_t current_frame, uint64_t max_age=600)
int width() const
Read-only introspection for the inspector's atlas viewer.
Definition texture_atlas.hpp:189
bool allocate(uint64_t path_hash, int w, int h, AtlasPacker::Region &out)
PathAtlas(int size=2048)
Definition texture_atlas.hpp:178
void mark_used(uint64_t key, uint64_t frame)
float occupancy() const
Definition texture_atlas.hpp:191
int height() const
Definition texture_atlas.hpp:190
Definition gpu_fwd.hpp:31
Definition texture_atlas.hpp:14
int x
Definition texture_atlas.hpp:15
int y
Definition texture_atlas.hpp:15
int h
Definition texture_atlas.hpp:15
int w
Definition texture_atlas.hpp:15
Definition texture_atlas.hpp:144
AtlasPacker::Region region
Definition texture_atlas.hpp:145
uint64_t last_used
Definition texture_atlas.hpp:146
Definition texture_atlas.hpp:107
uint64_t last_used
Definition texture_atlas.hpp:109
int row
Row in the atlas texture.
Definition texture_atlas.hpp:108
Definition texture_atlas.hpp:75
uint64_t last_used_frame
Definition texture_atlas.hpp:78
uint64_t ref_count
Definition texture_atlas.hpp:77
AtlasPacker::Region region
Definition texture_atlas.hpp:76
Definition texture_atlas.hpp:173
uint64_t last_used
Definition texture_atlas.hpp:175
AtlasPacker::Region region
Definition texture_atlas.hpp:174