From 1529d37d585ec38aee475519e444d2718a81fda5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 13 Apr 2023 02:10:44 +0100 Subject: Add TextureAtlas class as an extension of Texture --- gfx/models/texture.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'gfx/models/texture.h') diff --git a/gfx/models/texture.h b/gfx/models/texture.h index ffc9a4a..7900f17 100644 --- a/gfx/models/texture.h +++ b/gfx/models/texture.h @@ -16,6 +16,9 @@ struct TextureOptions { class Texture { public: + virtual ~Texture() = default; + DEFAULT_MOVE_NO_COPY(Texture); + explicit Texture(const std::filesystem::path & fileName, TextureOptions = {}); explicit Texture(const Image & image, TextureOptions = {}); explicit Texture(GLsizei width, GLsizei height, TextureOptions = {}); @@ -23,17 +26,29 @@ public: static Cache cachedTexture; - void bind(GLenum unit = GL_TEXTURE0) const; + 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); -private: +protected: static void save(const glTexture &, GLenum, GLenum, const glm::ivec2 & size, unsigned short channels, const char * path, short tgaFormat); glTexture m_texture; GLenum type; }; + +class TextureAtlas : public Texture { +public: + TextureAtlas(GLsizei width, GLsizei height, GLuint count); + + void bind(GLenum unit = GL_TEXTURE0) const override; + GLuint add(glm::ivec2 position, glm::ivec2 size, void * data, TextureOptions = {}); + +private: + glTexture m_atlas; + GLuint used {}; +}; -- cgit v1.2.3 From 0638aaaf2a60efae95a1b404d7eee29e894047bc Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Apr 2023 01:54:19 +0100 Subject: No need to pass size around, we can get it back from the texture --- gfx/models/texture.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'gfx/models/texture.h') 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; -- cgit v1.2.3 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.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gfx/models/texture.h') diff --git a/gfx/models/texture.h b/gfx/models/texture.h index f4e1476..68ec649 100644 --- a/gfx/models/texture.h +++ b/gfx/models/texture.h @@ -34,7 +34,7 @@ public: static void saveNormal(const glTexture &, const char * path); protected: - static void save(const glTexture &, GLenum, GLenum, unsigned short channels, const char * path, short tgaFormat); + static void save(const glTexture &, GLenum, GLenum, uint8_t channels, const char * path, uint8_t tgaFormat); static glm::ivec2 getSize(const glTexture &); glTexture m_texture; -- cgit v1.2.3 From b4ede2fd89d0effb44ebae15862427de9a147476 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Apr 2023 16:34:56 +0100 Subject: Define our own enum for texture mapmode --- gfx/models/texture.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'gfx/models/texture.h') diff --git a/gfx/models/texture.h b/gfx/models/texture.h index 68ec649..86e76a0 100644 --- a/gfx/models/texture.h +++ b/gfx/models/texture.h @@ -9,9 +9,16 @@ class Image; struct TextureOptions { - GLint wrap {GL_REPEAT}; + enum class MapMode { + Repeat, + Clamp, + Mirror, + Decal, + }; + MapMode wrapU {MapMode::Repeat}, wrapV {MapMode::Repeat}; GLint minFilter {GL_LINEAR}, magFilter {GL_LINEAR}; GLenum type {GL_TEXTURE_2D}; + static GLint glMapMode(MapMode); }; class Texture { -- cgit v1.2.3