diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-03-15 01:04:05 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-03-15 01:04:05 +0000 |
commit | ee1912e4f181594df40203f9c227b89d02a91242 (patch) | |
tree | 789ac0d91c9b0a83e90c4bc988209e707724641c /gfx | |
parent | Support creating a super texture from fragments (diff) | |
download | ilt-ee1912e4f181594df40203f9c227b89d02a91242.tar.bz2 ilt-ee1912e4f181594df40203f9c227b89d02a91242.tar.xz ilt-ee1912e4f181594df40203f9c227b89d02a91242.zip |
Add support for setting Texture options on construction
Diffstat (limited to 'gfx')
-rw-r--r-- | gfx/models/texture.cpp | 20 | ||||
-rw-r--r-- | gfx/models/texture.h | 12 |
2 files changed, 20 insertions, 12 deletions
diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp index ef6d7e7..87b73e7 100644 --- a/gfx/models/texture.cpp +++ b/gfx/models/texture.cpp @@ -12,26 +12,28 @@ Cache<Texture, std::filesystem::path> Texture::cachedTexture;
-Texture::Texture(const std::filesystem::path & fileName) :
- Texture {Image {Resource::mapPath(fileName).c_str(), STBI_rgb_alpha}}
+Texture::Texture(const std::filesystem::path & fileName, TextureOptions to) :
+ Texture {Image {Resource::mapPath(fileName).c_str(), STBI_rgb_alpha}, to}
{
}
-Texture::Texture(const Image & tex) :
- Texture {static_cast<GLsizei>(tex.width), static_cast<GLsizei>(tex.height), tex.data.data()}
+Texture::Texture(const Image & tex, TextureOptions to) :
+ Texture {static_cast<GLsizei>(tex.width), static_cast<GLsizei>(tex.height), tex.data.data(), to}
{
}
-Texture::Texture(GLsizei width, GLsizei height, const void * data)
+Texture::Texture(GLsizei width, GLsizei height, TextureOptions to) : Texture {width, height, nullptr, to} { }
+
+Texture::Texture(GLsizei width, GLsizei height, const void * data, TextureOptions to)
{
glBindTexture(GL_TEXTURE_2D, m_texture);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, to.wrap);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, to.wrap);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, to.minFilter);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, to.magFilter);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
}
diff --git a/gfx/models/texture.h b/gfx/models/texture.h index 1aad1e0..31ffaa5 100644 --- a/gfx/models/texture.h +++ b/gfx/models/texture.h @@ -8,11 +8,17 @@ // IWYU pragma: no_forward_declare Cache
class Image;
+struct TextureOptions {
+ GLint wrap {GL_REPEAT};
+ GLint minFilter {GL_LINEAR}, magFilter {GL_LINEAR};
+};
+
class Texture {
public:
- explicit Texture(const std::filesystem::path & fileName);
- explicit Texture(const Image & image);
- explicit Texture(GLsizei width, GLsizei height, const void * data);
+ explicit Texture(const std::filesystem::path & fileName, TextureOptions = {});
+ explicit Texture(const Image & image, TextureOptions = {});
+ explicit Texture(GLsizei width, GLsizei height, TextureOptions = {});
+ explicit Texture(GLsizei width, GLsizei height, const void * data, TextureOptions = {});
static Cache<Texture, std::filesystem::path> cachedTexture;
|