From ee1912e4f181594df40203f9c227b89d02a91242 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 15 Mar 2023 01:04:05 +0000 Subject: Add support for setting Texture options on construction --- gfx/models/texture.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'gfx/models/texture.cpp') diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp index ef6d7e7..87b73e7 100644 --- a/gfx/models/texture.cpp +++ b/gfx/models/texture.cpp @@ -12,26 +12,28 @@ Cache Texture::cachedTexture; -Texture::Texture(const std::filesystem::path & fileName) : - Texture {Image {Resource::mapPath(fileName).c_str(), STBI_rgb_alpha}} +Texture::Texture(const std::filesystem::path & fileName, TextureOptions to) : + Texture {Image {Resource::mapPath(fileName).c_str(), STBI_rgb_alpha}, to} { } -Texture::Texture(const Image & tex) : - Texture {static_cast(tex.width), static_cast(tex.height), tex.data.data()} +Texture::Texture(const Image & tex, TextureOptions to) : + Texture {static_cast(tex.width), static_cast(tex.height), tex.data.data(), to} { } -Texture::Texture(GLsizei width, GLsizei height, const void * data) +Texture::Texture(GLsizei width, GLsizei height, TextureOptions to) : Texture {width, height, nullptr, to} { } + +Texture::Texture(GLsizei width, GLsizei height, const void * data, TextureOptions to) { glBindTexture(GL_TEXTURE_2D, m_texture); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - 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_WRAP_S, to.wrap); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, to.wrap); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + 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); } -- cgit v1.2.3 From 5d7bb934068b0f2ce8b6315517a005cc2c1305f5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 15 Mar 2023 02:08:43 +0000 Subject: Texture member to save the texture as a TGA --- gfx/models/texture.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gfx/models/texture.cpp') diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp index 87b73e7..639ae0f 100644 --- a/gfx/models/texture.cpp +++ b/gfx/models/texture.cpp @@ -62,6 +62,12 @@ Texture::save(const glTexture & texture, GLenum format, GLenum type, const glm:: tga.msync(MS_ASYNC); } +void +Texture::save(const glm::ivec2 & size, const char * path) const +{ + save(m_texture, GL_BGR, GL_UNSIGNED_BYTE, size, 3, path, 2); +} + void Texture::save(const glTexture & texture, const glm::ivec2 & size, const char * path) { -- cgit v1.2.3 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 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'gfx/models/texture.cpp') 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 -- cgit v1.2.3