diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-14 01:54:19 +0100 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-14 01:54:19 +0100 | 
| commit | 0638aaaf2a60efae95a1b404d7eee29e894047bc (patch) | |
| tree | cf66983319dfde55c6f34e279d1260744ea843d9 /gfx/models | |
| parent | Extend timeout... this can be a bit slow now (diff) | |
| download | ilt-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')
| -rw-r--r-- | gfx/models/texture.cpp | 30 | ||||
| -rw-r--r-- | gfx/models/texture.h | 12 | 
2 files changed, 26 insertions, 16 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;
 | 
