diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-09-02 20:49:04 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-09-02 20:49:04 +0100 |
commit | 995961c162b4e79c690f722c61c01165ef497e9f (patch) | |
tree | 1066950804f4c94d1be0705e19d2eedfa803a256 /gfx/models/texture.cpp | |
parent | Add TextureDimensions type (diff) | |
download | ilt-995961c162b4e79c690f722c61c01165ef497e9f.tar.bz2 ilt-995961c162b4e79c690f722c61c01165ef497e9f.tar.xz ilt-995961c162b4e79c690f722c61c01165ef497e9f.zip |
Update Texture::getSize and ::size to account for the third texture dimension
Diffstat (limited to 'gfx/models/texture.cpp')
-rw-r--r-- | gfx/models/texture.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
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_t>(size.x * size.y * channels)); + const size_t dataSize = (static_cast<size_t>(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<TGAHead>() = { .format = tgaFormat, - .size = size, + .size = {size.x, size.y * size.z}, .pixelDepth = static_cast<uint8_t>(8 * channels), }; glPixelStorei(GL_PACK_ALIGNMENT, 1); |