对于科学任务,应在屏幕上显示具有稳定频率(最大60 Hz)的闪烁区域。我试图用Qt 5.6实现稳定的可视化刺激。Qt:vsync - 缺少渲染帧
根据这blog entry和许多其他在线建议,我实现了三种不同的方法:从QWindow类继承,QOpenGLWindow类和QRasterWindow类。我想获得vsync的优势并避免使用QTimer。
可以显示闪烁区域。此外,帧之间的稳定时间段已经用16至17毫秒进行了测量。但每隔几秒钟就会发现一些错过的帧。可以清楚地看到,刺激没有稳定的可视化。所有三种方法都会产生同样的效果。
我是否正确地执行了我的代码,或者做了更好的解决方案?如果代码足够用于它的目的,我是否必须假定它是一个硬件问题?难道那么显示一个简单的闪烁区域是困难的吗?
非常感谢您的帮助!
如例,你可以看到我的QWindow类此代码:
Window::Window(QWindow *parent)
: m_context(0)
, m_paintDevice(0)
, m_bFlickerState(true){
setSurfaceType(QSurface::OpenGLSurface);
QSurfaceFormat format;
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);
format.setSwapInterval(1);
this->setFormat(format);
m_context.setFormat(format);
m_context.create();}
的render()
功能,这是由覆盖事件函数调用,是:
void Window::render(){
//calculating exposed time between frames
m_t1 = QTime::currentTime();
int curDelta = m_t0.msecsTo(m_t1);
m_t0 = m_t1;
qDebug()<< curDelta;
m_context.makeCurrent(this);
if (!m_paintDevice)
m_paintDevice = new QOpenGLPaintDevice;
if (m_paintDevice->size() != size())
m_paintDevice->setSize(size());
QPainter p(m_paintDevice);
// draw using QPainter
if(m_bFlickerState){
p.setBrush(Qt::white);
p.drawRect(0,0,this->width(),this->height());
}
p.end();
m_bFlickerState = !m_bFlickerState;
m_context.swapBuffers(this);
// animate continuously: schedule an update
QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest));}