Citro3d
Loading...
Searching...
No Matches
drawElements.c
Go to the documentation of this file.
1#include "internal.h"
2
3void C3D_DrawElements(GPU_Primitive_t primitive, int count, int type, const void* indices)
4{
5 C3D_Context* ctx = C3Di_GetContext();
6 u32 pa = osConvertVirtToPhys(indices);
7 u32 base = ctx->bufInfo.base_paddr;
8 if (pa < base) return;
9
11
12 // Set primitive type
13 GPUCMD_AddMaskedWrite(GPUREG_PRIMITIVE_CONFIG, 2, primitive != GPU_TRIANGLES ? primitive : GPU_GEOMETRY_PRIM);
14 // Start a new primitive (breaks off a triangle strip/fan)
15 GPUCMD_AddWrite(GPUREG_RESTART_PRIMITIVE, 1);
16 // Configure the index buffer
17 GPUCMD_AddWrite(GPUREG_INDEXBUFFER_CONFIG, (pa - base) | (type << 31));
18 // Number of vertices
19 GPUCMD_AddWrite(GPUREG_NUMVERTICES, count);
20 // First vertex
21 GPUCMD_AddWrite(GPUREG_VERTEX_OFFSET, 0);
22 // Enable triangle element drawing mode if necessary
23 if (primitive == GPU_TRIANGLES)
24 {
25 GPUCMD_AddMaskedWrite(GPUREG_GEOSTAGE_CONFIG, 2, 0x100);
26 GPUCMD_AddMaskedWrite(GPUREG_GEOSTAGE_CONFIG2, 2, 0x100);
27 }
28 // Enable drawing mode
29 GPUCMD_AddMaskedWrite(GPUREG_START_DRAW_FUNC0, 1, 0);
30 // Trigger element drawing
31 GPUCMD_AddWrite(GPUREG_DRAWELEMENTS, 1);
32 // Go back to configuration mode
33 GPUCMD_AddMaskedWrite(GPUREG_START_DRAW_FUNC0, 1, 1);
34 // Disable triangle element drawing mode if necessary
35 if (primitive == GPU_TRIANGLES)
36 {
37 GPUCMD_AddMaskedWrite(GPUREG_GEOSTAGE_CONFIG, 2, 0);
38 GPUCMD_AddMaskedWrite(GPUREG_GEOSTAGE_CONFIG2, 2, 0);
39 }
40 // Clear the post-vertex cache
41 GPUCMD_AddWrite(GPUREG_VTX_FUNC, 1);
42 GPUCMD_AddMaskedWrite(GPUREG_PRIMITIVE_CONFIG, 0x8, 0);
43 GPUCMD_AddMaskedWrite(GPUREG_PRIMITIVE_CONFIG, 0x8, 0);
44
45 C3Di_GetContext()->flags |= C3DiF_DrawUsed;
46}
void C3Di_UpdateContext(void)
Definition: base.c:158
void C3D_DrawElements(GPU_Primitive_t primitive, int count, int type, const void *indices)
Definition: drawElements.c:3
@ C3DiF_DrawUsed
Definition: internal.h:76
C3D_BufInfo bufInfo
Definition: internal.h:42
int count
Definition: uniforms.c:15