From 1e6f91809e74662922ac593f4ccf171b713bbba6 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Wed, 25 Jun 2025 23:48:24 +0800 Subject: [PATCH] [Fix] (MG_State/Texture): deal with GL_UNPACK_ROW_LENGTH --- MG/MG_GL/Implementations/GL/Texture/GL_Texture.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/MG/MG_GL/Implementations/GL/Texture/GL_Texture.cpp b/MG/MG_GL/Implementations/GL/Texture/GL_Texture.cpp index 3efe86bc..9ceb27e5 100644 --- a/MG/MG_GL/Implementations/GL/Texture/GL_Texture.cpp +++ b/MG/MG_GL/Implementations/GL/Texture/GL_Texture.cpp @@ -600,6 +600,8 @@ namespace MG_GL::GL { auto unitState = &texState.textureUnits_[activeUnit]; GLuint boundTextureID = unitState->GetBoundTexture(target); + MG_Util::Debug::LogD("TexSubImage2D: bound texture: GL name %u", boundTextureID); + if (boundTextureID == 0) { MG_Util::Debug::LogD("TexSubImage2D: No texture bound to active unit. Skipping update."); return; @@ -622,11 +624,11 @@ namespace MG_GL::GL { return; } - Diligent::TextureDesc desc = pTexture->GetDesc(); + auto rowLength = TextureState::GetUnpackParam_(GL_UNPACK_ROW_LENGTH); Diligent::TextureSubResData SubResData; SubResData.pData = pixels; - SubResData.Stride = width * GetBytesPerPixel(format, type); + SubResData.Stride = ((rowLength > 0) ? rowLength : width) * GetBytesPerPixel(format, type); Diligent::Box UpdateBox; UpdateBox.MinX = xoffset; @@ -636,8 +638,10 @@ namespace MG_GL::GL { UpdateBox.MinZ = 0; UpdateBox.MaxZ = 1; - MG_Util::Debug::LogD("TexSubImage2D: Updating region [%d,%d]-[%d,%d] at level %d", - xoffset, yoffset, xoffset+width, yoffset+height, level); + MG_Util::Debug::LogD("TexSubImage2D: Got GL_UNPACK_ROW_LENGTH = %d", rowLength); + + MG_Util::Debug::LogD("TexSubImage2D: Updating region [%d,%d]-[%d,%d] at level %d, %d bytes", + xoffset, yoffset, xoffset+width, yoffset+height, level, width * height * GetBytesPerPixel(format, type)); if (MG_Diligent::IsInRenderPass) { MG_Diligent::g_pContext->EndRenderPass();