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 "app/gfx/bitmap.h"
9#include "absl/status/status.h"
10
11namespace yaze {
12namespace gfx {
13
34 public:
38 struct AtlasRegion {
39 int x = 0; // X position in atlas
40 int y = 0; // Y position in atlas
41 int width = 0; // Region width
42 int height = 0; // Region height
43 int source_id = -1; // ID of source (e.g., room_id)
44 bool in_use = false; // Whether this region is allocated
45 };
46
52 explicit TextureAtlas(int width = 2048, int height = 2048);
53
63 AtlasRegion* AllocateRegion(int source_id, int width, int height);
64
73 absl::Status PackBitmap(const Bitmap& src, const AtlasRegion& region);
74
84 absl::Status DrawRegion(int source_id, int dest_x, int dest_y);
85
90 void FreeRegion(int source_id);
91
95 void Clear();
96
102 const Bitmap& GetAtlasBitmap() const { return atlas_bitmap_; }
103
109 const AtlasRegion* GetRegion(int source_id) const;
110
114 int width() const { return width_; }
115 int height() const { return height_; }
116
120 struct AtlasStats {
124 int used_pixels = 0;
125 float utilization = 0.0f; // Percentage of atlas in use
126 };
127 AtlasStats GetStats() const;
128
129 private:
132 Bitmap atlas_bitmap_; // Large combined bitmap
133
134 // Simple linear packing for now (future: more efficient algorithms)
135 int next_x_ = 0;
136 int next_y_ = 0;
137 int row_height_ = 0; // Current row height for packing
138
139 // Map source_id → region
140 std::map<int, AtlasRegion> regions_;
141
142 // Simple rect packing helper
143 bool TryPackRect(int width, int height, int& out_x, int& out_y);
144};
145
146} // namespace gfx
147} // namespace yaze
148
149#endif // YAZE_APP_GFX_TEXTURE_ATLAS_H
150
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:66
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.
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_
Main namespace for the application.
Region within the atlas texture.
Get atlas utilization statistics.