Gamedev Framework (gf)  0.17.0
A C++14 framework for 2D games
Public Member Functions | Static Public Member Functions | List of all members
gf::VertexBuffer Class Reference

Data in the graphics memory. More...

#include <gf/VertexBuffer.h>

Public Member Functions

 VertexBuffer ()
 Default constructor. More...
 
 VertexBuffer (const Vertex *vertices, std::size_t count, PrimitiveType type)
 Load an array of vertices. More...
 
 VertexBuffer (const Vertex *vertices, const uint16_t *indices, std::size_t count, PrimitiveType type)
 Load an array of vertices and their indices. More...
 
 VertexBuffer (const void *vertices, std::size_t size, std::size_t count, PrimitiveType type)
 Load an array of custom vertices. More...
 
 VertexBuffer (const void *vertices, std::size_t size, const uint16_t *indices, std::size_t count, PrimitiveType type)
 Load an array of custom vertices and their indices. More...
 
bool hasArrayBuffer () const
 Check if there is an array buffer. More...
 
bool hasElementArrayBuffer () const
 Check if there is an element array buffer. More...
 
std::size_t getVertexSize () const
 Get the vertex size in the buffer. More...
 
std::size_t getCount () const
 Get the count of vertices or indices. More...
 
PrimitiveType getPrimitiveType () const
 Get the primitive type of the data in the buffer. More...
 

Static Public Member Functions

static void bind (const VertexBuffer *buffer)
 Binds a vertex buffer. More...
 

Detailed Description

Data in the graphics memory.

A vertex buffer is a buffer that resides directly in the graphics memory. The advantage is that the draw operations are faster than uploading data each time. The drawback is that the data must not change, i.e. data can be loaded only once.

In gf, a vertex buffer can be used directly. But the main usage is for drawable entities that can upload the final geometry and give the corresponding vertex buffer.

Usage:

gf::Texture texture;
gf::Sprite sprite;
sprite.setTexture(texture);
sprite.setTextureRect({ 0.5f, 0.5f, 0.25f, 0.25f });
geometry.setBuffer(buffer);
geometry.setTexture(texture);
renderer.draw(geometry);
See also
gf::BufferedGeometry

Constructor & Destructor Documentation

◆ VertexBuffer() [1/5]

gf::VertexBuffer::VertexBuffer ( )

Default constructor.

◆ VertexBuffer() [2/5]

gf::VertexBuffer::VertexBuffer ( const Vertex vertices,
std::size_t  count,
PrimitiveType  type 
)

Load an array of vertices.

Parameters
verticesPointer to the vertices
countNumber of vertices in the array
typeType of primitives to draw

◆ VertexBuffer() [3/5]

gf::VertexBuffer::VertexBuffer ( const Vertex vertices,
const uint16_t *  indices,
std::size_t  count,
PrimitiveType  type 
)

Load an array of vertices and their indices.

Parameters
verticesPointer to the vertices
indicesPointer to the indices
countNumber of indices in the array
typeType of primitives to draw

◆ VertexBuffer() [4/5]

gf::VertexBuffer::VertexBuffer ( const void *  vertices,
std::size_t  size,
std::size_t  count,
PrimitiveType  type 
)

Load an array of custom vertices.

Parameters
verticesPointer to the vertices
sizeThe size of one vertex
countNumber of vertices in the array
typeType of primitives to draw

◆ VertexBuffer() [5/5]

gf::VertexBuffer::VertexBuffer ( const void *  vertices,
std::size_t  size,
const uint16_t *  indices,
std::size_t  count,
PrimitiveType  type 
)

Load an array of custom vertices and their indices.

Parameters
verticesPointer to the vertices
sizeThe size of one vertex
indicesPointer to the indices
countNumber of indices in the array
typeType of primitives to draw

Member Function Documentation

◆ bind()

static void gf::VertexBuffer::bind ( const VertexBuffer buffer)
static

Binds a vertex buffer.

This function is for internal use only.

Parameters
bufferA pointer to a buffer or nullptr

◆ getCount()

std::size_t gf::VertexBuffer::getCount ( ) const
inline

Get the count of vertices or indices.

This function returns the count parameter given in the constructor.

Returns
The count of vertices or indices
See also
load()

◆ getPrimitiveType()

PrimitiveType gf::VertexBuffer::getPrimitiveType ( ) const
inline

Get the primitive type of the data in the buffer.

This function returns the type parameter given in the constructor.

Returns
The primitive type
See also
load()

◆ getVertexSize()

std::size_t gf::VertexBuffer::getVertexSize ( ) const
inline

Get the vertex size in the buffer.

Returns
The size of one vertex (custom or not)

◆ hasArrayBuffer()

bool gf::VertexBuffer::hasArrayBuffer ( ) const
inline

Check if there is an array buffer.

Returns
True if an array buffer is defined

◆ hasElementArrayBuffer()

bool gf::VertexBuffer::hasElementArrayBuffer ( ) const
inline

Check if there is an element array buffer.

Returns
True if an array element buffer is defined