Implement clipping. Enabled by default.

This commit is contained in:
Flyinghead 2018-05-02 15:41:42 +02:00
parent d0cd5a5f64
commit 08b8d30589
4 changed files with 36 additions and 7 deletions

View File

@ -244,6 +244,7 @@ void LoadSettings()
settings.rend.UseMipmaps = cfgLoadInt("config","rend.UseMipmaps",1);
settings.rend.WideScreen = cfgLoadInt("config","rend.WideScreen",0);
settings.rend.ModifierVolumes = cfgLoadInt("config","rend.ModifierVolumes",1);
settings.rend.Clipping = cfgLoadInt("config","rend.Clipping",1);
settings.pvr.subdivide_transp = cfgLoadInt("config","pvr.Subdivide",0);

View File

@ -74,6 +74,8 @@ const static u32 SrcBlendGL[] =
GL_ONE_MINUS_DST_ALPHA
};
extern int screen_width;
extern int screen_height;
PipelineShader* CurrentShader;
u32 gcflip;
@ -106,6 +108,9 @@ static struct
s32 SetTileClip(u32 val, bool set)
{
if (!settings.rend.Clipping)
return 0;
/*
if (set)
{
@ -121,9 +126,9 @@ s32 SetTileClip(u32 val, bool set)
clip_mode=0; //always passes
}
else if (clipmode&1)
clip_mode=-1; //render stuff inside the region
clip_mode=-1; //render stuff outside the region
else
clip_mode=1; //render stuff outside the region
clip_mode=1; //render stuff inside the region
float csx=0,csy=0,cex=0,cey=0;
@ -137,11 +142,20 @@ s32 SetTileClip(u32 val, bool set)
csy=csy*32;
cey=cey*32 +32;
if (csx==0 && csy==0 && cex==640 && cey==480)
if (csx <= 0 && csy <= 0 && cex >= 640 && cey >= 480)
return 0;
if (set)
glUniform4f(CurrentShader->pp_ClipTest,-csx,-csy,-cex,-cey);
if (set && clip_mode) {
csy = 480 - csy;
cey = 480 - cey;
float dc2s_scale_h = screen_height / 480.0f;
float ds2s_offs_x = (screen_width - dc2s_scale_h * 640) / 2;
csx = csx * dc2s_scale_h + ds2s_offs_x;
cex = cex * dc2s_scale_h + ds2s_offs_x;
csy = csy * dc2s_scale_h;
cey = cey * dc2s_scale_h;
glUniform4f(CurrentShader->pp_ClipTest, csx, cey, cex, csy);
}
return clip_mode;
}
@ -173,8 +187,8 @@ __forceinline
{
cache.program=CurrentShader->program;
glUseProgram(CurrentShader->program);
SetTileClip(gp->tileclip,true);
}
SetTileClip(gp->tileclip,true);
//This for some reason doesn't work properly
//So, shadow bit emulation is disabled.

View File

@ -233,7 +233,7 @@ const char* PixelPipelineShader =
"\
\
#define cp_AlphaTest %d \n\
#define pp_ClipTestMode %d.0 \n\
#define pp_ClipTestMode %d \n\
#define pp_UseAlpha %d \n\
#define pp_Texture %d \n\
#define pp_IgnoreTexA %d \n\
@ -259,6 +259,19 @@ lowp float fog_mode2(highp float val) \n\
} \n\
void main() \n\
{ \n\
// Clip outside the box \n\
#if pp_ClipTestMode==1 \n\
if (gl_FragCoord.x < pp_ClipTest.x || gl_FragCoord.x > pp_ClipTest.z \n\
|| gl_FragCoord.y < pp_ClipTest.y || gl_FragCoord.y > pp_ClipTest.w) \n\
discard; \n\
#endif \n\
// Clip inside the box \n\
#if pp_ClipTestMode==-1 \n\
if (gl_FragCoord.x >= pp_ClipTest.x && gl_FragCoord.x <= pp_ClipTest.z \n\
&& gl_FragCoord.y >= pp_ClipTest.y && gl_FragCoord.y <= pp_ClipTest.w) \n\
discard; \n\
#endif \n\
\n\
lowp vec4 color=vtx_base; \n\
#if pp_UseAlpha==0 \n\
color.a=1.0; \n\

View File

@ -616,6 +616,7 @@ struct settings_t
bool UseMipmaps;
bool WideScreen;
bool ModifierVolumes;
bool Clipping;
} rend;
struct