summaryrefslogtreecommitdiff
path: root/gfx/models/texture.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-01-30 20:36:42 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-02-04 19:29:49 +0000
commitbde4a9f40bb4af39270a124d5ef9571a83305d0a (patch)
tree536719df20d8f18d4c40e893c2f93b4fa45fb2d5 /gfx/models/texture.cpp
parentAdd some tests over collection (diff)
downloadilt-bde4a9f40bb4af39270a124d5ef9571a83305d0a.tar.bz2
ilt-bde4a9f40bb4af39270a124d5ef9571a83305d0a.tar.xz
ilt-bde4a9f40bb4af39270a124d5ef9571a83305d0a.zip
Restructure to allow a resource path and testing
Diffstat (limited to 'gfx/models/texture.cpp')
-rw-r--r--gfx/models/texture.cpp15
1 files changed, 5 insertions, 10 deletions
diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp
index bc80a1c..342f890 100644
--- a/gfx/models/texture.cpp
+++ b/gfx/models/texture.cpp
@@ -1,18 +1,14 @@
#include "texture.h"
#include "stb_image.h"
#include <cache.h>
-#include <stdexcept>
+#include <gfx/image.h>
+#include <resource.h>
Cache<Texture> Texture::cachedTexture;
-Texture::Texture(const std::string & fileName) : m_texture {}
+Texture::Texture(const std::filesystem::path & fileName) : m_texture {}
{
- int width, height, numComponents;
- unsigned char * data = stbi_load((fileName).c_str(), &width, &height, &numComponents, STBI_rgb_alpha);
-
- if (!data) {
- throw std::runtime_error {"Unable to load texture: " + fileName};
- }
+ const Image tex {Resource::mapPath(fileName).c_str(), STBI_rgb_alpha};
glGenTextures(1, &m_texture);
glBindTexture(GL_TEXTURE_2D, m_texture);
@@ -22,8 +18,7 @@ Texture::Texture(const std::string & fileName) : m_texture {}
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, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
- stbi_image_free(data);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width, tex.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.data.data());
}
Texture::~Texture()