GLW
Computer Graphics Structures library
glw::ArrayObject Class Reference

Class to store data arrays. Arrays can be later accessed by shaders when draw is requested. More...

Public Types

using BufferName = size_t
 Identifier of vertex buffer.
 
using ElementBufferName = size_t
 Identifier of element buffer.
 

Public Member Functions

 ArrayObject (size_t vertex_count)
 Creates new object. Defined vertex count is expected for a setters of this instance.
 
 ~ArrayObject ()
 Destructs array object and frees all allocated OpenGL buffers.
 
uint64_t GetVertexCount () const
 Returns number of vertices expected by this instance.
 
void Bind () const
 Binds this ArrayObject. Needs to be called before any changes and drawings are performed with this object.
 
void Unbind () const
 Unbinds this ArrayObject.
 
bool IsBound () const
 Returns, whether this ArrayObject is currently bound.
 
BufferName AddBuffer (const void *data, size_t per_vert_size, DataUsage usage=DataUsage::dynamic_draw)
 Creates new buffer in graphic memory, and fills it with data. Parameter per_vert_size defines data memory size (in bytes) for each vertex.
 
void SetBuffer (BufferName vert_buffer, const void *data, size_t per_vert_size)
 Replaces data in existing buffer.
 
bool IsBufferValid (BufferName vert_buffer) const
 Checks whether specified buffer name belongs to valid buffer.
 
void SetBinding (const Attrib &att, uint32_t shader_location, BufferName buffer)
 Creates shader binding for specified buffer. Attribute parameter defines how are data structured inside buffer.
 
BufferName GetBinding (uint32_t shader_location) const
 Return the name of buffer that is bound to shader location. If no such buffer exists, returns INVALID_NAME.
 
bool ExistsBinding (uint32_t shader_location) const
 Check if there is binding for a shader location;.
 
BufferName AddBufferBinding1f (uint32_t shader_location, const void *data)
 Creates new buffer and sets shader binding. This function replaces call of SetBuffer and SetBinding with Attrib1f parameter.
 
BufferName AddBufferBinding2f (uint32_t shader_location, const void *data)
 Creates new buffer and sets shader binding. This function replaces call of SetBuffer and SetBinding with Attrib2f parameter.
 
BufferName AddBufferBinding3f (uint32_t shader_location, const void *data)
 Creates new buffer and sets shader binding. This function replaces call of SetBuffer and SetBinding with Attrib3f parameter.
 
BufferName AddBufferBinding4f (uint32_t shader_location, const void *data)
 Creates new buffer and sets shader binding. This function replaces call of SetBuffer and SetBinding with Attrib4f parameter.
 
BufferName AddBufferBinding1i (uint32_t shader_location, const void *data)
 Creates new buffer and sets shader binding. This function replaces call of SetBuffer and SetBinding with Attrib1i parameter.
 
BufferName AddBufferBinding2i (uint32_t shader_location, const void *data)
 Creates new buffer and sets shader binding. This function replaces call of SetBuffer and SetBinding with Attrib2i parameter.
 
BufferName AddBufferBinding3i (uint32_t shader_location, const void *data)
 Creates new buffer and sets shader binding. This function replaces call of SetBuffer and SetBinding with Attrib3i parameter.
 
BufferName AddBufferBinding4i (uint32_t shader_location, const void *data)
 Creates new buffer and sets shader binding. This function replaces call of SetBuffer and SetBinding with Attrib4i parameter.
 
ElementBufferName AddElementBuffer (const uint32_t *data, size_t count)
 Creates new element buffer which defines how primitives are structured.
 
void SetDrawMode (DrawMode mode)
 Set default drawing mode used when calling pure Draw or DrawInstanced functions. Default value is DrawMode::points.
 
void Draw () const
 Draws vertices or first defined elements. Default draw mode set by function SetDrawMode.
 
void DrawInstanced (uint32_t instance_count) const
 Draws vertices or first defined elements multiple times. Default draw mode set by function SetDrawMode.
 
void DrawVertices (DrawMode mode) const
 Draws vertices from buffer arrays.
 
void DrawVertices (size_t num_vertices, DrawMode mode) const
 Draws vertices from buffer arrays, the number of vertices drawn is num_vertices or vao vertex count, whichever is smaller.
 
void DrawVerticesInstanced (uint32_t instance_count, DrawMode mode) const
 Draws vertices from buffer arrays multiple times.
 
void DrawElements (ElementBufferName el_buff, DrawMode mode) const
 Draws elements specified element buffer.
 
void DrawElementsInstanced (uint32_t instance_count, ElementBufferName el_buff, DrawMode mode) const
 Draws elements specified element buffer multiple times.
 

Static Public Member Functions

static PArrayObject Create (const size_t vertex_count)
 Crate a shared pointer with new instance of ArrayObject class.
 

Static Public Attributes

static const BufferName INVALID_NAME { UINT32_MAX }
 Element buffer or vertex buffer name which do not represent valid buffer.
 

Protected Attributes

uint32_t vao_ = 0
 
size_t vertex_count_ = 0
 
DrawMode default_mode_ = DrawMode::points
 
std::vector< uint32_t > buffer_names_
 
std::unordered_map< uint32_t, BufferName > bindings_
 
std::vector< ElementBuffer > elements_
 

Detailed Description

Class to store data arrays. Arrays can be later accessed by shaders when draw is requested.