[Fix] (MG_State/GL_Texture): take GL_UNPACK_SKIP_PIXELS and GL_UNPACK_SKIP_ROWS into account

This commit is contained in:
2025-10-28 12:13:46 +08:00
parent 7151080a67
commit de78e423fd
+21 -6
View File
@@ -58,22 +58,29 @@ namespace MobileGL {
if (!TextureImpl::ValidateTextureSubImageOffsets(textureObject, xoffset, width, yoffset, height)) return; if (!TextureImpl::ValidateTextureSubImageOffsets(textureObject, xoffset, width, yoffset, height)) return;
// ======================= Processing ================================ // ======================= Processing ================================
SizeT imageSize = // SizeT imageSize =
MG_Util::CalculateInputTextureImageSize(textureInternalFormat, // MG_Util::CalculateInputTextureImageSize(textureInternalFormat,
texturePixelDataType, // texturePixelDataType,
{width, height, 1}); // {width, height, 1});
auto& mipmap = textureObject->GetMipmap(level); auto& mipmap = textureObject->GetMipmap(level);
Vector<Uint8>& data = mipmap.data; Vector<Uint8>& data = mipmap.data;
SizeT bytesPerPixel = SizeT bytesPerPixel =
MG_Util::GetInputBytesPerPixel(textureInternalFormat, texturePixelDataType); MG_Util::GetInputBytesPerPixel(textureInternalFormat, texturePixelDataType);
SizeT rowStride = mipmap.size.x() * bytesPerPixel; // SizeT rowStride = mipmap.size.x() * bytesPerPixel;
const Uint8* srcData = reinterpret_cast<const Uint8*>(pixels); const Uint8* srcData = reinterpret_cast<const Uint8*>(pixels);
if (!srcData) { if (!srcData) {
return; return;
} }
if (pixels != nullptr) {
auto rowsToSkip = MG_State::pGLContext->GetPixelStoreParam(PixelStoreParam::UnpackSkipRows);
auto pixelsToSkip = MG_State::pGLContext->GetPixelStoreParam(PixelStoreParam::UnpackSkipPixels);
srcData += (rowsToSkip * width + pixelsToSkip);
}
for (GLint row = 0; row < height; ++row) { for (GLint row = 0; row < height; ++row) {
SizeT dstOffset = ((yoffset + row) * mipmap.size.x() + xoffset) * bytesPerPixel; SizeT dstOffset = ((yoffset + row) * mipmap.size.x() + xoffset) * bytesPerPixel;
// Should take states from glPixelStorei/glPixelStoref into account // Should take states from glPixelStorei/glPixelStoref into account
@@ -306,9 +313,17 @@ namespace MobileGL {
texturePixelDataType, texturePixelDataType,
{width, height, 1}); {width, height, 1});
Uint8* skippedPixels = (Uint8 *) pixels;
if (pixels != nullptr) {
auto rowsToSkip = MG_State::pGLContext->GetPixelStoreParam(PixelStoreParam::UnpackSkipRows);
auto pixelsToSkip = MG_State::pGLContext->GetPixelStoreParam(PixelStoreParam::UnpackSkipPixels);
skippedPixels += (rowsToSkip * width + pixelsToSkip);
}
textureObject->SetInternalFormat(textureInternalFormat); textureObject->SetInternalFormat(textureInternalFormat);
MG_State::GLState::MipmapLevelInput mipmap = MG_State::GLState::MipmapLevelInput( MG_State::GLState::MipmapLevelInput mipmap = MG_State::GLState::MipmapLevelInput(
{width, height, 1}, level, false, 0, {const_cast<void*>(isProxy ? pixels : nullptr), imageSize}); {width, height, 1}, level, false, 0, {const_cast<void*>(isProxy ? (void*)skippedPixels : nullptr), imageSize});
textureObject->SetMipmapLevel(mipmap); textureObject->SetMipmapLevel(mipmap);
} }