1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#pragma once
#include <QWindow>
#include <QList>
#include <QTime>
#include <QScopedPointer>
class QOpenGLContext;
class QSurfaceFormat;
class QBasicTimer;
class QTimerEvent;
class QKeyEvent;
class Painter;
class Canvas : public QWindow
{
Q_OBJECT
public:
enum SwapInterval
{
NoVerticalSyncronization = 0
, VerticalSyncronization = 1 ///< WGL_EXT_swap_control, GLX_EXT_swap_control, GLX_SGI_video_sync
, AdaptiveVerticalSyncronization = -1 ///< requires EXT_swap_control_tear
};
public:
Canvas(
const QSurfaceFormat & format
, QScreen * screen = nullptr);
virtual ~Canvas();
// from QWindow
virtual QSurfaceFormat format() const;
void setContinuousRepaint(bool enable, int msec = 1000 / 60);
bool continuousRepaint() const;
void setSwapInterval(SwapInterval swapInterval);
static const QString swapIntervalToString(SwapInterval swapInterval);
public slots:
void toggleSwapInterval();
protected:
virtual void initializeGL(const QSurfaceFormat & format);
virtual void paintGL();
virtual void resizeEvent(QResizeEvent * event);
virtual void keyPressEvent(QKeyEvent * event);
void timerEvent(QTimerEvent * event);
signals:
void fpsUpdate(float fps);
void numCubesUpdate(int numCubes);
protected:
QScopedPointer<QOpenGLContext> m_context;
SwapInterval m_swapInterval; ///< required for toggle
QScopedPointer<QBasicTimer> m_repaintTimer;
QTime m_fpsTimer;
long double m_swapts;
unsigned int m_swaps;
bool m_update; // checked in paintGL, if true, update of program gets triggered
bool m_continuousRepaint;
Painter * m_painter;
};
|