Gamedev Framework (gf)  0.17.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 
111  VertexBuffer(const void *vertices, std::size_t size, std::size_t count, PrimitiveType type);
112 
122  VertexBuffer(const void *vertices, std::size_t size, const uint16_t *indices, std::size_t count, PrimitiveType type);
123 
129  bool hasArrayBuffer() const {
130  return m_vbo.isValid();
131  }
132 
138  bool hasElementArrayBuffer() const {
139  return m_ebo.isValid();
140  }
141 
147  std::size_t getVertexSize() const {
148  return m_size;
149  }
150 
160  std::size_t getCount() const {
161  return m_count;
162  }
163 
174  return m_type;
175  }
176 
184  static void bind(const VertexBuffer *buffer);
185 
186  private:
189  std::size_t m_size;
190  std::size_t m_count;
191  PrimitiveType m_type;
192  };
193 
194 #ifndef DOXYGEN_SHOULD_SKIP_THIS
195 }
196 #endif
197 }
198 
199 #endif // GF_VERTEX_BUFFER_H
std::size_t getVertexSize() const
Get the vertex size in the buffer.
Definition: VertexBuffer.h:147
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:138
PrimitiveType
Kind of primitives to render.
Definition: PrimitiveType.h:43
Data in the graphics memory.
Definition: VertexBuffer.h:77
constexpr BufferRef< T > buffer(T *data, std::size_t size)
Create a reference to a buffer.
Definition: BufferRef.h:211
Definition: GraphicsHandle.h:41
PrimitiveType getPrimitiveType() const
Get the primitive type of the data in the buffer.
Definition: VertexBuffer.h:173
bool hasArrayBuffer() const
Check if there is an array buffer.
Definition: VertexBuffer.h:129
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:160