From 0638aaaf2a60efae95a1b404d7eee29e894047bc Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Apr 2023 01:54:19 +0100 Subject: No need to pass size around, we can get it back from the texture --- gfx/models/texture.cpp | 30 ++++++++++++++++++++---------- gfx/models/texture.h | 12 ++++++------ 2 files changed, 26 insertions(+), 16 deletions(-) (limited to 'gfx/models') diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp index a500fed..ab256d5 100644 --- a/gfx/models/texture.cpp +++ b/gfx/models/texture.cpp @@ -44,12 +44,22 @@ Texture::bind(GLenum unit) const glBindTexture(type, m_texture); } +glm::ivec2 +Texture::getSize(const glTexture & texture) +{ + glm::ivec2 size; + glGetTextureLevelParameteriv(texture, 0, GL_TEXTURE_WIDTH, &size.x); + glGetTextureLevelParameteriv(texture, 0, GL_TEXTURE_HEIGHT, &size.y); + return size; +} + void -Texture::save(const glTexture & texture, GLenum format, GLenum type, const glm::ivec2 & size, unsigned short channels, - const char * path, short tgaFormat) +Texture::save(const glTexture & texture, GLenum format, GLenum type, unsigned short channels, const char * path, + short tgaFormat) { using TGAHead = std::array; + const auto size = getSize(texture); const size_t dataSize = (static_cast(size.x * size.y * channels)); const size_t fileSize = dataSize + sizeof(TGAHead); @@ -63,27 +73,27 @@ Texture::save(const glTexture & texture, GLenum format, GLenum type, const glm:: } void -Texture::save(const glm::ivec2 & size, const char * path) const +Texture::save(const char * path) const { - save(m_texture, GL_BGR, GL_UNSIGNED_BYTE, size, 3, path, 2); + save(m_texture, GL_BGR, GL_UNSIGNED_BYTE, 3, path, 2); } void -Texture::save(const glTexture & texture, const glm::ivec2 & size, const char * path) +Texture::save(const glTexture & texture, const char * path) { - save(texture, GL_BGR, GL_UNSIGNED_BYTE, size, 3, path, 2); + save(texture, GL_BGR, GL_UNSIGNED_BYTE, 3, path, 2); } void -Texture::saveDepth(const glTexture & texture, const glm::ivec2 & size, const char * path) +Texture::saveDepth(const glTexture & texture, const char * path) { - save(texture, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, size, 1, path, 3); + save(texture, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 1, path, 3); } void -Texture::saveNormal(const glTexture & texture, const glm::ivec2 & size, const char * path) +Texture::saveNormal(const glTexture & texture, const char * path) { - save(texture, GL_BGR, GL_BYTE, size, 3, path, 2); + save(texture, GL_BGR, GL_BYTE, 3, path, 2); } TextureAtlas::TextureAtlas(GLsizei width, GLsizei height, GLuint count) : Texture(width, height, nullptr, {}) diff --git a/gfx/models/texture.h b/gfx/models/texture.h index 7900f17..f4e1476 100644 --- a/gfx/models/texture.h +++ b/gfx/models/texture.h @@ -28,14 +28,14 @@ public: virtual void bind(GLenum unit = GL_TEXTURE0) const; - void save(const glm::ivec2 & size, const char * path) const; - static void save(const glTexture &, const glm::ivec2 & size, const char * path); - static void saveDepth(const glTexture &, const glm::ivec2 & size, const char * path); - static void saveNormal(const glTexture &, const glm::ivec2 & size, const char * path); + void save(const char * path) const; + static void save(const glTexture &, const char * path); + static void saveDepth(const glTexture &, const char * path); + static void saveNormal(const glTexture &, const char * path); protected: - static void save(const glTexture &, GLenum, GLenum, const glm::ivec2 & size, unsigned short channels, - const char * path, short tgaFormat); + static void save(const glTexture &, GLenum, GLenum, unsigned short channels, const char * path, short tgaFormat); + static glm::ivec2 getSize(const glTexture &); glTexture m_texture; GLenum type; -- cgit v1.2.3