GlMesh.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <ivorium_config.hpp>
5 #include "gl.h"
6 
7 namespace iv
8 {
9 
10 struct GlMeshData
11 {
12  std::vector< float > positions;
13  std::vector< float > texcoords;
14  std::vector< GLuint > indices;
15  GLenum draw_mode;
16 };
17 
18 class GlMesh
19 {
20 public:
21  static const constexpr GLuint PrimitiveRestart = (GLuint)-1;
22 
23  static const constexpr GLuint AttributeLoc_Position = 0; // 3 floats
24  static const constexpr GLuint AttributeLoc_Texcoord = 1; // 2 floats
25 
26 public:
27  GlMesh();
28 
29  //------------------------- loading ----------------------------
30  void CreateMesh( Context const * logger );
31 
32  void Load_Positions( Context const * logger, float const * data, size_t length );
33  void Load_TexCoords( Context const * logger, float const * data, size_t length );
34  void Load_Indices( Context const * logger, GLuint const * data, size_t length, GLenum draw_mode );
35 
36  void Load_All( Context const * logger, GlMeshData const & data );
37 
38  void DestroyMesh( Context const * logger );
39  void DropMesh( Context const * logger );
40 
41  //------------------------- usage ------------------------------
46  void DrawElements( Context const * logger ) const;
47 
48  size_t indices_cnt() const;
49 
50 private:
51  GLuint _vao;
52  GLuint _position_buffer;
53  GLuint _texcoord_buffer;
54  GLuint _indices_buffer;
55  size_t _indices_cnt;
56  GLenum _draw_mode;
57 
58 #if IV_ENABLE_TRANSFORM_FEEDBACK
59  size_t _tf_triangles_cnt;
60  GLuint _tf_buffer;
61  std::vector< float > _tf_data;
62 #endif
63 };
64 
65 }