summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gfx/models/texture.cpp30
-rw-r--r--gfx/models/texture.h12
-rw-r--r--test/test-assetFactory.cpp2
-rw-r--r--test/test-render.cpp6
4 files changed, 30 insertions, 20 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, {})
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;
diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp
index 4fde5ed..59dc40d 100644
--- a/test/test-assetFactory.cpp
+++ b/test/test-assetFactory.cpp
@@ -32,7 +32,7 @@ public:
glDisable(GL_DEBUG_OUTPUT);
auto outpath = (TMP / boost::unit_test::framework::current_test_case().full_name()).replace_extension(".tga");
std::filesystem::create_directories(outpath.parent_path());
- Texture::save(outImage, size, outpath.c_str());
+ Texture::save(outImage, outpath.c_str());
}
void
content(const SceneShader & shader) const override
diff --git a/test/test-render.cpp b/test/test-render.cpp
index 7771760..8c6b31c 100644
--- a/test/test-render.cpp
+++ b/test/test-render.cpp
@@ -73,7 +73,7 @@ BOOST_AUTO_TEST_CASE(basic)
const TestScene scene;
ss.render(scene);
glDisable(GL_DEBUG_OUTPUT);
- Texture::save(outImage, size, "/tmp/basic.tga");
+ Texture::save(outImage, "/tmp/basic.tga");
}
BOOST_AUTO_TEST_CASE(pointlight)
@@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE(pointlight)
const PointLightScene scene;
ss.render(scene);
glDisable(GL_DEBUG_OUTPUT);
- Texture::save(outImage, size, "/tmp/pointlight.tga");
+ Texture::save(outImage, "/tmp/pointlight.tga");
}
BOOST_AUTO_TEST_CASE(spotlight)
@@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(spotlight)
const PointLightScene scene;
ss.render(scene);
glDisable(GL_DEBUG_OUTPUT);
- Texture::save(outImage, size, "/tmp/spotlight.tga");
+ Texture::save(outImage, "/tmp/spotlight.tga");
}
BOOST_AUTO_TEST_SUITE_END();