GLS
1.0.0
GL Stuff - A library aimed at reducing the boilerplate OpenGL code you always have to write.
|
Class encapsulating an OpenGL texture object. More...
#include <texture.hpp>
Public Member Functions | |
texture () | |
Default constructor. More... | |
GLuint | name () const |
Retrieve the OpenGL name of this texture. More... | |
GLsizei | width () const |
Retrieve the width of the level 0 image of the allocated texture storage. More... | |
GLsizei | height () const |
Retrieve the height of the level 0 image of the allocated texture storage. More... | |
GLsizei | depth () const |
Retrieve the depth of the level 0 image of the allocated texture storage. More... | |
void | bind () |
Bind this texture to its target. More... | |
void | parameter (GLenum pname, GLfloat param) |
Set a texture parameter. More... | |
void | parameter (GLenum pname, GLint param) |
Set a texture parameter. More... | |
void | parameter (GLenum pname, const GLfloat *param) |
Set a texture parameter. More... | |
void | parameter (GLenum pname, const GLint *param) |
Set a texture parameter. More... | |
template<typename T > | |
void | image_1d (GLint level, GLint internal_format, T the_width, GLenum format, GLenum type, const GLvoid *data) |
Allocate storage for a 1D image and upload texture data. More... | |
template<typename T , typename U > | |
void | image_2d (GLint level, GLint internal_format, T the_width, U the_height, GLenum format, GLenum type, const GLvoid *data) |
Allocate storage for a 2D image and upload texture data. More... | |
template<typename T , typename U , typename V > | |
void | image_3d (GLint level, GLint internal_format, T the_width, U the_height, V the_depth, GLenum format, GLenum type, const GLvoid *data) |
Allocate storage for a 3D image and upload texture data. More... | |
template<typename T , typename U > | |
void | sub_image_1d (GLint level, T xoffset, U the_width, GLenum format, GLenum type, const GLvoid *data) |
Update a section of a 1D image within the texture. More... | |
template<typename T , typename U , typename V , typename W > | |
void | sub_image_2d (GLint level, T xoffset, U yoffset, V the_width, W the_height, GLenum format, GLenum type, const GLvoid *data) |
Update a section of a 2D image within the texture. More... | |
template<typename T , typename U , typename V , typename W , typename X , typename Y > | |
void | sub_image_3d (GLint level, T xoffset, U yoffset, V zoffset, W the_width, X the_height, Y the_depth, GLenum format, GLenum type, const GLvoid *data) |
Update a section of a 3D image within the texture. More... | |
void | get_image (GLint level, GLint format, GLenum type, GLvoid *img) |
Get image data from this texture. More... | |
void | generate_mipmap () |
Generate mipmaps for this texture. More... | |
Static Public Member Functions | |
static void | unbind () |
Unbind the current texture from the target. More... | |
Class encapsulating an OpenGL texture object.
A gls::texture is an object that encapsulates an OpenGL texture object.
Target | The target this buffer object will be bound to when calling bind() |
Like all objects in GLS, the underlying name is generated at object construction and deleted at destruction. This can be retrieved with name().
Texture objects store arbitrary image data within server (GPU) memory. This data can then be used by shader samplers to e.g. provide texturing to rendered primitives.
Texture objects can contain multiple images. Each image is simply a block of data with an internal format. Typically, when uploading texture data to apply to a primitive, one uploads it as the level 0 image of the texture. In order to reduce aliasing effects that might occur when sampling from them, multiple smaller versions of the level 0 image can be created. This is what is known as a mipmap chain. OpenGL can automatically generate the mipmap chain for you from your level 0 data when you call the generate_mipmap() method. The algorithm used is implementation specific. Alternatively, you can manually upload each level yourself if you wish to.
In addition to the data, each texture object has certain parameters associated with it. These can control a multitude of different things. Parameters that are automatically set for you on creation of a gls::texture are GL_TEXTURE_MIN_FILTER and GL_TEXTURE_MAG_FILTER. They are both set to GL_LINEAR by default, meaning OpenGL uses bilinear filtering when sampling from the texture. If you generate mipmaps, those parameters should be set to take them into account. Other common parameters include those that control how the texture is tiled or clamped when the sampler is passed certain texture coordinates in the shader.
To use a gls::texture, simply call bind(). It will bind the gls::texture to its target binding and replace any previously bound to that target. To clear the binding to that target, call unbind(). In newer OpenGL, textures are bound to texture units which are in turn used by the samplers within a shader to access texel data within them. The number of available texture units depends on the hardware.
Example usage:
texture | ( | ) |
Default constructor.
The constructor, after a name has been generated for the object, sets the GL_TEXTURE_MIN_FILTER and GL_TEXTURE_MAG_FILTER texture parameters to GL_LINEAR.
|
protected |
Constructor that doesn't set texture parameters.
Currently only used internally by gls::buffertexture.
GLuint name | ( | ) | const |
Retrieve the OpenGL name of this texture.
GLsizei width | ( | ) | const |
Retrieve the width of the level 0 image of the allocated texture storage.
GLsizei height | ( | ) | const |
Retrieve the height of the level 0 image of the allocated texture storage.
GLsizei depth | ( | ) | const |
Retrieve the depth of the level 0 image of the allocated texture storage.
void bind | ( | ) |
Bind this texture to its target.
Bind this texture to the target specified by the Target template parameter. This replaces any previous binding on that target.
|
static |
Unbind the current texture from the target.
Unbind the texture currently bound to the target specified by the Target template parameter.
void parameter | ( | GLenum | pname, |
GLfloat | param | ||
) |
Set a texture parameter.
Set the given parameter to the given value
pname | Name of the parameter to set |
param | Value to set the parameter to |
void parameter | ( | GLenum | pname, |
GLint | param | ||
) |
Set a texture parameter.
Set the given parameter to the given value
pname | Name of the parameter to set |
param | Value to set the parameter to |
void parameter | ( | GLenum | pname, |
const GLfloat * | param | ||
) |
Set a texture parameter.
Set the given parameter to the given value
pname | Name of the parameter to set |
param | Pointer to the value to set the parameter to |
void parameter | ( | GLenum | pname, |
const GLint * | param | ||
) |
Set a texture parameter.
Set the given parameter to the given value
pname | Name of the parameter to set |
param | Pointer to the value to set the parameter to |
void image_1d | ( | GLint | level, |
GLint | internal_format, | ||
T | the_width, | ||
GLenum | format, | ||
GLenum | type, | ||
const GLvoid * | data | ||
) |
Allocate storage for a 1D image and upload texture data.
This marks any previously allocated image storage for deletion by the GL.
level | The level of detail number, 0 is the base image, level n is the n-th mipmap |
internal_format | Internal format of the texture |
the_width | Width of the texture image |
format | Format of the data passed to this method |
type | Type of the data passed to this method |
data | Pointer to memory containing the data to upload |
void image_2d | ( | GLint | level, |
GLint | internal_format, | ||
T | the_width, | ||
U | the_height, | ||
GLenum | format, | ||
GLenum | type, | ||
const GLvoid * | data | ||
) |
Allocate storage for a 2D image and upload texture data.
This marks any previously allocated image storage for deletion by the GL.
level | The level of detail number, 0 is the base image, level n is the n-th mipmap |
internal_format | Internal format of the texture |
the_width | Width of the texture image |
the_height | Height of the texture image |
format | Format of the data passed to this method |
type | Type of the data passed to this method |
data | Pointer to memory containing the data to upload |
void image_3d | ( | GLint | level, |
GLint | internal_format, | ||
T | the_width, | ||
U | the_height, | ||
V | the_depth, | ||
GLenum | format, | ||
GLenum | type, | ||
const GLvoid * | data | ||
) |
Allocate storage for a 3D image and upload texture data.
This marks any previously allocated image storage for deletion by the GL.
level | The level of detail number, 0 is the base image, level n is the n-th mipmap |
internal_format | Internal format of the texture |
the_width | Width of the texture image |
the_height | Height of the texture image |
the_depth | Depth of the texture image |
format | Format of the data passed to this method |
type | Type of the data passed to this method |
data | Pointer to memory containing the data to upload |
void sub_image_1d | ( | GLint | level, |
T | xoffset, | ||
U | the_width, | ||
GLenum | format, | ||
GLenum | type, | ||
const GLvoid * | data | ||
) |
Update a section of a 1D image within the texture.
level | The level of detail number, 0 is the base image, level n is the n-th mipmap |
xoffset | x-offset of the region to update |
the_width | Width of the region to update |
format | Format of the data passed to this method |
type | Type of the data passed to this method |
data | Pointer to memory containing the data to upload |
void sub_image_2d | ( | GLint | level, |
T | xoffset, | ||
U | yoffset, | ||
V | the_width, | ||
W | the_height, | ||
GLenum | format, | ||
GLenum | type, | ||
const GLvoid * | data | ||
) |
Update a section of a 2D image within the texture.
level | The level of detail number, 0 is the base image, level n is the n-th mipmap |
xoffset | x-offset of the region to update |
yoffset | y-offset of the region to update |
the_width | Width of the region to update |
the_height | Height of the region to update |
format | Format of the data passed to this method |
type | Type of the data passed to this method |
data | Pointer to memory containing the data to upload |
void sub_image_3d | ( | GLint | level, |
T | xoffset, | ||
U | yoffset, | ||
V | zoffset, | ||
W | the_width, | ||
X | the_height, | ||
Y | the_depth, | ||
GLenum | format, | ||
GLenum | type, | ||
const GLvoid * | data | ||
) |
Update a section of a 3D image within the texture.
level | The level of detail number, 0 is the base image, level n is the n-th mipmap |
xoffset | x-offset of the region to update |
yoffset | y-offset of the region to update |
zoffset | z-offset of the region to update |
the_width | Width of the region to update |
the_height | Height of the region to update |
the_depth | Depth of the region to update |
format | Format of the data passed to this method |
type | Type of the data passed to this method |
data | Pointer to memory containing the data to upload |
void get_image | ( | GLint | level, |
GLint | format, | ||
GLenum | type, | ||
GLvoid * | img | ||
) |
Get image data from this texture.
level | The level of detail number, 0 is the base image, level n is the n-th mipmap |
format | Format of the returned data |
type | Type of the returned data |
img | Pointer to memory to write the image data to |
void generate_mipmap | ( | ) |
Generate mipmaps for this texture.