citro3d
Loading...
Searching...
No Matches
base.h
Go to the documentation of this file.
1/**
2 * @file base.h
3 * @brief Base citro3d functions
4 */
5#pragma once
6#include "buffers.h"
7#include "maths.h"
8
9/// Default command buffer size
10#define C3D_DEFAULT_CMDBUF_SIZE 0x40000
11
12/**
13 * @brief Data type of indices for use with \ref C3D_DrawElements().
14 */
15enum
16{
17 C3D_UNSIGNED_BYTE = 0, ///< Unsigned 8-bit integer
18 C3D_UNSIGNED_SHORT = 1, ///< Unsigned 16-bit integer
19};
20
21/**
22 * @brief Initializes citro3d.
23 * @param[in] cmdBufSize Desired size of GPU command buffer. \ref C3D_DEFAULT_CMDBUF_SIZE should generally be used here.
24 * @note If you have a particularly complex scene you might need to specify a larger \p cmdBufSize.
25 * Conversely, you may want to decrease it if you're particularly concerned about memory consumption.
26 * @return true if library was initialized successfully, false if there was an error.
27 */
28bool C3D_Init(size_t cmdBufSize);
29
30/**
31 * @brief Deinitializes citro3d
32 * @sa C3D_Init()
33 */
34void C3D_Fini(void);
35
36/**
37 * @brief Retrieves the current command buffer usage.
38 * @return Fraction of command buffer used. (0.0f to 1.0f)
39 */
41
42/**
43 * @brief Binds a shader program to the current rendering state.
44 * @param[in] program Specifies the pointer to a shader program object whose executables are to be used
45 * as part of the current rendering state.
46 */
48
49/**
50 * @brief Sets the viewport for the current framebuffer.
51 * @note This function is called by \ref C3D_FrameDrawOn(). (using values specified by \ref C3D_RenderTargetCreate())
52 * @note When using this with a rendertarget intended for display, keep in mind the orientation of the screens.
53 * @param[in] x X offset from the origin of the viewport in pixels.
54 * @param[in] y Y offset from the origin of the viewport in pixels.
55 * @param[in] w Width of the viewport in pixels.
56 * @param[in] h Height of the viewport in pixels.
57 */
58void C3D_SetViewport(u32 x, u32 y, u32 w, u32 h);
59
60/**
61 * @brief Defines the scissor box.
62 * @note When using this with a rendertarget intended for display, keep in mind the orientation of the screens.
63 * @param[in] mode Specifies scissoring mode.
64 * @param[in] left Leftmost boundary in pixels.
65 * @param[in] top Topmost boundary in pixels.
66 * @param[in] right Rightmost boundary in pixels.
67 * @param[in] bottom Bottommost boundary in pixels.
68 */
69void C3D_SetScissor(GPU_SCISSORMODE mode, u32 left, u32 top, u32 right, u32 bottom);
70
71/**
72 * @brief Renders primitives from current vertex array buffer.
73 * @param[in] primitive Specifies what kind of primitives to render.
74 * @param[in] first Specifies the starting index in the current buffers.
75 * @param[in] size Specifies the number of indices to be rendered.
76 */
77void C3D_DrawArrays(GPU_Primitive_t primitive, int first, int size);
78
79/**
80 * @brief Renders primitives from current vertex array buffer in a manually specified order.
81 * @param[in] primitive Specifies what kind of primitives to render.
82 * @param[in] count Specifies the number of indices to be rendered.
83 * @param[in] type Specifies the data type of the indices.
84 * May be \ref C3D_UNSIGNED_BYTE or \ref C3D_UNSIGNED_SHORT.
85 * @param[in] indices Specifies a pointer to where the indices are stored.
86 */
87void C3D_DrawElements(GPU_Primitive_t primitive, int count, int type, const void* indices);
88
89/**
90 * @name Immediate-mode vertex submission
91 * @{
92 */
93
94/**
95 * @brief Delimits the vertices of a primitive or a group of like primitives.
96 * @param[in] primitive Specifies type of primitive or primitives that will be created
97 * using the vertices specified between \ref C3D_ImmDrawBegin() and \ref C3D_ImmDrawEnd().
98 */
100
101/**
102 * @brief Specifies an immediate attribute.
103 * @note Attributes must be specified in the same order they were specified using \ref AttrInfo_AddLoader().
104 * @param[in] x Specifies the X value of the current attribute.
105 * @param[in] y Specifies the Y value of the current attribute.
106 * @param[in] z Specifies the Z value of the current attribute.
107 * @param[in] w Specifies the W value of the current attribute.
108 */
109void C3D_ImmSendAttrib(float x, float y, float z, float w);
110
111/**
112 * @brief Delimits the vertices of a primitive or a group of like primitives.
113 * @sa C3D_ImmDrawBegin()
114 */
115void C3D_ImmDrawEnd(void);
116
117/**
118 * @brief Specifies the end of the previous strip/fan and the beginning of a new one.
119 * @sa C3D_ImmDrawBegin()
120 */
121static inline void C3D_ImmDrawRestartPrim(void)
122{
124}
125/** @} */
126
127/**
128 * @name Fixed vertex attributes
129 * @{
130 */
131
132
133/**
134 * @brief Gets the pointer to the fixed attribute vector for the specified attribute index.
135 * @param[in] id Attribute index.
136 * @return Pointer to the fixed attribute vector for the current attribute.
137 * @sa C3D_FixedAttribSet()
138 */
140
141/**
142 * @brief Sets fixed attribute vector for the specified attribute index.
143 * @note The attribute index should be the same as returned by \ref AttrInfo_AddFixed().
144 * @param[in] id Attribute index.
145 * @param[in] x Specifies the X value of the attribute.
146 * @param[in] y Specifies the Y value of the attribute.
147 * @param[in] z Specifies the Z value of the attribute.
148 * @param[in] w Specifies the W value of the attribute.
149 */
150static inline void C3D_FixedAttribSet(int id, float x, float y, float z, float w)
151{
153 ptr->x = x;
154 ptr->y = y;
155 ptr->z = z;
156 ptr->w = w;
157}
158/** @} */
void C3D_ImmDrawEnd(void)
Delimits the vertices of a primitive or a group of like primitives.
@ C3D_UNSIGNED_BYTE
Unsigned 8-bit integer.
Definition base.h:17
@ C3D_UNSIGNED_SHORT
Unsigned 16-bit integer.
Definition base.h:18
void C3D_DrawArrays(GPU_Primitive_t primitive, int first, int size)
Renders primitives from current vertex array buffer.
static void C3D_ImmDrawRestartPrim(void)
Specifies the end of the previous strip/fan and the beginning of a new one.
Definition base.h:121
void C3D_BindProgram(shaderProgram_s *program)
Binds a shader program to the current rendering state.
void C3D_ImmDrawBegin(GPU_Primitive_t primitive)
Delimits the vertices of a primitive or a group of like primitives.
void C3D_ImmSendAttrib(float x, float y, float z, float w)
Specifies an immediate attribute.
static void C3D_FixedAttribSet(int id, float x, float y, float z, float w)
Sets fixed attribute vector for the specified attribute index.
Definition base.h:150
void C3D_DrawElements(GPU_Primitive_t primitive, int count, int type, const void *indices)
Renders primitives from current vertex array buffer in a manually specified order.
C3D_FVec * C3D_FixedAttribGetWritePtr(int id)
Gets the pointer to the fixed attribute vector for the specified attribute index.
void C3D_SetScissor(GPU_SCISSORMODE mode, u32 left, u32 top, u32 right, u32 bottom)
Defines the scissor box.
bool C3D_Init(size_t cmdBufSize)
Initializes citro3d.
float C3D_GetCmdBufUsage(void)
Retrieves the current command buffer usage.
void C3D_Fini(void)
Deinitializes citro3d.
void C3D_SetViewport(u32 x, u32 y, u32 w, u32 h)
Sets the viewport for the current framebuffer.
Configure vertex array buffers.
GPU_SCISSORMODE
GPU_Primitive_t
#define GPUCMD_AddWrite(reg, val)
Basic math library for matrix, vector, and quaternion operations.
#define GPUREG_RESTART_PRIMITIVE
uint32_t u32
Float vector.
Definition types.h:52
float x
X-component.
Definition types.h:61
float z
Z-component.
Definition types.h:59
float w
W-component.
Definition types.h:58
float y
Y-component.
Definition types.h:60