From 1db33e8f0d3368e49ef105e0d091f1ce4fc4ae26 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 14 Mar 2026 22:59:05 +0000 Subject: 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. --- gfx/models/texture.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'gfx/models/texture.cpp') 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(tex.width), static_cast(tex.height), tex.data.data(), to} + Texture {static_cast(tex.width), static_cast(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(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(ceil(std::log2(std::max(width, height)))); if (levels > 1 && (isMimmap(to.minFilter) || isMimmap(to.magFilter))) { m_texture.generateMipmap(); } -- cgit v1.3