gl4: use same depth direction as gles. Round scale_y value.

This commit is contained in:
Flyinghead 2019-09-17 13:35:23 +02:00
parent 732e685ea7
commit 8792c06adc
7 changed files with 92 additions and 135 deletions

View File

@ -46,7 +46,7 @@ int fillAndSortFragmentArray(ivec2 coords) \n\
Pixel jp = pixels[pixel_list[j]]; \n\ Pixel jp = pixels[pixel_list[j]]; \n\
#if DEPTH_SORTED == 1 \n\ #if DEPTH_SORTED == 1 \n\
while (j >= 0 \n\ while (j >= 0 \n\
&& (jp.depth < p.depth \n\ && (jp.depth > p.depth \n\
|| (jp.depth == p.depth && getPolyNumber(jp) > getPolyNumber(p)))) \n\ || (jp.depth == p.depth && getPolyNumber(jp) > getPolyNumber(p)))) \n\
#else \n\ #else \n\
while (j >= 0 && getPolyNumber(jp) > getPolyNumber(p)) \n\ while (j >= 0 && getPolyNumber(jp) > getPolyNumber(p)) \n\
@ -85,28 +85,28 @@ vec4 resolveAlphaBlend(ivec2 coords) { \n\
{ \n\ { \n\
case 0: // Never \n\ case 0: // Never \n\
continue; \n\ continue; \n\
case 1: // Greater \n\ case 1: // Less \n\
if (frag_depth <= depth) \n\ if (frag_depth >= depth) \n\
continue; \n\ continue; \n\
break; \n\ break; \n\
case 2: // Equal \n\ case 2: // Equal \n\
if (frag_depth != depth) \n\ if (frag_depth != depth) \n\
continue; \n\ continue; \n\
break; \n\ break; \n\
case 3: // Greater or equal \n\ case 3: // Less or equal \n\
if (frag_depth < depth) \n\ if (frag_depth > depth) \n\
continue; \n\ continue; \n\
break; \n\ break; \n\
case 4: // Less \n\ case 4: // Greater \n\
if (frag_depth >= depth) \n\ if (frag_depth <= depth) \n\
continue; \n\ continue; \n\
break; \n\ break; \n\
case 5: // Not equal \n\ case 5: // Not equal \n\
if (frag_depth == depth) \n\ if (frag_depth == depth) \n\
continue; \n\ continue; \n\
break; \n\ break; \n\
case 6: // Less or equal \n\ case 6: // Greater or equal \n\
if (frag_depth > depth) \n\ if (frag_depth < depth) \n\
continue; \n\ continue; \n\
break; \n\ break; \n\
case 7: // Always \n\ case 7: // Always \n\

View File

@ -114,7 +114,7 @@ uint getNextPixelIndex() \n\
void setFragDepth(void) \n\ void setFragDepth(void) \n\
{ \n\ { \n\
highp float w = 100000.0 * gl_FragCoord.w; \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\ } \n\
struct PolyParam { \n\ struct PolyParam { \n\
int first; \n\ int first; \n\

View File

@ -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; static gl4PipelineShader* CurrentShader;
extern u32 gcflip; extern u32 gcflip;
static GLuint geom_fbo; static GLuint geom_fbo;
@ -236,7 +214,7 @@ template <u32 Type, bool SortingEnabled>
//set Z mode, only if required //set Z mode, only if required
if (Type == ListType_Punch_Through || (pass == 0 && SortingEnabled)) 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)) 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.UseProgram(gl4.modvol_shader.program);
glcache.Enable(GL_DEPTH_TEST);
glcache.DepthMask(GL_FALSE); 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 ModifierVolumeParam& param = params[cmv];
SetCull(0);
glDrawArrays(GL_TRIANGLES, first, count * 3);
}
else
{
//Full emulation
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]; // Sum the area
SetMVS_Mode(mv_mode == 1 ? Inclusion : Exclusion, param.isp);
if (param.count == 0) glDrawArrays(GL_TRIANGLES, mod_base * 3, (param.first + param.count - mod_base) * 3);
continue; mod_base = -1;
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;
}
} }
} }
@ -457,6 +425,7 @@ void gl4DrawStrips(GLuint output_fbo, int width, int height)
glGenSamplers(2, texSamplers); glGenSamplers(2, texSamplers);
glcache.DepthMask(GL_TRUE); glcache.DepthMask(GL_TRUE);
glClearDepthf(0.0);
glStencilMask(0xFF); glStencilMask(0xFF);
glClear(GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glCheck(); 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) if (render_pass == 0)
{ {
glcache.DepthMask(GL_TRUE); glcache.DepthMask(GL_TRUE);
glClearDepthf(0.0);
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
} }
else else

View File

@ -159,23 +159,23 @@ void main() \n\
highp float frontDepth = texture(DepthTex, gl_FragCoord.xy / textureSize(DepthTex, 0)).r; \n\ highp float frontDepth = texture(DepthTex, gl_FragCoord.xy / textureSize(DepthTex, 0)).r; \n\
#if pp_DepthFunc == 0 // Never \n\ #if pp_DepthFunc == 0 // Never \n\
discard; \n\ discard; \n\
#elif pp_DepthFunc == 1 // Greater \n\ #elif pp_DepthFunc == 1 // Less \n\
if (gl_FragDepth <= frontDepth) \n\ if (gl_FragDepth >= frontDepth) \n\
discard; \n\ discard; \n\
#elif pp_DepthFunc == 2 // Equal \n\ #elif pp_DepthFunc == 2 // Equal \n\
if (gl_FragDepth != frontDepth) \n\ if (gl_FragDepth != frontDepth) \n\
discard; \n\ discard; \n\
#elif pp_DepthFunc == 3 // Greater or equal \n\ #elif pp_DepthFunc == 3 // Less or equal \n\
if (gl_FragDepth < frontDepth) \n\ if (gl_FragDepth > frontDepth) \n\
discard; \n\ discard; \n\
#elif pp_DepthFunc == 4 // Less \n\ #elif pp_DepthFunc == 4 // Greater \n\
if (gl_FragDepth >= frontDepth) \n\ if (gl_FragDepth <= frontDepth) \n\
discard; \n\ discard; \n\
#elif pp_DepthFunc == 5 // Not equal \n\ #elif pp_DepthFunc == 5 // Not equal \n\
if (gl_FragDepth == frontDepth) \n\ if (gl_FragDepth == frontDepth) \n\
discard; \n\ discard; \n\
#elif pp_DepthFunc == 6 // Less or equal \n\ #elif pp_DepthFunc == 6 // Greater or equal \n\
if (gl_FragDepth > frontDepth) \n\ if (gl_FragDepth < frontDepth) \n\
discard; \n\ discard; \n\
#endif \n\ #endif \n\
#endif \n\ #endif \n\
@ -687,8 +687,8 @@ static bool RenderFrame()
{ {
scale_x=fb_scale_x; scale_x=fb_scale_x;
scale_y=fb_scale_y; scale_y=fb_scale_y;
if (SCALER_CTL.interlace == 0 && SCALER_CTL.vscalefactor >= 0x400) if (SCALER_CTL.interlace == 0 && SCALER_CTL.vscalefactor > 0x400)
scale_y *= (float)SCALER_CTL.vscalefactor / 0x400; scale_y *= roundf((float)SCALER_CTL.vscalefactor / 0x400);
//work out scaling parameters ! //work out scaling parameters !
//Pixel doubling is on VO, so it does not affect any pixel operations //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; float min_y = pvrrc.fb_Y_CLIP.min / scale_y;
if (!is_rtt) 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 // Clipping is done after scaling/filtering so account for that if enabled
height *= (float)SCALER_CTL.vscalefactor / 0x400; height *= (float)SCALER_CTL.vscalefactor / 0x400;

View File

@ -7,30 +7,26 @@
Drawing and related state management Drawing and related state management
Takes vertex, textures and renders to the currently set up target Takes vertex, textures and renders to the currently set up target
*/ */
const static u32 CullMode[]= const static u32 CullMode[]=
{ {
GL_NONE, //0 No culling No culling GL_NONE, //0 No culling No culling
GL_NONE, //1 Cull if Small Cull if ( |det| < fpu_cull_val ) 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_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 ) 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_NEVER, //0 Never
GL_LESS, //GL_LESS/*EQUAL*/, //1 Less GL_LESS, //1 Less
GL_EQUAL, //GL_EQUAL, //2 Equal GL_EQUAL, //2 Equal
GL_LEQUAL, //GL_LEQUAL, //3 Less Or Equal GL_LEQUAL, //3 Less Or Equal
GL_GREATER, //GL_GREATER/*EQUAL*/, //4 Greater GL_GREATER, //4 Greater
GL_NOTEQUAL, //GL_NOTEQUAL, //5 Not Equal GL_NOTEQUAL, //5 Not Equal
GL_GEQUAL, //GL_GEQUAL, //6 Greater Or Equal GL_GEQUAL, //6 Greater Or Equal
GL_ALWAYS, //GL_ALWAYS, //7 Always GL_ALWAYS, //7 Always
}; };
/* /*
@ -73,7 +69,6 @@ extern int screen_height;
PipelineShader* CurrentShader; PipelineShader* CurrentShader;
u32 gcflip; u32 gcflip;
static GLuint g_previous_frame_tex;
s32 SetTileClip(u32 val, GLint uniform) s32 SetTileClip(u32 val, GLint uniform)
{ {
@ -1003,53 +998,43 @@ void DrawModVols(int first, int count)
glcache.UseProgram(gl.modvol_shader.program); glcache.UseProgram(gl.modvol_shader.program);
glUniform1f(gl.modvol_shader.sp_ShaderColor, 1 - FPU_SHAD_SCALE.scale_factor / 256.f); glUniform1f(gl.modvol_shader.sp_ShaderColor, 1 - FPU_SHAD_SCALE.scale_factor / 256.f);
glcache.Enable(GL_DEPTH_TEST);
glcache.DepthMask(GL_FALSE); glcache.DepthMask(GL_FALSE);
glcache.DepthFunc(GL_GREATER); 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 ModifierVolumeParam& param = params[cmv];
SetCull(0);
glDrawArrays(GL_TRIANGLES, first, count * 3);
SetupMainVBO();
}
else
{
//Full emulation
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]; // Sum the area
SetMVS_Mode(mv_mode == 1 ? Inclusion : Exclusion, param.isp);
if (param.count == 0) glDrawArrays(GL_TRIANGLES, mod_base * 3, (param.first + param.count - mod_base) * 3);
continue; mod_base = -1;
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;
}
} }
//disable culling //disable culling
SetCull(0); SetCull(0);
//enable color writes //enable color writes

View File

@ -1745,8 +1745,8 @@ bool RenderFrame()
{ {
scale_x=fb_scale_x; scale_x=fb_scale_x;
scale_y=fb_scale_y; scale_y=fb_scale_y;
if (SCALER_CTL.interlace == 0 && SCALER_CTL.vscalefactor >= 0x400) if (SCALER_CTL.interlace == 0 && SCALER_CTL.vscalefactor > 0x400)
scale_y *= (float)SCALER_CTL.vscalefactor / 0x400; scale_y *= roundf((float)SCALER_CTL.vscalefactor / 0x400);
//work out scaling parameters ! //work out scaling parameters !
//Pixel doubling is on VO, so it does not affect any pixel operations //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; float min_y = pvrrc.fb_Y_CLIP.min / scale_y;
if (!is_rtt) 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 // Clipping is done after scaling/filtering so account for that if enabled
height *= (float)SCALER_CTL.vscalefactor / 0x400; height *= (float)SCALER_CTL.vscalefactor / 0x400;

View File

@ -296,3 +296,5 @@ struct TextureCacheData
bool NeedsUpdate(); bool NeedsUpdate();
bool Delete(); bool Delete();
}; };
extern const u32 Zfunction[8];