From 7ccd2d02463f8076631bc45e5bf1386c61037dc7 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 3 Feb 2021 18:07:47 +0100 Subject: rhi: Add support for custom bytes-per-line for uncompressed raw data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: QTBUG-90770 Change-Id: Icba328c417bcce256e7b44f1d540af7f8e83376b Reviewed-by: Qt CI Bot Reviewed-by: Christian Strømme --- tests/auto/gui/rhi/qrhi/tst_qrhi.cpp | 63 +++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp index c4d1dca1bb..6d0ec2a488 100644 --- a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp +++ b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp @@ -89,6 +89,8 @@ private slots: void resourceUpdateBatchRGBATextureCopy(); void resourceUpdateBatchRGBATextureMip_data(); void resourceUpdateBatchRGBATextureMip(); + void resourceUpdateBatchTextureRawDataStride_data(); + void resourceUpdateBatchTextureRawDataStride(); void invalidPipeline_data(); void invalidPipeline(); void srbLayoutCompatibility_data(); @@ -348,7 +350,8 @@ void tst_QRhi::create() QRhi::IntAttributes, QRhi::ScreenSpaceDerivatives, QRhi::ReadBackAnyTextureFormat, - QRhi::PipelineCacheDataLoadSave + QRhi::PipelineCacheDataLoadSave, + QRhi::ImageDataStride }; for (size_t i = 0; i isFeatureSupported(features[i]); @@ -1293,6 +1296,64 @@ void tst_QRhi::resourceUpdateBatchRGBATextureMip() } } +void tst_QRhi::resourceUpdateBatchTextureRawDataStride_data() +{ + rhiTestData(); +} + +void tst_QRhi::resourceUpdateBatchTextureRawDataStride() +{ + QFETCH(QRhi::Implementation, impl); + QFETCH(QRhiInitParams *, initParams); + + QScopedPointer rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr)); + if (!rhi) + QSKIP("QRhi could not be created, skipping testing texture resource updates"); + + const int WIDTH = 150; + const int DATA_WIDTH = 180; + const int HEIGHT = 50; + QByteArray image; + image.resize(DATA_WIDTH * HEIGHT * 4); + for (int y = 0; y < HEIGHT; ++y) { + char *p = image.data() + y * DATA_WIDTH * 4; + memset(p, y, DATA_WIDTH * 4); + } + + { + QScopedPointer texture(rhi->newTexture(QRhiTexture::RGBA8, QSize(WIDTH, HEIGHT), + 1, QRhiTexture::UsedAsTransferSource)); + QVERIFY(texture->create()); + + QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch(); + + QRhiTextureSubresourceUploadDescription subresDesc(image.constData(), image.size()); + subresDesc.setDataStride(DATA_WIDTH * 4); + QRhiTextureUploadEntry upload(0, 0, subresDesc); + QRhiTextureUploadDescription uploadDesc(upload); + batch->uploadTexture(texture.data(), uploadDesc); + + QRhiReadbackResult readResult; + bool readCompleted = false; + readResult.completed = [&readCompleted] { readCompleted = true; }; + batch->readBackTexture(texture.data(), &readResult); + + QVERIFY(submitResourceUpdates(rhi.data(), batch)); + QVERIFY(readCompleted); + QCOMPARE(readResult.format, QRhiTexture::RGBA8); + QCOMPARE(readResult.pixelSize, QSize(WIDTH, HEIGHT)); + + QImage wrapperImage(reinterpret_cast(readResult.data.constData()), + readResult.pixelSize.width(), readResult.pixelSize.height(), + QImage::Format_RGBA8888_Premultiplied); + // wrap the original data, note the bytesPerLine argument + QImage originalWrapperImage(reinterpret_cast(image.constData()), + WIDTH, HEIGHT, DATA_WIDTH * 4, + QImage::Format_RGBA8888_Premultiplied); + QVERIFY(imageRGBAEquals(wrapperImage, originalWrapperImage)); + } +} + static QShader loadShader(const char *name) { QFile f(QString::fromUtf8(name)); -- cgit v1.2.3