How to bufferswap between two textures, to achieve drawing on the next VBL?
Currently I'm using two QPixmap which I set to a QLabel. This results in a unstable delay between 18ms and 45ms measured against parallelport, using a 85Hz CRT monitor (no buffers there which add any delays).
My goal would be to issue a flip command which leads to bufferswap on the next VBL (Vertical Blanking Interrupt).
What I have tried now: I setup a full screen window in the main.cpp (different problem: can't open a window at runtime) and initialize there two QPixmaps.
With a signal created by a timer I trigger the change:
myVisualStimuli = new VisualStimuli(0);
//Start Timer for Stimulus Presenation
StimulusThread = new QThread(this);
StimulusTimer = new QTimer(0);
StimulusTimer->setInterval(500);
StimulusTimer->moveToThread(StimulusThread);
myVisualStimuli->moveToThread(StimulusThread);
myVisualStimuli->connect(StimulusTimer, SIGNAL(timeout()), SLOT(SetStimulus()), Qt::DirectConnection);
this->connect(StimulusTimer, SIGNAL(timeout()), SLOT(SetStimulus()), Qt::DirectConnection);
// Make sure the timer gets started from m_thread.
StimulusTimer->connect(StimulusThread, SIGNAL(started()), SLOT(start()));
StimulusThread->start();
And the Drawing: Header / Code
#ifndef VISUALSTIMULI_H
#define VISUALSTIMULI_H
#include <QtCore>
#include <QObject>
#include <QThread>
#include <QLabel>
class VisualStimuli: public QThread
{
Q_OBJECT
public:
explicit VisualStimuli(QObject *parent = 0);
int Setup();
bool StimulusToggle = true;
QRect *screenres;
QLabel* StimulusWindow;
QPixmap *pix1;
QPixmap *pix2;
public slots:
void SetStimulus();
private:
protected:
void run();
};
#endif // VISUALSTIMULI_H
#include "visualstimuli.h"
VisualStimuli::VisualStimuli(QObject *parent) : QThread(parent)
{
}
int VisualStimuli::Setup()
{
return 0;
}
void VisualStimuli::SetStimulus()
{
start();
}
void VisualStimuli::run()
{
if(StimulusToggle){
this->StimulusWindow->setPixmap(*pix1);
StimulusToggle=false;
}else{
this->StimulusWindow->setPixmap(*pix2);
StimulusToggle=true;
}
}
Due to Hardware I'm bound to Windows 10 64Bit, so I 'don’t mind to use any platform dependent code/library for the stimulus presentation.