Walls And Holes  1
abstractrenderer.h
Go to the documentation of this file.
1 #ifndef ABSTRACTRENDERER_H
2 #define ABSTRACTRENDERER_H
3 
4 #include <QObject>
5 #include <QQueue>
6 #include <QMutex>
7 #include <QMutexLocker>
8 
9 #include <QOpenGLFunctions>
10 #include <QMatrix4x4>
11 
12 // For std::function
13 #include <functional>
14 
18 class AbstractRenderer : public QObject, public QOpenGLFunctions
19 {
20  Q_OBJECT
21 
22 public:
23 
24  virtual ~AbstractRenderer() {}
25 
37  virtual void paint(QMatrix4x4 mvpMatrix, QVector3D camPos) = 0;
38 
46  virtual void create() {}
47 
51  void initializeGL()
52  {
53  initializeOpenGLFunctions();
54 
56  }
57 
58 public slots:
59 
63  void requestUpdate() { emit repaintNeeded(); }
64 
65 
69  virtual void cleanUp() = 0;
70 
71 signals:
75  void repaintNeeded();
76 
77 
78  void makeContextCurrent();
79  void doneContextCurrent();
80 
81 protected:
90  {
91  bool hadError = false;
92 
93  GLenum error;
94  while ((error = glGetError()) != GL_NO_ERROR) {
95  switch (error) {
96  case GL_INVALID_ENUM: qDebug() << "GL_INVALID_ENUM"; break;
97  case GL_INVALID_VALUE: qDebug() << "GL_INVALID_VALUE"; break;
98  case GL_INVALID_OPERATION: qDebug() << "GL_INVALID_OPERATION"; break;
99  case GL_INVALID_FRAMEBUFFER_OPERATION: qDebug() << "GL_INVALID_FRAMEBUFFER_OPERATION"; break;
100  case GL_OUT_OF_MEMORY: qDebug() << "GL_OUT_OF_MEMORY"; break;
101  case GL_STACK_UNDERFLOW: qDebug() << "GL_STACK_UNDERFLOW"; break;
102  case GL_STACK_OVERFLOW: qDebug() << "GL_STACK_OVERFLOW"; break;
103  default: qDebug() << "Unknown error."; break;
104  }
105 
106  hadError = true;
107  }
108 
109  return hadError;
110  }
111 
112 
117  virtual void initializeRenderer() = 0;
118 
119 };
120 
121 #endif // ABSTRACTRENDERER_H
void makeContextCurrent()
virtual void cleanUp()=0
This slot should clean up all resources associated to the renderer.
virtual void paint(QMatrix4x4 mvpMatrix, QVector3D camPos)=0
Uses OpenGL commands to draw to the frame buffer. Nothing is assumed about the previous contents of t...
void doneContextCurrent()
void requestUpdate()
Calling this slot makes the renderer update itself when possible.
Definition: abstractrenderer.h:63
void initializeGL()
Initializes OpenGL-related details.
Definition: abstractrenderer.h:51
virtual void initializeRenderer()=0
Used to initialize renderer parameters that require an OpenGL context to be bound.
Something that renders a 3D scene to the screen using OpenGL.
Definition: abstractrenderer.h:18
virtual ~AbstractRenderer()
Definition: abstractrenderer.h:24
virtual void create()
This is (should be) called on an OpenGL thread before this object is used. Allows the renderer to ini...
Definition: abstractrenderer.h:46
bool checkGLErrors()
Helper method to loop glGetError() and print out all current errors.
Definition: abstractrenderer.h:89
void repaintNeeded()
Emitted when the renderer has updates to make to its image.