summaryrefslogtreecommitdiff
path: root/gfx/models/texture.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-04-14 01:54:19 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-04-14 01:54:19 +0100
commit0638aaaf2a60efae95a1b404d7eee29e894047bc (patch)
treecf66983319dfde55c6f34e279d1260744ea843d9 /gfx/models/texture.cpp
parentExtend timeout... this can be a bit slow now (diff)
downloadilt-0638aaaf2a60efae95a1b404d7eee29e894047bc.tar.bz2
ilt-0638aaaf2a60efae95a1b404d7eee29e894047bc.tar.xz
ilt-0638aaaf2a60efae95a1b404d7eee29e894047bc.zip
No need to pass size around, we can get it back from the texture
Diffstat (limited to 'gfx/models/texture.cpp')
-rw-r--r--gfx/models/texture.cpp30
1 files changed, 20 insertions, 10 deletions
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<short, 9>;
+ const auto size = getSize(texture);
const size_t dataSize = (static_cast<size_t>(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, {})