yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
background_buffer.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GFX_BACKGROUND_BUFFER_H
2#define YAZE_APP_GFX_BACKGROUND_BUFFER_H
3
4#include <cstdint>
5#include <vector>
6
9
10namespace yaze {
11namespace gfx {
12
13enum class BG1RevealMaskSource : uint8_t {
14 kBG2Layout = 1 << 0,
15 kBG2Objects = 1 << 1,
16};
17
19 public:
20 BackgroundBuffer(int width = 512, int height = 512);
21
22 // Buffer manipulation methods
23 void SetTileAt(int x, int y, uint16_t value);
24 uint16_t GetTileAt(int x, int y) const;
25 void ClearBuffer();
26
27 // Drawing methods
28 void DrawTile(const TileInfo& tile_info, uint8_t* canvas,
29 const uint8_t* tiledata, int indexoffset);
30 void DrawBackground(std::span<uint8_t> gfx16_data);
31
32 // Floor drawing methods
33 void DrawFloor(const std::vector<uint8_t>& rom_data, int tile_address,
34 int tile_address_floor, uint8_t floor_graphics);
35
36 // Ensure bitmap is initialized before accessing
37 // Call this before using bitmap() if the buffer was created standalone
39
40 // Priority buffer methods for per-tile priority support
41 // SNES Mode 1 uses priority bits to control Z-ordering between layers
43 uint8_t GetPriorityAt(int x, int y) const;
44 void SetPriorityAt(int x, int y, uint8_t priority);
45 const std::vector<uint8_t>& priority_data() const { return priority_buffer_; }
46 std::vector<uint8_t>& mutable_priority_data();
47
48 // Coverage buffer methods for per-pixel "this layer wrote here" tracking.
49 //
50 // This is critical for accurate dungeon compositing: a tilemap entry can
51 // legally be fully transparent (all pixels == 0), and it still overwrites
52 // whatever was previously on that BG. With separate Layout/Object buffers,
53 // we need an explicit coverage mask to distinguish:
54 // - "object layer didn't write here" (fall back to layout), vs
55 // - "object layer wrote transparent here" (clear layout; reveal BG2/backdrop).
57 const std::vector<uint8_t>& coverage_data() const { return coverage_buffer_; }
58 std::vector<uint8_t>& mutable_coverage_data();
59
60 // Per-pixel cross-layer reveal bits carried by raw BG1 target buffers.
61 // Each bit identifies the BG2 source layer that requested the reveal, so
62 // compositing can ignore that request when its owner is hidden while later
63 // BG1 writes can clear only the source bit they supersede.
64 void ClearBG1RevealMask();
66 void ClearBG1RevealMaskRect(BG1RevealMaskSource source, int start_x,
67 int start_y, int width, int height);
68 void SetBG1RevealMaskRect(BG1RevealMaskSource source, int start_x,
69 int start_y, int width, int height);
70 const std::vector<uint8_t>& bg1_reveal_mask_data() const {
72 }
73 std::vector<uint8_t>& mutable_bg1_reveal_mask_data();
74
75 // Accessors
76 std::vector<uint16_t>& buffer() { return buffer_; }
77 const std::vector<uint16_t>& buffer() const { return buffer_; }
78 auto& bitmap() { return bitmap_; }
79 const gfx::Bitmap& bitmap() const { return bitmap_; }
80
81 private:
86
87 std::vector<uint16_t> buffer_;
88 std::vector<uint8_t> priority_buffer_; // Per-pixel priority (0 or 1)
89 std::vector<uint8_t> coverage_buffer_; // Per-pixel coverage (0=unset,1=set)
90 std::vector<uint8_t> bg1_reveal_mask_buffer_; // Per-pixel BG1 reveal mask
92 int width_;
94};
95
96} // namespace gfx
97} // namespace yaze
98
99#endif // YAZE_APP_GFX_BACKGROUND_BUFFER_H
void DrawTile(const TileInfo &tile_info, uint8_t *canvas, const uint8_t *tiledata, int indexoffset)
void DrawBackground(std::span< uint8_t > gfx16_data)
const std::vector< uint16_t > & buffer() const
const std::vector< uint8_t > & bg1_reveal_mask_data() const
void SetBG1RevealMaskRect(BG1RevealMaskSource source, int start_x, int start_y, int width, int height)
std::vector< uint8_t > & mutable_bg1_reveal_mask_data()
BackgroundBuffer(int width=512, int height=512)
const std::vector< uint8_t > & coverage_data() const
std::vector< uint8_t > coverage_buffer_
void SetPriorityAt(int x, int y, uint8_t priority)
std::vector< uint8_t > & mutable_priority_data()
std::vector< uint8_t > bg1_reveal_mask_buffer_
uint8_t GetPriorityAt(int x, int y) const
void SetTileAt(int x, int y, uint16_t value)
void DrawFloor(const std::vector< uint8_t > &rom_data, int tile_address, int tile_address_floor, uint8_t floor_graphics)
const gfx::Bitmap & bitmap() const
std::vector< uint8_t > priority_buffer_
std::vector< uint8_t > & mutable_coverage_data()
std::vector< uint16_t > & buffer()
void ClearBG1RevealMaskRect(BG1RevealMaskSource source, int start_x, int start_y, int width, int height)
uint16_t GetTileAt(int x, int y) const
const std::vector< uint8_t > & priority_data() const
std::vector< uint16_t > buffer_
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:67
SNES 16-bit tile metadata container.
Definition snes_tile.h:52