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

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

#include <gui_sfml_vertex_cache.hpp>

Inheritance diagram for lxgui::gui::sfml::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...
 
void update (const vertex *vertex_data, std::size_t num_vertex) override
 Update the data stored in the cache to form new triangles. More...
 
std::size_t get_vertex_count () const
 Returns the number of vertices currently stored in the cache. More...
 
const sf::VertexBuffer & get_impl () const
 Returns the SFML vertex buffer object. 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_sfml_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::sfml::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.

Member Function Documentation

◆ get_impl()

const sf::VertexBuffer& lxgui::gui::sfml::vertex_cache::get_impl ( ) const

Returns the SFML vertex buffer object.

Returns
The SFML vertex buffer object

◆ get_vertex_count()

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

Returns the number of vertices currently stored in the cache.

Returns
The number of vertices currently stored in the cache

◆ update()

void lxgui::gui::sfml::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.

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: