@@ -206,8 +206,7 @@ namespace cage
206206
207207 void updateDynamicResolution ()
208208 {
209- // dynamic resolution may update every 4 frames at most
210- if ((frameIndex % 4 ) != 0 || frameIndex < 100 )
209+ if (frameIndex < nextAllowedDrFrameIndex)
211210 return ;
212211
213212 if (!engineDynamicResolution ().enabled )
@@ -226,8 +225,11 @@ namespace cage
226225 if (!valid (k))
227226 return ;
228227 k = clamp (k, engineDynamicResolution ().minimumScale , 1 );
229- if (abs (dynamicResolution - k) > 0.02 )
230- dynamicResolution = k;
228+ if (abs (dynamicResolution - k) < 0.02 )
229+ return ;
230+
231+ dynamicResolution = k;
232+ nextAllowedDrFrameIndex = frameIndex + 5 ;
231233 }
232234
233235 void prepareCameras (const RenderPipelineConfig &cfg, Holder<VirtualRealityGraphicsFrame> vrFrame)
@@ -474,11 +476,15 @@ namespace cage
474476 void swap () // opengl thread
475477 {
476478 CAGE_CHECK_GL_ERROR_DEBUG ();
479+ engineWindow ()->swapBuffers ();
480+ }
481+
482+ void frameStart () { timeQueries[0 ].start (); }
483+
484+ void frameFinish ()
485+ {
477486 timeQueries[0 ].finish ();
478487 std::rotate (timeQueries.begin (), timeQueries.begin () + 1 , timeQueries.end ());
479- engineWindow ()->swapBuffers ();
480- // this is where the engine should be waiting for the gpu
481- timeQueries[0 ].start ();
482488 }
483489
484490 Holder<RenderQueue> renderQueue;
@@ -491,6 +497,7 @@ namespace cage
491497 uint64 lastDispatchTime = 0 ;
492498 uint32 frameIndex = 0 ;
493499 Real dynamicResolution = 1 ;
500+ uint32 nextAllowedDrFrameIndex = 100 ; // do not update DR at the very start
494501 std::array<TimeQuery, 3 > timeQueries = {};
495502 };
496503
@@ -535,9 +542,19 @@ namespace cage
535542 graphics->dispatch ();
536543 }
537544
538- void graphicsSwap (uint64 &gpuTime )
545+ void graphicsSwap ()
539546 {
540547 graphics->swap ();
548+ }
549+
550+ void graphicsFrameStart ()
551+ {
552+ graphics->frameStart ();
553+ }
554+
555+ void graphicsFrameFinish (uint64 &gpuTime)
556+ {
557+ graphics->frameFinish ();
541558 gpuTime = graphics->timeQueries [0 ].time / 1000 ;
542559 }
543560
0 commit comments