glpp::core::object::texture_t class

storage class for OpenGL textures

texture_t is a storage class for OpenGL textures. It creates, owns and destroys the related OpenGL texture object and provides a typesafe interface to corresponding the OpenGL calls.

Constructors, destructors, conversion operators

texture_t(texture_t&& mov) defaulted
move constructor
texture_t(const texture_t& cpy) deleted
copy constructor
texture_t(const size_t width, const size_t height, image_format_t format = image_format_t::rgb_8, const clamp_mode_t clamp_mode = clamp_mode_t::repeat, const filter_mode_t filter = filter_mode_t::linear, const mipmap_mode_t mipmap_mode = mipmap_mode_t::none, swizzle_mask_t swizzle_mask = {texture_channel_t::red, texture_channel_t::green, texture_channel_t::blue, texture_channel_t::alpha})
constuct empty texture with given parameters
template<class T>
texture_t(const image_t<T>& image, image_format_t format = image_format_t::preferred, const clamp_mode_t clamp_mode = clamp_mode_t::repeat, const filter_mode_t filter = filter_mode_t::linear, const mipmap_mode_t mipmap_mode = mipmap_mode_t::none, swizzle_mask_t swizzle_mask = {texture_channel_t::red, texture_channel_t::green, texture_channel_t::blue, texture_channel_t::alpha})
constuct texture with given parameters from a image_t object

Public functions

auto bind_to_texture_slot() const -> texture_slot_t
bind texture to the next free texture unit
auto height() const -> size_t
getter function for texture height
auto operator=(texture_t&& mov) -> texture_t& defaulted
move assignment operator
auto operator=(const texture_t& cpy) -> texture_t& deleted
copy assignment operator
template<class T>
void update(const T* pixels, image_format_t format = image_format_t::preferred)
update pixel data of the whole texture
template<class T>
void update(size_t xoffset, size_t yoffset, size_t width, size_t height, const T* pixels, image_format_t format = image_format_t::preferred)
update pixel data of rectangular part of the texture
template<class T>
void update(const image_t<T>& image)
update pixel data of the whole texture
template<class T>
void update(const image_t<T>& image, size_t xoffset, size_t yoffset, size_t width, size_t height)
update pixel data of a part of the texture
auto width() const -> size_t
getter function for texture width

Function documentation

glpp::core::object::texture_t::texture_t(texture_t&& mov) defaulted

move constructor

texture_t is move constructible.

glpp::core::object::texture_t::texture_t(const texture_t& cpy) deleted

copy constructor

texture_t is not copy constructible.

glpp::core::object::texture_t::texture_t(const size_t width, const size_t height, image_format_t format = image_format_t::rgb_8, const clamp_mode_t clamp_mode = clamp_mode_t::repeat, const filter_mode_t filter = filter_mode_t::linear, const mipmap_mode_t mipmap_mode = mipmap_mode_t::none, swizzle_mask_t swizzle_mask = {texture_channel_t::red, texture_channel_t::green, texture_channel_t::blue, texture_channel_t::alpha})

constuct empty texture with given parameters

Parameters
width [in] width of texture in pixels
height [in] height of texture in pixels
format [in] pixel format representation. format must not be image_format_t::preferred.
clamp_mode [in] clamp mode of texture
filter [in] filter mode of texture
mipmap_mode [in] mipmap mode of texture
swizzle_mask [in] swizzle mask of texture

This constructor will create an OpenGL texture object with the given parameters and allocate memory for the pixel data in the given format. The provided format parameter must not be equal to image_format_t::preferred in this constructor. The swizzle mask can be used to change the color channels in the glsl sampler.

template<class T>
glpp::core::object::texture_t::texture_t(const image_t<T>& image, image_format_t format = image_format_t::preferred, const clamp_mode_t clamp_mode = clamp_mode_t::repeat, const filter_mode_t filter = filter_mode_t::linear, const mipmap_mode_t mipmap_mode = mipmap_mode_t::none, swizzle_mask_t swizzle_mask = {texture_channel_t::red, texture_channel_t::green, texture_channel_t::blue, texture_channel_t::alpha})

constuct texture with given parameters from a image_t object

Parameters
image [in] image_t object to construct a texture from.
format [in] pixel format representation. If image_format_t::preferred is selected the pixel format of image_t will be used.
clamp_mode [in] clamp mode of texture
filter [in] filter mode of texture
mipmap_mode [in] mipmap mode of texture
swizzle_mask [in] swizzle mask of texture

This constructor will create an OpenGL texture object with the given parameters and allocate memory for the pixel data in the given format. The width and height of the texture will match the width and height of the image_t object. The pixel data will be copied to gpu memory from the image_t object. If the pixel format of the texture and the image_t do not match, the pixel data will be converted in the requested format. The swizzle mask can be used to change the color channels in the glsl sampler.

texture_slot_t glpp::core::object::texture_t::bind_to_texture_slot() const

bind texture to the next free texture unit

Returns texture_slot_t object representing the binding

This function will bind the texture to the next free texture unit. If there is no more free texture unit to bind to, the function will throw a std::runtime_error.

size_t glpp::core::object::texture_t::height() const

getter function for texture height

Returns height of the texture in pixels

texture_t& glpp::core::object::texture_t::operator=(texture_t&& mov) defaulted

move assignment operator

texture_t is move assignable.

texture_t& glpp::core::object::texture_t::operator=(const texture_t& cpy) deleted

copy assignment operator

texture_t is not copy assignable.

template<class T>
void glpp::core::object::texture_t::update(const T* pixels, image_format_t format = image_format_t::preferred)

update pixel data of the whole texture

Parameters
pixels [in] new pixel data
format [in] format of provided pixel data

This function will update the pixel data of the texture with the one provided as first argument. The pixel data given will be interpreted with the given pixel format.

template<class T>
void glpp::core::object::texture_t::update(size_t xoffset, size_t yoffset, size_t width, size_t height, const T* pixels, image_format_t format = image_format_t::preferred)

update pixel data of rectangular part of the texture

Parameters
xoffset [in] offset of the the subtexture from the left
yoffset [in] offset of the subtexture from the top
width [in] width of the subtexture
height [in] height of the subtexture
pixels [in] new pixel data
format [in] format of provided pixel data

This function will update the pixel data of the texture with the one provided as argument. The pixel data given will be interpreted with the given pixel format.

template<class T>
void glpp::core::object::texture_t::update(const image_t<T>& image)

update pixel data of the whole texture

Parameters
image [in] new pixel data

This function will update the pixel data of the texture with the the pixel data of the provided image_t object.

template<class T>
void glpp::core::object::texture_t::update(const image_t<T>& image, size_t xoffset, size_t yoffset, size_t width, size_t height)

update pixel data of a part of the texture

Parameters
image [in] new pixel data
xoffset [in] offset of the the subtexture from the left
yoffset [in] offset of the subtexture from the top
width [in] width of the subtexture
height [in] height of the subtexture

This function will update the pixel data of the texture with the the pixel data of the provided image_t object.

size_t glpp::core::object::texture_t::width() const

getter function for texture width

Returns width of the texture in pixels