Qt之使用OpenGL硬件加速
参考的用例 2D Painting Example
文档说的很清楚,The quality and speed of rendering in the GLWidget
depends on the level of support for multisampling and hardware acceleration
that your system’s OpenGL driver provides.
测试fps函数
#include <chrono>
using namespace std;
using namespace std::chrono;
static double fps(){
static double fps = 0.0;
static int frameCount = 0;
static auto lastTime = system_clock::now();
static auto curTime = system_clock::now();
curTime = system_clock::now();
auto duration = duration_cast<microseconds>(curTime - lastTime);
double duration_s = double(duration.count()) * microseconds::period::num / microseconds::period::den;
if (duration_s > 2)//2秒之后开始统计FPS
{
fps = frameCount / duration_s;
frameCount = 0;
lastTime = curTime;
}
++frameCount;
return fps;
}
之前帧率一直测的是60fps,原因:
-
电脑垂直同步没关
-
设置QSurfaceFormat::setSwapInterval(0)
QSurfaceFormat fmt; fmt.setSamples(4); fmt.setSwapInterval(0); QSurfaceFormat::setDefaultFormat(fmt);
判断系统中是否支持Opengl
QGLFormat::hasOpenGL()
博客介绍了Qt使用OpenGL硬件加速,参考2D Painting Example用例。提到测试fps函数时,之前帧率一直为60fps是因电脑垂直同步未关,可设置QSurfaceFormat::setSwapInterval(0)解决,还涉及判断系统是否支持Opengl。

1231

被折叠的 条评论
为什么被折叠?



