2014-12-20 21:34:19 +01:00
|
|
|
#pragma once
|
|
|
|
#include <c3d/attribs.h>
|
2015-09-07 14:47:20 +02:00
|
|
|
#include <c3d/buffers.h>
|
2017-03-15 16:49:06 +01:00
|
|
|
#include <c3d/proctex.h>
|
2015-09-13 23:27:38 +02:00
|
|
|
#include <c3d/light.h>
|
2017-02-14 18:24:57 +01:00
|
|
|
#include <c3d/framebuffer.h>
|
2017-02-09 04:30:25 +01:00
|
|
|
#include <c3d/texenv.h>
|
2017-04-08 12:46:25 +02:00
|
|
|
#include <c3d/fog.h>
|
2017-02-09 04:30:25 +01:00
|
|
|
|
|
|
|
#define C3D_UNUSED __attribute__((unused))
|
2014-12-20 21:34:19 +01:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2015-11-25 22:02:16 +01:00
|
|
|
u32 fragOpMode;
|
2017-02-09 19:59:46 +01:00
|
|
|
u32 fragOpShadow;
|
2015-03-07 17:02:38 +01:00
|
|
|
u32 zScale, zOffset;
|
2014-12-20 21:34:19 +01:00
|
|
|
GPU_CULLMODE cullMode;
|
2017-04-02 17:14:49 +02:00
|
|
|
bool zBuffer, earlyDepth;
|
|
|
|
GPU_EARLYDEPTHFUNC earlyDepthFunc;
|
|
|
|
u32 earlyDepthRef;
|
2014-12-20 21:34:19 +01:00
|
|
|
|
|
|
|
u32 alphaTest;
|
|
|
|
u32 stencilMode, stencilOp;
|
|
|
|
u32 depthTest;
|
|
|
|
|
|
|
|
u32 blendClr;
|
|
|
|
u32 alphaBlend;
|
2015-11-25 22:02:16 +01:00
|
|
|
GPU_LOGICOP clrLogicOp;
|
2014-12-20 21:34:19 +01:00
|
|
|
} C3D_Effect;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2017-03-26 20:15:01 +02:00
|
|
|
gxCmdQueue_s gxQueue;
|
2016-01-05 17:30:05 +01:00
|
|
|
u32* cmdBuf;
|
2014-12-20 21:34:19 +01:00
|
|
|
size_t cmdBufSize;
|
2016-01-19 22:32:55 +01:00
|
|
|
float cmdBufUsage;
|
2014-12-20 21:34:19 +01:00
|
|
|
|
|
|
|
u32 flags;
|
2015-06-27 19:17:50 +02:00
|
|
|
shaderProgram_s* program;
|
2014-12-20 21:34:19 +01:00
|
|
|
|
|
|
|
C3D_AttrInfo attrInfo;
|
2015-09-07 14:47:20 +02:00
|
|
|
C3D_BufInfo bufInfo;
|
2014-12-20 21:34:19 +01:00
|
|
|
C3D_Effect effect;
|
2015-09-13 23:27:38 +02:00
|
|
|
C3D_LightEnv* lightEnv;
|
2014-12-20 21:34:19 +01:00
|
|
|
|
2017-02-14 18:40:58 +01:00
|
|
|
u32 texConfig;
|
2017-02-14 19:40:07 +01:00
|
|
|
u32 texShadow;
|
2014-12-20 21:34:19 +01:00
|
|
|
C3D_Tex* tex[3];
|
|
|
|
C3D_TexEnv texEnv[6];
|
|
|
|
|
2015-09-10 13:47:16 +02:00
|
|
|
u32 texEnvBuf, texEnvBufClr;
|
2017-04-08 12:46:25 +02:00
|
|
|
u32 fogClr;
|
|
|
|
C3D_FogLut* fogLut;
|
2015-09-10 13:47:16 +02:00
|
|
|
|
2017-07-13 21:53:18 +02:00
|
|
|
u16 gasAttn, gasAccMax;
|
2018-05-23 13:54:49 +02:00
|
|
|
u32 gasLightXY, gasLightZ, gasLightZColor;
|
|
|
|
u32 gasDeltaZ : 24;
|
|
|
|
u32 gasFlags : 8;
|
2017-07-13 21:53:18 +02:00
|
|
|
C3D_GasLut* gasLut;
|
|
|
|
|
2017-03-15 16:49:06 +01:00
|
|
|
C3D_ProcTex* procTex;
|
|
|
|
C3D_ProcTexLut* procTexLut[3];
|
|
|
|
C3D_ProcTexColorLut* procTexColorLut;
|
|
|
|
|
2017-02-14 18:24:57 +01:00
|
|
|
C3D_FrameBuf fb;
|
2015-03-07 23:41:32 +01:00
|
|
|
u32 viewport[5];
|
|
|
|
u32 scissor[3];
|
|
|
|
|
2015-11-22 17:47:33 +01:00
|
|
|
u16 fixedAttribDirty, fixedAttribEverDirty;
|
|
|
|
C3D_FVec fixedAttribs[12];
|
2014-12-20 21:34:19 +01:00
|
|
|
} C3D_Context;
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
C3DiF_Active = BIT(0),
|
2015-09-20 14:04:50 +02:00
|
|
|
C3DiF_DrawUsed = BIT(1),
|
2015-09-07 14:47:20 +02:00
|
|
|
C3DiF_AttrInfo = BIT(2),
|
|
|
|
C3DiF_BufInfo = BIT(3),
|
|
|
|
C3DiF_Effect = BIT(4),
|
2017-02-14 18:24:57 +01:00
|
|
|
C3DiF_FrameBuf = BIT(5),
|
2015-09-07 14:47:20 +02:00
|
|
|
C3DiF_Viewport = BIT(6),
|
|
|
|
C3DiF_Scissor = BIT(7),
|
|
|
|
C3DiF_Program = BIT(8),
|
2015-09-10 13:47:16 +02:00
|
|
|
C3DiF_TexEnvBuf = BIT(9),
|
2015-09-13 23:27:38 +02:00
|
|
|
C3DiF_LightEnv = BIT(10),
|
2015-11-21 01:02:25 +01:00
|
|
|
C3DiF_VshCode = BIT(11),
|
|
|
|
C3DiF_GshCode = BIT(12),
|
2017-02-14 18:40:58 +01:00
|
|
|
C3DiF_TexStatus = BIT(14),
|
2017-03-15 16:49:06 +01:00
|
|
|
C3DiF_ProcTex = BIT(15),
|
|
|
|
C3DiF_ProcTexColorLut = BIT(16),
|
2017-04-08 12:46:25 +02:00
|
|
|
C3DiF_FogLut = BIT(17),
|
2017-07-13 21:53:18 +02:00
|
|
|
C3DiF_Gas = BIT(18),
|
|
|
|
C3DiF_GasLut = BIT(19),
|
2014-12-20 21:34:19 +01:00
|
|
|
|
2017-03-15 16:49:06 +01:00
|
|
|
#define C3DiF_ProcTexLut(n) BIT(20+(n))
|
|
|
|
C3DiF_ProcTexLutAll = 7 << 20,
|
2014-12-20 21:34:19 +01:00
|
|
|
#define C3DiF_Tex(n) BIT(23+(n))
|
|
|
|
C3DiF_TexAll = 7 << 23,
|
|
|
|
#define C3DiF_TexEnv(n) BIT(26+(n))
|
|
|
|
C3DiF_TexEnvAll = 0x3F << 26,
|
|
|
|
};
|
|
|
|
|
2018-05-23 13:54:49 +02:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
C3DiG_BeginAcc = BIT(0),
|
|
|
|
C3DiG_AccStage = BIT(1),
|
|
|
|
C3DiG_SetAccMax = BIT(2),
|
|
|
|
C3DiG_RenderStage = BIT(3),
|
|
|
|
};
|
|
|
|
|
2014-12-20 21:34:19 +01:00
|
|
|
static inline C3D_Context* C3Di_GetContext(void)
|
|
|
|
{
|
|
|
|
extern C3D_Context __C3D_Context;
|
|
|
|
return &__C3D_Context;
|
|
|
|
}
|
|
|
|
|
2017-02-14 18:24:57 +01:00
|
|
|
static inline bool typeIsCube(GPU_TEXTURE_MODE_PARAM type)
|
|
|
|
{
|
|
|
|
return type == GPU_TEX_CUBE_MAP || type == GPU_TEX_SHADOW_CUBE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool C3Di_TexIs2D(C3D_Tex* tex)
|
|
|
|
{
|
|
|
|
return !typeIsCube(C3D_TexGetType(tex));
|
|
|
|
}
|
|
|
|
|
2021-08-26 23:46:07 +02:00
|
|
|
static inline bool addrIsVRAM(const void* addr)
|
|
|
|
{
|
|
|
|
u32 vaddr = (u32)addr;
|
|
|
|
return vaddr >= OS_VRAM_VADDR && vaddr < OS_VRAM_VADDR + OS_VRAM_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline vramAllocPos addrGetVRAMBank(const void* addr)
|
|
|
|
{
|
|
|
|
u32 vaddr = (u32)addr;
|
|
|
|
return vaddr < OS_VRAM_VADDR + OS_VRAM_SIZE/2 ? VRAM_ALLOC_A : VRAM_ALLOC_B;
|
|
|
|
}
|
|
|
|
|
2014-12-20 21:34:19 +01:00
|
|
|
void C3Di_UpdateContext(void);
|
|
|
|
void C3Di_AttrInfoBind(C3D_AttrInfo* info);
|
2015-09-07 14:47:20 +02:00
|
|
|
void C3Di_BufInfoBind(C3D_BufInfo* info);
|
2017-02-14 18:24:57 +01:00
|
|
|
void C3Di_FrameBufBind(C3D_FrameBuf* fb);
|
2014-12-20 21:34:19 +01:00
|
|
|
void C3Di_TexEnvBind(int id, C3D_TexEnv* env);
|
2017-02-14 18:40:58 +01:00
|
|
|
void C3Di_SetTex(int unit, C3D_Tex* tex);
|
2014-12-20 21:34:19 +01:00
|
|
|
void C3Di_EffectBind(C3D_Effect* effect);
|
2017-07-13 21:53:18 +02:00
|
|
|
void C3Di_GasUpdate(C3D_Context* ctx);
|
2015-09-13 23:27:38 +02:00
|
|
|
|
|
|
|
void C3Di_LightMtlBlend(C3D_Light* light);
|
2015-11-21 01:02:25 +01:00
|
|
|
|
|
|
|
void C3Di_DirtyUniforms(GPU_SHADER_TYPE type);
|
|
|
|
void C3Di_LoadShaderUniforms(shaderInstance_s* si);
|
|
|
|
void C3Di_ClearShaderUniforms(GPU_SHADER_TYPE type);
|
2016-01-05 17:30:05 +01:00
|
|
|
|
2017-03-26 20:15:01 +02:00
|
|
|
bool C3Di_SplitFrame(u32** pBuf, u32* pSize);
|
2020-05-05 16:57:18 +02:00
|
|
|
|
|
|
|
void C3Di_RenderQueueInit(void);
|
|
|
|
void C3Di_RenderQueueExit(void);
|
|
|
|
void C3Di_RenderQueueWaitDone(void);
|
2020-07-06 20:21:03 +02:00
|
|
|
void C3Di_RenderQueueEnableVBlank(void);
|
|
|
|
void C3Di_RenderQueueDisableVBlank(void);
|