tron-room-demo: store the framebuffer in panel wire order (fixes swapped colors on HW)
The ST7789 receives pixel bytes high-byte-first, and TFT_eSprite's pushSprite sends the sprite buffer raw — which is why the sprite's own primitives store colors byte-swapped (drawPixel: color = color>>8 | color<<8). RoomViewCore wrote native little-endian values instead, so every pixel reached the panel byte-swapped: BG 0x0002 showed as green (0x0200), the fogged floor 0x0882 as pink (0x8208) — exactly the symptoms reported from hardware. The core now stores pixels in panel wire order (toWire byteswap on store, one 16-bit rotate per pixel); the emulator blit unswaps before the 565-to-8888 expansion, so its output is pixel-identical. Also add -O2 to the firmware env: PlatformIO's default -Os optimizes for size and was likely a large part of the 13 fps report.
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
* RoomViewCore — the RoomView renderer, shared between targets.
|
||||
*
|
||||
* Header-only, device-agnostic: renders the whole scene into a caller
|
||||
* supplied 320x240 RGB565 buffer (the exact pixel format the T-Deck's
|
||||
* ST7789 panel consumes over SPI). On hardware the caller hands in a
|
||||
* TFT_eSprite's frameBuffer() pointer so the rasterizer draws straight
|
||||
* into the sprite — zero copies. In the emulator it is a static array.
|
||||
* supplied 320x240 RGB565 buffer held in PANEL WIRE ORDER — big-endian,
|
||||
* the byte order the ST7789 receives over SPI, the same convention as
|
||||
* TFT_eSprite's own primitives (its drawPixel byteswaps on store). On
|
||||
* hardware the caller hands in a TFT_eSprite's frameBuffer() pointer so
|
||||
* the rasterizer draws straight into the sprite — zero copies. In the
|
||||
* emulator it is a static array, and the shell unswaps+expands to 8888.
|
||||
*
|
||||
* Palette comes from NetDeck's nd_layout.h RGB565 constants; the world
|
||||
* is NetDeck's real demo floorplan via nd_demomap.h / MapSource.
|
||||
@@ -78,9 +80,15 @@ static inline int fogFor(float d) {
|
||||
}
|
||||
|
||||
// --- Drawing helpers (uint16_t throughout) -----------------------------------
|
||||
// The buffer holds pixels in PANEL WIRE ORDER: the ST7789 receives bytes
|
||||
// big-endian (high byte first), and TFT_eSprite's pushSprite sends the
|
||||
// buffer raw — so, exactly like TFT_eSprite's own primitives, we store
|
||||
// byte-swapped values. The emulator blit unswaps on its way to 8888.
|
||||
static inline uint16_t toWire(uint16_t c) { return (uint16_t)((c << 8) | (c >> 8)); }
|
||||
|
||||
static inline void putPixel(int x, int y, uint16_t c) {
|
||||
if (x < 0 || x >= W || y < 0 || y >= H || !g_fb) return;
|
||||
g_fb[y * W + x] = c;
|
||||
g_fb[y * W + x] = toWire(c);
|
||||
}
|
||||
|
||||
static void drawLine(int x0, int y0, int x1, int y1, uint16_t color) {
|
||||
@@ -102,13 +110,14 @@ static void fillCircle(int cx, int cy, int r, uint16_t color) {
|
||||
if (x * x + y * y <= r * r) putPixel(cx + x, cy + y, color);
|
||||
}
|
||||
|
||||
// Horizontal span with clipping.
|
||||
// Horizontal span with clipping. Writes in panel wire order (see toWire).
|
||||
static inline void hline(int y, int xa, int xb, uint16_t c) {
|
||||
if (y < 0 || y >= H || !g_fb) return;
|
||||
if (xa > xb) { int t = xa; xa = xb; xb = t; }
|
||||
if (xb < 0 || xa >= W) return;
|
||||
if (xa < 0) xa = 0;
|
||||
if (xb >= W) xb = W - 1;
|
||||
c = toWire(c);
|
||||
for (int x = xa; x <= xb; x++) g_fb[y * W + x] = c;
|
||||
}
|
||||
|
||||
@@ -368,8 +377,11 @@ static void rvFrame(float dt, unsigned long nowMs) {
|
||||
}
|
||||
}
|
||||
|
||||
// --- clear the 565 device framebuffer ---
|
||||
for (int i = 0; i < W * H; i++) g_fb[i] = COL_BG;
|
||||
// --- clear the 565 device framebuffer (panel wire order) ---
|
||||
{
|
||||
uint16_t bg = toWire(COL_BG);
|
||||
for (int i = 0; i < W * H; i++) g_fb[i] = bg;
|
||||
}
|
||||
|
||||
// --- floor: flat lit quads for every non-wall tile, checker shaded ---
|
||||
for (int ty = 0; ty < nd::TILE_ROWS; ty++) {
|
||||
|
||||
Reference in New Issue
Block a user