Citro3d
Loading...
Searching...
No Matches
effect.c
Go to the documentation of this file.
1#include "internal.h"
2
3static inline C3D_Effect* getEffect()
4{
5 C3D_Context* ctx = C3Di_GetContext();
6 ctx->flags |= C3DiF_Effect;
7 return &ctx->effect;
8}
9
10void C3D_DepthMap(bool bIsZBuffer, float zScale, float zOffset)
11{
12 C3D_Effect* e = getEffect();
13 e->zBuffer = bIsZBuffer;
14 e->zScale = f32tof24(zScale);
15 e->zOffset = f32tof24(zOffset);
16}
17
18void C3D_CullFace(GPU_CULLMODE mode)
19{
20 C3D_Effect* e = getEffect();
21 e->cullMode = mode;
22}
23
24void C3D_StencilTest(bool enable, GPU_TESTFUNC function, int ref, int inputMask, int writeMask)
25{
26 C3D_Effect* e = getEffect();
27 e->stencilMode = (!!enable) | ((function & 7) << 4) | (writeMask << 8) | (ref << 16) | (inputMask << 24);
28}
29
30void C3D_StencilOp(GPU_STENCILOP sfail, GPU_STENCILOP dfail, GPU_STENCILOP pass)
31{
32 C3D_Effect* e = getEffect();
33 e->stencilOp = sfail | (dfail << 4) | (pass << 8);
34}
35
36void C3D_BlendingColor(u32 color)
37{
38 C3D_Effect* e = getEffect();
39 e->blendClr = color;
40}
41
42void C3D_EarlyDepthTest(bool enable, GPU_EARLYDEPTHFUNC function, u32 ref)
43{
44 C3D_Effect* e = getEffect();
45 e->earlyDepth = enable;
46 e->earlyDepthFunc = function;
47 e->earlyDepthRef = ref;
48}
49
50void C3D_DepthTest(bool enable, GPU_TESTFUNC function, GPU_WRITEMASK writemask)
51{
52 C3D_Effect* e = getEffect();
53 e->depthTest = (!!enable) | ((function & 7) << 4) | (writemask << 8);
54}
55
56void C3D_AlphaTest(bool enable, GPU_TESTFUNC function, int ref)
57{
58 C3D_Effect* e = getEffect();
59 e->alphaTest = (!!enable) | ((function & 7) << 4) | (ref << 8);
60}
61
62void C3D_AlphaBlend(GPU_BLENDEQUATION colorEq, GPU_BLENDEQUATION alphaEq, GPU_BLENDFACTOR srcClr, GPU_BLENDFACTOR dstClr, GPU_BLENDFACTOR srcAlpha, GPU_BLENDFACTOR dstAlpha)
63{
64 C3D_Effect* e = getEffect();
65 e->alphaBlend = colorEq | (alphaEq << 8) | (srcClr << 16) | (dstClr << 20) | (srcAlpha << 24) | (dstAlpha << 28);
66 e->fragOpMode &= ~0xFF00;
67 e->fragOpMode |= 0x0100;
68}
69
70void C3D_ColorLogicOp(GPU_LOGICOP op)
71{
72 C3D_Effect* e = getEffect();
73 e->fragOpMode &= ~0xFF00;
74 e->clrLogicOp = op;
75}
76
77void C3D_FragOpMode(GPU_FRAGOPMODE mode)
78{
79 C3D_Effect* e = getEffect();
80 e->fragOpMode &= ~0xFF00FF;
81 e->fragOpMode |= 0xE40000 | mode;
82}
83
84void C3D_FragOpShadow(float scale, float bias)
85{
86 C3D_Effect* e = getEffect();
87 e->fragOpShadow = f32tof16(scale+bias) | (f32tof16(-scale)<<16);
88}
89
91{
92 GPUCMD_AddWrite(GPUREG_DEPTHMAP_ENABLE, e->zBuffer ? 1 : 0);
93 GPUCMD_AddWrite(GPUREG_FACECULLING_CONFIG, e->cullMode & 0x3);
94 GPUCMD_AddIncrementalWrites(GPUREG_DEPTHMAP_SCALE, (u32*)&e->zScale, 2);
95 GPUCMD_AddIncrementalWrites(GPUREG_FRAGOP_ALPHA_TEST, (u32*)&e->alphaTest, 4);
96 GPUCMD_AddMaskedWrite(GPUREG_GAS_DELTAZ_DEPTH, 0x8, (u32)GPU_MAKEGASDEPTHFUNC((e->depthTest>>4)&7) << 24);
97 GPUCMD_AddWrite(GPUREG_BLEND_COLOR, e->blendClr);
98 GPUCMD_AddWrite(GPUREG_BLEND_FUNC, e->alphaBlend);
99 GPUCMD_AddWrite(GPUREG_LOGIC_OP, e->clrLogicOp);
100 GPUCMD_AddMaskedWrite(GPUREG_COLOR_OPERATION, 7, e->fragOpMode);
101 GPUCMD_AddWrite(GPUREG_FRAGOP_SHADOW, e->fragOpShadow);
102 GPUCMD_AddMaskedWrite(GPUREG_EARLYDEPTH_TEST1, 1, e->earlyDepth ? 1 : 0);
103 GPUCMD_AddWrite(GPUREG_EARLYDEPTH_TEST2, e->earlyDepth ? 1 : 0);
104 GPUCMD_AddMaskedWrite(GPUREG_EARLYDEPTH_FUNC, 1, e->earlyDepthFunc);
105 GPUCMD_AddMaskedWrite(GPUREG_EARLYDEPTH_DATA, 0x7, e->earlyDepthRef);
106}
void C3D_DepthMap(bool bIsZBuffer, float zScale, float zOffset)
Definition: effect.c:10
void C3D_AlphaTest(bool enable, GPU_TESTFUNC function, int ref)
Definition: effect.c:56
void C3Di_EffectBind(C3D_Effect *e)
Definition: effect.c:90
void C3D_CullFace(GPU_CULLMODE mode)
Definition: effect.c:18
void C3D_FragOpMode(GPU_FRAGOPMODE mode)
Definition: effect.c:77
void C3D_StencilTest(bool enable, GPU_TESTFUNC function, int ref, int inputMask, int writeMask)
Definition: effect.c:24
void C3D_FragOpShadow(float scale, float bias)
Definition: effect.c:84
void C3D_StencilOp(GPU_STENCILOP sfail, GPU_STENCILOP dfail, GPU_STENCILOP pass)
Definition: effect.c:30
void C3D_ColorLogicOp(GPU_LOGICOP op)
Definition: effect.c:70
void C3D_AlphaBlend(GPU_BLENDEQUATION colorEq, GPU_BLENDEQUATION alphaEq, GPU_BLENDFACTOR srcClr, GPU_BLENDFACTOR dstClr, GPU_BLENDFACTOR srcAlpha, GPU_BLENDFACTOR dstAlpha)
Definition: effect.c:62
void C3D_BlendingColor(u32 color)
Definition: effect.c:36
void C3D_DepthTest(bool enable, GPU_TESTFUNC function, GPU_WRITEMASK writemask)
Definition: effect.c:50
void C3D_EarlyDepthTest(bool enable, GPU_EARLYDEPTHFUNC function, u32 ref)
Definition: effect.c:42
@ C3DiF_Effect
Definition: internal.h:79
u32 flags
Definition: internal.h:38
C3D_Effect effect
Definition: internal.h:43
u32 stencilMode
Definition: internal.h:23
u32 blendClr
Definition: internal.h:26
u32 alphaTest
Definition: internal.h:22
bool earlyDepth
Definition: internal.h:18
GPU_CULLMODE cullMode
Definition: internal.h:17
u32 stencilOp
Definition: internal.h:23
bool zBuffer
Definition: internal.h:18
u32 zOffset
Definition: internal.h:16
u32 depthTest
Definition: internal.h:24
u32 fragOpMode
Definition: internal.h:14
u32 earlyDepthRef
Definition: internal.h:20
GPU_LOGICOP clrLogicOp
Definition: internal.h:28
GPU_EARLYDEPTHFUNC earlyDepthFunc
Definition: internal.h:19
u32 alphaBlend
Definition: internal.h:27
u32 fragOpShadow
Definition: internal.h:15
u32 zScale
Definition: internal.h:16