yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
sprite_editor_internal.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_SPRITE_SPRITE_EDITOR_INTERNAL_H_
2#define YAZE_APP_EDITOR_SPRITE_SPRITE_EDITOR_INTERNAL_H_
3
4#include <cstdint>
5#include <vector>
6
8
9namespace yaze {
10namespace editor {
11namespace internal {
12
13// Initialize a sprite-preview bitmap once and queue its texture for creation.
14// Idempotent: returns immediately if the bitmap is already active.
15//
16// SpriteEditor used to call Create()+Reformat() inline, never queueing a
17// CREATE texture command, so canvas_rendering's `if (!texture()) return;`
18// guard skipped the draw silently and the preview was always blank. This
19// helper closes that gap and stamps the bitmap as a composite output (the
20// pixels come from SpriteDrawer rendering OAM tiles into the surface, not
21// from direct user paint).
22//
23// Safe to call every render frame; the `is_active()` short-circuit ensures
24// only the first call does any work.
26 gfx::Bitmap& bmp, int width, int height, int depth,
27 const std::vector<uint8_t>& gfx_buffer) {
28 if (bmp.is_active()) {
29 return;
30 }
31 bmp.Create(width, height, depth, gfx_buffer);
32 if (!bmp.is_active()) {
33 // Create bailed (empty buffer, surface allocation failed). Don't call
34 // Reformat. It would unconditionally allocate a fresh surface and set
35 // active=true with no pixel data, masking the load failure and queuing
36 // a CREATE for an effectively-blank bitmap. Leave the bitmap inactive
37 // so the next frame's call retries Create with a real buffer.
38 return;
39 }
40 bmp.Reformat(depth);
41 if (bmp.surface() != nullptr) {
42 bmp.CreateTexture();
43 }
45}
46
47} // namespace internal
48} // namespace editor
49} // namespace yaze
50
51#endif // YAZE_APP_EDITOR_SPRITE_SPRITE_EDITOR_INTERNAL_H_
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:67
void Create(int width, int height, int depth, std::span< uint8_t > data)
Create a bitmap with the given dimensions and data.
Definition bitmap.cc:201
void Reformat(int format)
Reformat the bitmap to use a different pixel format.
Definition bitmap.cc:277
BitmapMetadata & metadata()
Definition bitmap.h:391
void CreateTexture()
Creates the underlying SDL_Texture to be displayed.
Definition bitmap.cc:293
bool is_active() const
Definition bitmap.h:405
SDL_Surface * surface() const
Definition bitmap.h:400
void EnsureSpritePreviewBitmapReady(gfx::Bitmap &bmp, int width, int height, int depth, const std::vector< uint8_t > &gfx_buffer)