aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2019-09-09 15:31:26 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2019-09-11 12:32:52 +0200
commit1bb96cfcce47152c578bcc9a7c2ad80b0f0e6553 (patch)
treeab85a4c42c6e4dfb1c10c41dea0daf23402439cc
parent2b566231a6e35ee1646754cee09b30fc99240a80 (diff)
Request correct alpha composition on the rhi code path
Task-number: QTBUG-78089 Change-Id: I22f8bb5ec0af33397df14e064a0306bd4c5a5ef5 Reviewed-by: Christian Strømme <christian.stromme@qt.io>
-rw-r--r--src/quick/scenegraph/qsgrenderloop.cpp11
-rw-r--r--src/quick/scenegraph/qsgthreadedrenderloop.cpp10
-rw-r--r--tests/manual/nodetypes_ng/nodetypes_ng.cpp7
3 files changed, 26 insertions, 2 deletions
diff --git a/src/quick/scenegraph/qsgrenderloop.cpp b/src/quick/scenegraph/qsgrenderloop.cpp
index f15105168e..25d10d37d4 100644
--- a/src/quick/scenegraph/qsgrenderloop.cpp
+++ b/src/quick/scenegraph/qsgrenderloop.cpp
@@ -561,6 +561,14 @@ void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window)
QRhiSwapChain::Flags flags = QRhiSwapChain::UsedAsTransferSource; // may be used in a grab
+ // QQ is always premul alpha. Decide based on alphaBufferSize in
+ // requestedFormat(). (the platform plugin can override format() but
+ // what matters here is what the application wanted, hence using the
+ // requested one)
+ const bool alpha = window->requestedFormat().alphaBufferSize() > 0;
+ if (alpha)
+ flags |= QRhiSwapChain::SurfaceHasPreMulAlpha;
+
cd->swapchain = rhi->newSwapChain();
cd->depthStencilForSwapchain = rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil,
QSize(),
@@ -568,7 +576,8 @@ void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window)
QRhiRenderBuffer::UsedWithSwapChainOnly);
cd->swapchain->setWindow(window);
cd->swapchain->setDepthStencil(cd->depthStencilForSwapchain);
- qCDebug(QSG_LOG_INFO, "MSAA sample count for the swapchain is %d", rhiSampleCount);
+ qCDebug(QSG_LOG_INFO, "MSAA sample count for the swapchain is %d. Alpha channel requested = %s",
+ rhiSampleCount, alpha ? "yes" : "no");
cd->swapchain->setSampleCount(rhiSampleCount);
cd->swapchain->setFlags(flags);
cd->rpDescForSwapchain = cd->swapchain->newCompatibleRenderPassDescriptor();
diff --git a/src/quick/scenegraph/qsgthreadedrenderloop.cpp b/src/quick/scenegraph/qsgthreadedrenderloop.cpp
index 9bcb96a65a..eb6eec342c 100644
--- a/src/quick/scenegraph/qsgthreadedrenderloop.cpp
+++ b/src/quick/scenegraph/qsgthreadedrenderloop.cpp
@@ -924,6 +924,13 @@ void QSGRenderThread::run()
if (rhi && !cd->swapchain) {
cd->rhi = rhi;
QRhiSwapChain::Flags flags = QRhiSwapChain::UsedAsTransferSource; // may be used in a grab
+ // QQ is always premul alpha. Decide based on alphaBufferSize in
+ // requestedFormat(). (the platform plugin can override format() but
+ // what matters here is what the application wanted, hence using the
+ // requested one)
+ const bool alpha = window->requestedFormat().alphaBufferSize() > 0;
+ if (alpha)
+ flags |= QRhiSwapChain::SurfaceHasPreMulAlpha;
cd->swapchain = rhi->newSwapChain();
cd->depthStencilForSwapchain = rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil,
QSize(),
@@ -931,7 +938,8 @@ void QSGRenderThread::run()
QRhiRenderBuffer::UsedWithSwapChainOnly);
cd->swapchain->setWindow(window);
cd->swapchain->setDepthStencil(cd->depthStencilForSwapchain);
- qCDebug(QSG_LOG_INFO, "MSAA sample count for the swapchain is %d", rhiSampleCount);
+ qCDebug(QSG_LOG_INFO, "MSAA sample count for the swapchain is %d. Alpha channel requested = %s.",
+ rhiSampleCount, alpha ? "yes" : "no");
cd->swapchain->setSampleCount(rhiSampleCount);
cd->swapchain->setFlags(flags);
cd->rpDescForSwapchain = cd->swapchain->newCompatibleRenderPassDescriptor();
diff --git a/tests/manual/nodetypes_ng/nodetypes_ng.cpp b/tests/manual/nodetypes_ng/nodetypes_ng.cpp
index 829002b538..8fe0e0dc98 100644
--- a/tests/manual/nodetypes_ng/nodetypes_ng.cpp
+++ b/tests/manual/nodetypes_ng/nodetypes_ng.cpp
@@ -301,6 +301,13 @@ int main(int argc, char **argv)
fmt.setProfile(QSurfaceFormat::CoreProfile);
view.setFormat(fmt);
}
+ if (app.arguments().contains(QLatin1String("--transparent"))) {
+ qDebug("Requesting alpha channel for the window and using Qt::transparent as background");
+ QSurfaceFormat fmt = view.format();
+ fmt.setAlphaBufferSize(8);
+ view.setFormat(fmt);
+ view.setColor(Qt::transparent);
+ }
view.engine()->rootContext()->setContextProperty(QLatin1String("helper"), &helper);