Gamedev Framework (gf)  0.14.0
A C++14 framework for 2D games
VertexBuffer.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2019 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 "GraphicsHandle.h"
28 #include "Portability.h"
29 #include "PrimitiveType.h"
30 
31 namespace gf {
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
33 inline namespace v1 {
34 #endif
35 
36  struct Vertex;
37 
38  template<>
39  struct GF_API GraphicsTrait<GraphicsTag::Buffer> {
40  static void gen(int n, unsigned* resources);
41  static void del(int n, const unsigned* resources);
42  };
43 
77  class GF_API VertexBuffer {
78  public:
82  VertexBuffer();
83 
91  VertexBuffer(const Vertex *vertices, std::size_t count, PrimitiveType type);
92 
101  VertexBuffer(const Vertex *vertices, const uint16_t *indices, std::size_t count, PrimitiveType type);
102 
108  bool hasArrayBuffer() const {
109  return m_vbo.isValid();
110  }
111 
117  bool hasElementArrayBuffer() const {
118  return m_ebo.isValid();
119  }
120 
130  std::size_t getCount() const {
131  return m_count;
132  }
133 
144  return m_type;
145  }
146 
154  static void bind(const VertexBuffer *buffer);
155 
156  private:
159  std::size_t m_count;
160  PrimitiveType m_type;
161  };
162 
163 #ifndef DOXYGEN_SHOULD_SKIP_THIS
164 }
165 #endif
166 }
167 
168 #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:117
PrimitiveType
Kind of primitives to render.
Definition: PrimitiveType.h:43
Data in the graphics memory.
Definition: VertexBuffer.h:77
Definition: GraphicsHandle.h:41
PrimitiveType getPrimitiveType() const
Get the primitive type of the data in the buffer.
Definition: VertexBuffer.h:143
bool hasArrayBuffer() const
Check if there is an array buffer.
Definition: VertexBuffer.h:108
GraphicsTag
Definition: GraphicsHandle.h:34
The namespace for gf classes.
Definition: Action.h:35
std::size_t getCount() const
Get the count of vertices or indices.
Definition: VertexBuffer.h:130