From 393eba5f9f72fdec566b1d6771d40916793c2bc1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 16 Mar 2023 23:21:25 +0000 Subject: Allow specifiying the texture type/target --- gfx/models/texture.cpp | 16 ++++++++-------- gfx/models/texture.h | 2 ++ 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'gfx/models') diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp index 639ae0f..efc76e1 100644 --- a/gfx/models/texture.cpp +++ b/gfx/models/texture.cpp @@ -24,24 +24,24 @@ Texture::Texture(const Image & tex, TextureOptions to) : Texture::Texture(GLsizei width, GLsizei height, TextureOptions to) : Texture {width, height, nullptr, to} { } -Texture::Texture(GLsizei width, GLsizei height, const void * data, TextureOptions to) +Texture::Texture(GLsizei width, GLsizei height, const void * data, TextureOptions to) : type {to.type} { - glBindTexture(GL_TEXTURE_2D, m_texture); + glBindTexture(type, m_texture); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, to.wrap); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, to.wrap); + glTexParameteri(type, GL_TEXTURE_WRAP_S, to.wrap); + glTexParameteri(type, GL_TEXTURE_WRAP_T, to.wrap); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, to.minFilter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, to.magFilter); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); + glTexParameteri(type, GL_TEXTURE_MIN_FILTER, to.minFilter); + glTexParameteri(type, GL_TEXTURE_MAG_FILTER, to.magFilter); + glTexImage2D(type, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); } void Texture::bind(GLenum unit) const { glActiveTexture(unit); - glBindTexture(GL_TEXTURE_2D, m_texture); + glBindTexture(type, m_texture); } void diff --git a/gfx/models/texture.h b/gfx/models/texture.h index cc0c07e..ffc9a4a 100644 --- a/gfx/models/texture.h +++ b/gfx/models/texture.h @@ -11,6 +11,7 @@ class Image; struct TextureOptions { GLint wrap {GL_REPEAT}; GLint minFilter {GL_LINEAR}, magFilter {GL_LINEAR}; + GLenum type {GL_TEXTURE_2D}; }; class Texture { @@ -34,4 +35,5 @@ private: const char * path, short tgaFormat); glTexture m_texture; + GLenum type; }; -- cgit v1.2.3