Skip to content

DisplaySurface

public class DisplaySurface

A writable pixel surface on a mesh’s material, the render half of a display component (an SPI TFT, an LED matrix, a character LCD), reached as Rendering.<Mesh>.Display. Component logic hands it raw RGB565 framebuffers (big-endian, row-major, the layout Circuit.ReadFramebuffer snapshots). SetPixels is the picture the panel makes itself, uploaded as EMISSION over a black albedo: an OLED, a backlit TFT or LED texels glow, so scene light never washes the image, black pixels stay black in a lit room and the frame stays readable in a dark one (modulate Material.EmissionEnergyMultiplier for backlight brightness). SetReflectedPixels adds the picture the panel shows by the light that falls on it, uploaded as the ALBEDO, for anything that is seen by room light too: a transflective LCD with its backlight off, an e-ink sheet, a segment display. Material.AlbedoColor then scales it. Allocates nothing until the first call, so every mesh has one for free. Gate calls on Circuit.FramebufferVersion: each call is a full convert and GPU upload.

public void SetPixels(int width, int height, byte[] rgb565);

Upload a full frame of RGB565 pixels (2 bytes per pixel, high byte first, the order an ST7735 receives them over SPI) to this mesh’s material as the picture the panel makes itself: its emission. First call creates the texture and binds it (emission over a black albedo unless SetReflectedPixels has given the albedo a picture, nearest-neighbour filtering); later calls update it in place. Does nothing when a size is not positive or rgb565 holds fewer than 2 bytes per pixel. Also re-arms the render-on-demand latch, so only call when the framebuffer version actually moved. Main thread (Update).

Parameters

  • width: Frame width in pixels.
  • height: Frame height in pixels.
  • rgb565: The pixels, one row after another, 2 bytes each.
public void SetReflectedPixels(int width, int height, byte[] rgb565);

Upload a full frame of RGB565 pixels, laid out as for SetPixels, as the picture the panel shows by the light that falls on it: its albedo, lit by the scene like any surface and scaled by Material.AlbedoColor (set it to white to show the picture as given). A panel seen only this way (e-ink) never calls SetPixels; one that glows and reflects (a character LCD, with or without its backlight) calls both with the same size, and with its emission at zero only this picture is left. Same costs and rules as SetPixels: a full upload each call, main thread.

Parameters

  • width: Frame width in pixels.
  • height: Frame height in pixels.
  • rgb565: The pixels, one row after another, 2 bytes each.

static

public static void Rgb565ToRgba8(byte[] rgb565, byte[] rgba, int pixels);

Expand big-endian RGB565 into RGBA8 (bit-replicated so full-scale 0x1F/0x3F reach 255, alpha always 255). rgba must hold 4 bytes per pixel. Public and pure so the headless test suite can pin the conversion.

Generated from the CRUMB source, commit fcec660d, 2026-10-29.