diff options
Diffstat (limited to 'gfx')
-rw-r--r-- | gfx/gl/shadowMapper.cpp | 1 | ||||
-rw-r--r-- | gfx/models/texture.cpp | 23 | ||||
-rw-r--r-- | gfx/models/texture.h | 4 |
3 files changed, 23 insertions, 5 deletions
diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp index a74f3dd..1169524 100644 --- a/gfx/gl/shadowMapper.cpp +++ b/gfx/gl/shadowMapper.cpp @@ -51,7 +51,6 @@ ShadowMapper::update(const SceneProvider & scene, const glm::vec3 & dir) const scene.shadows(*this); glCullFace(GL_BACK); - // Texture::saveDepth(depthMap, size, "/tmp/depth.tga"); return lightViewProjection; } diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp index 313b3fa..645920f 100644 --- a/gfx/models/texture.cpp +++ b/gfx/models/texture.cpp @@ -41,15 +41,30 @@ Texture::bind(GLenum unit) const }
void
-Texture::save(const glTexture & texture, const glm::ivec2 & size, const char * path)
+Texture::save(const glTexture & texture, GLenum format, const glm::ivec2 & size, unsigned short channels,
+ const char * path, short tgaFormat)
{
- std::vector<unsigned char> buffer(static_cast<size_t>(size.x * size.y * 3));
- glGetTextureImage(texture, 0, GL_BGR, GL_UNSIGNED_BYTE, static_cast<GLsizei>(buffer.size()), buffer.data());
+ using PixelData = std::vector<unsigned char>;
+ PixelData buffer(static_cast<size_t>(size.x * size.y * channels));
+ glGetTextureImage(texture, 0, format, GL_UNSIGNED_BYTE, static_cast<GLsizei>(buffer.size()), buffer.data());
auto out = open(path, O_WRONLY | O_CREAT, 0660);
- short TGAhead[] = {0, 2, 0, 0, 0, 0, static_cast<short>(size.x), static_cast<short>(size.y), 24};
+ const short TGAhead[] = {0, tgaFormat, 0, 0, 0, 0, static_cast<short>(size.x), static_cast<short>(size.y),
+ static_cast<short>(8 * channels)};
std::ignore = write(out, &TGAhead, sizeof(TGAhead));
std::ignore = write(out, buffer.data(), buffer.size());
std::ignore = ftruncate(out, static_cast<off_t>(buffer.size() + sizeof(TGAhead)));
close(out);
}
+
+void
+Texture::save(const glTexture & texture, const glm::ivec2 & size, const char * path)
+{
+ save(texture, GL_BGR, size, 3, path, 2);
+}
+
+void
+Texture::saveDepth(const glTexture & texture, const glm::ivec2 & size, const char * path)
+{
+ save(texture, GL_DEPTH_COMPONENT, size, 1, path, 3);
+}
diff --git a/gfx/models/texture.h b/gfx/models/texture.h index 09538b3..de532a5 100644 --- a/gfx/models/texture.h +++ b/gfx/models/texture.h @@ -19,7 +19,11 @@ public: void bind(GLenum unit = GL_TEXTURE0) 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);
private:
+ static void save(const glTexture &, GLenum, const glm::ivec2 & size, unsigned short channels, const char * path,
+ short tgaFormat);
+
glTexture m_texture;
};
|