Langmuir
Simulation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mesh.h
Go to the documentation of this file.
1 #ifndef MESH_H
2 #define MESH_H
3 
4 #include "sceneobject.h"
5 
6 #include <QOpenGLShaderProgram>
7 #include <QOpenGLShader>
8 #include <QOpenGLBuffer>
9 #include <QMatrix4x4>
10 #include <QVector>
11 
12 namespace LangmuirView {
13 
17 class Mesh : public SceneObject
18 {
19  Q_OBJECT
20 public:
26  explicit Mesh(LangmuirViewer &viewer, QObject *parent = 0);
27 
31  ~Mesh();
32 
36  enum Mode {
37  Single = 1,
39  Double = 3,
41  Shader1 = 5,
42  Shader2 = 6,
43  };
44  Q_DECLARE_FLAGS(Modes, Mode)
45  Q_FLAGS(Modes)
46 
50  const QColor& getColorA() const;
51 
55  const QColor& getColorB() const;
56 
60  Mode getMode() const;
61 
62 signals:
67  void colorAChanged(QColor color);
68 
73  void colorBChanged(QColor color);
74 
78  void meshChanged();
79 
84  void modeChanged(Mesh::Mode mode);
85 
90  void modeChanged(QString mode);
91 
92 public slots:
96  virtual void makeConnections();
97 
102  void setColorA(QColor color);
103 
108  void setColorB(QColor color);
109 
116  void setMesh(const QVector<float> &vertices, const QVector<float>& normals, const QVector<unsigned int> &indices);
117 
122  void setMode(Mesh::Mode mode);
123 
127  void clear();
128 
133  static QString modeToQString(Mode mode);
134 
139  static Mode QStringToMode(QString string);
140 
141 protected:
145  virtual void init();
146 
150  virtual void draw();
151 
155  void initShaders();
156 
158  void drawSingle();
159 
161  void drawSingleAlpha();
162 
164  void drawDouble();
165 
167  void drawDoubleAlpha();
168 
170  void drawShader1();
171 
173  void drawShader2();
174 
176  QOpenGLShaderProgram m_shader1;
177 
179  QOpenGLShaderProgram m_shader2;
180 
182  QOpenGLBuffer *m_verticesVBO;
183 
185  QOpenGLBuffer *m_normalsVBO;
186 
188  QOpenGLBuffer *m_indexVBO;
189 
191  QColor m_colorA;
192 
194  QColor m_colorB;
195 
197  unsigned int m_numVertices;
198 
200  unsigned int m_numIndices;
201 
204 
207 
210 };
211 
212 }
213 
215 
216 #endif // MESH_H
void setMode(Mesh::Mode mode)
set the mode
void clear()
clear GPU buffers
static Mode QStringToMode(QString string)
convert string to Mode enum
unsigned int m_numIndices
index count
Definition: mesh.h:200
Mode getMode() const
get render mode
void drawShader1()
render function
render mesh using two colors
Definition: mesh.h:40
Definition: mesh.h:37
render mesh using two colors with alpha blending
Definition: mesh.h:41
Base class for objects in OpenGL scene.
Definition: sceneobject.h:22
void drawSingleAlpha()
render function
void drawShader2()
render function
QOpenGLBuffer * m_indexVBO
index buffer CW
Definition: mesh.h:188
const QColor & getColorA() const
get color A
render mesh using single color with alpha blending
Definition: mesh.h:39
Mode
The rendering mode for the cloud.
Definition: mesh.h:36
void drawDoubleAlpha()
render function
void modeChanged(Mesh::Mode mode)
signal that the render mode has changed
QOpenGLBuffer * m_normalsVBO
normals buffer
Definition: mesh.h:185
render mesh using single color
Definition: mesh.h:38
virtual void makeConnections()
make signal/slot connections
void drawDouble()
render function
bool m_shader2OK
shader2 ok to use
Definition: mesh.h:209
Mesh(LangmuirViewer &viewer, QObject *parent=0)
create the Mesh
QColor m_colorA
color of side A
Definition: mesh.h:191
Mode m_mode
rendering mode
Definition: mesh.h:203
void meshChanged()
signal that the mesh has changed
QOpenGLShaderProgram m_shader2
tesselation shader
Definition: mesh.h:179
QOpenGLShaderProgram m_shader1
tesselation shader
Definition: mesh.h:176
bool m_shader1OK
shader1 ok to use
Definition: mesh.h:206
static QString modeToQString(Mode mode)
convert Mode to string
Definition: axis.h:6
virtual void init()
initialize object
unsigned int m_numVertices
number of vertices (3 * number of points)
Definition: mesh.h:197
void setColorB(QColor color)
set color B
render mesh with shader1
Definition: mesh.h:42
Q_DECLARE_METATYPE(LangmuirView::Mesh::Mode)
QColor m_colorB
color of side B
Definition: mesh.h:194
Widget to view Langmuir Simulation in real time.
Definition: langmuirviewer.h:47
QOpenGLBuffer * m_verticesVBO
vertices buffer
Definition: mesh.h:182
void colorBChanged(QColor color)
signal that color B of has changed
void initShaders()
load the shaders
~Mesh()
destroy the Mesh
const QColor & getColorB() const
get color B
void setColorA(QColor color)
set color A
void setMesh(const QVector< float > &vertices, const QVector< float > &normals, const QVector< unsigned int > &indices)
set up the mesh on the GPU
void drawSingle()
render function
void colorAChanged(QColor color)
signal that color A of has changed
A class to represent a mesh.
Definition: mesh.h:17
virtual void draw()
perform OpenGL drawing operations