From 995961c162b4e79c690f722c61c01165ef497e9f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 2 Sep 2024 20:49:04 +0100 Subject: Update Texture::getSize and ::size to account for the third texture dimension --- gfx/models/texture.cpp | 9 +++++---- gfx/models/texture.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'gfx') diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp index 51223aa..a508421 100644 --- a/gfx/models/texture.cpp +++ b/gfx/models/texture.cpp @@ -59,12 +59,13 @@ Texture::bind(GLenum unit) const glBindTexture(type, m_texture); } -TextureAbsCoord +TextureDimensions Texture::getSize(const glTexture & texture) { - TextureAbsCoord size; + TextureDimensions size {}; glGetTextureLevelParameteriv(texture, 0, GL_TEXTURE_WIDTH, &size.x); glGetTextureLevelParameteriv(texture, 0, GL_TEXTURE_HEIGHT, &size.y); + glGetTextureLevelParameteriv(texture, 0, GL_TEXTURE_DEPTH, &size.z); return size; } @@ -73,7 +74,7 @@ Texture::save( const glTexture & texture, GLenum format, GLenum type, uint8_t channels, const char * path, uint8_t tgaFormat) { const auto size = getSize(texture); - const size_t dataSize = (static_cast(size.x * size.y * channels)); + const size_t dataSize = (static_cast(size.x * size.y * size.z * channels)); const size_t fileSize = dataSize + sizeof(TGAHead); filesystem::fh out {path, O_RDWR | O_CREAT, 0660}; @@ -81,7 +82,7 @@ Texture::save( auto tga = out.mmap(fileSize, 0, PROT_WRITE, MAP_SHARED); *tga.get() = { .format = tgaFormat, - .size = size, + .size = {size.x, size.y * size.z}, .pixelDepth = static_cast(8 * channels), }; glPixelStorei(GL_PACK_ALIGNMENT, 1); diff --git a/gfx/models/texture.h b/gfx/models/texture.h index 8cb8128..3329511 100644 --- a/gfx/models/texture.h +++ b/gfx/models/texture.h @@ -41,7 +41,7 @@ public: protected: static void save(const glTexture &, GLenum, GLenum, uint8_t channels, const char * path, uint8_t tgaFormat); - static TextureAbsCoord getSize(const glTexture &); + static TextureDimensions getSize(const glTexture &); glTexture m_texture; GLenum type; -- cgit v1.2.3