From c44e7537d027cba66abe564b247549040426ebfe Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Apr 2023 02:56:33 +0100 Subject: Externalise a neater definition of TGAHead --- gfx/models/texture.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'gfx/models/texture.cpp') diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp index ab256d5..3b27e77 100644 --- a/gfx/models/texture.cpp +++ b/gfx/models/texture.cpp @@ -1,5 +1,6 @@ #include "texture.h" #include "glArrays.h" +#include "tga.h" #include #include #include @@ -54,11 +55,9 @@ Texture::getSize(const glTexture & texture) } void -Texture::save(const glTexture & texture, GLenum format, GLenum type, unsigned short channels, const char * path, - short tgaFormat) +Texture::save( + const glTexture & texture, GLenum format, GLenum type, uint8_t channels, const char * path, uint8_t 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); @@ -66,8 +65,11 @@ Texture::save(const glTexture & texture, GLenum format, GLenum type, unsigned sh filesystem::fh out {path, O_RDWR | O_CREAT, 0660}; out.truncate(fileSize); auto tga = out.mmap(fileSize, 0, PROT_WRITE, MAP_SHARED); - *tga.get() = {0, tgaFormat, 0, 0, 0, 0, static_cast(size.x), static_cast(size.y), - static_cast(8 * channels)}; + *tga.get() = { + .format = tgaFormat, + .size = size, + .pixelDepth = static_cast(8 * channels), + }; glGetTextureImage(texture, 0, format, type, static_cast(dataSize), tga.get() + 1); tga.msync(MS_ASYNC); } -- cgit v1.2.3