zMol
A viewer for molecular data using OpenGL and ambient occlusion
|
#include <buffer_object.hpp>
Inherits zmol::noncopyable_::noncopyable.
Public Member Functions | |
buffer_object (GLenum const p_target, GLenum const p_usage) | |
~buffer_object () | |
GLuint | get_name () const |
GLenum | get_target () const |
GLenum | get_usage () const |
void | bind () |
void | unbind () |
void | upload_data (void const *p_data, unsigned long const p_num_bytes) |
void | resize (unsigned long const p_num_bytes) |
unsigned long | get_size () const |
Buffer object wrapper class.
The class creates a buffer object in the constructor, and destroys it in the destructor. This makes proper use of the C++ RAII idiom, and ensures exception safety (-> no resource leak).
The OpenGL terminology is somewhat counter-intuitive. Informally, these entities are known as "vertex buffer objects", but are used for vertices and indices. The OpenGL target for the former is GL_ARRAY_BUFFER, the latter is GL_ELEMENT_ARRAY_BUFFER. For sake of clarity, buffers for vertices are simply called "vertex buffer objects", and buffers for indices "index buffer objects".
|
explicit |
Constructor. Creates the buffer object with glGenBuffers().
p_target | See the OpenGL glBindBuffer() documentation for an explanation of this value |
p_usage | See the OpenGL glBindBuffer() documentation for an explanation of this value |
zmol::buffer_object::~buffer_object | ( | ) |
Destructor. Destroys the buffer object with glDeleteBuffers().
void zmol::buffer_object::bind | ( | ) |
Binds the buffer object to the OpenGL context.
|
inline |
Returns the OpenGL name of the buffer object.
|
inline |
Returns the size of the buffer object, in bytes
|
inline |
Returns the target of the buffer object.
|
inline |
Returns the usage of the buffer object.
void zmol::buffer_object::resize | ( | unsigned long const | p_num_bytes | ) |
Creates or resizes the buffer object with the given number of bytes. Existing contents will be erased by this call. This is mainly useful if the buffer_object_mapping class is used.
p_num_bytes | New size for the buffer object, in bytes |
void zmol::buffer_object::unbind | ( | ) |
Unbinds the buffer object to the OpenGL context.
void zmol::buffer_object::upload_data | ( | void const * | p_data, |
unsigned long const | p_num_bytes | ||
) |
Uploads a block of data into the buffer object. Previous contents will be erased by this call.
p_data | Pointer to the data block to be uploaded |
p_num_bytes | Size of the data block to be uploaded, in bytes |