Use APT hooks to restore GPU state when returning from homemenu
This commit is contained in:
parent
153f01e741
commit
d4971ddca5
@ -134,7 +134,7 @@ int main()
|
|||||||
shaderProgramInit(&shader);
|
shaderProgramInit(&shader);
|
||||||
shaderProgramSetVsh(&shader, &pVsh->DVLE[0]);
|
shaderProgramSetVsh(&shader, &pVsh->DVLE[0]);
|
||||||
shaderProgramSetGsh(&shader, &pGsh->DVLE[0], 3*5); // Comment this out to disable the geoshader
|
shaderProgramSetGsh(&shader, &pGsh->DVLE[0], 3*5); // Comment this out to disable the geoshader
|
||||||
shaderProgramUse(&shader);
|
C3D_BindProgram(&shader);
|
||||||
|
|
||||||
// Configure attributes
|
// Configure attributes
|
||||||
C3D_AttrInfo* attrInfo = C3D_GetAttrInfo();
|
C3D_AttrInfo* attrInfo = C3D_GetAttrInfo();
|
||||||
|
@ -7,6 +7,8 @@ bool C3D_Init(size_t cmdBufSize);
|
|||||||
void C3D_FlushAsync(void);
|
void C3D_FlushAsync(void);
|
||||||
void C3D_Fini(void);
|
void C3D_Fini(void);
|
||||||
|
|
||||||
|
void C3D_BindProgram(shaderProgram_s* program);
|
||||||
|
|
||||||
void C3D_SetViewport(u32 x, u32 y, u32 w, u32 h);
|
void C3D_SetViewport(u32 x, u32 y, u32 w, u32 h);
|
||||||
void C3D_SetScissor(GPU_SCISSORMODE mode, u32 x, u32 y, u32 w, u32 h);
|
void C3D_SetScissor(GPU_SCISSORMODE mode, u32 x, u32 y, u32 w, u32 h);
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ static void C3Di_SetTex(GPU_TEXUNIT unit, C3D_Tex* tex)
|
|||||||
u32 reg[4];
|
u32 reg[4];
|
||||||
reg[0] = tex->fmt;
|
reg[0] = tex->fmt;
|
||||||
reg[1] = osConvertVirtToPhys((u32)tex->data) >> 3;
|
reg[1] = osConvertVirtToPhys((u32)tex->data) >> 3;
|
||||||
reg[2] = (u32)tex->width | ((u32)tex->height << 16);
|
reg[2] = (u32)tex->height | ((u32)tex->width << 16);
|
||||||
reg[3] = tex->param;
|
reg[3] = tex->param;
|
||||||
|
|
||||||
switch (unit)
|
switch (unit)
|
||||||
@ -52,6 +52,28 @@ static void C3Di_SetTex(GPU_TEXUNIT unit, C3D_Tex* tex)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static aptHookCookie hookCookie;
|
||||||
|
|
||||||
|
static void C3Di_AptEventHook(int hookType, void* param)
|
||||||
|
{
|
||||||
|
C3D_Context* ctx = C3Di_GetContext();
|
||||||
|
|
||||||
|
switch (hookType)
|
||||||
|
{
|
||||||
|
case APTHOOK_ONSUSPEND:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case APTHOOK_ONRESTORE:
|
||||||
|
{
|
||||||
|
ctx->flags |= C3DiF_AttrBuf | C3DiF_Effect | C3DiF_RenderBuf
|
||||||
|
| C3DiF_Viewport | C3DiF_Scissor | C3DiF_Program
|
||||||
|
| C3DiF_TexAll | C3DiF_TexEnvAll;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool C3D_Init(size_t cmdBufSize)
|
bool C3D_Init(size_t cmdBufSize)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -85,6 +107,8 @@ bool C3D_Init(size_t cmdBufSize)
|
|||||||
for (i = 0; i < 6; i ++)
|
for (i = 0; i < 6; i ++)
|
||||||
TexEnv_Init(&ctx->texEnv[i]);
|
TexEnv_Init(&ctx->texEnv[i]);
|
||||||
|
|
||||||
|
aptHook(&hookCookie, C3Di_AptEventHook, NULL);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +145,12 @@ void C3Di_UpdateContext(void)
|
|||||||
//GPU_FinishDrawing();
|
//GPU_FinishDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ctx->flags & C3DiF_Program)
|
||||||
|
{
|
||||||
|
ctx->flags &= ~C3DiF_Program;
|
||||||
|
shaderProgramUse(ctx->program);
|
||||||
|
}
|
||||||
|
|
||||||
if (ctx->flags & C3DiF_RenderBuf)
|
if (ctx->flags & C3DiF_RenderBuf)
|
||||||
{
|
{
|
||||||
ctx->flags &= ~C3DiF_RenderBuf;
|
ctx->flags &= ~C3DiF_RenderBuf;
|
||||||
@ -211,6 +241,18 @@ void C3D_Fini(void)
|
|||||||
if (!(ctx->flags & C3DiF_Active))
|
if (!(ctx->flags & C3DiF_Active))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
aptUnhook(&hookCookie);
|
||||||
linearFree(ctx->cmdBuf);
|
linearFree(ctx->cmdBuf);
|
||||||
ctx->flags = 0;
|
ctx->flags = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void C3D_BindProgram(shaderProgram_s* program)
|
||||||
|
{
|
||||||
|
C3D_Context* ctx = C3Di_GetContext();
|
||||||
|
|
||||||
|
if (!(ctx->flags & C3DiF_Active))
|
||||||
|
return;
|
||||||
|
|
||||||
|
ctx->program = program;
|
||||||
|
ctx->flags |= C3DiF_Program;
|
||||||
|
}
|
||||||
|
@ -27,6 +27,7 @@ typedef struct
|
|||||||
size_t cmdBufSize;
|
size_t cmdBufSize;
|
||||||
|
|
||||||
u32 flags;
|
u32 flags;
|
||||||
|
shaderProgram_s* program;
|
||||||
|
|
||||||
u32 vboPos;
|
u32 vboPos;
|
||||||
C3D_AttrInfo attrInfo;
|
C3D_AttrInfo attrInfo;
|
||||||
@ -50,6 +51,7 @@ enum
|
|||||||
C3DiF_RenderBuf = BIT(4),
|
C3DiF_RenderBuf = BIT(4),
|
||||||
C3DiF_Viewport = BIT(5),
|
C3DiF_Viewport = BIT(5),
|
||||||
C3DiF_Scissor = BIT(6),
|
C3DiF_Scissor = BIT(6),
|
||||||
|
C3DiF_Program = BIT(7),
|
||||||
|
|
||||||
#define C3DiF_Tex(n) BIT(23+(n))
|
#define C3DiF_Tex(n) BIT(23+(n))
|
||||||
C3DiF_TexAll = 7 << 23,
|
C3DiF_TexAll = 7 << 23,
|
||||||
|
Loading…
Reference in New Issue
Block a user