Qt之使用OpenGL硬件加速

博客介绍了Qt使用OpenGL硬件加速,参考2D Painting Example用例。提到测试fps函数时,之前帧率一直为60fps是因电脑垂直同步未关,可设置QSurfaceFormat::setSwapInterval(0)解决,还涉及判断系统是否支持Opengl。

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

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,原因:

  1. 电脑垂直同步没关

  2. 设置QSurfaceFormat::setSwapInterval(0)

     QSurfaceFormat fmt;
     fmt.setSamples(4);
     fmt.setSwapInterval(0);
     QSurfaceFormat::setDefaultFormat(fmt);
    

判断系统中是否支持Opengl

QGLFormat::hasOpenGL()

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值