From 08b8d305899f4d09583df118cfe6ff8e522861c3 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Wed, 2 May 2018 15:41:42 +0200 Subject: [PATCH] Implement clipping. Enabled by default. --- core/nullDC.cpp | 1 + core/rend/gles/gldraw.cpp | 26 ++++++++++++++++++++------ core/rend/gles/gles.cpp | 15 ++++++++++++++- core/types.h | 1 + 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/core/nullDC.cpp b/core/nullDC.cpp index c62db04e8..6c8ac67f0 100755 --- a/core/nullDC.cpp +++ b/core/nullDC.cpp @@ -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); diff --git a/core/rend/gles/gldraw.cpp b/core/rend/gles/gldraw.cpp index ed0ae7a3a..ded55e1d4 100644 --- a/core/rend/gles/gldraw.cpp +++ b/core/rend/gles/gldraw.cpp @@ -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. diff --git a/core/rend/gles/gles.cpp b/core/rend/gles/gles.cpp index ef16af4e9..f6c208eec 100755 --- a/core/rend/gles/gles.cpp +++ b/core/rend/gles/gles.cpp @@ -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\ diff --git a/core/types.h b/core/types.h index 24df94bde..b9c6333c9 100644 --- a/core/types.h +++ b/core/types.h @@ -616,6 +616,7 @@ struct settings_t bool UseMipmaps; bool WideScreen; bool ModifierVolumes; + bool Clipping; } rend; struct