Point Cloud Viewer  1.00
A Viewer to display point clouds with phong shading by converting them to splats.
renderpass.h
1 #ifndef RENDERPASS_H
2 #define RENDERPASS_H
3 
4 #include <QOpenGLFunctions>
5 
6 #define SI_POSITION 0
7 #define SI_ELLIPSE_U 1
8 #define SI_ELLIPSE_V 2
9 #define SI_COLOR 3
10 
11 #define GL Globals::gl
12 
26 class RenderPass {
27 public:
28  RenderPass();
29 
35  virtual ~RenderPass();
36 
42  virtual void render() = 0;
43 
50  virtual void cleanup() = 0;
51 
57  virtual void updateResolution() = 0;
58 
64  virtual void removeInput() = 0;
65 
72  static void cleanupHelpers();
73 protected:
74  static bool loadShader(std::string &path, GLuint id);
75  static bool noGlErrors();
76  static bool checkFbo();
77  static void drawUnitQuad();
78 private:
79  static GLuint unitQuadVao, unitQuadVbo;
80 
81  static bool textFileRead(std::string &file, std::string &into);
82  static void printInfoLog(GLint id, bool program);
83  static void generateUnitQuad();
84 
93  class Channel {
94  public:
95  Channel();
96  virtual ~Channel();
97 
102  bool isActive();
103 
111  void setActive(bool active);
112 
116  void registerAsReceiver();
117 
124  void unregisterAsReceiver();
125  private:
126  unsigned char receiverCounter;
127  bool active;
128  };
129 protected:
130  template<class C> bool helperMultiChannelContains(std::list<C*> &list, C &channel) {
131  std::list<C*>::iterator iter = list.begin();
132  while (iter != list.end()) {
133  if (*iter == &channel)
134  return true;
135  ++iter;
136  }
137  return false;
138  }
139  template<class C> void helperMultiChannelAdd(std::list<C*> &list, C &channel) {
140  if (channel.isActive() && !helperMultiChannelContains(list, channel)) {
141  list.push_back(&channel);
142  channel.registerAsReceiver();
143  }
144  }
145  template<class C> bool helperMultiChannelRemove(std::list<C*> &list, C &channel) {
146  std::list<C*>::iterator iter = list.begin();
147  while (iter != list.end()) {
148  if (*iter == &channel) {
149  channel.unregisterAsReceiver();
150  list.erase(iter);
151  return true;
152  }
153  ++iter;
154  }
155  return false;
156  }
157  template<class C> void helperMultiChannelClean(std::list<C*> &list) {
158  std::list<C*>::iterator iter = list.begin();
159  while (iter != list.end()) {
160  if (!(*iter)->isActive()) {
161  (*iter)->unregisterAsReceiver();
162  iter = list.erase(iter);
163  } else
164  ++iter;
165  }
166  }
167  template<class C> void helperMultiChannelClear(std::list<C*> &list) {
168  std::list<C*>::iterator iter = list.begin();
169  while (iter != list.end()) {
170  (*iter)->unregisterAsReceiver();
171  ++iter;
172  }
173  list.clear();
174  }
175 
176 public:
182  class VaoChannel: public Channel {
183  public:
184  struct vao {
185  GLuint id, size;
186  QMatrix4x4 *modelMat;
187  };
188 
193  VaoChannel(vao sentVao);
194 
200  vao *getVao();
201  private:
202  vao sentVao;
203  };
204 
210  class TextureChannel: public Channel {
211  public:
212  TextureChannel();
213  ~TextureChannel();
214 
219  GLuint getID();
220 
229  void reserveTexture(unsigned int x, unsigned int y, bool floatPrecision);
230 
238  void reserveDepthTexture(unsigned int x, unsigned int y);
239 
247  void freeTexture();
248  private:
249  GLuint id;
250  };
251 };
252 
253 #endif // RENDERPASS_H
VaoChannel(vao sentVao)
Create a new VaoChannel containing the given geometry.
Definition: renderpass.cpp:184
virtual void render()=0
Uses the input data to generate the output.
An abstract class for Render Passes.
Definition: renderpass.h:26
This channel is used to link textures or data maps.
Definition: renderpass.h:210
GLuint getID()
Getter for the OpenGL texture id.
Definition: renderpass.cpp:202
virtual ~RenderPass()
Calls cleanup()
Definition: renderpass.cpp:12
void freeTexture()
Tells the channel that it will not be updated anymore.
Definition: renderpass.cpp:234
static void cleanupHelpers()
Removes helper variables.
Definition: renderpass.cpp:14
This channel is used to link geometry.
Definition: renderpass.h:182
Definition: renderpass.h:184
vao * getVao()
Getter for the contained geometry.
Definition: renderpass.cpp:189
virtual void updateResolution()=0
Must be called after the screen resolution has changed.
void reserveDepthTexture(unsigned int x, unsigned int y)
Reserves a new depth map on the GPU.
Definition: renderpass.cpp:220
virtual void cleanup()=0
Resets the Render Pass to the state after creation but before initialization.
void reserveTexture(unsigned int x, unsigned int y, bool floatPrecision)
Reserves a new texture on the GPU.
Definition: renderpass.cpp:206
virtual void removeInput()=0
Removes all input channels except for VaoChannels. If the Render Pass uses VaoChannels as input use t...