Cutout Vis2012
TUWienVisualisierung2(SS2012)-AdaptiveCutaways
 All Classes Namespaces Functions Pages
Mesh.h
1 #ifndef _MESH_H_
2 #define _MESH_H_
3 
4 #include "include_opengl.h"
5 #include "Texture.h"
6 
12 {
13 public:
15 
16  int numVertices;
17  GLfloat* vertices;
18  GLfloat* normals;
19  GLfloat* texCoords;
20  GLfloat* colors;
21  int numIndices;
22  GLuint* indices;
23  GLenum primitiveMode;
24  bool calcAdjacency;
25 
26  bool hasMinMax;
27  float maxX, maxY, maxZ;
28  float minX, minY, minZ;
29 };
30 
34 class Mesh
35 {
36 public:
37  Mesh();
38  ~Mesh();
39 
40  void init(int numVertices, GLfloat* vertices, GLfloat* normals, GLfloat* texCoords,
41  GLenum primitiveMode, bool adjacency=false);
42  void init(int numVertices, GLfloat* vertices, GLfloat* normals, GLfloat* texCoords, int numIndices, GLuint* indices,
43  GLenum primitiveMode, bool adjacency=false);
44 
48  void init(const MeshDescriptor& descr);
49 
53  void setTexture(Texture* texture); //nullptr allowed
57  const Texture* getTexture() const;
58 
62  void bindVAO() const;
66  void unbindVAO() const;
67 
71  void draw() const;
75  void drawLines() const;
76 
77  bool hasIndices() const;
78  bool hasNormals() const;
79  bool hasTexCoords() const;
80  bool hasColors() const;
81  int getNumIndices() const;
82  int getNumVertices() const;
83 
84  GLenum getPrimitiveMode() const;
85 
86  const GLfloat* getVertices() const;
87  const GLfloat* getNormals() const;
88  const GLfloat* getTexCoords() const;
89  const GLfloat* getColors() const;
90  const GLuint* getIndices() const;
91 
96  void calculateMinMax(bool overrideCurrent=false);
97 
98  bool hasMinMax() const;
99  void getMin(float& outX, float& outY, float& outZ) const;
100  void getMax(float& outX, float& outY, float& outZ) const;
101 
102 private:
103  // every mesh has vertex positions, normals and texture coordinates
104  GLuint _vao;
105 
106  int _numVertices;
107  GLfloat* _vertices;
108  GLfloat* _normals;
109  GLfloat* _texCoords;
110  GLfloat* _colors;
111  GLuint _vboBasic[3];
112 
113  // can have vertex indexing
114  int _numIndices; // -1 if unused
115  GLuint* _indices; //don't use if nullptr
116  GLuint _vboIndices;
117 
118  // bounding box
119  bool _hasMinMax;
120  float _minX, _minY, _minZ;
121  float _maxX, _maxY, _maxZ;
122 
123  // can have texture
124  Texture* _texture; //can be nullptr
125 
126  GLenum _primitiveMode; //GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN
127 
128  bool _initted;
129 
130  void calcAdjacency(int numIndices, GLuint* indices, int numVertices, GLfloat* vertices, GLenum primitiveMode);
131 };
132 
133 
134 #endif