Add some shadow-related texture functions:
- C3D_TexShadowParams: configure GPUREG_TEXUNIT0_SHADOW - C3D_TexInitShadow: create shadow map texture - C3D_TexInitShadowCube: as above, but for shadow cubemaps
This commit is contained in:
parent
82b9eea410
commit
ac755aa3ec
@ -58,6 +58,8 @@ void C3D_TexBind(int unitId, C3D_Tex* tex);
|
||||
void C3D_TexFlush(C3D_Tex* tex);
|
||||
void C3D_TexDelete(C3D_Tex* tex);
|
||||
|
||||
void C3D_TexShadowParams(bool perspective, float bias);
|
||||
|
||||
static inline int C3D_TexCalcMaxLevel(u32 width, u32 height)
|
||||
{
|
||||
return (31-__builtin_clz(width < height ? width : height)) - 3; // avoid sizes smaller than 8
|
||||
@ -113,6 +115,18 @@ static inline bool C3D_TexInitVRAM(C3D_Tex* tex, u16 width, u16 height, GPU_TEXC
|
||||
(C3D_TexInitParams){ width, height, 0, format, GPU_TEX_2D, true });
|
||||
}
|
||||
|
||||
static inline bool C3D_TexInitShadow(C3D_Tex* tex, u16 width, u16 height)
|
||||
{
|
||||
return C3D_TexInitWithParams(tex, NULL,
|
||||
(C3D_TexInitParams){ width, height, 0, GPU_RGBA8, GPU_TEX_SHADOW_2D, true });
|
||||
}
|
||||
|
||||
static inline bool C3D_TexInitShadowCube(C3D_Tex* tex, C3D_TexCube* cube, u16 width, u16 height)
|
||||
{
|
||||
return C3D_TexInitWithParams(tex, cube,
|
||||
(C3D_TexInitParams){ width, height, 0, GPU_RGBA8, GPU_TEX_SHADOW_CUBE, true });
|
||||
}
|
||||
|
||||
static inline GPU_TEXTURE_MODE_PARAM C3D_TexGetType(C3D_Tex* tex)
|
||||
{
|
||||
return (GPU_TEXTURE_MODE_PARAM)((tex->param>>28)&0x7);
|
||||
|
@ -71,6 +71,7 @@ bool C3D_Init(size_t cmdBufSize)
|
||||
C3D_FragOpShadow(0.0, 1.0);
|
||||
|
||||
ctx->texConfig = BIT(12);
|
||||
ctx->texShadow = BIT(0);
|
||||
ctx->texEnvBuf = 0;
|
||||
ctx->texEnvBufClr = 0xFFFFFFFF;
|
||||
|
||||
@ -188,6 +189,7 @@ void C3Di_UpdateContext(void)
|
||||
{
|
||||
ctx->flags &= ~C3DiF_TexStatus;
|
||||
GPUCMD_AddWrite(GPUREG_TEXUNIT_CONFIG, ctx->texConfig);
|
||||
GPUCMD_AddWrite(GPUREG_TEXUNIT0_SHADOW, ctx->texShadow);
|
||||
ctx->texConfig &= ~BIT(16); // Remove clear-texture-cache flag
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ typedef struct
|
||||
C3D_LightEnv* lightEnv;
|
||||
|
||||
u32 texConfig;
|
||||
u32 texShadow;
|
||||
C3D_Tex* tex[3];
|
||||
C3D_TexEnv texEnv[6];
|
||||
|
||||
|
@ -255,6 +255,20 @@ void C3D_TexDelete(C3D_Tex* tex)
|
||||
tex->data = NULL;
|
||||
}
|
||||
|
||||
void C3D_TexShadowParams(bool perspective, float bias)
|
||||
{
|
||||
C3D_Context* ctx = C3Di_GetContext();
|
||||
|
||||
if (!(ctx->flags & C3DiF_Active))
|
||||
return;
|
||||
|
||||
u32 iBias = (u32)(fabs(bias) * BIT(24));
|
||||
if (iBias >= BIT(24))
|
||||
iBias = BIT(24)-1;
|
||||
|
||||
ctx->texShadow = (iBias &~ 1) | (perspective ? 0 : 1);
|
||||
}
|
||||
|
||||
void C3Di_SetTex(int unit, C3D_Tex* tex)
|
||||
{
|
||||
u32 reg[10];
|
||||
|
Loading…
Reference in New Issue
Block a user