宏定义文件:

//MARK: 启用降帧 [2013-4-28 18:04 Athrob]
#define __FRAME_LIMI

文件d3dapp.cpp:
CD3DApplication::CD3DApplication()下添加

#ifdef __FRAME_LIMIT //非前台时降帧
m_bFocused = false;
m_dwLastRender = 0;
m_dwCurrentFrameCount = 0;
#endif //end of #ifdef __FRAME_LIMIT //非前台时降帧

LRESULT CD3DApplication::MsgProc下添加

#ifdef __FRAME_LIMIT //非前台时降帧
case WM_SETFOCUS:
m_bFocused = true;
break;
case WM_KILLFOCUS:
m_bFocused = false;
break;
#endif //end of #ifndef __FRAME_LIMIT //非前台时降帧

bool CD3DApplication::IsNeedRender()下添加

#ifdef __FRAME_LIMIT //非前台时降帧
const DWORD dwFramesPerSec = 3; //10秒3帧
const DWORD dwMillisecPerFrame = 10000 / dwFramesPerSec; //1帧多少毫秒
if(m_bFocused) //焦点窗口一直渲染
return true;
if(!g_Option.m_bReduceFrameOnBlur) //不降帧, 最小化也不降帧
return true;
if (m_bMinimized) //最小化时候不渲染
{
Sleep(100);
return false;
}
if (m_bFocused == false) //非焦点,降帧
{
if(g_tmCurrent - m_dwLastRender >= dwMillisecPerFrame)
{
m_dwLastRender = g_tmCurrent;
return true;
}else
Sleep(100);
/*
if (m_dwCurrentFrameCount++ > 60)
{
m_dwCurrentFrameCount = 0;
Sleep(1);
}
*/
return false;
}
#endif //end of #ifdef __FRAME_LIMIT //非前台时降帧

文件d3dapp.h:
class CD3DApplication\protected:下添加

#ifdef __FRAME_LIMIT //非前台时降帧
bool m_bFocused; //焦点窗口
DWORD m_dwLastRender; //上次渲染时间
DWORD m_dwCurrentFrameCount; //当前已渲染帧数
#endif //end of #ifdef __FRAME_LIMIT //非前台时降帧
Last modification:February 21st, 2018 at 11:26 pm
If you think my article is useful to you, please feel free to appreciate