libctru  v1.6.0
Macros | Enumerations | Variables
gfx.h File Reference

LCD Screens manipulation. More...

#include <3ds/types.h>
#include <3ds/services/gspgpu.h>

Go to the source code of this file.

Macros

#define RGB565(r, g, b)   (((b)&0x1f)|(((g)&0x3f)<<5)|(((r)&0x1f)<<11))
 Converts red, green, and blue components to packed RGB565.
 
#define RGB8_to_565(r, g, b)   (((b)>>3)&0x1f)|((((g)>>2)&0x3f)<<5)|((((r)>>3)&0x1f)<<11)
 Converts packed RGB8 to packed RGB565.
 

Enumerations

enum  gfxScreen_t {
  GFX_TOP = 0,
  GFX_BOTTOM = 1
}
 Available screens. More...
 
enum  gfx3dSide_t {
  GFX_LEFT = 0,
  GFX_RIGHT = 1
}
 Side of top screen framebuffer. More...
 

Functions

System related
void gfxInitDefault (void)
 Initializes the LCD framebuffers with default parameters. More...
 
void gfxInit (GSPGPU_FramebufferFormats topFormat, GSPGPU_FramebufferFormats bottomFormat, bool vrambuffers)
 Initializes the LCD framebuffers. More...
 
void gfxExit (void)
 Closes the gsp service and frees the framebuffers. More...
 
Control
void gfxSet3D (bool enable)
 Enables the 3D stereoscopic effect. More...
 
bool gfxIs3D (void)
 Retrieves the status of the 3D stereoscopic effect. More...
 
void gfxSetScreenFormat (gfxScreen_t screen, GSPGPU_FramebufferFormats format)
 Changes the color format of a screen. More...
 
GSPGPU_FramebufferFormats gfxGetScreenFormat (gfxScreen_t screen)
 Gets a screen pixel format. More...
 
void gfxSetDoubleBuffering (gfxScreen_t screen, bool doubleBuffering)
 Sets whether to use ctrulib's double buffering. More...
 
void gfxFlushBuffers (void)
 Flushes the current framebuffers. More...
 
void gfxConfigScreen (gfxScreen_t scr, bool immediate)
 Updates the configuration of the specified screen (swapping the buffers if double-buffering is enabled). More...
 
void gfxSwapBuffers (void)
 Swaps the buffers and sets the gsp state. More...
 
void gfxSwapBuffersGpu (void)
 Swaps the framebuffers. More...
 
Helper
u8gfxGetFramebuffer (gfxScreen_t screen, gfx3dSide_t side, u16 *width, u16 *height)
 Retrieves a framebuffer information. More...
 

Variables

u8gfxTopLeftFramebuffers [2]
 
u8gfxTopRightFramebuffers [2]
 
u8gfxBottomFramebuffers [2]
 

Detailed Description

LCD Screens manipulation.

This header provides functions to configure and manipulate the two screens, including double buffering and 3D activation. It is mainly an abstraction over the gsp service.

Enumeration Type Documentation

◆ gfx3dSide_t

Side of top screen framebuffer.

This is to be used only when the 3D is enabled. Use only GFX_LEFT if this concerns the bottom screen or if 3D is disabled.

Enumerator
GFX_LEFT 

Left eye framebuffer.

GFX_RIGHT 

Right eye framebuffer.

◆ gfxScreen_t

Available screens.

Enumerator
GFX_TOP 

Top screen.

GFX_BOTTOM 

Bottom screen.

Function Documentation

◆ gfxConfigScreen()

void gfxConfigScreen ( gfxScreen_t  scr,
bool  immediate 
)

Updates the configuration of the specified screen (swapping the buffers if double-buffering is enabled).

Parameters
scrScreen to configure.
immediateWhether to apply the updated configuration immediately or let GSPGPU apply it after the next GX transfer completes.

◆ gfxExit()

void gfxExit ( void  )

Closes the gsp service and frees the framebuffers.

Just call it when you're done.

Examples
app_launch/source/main.c, audio/filters/source/main.c, audio/mic/source/main.c, audio/streaming/source/main.c, camera/image/source/main.c, camera/video/source/main.c, get_system_language/source/main.c, graphics/bitmap/24bit-color/source/main.c, graphics/gpu/both_screens/source/main.c, graphics/gpu/fragment_light/source/main.c, graphics/gpu/geoshader/source/main.c, graphics/gpu/gpusprites/source/main.c, graphics/gpu/immediate/source/main.c, graphics/gpu/lenny/source/main.c, graphics/gpu/loop_subdivision/source/main.c, graphics/gpu/mipmap_fog/source/main.c, graphics/gpu/particles/source/main.c, graphics/gpu/proctex/source/main.c, graphics/gpu/simple_tri/source/main.c, graphics/gpu/textured_cube/source/main.c, graphics/gpu/toon_shading/source/main.c, graphics/printing/both-screen-text/source/main.c, graphics/printing/colored-text/source/main.c, graphics/printing/hello-world/source/main.c, graphics/printing/multiple-windows-text/source/main.c, graphics/printing/system-font/source/main.c, input/read-controls/source/main.c, input/software-keyboard/source/main.c, input/touch-screen/source/main.c, libapplet_launch/source/main.c, mvd/source/main.c, network/boss/source/main.c, network/http/source/main.c, network/http_post/source/main.c, network/sockets/source/sockets.c, network/sslc/source/ssl.c, network/uds/source/uds.c, nfc/source/main.c, qtm/source/main.c, romfs/source/main.c, sdmc/source/main.c, threads/event/source/main.c, threads/thread-basic/source/main.c, and time/rtc/source/main.c.

◆ gfxFlushBuffers()

void gfxFlushBuffers ( void  )

◆ gfxGetFramebuffer()

u8* gfxGetFramebuffer ( gfxScreen_t  screen,
gfx3dSide_t  side,
u16 width,
u16 height 
)

Retrieves a framebuffer information.

Parameters
screenScreen to retrieve framebuffer information for.
sideSide of the screen to retrieve framebuffer information for.
widthPointer that will hold the width of the framebuffer in pixels.
heightPointer that will hold the height of the framebuffer in pixels.
Returns
A pointer to the current framebuffer of the choosen screen.

Please remember that the returned pointer will change after each call to gfxSwapBuffers if double buffering is enabled.

Examples
camera/image/source/main.c, camera/video/source/main.c, graphics/bitmap/24bit-color/source/main.c, mvd/source/main.c, network/http/source/main.c, qtm/source/main.c, and sdmc/source/main.c.

◆ gfxGetScreenFormat()

GSPGPU_FramebufferFormats gfxGetScreenFormat ( gfxScreen_t  screen)

Gets a screen pixel format.

Parameters
screenScreen to get the pixel format of.
Returns
the pixel format of the chosen screen set by ctrulib.

◆ gfxInit()

void gfxInit ( GSPGPU_FramebufferFormats  topFormat,
GSPGPU_FramebufferFormats  bottomFormat,
bool  vrambuffers 
)

Initializes the LCD framebuffers.

Parameters
topFormatThe format of the top screen framebuffers.
bottomFormatThe format of the bottom screen framebuffers.
vramBuffersWhether to allocate the framebuffers in VRAM.

This function will allocate the memory for the framebuffers and open a gsp service session. It will also bind the newly allocated framebuffers to the LCD screen and setup the VBlank event.

The 3D stereoscopic display is will be disabled.

Note
Even if the double buffering is disabled, it will allocate two buffer per screen.
You should always call gfxExit once done to free the memory and services
Examples
mvd/source/main.c.

◆ gfxInitDefault()

void gfxInitDefault ( void  )

Initializes the LCD framebuffers with default parameters.

By default ctrulib will configure the LCD framebuffers with the GSP_BGR8_OES format in linear memory. This is the same as calling :

Note
You should always call gfxExit once done to free the memory and services
Examples
app_launch/source/main.c, audio/filters/source/main.c, audio/mic/source/main.c, audio/streaming/source/main.c, camera/image/source/main.c, camera/video/source/main.c, get_system_language/source/main.c, graphics/bitmap/24bit-color/source/main.c, graphics/gpu/both_screens/source/main.c, graphics/gpu/fragment_light/source/main.c, graphics/gpu/geoshader/source/main.c, graphics/gpu/gpusprites/source/main.c, graphics/gpu/immediate/source/main.c, graphics/gpu/lenny/source/main.c, graphics/gpu/loop_subdivision/source/main.c, graphics/gpu/mipmap_fog/source/main.c, graphics/gpu/particles/source/main.c, graphics/gpu/proctex/source/main.c, graphics/gpu/simple_tri/source/main.c, graphics/gpu/textured_cube/source/main.c, graphics/gpu/toon_shading/source/main.c, graphics/printing/both-screen-text/source/main.c, graphics/printing/colored-text/source/main.c, graphics/printing/hello-world/source/main.c, graphics/printing/multiple-windows-text/source/main.c, graphics/printing/system-font/source/main.c, input/read-controls/source/main.c, input/software-keyboard/source/main.c, input/touch-screen/source/main.c, libapplet_launch/source/main.c, network/boss/source/main.c, network/http/source/main.c, network/http_post/source/main.c, network/sockets/source/sockets.c, network/sslc/source/ssl.c, network/uds/source/uds.c, nfc/source/main.c, qtm/source/main.c, romfs/source/main.c, sdmc/source/main.c, threads/event/source/main.c, threads/thread-basic/source/main.c, and time/rtc/source/main.c.

◆ gfxIs3D()

bool gfxIs3D ( void  )

Retrieves the status of the 3D stereoscopic effect.

Returns
true if 3D enabled, false otherwise.

◆ gfxSet3D()

void gfxSet3D ( bool  enable)

◆ gfxSetDoubleBuffering()

void gfxSetDoubleBuffering ( gfxScreen_t  screen,
bool  doubleBuffering 
)

Sets whether to use ctrulib's double buffering.

Parameters
screenScreen to toggle double buffering for.
doubleBufferingWhether to use double buffering.

ctrulib is by default using a double buffering scheme. If you do not want to swap one of the screen framebuffers when gfxSwapBuffers or gfxSwapBuffers is called, then you have to disable double buffering.

It is however recommended to call gfxSwapBuffers even if double buffering is disabled for both screens if you want to keep the gsp configuration up to date.

Examples
camera/image/source/main.c, camera/video/source/main.c, and graphics/bitmap/24bit-color/source/main.c.

◆ gfxSetScreenFormat()

void gfxSetScreenFormat ( gfxScreen_t  screen,
GSPGPU_FramebufferFormats  format 
)

Changes the color format of a screen.

Parameters
screenThe screen of which format should be changed
formatOne of the gsp pixel formats.

◆ gfxSwapBuffers()

void gfxSwapBuffers ( void  )

◆ gfxSwapBuffersGpu()

void gfxSwapBuffersGpu ( void  )

Swaps the framebuffers.

This is the version to be used with the GPU since the GPU will use the gsp shared memory, so the gsp state mustn't be set directly by the user.

Examples
mvd/source/main.c, and sdmc/source/main.c.