From 33ea011757d79d87baf734be6ad006be43beb0fe Mon Sep 17 00:00:00 2001 From: havoc Date: Fri, 1 Apr 2011 07:04:58 +0000 Subject: [PATCH] reworked r_viewscale_fpsscaling to use the time of SCR_DrawScreen wrapped in glFinish calls (REALLY should use GL_EXT_timery_query), this means that vid_vsync now works fine with it git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10995 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=48ac175a246c448d53cd83c723c3f9a668fb313d --- cl_screen.c | 14 ++++++++++++-- client.h | 3 +++ gl_rmain.c | 6 ++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/cl_screen.c b/cl_screen.c index b8addbba..75bf4e02 100644 --- a/cl_screen.c +++ b/cl_screen.c @@ -781,6 +781,8 @@ static int R_CountLeafTriangles(const dp_model_t *model, const mleaf_t *leaf) return triangles; } +extern cvar_t r_viewscale; +extern float viewscalefpsadjusted; void R_TimeReport_EndFrame(void) { int i, j, lines, y; @@ -796,7 +798,7 @@ void R_TimeReport_EndFrame(void) loc = CL_Locs_FindNearest(cl.movement_origin); viewleaf = (r_refdef.scene.worldmodel && r_refdef.scene.worldmodel->brush.PointInLeaf) ? r_refdef.scene.worldmodel->brush.PointInLeaf(r_refdef.scene.worldmodel, r_refdef.view.origin) : NULL; dpsnprintf(string, sizeof(string), -"%s%s\n" +"%6.0fus rendertime %3.0f%% viewscale %s%s\n" "%3i renders org:'%+8.2f %+8.2f %+8.2f' dir:'%+2.3f %+2.3f %+2.3f'\n" "%5i viewleaf%5i cluster%2i area%4i brushes%4i surfaces(%7i triangles)\n" "%7i surfaces%7i triangles %5i entities (%7i surfaces%7i triangles)\n" @@ -808,7 +810,7 @@ void R_TimeReport_EndFrame(void) "%6i draws%8i vertices%8i triangles bloompixels%8i copied%8i drawn\n" "updated%5i indexbuffers%8i bytes%5i vertexbuffers%8i bytes\n" "%s" -, loc ? "Location: " : "", loc ? loc->name : "" +, r_refdef.lastdrawscreentime * 1000000.0, r_viewscale.value * sqrt(viewscalefpsadjusted) * 100.0f, loc ? "Location: " : "", loc ? loc->name : "" , r_refdef.stats.renders, r_refdef.view.origin[0], r_refdef.view.origin[1], r_refdef.view.origin[2], r_refdef.view.forward[0], r_refdef.view.forward[1], r_refdef.view.forward[2] , viewleaf ? (int)(viewleaf - r_refdef.scene.worldmodel->brush.data_leafs) : -1, viewleaf ? viewleaf->clusterindex : -1, viewleaf ? viewleaf->areaindex : -1, viewleaf ? viewleaf->numleafbrushes : 0, viewleaf ? viewleaf->numleafsurfaces : 0, viewleaf ? R_CountLeafTriangles(r_refdef.scene.worldmodel, viewleaf) : 0 , r_refdef.stats.world_surfaces, r_refdef.stats.world_triangles, r_refdef.stats.entities, r_refdef.stats.entities_surfaces, r_refdef.stats.entities_triangles @@ -2196,6 +2198,7 @@ extern cvar_t cl_minfps_qualitymax; extern cvar_t cl_minfps_qualitymin; extern cvar_t cl_minfps_qualitypower; extern cvar_t cl_minfps_qualityscale; +extern cvar_t r_viewscale_fpsscaling; static double cl_updatescreen_rendertime = 0; static double cl_updatescreen_quality = 1; extern void Sbar_ShowFPS_Update(void); @@ -2203,6 +2206,7 @@ void CL_UpdateScreen(void) { vec3_t vieworigin; double rendertime1; + double drawscreenstart; float conwidth, conheight; float f; r_viewport_t viewport; @@ -2331,6 +2335,9 @@ void CL_UpdateScreen(void) } } + if (r_viewscale_fpsscaling.integer && qglFinish) + qglFinish(); + drawscreenstart = Sys_DoubleTime(); if (R_Stereo_Active()) { r_stereo_side = 0; @@ -2363,6 +2370,9 @@ void CL_UpdateScreen(void) } else SCR_DrawScreen(); + if (r_viewscale_fpsscaling.integer && qglFinish) + qglFinish(); + r_refdef.lastdrawscreentime = Sys_DoubleTime() - drawscreenstart; SCR_CaptureVideo(); diff --git a/client.h b/client.h index 0df5daee..909a5e22 100644 --- a/client.h +++ b/client.h @@ -1824,6 +1824,9 @@ typedef struct r_refdef_s float shadowpolygonfactor; float shadowpolygonoffset; + // how long R_RenderView took on the previous frame + double lastdrawscreentime; + // rendering stats for r_speeds display // (these are incremented in many places) r_refdef_stats_t stats; diff --git a/gl_rmain.c b/gl_rmain.c index 59cf2874..14006411 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -5125,7 +5125,7 @@ void R_View_Update(void) R_View_UpdateEntityLighting(); } -static float viewscalefpsadjusted = 1.0f; +float viewscalefpsadjusted = 1.0f; void R_GetScaledViewSize(int width, int height, int *outwidth, int *outheight) { @@ -5687,18 +5687,16 @@ void R_Bloom_StartFrame(void) if (r_viewscale_fpsscaling.integer) { - static double lastrealtime; double actualframetime; double targetframetime; double adjust; - actualframetime = realtime - lastrealtime; + actualframetime = r_refdef.lastdrawscreentime; targetframetime = (1.0 / r_viewscale_fpsscaling_target.value); adjust = (targetframetime - actualframetime) * r_viewscale_fpsscaling_multiply.value; adjust = bound(-r_viewscale_fpsscaling_stepmax.value, adjust, r_viewscale_fpsscaling_stepmax.value); if (r_viewscale_fpsscaling_stepsize.value > 0) adjust = (int)(adjust / r_viewscale_fpsscaling_stepsize.value) * r_viewscale_fpsscaling_stepsize.value; viewscalefpsadjusted += adjust; - lastrealtime = realtime; viewscalefpsadjusted = bound(r_viewscale_fpsscaling_min.value, viewscalefpsadjusted, 1.0f); } else -- 2.39.2