Tucano  0.1
A library for rapid prototyping with modern OpenGL and GLSL
mesh.hpp
Go to the documentation of this file.
1 
23 #ifndef __MESH__
24 #define __MESH__
25 
26 #include <tucano/model.hpp>
27 #include <tucano/shader.hpp>
28 #include <memory>
29 
30 
31 namespace Tucano
32 {
33 
34 class Mesh;
35 
43 {
44  friend class Mesh;
45 private:
46 public:
48  string name;
50  int size = 0;
52  int element_size = 0;
54  GLint location = -1;
56  GLuint bufferID = 0;
58  GLenum type = GL_FLOAT;
60  GLenum array_type = GL_ARRAY_BUFFER;
61 
62  std::shared_ptr < GLuint > bufferID_sptr;
63 
64 public:
65 
66 
67  //VertexAttribute() = default;
68 
69  VertexAttribute(string in_name, int in_num_elements, int in_element_size, GLenum in_type, GLenum in_array_type = GL_ARRAY_BUFFER) :
70  name(in_name), size(in_num_elements), element_size(in_element_size), type(in_type), array_type (in_array_type)
71  {
72  // create new buffer for attribute if it is not yet set (ex copy constructor)
73  glGenBuffers(1, &bufferID);
74 
75  bufferID_sptr = std::shared_ptr < GLuint > (
76  new GLuint (bufferID),
77  [] (GLuint *p) {
78  glDeleteBuffers(1, p);
79  delete p;
80  }
81  );
82  #ifdef TUCANODEBUG
83  Tucano::Misc::errorCheckFunc(__FILE__, __LINE__, "mesh constructor");
84  #endif
85  }
86 
91  string getName (void) const {return name;}
92 
97  int getSize (void) const {return size;}
98 
104  int getElementSize (void) const {return element_size;}
105 
110  GLenum getType (void) const {return type;}
111 
116  GLenum getArrayType (void) const {return array_type;}
117 
122  void setArrayType (GLenum at) {array_type = at;}
123 
131  GLint getLocation(void) const {return location;}
132 
137  void setLocation(GLint loc) {location = loc;}
138 
143  GLuint getBufferID (void) {return *bufferID_sptr;}
144 
146  void bind(void)
147  {
148  glBindBuffer(array_type, *bufferID_sptr);
149  }
150 
152  void enable(GLint loc)
153  {
154  setLocation(loc);
155  enable();
156  }
157 
159  void enable()
160  {
161  if (location != -1)
162  {
163  glBindBuffer(array_type, *bufferID_sptr);
164  glVertexAttribPointer(location, element_size, type, GL_FALSE, 0, NULL);
165  glEnableVertexAttribArray(location);
166  }
167  }
168 
169 
171  void unbind(void)
172  {
173  glBindBuffer(array_type, 0);
174  }
175 
177  void disable(void)
178  {
179  if (location != -1)
180  {
181  glDisableVertexAttribArray(location);
182  }
183  }
184 
185 };
186 
194 class Mesh : public Tucano::Model {
195 protected:
196 
198  vector < Tucano::VertexAttribute > vertex_attributes;
199 
201  unsigned int numberOfVertices = 0;
202 
204  unsigned int numberOfNormals = 0;
205 
207  unsigned int numberOfElements = 0;
208 
210  unsigned int numberOfTexCoords = 0;
211 
213  unsigned int numberOfColors = 0;
214 
216  GLuint index_buffer_id = 0;
217 
219  GLuint vao_id = 0;
220 
222  bool willTessellate = false;
223 
225  std::shared_ptr < GLuint > index_buffer_sptr = 0;
226 
228  std::shared_ptr < GLuint > vao_sptr = 0;
229 
230 public:
231 
235  Mesh (void)
236  {
237  radius = 1.0;
238  scale = 1.0;
239 
240  glGenBuffers(1, &index_buffer_id);
241  index_buffer_sptr = std::shared_ptr < GLuint > (
242  new GLuint (index_buffer_id),
243  [] (GLuint *p) {
244  glDeleteBuffers(1, p);
245  delete p;
246  }
247  );
248 
249  glGenVertexArrays(1, &vao_id);
250  vao_sptr = std::shared_ptr < GLuint > (
251  new GLuint (vao_id),
252  [] (GLuint *p) {
253  glDeleteVertexArrays(1, p);
254  delete p;
255  }
256  );
257 
258 
259  #ifdef TUCANODEBUG
260  Misc::errorCheckFunc(__FILE__, __LINE__);
261  #endif
262  }
263 
264 
270  {
271  return numberOfElements;
272  }
273 
279  {
280  return numberOfVertices;
281  }
282 
286  void resetLocations (void)
287  {
288  for (unsigned int i = 0; i < vertex_attributes.size(); ++i)
289  {
290  vertex_attributes[i].setLocation(-1);
291  }
292  }
293 
294  void reset (void)
295  {
296  for (unsigned int i = 0; i < vertex_attributes.size(); ++i)
297  {
298  vertex_attributes[i].disable();
299 
300  }
301 
302  }
303 
304 
305 
312  void loadVertices (vector<Eigen::Vector4f> &vert)
313  {
314 
315  numberOfVertices = vert.size();
316 
317  // creates new attribute and load vertex coordinates
318  createAttribute("in_Position", vert);
319 
320  // from now on we are just computing some information about the model such as bounding box, centroid ...
321 
322  float xMax = 0; float xMin = 0; float yMax = 0; float yMin = 0; float zMax = 0; float zMin = 0;
323 
324  int temp = 0;
325  for(unsigned int i = 0; i < numberOfVertices*4; i+=4) {
326 
327  //X:
328  if(vert[temp][0] > xMax) {
329  xMax = vert[temp][0];
330  }
331  if(vert[temp][0] < xMin) {
332  xMin = vert[temp][0];
333  }
334 
335  //Y:
336  if(vert[temp][1] > yMax) {
337  yMax = vert[temp][1];
338  }
339  if(vert[temp][1] < yMin) {
340  yMin = vert[temp][1];
341  }
342 
343  //Z:
344  if(vert[temp][2] > zMax) {
345  zMax = vert[temp][2];
346  }
347  if(vert[temp][2] < zMin) {
348  zMin = vert[temp][2];
349  }
350 
351  //W:
352  temp++;
353  }
354 
355  scale = 1.0/max(max(xMax-xMin, yMax-yMin), zMax-zMin);
356 
357  float centerX = (xMax+xMin)/2.0;
358  float centerY = (yMax+yMin)/2.0;
359  float centerZ = (zMax+zMin)/2.0;
360  objectCenter = Eigen::Vector3f(centerX, centerY, centerZ);
361 
362  // compute the centroid (different from the box center)
363  centroid = Eigen::Vector3f::Zero();
364  for(unsigned int i = 0; i < numberOfVertices; i++) {
365  centroid = centroid + vert[i].head(3);//Eigen::Vector3f(vert[i][0], vert[i][1], vert[i][2]);
366  }
367  centroid = centroid / numberOfVertices;
368 
369  // compute the radius of the bounding sphere
370  // most distance point from the centroid
371  radius = 0.0;
372  for(unsigned int i = 0; i < numberOfVertices; i++) {
373  radius = max(radius, ( vert[i].head(3) - centroid ).norm());
374  }
375 
376  scale = 1.0/radius;
377 
378  }
379 
384  void loadNormals (vector<Eigen::Vector3f> &norm)
385  {
386  numberOfNormals = norm.size();
387 
388  createAttribute("in_Normal", norm);
389  }
390 
397  void loadTexCoords (vector<Eigen::Vector2f> &tex, bool normalize = false)
398  {
399  numberOfTexCoords = tex.size();
400 
401  if (normalize)
402  {
403  vector<Eigen::Vector2f> tex_normalized;
404 
405  float texXmax = tex[0][0];
406  float texXmin = tex[0][0];
407  float texYmax = tex[0][1];
408  float texYmin = tex[0][1];
409 
410  // compute min and max values for x and y
411  for(unsigned int i = 0; i < numberOfTexCoords; i++)
412  {
413  if (tex[i][0] < texXmin) texXmin = tex[i][0];
414  if (tex[i][0] > texXmax) texXmax = tex[i][0];
415  if (tex[i][1] < texYmin) texYmin = tex[i][1];
416  if (tex[i][1] > texYmax) texYmax = tex[i][1];
417 
418  }
419  for(unsigned int i = 0; i < numberOfTexCoords; i++)
420  {
421  tex_normalized.push_back ( Eigen::Vector2f(
422  (tex[i][0] - texXmin) / (texXmax - texXmin),
423  (tex[i][1] - texYmin) / (texYmax - texYmin) ) );
424  }
425  createAttribute("in_TexCoords", tex_normalized);
426  }
427  else
428  {
429  createAttribute("in_TexCoords", tex);
430  }
431  }
432 
433 
438  void loadColors (vector<Eigen::Vector4f> &clrs)
439  {
440  createAttribute("in_Color", clrs);
441  }
442 
443 
448  void loadIndices (vector<GLuint> &ind)
449  {
450  numberOfElements = ind.size();
451 
452  GLuint *indices = new GLuint[ind.size()];
453 
454  //Indices:
455  for(unsigned int i = 0; i < ind.size(); i++)
456  {
457  indices[i] = ind[i];
458  }
459 
460  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *index_buffer_sptr);
461  glBufferData(GL_ELEMENT_ARRAY_BUFFER, ind.size()*sizeof(GLuint), indices, GL_STATIC_DRAW);
462  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
463 
464  delete [] indices;
465  }
466 
475  {
476  resetLocations();
477  for (unsigned int i = 0; i < vertex_attributes.size(); ++i)
478  {
479  if (!vertex_attributes[i].getName().compare("in_Position"))
480  {
481  vertex_attributes[i].setLocation(0);
482  }
483  else if (!vertex_attributes[i].getName().compare("in_Normal"))
484  {
485  vertex_attributes[i].setLocation(1);
486  }
487  else if (!vertex_attributes[i].getName().compare("in_Color"))
488  {
489  vertex_attributes[i].setLocation(2);
490  }
491  else if (!vertex_attributes[i].getName().compare("in_TexCoord"))
492  {
493  vertex_attributes[i].setLocation(3);
494  }
495  }
496  }
497 
503  bool hasAttribute (const string& name) const
504  {
505  for (unsigned int i = 0; i < vertex_attributes.size(); ++i)
506  {
507  if (!vertex_attributes[i].getName().compare(name))
508  {
509  return true;
510  }
511  }
512  return false;
513  }
514 
515 
523  {
524  for (unsigned int i = 0; i < vertex_attributes.size(); ++i)
525  {
526  if (!vertex_attributes[i].getName().compare(name))
527  {
528  return &vertex_attributes[i];
529  }
530  }
531  return NULL;
532  }
533 
542  {
543  for (unsigned int i = 0; i < vertex_attributes.size(); ++i)
544  {
545  GLint loc = shader->getAttributeLocation(vertex_attributes[i].getName().c_str());
546  vertex_attributes[i].setLocation(loc);
547  }
548  if (shader->getTessellationEvaluationShader() != 0)
549  willTessellate = true;
550  else
551  willTessellate = false;
552  }
553 
554  void setAttributeLocation (const Shader& shader)
555  {
556  setAttributeLocation((Shader*)(&shader));
557  }
558 
559 
565  void setAttributeLocation (string name, GLint loc)
566  {
567  for (unsigned int i = 0; i < vertex_attributes.size(); ++i)
568  {
569  if (!name.compare(vertex_attributes[i].getName()))
570  {
571  vertex_attributes[i].setLocation(loc);
572  }
573  }
574  }
575 
576 
583  VertexAttribute* createAttribute (string name, vector<Eigen::Vector4f> &attrib)
584  {
585  // create new vertex attribute
586  VertexAttribute va (name, attrib.size(), 4, GL_FLOAT);
587 
588  float * attrib_array = new float[va.getSize()*va.getElementSize()];
589  int temp = 0;
590  for(int i = 0; i < va.getSize()*va.getElementSize(); i+=4) {
591  attrib_array[i] = attrib[temp][0];
592  attrib_array[i+1] = attrib[temp][1];
593  attrib_array[i+2] = attrib[temp][2];
594  attrib_array[i+3] = attrib[temp][3];
595  temp++;
596  }
597 
598  // fill buffer with attribute data
599  va.bind();
600  glBufferData(va.getArrayType(), va.getSize()*va.getElementSize()*sizeof(va.getType()), attrib_array, GL_STATIC_DRAW);
601  va.unbind();
602 
603  vertex_attributes.push_back(va);
604  delete [] attrib_array;
605  return &vertex_attributes[vertex_attributes.size()-1];
606 
607  }
608 
615  VertexAttribute* createAttribute(string name, vector<Eigen::Vector3f> &attrib)
616  {
617  // create new vertex attribute
618  VertexAttribute va (name, attrib.size(), 3, GL_FLOAT);
619 
620  float * attrib_array = new float[va.getSize()*va.getElementSize()];
621 
622  int temp = 0;
623  for(int i = 0; i < va.getSize()*va.getElementSize(); i+=3) {
624  attrib_array[i] = attrib[temp][0];
625  attrib_array[i+1] = attrib[temp][1];
626  attrib_array[i+2] = attrib[temp][2];
627  temp++;
628  }
629 
630  // fill buffer with attribute data
631  va.bind();
632  glBufferData(va.getArrayType(), va.getSize()*va.getElementSize()*sizeof(va.getType()), attrib_array, GL_STATIC_DRAW);
633  va.unbind();
634 
635  vertex_attributes.push_back(va);
636  delete [] attrib_array;
637  return &vertex_attributes[vertex_attributes.size()-1];
638  }
639 
646  VertexAttribute* createAttribute(string name, vector<Eigen::Vector2f> &attrib)
647  {
648  // create new vertex attribute
649  VertexAttribute va (name, attrib.size(), 2, GL_FLOAT);
650 
651  float * attrib_array = new float[va.getSize()*va.getElementSize()];
652 
653  int temp = 0;
654  for(int i = 0; i < va.getSize()*va.getElementSize(); i+=2) {
655  attrib_array[i] = attrib[temp][0];
656  attrib_array[i+1] = attrib[temp][1];
657  temp++;
658  }
659 
660  // fill buffer with attribute data
661  va.bind();
662  glBufferData(va.getArrayType(), va.getSize()*va.getElementSize()*sizeof(va.getType()), attrib_array, GL_STATIC_DRAW);
663  va.unbind();
664 
665  vertex_attributes.push_back(va);
666  delete [] attrib_array;
667  return &vertex_attributes[vertex_attributes.size()-1];
668  }
669 
670 
677  virtual void bindBuffers (void)
678  {
679  assert (vao_sptr != 0);
680 
681  glBindVertexArray(*vao_sptr); //Vertex Array Object
682 
683  if (*index_buffer_sptr)
684  {
685  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *index_buffer_sptr);
686  }
687 
688  // bind generic attributes
689  for (unsigned int i = 0; i < vertex_attributes.size(); ++i)
690  {
691  vertex_attributes[i].enable();
692  }
693 
694  #ifdef TUCANODEBUG
695  Misc::errorCheckFunc(__FILE__, __LINE__);
696  #endif
697  }
698 
702  virtual void unbindBuffers (void)
703  {
704  glBindVertexArray(0);
705  glBindBuffer(GL_ARRAY_BUFFER,0);
706  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
707 
708  for (unsigned int i = 0; i < vertex_attributes.size(); ++i)
709  {
710  vertex_attributes[i].disable();
711  }
712  }
713 
717  virtual void renderPoints (void)
718  {
719  glDrawArrays(GL_POINTS, 0, numberOfVertices);
720  }
721 
726  virtual void renderElements (void)
727  {
728 
729  glDrawElements(GL_TRIANGLES, numberOfElements, GL_UNSIGNED_INT, (GLvoid*)0);
730  }
731 
735  virtual void renderLineLoop (void)
736  {
737  glDrawArrays(GL_LINE_LOOP, 0, numberOfVertices);
738  }
739 
740 
745  virtual void renderPatches(void)
746  {
747  glPatchParameteri(GL_PATCH_VERTICES, 3);
748  glDrawElements(GL_PATCHES, numberOfElements,GL_UNSIGNED_INT, 0);
749  }
750 
756  virtual void render (void)
757  {
758  bindBuffers();
759  if (numberOfElements == 0)
760  {
761  renderPoints();
762  }
763  else
764  {
765  if (willTessellate)
766  {
767  renderPatches();
768  }
769  else
770  {
771  renderElements();
772  }
773  }
774  unbindBuffers();
775  }
776 
783  void createParallelepiped(float x, float y, float z)
784  {
785 
786  numberOfVertices = 32;
787  numberOfElements = 36;
788  //numberOfColors = 32;
789 
790  vector<Eigen::Vector4f> vert;
791  vector<GLuint> ind;
792 
793  //Normalizing the cube coordinates:
794  float scale = x;
795  if (y > x) scale = y;
796  if (z > scale) scale = z;
797 
798  vert.push_back( Eigen::Vector4f (-.5f*x/scale, -.5f*y/scale, .5f*z/scale, 1) );
799  vert.push_back( Eigen::Vector4f (-.5f*x/scale, .5f*y/scale, .5f*z/scale, 1) );
800  vert.push_back( Eigen::Vector4f (.5f*x/scale, .5f*y/scale, .5f*z/scale, 1) );
801  vert.push_back( Eigen::Vector4f (.5f*x/scale, -.5f*y/scale, .5f*z/scale, 1) );
802  vert.push_back( Eigen::Vector4f (-.5f*x/scale, -.5f*y/scale, -.5f*z/scale, 1) );
803  vert.push_back( Eigen::Vector4f (-.5f*x/scale, .5f*y/scale, -.5f*z/scale, 1) );
804  vert.push_back( Eigen::Vector4f (.5f*x/scale, .5f*y/scale, -.5f*z/scale, 1) );
805  vert.push_back( Eigen::Vector4f (.5f*x/scale, -.5f*y/scale, -.5f*z/scale, 1) );
806 
807  GLuint tempIndices[36] = {
808  0,2,1, 0,3,2,
809  4,3,0, 4,7,3,
810  4,1,5, 4,0,1,
811  3,6,2, 3,7,6,
812  1,6,5, 1,2,6,
813  7,5,6, 7,4,5
814  };
815 
816  for(unsigned int i = 0; i < numberOfElements;i++) {
817  ind.push_back( tempIndices[i] );
818  }
819 
820  /*float colors[32] =
821  {
822  0, 0, 1, 1,
823  1, 0, 0, 1,
824  0, 1, 0, 1,
825  1, 1, 0, 1,
826  1, 1, 1, 1,
827  1, 0, 0, 1,
828  1, 0, 1, 1,
829  0, 0, 1, 1
830  };*/
831 
832  loadVertices(vert);
833  loadIndices(ind);
834 
835  setDefaultAttribLocations();
836  }
837 
841  void createQuad (void)
842  {
843  vector<Eigen::Vector4f> vert;
844  vector<Eigen::Vector2f> texCoord;
845  vector<GLuint> elementsVertices;
846 
847  vert.push_back ( Eigen::Vector4f(-1.0, -1.0, 0.0, 1.0) );
848  vert.push_back ( Eigen::Vector4f( 1.0, -1.0, 0.0, 1.0) );
849  vert.push_back ( Eigen::Vector4f( 1.0, 1.0, 0.0, 1.0) );
850  vert.push_back ( Eigen::Vector4f(-1.0, 1.0, 0.0, 1.0) );
851 
852  elementsVertices.push_back(0);
853  elementsVertices.push_back(1);
854  elementsVertices.push_back(2);
855  elementsVertices.push_back(2);
856  elementsVertices.push_back(3);
857  elementsVertices.push_back(0);
858 
859  texCoord.push_back ( Eigen::Vector2f(0.0, 0.0) );
860  texCoord.push_back ( Eigen::Vector2f(1.0, 0.0) );
861  texCoord.push_back ( Eigen::Vector2f(1.0, 1.0) );
862  texCoord.push_back ( Eigen::Vector2f(0.0, 1.0) );
863 
864  loadVertices(vert);
865  loadTexCoords(texCoord);
866  loadIndices(elementsVertices);
867 
868  setDefaultAttribLocations();
869 
870  }
871 };
872 
873 }
874 #endif
void setAttributeLocation(string name, GLint loc)
Sets the location of a generic vertex attribute.
Definition: mesh.hpp:565
int getElementSize(void) const
Returns the number of elements per attribute For example, returns 3 if attribute is of type vec3...
Definition: mesh.hpp:104
void createQuad(void)
Sets the mesh as Unit Quad.
Definition: mesh.hpp:841
int getNumberOfElements(void)
Returns the number of elements (primitives such as triangles) of the mesh.
Definition: mesh.hpp:269
void loadNormals(vector< Eigen::Vector3f > &norm)
Load normals (x,y,z) as a vertex attribute.
Definition: mesh.hpp:384
VertexAttribute * createAttribute(string name, vector< Eigen::Vector4f > &attrib)
Creates and loads a new mesh attribute of 4 floats.
Definition: mesh.hpp:583
virtual void renderLineLoop(void)
Render all vertices as a continous line loop.
Definition: mesh.hpp:735
void createParallelepiped(float x, float y, float z)
Sets the mesh as a Parallelpiped with given dimensions, scales so larger side is equal to 1...
Definition: mesh.hpp:783
GLuint getTessellationEvaluationShader(void)
Returns a handle to the tessellation evaluation shader.
Definition: shader.hpp:405
void loadColors(vector< Eigen::Vector4f > &clrs)
Load colors (r,g,b,a) as a vertex attribute.
Definition: mesh.hpp:438
int element_size
number of elements per attribute
Definition: mesh.hpp:52
GLint getAttributeLocation(const GLchar *name) const
Definition: shader.hpp:1240
Definition: bufferobject.hpp:34
GLuint getBufferID(void)
Returns the id of the vertex array of this attribute.
Definition: mesh.hpp:143
void setAttributeLocation(const Shader &shader)
Definition: mesh.hpp:554
virtual void renderPatches(void)
Call the draw method for rendering patches. This method requires that a index buffer has been created...
Definition: mesh.hpp:745
int getSize(void) const
Returns the number of elements of this attribute (usually number of vertices in VAO) ...
Definition: mesh.hpp:97
int getNumberOfVertices(void)
Returns the number of vertices in the mesh.
Definition: mesh.hpp:278
The Model class is a holder for any kind of model, such as meshes, point clouds, surfaces ...
Definition: model.hpp:16
virtual void renderPoints(void)
Render only points without index buffer.
Definition: mesh.hpp:717
A Shader object represents one GLSL program.
Definition: shader.hpp:45
void errorCheckFunc(std::string file, int line, std::string message="")
GL error check method.
Definition: misc.hpp:53
void disable(void)
Disables associated location if attribute has one.
Definition: mesh.hpp:177
GLenum type
Type of attribute element (ex. GL_FLOAT)
Definition: mesh.hpp:58
Mesh(void)
Default Constructor.
Definition: mesh.hpp:235
void loadIndices(vector< GLuint > &ind)
Load indices into indices array.
Definition: mesh.hpp:448
GLenum array_type
Type of attribute array (GL_ARRAY_BUFFER for most cases), indices are GL_ELEMENT_ARRAY_BUFFER.
Definition: mesh.hpp:60
void setLocation(GLint loc)
Sets the location of the attribute for a shader.
Definition: mesh.hpp:137
bool hasAttribute(const string &name) const
Returns wether an attribute exists or not.
Definition: mesh.hpp:503
GLenum getType(void) const
Returns the type of the attribute (ex. GL_FLOAT)
Definition: mesh.hpp:110
VertexAttribute * createAttribute(string name, vector< Eigen::Vector2f > &attrib)
Creates and loads a new mesh attribute of 2 floats.
Definition: mesh.hpp:646
GLint getLocation(void) const
Returns the location of the attribute. The location is usually set by the shader, since it can be use...
Definition: mesh.hpp:131
A vertex attribute of a mesh.
Definition: mesh.hpp:42
VertexAttribute(string in_name, int in_num_elements, int in_element_size, GLenum in_type, GLenum in_array_type=GL_ARRAY_BUFFER)
Definition: mesh.hpp:69
void setDefaultAttribLocations(void)
Sets default attribute locations. vertex coords -> location 0 normals -> location 1 colors -> locatio...
Definition: mesh.hpp:474
void reset(void)
Definition: mesh.hpp:294
int size
size of attribute array (usually number of vertices)
Definition: mesh.hpp:50
void bind(void)
Bind the attribute.
Definition: mesh.hpp:146
GLint location
this is set by the shader using the attribute
Definition: mesh.hpp:54
void resetLocations(void)
Resets all vertex attributes locations to -1.
Definition: mesh.hpp:286
void setArrayType(GLenum at)
Sets the type of array (default is GL_ARRAY_BUFFER)
Definition: mesh.hpp:122
GLuint bufferID
Vertex array Buffer ID.
Definition: mesh.hpp:56
std::shared_ptr< GLuint > bufferID_sptr
Definition: mesh.hpp:62
VertexAttribute * getAttribute(const string &name)
Returns a pointer to an attribute Given an attribute name, searches to see if it exists, if so, returns a pointer to it.
Definition: mesh.hpp:522
virtual void unbindBuffers(void)
Unbinds all buffers.
Definition: mesh.hpp:702
virtual void render(void)
Render the mesh triangles. The method binds the buffers, calls the method to render triangles...
Definition: mesh.hpp:756
GLenum getArrayType(void) const
Returns the type of array (ex. GL_ARRAY_BUFFER)
Definition: mesh.hpp:116
vector< Tucano::VertexAttribute > vertex_attributes
Array of generic attributes.
Definition: mesh.hpp:198
void loadVertices(vector< Eigen::Vector4f > &vert)
Load vertices (x,y,z,w) and creates appropriate vertex attribute. The default attribute name is "in_P...
Definition: mesh.hpp:312
string getName(void) const
Returns the name of the attribute.
Definition: mesh.hpp:91
VertexAttribute * createAttribute(string name, vector< Eigen::Vector3f > &attrib)
Creates and loads a new mesh attribute of 3 floats.
Definition: mesh.hpp:615
void enable()
Binds the attribute to its location.
Definition: mesh.hpp:159
void loadTexCoords(vector< Eigen::Vector2f > &tex, bool normalize=false)
Load tex coords (u,v) as a vertex attribute. Optionally normalizes coords in range [0...
Definition: mesh.hpp:397
virtual void renderElements(void)
Call the draw method for rendering triangles. This method requires that a index buffer has been creat...
Definition: mesh.hpp:726
virtual void bindBuffers(void)
Binds all buffers.
Definition: mesh.hpp:677
void enable(GLint loc)
Bind the attribute to a given location.
Definition: mesh.hpp:152
A common Mesh, usually containing triagles or points.
Definition: mesh.hpp:194
void setAttributeLocation(Shader *shader)
Automatically sets the attribute locations for a given Shader.
Definition: mesh.hpp:541
string name
Attribute&#39;s name.
Definition: mesh.hpp:48
void unbind(void)
Unbind the attribute.
Definition: mesh.hpp:171