Easy3D 2.6.1
Loading...
Searching...
No Matches
VertexArrayObject Class Reference

A thin wrapper around an OpenGL Vertex Array Object (VAO). More...

#include <easy3d/renderer/vertex_array_object.h>

Public Member Functions

 VertexArrayObject ()
 Constructor.
 
 ~VertexArrayObject ()
 Destructor.
 
GLuint id () const
 Get the OpenGL ID of the VAO.
 
void bind ()
 Bind the VAO.
 
void release () const
 Release the VAO.
 
bool create_array_buffer (GLuint &buffer, GLuint index, const void *data, std::size_t size, std::size_t dim, bool dynamic=false)
 Creates an OpenGL array buffer and uploads data to the buffer.
 
bool create_element_buffer (GLuint &buffer, const void *data, std::size_t size, bool dynamic=false)
 Creates an OpenGL element buffer and uploads data to the buffer.
 
bool create_storage_buffer (GLuint &buffer, GLuint index, const void *data, std::size_t size)
 Creates an OpenGL shader storage buffer and uploads data to the buffer.
 
bool update_storage_buffer (GLuint &buffer, GLintptr offset, GLsizeiptr size, const void *data)
 Updates an OpenGL shader storage buffer with new data.
 

Static Public Member Functions

static bool is_supported ()
 Check if VAOs are supported by the current OpenGL context.
 
static void release_buffer (GLuint &buffer)
 Frees the GPU memory of the buffer specified by 'buffer'.
 
static void get_buffer_data (GLenum target, GLuint buffer, GLintptr offset, GLsizeiptr size, void *data)
 Returns a subset of a buffer object's data store.
 
static void * map_buffer (GLenum target, GLuint buffer, GLenum access)
 Maps a buffer object's data store.
 
static void unmap_buffer (GLenum target, GLuint buffer)
 Unmaps a buffer object's data store.
 

Detailed Description

A thin wrapper around an OpenGL Vertex Array Object (VAO).

A VAO is an OpenGL container object that encapsulates the state needed to specify per-vertex attribute data to the OpenGL pipeline. To put it another way, a VAO remembers the states of buffer objects (i.e., vertex buffers) and their associated state (e.g. vertex attribute divisors). This allows a very easy and efficient method of switching between OpenGL buffer states for rendering different "objects" in a scene.

Note
This implementation is more than the standard VAO. It also provides functions for creating and managing other buffer objects (i.e., shader storage buffer).

Constructor & Destructor Documentation

◆ ~VertexArrayObject()

Destructor.

Deletes the VAO and frees the associated OpenGL resources.

Member Function Documentation

◆ bind()

void bind ( )

Bind the VAO.

Makes the VAO the current VAO in the OpenGL context.

◆ create_array_buffer()

bool create_array_buffer ( GLuint & buffer,
GLuint index,
const void * data,
std::size_t size,
std::size_t dim,
bool dynamic = false )

Creates an OpenGL array buffer and uploads data to the buffer.

Parameters
bufferThe name of the buffer object.
indexThe index of the generic vertex attribute to be enabled.
dataThe pointer to the data.
sizeThe size of the data in bytes.
dimThe number of components per generic vertex attribute. Must be 1, 2, 3, or 4.
dynamicThe expected usage pattern is GL_STATIC_DRAW or GL_DYNAMIC_DRAW.
Returns
True if the buffer was created successfully, false otherwise.

◆ create_element_buffer()

bool create_element_buffer ( GLuint & buffer,
const void * data,
std::size_t size,
bool dynamic = false )

Creates an OpenGL element buffer and uploads data to the buffer.

Parameters
bufferThe name of the buffer object.
dataThe pointer to the data.
sizeThe size of the data in bytes.
dynamicThe expected usage pattern is GL_STATIC_DRAW or GL_DYNAMIC_DRAW.
Returns
True if the buffer was created successfully, false otherwise.

◆ create_storage_buffer()

bool create_storage_buffer ( GLuint & buffer,
GLuint index,
const void * data,
std::size_t size )

Creates an OpenGL shader storage buffer and uploads data to the buffer.

Parameters
bufferThe name of the buffer object.
indexThe index of the binding point.
dataThe pointer to the data.
sizeThe size of the data in bytes.
Returns
True if the buffer was created successfully, false otherwise.

◆ get_buffer_data()

void get_buffer_data ( GLenum target,
GLuint buffer,
GLintptr offset,
GLsizeiptr size,
void * data )
static

Returns a subset of a buffer object's data store.

Parameters
targetThe target buffer object. Can be GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_SHADER_STORAGE_BUFFER, etc.
bufferThe name of the buffer object.
offsetThe offset into the buffer object's data store from which data will be returned, measured in bytes.
sizeThe size in bytes of the data store region being returned.
dataA pointer to the location where buffer object data is returned.

◆ id()

GLuint id ( ) const
inline

Get the OpenGL ID of the VAO.

Returns
The OpenGL ID of the VAO.

◆ is_supported()

bool is_supported ( )
static

Check if VAOs are supported by the current OpenGL context.

Returns
True if VAOs are supported, false otherwise.

◆ map_buffer()

void * map_buffer ( GLenum target,
GLuint buffer,
GLenum access )
static

Maps a buffer object's data store.

Parameters
targetThe target buffer object. Can be GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_SHADER_STORAGE_BUFFER, etc.
bufferThe name of the buffer object.
accessThe access policy. Must be GL_READ_ONLY, GL_WRITE_ONLY, or GL_READ_WRITE.
Returns
A pointer to the mapped data store.

◆ release()

void release ( ) const

Release the VAO.

Unbinds the VAO from the OpenGL context.

◆ release_buffer()

void release_buffer ( GLuint & buffer)
static

Frees the GPU memory of the buffer specified by 'buffer'.

Parameters
bufferThe name of the buffer object.

◆ unmap_buffer()

void unmap_buffer ( GLenum target,
GLuint buffer )
static

Unmaps a buffer object's data store.

Parameters
targetThe target buffer object. Can be GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_SHADER_STORAGE_BUFFER, etc.
bufferThe name of the buffer object.

◆ update_storage_buffer()

bool update_storage_buffer ( GLuint & buffer,
GLintptr offset,
GLsizeiptr size,
const void * data )

Updates an OpenGL shader storage buffer with new data.

Parameters
bufferThe name of the buffer object.
offsetThe offset into the buffer object's data store where data replacement will begin, measured in bytes.
sizeThe size in bytes of the data store region being replaced.
dataThe pointer to the new data.
Returns
True if the buffer was updated successfully, false otherwise.

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