zMol
A viewer for molecular data using OpenGL and ambient occlusion
|
#include <texture.hpp>
Inherits zmol::noncopyable_::noncopyable.
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) |
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.
|
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.
p_width | Width of the texture, in pixels |
p_height | Height of the texture, in pixels |
p_internal_format | Internal format of the texture, see |
p_format | Initial pixel data format (this is necessary, even though only space is reserved for the texture) |
p_type | Initial 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().
void zmol::texture::bind | ( | GLuint const | p_unit | ) |
Binds the texture object to the specified texture unit of the OpenGL context.
p_unit | Texture unit index to bind to |
|
inline |
Returns the height of the texture object, in pixels.
|
inline |
Returns the OpenGL name of the texture object.
|
inline |
Returns the width of the texture object, in pixels.
|
static |
Unbinds the texture object from the specified texture unit of the OpenGL context.
p_unit | Texture 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.
p_pixels | Pointer to the data block that shall be uploaded |
p_num_pixel_bytes | Size of the data block, in bytes |
p_pixel_data_format | Pixel data format of the data to be uploaded |
p_pixel_data_type | Pixel data type of the data to be uploaded |