Citro3d
Loading...
Searching...
No Matches
immediate.c
Go to the documentation of this file.
1#include "internal.h"
2
3void C3D_ImmDrawBegin(GPU_Primitive_t primitive)
4{
6
7 // Set primitive type
8 GPUCMD_AddMaskedWrite(GPUREG_PRIMITIVE_CONFIG, 2, primitive);
9 // Start a new primitive (breaks off a triangle strip/fan)
10 GPUCMD_AddWrite(GPUREG_RESTART_PRIMITIVE, 1);
11 // Not sure if this command is necessary
12 GPUCMD_AddWrite(GPUREG_INDEXBUFFER_CONFIG, 0x80000000);
13 // Enable vertex submission mode
14 GPUCMD_AddMaskedWrite(GPUREG_GEOSTAGE_CONFIG2, 1, 1);
15 // Enable drawing mode
16 GPUCMD_AddMaskedWrite(GPUREG_START_DRAW_FUNC0, 1, 0);
17 // Begin immediate-mode vertex submission
18 GPUCMD_AddWrite(GPUREG_FIXEDATTRIB_INDEX, 0xF);
19}
20
21static inline void write24(u8* p, u32 val)
22{
23 p[0] = val;
24 p[1] = val>>8;
25 p[2] = val>>16;
26}
27
28void C3D_ImmSendAttrib(float x, float y, float z, float w)
29{
30 union
31 {
32 u32 packed[3];
33 struct
34 {
35 u8 x[3];
36 u8 y[3];
37 u8 z[3];
38 u8 w[3];
39 };
40 } param;
41
42 // Convert the values to float24
43 write24(param.x, f32tof24(x));
44 write24(param.y, f32tof24(y));
45 write24(param.z, f32tof24(z));
46 write24(param.w, f32tof24(w));
47
48 // Reverse the packed words
49 u32 p = param.packed[0];
50 param.packed[0] = param.packed[2];
51 param.packed[2] = p;
52
53 // Send the attribute
54 GPUCMD_AddIncrementalWrites(GPUREG_FIXEDATTRIB_DATA0, param.packed, 3);
55}
56
58{
59 // Go back to configuration mode
60 GPUCMD_AddMaskedWrite(GPUREG_START_DRAW_FUNC0, 1, 1);
61 // Disable vertex submission mode
62 GPUCMD_AddMaskedWrite(GPUREG_GEOSTAGE_CONFIG2, 1, 0);
63 // Clear the post-vertex cache
64 GPUCMD_AddWrite(GPUREG_VTX_FUNC, 1);
65
66 C3Di_GetContext()->flags |= C3DiF_DrawUsed;
67}
void C3Di_UpdateContext(void)
Definition: base.c:158
void C3D_ImmDrawEnd(void)
Definition: immediate.c:57
void C3D_ImmDrawBegin(GPU_Primitive_t primitive)
Definition: immediate.c:3
void C3D_ImmSendAttrib(float x, float y, float z, float w)
Definition: immediate.c:28
@ C3DiF_DrawUsed
Definition: internal.h:76