#include "texture.h" #include #include #include #include Cache Texture::cachedTexture; Texture::Texture(const std::filesystem::path & fileName) : m_texture {} { const Image tex {Resource::mapPath(fileName).c_str(), STBI_rgb_alpha}; glGenTextures(1, &m_texture); glBindTexture(GL_TEXTURE_2D, m_texture); 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); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, static_cast(tex.width), static_cast(tex.height), 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.data.data()); } Texture::~Texture() { glDeleteTextures(1, &m_texture); } void Texture::Bind() const { glBindTexture(GL_TEXTURE_2D, m_texture); }