From 8792c06adccd7bf5ee5f7a9eb0e6085fc50e14f8 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Tue, 17 Sep 2019 13:35:23 +0200 Subject: [PATCH] gl4: use same depth direction as gles. Round scale_y value. --- core/rend/gl4/abuffer.cpp | 18 ++++---- core/rend/gl4/gl4.h | 2 +- core/rend/gl4/gldraw.cpp | 90 +++++++++++++-------------------------- core/rend/gl4/gles.cpp | 22 +++++----- core/rend/gles/gldraw.cpp | 87 ++++++++++++++++--------------------- core/rend/gles/gles.cpp | 6 +-- core/rend/gles/gles.h | 2 + 7 files changed, 92 insertions(+), 135 deletions(-) diff --git a/core/rend/gl4/abuffer.cpp b/core/rend/gl4/abuffer.cpp index 7daf8da2d..6062edbbf 100644 --- a/core/rend/gl4/abuffer.cpp +++ b/core/rend/gl4/abuffer.cpp @@ -46,7 +46,7 @@ int fillAndSortFragmentArray(ivec2 coords) \n\ Pixel jp = pixels[pixel_list[j]]; \n\ #if DEPTH_SORTED == 1 \n\ while (j >= 0 \n\ - && (jp.depth < p.depth \n\ + && (jp.depth > p.depth \n\ || (jp.depth == p.depth && getPolyNumber(jp) > getPolyNumber(p)))) \n\ #else \n\ while (j >= 0 && getPolyNumber(jp) > getPolyNumber(p)) \n\ @@ -85,28 +85,28 @@ vec4 resolveAlphaBlend(ivec2 coords) { \n\ { \n\ case 0: // Never \n\ continue; \n\ - case 1: // Greater \n\ - if (frag_depth <= depth) \n\ + case 1: // Less \n\ + if (frag_depth >= depth) \n\ continue; \n\ break; \n\ case 2: // Equal \n\ if (frag_depth != depth) \n\ continue; \n\ break; \n\ - case 3: // Greater or equal \n\ - if (frag_depth < depth) \n\ + case 3: // Less or equal \n\ + if (frag_depth > depth) \n\ continue; \n\ break; \n\ - case 4: // Less \n\ - if (frag_depth >= depth) \n\ + case 4: // Greater \n\ + if (frag_depth <= depth) \n\ continue; \n\ break; \n\ case 5: // Not equal \n\ if (frag_depth == depth) \n\ continue; \n\ break; \n\ - case 6: // Less or equal \n\ - if (frag_depth > depth) \n\ + case 6: // Greater or equal \n\ + if (frag_depth < depth) \n\ continue; \n\ break; \n\ case 7: // Always \n\ diff --git a/core/rend/gl4/gl4.h b/core/rend/gl4/gl4.h index 8c8344f94..51c6343df 100755 --- a/core/rend/gl4/gl4.h +++ b/core/rend/gl4/gl4.h @@ -114,7 +114,7 @@ uint getNextPixelIndex() \n\ void setFragDepth(void) \n\ { \n\ highp float w = 100000.0 * gl_FragCoord.w; \n\ - gl_FragDepth = 1.0 - log2(1.0 + w) / 34.0; \n\ + gl_FragDepth = log2(1.0 + w) / 34.0; \n\ } \n\ struct PolyParam { \n\ int first; \n\ diff --git a/core/rend/gl4/gldraw.cpp b/core/rend/gl4/gldraw.cpp index 26e53b336..6a6533313 100644 --- a/core/rend/gl4/gldraw.cpp +++ b/core/rend/gl4/gldraw.cpp @@ -13,28 +13,6 @@ Takes vertex, textures and renders to the currently set up target */ -#define INVERT_DEPTH_FUNC -const static u32 Zfunction[]= -{ - GL_NEVER, //GL_NEVER, //0 Never -#ifndef INVERT_DEPTH_FUNC - GL_LESS, //GL_LESS/*EQUAL*/, //1 Less - GL_EQUAL, //GL_EQUAL, //2 Equal - GL_LEQUAL, //GL_LEQUAL, //3 Less Or Equal - GL_GREATER, //GL_GREATER/*EQUAL*/, //4 Greater - GL_NOTEQUAL, //GL_NOTEQUAL, //5 Not Equal - GL_GEQUAL, //GL_GEQUAL, //6 Greater Or Equal -#else - GL_GREATER, //1 Less - GL_EQUAL, //2 Equal - GL_GEQUAL, //3 Less Or Equal - GL_LESS, //4 Greater - GL_NOTEQUAL, //5 Not Equal - GL_LEQUAL, //6 Greater Or Equal -#endif - GL_ALWAYS, //GL_ALWAYS, //7 Always -}; - static gl4PipelineShader* CurrentShader; extern u32 gcflip; static GLuint geom_fbo; @@ -236,7 +214,7 @@ template //set Z mode, only if required if (Type == ListType_Punch_Through || (pass == 0 && SortingEnabled)) { - glcache.DepthFunc(Zfunction[6]); // Greater or equal + glcache.DepthFunc(GL_GEQUAL); } else if (Type == ListType_Opaque || (pass == 0 && !SortingEnabled)) { @@ -344,51 +322,41 @@ static void DrawModVols(int first, int count) glcache.UseProgram(gl4.modvol_shader.program); + glcache.Enable(GL_DEPTH_TEST); glcache.DepthMask(GL_FALSE); - glcache.DepthFunc(Zfunction[4]); + glcache.DepthFunc(GL_GREATER); - if(false) + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + + ModifierVolumeParam* params = &pvrrc.global_param_mvo.head()[first]; + + int mod_base = -1; + + for (u32 cmv = 0; cmv < count; cmv++) { - //simply draw the volumes -- for debugging - SetCull(0); - glDrawArrays(GL_TRIANGLES, first, count * 3); - } - else - { - //Full emulation + ModifierVolumeParam& param = params[cmv]; - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + if (param.count == 0) + continue; - ModifierVolumeParam* params = &pvrrc.global_param_mvo.head()[first]; + u32 mv_mode = param.isp.DepthMode; - int mod_base = -1; + if (mod_base == -1) + mod_base = param.first; - for (u32 cmv = 0; cmv < count; cmv++) + if (!param.isp.VolumeLast && mv_mode > 0) + SetMVS_Mode(Or, param.isp); // OR'ing (open volume or quad) + else + SetMVS_Mode(Xor, param.isp); // XOR'ing (closed volume) + + glDrawArrays(GL_TRIANGLES, param.first * 3, param.count * 3); + + if (mv_mode == 1 || mv_mode == 2) { - ModifierVolumeParam& param = params[cmv]; - - if (param.count == 0) - continue; - - u32 mv_mode = param.isp.DepthMode; - - if (mod_base == -1) - mod_base = param.first; - - if (!param.isp.VolumeLast && mv_mode > 0) - SetMVS_Mode(Or, param.isp); // OR'ing (open volume or quad) - else - SetMVS_Mode(Xor, param.isp); // XOR'ing (closed volume) - - glDrawArrays(GL_TRIANGLES, param.first * 3, param.count * 3); - - if (mv_mode == 1 || mv_mode == 2) - { - // Sum the area - SetMVS_Mode(mv_mode == 1 ? Inclusion : Exclusion, param.isp); - glDrawArrays(GL_TRIANGLES, mod_base * 3, (param.first + param.count - mod_base) * 3); - mod_base = -1; - } + // Sum the area + SetMVS_Mode(mv_mode == 1 ? Inclusion : Exclusion, param.isp); + glDrawArrays(GL_TRIANGLES, mod_base * 3, (param.first + param.count - mod_base) * 3); + mod_base = -1; } } @@ -457,6 +425,7 @@ void gl4DrawStrips(GLuint output_fbo, int width, int height) glGenSamplers(2, texSamplers); glcache.DepthMask(GL_TRUE); + glClearDepthf(0.0); glStencilMask(0xFF); glClear(GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glCheck(); @@ -553,6 +522,7 @@ void gl4DrawStrips(GLuint output_fbo, int width, int height) if (render_pass == 0) { glcache.DepthMask(GL_TRUE); + glClearDepthf(0.0); glClear(GL_DEPTH_BUFFER_BIT); } else diff --git a/core/rend/gl4/gles.cpp b/core/rend/gl4/gles.cpp index bc93a4f62..83fac9be7 100644 --- a/core/rend/gl4/gles.cpp +++ b/core/rend/gl4/gles.cpp @@ -159,23 +159,23 @@ void main() \n\ highp float frontDepth = texture(DepthTex, gl_FragCoord.xy / textureSize(DepthTex, 0)).r; \n\ #if pp_DepthFunc == 0 // Never \n\ discard; \n\ - #elif pp_DepthFunc == 1 // Greater \n\ - if (gl_FragDepth <= frontDepth) \n\ + #elif pp_DepthFunc == 1 // Less \n\ + if (gl_FragDepth >= frontDepth) \n\ discard; \n\ #elif pp_DepthFunc == 2 // Equal \n\ if (gl_FragDepth != frontDepth) \n\ discard; \n\ - #elif pp_DepthFunc == 3 // Greater or equal \n\ - if (gl_FragDepth < frontDepth) \n\ + #elif pp_DepthFunc == 3 // Less or equal \n\ + if (gl_FragDepth > frontDepth) \n\ discard; \n\ - #elif pp_DepthFunc == 4 // Less \n\ - if (gl_FragDepth >= frontDepth) \n\ + #elif pp_DepthFunc == 4 // Greater \n\ + if (gl_FragDepth <= frontDepth) \n\ discard; \n\ #elif pp_DepthFunc == 5 // Not equal \n\ if (gl_FragDepth == frontDepth) \n\ discard; \n\ - #elif pp_DepthFunc == 6 // Less or equal \n\ - if (gl_FragDepth > frontDepth) \n\ + #elif pp_DepthFunc == 6 // Greater or equal \n\ + if (gl_FragDepth < frontDepth) \n\ discard; \n\ #endif \n\ #endif \n\ @@ -687,8 +687,8 @@ static bool RenderFrame() { scale_x=fb_scale_x; scale_y=fb_scale_y; - if (SCALER_CTL.interlace == 0 && SCALER_CTL.vscalefactor >= 0x400) - scale_y *= (float)SCALER_CTL.vscalefactor / 0x400; + if (SCALER_CTL.interlace == 0 && SCALER_CTL.vscalefactor > 0x400) + scale_y *= roundf((float)SCALER_CTL.vscalefactor / 0x400); //work out scaling parameters ! //Pixel doubling is on VO, so it does not affect any pixel operations @@ -906,7 +906,7 @@ static bool RenderFrame() float min_y = pvrrc.fb_Y_CLIP.min / scale_y; if (!is_rtt) { - if (SCALER_CTL.interlace && SCALER_CTL.vscalefactor >= 0x400) + if (SCALER_CTL.interlace && SCALER_CTL.vscalefactor > 0x400) { // Clipping is done after scaling/filtering so account for that if enabled height *= (float)SCALER_CTL.vscalefactor / 0x400; diff --git a/core/rend/gles/gldraw.cpp b/core/rend/gles/gldraw.cpp index 7875ade4e..90795375b 100644 --- a/core/rend/gles/gldraw.cpp +++ b/core/rend/gles/gldraw.cpp @@ -7,30 +7,26 @@ Drawing and related state management Takes vertex, textures and renders to the currently set up target - - - */ const static u32 CullMode[]= { - GL_NONE, //0 No culling No culling GL_NONE, //1 Cull if Small Cull if ( |det| < fpu_cull_val ) GL_FRONT, //2 Cull if Negative Cull if ( |det| < 0 ) or ( |det| < fpu_cull_val ) GL_BACK, //3 Cull if Positive Cull if ( |det| > 0 ) or ( |det| < fpu_cull_val ) }; -const static u32 Zfunction[]= +const u32 Zfunction[] = { - GL_NEVER, //GL_NEVER, //0 Never - GL_LESS, //GL_LESS/*EQUAL*/, //1 Less - GL_EQUAL, //GL_EQUAL, //2 Equal - GL_LEQUAL, //GL_LEQUAL, //3 Less Or Equal - GL_GREATER, //GL_GREATER/*EQUAL*/, //4 Greater - GL_NOTEQUAL, //GL_NOTEQUAL, //5 Not Equal - GL_GEQUAL, //GL_GEQUAL, //6 Greater Or Equal - GL_ALWAYS, //GL_ALWAYS, //7 Always + GL_NEVER, //0 Never + GL_LESS, //1 Less + GL_EQUAL, //2 Equal + GL_LEQUAL, //3 Less Or Equal + GL_GREATER, //4 Greater + GL_NOTEQUAL, //5 Not Equal + GL_GEQUAL, //6 Greater Or Equal + GL_ALWAYS, //7 Always }; /* @@ -73,7 +69,6 @@ extern int screen_height; PipelineShader* CurrentShader; u32 gcflip; -static GLuint g_previous_frame_tex; s32 SetTileClip(u32 val, GLint uniform) { @@ -1003,53 +998,43 @@ void DrawModVols(int first, int count) glcache.UseProgram(gl.modvol_shader.program); glUniform1f(gl.modvol_shader.sp_ShaderColor, 1 - FPU_SHAD_SCALE.scale_factor / 256.f); + glcache.Enable(GL_DEPTH_TEST); glcache.DepthMask(GL_FALSE); glcache.DepthFunc(GL_GREATER); - if(0) + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + + ModifierVolumeParam* params = &pvrrc.global_param_mvo.head()[first]; + + int mod_base = -1; + + for (u32 cmv = 0; cmv < count; cmv++) { - //simply draw the volumes -- for debugging - SetCull(0); - glDrawArrays(GL_TRIANGLES, first, count * 3); - SetupMainVBO(); - } - else - { - //Full emulation + ModifierVolumeParam& param = params[cmv]; - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + if (param.count == 0) + continue; - ModifierVolumeParam* params = &pvrrc.global_param_mvo.head()[first]; + u32 mv_mode = param.isp.DepthMode; - int mod_base = -1; + if (mod_base == -1) + mod_base = param.first; - for (u32 cmv = 0; cmv < count; cmv++) + if (!param.isp.VolumeLast && mv_mode > 0) + SetMVS_Mode(Or, param.isp); // OR'ing (open volume or quad) + else + SetMVS_Mode(Xor, param.isp); // XOR'ing (closed volume) + + glDrawArrays(GL_TRIANGLES, param.first * 3, param.count * 3); + + if (mv_mode == 1 || mv_mode == 2) { - ModifierVolumeParam& param = params[cmv]; - - if (param.count == 0) - continue; - - u32 mv_mode = param.isp.DepthMode; - - if (mod_base == -1) - mod_base = param.first; - - if (!param.isp.VolumeLast && mv_mode > 0) - SetMVS_Mode(Or, param.isp); // OR'ing (open volume or quad) - else - SetMVS_Mode(Xor, param.isp); // XOR'ing (closed volume) - - glDrawArrays(GL_TRIANGLES, param.first * 3, param.count * 3); - - if (mv_mode == 1 || mv_mode == 2) - { - // Sum the area - SetMVS_Mode(mv_mode == 1 ? Inclusion : Exclusion, param.isp); - glDrawArrays(GL_TRIANGLES, mod_base * 3, (param.first + param.count - mod_base) * 3); - mod_base = -1; - } + // Sum the area + SetMVS_Mode(mv_mode == 1 ? Inclusion : Exclusion, param.isp); + glDrawArrays(GL_TRIANGLES, mod_base * 3, (param.first + param.count - mod_base) * 3); + mod_base = -1; } + //disable culling SetCull(0); //enable color writes diff --git a/core/rend/gles/gles.cpp b/core/rend/gles/gles.cpp index 825b8e363..307f9ba53 100644 --- a/core/rend/gles/gles.cpp +++ b/core/rend/gles/gles.cpp @@ -1745,8 +1745,8 @@ bool RenderFrame() { scale_x=fb_scale_x; scale_y=fb_scale_y; - if (SCALER_CTL.interlace == 0 && SCALER_CTL.vscalefactor >= 0x400) - scale_y *= (float)SCALER_CTL.vscalefactor / 0x400; + if (SCALER_CTL.interlace == 0 && SCALER_CTL.vscalefactor > 0x400) + scale_y *= roundf((float)SCALER_CTL.vscalefactor / 0x400); //work out scaling parameters ! //Pixel doubling is on VO, so it does not affect any pixel operations @@ -1996,7 +1996,7 @@ bool RenderFrame() float min_y = pvrrc.fb_Y_CLIP.min / scale_y; if (!is_rtt) { - if (SCALER_CTL.interlace && SCALER_CTL.vscalefactor >= 0x400) + if (SCALER_CTL.interlace && SCALER_CTL.vscalefactor > 0x400) { // Clipping is done after scaling/filtering so account for that if enabled height *= (float)SCALER_CTL.vscalefactor / 0x400; diff --git a/core/rend/gles/gles.h b/core/rend/gles/gles.h index 87a27e0d6..0ac0d8da5 100755 --- a/core/rend/gles/gles.h +++ b/core/rend/gles/gles.h @@ -296,3 +296,5 @@ struct TextureCacheData bool NeedsUpdate(); bool Delete(); }; + +extern const u32 Zfunction[8];