From 690bb2e0c471e43d408f79c8e23126e2113da938 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 30 Apr 2024 11:52:34 +0200 Subject: [PATCH] rhi: gl: Avoid a copy in partial texture uploads Pick-to: 6.7 6.6 6.5 Task-number: QTBUG-120565 Change-Id: I7f1f8c42b98c5743708c4ff80e401070d8ab24ac Reviewed-by: Andy Nichols --- src/gui/rhi/qrhigles2.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index f54371da66..dcaa87a5ff 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -2377,7 +2377,15 @@ void QRhiGles2::enqueueSubresUpload(QGles2Texture *texD, QGles2CommandBuffer *cb const QPoint sp = subresDesc.sourceTopLeft(); if (!subresDesc.sourceSize().isEmpty()) size = subresDesc.sourceSize(); - img = img.copy(sp.x(), sp.y(), size.width(), size.height()); + + if (caps.unpackRowLength) { + cbD->retainImage(img); + // create a non-owning wrapper for the subimage + const uchar *data = img.constBits() + sp.y() * img.bytesPerLine() + sp.x() * (qMax(1, img.depth() / 8)); + img = QImage(data, size.width(), size.height(), img.bytesPerLine(), img.format()); + } else { + img = img.copy(sp.x(), sp.y(), size.width(), size.height()); + } } setCmdByNotCompressedData(cbD->retainImage(img), size, img.bytesPerLine());