2021-12-23 03:19:13 +00:00
|
|
|
#include <lol/Texture.hpp>
|
|
|
|
|
|
|
|
#include <glad/glad.h>
|
|
|
|
|
2021-12-24 22:33:49 +00:00
|
|
|
#include <lol/Image.hpp>
|
|
|
|
|
2021-12-23 03:19:13 +00:00
|
|
|
namespace lol
|
|
|
|
{
|
2021-12-24 22:33:49 +00:00
|
|
|
Texture::Texture(const Image& image, TextureFormat texFormat) :
|
|
|
|
id(0)
|
|
|
|
{
|
|
|
|
glGenTextures(1, &id);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, id);
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
|
|
|
|
glm::uvec2 imageSize = image.GetDimensions();
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, NATIVE(texFormat), imageSize.x, imageSize.y, 0, NATIVE(image.GetPixelFormat()), NATIVE(image.GetPixelType()), image.GetPixels());
|
|
|
|
glGenerateMipmap(GL_TEXTURE_2D);
|
|
|
|
}
|
|
|
|
|
|
|
|
Texture::~Texture()
|
2021-12-23 03:19:13 +00:00
|
|
|
{
|
2021-12-24 22:33:49 +00:00
|
|
|
glDeleteTextures(1, &id);
|
|
|
|
}
|
2021-12-24 13:20:53 +00:00
|
|
|
|
2021-12-24 22:33:49 +00:00
|
|
|
void Texture::Bind()
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, id);
|
2021-12-24 13:20:53 +00:00
|
|
|
}
|
|
|
|
|
2021-12-24 22:33:49 +00:00
|
|
|
void Texture::Unbind()
|
2021-12-24 13:20:53 +00:00
|
|
|
{
|
2021-12-24 22:33:49 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2021-12-23 03:19:13 +00:00
|
|
|
}
|
|
|
|
}
|