summaryrefslogtreecommitdiff
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
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.
-rw-r--r--gfx/models/texture.cpp19
-rw-r--r--gfx/models/texture.h3
-rw-r--r--ui/editNetwork.cpp2
3 files changed, 15 insertions, 9 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();
}
diff --git a/gfx/models/texture.h b/gfx/models/texture.h
index 19a2ebe..9c67ae1 100644
--- a/gfx/models/texture.h
+++ b/gfx/models/texture.h
@@ -28,7 +28,8 @@ public:
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 = {});
+ explicit Texture(GLsizei width, GLsizei height, GLenum pixelFormat, GLenum PixelType, const void * pixels,
+ TextureOptions = {});
virtual void bind(GLuint unit) const;
diff --git a/ui/editNetwork.cpp b/ui/editNetwork.cpp
index 0215468..a213ccd 100644
--- a/ui/editNetwork.cpp
+++ b/ui/editNetwork.cpp
@@ -10,7 +10,7 @@
constexpr const glm::u8vec4 TRANSPARENT_BLUE {30, 50, 255, 200};
-EditNetwork::EditNetwork(Network * n) : network {n}, blue {1, 1, &TRANSPARENT_BLUE} { }
+EditNetwork::EditNetwork(Network * n) : network {n}, blue {1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &TRANSPARENT_BLUE} { }
bool
EditNetwork::click(const SDL_MouseButtonEvent & e, const Ray<GlobalPosition3D> & ray)