5 Texture::Texture(
const std::string& path)
8 , m_LocalBuffer(nullptr)
13 stbi_set_flip_vertically_on_load(0);
14 stbi_set_flip_vertically_on_load_thread(0);
15 m_LocalBuffer = stbi_load(path.c_str(), &m_Width, &m_Height, &m_BPP, 4);
17 GLCall(glGenTextures(1, &m_RendererID));
18 GLCall(glBindTexture(GL_TEXTURE_2D, m_RendererID));
20 GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
21 GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
22 GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
23 GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
25 GLCall(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
27 GLCall(glBindTexture(GL_TEXTURE_2D, 0));
31 stbi_image_free(m_LocalBuffer);
34 m_Name =
"Texture" + std::to_string(m_RendererID);
39 , m_LocalBuffer(nullptr)
44 GLCall(glGenTextures(1, &m_RendererID));
45 GLCall(glBindTexture(GL_TEXTURE_2D, m_RendererID));
47 GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
48 GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
49 GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
50 GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
52 GLCall(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
54 GLCall(glBindTexture(GL_TEXTURE_2D, 0));
59 GLCall(glDeleteTextures(1, &m_RendererID));
62 void Texture::Bind(
unsigned int slot)
const
64 GLCall(glActiveTexture(GL_TEXTURE0 + slot));
65 GLCall(glBindTexture(GL_TEXTURE_2D, m_RendererID));
68 void Texture::Unbind()
const
70 GLCall(glBindTexture(GL_TEXTURE_2D, 0));