summaryrefslogtreecommitdiff
path: root/gfx/models/texture.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2026-03-14 22:59:05 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2026-03-14 22:59:05 +0000
commit1db33e8f0d3368e49ef105e0d091f1ce4fc4ae26 (patch)
tree136a7582f65fc1e1ac4cd2174e025fef78b82fec /gfx/models/texture.cpp
parentShared VAO for all 3 parts of RailVehicleClass (diff)
downloadilt-1db33e8f0d3368e49ef105e0d091f1ce4fc4ae26.tar.bz2
ilt-1db33e8f0d3368e49ef105e0d091f1ce4fc4ae26.tar.xz
ilt-1db33e8f0d3368e49ef105e0d091f1ce4fc4ae26.zip
Don't pass null to Texture constructor pixel data
Pixel data variant now proxies to the simple version and then uploads the image data, instead of vice versa with nullptr pixels.
Diffstat (limited to 'gfx/models/texture.cpp')
-rw-r--r--gfx/models/texture.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp
index 7e413d4..5a104be 100644
--- a/gfx/models/texture.cpp
+++ b/gfx/models/texture.cpp
@@ -33,23 +33,27 @@ Texture::Texture(const std::filesystem::path & fileName, TextureOptions to) :
}
Texture::Texture(const Image & tex, TextureOptions to) :
- Texture {static_cast<GLsizei>(tex.width), static_cast<GLsizei>(tex.height), tex.data.data(), to}
+ Texture {static_cast<GLsizei>(tex.width), static_cast<GLsizei>(tex.height), GL_RGBA, GL_UNSIGNED_BYTE,
+ tex.data.data(), to}
{
}
-Texture::Texture(GLsizei width, GLsizei height, TextureOptions to) : Texture {width, height, nullptr, to} { }
-
-Texture::Texture(GLsizei width, GLsizei height, const void * data, TextureOptions to)
+Texture::Texture(GLsizei width, GLsizei height, TextureOptions to)
{
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-
const auto levels = static_cast<GLsizei>(ceil(std::log2(std::max(width, height))));
m_texture.storage(levels, GL_RGBA8, {width, height});
m_texture.parameter(GL_TEXTURE_WRAP_S, TextureOptions::glMapMode(to.wrapU));
m_texture.parameter(GL_TEXTURE_WRAP_T, TextureOptions::glMapMode(to.wrapV));
m_texture.parameter(GL_TEXTURE_MIN_FILTER, to.minFilter);
m_texture.parameter(GL_TEXTURE_MAG_FILTER, to.magFilter);
- m_texture.image({width, height}, GL_RGBA, GL_UNSIGNED_BYTE, data);
+}
+
+Texture::Texture(GLsizei width, GLsizei height, GLenum pixelFormat, GLenum PixelType, const void * pixels,
+ TextureOptions to) : Texture {width, height, to}
+{
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
+ m_texture.image({width, height}, pixelFormat, PixelType, pixels);
auto isMimmap = [](auto value) {
auto eqAnyOf = [value](auto... test) {
return (... || (value == test));
@@ -57,6 +61,7 @@ Texture::Texture(GLsizei width, GLsizei height, const void * data, TextureOption
return eqAnyOf(
GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR);
};
+ const auto levels = static_cast<GLsizei>(ceil(std::log2(std::max(width, height))));
if (levels > 1 && (isMimmap(to.minFilter) || isMimmap(to.magFilter))) {
m_texture.generateMipmap();
}