yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
texture_atlas.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GFX_TEXTURE_ATLAS_H
2#define YAZE_APP_GFX_TEXTURE_ATLAS_H
3
4#include <map>
5#include <memory>
6#include <vector>
7
8#include "absl/status/status.h"
10
11namespace yaze {
12namespace gfx {
13
36 public:
40 struct AtlasRegion {
41 int x = 0; // X position in atlas
42 int y = 0; // Y position in atlas
43 int width = 0; // Region width
44 int height = 0; // Region height
45 int source_id = -1; // ID of source (e.g., room_id)
46 bool in_use = false; // Whether this region is allocated
47 };
48
54 explicit TextureAtlas(int width = 2048, int height = 2048);
55
66 AtlasRegion* AllocateRegion(int source_id, int width, int height);
67
76 absl::Status PackBitmap(const Bitmap& src, const AtlasRegion& region);
77
87 absl::Status DrawRegion(int source_id, int dest_x, int dest_y);
88
93 void FreeRegion(int source_id);
94
98 void Clear();
99
105 const Bitmap& GetAtlasBitmap() const { return atlas_bitmap_; }
106
112 const AtlasRegion* GetRegion(int source_id) const;
113
117 int width() const { return width_; }
118 int height() const { return height_; }
119
123 struct AtlasStats {
127 int used_pixels = 0;
128 float utilization = 0.0f; // Percentage of atlas in use
129 };
130 AtlasStats GetStats() const;
131
132 private:
135 Bitmap atlas_bitmap_; // Large combined bitmap
136
137 // Simple linear packing for now (future: more efficient algorithms)
138 int next_x_ = 0;
139 int next_y_ = 0;
140 int row_height_ = 0; // Current row height for packing
141
142 // Map source_id → region
143 std::map<int, AtlasRegion> regions_;
144
145 // Simple rect packing helper
146 bool TryPackRect(int width, int height, int& out_x, int& out_y);
147};
148
149} // namespace gfx
150} // namespace yaze
151
152#endif // YAZE_APP_GFX_TEXTURE_ATLAS_H
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:67
Manages multiple textures packed into a single large texture for performance.
AtlasStats GetStats() const
const AtlasRegion * GetRegion(int source_id) const
Get region for a specific source.
absl::Status PackBitmap(const Bitmap &src, const AtlasRegion &region)
Pack a bitmap into an allocated region.
Bitmap & GetAtlasBitmap()
Get the atlas bitmap (contains all packed textures)
void FreeRegion(int source_id)
Free a region and mark it as available.
int width() const
Get atlas dimensions.
TextureAtlas(int width=2048, int height=2048)
Construct texture atlas with specified dimensions.
const Bitmap & GetAtlasBitmap() const
void Clear()
Clear all regions and reset atlas.
absl::Status DrawRegion(int source_id, int dest_x, int dest_y)
Draw a region from the atlas to screen coordinates.
AtlasRegion * AllocateRegion(int source_id, int width, int height)
Allocate a region in the atlas for a source texture.
bool TryPackRect(int width, int height, int &out_x, int &out_y)
std::map< int, AtlasRegion > regions_
Region within the atlas texture.
Get atlas utilization statistics.