From b1cb5fcb9fd3b1dca9e6de407d9a8877b336a800 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 8 Aug 2025 13:42:36 +0200 Subject: [PATCH] Improve texture creation logging and checking --- irr/include/SColor.h | 5 +++++ irr/src/COpenGLCoreTexture.h | 35 +++++++++++++++++++++++++--------- irr/src/COpenGLDriver.cpp | 1 + irr/src/OpenGL/Driver.cpp | 3 --- irr/src/OpenGL/Driver.h | 10 ++++------ src/client/render/pipeline.cpp | 2 +- 6 files changed, 37 insertions(+), 19 deletions(-) diff --git a/irr/include/SColor.h b/irr/include/SColor.h index f45d7404b..48af09c71 100644 --- a/irr/include/SColor.h +++ b/irr/include/SColor.h @@ -119,6 +119,11 @@ const c8 *const ColorFormatNames[] = { static_assert(sizeof(ColorFormatNames) / sizeof(ColorFormatNames[0]) == ECF_UNKNOWN + 2, "name table size mismatch"); +inline const c8 *ColorFormatName(ECOLOR_FORMAT format) +{ + return ColorFormatNames[format < ECF_UNKNOWN ? format : ECF_UNKNOWN]; +} + //! Creates a 16 bit A1R5G5B5 color inline u16 RGBA16(u32 r, u32 g, u32 b, u32 a = 0xFF) { diff --git a/irr/src/COpenGLCoreTexture.h b/irr/src/COpenGLCoreTexture.h index 8e2214922..433acbb6b 100644 --- a/irr/src/COpenGLCoreTexture.h +++ b/irr/src/COpenGLCoreTexture.h @@ -56,15 +56,18 @@ public: HasMipMaps = Driver->getTextureCreationFlag(ETCF_CREATE_MIP_MAPS); KeepImage = Driver->getTextureCreationFlag(ETCF_ALLOW_MEMORY_COPY); + if (!name.empty()) + os::Printer::log("COpenGLCoreTexture: name", name.c_str(), ELL_DEBUG); + getImageValues(srcImages[0]); if (!InternalFormat) return; char lbuf[128]; snprintf_irr(lbuf, sizeof(lbuf), - "COpenGLCoreTexture: Type = %d Size = %dx%d (%dx%d) ColorFormat = %d (%d)%s -> %#06x %#06x %#06x%s", + "COpenGLCoreTexture: Type = %d Size = %dx%d (%dx%d) ColorFormat = %s (%s)%s -> %#06x %#06x %#06x%s", (int)Type, Size.Width, Size.Height, OriginalSize.Width, OriginalSize.Height, - (int)ColorFormat, (int)OriginalColorFormat, + ColorFormatName(ColorFormat), ColorFormatName(OriginalColorFormat), HasMipMaps ? " +Mip" : "", InternalFormat, PixelFormat, PixelType, Converter ? " (c)" : "" ); @@ -147,6 +150,9 @@ public: HasMipMaps = false; IsRenderTarget = true; + if (!name.empty()) + os::Printer::log("COpenGLCoreTexture: name", name.c_str(), ELL_DEBUG); + OriginalColorFormat = format; if (ECF_UNKNOWN == OriginalColorFormat) @@ -157,10 +163,17 @@ public: OriginalSize = size; Size = OriginalSize; + if (Size.Width == 0 || Size.Height == 0) { + char buf[64]; + snprintf_irr(buf, sizeof(buf), "%dx%d", Size.Width, Size.Height); + os::Printer::log("Invalid size for render target", buf, ELL_ERROR); + return; + } + Pitch = Size.Width * IImage::getBitsPerPixelFromFormat(ColorFormat) / 8; if (!Driver->getColorFormatParameters(ColorFormat, InternalFormat, PixelFormat, PixelType, &Converter)) { - os::Printer::log("COpenGLCoreTexture: Color format is not supported", ColorFormatNames[ColorFormat < ECF_UNKNOWN ? ColorFormat : ECF_UNKNOWN], ELL_ERROR); + os::Printer::log("COpenGLCoreTexture: Color format is not supported", ColorFormatName(ColorFormat), ELL_ERROR); return; } @@ -176,8 +189,8 @@ public: char lbuf[100]; snprintf_irr(lbuf, sizeof(lbuf), - "COpenGLCoreTexture: RTT Type = %d Size = %dx%d ColorFormat = %d -> %#06x %#06x %#06x%s", - (int)Type, Size.Width, Size.Height, (int)ColorFormat, + "COpenGLCoreTexture: RTT Type = %d Size = %dx%d (S:%d) ColorFormat = %s -> %#06x %#06x %#06x%s", + (int)Type, Size.Width, Size.Height, (int)MSAA, ColorFormatName(ColorFormat), InternalFormat, PixelFormat, PixelType, Converter ? " (c)" : "" ); os::Printer::log(lbuf, ELL_DEBUG); @@ -458,7 +471,7 @@ protected: ColorFormat = getBestColorFormat(OriginalColorFormat); if (!Driver->getColorFormatParameters(ColorFormat, InternalFormat, PixelFormat, PixelType, &Converter)) { - os::Printer::log("getImageValues: Color format is not supported", ColorFormatNames[ColorFormat < ECF_UNKNOWN ? ColorFormat : ECF_UNKNOWN], ELL_ERROR); + os::Printer::log("getImageValues: Color format is not supported", ColorFormatName(ColorFormat), ELL_ERROR); InternalFormat = 0; return; } @@ -471,7 +484,9 @@ protected: Size = OriginalSize; if (Size.Width == 0 || Size.Height == 0) { - os::Printer::log("Invalid size of image for texture.", ELL_ERROR); + char buf[64]; + snprintf_irr(buf, sizeof(buf), "%dx%d", Size.Width, Size.Height); + os::Printer::log("Invalid size of image for texture", buf, ELL_ERROR); return; } @@ -520,6 +535,7 @@ protected: if (HasMipMaps) { levels = core::u32_log2(core::max_(Size.Width, Size.Height)) + 1; } + assert(levels > 0); // reference: bool use_tex_storage = Driver->getFeature().TexStorage; @@ -543,7 +559,7 @@ protected: TEST_GL_ERROR(Driver); break; case ETT_2D_MS: { - GLint max_samples = 0; + GLint max_samples = 1; GL.GetIntegerv(GL_MAX_SAMPLES, &max_samples); MSAA = core::min_(MSAA, (u8)max_samples); @@ -663,7 +679,8 @@ protected: return GL_TEXTURE_2D_ARRAY; } - os::Printer::log("COpenGLCoreTexture::TextureTypeIrrToGL unknown texture type", ELL_WARNING); + auto s = std::to_string(type); + os::Printer::log("COpenGLCoreTexture: unknown texture type", s.c_str(), ELL_WARNING); return GL_TEXTURE_2D; } diff --git a/irr/src/COpenGLDriver.cpp b/irr/src/COpenGLDriver.cpp index 4105942d0..6ae4654e1 100644 --- a/irr/src/COpenGLDriver.cpp +++ b/irr/src/COpenGLDriver.cpp @@ -1597,6 +1597,7 @@ inline void COpenGLDriver::getGLTextureMatrix(GLfloat *o, const core::matrix4 &m ITexture *COpenGLDriver::createDeviceDependentTexture(const io::path &name, E_TEXTURE_TYPE type, const std::vector &images) { + assert(type == ETT_2D); return new COpenGLTexture(name, images, ETT_2D, this); } diff --git a/irr/src/OpenGL/Driver.cpp b/irr/src/OpenGL/Driver.cpp index e114e48ff..35538a59b 100644 --- a/irr/src/OpenGL/Driver.cpp +++ b/irr/src/OpenGL/Driver.cpp @@ -278,9 +278,6 @@ bool COpenGL3DriverBase::genericDriverInit(const core::dimension2d &screenS // set fog mode setFog(FogColor, FogType, FogStart, FogEnd, FogDensity, PixelFog, RangeFog); - // create matrix for flipping textures - TextureFlipMatrix.buildTextureTransform(0.0f, core::vector2df(0, 0), core::vector2df(0, 1.0f), core::vector2df(1.0f, -1.0f)); - // We need to reset once more at the beginning of the first rendering. // This fixes problems with intermediate changes to the material during texture load. ResetRenderStates = true; diff --git a/irr/src/OpenGL/Driver.h b/irr/src/OpenGL/Driver.h index 3ad0e720c..839c5f602 100644 --- a/irr/src/OpenGL/Driver.h +++ b/irr/src/OpenGL/Driver.h @@ -324,15 +324,13 @@ protected: bool LockRenderStateMode; u8 AntiAlias; - core::matrix4 TextureFlipMatrix; - using FColorConverter = void (*)(const void *source, s32 count, void *dest); struct STextureFormatInfo { - GLenum InternalFormat; - GLenum PixelFormat; - GLenum PixelType; - FColorConverter Converter; + GLenum InternalFormat = 0; + GLenum PixelFormat = 0; + GLenum PixelType = 0; + FColorConverter Converter = nullptr; }; STextureFormatInfo TextureFormats[ECF_UNKNOWN] = {}; diff --git a/src/client/render/pipeline.cpp b/src/client/render/pipeline.cpp index 33b3e78e2..e34a55dd9 100644 --- a/src/client/render/pipeline.cpp +++ b/src/client/render/pipeline.cpp @@ -131,7 +131,7 @@ bool TextureBuffer::ensureTexture(video::ITexture **texture, const TextureDefini if (definition.valid) { if (!m_driver->queryTextureFormat(definition.format)) { errorstream << "Failed to create texture \"" << definition.name - << "\": unsupported format " << video::ColorFormatNames[definition.format] + << "\": unsupported format " << video::ColorFormatName(definition.format) << std::endl; return false; }