Gamedev Framework (gf)  0.5.0
A C++11 framework for 2D games
VertexBuffer.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2017 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 #ifndef GF_VERTEX_BUFFER_H
22 #define GF_VERTEX_BUFFER_H
23 
24 #include <cstddef>
25 #include <cstdint>
26 
27 #include "Portability.h"
28 #include "PrimitiveType.h"
29 
30 namespace gf {
31 #ifndef DOXYGEN_SHOULD_SKIP_THIS
32 inline namespace v1 {
33 #endif
34 
35  struct Vertex;
36 
70  class GF_API VertexBuffer {
71  public:
75  VertexBuffer();
76 
80  ~VertexBuffer();
81 
85  VertexBuffer(const VertexBuffer&) = delete;
86 
90  VertexBuffer& operator=(const VertexBuffer&) = delete;
91 
95  VertexBuffer(VertexBuffer&& other);
96 
100  VertexBuffer& operator=(VertexBuffer&& other);
101 
109  void load(const Vertex *vertices, std::size_t count, PrimitiveType type);
110 
119  void load(const Vertex *vertices, const uint16_t *indices, std::size_t count, PrimitiveType type);
120 
126  bool hasArrayBuffer() const {
127  return m_vbo != 0;
128  }
129 
135  bool hasElementArrayBuffer() const {
136  return m_ebo != 0;
137  }
138 
148  std::size_t getCount() const {
149  return m_count;
150  }
151 
162  return m_type;
163  }
164 
172  static void bind(const VertexBuffer *buffer);
173 
174  private:
175  unsigned m_vbo;
176  unsigned m_ebo;
177  std::size_t m_count;
178  PrimitiveType m_type;
179  };
180 
181 #ifndef DOXYGEN_SHOULD_SKIP_THIS
182 }
183 #endif
184 }
185 
186 #endif // GF_VERTEX_BUFFER_H
A point associated with a color and a texture coordinate.
Definition: Vertex.h:75
bool hasElementArrayBuffer() const
Check if there is an element array buffer.
Definition: VertexBuffer.h:135
PrimitiveType
Kind of primitives to render.
Definition: PrimitiveType.h:43
Data in the graphics memory.
Definition: VertexBuffer.h:70
PrimitiveType getPrimitiveType() const
Get the primitive type of the data in the buffer.
Definition: VertexBuffer.h:161
bool hasArrayBuffer() const
Check if there is an array buffer.
Definition: VertexBuffer.h:126
The namespace for gf classes.
Definition: Action.h:34
std::size_t getCount() const
Get the count of vertices or indices.
Definition: VertexBuffer.h:148