Skip to content

RGB layers

Adan edited this page Aug 7, 2020 · 6 revisions

Introduction

The MMSP2 supports 5 RGB layers, of which the first four (REGION1 - REGION4 in Orcus) are of configurable size and position; REGION5 is always the full size of the screen (320x240). One can turn all the layers on and off individually, as well as specify alpha blending when overlaid on one another, and colour key transparency.

All layers must use the same colour mode, and use consecutive blocks of memory (i.e. one has to allocate enough space for all the layers one wishes to use).

Colour modes

The RGB layers can be configured to use a variety of colour modes by using rgbSetPixelFormat(format), these are summarised below.

Mode Bits per pixel Word data format (letters represent pixels) Note
P4BPP 4 0xABCDEFGH Each nibble is an index into the hardware colour palette (up to 16 colours)
P8BPP 8 0xAABBCCDD Each byte is an index into the hardware colour palette (up to 256 colours)
RGB565 16 0xAAAABBBB 16 bits per pixel in RGB565 format
RGB888 24 0xBBAAAAAA 24 bits per pixel in RGB888 format, no gaps between pixels

Enabling layers

To enable a layer, one must first set the pixel format and the base address of the graphic data, then configure the position of the layer and finally turn it on:

  #define RED 0xF800

  uint16_t* fb = malloc(320*240*2);

  rgbSetPixelFormat(RGB565);
  rgbRegionNoBlend(REGION1);
  rgbSetRegionPosition(REGION1, 0, 0, 320, 240);
  for(int i = 320*240 ; i-- ; ) {
    *(fb+i) = RED;
  }
  rgbSetFbAddress((void*)fb);
  rgbToggleRegion(REGION1, true);

Blending

Where layers overlap, there are 3 options for how to combine the pixels: no blending (lower numbered regions appear on top of higher numbers); alpha blending (each layer has an individually controllable alpha value); colour key (pixels of a particular colour are not drawn to the screen).

Alpha

One can enable alpha blending for a layer using rgbRegionBlendAlpha(region, alpha) where alpha is 0 - 15.

Colour key

When colour key blending is enabled for a layer (rgbRegionBlendColourKey()), a particular colour of pixel will not be drawn to the screen if it is found within the pixel data. All layers share a single transparency colour, which can be set with rgbColourKey().

No blending

One can turn off blending with rgbRegionNoBlend().

Sync

Orcus provides utility functions for detecting and/or waiting for V/HSync - it is recommended to wait until in a sync period before updating graphic data on the screen, or changing the framebuffer address (e.g. in double buffering) in order to prevent tearing.

lcdWaitNextVsync(), lcdWaitNextHSync()

Clone this wiki locally