Tucano  0.1
A library for rapid prototyping with modern OpenGL and GLSL
Tucano::Texture Class Reference

An OpenGL texture. It can be a simple texture or an FBO texture. More...

#include <texture.hpp>

Public Member Functions

 Texture (void)
 Default Constructor. More...
 
int getWidth (void)
 Returns the texture width. More...
 
int getHeight (void)
 Returns the texture height. More...
 
Eigen::Vector2i getDimensions (void)
 Returns the texture dimensions. More...
 
void setNumSamples (int num)
 Sets the number of samples for multisampling. More...
 
GLuint create (GLenum type, GLenum int_format, int w, int h, GLenum fmt, GLenum pix_type, const GLvoid *data=NULL, int dpt=256)
 Creates a texture object and returns its handler. More...
 
GLuint create (int w, int h, const GLvoid *data=NULL)
 Creates a texture object with typical default parameters and returns its handler. More...
 
void setTexParameters (GLenum wraps=GL_CLAMP, GLenum wrapt=GL_CLAMP, GLenum magfilter=GL_NEAREST, GLenum minfilter=GL_NEAREST)
 Deletes the texture. More...
 
void setTexParametersMipMap (int maxlevel, int baselevel=0, GLenum wraps=GL_CLAMP, GLenum wrapt=GL_CLAMP, GLenum magfilter=GL_NEAREST, GLenum minfilter=GL_NEAREST_MIPMAP_NEAREST)
 Sets texture parameters. Sets the Wrap S and T, Min and Mag filter, and MipMap parameters. Also generates the MipMap at the end. More...
 
void update (const GLvoid *data)
 Updates the data of the texture mantaining all other parameters. More...
 
void bind (int texture_unit)
 Binds the texture to a given unit. Note that if there is another texture already binded to this unit, no warning is given, and this texture will replace it. More...
 
int bind (void)
 Binds the texture to the first free texture unit and returns the unit used. Gets the first free unit from the texture manager to bind the texture. More...
 
int bindImageRW (void)
 Binds the texture as an image texture. Image textures are used for example for atomic counters, compute shaders, and other uses. Binds with READ and WRITE access using the current internal format. Gets the first free unit from the texture manager to bind the texture. More...
 
void bindImageRW (int texture_unit)
 Binds the texture as an image texture to a given unit. Image textures are used for example for atomic counters, compute shaders, and other uses. Binds with READ and WRITE access. If another texture is using the given unit it will be replaced by the current one. More...
 
int bindImageFormatRW (GLenum fmt)
 Binds the texture as an image texture with a given format. Binds with READ and WRITE access with a given format that might be different from texture internal format. More...
 
void bindImageFormatRW (int texture_unit, GLenum fmt)
 Binds the texture as an image texture to a given texture unit with a given internal format. Binds with READ and WRITE access with a given format that might be different from texture internal format. If another texture is using the given unit it will be replaced by the current one. More...
 
void unbind (void)
 Unbinds this texture and frees the texture unit. More...
 
GLuint texID (void) const
 Returns the texture handle (texture ID). More...
 
int textureUnit (void) const
 Returns the texture unit this texture is bound to. More...
 

Private Attributes

GLuint tex_id
 ID handler to texture. More...
 
GLenum tex_type
 Type of texture (ex. GL_TEXTURE_2D, GL_TEXTURE_3D ...). More...
 
GLenum internal_format
 Internal format (ex. GL_RGBA, GL_RGBA32F ...). More...
 
int width
 Width in pixels. More...
 
int height
 Height in pixels. More...
 
int depth
 Depth in pixels (for 3D texture). More...
 
GLenum format
 Format of texture channels (ex. GL_RGBA). More...
 
GLenum pixel_type
 Type of pixel channel (ex. GL_FLOAT, GL_UNSIGNED_BYTE ...). More...
 
int lod
 Number of lod levels (1 for textures without lod). More...
 
int unit
 Texture unit this texture is occupying (if any). More...
 
int num_samples = 1
 Number of samples, default is 1 (no multisampling) More...
 
std::shared_ptr< GLuint > texID_sptr
 shared pointer for maintaing texture id More...
 

Detailed Description

An OpenGL texture. It can be a simple texture or an FBO texture.

Constructor & Destructor Documentation

Tucano::Texture::Texture ( void  )
inline

Default Constructor.

Member Function Documentation

void Tucano::Texture::bind ( int  texture_unit)
inline

Binds the texture to a given unit. Note that if there is another texture already binded to this unit, no warning is given, and this texture will replace it.

Parameters
texture_unitGiven texture unit.
int Tucano::Texture::bind ( void  )
inline

Binds the texture to the first free texture unit and returns the unit used. Gets the first free unit from the texture manager to bind the texture.

Returns
Unit the texture was bound to, or -1 if no unit available.
int Tucano::Texture::bindImageFormatRW ( GLenum  fmt)
inline

Binds the texture as an image texture with a given format. Binds with READ and WRITE access with a given format that might be different from texture internal format.

Parameters
fmtInternal elements format (ex. GL_R32UI).
Returns
Unit the texture was bound to, or -1 if no unit available.
void Tucano::Texture::bindImageFormatRW ( int  texture_unit,
GLenum  fmt 
)
inline

Binds the texture as an image texture to a given texture unit with a given internal format. Binds with READ and WRITE access with a given format that might be different from texture internal format. If another texture is using the given unit it will be replaced by the current one.

Parameters
texture_unitTexture unit to bound.
fmtInternal elements format (ex. GL_R32UI).
int Tucano::Texture::bindImageRW ( void  )
inline

Binds the texture as an image texture. Image textures are used for example for atomic counters, compute shaders, and other uses. Binds with READ and WRITE access using the current internal format. Gets the first free unit from the texture manager to bind the texture.

Returns
Unit the texture was bound to, or -1 if no unit available.
void Tucano::Texture::bindImageRW ( int  texture_unit)
inline

Binds the texture as an image texture to a given unit. Image textures are used for example for atomic counters, compute shaders, and other uses. Binds with READ and WRITE access. If another texture is using the given unit it will be replaced by the current one.

Parameters
texture_unitTexture unit to bound.
GLuint Tucano::Texture::create ( GLenum  type,
GLenum  int_format,
int  w,
int  h,
GLenum  fmt,
GLenum  pix_type,
const GLvoid *  data = NULL,
int  dpt = 256 
)
inline

Creates a texture object and returns its handler.

Parameters
typeType of GL texture (usually GL_TEXTURE_2D)
int_formatFormat of texel (usually GL_RGBA or GL_RGBA32F for precision)
wWidth of texture
hHeight of texture
fmtFormat of texel channels (usually GL_RGBA)
pix_typeType of one channel of a texel (usually GL_FLOAT or GL_USIGNED_BYTE)
dataPointer to data to fill the texture
dpt
Returns
Texture ID (handler for OpenGL)
GLuint Tucano::Texture::create ( int  w,
int  h,
const GLvoid *  data = NULL 
)
inline

Creates a texture object with typical default parameters and returns its handler.

The default parameters are texture type (GL_TEXTURE_2D), internal format (GL_RGBA32F), format (GL_RGBA), pixel type (GL_UNSIGNED_BYTE)

Parameters
wWidth of texture
hHeight of texture
dataPointer to data to fill the texture
Returns
Texture ID (handler for OpenGL)
Eigen::Vector2i Tucano::Texture::getDimensions ( void  )
inline

Returns the texture dimensions.

Returns
Texture dimensions as an int vector
int Tucano::Texture::getHeight ( void  )
inline

Returns the texture height.

Returns
texture height in pixels
int Tucano::Texture::getWidth ( void  )
inline

Returns the texture width.

Returns
texture width in pixels
void Tucano::Texture::setNumSamples ( int  num)
inline

Sets the number of samples for multisampling.

Parameters
numNumber of samples
void Tucano::Texture::setTexParameters ( GLenum  wraps = GL_CLAMP,
GLenum  wrapt = GL_CLAMP,
GLenum  magfilter = GL_NEAREST,
GLenum  minfilter = GL_NEAREST 
)
inline

Deletes the texture.

Sets texture parameters. Sets the Wrap S and T, and Min and Mag filter parameters.

Parameters
wrapsWrap S
wraptWrap T
magfilterMag Filter
minfilterMin Filter
void Tucano::Texture::setTexParametersMipMap ( int  maxlevel,
int  baselevel = 0,
GLenum  wraps = GL_CLAMP,
GLenum  wrapt = GL_CLAMP,
GLenum  magfilter = GL_NEAREST,
GLenum  minfilter = GL_NEAREST_MIPMAP_NEAREST 
)
inline

Sets texture parameters. Sets the Wrap S and T, Min and Mag filter, and MipMap parameters. Also generates the MipMap at the end.

Parameters
maxlevelMax Mipmap level
baselevelMipmap Base Level
wrapsWrap S
wraptWrap T
magfilterMag Filter
minfilterMin Filter
GLuint Tucano::Texture::texID ( void  ) const
inline

Returns the texture handle (texture ID).

Returns
Texture ID.
int Tucano::Texture::textureUnit ( void  ) const
inline

Returns the texture unit this texture is bound to.

Returns
The bound texture unit.
void Tucano::Texture::unbind ( void  )
inline

Unbinds this texture and frees the texture unit.

void Tucano::Texture::update ( const GLvoid *  data)
inline

Updates the data of the texture mantaining all other parameters.

Parameters
dataPointer to data to fill the texture.
Remarks
Using glTexSubImage to update texture as recommended on OpenGL wiki
See also
https://www.opengl.org/wiki/Common_Mistakes#Updating_a_texture

Member Data Documentation

int Tucano::Texture::depth
private

Depth in pixels (for 3D texture).

GLenum Tucano::Texture::format
private

Format of texture channels (ex. GL_RGBA).

int Tucano::Texture::height
private

Height in pixels.

GLenum Tucano::Texture::internal_format
private

Internal format (ex. GL_RGBA, GL_RGBA32F ...).

int Tucano::Texture::lod
private

Number of lod levels (1 for textures without lod).

int Tucano::Texture::num_samples = 1
private

Number of samples, default is 1 (no multisampling)

GLenum Tucano::Texture::pixel_type
private

Type of pixel channel (ex. GL_FLOAT, GL_UNSIGNED_BYTE ...).

GLuint Tucano::Texture::tex_id
private

ID handler to texture.

GLenum Tucano::Texture::tex_type
private

Type of texture (ex. GL_TEXTURE_2D, GL_TEXTURE_3D ...).

std::shared_ptr< GLuint > Tucano::Texture::texID_sptr
private

shared pointer for maintaing texture id

int Tucano::Texture::unit
private

Texture unit this texture is occupying (if any).

int Tucano::Texture::width
private

Width in pixels.


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