libnx  v4.8.0
Data Structures | Macros | Functions
framebuffer.h File Reference

Framebuffer wrapper object, providing support for software rendered graphics. More...

#include "../nvidia/map.h"
#include "native_window.h"

Go to the source code of this file.

Data Structures

struct  Framebuffer
 Framebuffer structure. More...
 

Macros

#define RGBA8(r, g, b, a)   (((r)&0xff)|(((g)&0xff)<<8)|(((b)&0xff)<<16)|(((a)&0xff)<<24))
 Converts red/green/blue/alpha components to packed RGBA8 (i.e. PIXEL_FORMAT_RGBA_8888).
 
#define RGBA8_MAXALPHA(r, g, b)   RGBA8((r),(g),(b),0xff)
 Same as RGBA8 except with alpha=0xff.
 
#define RGBX8(r, g, b)   RGBA8((r),(g),(b),0)
 Converts red/green/blue to packed RGBX8 (i.e. PIXEL_FORMAT_RGBX_8888).
 
#define RGB565(r, g, b)   (((b)&0x1f)|(((g)&0x3f)<<5)|(((r)&0x1f)<<11))
 Converts red/green/blue components to packed RGB565 (i.e. PIXEL_FORMAT_RGB_565)
 
#define RGB565_FROM_RGB8(r, g, b)   RGB565((r)>>3,(g)>>2,(b)>>3)
 Same as RGB565 but accepting 8-bit components as input instead.
 
#define BGRA8(r, g, b, a)   RGBA8((b),(g),(r),(a))
 Converts red/green/blue/alpha components to packed BGR8 (i.e. PIXEL_FORMAT_BGRA_8888).
 
#define BGRA8_MAXALPHA(r, g, b)   RGBA8((b),(g),(r),0xff)
 Same as BGRA8 except with alpha=0xff.
 
#define RGBA4(r, g, b, a)   (((r)&0xf)|(((g)&0xf)<<4)|(((b)&0xf)<<8)|(((a)&0xf)<<12))
 Converts red/green/blue/alpha components to packed RGBA4 (i.e. PIXEL_FORMAT_RGBA_4444).
 
#define RGBA4_MAXALPHA(r, g, b)   RGBA4((r),(g),(b),0xf)
 Same as RGBA4 except with alpha=0xf.
 
#define RGBA4_FROM_RGBA8(r, g, b, a)   RGBA4((r)>>4,(g)>>4,(b)>>4,(a)>>4)
 Same as RGBA4 but accepting 8-bit components as input instead.
 
#define RGBA4_FROM_RGBA8_MAXALPHA(r, g, b)   RGBA4_MAXALPHA((r)>>4,(g)>>4,(b)>>4)
 Same as RGBA4_MAXALPHA except with alpha=0xff.
 

Functions

Result framebufferCreate (Framebuffer *fb, NWindow *win, u32 width, u32 height, u32 format, u32 num_fbs)
 Creates a Framebuffer object. More...
 
Result framebufferMakeLinear (Framebuffer *fb)
 Enables linear framebuffer mode in a Framebuffer, allocating a shadow buffer in the process.
 
void framebufferClose (Framebuffer *fb)
 Closes a Framebuffer object, freeing all resources associated with it.
 
void * framebufferBegin (Framebuffer *fb, u32 *out_stride)
 Begins rendering a frame in a Framebuffer. More...
 
void framebufferEnd (Framebuffer *fb)
 Finishes rendering a frame in a Framebuffer. More...
 

Detailed Description

Framebuffer wrapper object, providing support for software rendered graphics.

Author
fincs

Function Documentation

◆ framebufferBegin()

void* framebufferBegin ( Framebuffer fb,
u32 out_stride 
)

Begins rendering a frame in a Framebuffer.

Parameters
[in]fbPointer to Framebuffer structure.
[out]out_strideOutput variable containing the distance in bytes between rows of pixels in memory.
Returns
Pointer to buffer to which new graphics data should be written to.
Note
When this function is called, a buffer will be dequeued from the corresponding NWindow.
This function will return pointers to different buffers, depending on the number of buffers it was initialized with.
If framebufferMakeLinear was used, this function will instead return a pointer to the shadow linear buffer. In this case, the offset of a pixel is y * out_stride + x * bytes_per_pixel.
Each call to framebufferBegin must be paired with a framebufferEnd call.

◆ framebufferCreate()

Result framebufferCreate ( Framebuffer fb,
NWindow win,
u32  width,
u32  height,
u32  format,
u32  num_fbs 
)

Creates a Framebuffer object.

Parameters
[out]fbOutput Framebuffer structure.
[in]winPointer to the NWindow to which the Framebuffer will be registered.
[in]widthDesired width of the framebuffer (usually 1280).
[in]heightDesired height of the framebuffer (usually 720).
[in]formatDesired pixel format (see PIXEL_FORMAT_* enum).
[in]num_fbsNumber of buffers to create. Pass 1 for single-buffering, 2 for double-buffering or 3 for triple-buffering.
Note
Framebuffer images are stored in Tegra block linear format with 16Bx2 sector ordering, read TRM chapter 20.1 for more details. In order to use regular linear layout, consider calling framebufferMakeLinear after the Framebuffer object is created.
Presently, only the following pixel formats are supported: PIXEL_FORMAT_RGBA_8888 PIXEL_FORMAT_RGBX_8888 PIXEL_FORMAT_RGB_565 PIXEL_FORMAT_BGRA_8888 PIXEL_FORMAT_RGBA_4444

◆ framebufferEnd()

void framebufferEnd ( Framebuffer fb)

Finishes rendering a frame in a Framebuffer.

Parameters
[in]fbPointer to Framebuffer structure.
Note
When this function is called, the written image data will be flushed and queued (presented) in the corresponding NWindow.
If framebufferMakeLinear was used, this function will copy the image from the shadow linear buffer to the actual framebuffer, converting it in the process to the layout expected by the compositor.
Each call to framebufferBegin must be paired with a framebufferEnd call.