Implement a small texture wrapper.

Allows for RAII use of OpenGL textures.
This commit is contained in:
2018-02-25 19:03:10 +01:00
parent 23ae9717ea
commit 17d4e07025
6 changed files with 89 additions and 13 deletions

36
src/Texture.cpp Normal file
View File

@@ -0,0 +1,36 @@
#include <algorithm>
#include "Texture.hpp"
using namespace fmri;
Texture::Texture() noexcept
{
glGenTextures(1, &id);
}
Texture::Texture(GLuint id) noexcept : id(id)
{
}
Texture::~Texture()
{
if (id != 0) {
glDeleteTextures(1, &id);
}
}
Texture &Texture::operator=(Texture && other) noexcept
{
std::swap(id, other.id);
return *this;
}
Texture::Texture(Texture && other) noexcept
{
std::swap(id, other.id);
}
void Texture::bind(GLenum target) const
{
glBindTexture(target, id);
}