84 lines
1.6 KiB
C++
84 lines
1.6 KiB
C++
#include <psemek/gfx/texture.hpp>
|
|
|
|
namespace psemek::gfx
|
|
{
|
|
|
|
texture_2d::texture_2d()
|
|
{
|
|
gl::GenTextures(1, &id_);
|
|
}
|
|
|
|
texture_2d::texture_2d(GLuint id)
|
|
: id_(id)
|
|
{}
|
|
|
|
texture_2d texture_2d::null()
|
|
{
|
|
return texture_2d(0);
|
|
}
|
|
|
|
void texture_2d::bind() const
|
|
{
|
|
gl::BindTexture(gl::TEXTURE_2D, id_);
|
|
}
|
|
|
|
texture_2d::texture_2d(texture_2d && other)
|
|
: id_(other.id_)
|
|
, width_(other.width_)
|
|
, height_(other.height_)
|
|
{
|
|
other.id_ = 0;
|
|
other.width_ = 0;
|
|
other.height_ = 0;
|
|
}
|
|
|
|
texture_2d & texture_2d::operator = (texture_2d && other)
|
|
{
|
|
if (this == &other) return *this;
|
|
|
|
gl::DeleteTextures(1, &id_);
|
|
id_ = other.id_;
|
|
width_ = other.width_;
|
|
height_ = other.height_;
|
|
other.id_ = 0;
|
|
other.width_ = 0;
|
|
other.height_ = 0;
|
|
|
|
return *this;
|
|
}
|
|
|
|
texture_2d::~texture_2d()
|
|
{
|
|
gl::DeleteTextures(1, &id_);
|
|
}
|
|
|
|
void texture_2d::load(GLint internal_format, std::size_t width, std::size_t height, GLenum format, GLenum type, const void * data)
|
|
{
|
|
bind();
|
|
gl::TexImage2D(gl::TEXTURE_2D, 0, internal_format, width, height, 0, format, type, data);
|
|
gl::GenerateMipmap(gl::TEXTURE_2D);
|
|
|
|
width_ = width;
|
|
height_ = height;
|
|
}
|
|
|
|
void texture_2d::pixels(GLenum format, GLenum type, void * data) const
|
|
{
|
|
bind();
|
|
gl::GetTexImage(gl::TEXTURE_2D, 0, format, type, data);
|
|
}
|
|
|
|
texture_2d texture_2d::from_data(GLint internal_format, std::size_t width, std::size_t height, GLenum format, GLenum type, const void * data)
|
|
{
|
|
texture_2d tex;
|
|
tex.load(internal_format, width, height, format, type, data);
|
|
return tex;
|
|
}
|
|
|
|
void texture_2d::generate_mipmap()
|
|
{
|
|
bind();
|
|
gl::GenerateMipmap(gl::TEXTURE_2D);
|
|
}
|
|
|
|
}
|