citro3d
framebuffer.h
Go to the documentation of this file.
1 /**
2  * @file framebuffer.h
3  * @brief Process render target framebuffer
4  */
5 #pragma once
6 #include "texture.h"
7 
8 typedef struct
9 {
10  void* colorBuf;
11  void* depthBuf;
12  u16 width;
13  u16 height;
14  GPU_COLORBUF colorFmt;
15  GPU_DEPTHBUF depthFmt;
16  bool block32;
17  u8 colorMask : 4;
18  u8 depthMask : 4;
19 } C3D_FrameBuf;
20 
21 /// Flags for C3D_FrameBufClear
22 typedef enum
23 {
24  C3D_CLEAR_COLOR = BIT(0), ///< Clear the color buffer.
25  C3D_CLEAR_DEPTH = BIT(1), ///< Clear the the depth/stencil buffer.
26  C3D_CLEAR_ALL = C3D_CLEAR_COLOR | C3D_CLEAR_DEPTH, ///< Clear both buffers
28 
29 /**
30  * @brief Calculates the size of a color buffer.
31  * @param[in] width Width of the color buffer in pixels.
32  * @param[in] height Height of the color buffer in pixels.
33  * @param[in] fmt Format of the color buffer.
34  * @return Calculated color buffer size.
35  */
37 
38 /**
39  * @brief Calculates the size of a depth buffer.
40  * @param[in] width Width of the depth buffer in pixels.
41  * @param[in] height Height of the depth buffer in pixels.
42  * @param[in] fmt Format of the depth buffer.
43  * @return Calculated depth buffer size.
44  */
46 
47 /**
48  * @brief Returns global citro3d framebuffer structure.
49  * @return Pointer to \ref C3D_FrameBuf struct.
50  */
52 
53 /**
54  * @brief Sets global citro3d framebuffer structure.
55  * @param[in] fb Pointer to \ref C3D_FrameBuf struct.
56  */
58 
59 /**
60  * @brief Binds a texture to a framebuffer. This texture will be used as the color buffer.
61  * @param[out] fb Pointer to \ref C3D_FrameBuf struct.
62  * @param[in] tex Pointer to \ref C3D_Tex struct.
63  * @param[in] face Specifies face of cubemap to be used (ignored if it is a 2D texture)
64  * @param[in] level Specifies mipmap level. 0 is the original image, 1 is the first mipmap, and so on.
65  * @remark This calls \ref C3D_FrameBufColor with the proper arguments for the buffer of the texture.
66  */
67 void C3D_FrameBufTex(C3D_FrameBuf* fb, C3D_Tex* tex, GPU_TEXFACE face, int level);
68 
69 /**
70  * @brief Sets the clear bits and color for a framebuffer.
71  * @param[in] fb Pointer to a \ref C3D_FrameBuf struct.
72  * @param[in] clearBits Specifies which buffers to clear. (see \ref C3D_ClearBits)
73  * @param[in] clearColor 32 bit RGBA value to clear the color buffer with.
74  * @param[in] clearDepth Value to clear the depth buffer with.
75  */
76 void C3D_FrameBufClear(C3D_FrameBuf* fb, C3D_ClearBits clearBits, u32 clearColor, u32 clearDepth);
77 
78 /**
79  * @brief Transfers a framebuffer to the LCD display.
80  * @param[in] fb Pointer to a \ref C3D_FrameBuf struct.
81  * @param[in] screen Screen to transfer the framebuffer to.
82  * @param[in] side Side of the screen to transfer the framebuffer to (unused for the bottom screen)
83  * @param[in] transferFlags Specifies GX_TRANSFER bitflags.
84  */
85 void C3D_FrameBufTransfer(C3D_FrameBuf* fb, gfxScreen_t screen, gfx3dSide_t side, u32 transferFlags);
86 
87 /**
88  * @brief Sets framebuffer attributes.
89  * @param[in] fb Pointer to a \ref C3D_FrameBuf struct.
90  * @param[in] width Width of framebuffer in pixels.
91  * @param[in] height Height of framebuffer in pixels.
92  * @param[in] block32 Specifies if using 32x32 tile format.
93  */
94 static inline void C3D_FrameBufAttrib(C3D_FrameBuf* fb, u16 width, u16 height, bool block32)
95 {
96  fb->width = width;
97  fb->height = height;
98  fb->block32 = block32;
99 }
100 
101 /**
102  * @brief Assigns a color buffer to a framebuffer.
103  * @param[in] fb Pointer to a \ref C3D_FrameBuf struct.
104  * @param[in] buf Pointer to the buffer to use.
105  * @param[in] fmt Format of the color buffer.
106  */
107 static inline void C3D_FrameBufColor(C3D_FrameBuf* fb, void* buf, GPU_COLORBUF fmt)
108 {
109  if (buf)
110  {
111  fb->colorBuf = buf;
112  fb->colorFmt = fmt;
113  fb->colorMask = 0xF;
114  } else
115  {
116  fb->colorBuf = NULL;
117  fb->colorFmt = GPU_RB_RGBA8;
118  fb->colorMask = 0;
119  }
120 }
121 
122 /**
123  * @brief Assigns a depth buffer to a framebuffer.
124  * @param[in] fb Pointer to a \ref C3D_FrameBuf struct.
125  * @param[in] buf Pointer to the buffer to use.
126  * @param[in] fmt Format of the depth buffer.
127  * @note Depending on the format chosen, this may be used as a stencil buffer as well.
128  */
129 static inline void C3D_FrameBufDepth(C3D_FrameBuf* fb, void* buf, GPU_DEPTHBUF fmt)
130 {
131  if (buf)
132  {
133  fb->depthBuf = buf;
134  fb->depthFmt = fmt;
135  fb->depthMask = fmt == GPU_RB_DEPTH24_STENCIL8 ? 0x3 : 0x2;
136  } else
137  {
138  fb->depthBuf = NULL;
139  fb->depthFmt = GPU_RB_DEPTH24;
140  fb->depthMask = 0;
141  }
142 }
GPU_COLORBUF
GPU_RB_RGBA8
GPU_TEXFACE
GPU_DEPTHBUF
GPU_RB_DEPTH24
GPU_RB_DEPTH24_STENCIL8
void C3D_FrameBufTex(C3D_FrameBuf *fb, C3D_Tex *tex, GPU_TEXFACE face, int level)
Binds a texture to a framebuffer. This texture will be used as the color buffer.
static void C3D_FrameBufColor(C3D_FrameBuf *fb, void *buf, GPU_COLORBUF fmt)
Assigns a color buffer to a framebuffer.
Definition: framebuffer.h:107
C3D_FrameBuf * C3D_GetFrameBuf(void)
Returns global citro3d framebuffer structure.
u32 C3D_CalcColorBufSize(u32 width, u32 height, GPU_COLORBUF fmt)
Calculates the size of a color buffer.
u32 C3D_CalcDepthBufSize(u32 width, u32 height, GPU_DEPTHBUF fmt)
Calculates the size of a depth buffer.
void C3D_SetFrameBuf(C3D_FrameBuf *fb)
Sets global citro3d framebuffer structure.
static void C3D_FrameBufDepth(C3D_FrameBuf *fb, void *buf, GPU_DEPTHBUF fmt)
Assigns a depth buffer to a framebuffer.
Definition: framebuffer.h:129
static void C3D_FrameBufAttrib(C3D_FrameBuf *fb, u16 width, u16 height, bool block32)
Sets framebuffer attributes.
Definition: framebuffer.h:94
void C3D_FrameBufTransfer(C3D_FrameBuf *fb, gfxScreen_t screen, gfx3dSide_t side, u32 transferFlags)
Transfers a framebuffer to the LCD display.
void C3D_FrameBufClear(C3D_FrameBuf *fb, C3D_ClearBits clearBits, u32 clearColor, u32 clearDepth)
Sets the clear bits and color for a framebuffer.
C3D_ClearBits
Flags for C3D_FrameBufClear.
Definition: framebuffer.h:23
@ C3D_CLEAR_COLOR
Clear the color buffer.
Definition: framebuffer.h:24
@ C3D_CLEAR_DEPTH
Clear the the depth/stencil buffer.
Definition: framebuffer.h:25
@ C3D_CLEAR_ALL
Clear both buffers.
Definition: framebuffer.h:26
gfxScreen_t
gfx3dSide_t
Definition: framebuffer.h:9
Texture data.
Definition: texture.h:16
Create and manipulate textures.
#define BIT(n)
uint8_t u8
uint16_t u16
uint32_t u32