From 69caca590360215788de17c20e486d6fe6d70be5 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Tue, 30 Dec 2025 12:39:19 +0800 Subject: [PATCH] [Fix] (MG_Impl/Texture): read PBO if `pixels` == NULL at `TexSubImage2D` --- MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp index 90c566ba..6e652a97 100644 --- a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp +++ b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp @@ -52,7 +52,9 @@ namespace MobileGL { TextureInputFormat textureInputFormat = MG_Util::ConvertGLEnumToTextureInputFormat(format); TexturePixelDataType texturePixelDataType = MG_Util::ConvertGLEnumToTexturePixelDataType(type); // TextureInternalFormat textureInternalFormat = MG_Util::ConvertGLEnumToTextureInternalFormat(format); - + MGLOG_D("TexSubImage2D_State: (%d, %d), format = %s, pixels = %p", width, height, + MG_Util::ConvertTextureInputFormatToString(textureInputFormat).c_str(), + pixels); // ===================== Error Checking ============================== if (!TextureImpl::ValidateTexturePixelDataType(texturePixelDataType)) return; if (!TextureImpl::ValidateTextureInputFormat(textureInputFormat)) return; @@ -61,7 +63,6 @@ namespace MobileGL { if (!TextureImpl::ValidateTextureSizeWithTextureUploadTarget(textureUploadingTarget, width, height)) return; if (!TextureImpl::ValidateTextureSizeRange(width, height)) return; if (!TextureImpl::ValidateTextureLevelWithUploadTarget(textureUploadingTarget, level)) return; - if (!pixels) return; // TODO: GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the // GL_PIXEL_UNPACK_BUFFER target and the buffer object's data store is currently mapped. @@ -108,6 +109,13 @@ namespace MobileGL { originalPixels = reinterpret_cast(pixelUnpackBufferObject->GetDataReadOnly()->data()) + reinterpret_cast(pixels); } + + if (!originalPixels) { + MG_State::pGLContext->RecordError( + ErrorCode::InvalidOperation, + MakeShared("MG_Impl/GLImpl", __func__, "No data supplied from pixels parameter and no PBO bound.")); + return; + } void* processedPixels = MG_Util::PixelStoreProcessor::ProcessTexturePixelsDataUnpack( originalPixels, MG_State::pGLContext->GetPixelStoreParameters(true), textureInternalFormat, textureInputFormat, texturePixelDataType, {width, height, 1},