Gamedev Framework (gf)  0.19.0
A C++17 framework for 2D games
VertexBuffer.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2021 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 "GraphicsApi.h"
28 #include "GraphicsHandle.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 
42  template<>
43  struct GF_GRAPHICS_API GraphicsTrait<GraphicsTag::Buffer> {
44  static void gen(int n, unsigned* resources);
45  static void del(int n, const unsigned* resources);
46  };
47 
81  class GF_GRAPHICS_API VertexBuffer {
82  public:
86  VertexBuffer();
87 
95  VertexBuffer(const Vertex *vertices, std::size_t count, PrimitiveType type);
96 
105  VertexBuffer(const Vertex *vertices, const uint16_t *indices, std::size_t count, PrimitiveType type);
106 
115  VertexBuffer(const void *vertices, std::size_t size, std::size_t count, PrimitiveType type);
116 
126  VertexBuffer(const void *vertices, std::size_t size, const uint16_t *indices, std::size_t count, PrimitiveType type);
127 
133  bool hasArrayBuffer() const {
134  return m_vbo.isValid();
135  }
136 
142  bool hasElementArrayBuffer() const {
143  return m_ebo.isValid();
144  }
145 
151  std::size_t getVertexSize() const {
152  return m_size;
153  }
154 
164  std::size_t getCount() const {
165  return m_count;
166  }
167 
178  return m_type;
179  }
180 
188  static void bind(const VertexBuffer *buffer);
189 
190  private:
193  std::size_t m_size;
194  std::size_t m_count;
195  PrimitiveType m_type;
196  };
197 
198 #ifndef DOXYGEN_SHOULD_SKIP_THIS
199 }
200 #endif
201 }
202 
203 #endif // GF_VERTEX_BUFFER_H
PrimitiveType
Kind of primitives to render.
Definition: PrimitiveType.h:43
std::size_t getVertexSize() const
Get the vertex size in the buffer.
Definition: VertexBuffer.h:151
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:142
Data in the graphics memory.
Definition: VertexBuffer.h:81
A trait to handle creation and deletion of GPU resources.
Definition: GraphicsHandle.h:48
PrimitiveType getPrimitiveType() const
Get the primitive type of the data in the buffer.
Definition: VertexBuffer.h:177
bool hasArrayBuffer() const
Check if there is an array buffer.
Definition: VertexBuffer.h:133
The namespace for gf classes.
Definition: Action.h:35
std::size_t getCount() const
Get the count of vertices or indices.
Definition: VertexBuffer.h:164
GraphicsTag
A tag to represent various GPU resources.
Definition: GraphicsHandle.h:37