lxgui
Public Types | Public Member Functions | Protected Attributes | List of all members
lxgui::gui::gl::vertex_cache Class Referencefinal

An object representing cached vertex data on the GPU. More...

#include <gui_gl_vertex_cache.hpp>

Inheritance diagram for lxgui::gui::gl::vertex_cache:
lxgui::gui::vertex_cache

Public Types

enum class  type { triangles , quads }
 The type of vertex data contained in a vertex_cache. More...
 

Public Member Functions

 vertex_cache (type t)
 Constructor. More...
 
 ~vertex_cache () override
 Destructor. More...
 
void update_data (const vertex *vertex_data, std::size_t num_vertex)
 Update the data stored in the cache, reusing existing indices. More...
 
void update_indices (const std::uint32_t *vertex_indices, std::size_t num_indices)
 Update the indices stored in the cache, reusing existing data. More...
 
void update_indices_if_grow (const std::uint32_t *vertex_indices, std::size_t num_indices)
 Update the indices stored in the cache, but only if the current index cache is smaller. More...
 
void update (const vertex *vertex_data, std::size_t num_vertex) override
 Update the data stored in the cache to form new triangles. More...
 
void render () const
 Renders the cache. More...
 
std::size_t get_vertex_count () const
 Returns the number of vertices stored in this cache. More...
 

Protected Attributes

type type_ = type::triangles
 
std::size_t num_vertex_ = 0
 

Detailed Description

An object representing cached vertex data on the GPU.

A vertex cache stores vertices and indices that can be used to draw any shape on the screen. If the type is TRIANGLES, each group of 3 vertices forms a triangle, while if the type is QUADS, each group of 4 vertices forms a quad.

Using this class enables more efficient rendering of large groups of sprites or quads that share the same material (texture). This is especially true if the data to render does not change often.

A vertex cache can be rendered with gui::renderer::render_vertex_cache().

Note
This is an abstract class that must be inherited from and created by the corresponding gui::renderer.

Definition at line 28 of file gui_gl_vertex_cache.hpp.

Member Enumeration Documentation

◆ type

enum lxgui::gui::vertex_cache::type
stronginherited

The type of vertex data contained in a vertex_cache.

Enumerator
triangles 
quads 

3 vertices per element

4 vertices per element

Definition at line 32 of file gui_vertex_cache.hpp.

Constructor & Destructor Documentation

◆ vertex_cache()

lxgui::gui::gl::vertex_cache::vertex_cache ( type  t)
explicit

Constructor.

Parameters
tThe type of data this cache will hold

A default constructed vertex cache holds no data. Use update() to store vertices to be rendered. The size hint can enable the cache to be pre-allocated, which will avoid a reallocation when update() is called.

◆ ~vertex_cache()

lxgui::gui::gl::vertex_cache::~vertex_cache ( )
overridevirtual

Destructor.

Reimplemented from lxgui::gui::vertex_cache.

Member Function Documentation

◆ get_vertex_count()

std::size_t lxgui::gui::vertex_cache::get_vertex_count ( ) const
inlineinherited

Returns the number of vertices stored in this cache.

Returns
The number of vertices stored in this cache

Definition at line 73 of file gui_vertex_cache.hpp.

◆ render()

void lxgui::gui::gl::vertex_cache::render ( ) const

Renders the cache.

Note
This does not bind the material, just binds the cache and renders it with whatever shader / texture is currently bound.

◆ update()

void lxgui::gui::gl::vertex_cache::update ( const vertex vertex_data,
std::size_t  num_vertex 
)
overridevirtual

Update the data stored in the cache to form new triangles.

Parameters
vertex_dataThe vertices to cache
num_vertexThe number of vertices to cache
Note
If the type if TRIANGLES, num_vertex must be a multiple of 3. If the type if QUADS, num_vertex must be a multiple of 4.

Implements lxgui::gui::vertex_cache.

◆ update_data()

void lxgui::gui::gl::vertex_cache::update_data ( const vertex vertex_data,
std::size_t  num_vertex 
)

Update the data stored in the cache, reusing existing indices.

Parameters
vertex_dataThe vertices to cache
num_vertexThe number of vertices to cache

◆ update_indices()

void lxgui::gui::gl::vertex_cache::update_indices ( const std::uint32_t *  vertex_indices,
std::size_t  num_indices 
)

Update the indices stored in the cache, reusing existing data.

Parameters
vertex_indicesThe indices to use for drawing triangles
num_indicesThe number of indices to cache

◆ update_indices_if_grow()

void lxgui::gui::gl::vertex_cache::update_indices_if_grow ( const std::uint32_t *  vertex_indices,
std::size_t  num_indices 
)

Update the indices stored in the cache, but only if the current index cache is smaller.

Parameters
vertex_indicesThe indices to use for drawing triangles
num_indicesThe number of indices to cache
Note
This function assumes that the index buffer is always initialised with valid indices, and that only the number of indices changes. Indices that were set in previous calls of update_indices() are assumed to not change value.

Member Data Documentation

◆ num_vertex_

std::size_t lxgui::gui::vertex_cache::num_vertex_ = 0
protectedinherited

Definition at line 79 of file gui_vertex_cache.hpp.

◆ type_

type lxgui::gui::vertex_cache::type_ = type::triangles
protectedinherited

Definition at line 78 of file gui_vertex_cache.hpp.


The documentation for this class was generated from the following file: