From 8b39e3c8a9af266e5fbb433094b0eca6cdf46966 Mon Sep 17 00:00:00 2001 From: BZLZHH Date: Sat, 15 Nov 2025 23:02:00 +0800 Subject: [PATCH] [Feat] (MG_Impl/Texture): Implement PBO. --- .../MG_Impl/GLImpl/Texture/GL_Texture.cpp | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp index 99cf4087..9cf31a07 100644 --- a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp +++ b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp @@ -66,8 +66,20 @@ namespace MobileGL { SizeT imageSize = 0; const SizeT bytesPerPixel = MG_Util::GetInputBytesPerPixel(textureInternalFormat, texturePixelDataType); + const void* originalPixels = pixels; + + // PBO + const auto& pixelUnpackBufferObject = + MG_State::pGLContext->GetBufferBindingSlot(BufferTarget::PixelUnpack).GetBoundObject(); + if (pixelUnpackBufferObject) { + MGLOG_D("TexSubImage2D_State: Using Pixel Unpack Buffer Object ID: %u", + pixelUnpackBufferObject->GetExternalIndex()); + originalPixels = reinterpret_cast(pixelUnpackBufferObject->GetDataReadOnly()->data()) + + reinterpret_cast(pixels); + } + void* processedPixels = MG_Util::PixelStoreProcessor::ProcessTexturePixelsDataUnpack( - pixels, MG_State::pGLContext->GetPixelStoreParameters(true), bytesPerPixel, {width, height, 1}, + originalPixels, MG_State::pGLContext->GetPixelStoreParameters(true), bytesPerPixel, {width, height, 1}, false /*TODO*/, imageSize); if (!processedPixels || imageSize == 0) { @@ -360,10 +372,22 @@ namespace MobileGL { const SizeT bytesPerPixel = MG_Util::GetInputBytesPerPixel(textureInternalFormat, texturePixelDataType); const SizeT totalBytes = width * height * bytesPerPixel; - if (pixels) { + const void* originalPixels = pixels; + + // PBO + const auto& pixelUnpackBufferObject = + MG_State::pGLContext->GetBufferBindingSlot(BufferTarget::PixelUnpack).GetBoundObject(); + if (pixelUnpackBufferObject) { + MGLOG_D("TexImage2D_State: Using Pixel Unpack Buffer Object ID: %u", + pixelUnpackBufferObject->GetExternalIndex()); + originalPixels = reinterpret_cast(pixelUnpackBufferObject->GetDataReadOnly()->data()) + + reinterpret_cast(pixels); + } + + if (originalPixels) { processedPixels = MG_Util::PixelStoreProcessor::ProcessTexturePixelsDataUnpack( - pixels, MG_State::pGLContext->GetPixelStoreParameters(true), bytesPerPixel, {width, height, 1}, - false, imageSize); + originalPixels, MG_State::pGLContext->GetPixelStoreParameters(true), bytesPerPixel, + {width, height, 1}, false, imageSize); } MG_State::GLState::MipmapLevelInput mipmap = @@ -831,6 +855,7 @@ namespace MobileGL { } void BindTexture_State(GLenum target, GLuint texture) { + MGLOG_D("BindTexture_State called with target: 0x%X, texture: %u", target, texture); // ======================= Converting ================================ TextureTarget textureTarget = MG_Util::ConvertGLEnumToTextureTarget(target);