Implement a small texture wrapper.
Allows for RAII use of OpenGL textures.
This commit is contained in:
36
src/Texture.cpp
Normal file
36
src/Texture.cpp
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user