zMol
A viewer for molecular data using OpenGL and ambient occlusion
Public Member Functions
zmol::buffer_object Class Reference

#include <buffer_object.hpp>

Inherits zmol::noncopyable_::noncopyable.

List of all members.

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

Detailed Description

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".


Constructor & Destructor Documentation

zmol::buffer_object::buffer_object ( GLenum const  p_target,
GLenum const  p_usage 
)
explicit

Constructor. Creates the buffer object with glGenBuffers().

Parameters:
p_targetSee the OpenGL glBindBuffer() documentation for an explanation of this value
p_usageSee the OpenGL glBindBuffer() documentation for an explanation of this value
zmol::buffer_object::~buffer_object ( )

Destructor. Destroys the buffer object with glDeleteBuffers().


Member Function Documentation

void zmol::buffer_object::bind ( )

Binds the buffer object to the OpenGL context.

GLuint zmol::buffer_object::get_name ( ) const
inline

Returns the OpenGL name of the buffer object.

unsigned long zmol::buffer_object::get_size ( ) const
inline

Returns the size of the buffer object, in bytes

GLenum zmol::buffer_object::get_target ( ) const
inline

Returns the target of the buffer object.

GLenum zmol::buffer_object::get_usage ( ) const
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.

Parameters:
p_num_bytesNew 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.

Parameters:
p_dataPointer to the data block to be uploaded
p_num_bytesSize of the data block to be uploaded, in bytes