Gamedev Framework (gf)  0.4.0
A C++11 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 ()
 Destructor. More...
 
 VertexBuffer (const VertexBuffer &)=delete
 Deleted copy constructor. More...
 
VertexBufferoperator= (const VertexBuffer &)=delete
 Deleted copy assignment. More...
 
 VertexBuffer (VertexBuffer &&other)
 Move constructor. More...
 
VertexBufferoperator= (VertexBuffer &&other)
 Move assignment. More...
 
void load (const Vertex *vertices, std::size_t count, PrimitiveType type)
 Load an array of vertices. More...
 
void load (const Vertex *vertices, const uint16_t *indices, std::size_t count, PrimitiveType type)
 Load an array of 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 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 });
gf::VertexBuffer buffer = sprite.commitGeometry();
geometry.setBuffer(buffer);
geometry.setTexture(texture);
renderer.draw(geometry);
See also
gf::BufferedGeometry

Constructor & Destructor Documentation

gf::VertexBuffer::VertexBuffer ( )

Default constructor.

gf::VertexBuffer::~VertexBuffer ( )

Destructor.

gf::VertexBuffer::VertexBuffer ( const VertexBuffer )
delete

Deleted copy constructor.

gf::VertexBuffer::VertexBuffer ( VertexBuffer &&  other)

Move constructor.

Member Function Documentation

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
std::size_t gf::VertexBuffer::getCount ( ) const
inline

Get the count of vertices or indices.

This function returns the count parameter given in VertexBuffer::load().

Returns
The count of vertices or indices
See also
load()
PrimitiveType gf::VertexBuffer::getPrimitiveType ( ) const
inline

Get the primitive type of the data in the buffer.

This function returns the type parameter given in VertexBuffer::load().

Returns
The primitive type
See also
load()
bool gf::VertexBuffer::hasArrayBuffer ( ) const
inline

Check if there is an array buffer.

Returns
True if an array buffer is defined
bool gf::VertexBuffer::hasElementArrayBuffer ( ) const
inline

Check if there is an element array buffer.

Returns
True if an array element buffer is defined
void gf::VertexBuffer::load ( 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
void gf::VertexBuffer::load ( 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& gf::VertexBuffer::operator= ( const VertexBuffer )
delete

Deleted copy assignment.

VertexBuffer& gf::VertexBuffer::operator= ( VertexBuffer &&  other)

Move assignment.