From 29779c7e599612727a1b2119a7e556d181dba6b1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Oct 2022 00:41:34 +0100 Subject: Allow creating a texture directly from an dimensions and pixel data --- gfx/models/texture.cpp | 10 +++++++--- gfx/models/texture.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'gfx/models') 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(tex.width), static_cast(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(tex.width), static_cast(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 diff --git a/gfx/models/texture.h b/gfx/models/texture.h index 8f93a42..7948a58 100644 --- a/gfx/models/texture.h +++ b/gfx/models/texture.h @@ -11,6 +11,7 @@ class Texture { public: explicit Texture(const std::filesystem::path & fileName); explicit Texture(const Image & image); + explicit Texture(GLsizei width, GLsizei height, void * data); static Cache cachedTexture; -- cgit v1.2.3