From b0d2ef2b93f9f5ce5fb1c54748a95fefe8484161 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Fri, 8 Jan 2021 01:51:34 +0100 Subject: [PATCH] Add setting texture unit in bind() --- inferno/src/inferno/render/texture.cpp | 8 +++++++- inferno/src/inferno/render/texture.h | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/inferno/src/inferno/render/texture.cpp b/inferno/src/inferno/render/texture.cpp index 4ee7710..f1c14a8 100644 --- a/inferno/src/inferno/render/texture.cpp +++ b/inferno/src/inferno/render/texture.cpp @@ -45,9 +45,15 @@ namespace Inferno { glDeleteTextures(1, &m_id); } - void Texture::bind() const + void Texture::bind(uint32_t unit) const { + // Set active unit + glActiveTexture(GL_TEXTURE0 + unit); + glBindTexture(GL_TEXTURE_2D, m_id); + + // Reset unit + glActiveTexture(GL_TEXTURE0); } void Texture::unbind() const diff --git a/inferno/src/inferno/render/texture.h b/inferno/src/inferno/render/texture.h index 8751144..7f9996b 100644 --- a/inferno/src/inferno/render/texture.h +++ b/inferno/src/inferno/render/texture.h @@ -13,7 +13,7 @@ namespace Inferno { Texture(const std::string& path); virtual ~Texture(); - void bind() const; + void bind(uint32_t unit = 0) const; void unbind() const; inline std::string path() const { return m_path; }