7 #include <gls/headercheck.hpp>
8 #include <gls/errorcheck.hpp>
9 #include <gls/objects/object.hpp>
15 void gen_textures( GLsizei size, GLuint* name ) { glGenTextures( size, name ); }
16 void delete_textures( GLsizei size,
const GLuint* name ) { glDeleteTextures( size, name ); }
25 template<GLenum Target = GL_TEXTURE_2D>
37 parameter( GL_TEXTURE_MIN_FILTER, GL_LINEAR );
38 parameter( GL_TEXTURE_MAG_FILTER, GL_LINEAR );
48 return m_object.name();
89 check_gl_error( glBindTexture( Target, m_object.name() ) );
100 check_gl_error( glBindTexture( Target, 0 ) );
114 check_gl_error( glTexParameterf( Target, pname, param ) );
129 check_gl_error( glTexParameteri( Target, pname, param ) );
144 check_gl_error( glTexParameterfv( Target, pname, param ) );
159 check_gl_error( glTexParameteriv( Target, pname, param ) );
177 void image_1d( GLint level, GLint internal_format, T the_width, GLenum format, GLenum type,
const GLvoid* data ) {
178 m_width =
static_cast<GLsizei
>( the_width );
180 check_gl_error( glTexImage1D( Target, level, internal_format, m_width, 0, format, type, data ) );
198 template<
typename T,
typename U>
199 void image_2d( GLint level, GLint internal_format, T the_width, U the_height, GLenum format, GLenum type,
const GLvoid* data ) {
200 m_width =
static_cast<GLsizei
>( the_width );
201 m_height =
static_cast<GLsizei
>( the_height );
203 check_gl_error( glTexImage2D( Target, level, internal_format, m_width, m_height, 0, format, type, data ) );
222 template<
typename T,
typename U,
typename V>
223 void image_3d( GLint level, GLint internal_format, T the_width, U the_height, V the_depth, GLenum format, GLenum type,
const GLvoid* data ) {
224 m_width =
static_cast<GLsizei
>( the_width );
225 m_height =
static_cast<GLsizei
>( the_height );
226 m_depth =
static_cast<GLsizei
>( the_depth );
228 check_gl_error( glTexImage3D( Target, level, internal_format, m_width, m_height, m_depth, 0, format, type, data ) );
243 template<
typename T,
typename U>
244 void sub_image_1d( GLint level, T xoffset, U the_width, GLenum format, GLenum type,
const GLvoid* data ) {
245 assert( xoffset + the_width < m_width );
247 check_gl_error( glTexSubImage1D( Target, level, static_cast<GLint>( xoffset ), static_cast<GLsizei>( the_width ), format, type, data ) );
264 template<
typename T,
typename U,
typename V,
typename W>
265 void sub_image_2d( GLint level, T xoffset, U yoffset, V the_width, W the_height, GLenum format, GLenum type,
const GLvoid* data ) {
266 assert( xoffset + the_width < m_width );
267 assert( yoffset + the_height < m_height );
269 check_gl_error( glTexSubImage2D( Target, level, static_cast<GLint>( xoffset ), static_cast<GLint>( yoffset ), static_cast<GLsizei>( the_width ), static_cast<GLsizei>( the_height ), format, type, data ) );
288 template<
typename T,
typename U,
typename V,
typename W,
typename X,
typename Y>
289 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 ) {
290 assert( xoffset + the_width < m_width );
291 assert( yoffset + the_height < m_height );
292 assert( zoffset + the_depth < m_depth );
294 check_gl_error( glTexSubImage3D( Target, level, static_cast<GLint>( xoffset ), static_cast<GLint>( yoffset ), static_cast<GLint>( zoffset ), static_cast<GLsizei>( the_width ), static_cast<GLsizei>( the_height ), static_cast<GLsizei>( the_depth ), format, type, data ) );
307 void get_image( GLint level, GLint format, GLenum type, GLvoid* img ) {
309 check_gl_error( glGetTexImage( Target, level, format, type, img ) );
319 check_gl_error( glGenerateMipmap( Target ) );
336 GLsizei m_height = 0;
void parameter(GLenum pname, GLint param)
Set a texture parameter.
Definition: texture.hpp:127
void parameter(GLenum pname, GLfloat param)
Set a texture parameter.
Definition: texture.hpp:112
GLuint name() const
Retrieve the OpenGL name of this texture.
Definition: texture.hpp:47
GLsizei height() const
Retrieve the height of the level 0 image of the allocated texture storage.
Definition: texture.hpp:67
void get_image(GLint level, GLint format, GLenum type, GLvoid *img)
Get image data from this texture.
Definition: texture.hpp:307
GLsizei width() const
Retrieve the width of the level 0 image of the allocated texture storage.
Definition: texture.hpp:57
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.
Definition: texture.hpp:289
void parameter(GLenum pname, const GLint *param)
Set a texture parameter.
Definition: texture.hpp:157
void generate_mipmap()
Generate mipmaps for this texture.
Definition: texture.hpp:317
GLsizei depth() const
Retrieve the depth of the level 0 image of the allocated texture storage.
Definition: texture.hpp:77
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.
Definition: texture.hpp:199
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.
Definition: texture.hpp:223
texture(int)
Constructor that doesn't set texture parameters.
Definition: texture.hpp:330
static void unbind()
Unbind the current texture from the target.
Definition: texture.hpp:99
void bind()
Bind this texture to its target.
Definition: texture.hpp:88
texture()
Default constructor.
Definition: texture.hpp:36
Definition: buffer.hpp:12
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.
Definition: texture.hpp:177
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.
Definition: texture.hpp:244
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.
Definition: texture.hpp:265
Class encapsulating an OpenGL texture object.
Definition: texture.hpp:26
void parameter(GLenum pname, const GLfloat *param)
Set a texture parameter.
Definition: texture.hpp:142