diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-10-14 00:41:34 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-10-14 00:41:34 +0100 |
commit | 29779c7e599612727a1b2119a7e556d181dba6b1 (patch) | |
tree | e3fddd9a68963793a12412ac2912d5b686e68ec3 /gfx/models/texture.cpp | |
parent | Allow creating a texture directly from an Image (diff) | |
download | ilt-29779c7e599612727a1b2119a7e556d181dba6b1.tar.bz2 ilt-29779c7e599612727a1b2119a7e556d181dba6b1.tar.xz ilt-29779c7e599612727a1b2119a7e556d181dba6b1.zip |
Allow creating a texture directly from an dimensions and pixel data
Diffstat (limited to 'gfx/models/texture.cpp')
-rw-r--r-- | gfx/models/texture.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp index cff44f9..e311937 100644 --- a/gfx/models/texture.cpp +++ b/gfx/models/texture.cpp @@ -13,7 +13,12 @@ Texture::Texture(const std::filesystem::path & fileName) : {
}
-Texture::Texture(const Image & tex)
+Texture::Texture(const Image & tex) :
+ Texture {static_cast<GLsizei>(tex.width), static_cast<GLsizei>(tex.height), tex.data.data()}
+{
+}
+
+Texture::Texture(GLsizei width, GLsizei height, void * data)
{
glBindTexture(GL_TEXTURE_2D, m_texture);
@@ -22,8 +27,7 @@ Texture::Texture(const Image & tex) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, static_cast<GLsizei>(tex.width), static_cast<GLsizei>(tex.height), 0,
- GL_RGBA, GL_UNSIGNED_BYTE, tex.data.data());
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
}
void
|