From: <z-...@us...> - 2007-11-12 21:33:44
|
Revision: 7387 http://armagetronad.svn.sourceforge.net/armagetronad/?rev=7387&view=rev Author: z-man Date: 2007-11-12 13:33:48 -0800 (Mon, 12 Nov 2007) Log Message: ----------- Improved switching from motion blurred to nonblurred operation. Modified Paths: -------------- armagetronad/trunk/armagetronad/src/render/rSysdep.cpp Modified: armagetronad/trunk/armagetronad/src/render/rSysdep.cpp =================================================================== --- armagetronad/trunk/armagetronad/src/render/rSysdep.cpp 2007-11-12 21:13:32 UTC (rev 7386) +++ armagetronad/trunk/armagetronad/src/render/rSysdep.cpp 2007-11-12 21:33:48 UTC (rev 7387) @@ -778,20 +778,22 @@ // blurs the motion, time is the current time bool sr_MotionBlur( double time, std::auto_ptr< rTextureRenderTarget > & blurTarget ) { + static bool lastActive = true; + bool active = false; + + // measure frame rendering time + static double lastTime = time; + REAL frameTime = time - lastTime; + if ( currentScreensetting.vSync == ArmageTron_VSync_MotionBlur ) { - // measure frame rendering time - static double lastTime = time; - REAL frameTime = time - lastTime; - - // use hysteresis to autodisable motion blurring if rendering gets // far too slow and reenable it if rendering gets fast enough again static int hyster = 0; static int thresh = 100; - static bool active = true; + active = lastActive; - if ( frameTime * 5 < sr_motionBlurTime ) + if ( frameTime * 2 < sr_motionBlurTime ) { if ( ++hyster > thresh ) { @@ -816,30 +818,44 @@ } lastTime = time; + } - // really blur. - if ( active ) + // really blur. + if ( lastActive ) + { + // determine blur texture size + int blurWidth = NextPowerOfTwo( sr_screenWidth ); + int blurHeight = NextPowerOfTwo( sr_screenHeight ); + + // destroy existing blur texture if it is too small + if ( blurTarget.get() && ( blurTarget->GetWidth() < blurWidth || blurTarget->GetHeight() < blurHeight ) ) { - // determine blur texture size - int blurWidth = NextPowerOfTwo( sr_screenWidth ); - int blurHeight = NextPowerOfTwo( sr_screenHeight ); + blurTarget = std::auto_ptr< rTextureRenderTarget >(); + } + + // create blur texture + if ( !blurTarget.get() ) + { + blurTarget = std::auto_ptr< rTextureRenderTarget >( new rTextureRenderTarget( blurWidth, blurHeight ) ); + } - // destroy existing blur texture if it is too small - if ( blurTarget.get() && ( blurTarget->GetWidth() < blurWidth || blurTarget->GetHeight() < blurHeight ) ) - { - blurTarget = std::auto_ptr< rTextureRenderTarget >(); - } + // really blur + bool ret = sr_MotionBlurCore( 1 - frameTime / sr_motionBlurTime, *blurTarget ); - // create blur texture - if ( !blurTarget.get() ) - { - blurTarget = std::auto_ptr< rTextureRenderTarget >( new rTextureRenderTarget( blurWidth, blurHeight ) ); - } + // store active value for the next frame + lastActive = active; - return sr_MotionBlurCore( 1 - frameTime / sr_motionBlurTime, *blurTarget ); + // if the next frame won't be blurred, deactivate rendering to the texture + if ( !active ) + { + blurTarget->Pop(); } + + return ret; } + lastActive = active; + // no motion blur happened when we got here if ( blurTarget.get() && blurTarget->IsTarget() ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |