![]() |
libdragon
|
RDP Command queue. More...
Go to the source code of this file.
Data Structures | |
struct | rdpq_trifmt_t |
Format descriptor of a triangle. More... | |
Functions | |
void | rdpq_triangle (const rdpq_trifmt_t *fmt, const float *v1, const float *v2, const float *v3) |
Draw a triangle (RDP command: TRI_*) | |
Variables | |
const rdpq_trifmt_t | TRIFMT_FILL |
Format descriptor for a solid-filled triangle. | |
const rdpq_trifmt_t | TRIFMT_SHADE |
Format descriptor for a shaded triangle. | |
const rdpq_trifmt_t | TRIFMT_TEX |
Format descriptor for a textured triangle. | |
const rdpq_trifmt_t | TRIFMT_SHADE_TEX |
Format descriptor for a shaded, textured triangle. | |
const rdpq_trifmt_t | TRIFMT_ZBUF |
Format descriptor for a solid-filled, z-buffered triangle. | |
const rdpq_trifmt_t | TRIFMT_ZBUF_SHADE |
Format descriptor for a z-buffered, shaded triangle. | |
const rdpq_trifmt_t | TRIFMT_ZBUF_TEX |
Format descriptor for a z-buffered, textured triangle. | |
const rdpq_trifmt_t | TRIFMT_ZBUF_SHADE_TEX |
Format descriptor for a z-buffered, shaded, textured triangle. | |
RDP Command queue.
struct rdpq_trifmt_t |
Format descriptor of a triangle.
This structure holds the parameters required to draw triangles. It contains both a description of the vertex format, and some configuration parameters for the triangle rasterizer.
This library provides a few predefined formats (such as TRIFMT_FILL, TRIFMT_TEX, etc.) but you are free to define your own format.
There is no overhead in using a custom format or even switching format from a triangle to another (besides the required mode changes), so feel free to define as many formats are required for your application.
Refer to rdpq_triangle for a description of the different vertex components.
Data Fields | ||
---|---|---|
int | pos_offset |
Index of the position component within the vertex arrays. For instance, if |
int | shade_offset |
Index of the shade component within the vertex arrays. For instance, if |
bool | shade_flat |
If true, draw the triangle with flat shading (instead of gouraud shading). This parameter is ignored if the shade component does not exist ( |
int | tex_offset |
Index of the texture component within the vertex arrays. For instance, if |
rdpq_tile_t | tex_tile |
RDP tile descriptor that describes the texture (0-7). This parameter is ignored if the texture component does not exist ( |
int | tex_mipmaps |
Number of mipmaps to use for the texture. This parameter is ignored if the texture component does not exist ( Notice that when using the mode API (rdpq_mode_mipmap), the number of mipmaps is specified there, so this parameter should be left to zero. |
int | z_offset |
Index of the depth component within the vertex array. For instance, if |
void rdpq_triangle | ( | const rdpq_trifmt_t * | fmt, |
const float * | v1, | ||
const float * | v2, | ||
const float * | v3 | ||
) |
Draw a triangle (RDP command: TRI_*)
This function allows to draw a triangle into the framebuffer using RDP, in screen coordinates. RDP does not handle transform and lightning, so it only reasons of screen level coordinates.
Each vertex of a triangle is made of up to 4 components:
Only the position is mandatory, all other components are optionals, depending on the kind of triangle that needs to be drawn. For instance, specifying only position and shade will allow to draw a gouraud-shaded triangle with no texturing and no z-buffer usage.
The vertex components must be provided via arrays of floating point values. The order of the components within the array is flexible, and can be specified at call time via the rdpq_trifmt_t structure.
Notice that it is important to configure the correct render modes before calling this function. Specifically:
If you fail to activate a specific render mode for a provided component, the component will be ignored by RDP. For instance, if you provide S,T,W but do not configure a combiner formula that accesses TEX0, the texture will not be rendered. On the contrary, if you activate a specific render mode but then fail to provide the component (eg: activate z buffering but then fail to provide a depth component), RDP will fall into undefined behavior that can vary from nothing being rendered, garbage on the screen or even a freeze. The rdpq validator will do its best to help you catching these mistakes, so remember to activate it via rdpq_debug_start whenever you get a surprising result.
For instance, this code snippet will draw a filled triangle, with a flat green color:
The three vertices (v1, v2, v3) can be provided in any order (clockwise or counter-clockwise). The function will render the triangle in any case (so back-face culling must be handled before calling it).
fmt | Format of the triangle being drawn. This structure specifies the order of the components within the vertex arrays, and also some additional rasterization parameters. You can pass one of the predefined formats (TRIFMT_FILL, TRIFMT_TEX, etc.), or a custom one. |
v1 | Array of components for vertex 1 |
v2 | Array of components for vertex 2 |
v3 | Array of components for vertex 3 |
|
extern |
Format descriptor for a solid-filled triangle.
Vertex array format: (float){X, Y}
(2 floats)
Given that only position is provided, the triangle is drawn with a solid color, which is the output of the color combiner. See rdpq_mode_combiner for more information.
A common choice for a combiner formula is RDPQ_COMBINER_FLAT, that will simply output whatever color is configured via rdpq_set_prim_color.
|
extern |
Format descriptor for a shaded triangle.
Vertex array format: (float){X, Y, R, G, B, A}
(6 floats)
The suggested standard color combiner for this format is RDPQ_COMBINER_SHADE.
|
extern |
Format descriptor for a textured triangle.
Vertex array format: (float){X, Y, S, T, INV_W}
(5 floats)
The suggested standard color combiner for this format is RDPQ_COMBINER_TEX.
|
extern |
Format descriptor for a shaded, textured triangle.
Vertex array format: (float){X, Y, R, G, B, A, S, T, INV_W}
(9 floats)
The suggested standard color combiner for this format is RDPQ_COMBINER_TEX_SHADE.
|
extern |
Format descriptor for a solid-filled, z-buffered triangle.
Vertex array format: (float){X, Y, Z}
(3 floats)
|
extern |
Format descriptor for a z-buffered, shaded triangle.
Vertex array format: (float){X, Y, Z, R, G, B, A}
(7 floats)
|
extern |
Format descriptor for a z-buffered, textured triangle.
Vertex array format: (float){X, Y, Z, S, T, INV_W}
(6 floats)
|
extern |
Format descriptor for a z-buffered, shaded, textured triangle.
Vertex array format: (float){X, Y, Z, R, G, B, A, S, T, INV_W}
(10 floats)