Kale
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
Kale::OpenGL::VertexArray< T, NFloats > Class Template Reference

#include <VertexArray.hpp>

Public Member Functions

 VertexArray ()
 
template<size_t N>
 VertexArray (const std::array< T, N > &verts, BufferUsage usage, bool condense=true)
 
 VertexArray (const std::vector< T > &verts, BufferUsage usage, bool condense=true)
 
template<size_t N1, size_t N2, typename index_type = unsigned int>
 VertexArray (const std::array< T, N1 > &verts, const std::array< index_type, N2 > &indices, BufferUsage usage)
 
template<typename index_type = unsigned int>
 VertexArray (const std::vector< T > &verts, const std::vector< index_type > &indices, BufferUsage usage)
 
 VertexArray (const std::vector< T > &verts, std::vector< unsigned int > &&indices, BufferUsage usage)
 
 ~VertexArray ()
 
void enableAttributePointer (const std::array< unsigned int, sizeof...(NFloats)> &attributes) const
 
void bind () const
 
template<size_t N>
void updateVerticesCondense (const std::array< T, N > &verts, BufferUsage usage)
 
void updateVerticesCondense (const std::vector< T > &verts, BufferUsage usage)
 
void draw () const
 
void drawNoElements () const
 
void draw (DrawType type) const
 
void drawNoElements (DrawType type) const
 

Public Attributes

Buffer< float > vertices
 
Buffer< unsigned int > elements
 

Private Member Functions

constexpr size_t numFloatsInVert ()
 
bool vertFloatPtrEqual (const float *floatPtr, const T &vert)
 
template<typename Container >
void condenseVertices (const Container &verts, BufferUsage usage)
 
template<typename Verts , typename Func >
void createVerticesAndElements (const Verts &verts, const Func &func, BufferUsage usage)
 

Private Attributes

unsigned int vertexArray
 

Detailed Description

template<typename T, size_t... NFloats>
class Kale::OpenGL::VertexArray< T, NFloats >

Represents an array of vertices, NOT an OpenGL vertex array (although the class does use OpenGL vertex arrays internally)

Template Parameters
Tthe struct containing an individual vertex
NFloatsfor each vector within the vertex the number of floats in the vector must be given

Definition at line 44 of file VertexArray.hpp.

Constructor & Destructor Documentation

◆ VertexArray() [1/6]

template<typename T , size_t... NFloats>
Kale::OpenGL::VertexArray< T, NFloats >::VertexArray ( )
inline

Creates an empty vertex array

Definition at line 152 of file VertexArray.hpp.

◆ VertexArray() [2/6]

template<typename T , size_t... NFloats>
template<size_t N>
Kale::OpenGL::VertexArray< T, NFloats >::VertexArray ( const std::array< T, N > & verts,
BufferUsage usage,
bool condense = true )
inline

Creates a vertex array given the vertices

Parameters
vertsThe vertices
usageThe usage of the vertex array
condenseWhether or not to remove the duplicates of vertices given and condense it into elements

Definition at line 166 of file VertexArray.hpp.

◆ VertexArray() [3/6]

template<typename T , size_t... NFloats>
Kale::OpenGL::VertexArray< T, NFloats >::VertexArray ( const std::vector< T > & verts,
BufferUsage usage,
bool condense = true )
inline

Creates a vertex array given the vertices

Parameters
vertsThe vertices
usageThe usage of the vertex array
condenseWhether or not to remove the duplicates of vertices given and condense it into elements

Definition at line 185 of file VertexArray.hpp.

◆ VertexArray() [4/6]

template<typename T , size_t... NFloats>
template<size_t N1, size_t N2, typename index_type = unsigned int>
Kale::OpenGL::VertexArray< T, NFloats >::VertexArray ( const std::array< T, N1 > & verts,
const std::array< index_type, N2 > & indices,
BufferUsage usage )
inline

Creates a vertex array given the vertices and elements/indices

Template Parameters
N1Size of vertices array
N2Size of indices array
index_typeType of indices (should be numeric)
Parameters
vertsThe vertices
indicesThe indices
usageThe usage of the vertex array

Definition at line 208 of file VertexArray.hpp.

◆ VertexArray() [5/6]

template<typename T , size_t... NFloats>
template<typename index_type = unsigned int>
Kale::OpenGL::VertexArray< T, NFloats >::VertexArray ( const std::vector< T > & verts,
const std::vector< index_type > & indices,
BufferUsage usage )
inline

Creates a vertex array given the vertices and elements/indices

Template Parameters
index_typeThe type of indices, should be numeric
Parameters
vertsThe vertices
indicesThe indices
usageThe usage of the vertex array

Definition at line 225 of file VertexArray.hpp.

◆ VertexArray() [6/6]

template<typename T , size_t... NFloats>
Kale::OpenGL::VertexArray< T, NFloats >::VertexArray ( const std::vector< T > & verts,
std::vector< unsigned int > && indices,
BufferUsage usage )
inline

Creates a vertex array given the vertices and elements/indices

Parameters
vertsThe vertices
indicesThe indices
usageThe usage of the vertex array

Definition at line 240 of file VertexArray.hpp.

◆ ~VertexArray()

template<typename T , size_t... NFloats>
Kale::OpenGL::VertexArray< T, NFloats >::~VertexArray ( )
inline

Frees resources

Definition at line 251 of file VertexArray.hpp.

Member Function Documentation

◆ bind()

template<typename T , size_t... NFloats>
void Kale::OpenGL::VertexArray< T, NFloats >::bind ( ) const
inline

Binds this vertex array for use externally

Definition at line 275 of file VertexArray.hpp.

◆ condenseVertices()

template<typename T , size_t... NFloats>
template<typename Container >
void Kale::OpenGL::VertexArray< T, NFloats >::condenseVertices ( const Container & verts,
BufferUsage usage )
inlineprivate

Condenses vertices from a container into the vertices and elements buffers and syncs them with the GPU

Parameters
vertsThe vertices
usageThe usage of the vertex array

Definition at line 74 of file VertexArray.hpp.

◆ createVerticesAndElements()

template<typename T , size_t... NFloats>
template<typename Verts , typename Func >
void Kale::OpenGL::VertexArray< T, NFloats >::createVerticesAndElements ( const Verts & verts,
const Func & func,
BufferUsage usage )
inlineprivate

Creates the vertices and elements given the vertices container and a function to create the elements

Parameters
vertsThe vertices
funcThe function for setting the elements
usageThe usage of the vertex array

Definition at line 127 of file VertexArray.hpp.

◆ draw() [1/2]

template<typename T , size_t... NFloats>
void Kale::OpenGL::VertexArray< T, NFloats >::draw ( ) const
inline

Draws the vertex array as triangles

Definition at line 308 of file VertexArray.hpp.

◆ draw() [2/2]

template<typename T , size_t... NFloats>
void Kale::OpenGL::VertexArray< T, NFloats >::draw ( DrawType type) const
inline

Draws the vertex array

Parameters
typeThe type of object to draw

Definition at line 325 of file VertexArray.hpp.

◆ drawNoElements() [1/2]

template<typename T , size_t... NFloats>
void Kale::OpenGL::VertexArray< T, NFloats >::drawNoElements ( ) const
inline

Draws the vertex array as triangles directly using the vertex buffer

Definition at line 316 of file VertexArray.hpp.

◆ drawNoElements() [2/2]

template<typename T , size_t... NFloats>
void Kale::OpenGL::VertexArray< T, NFloats >::drawNoElements ( DrawType type) const
inline

Draws the vertex array directly using the vertex buffer

Parameters
typeThe type of object to draw

Definition at line 334 of file VertexArray.hpp.

◆ enableAttributePointer()

template<typename T , size_t... NFloats>
void Kale::OpenGL::VertexArray< T, NFloats >::enableAttributePointer ( const std::array< unsigned int, sizeof...(NFloats)> & attributes) const
inline

Links the vertex array to the attributes of shaders. All shaders using this vertex array must use the correct attribute layouts.

Parameters
attributesAn array of the attribute locations for each vertex component

Definition at line 260 of file VertexArray.hpp.

◆ numFloatsInVert()

template<typename T , size_t... NFloats>
constexpr size_t Kale::OpenGL::VertexArray< T, NFloats >::numFloatsInVert ( )
inlineconstexprprivate

The total number of floats within a single vertex

Definition at line 55 of file VertexArray.hpp.

◆ updateVerticesCondense() [1/2]

template<typename T , size_t... NFloats>
template<size_t N>
void Kale::OpenGL::VertexArray< T, NFloats >::updateVerticesCondense ( const std::array< T, N > & verts,
BufferUsage usage )
inline

Updates the vertices and condenses them NOTE - This condenses again and updates both elements and vertices. If you're only updating vertices and not elements it is highly recommended to directly update the buffers

Parameters
vertsThe vertices
usageThe usage of the vertex array

Definition at line 286 of file VertexArray.hpp.

◆ updateVerticesCondense() [2/2]

template<typename T , size_t... NFloats>
void Kale::OpenGL::VertexArray< T, NFloats >::updateVerticesCondense ( const std::vector< T > & verts,
BufferUsage usage )
inline

Updates the vertices and condenses them NOTE - This condenses again and updates both elements and vertices. If you're only updating vertices and not elements it is highly recommended to directly update the buffers

Parameters
vertsThe vertices
usageThe usage of the vertex array

Definition at line 299 of file VertexArray.hpp.

◆ vertFloatPtrEqual()

template<typename T , size_t... NFloats>
bool Kale::OpenGL::VertexArray< T, NFloats >::vertFloatPtrEqual ( const float * floatPtr,
const T & vert )
inlineprivate

Checks if the underlying floats are equal between a float pointer and a vertex

Parameters
floatPtrThe float pointer to the first float within the vertex
vertThe vertex to compare to
Returns
Whether or not they are equal

Definition at line 65 of file VertexArray.hpp.

Member Data Documentation

◆ elements

template<typename T , size_t... NFloats>
Buffer<unsigned int> Kale::OpenGL::VertexArray< T, NFloats >::elements

The element buffer/index buffer

Definition at line 147 of file VertexArray.hpp.

◆ vertexArray

template<typename T , size_t... NFloats>
unsigned int Kale::OpenGL::VertexArray< T, NFloats >::vertexArray
private

The OpenGL Vertex Array ID

Definition at line 50 of file VertexArray.hpp.

◆ vertices

template<typename T , size_t... NFloats>
Buffer<float> Kale::OpenGL::VertexArray< T, NFloats >::vertices

The vertex data itself

Definition at line 142 of file VertexArray.hpp.


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