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

#include <texture.hpp>

Inherits zmol::noncopyable_::noncopyable.

List of all members.

Public Member Functions

 texture (GLsizei const p_width, GLsizei const p_height, GLint const p_internal_format, GLenum const p_format, GLenum const p_type)
 ~texture ()
GLsizei get_width () const
GLsizei get_height () const
GLuint get_name () const
void bind (GLuint const p_unit)
void upload_pixels (void const *p_pixels, unsigned int const p_num_pixel_bytes, GLenum const p_pixel_data_format, GLenum const p_pixel_data_type)

Static Public Member Functions

static void unbind (GLuint const p_unit)

Detailed Description

Texture object wrapper class.

The class creates a texture 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 class limits itself to 2D textures, since no other types are necessary for zMol. Also, only one mipmap level is used, together with bilinear filtering. GL_CLAMP_TO_EDGE is used as wrapping mode in the S and T directions.


Constructor & Destructor Documentation

zmol::texture::texture ( GLsizei const  p_width,
GLsizei const  p_height,
GLint const  p_internal_format,
GLenum const  p_format,
GLenum const  p_type 
)
explicit

Constructor. Creates a texture object using glGenTextures(). Memory is reserved for the texture object by using glTexImage2D() with the data pointer set to null.

See the OpenGL glTexImage2D() documentation for details about the internal format, the pixel data format, and the pixel data type.

Parameters:
p_widthWidth of the texture, in pixels
p_heightHeight of the texture, in pixels
p_internal_formatInternal format of the texture, see
p_formatInitial pixel data format (this is necessary, even though only space is reserved for the texture)
p_typeInitial pixel data type (this is necessary, even though only space is reserved for the texture)
zmol::texture::~texture ( )

Destructor. Destroys the texture object using glDeleteTextures().


Member Function Documentation

void zmol::texture::bind ( GLuint const  p_unit)

Binds the texture object to the specified texture unit of the OpenGL context.

Parameters:
p_unitTexture unit index to bind to
GLsizei zmol::texture::get_height ( ) const
inline

Returns the height of the texture object, in pixels.

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

Returns the OpenGL name of the texture object.

GLsizei zmol::texture::get_width ( ) const
inline

Returns the width of the texture object, in pixels.

void zmol::texture::unbind ( GLuint const  p_unit)
static

Unbinds the texture object from the specified texture unit of the OpenGL context.

Parameters:
p_unitTexture unit index to unbind from
void zmol::texture::upload_pixels ( void const *  p_pixels,
unsigned int const  p_num_pixel_bytes,
GLenum const  p_pixel_data_format,
GLenum const  p_pixel_data_type 
)

Uploads pixel data into the texture object by using glTexSubImage2D().

See the OpenGL glTexSubImage2D() documentation for details about the the pixel data format and the pixel data type.

Parameters:
p_pixelsPointer to the data block that shall be uploaded
p_num_pixel_bytesSize of the data block, in bytes
p_pixel_data_formatPixel data format of the data to be uploaded
p_pixel_data_typePixel data type of the data to be uploaded