rhi: Add a --transparent option to manual tests
This will also cause clearing to 0,0,0,0. Essential in order to allow fast testing of window transparency issues in combination with QRhi and the various backends. Change-Id: Iee2763c1d06f1d3e5d59a9142abaf30fab1dc543 Reviewed-by: Christian Strømme <christian.stromme@qt.io>
This commit is contained in:
parent
30e27328e3
commit
22d22eb282
@ -182,7 +182,7 @@ void Window::customRender()
|
|||||||
QRhiCommandBuffer *cb = m_sc->currentFrameCommandBuffer();
|
QRhiCommandBuffer *cb = m_sc->currentFrameCommandBuffer();
|
||||||
const QSize outputSizeInPixels = m_sc->currentPixelSize();
|
const QSize outputSizeInPixels = m_sc->currentPixelSize();
|
||||||
|
|
||||||
cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u);
|
cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u);
|
||||||
|
|
||||||
cb->setGraphicsPipeline(d.ps);
|
cb->setGraphicsPipeline(d.ps);
|
||||||
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
||||||
|
@ -197,7 +197,7 @@ void Window::customRender()
|
|||||||
QRhiCommandBuffer *cb = m_sc->currentFrameCommandBuffer();
|
QRhiCommandBuffer *cb = m_sc->currentFrameCommandBuffer();
|
||||||
const QSize outputSizeInPixels = m_sc->currentPixelSize();
|
const QSize outputSizeInPixels = m_sc->currentPixelSize();
|
||||||
|
|
||||||
cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u);
|
cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u);
|
||||||
|
|
||||||
cb->setGraphicsPipeline(d.ps);
|
cb->setGraphicsPipeline(d.ps);
|
||||||
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
||||||
|
@ -195,7 +195,7 @@ void Window::customRender()
|
|||||||
cb->endComputePass();
|
cb->endComputePass();
|
||||||
|
|
||||||
// graphics pass
|
// graphics pass
|
||||||
cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 });
|
cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 });
|
||||||
cb->setGraphicsPipeline(d.graphicsPipeline);
|
cb->setGraphicsPipeline(d.graphicsPipeline);
|
||||||
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
||||||
QRhiCommandBuffer::VertexInput vbufBinding(d.sbuf, 0);
|
QRhiCommandBuffer::VertexInput vbufBinding(d.sbuf, 0);
|
||||||
|
@ -217,7 +217,7 @@ void Window::customRender()
|
|||||||
cb->dispatch(d.imageSize.width() / 16, d.imageSize.height() / 16, 1);
|
cb->dispatch(d.imageSize.width() / 16, d.imageSize.height() / 16, 1);
|
||||||
cb->endComputePass();
|
cb->endComputePass();
|
||||||
|
|
||||||
cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 });
|
cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 });
|
||||||
cb->setGraphicsPipeline(d.ps);
|
cb->setGraphicsPipeline(d.ps);
|
||||||
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
||||||
cb->setShaderResources();
|
cb->setShaderResources();
|
||||||
|
@ -168,7 +168,7 @@ void Window::customRender()
|
|||||||
// no translation
|
// no translation
|
||||||
u->updateDynamicBuffer(d.ubuf, 0, 64, mvp.constData());
|
u->updateDynamicBuffer(d.ubuf, 0, 64, mvp.constData());
|
||||||
|
|
||||||
cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u);
|
cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u);
|
||||||
cb->setGraphicsPipeline(d.ps);
|
cb->setGraphicsPipeline(d.ps);
|
||||||
cb->setViewport(QRhiViewport(0, 0, outputSizeInPixels.width(), outputSizeInPixels.height()));
|
cb->setViewport(QRhiViewport(0, 0, outputSizeInPixels.width(), outputSizeInPixels.height()));
|
||||||
cb->setShaderResources();
|
cb->setShaderResources();
|
||||||
|
@ -221,7 +221,7 @@ void Window::customRender()
|
|||||||
// no translation
|
// no translation
|
||||||
u->updateDynamicBuffer(d.ubuf, 0, 64, mvp.constData());
|
u->updateDynamicBuffer(d.ubuf, 0, 64, mvp.constData());
|
||||||
|
|
||||||
cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u);
|
cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u);
|
||||||
cb->setGraphicsPipeline(d.ps);
|
cb->setGraphicsPipeline(d.ps);
|
||||||
cb->setViewport(QRhiViewport(0, 0, outputSizeInPixels.width(), outputSizeInPixels.height()));
|
cb->setViewport(QRhiViewport(0, 0, outputSizeInPixels.width(), outputSizeInPixels.height()));
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ void Window::customRender()
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QSize outputSizeInPixels = m_sc->currentPixelSize();
|
const QSize outputSizeInPixels = m_sc->currentPixelSize();
|
||||||
cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u);
|
cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u);
|
||||||
cb->setGraphicsPipeline(d.ps);
|
cb->setGraphicsPipeline(d.ps);
|
||||||
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
||||||
cb->setShaderResources();
|
cb->setShaderResources();
|
||||||
|
@ -161,7 +161,7 @@ void Window::customRender()
|
|||||||
u->updateDynamicBuffer(d.ubuf, 0, 64, mvp.constData());
|
u->updateDynamicBuffer(d.ubuf, 0, 64, mvp.constData());
|
||||||
}
|
}
|
||||||
|
|
||||||
cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u);
|
cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u);
|
||||||
cb->setGraphicsPipeline(d.ps);
|
cb->setGraphicsPipeline(d.ps);
|
||||||
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
||||||
cb->setShaderResources();
|
cb->setShaderResources();
|
||||||
|
@ -283,7 +283,7 @@ void Window::customRender()
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QSize outputSizeInPixels = m_sc->currentPixelSize();
|
const QSize outputSizeInPixels = m_sc->currentPixelSize();
|
||||||
cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u);
|
cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u);
|
||||||
cb->setGraphicsPipeline(d.ps);
|
cb->setGraphicsPipeline(d.ps);
|
||||||
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
||||||
vbufBinding.second = 0;
|
vbufBinding.second = 0;
|
||||||
|
@ -248,7 +248,7 @@ void Window::customRender()
|
|||||||
|
|
||||||
// onscreen (quad)
|
// onscreen (quad)
|
||||||
const QSize outputSizeInPixels = m_sc->currentPixelSize();
|
const QSize outputSizeInPixels = m_sc->currentPixelSize();
|
||||||
cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 });
|
cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 });
|
||||||
cb->setGraphicsPipeline(d.ps);
|
cb->setGraphicsPipeline(d.ps);
|
||||||
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
||||||
cb->setShaderResources();
|
cb->setShaderResources();
|
||||||
|
@ -315,7 +315,7 @@ void Window::customRender()
|
|||||||
|
|
||||||
// onscreen
|
// onscreen
|
||||||
const QSize outputSizeInPixels = m_sc->currentPixelSize();
|
const QSize outputSizeInPixels = m_sc->currentPixelSize();
|
||||||
cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 });
|
cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 });
|
||||||
cb->setGraphicsPipeline(d.psLeft); // showing the non-msaa version
|
cb->setGraphicsPipeline(d.psLeft); // showing the non-msaa version
|
||||||
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
||||||
cb->setShaderResources();
|
cb->setShaderResources();
|
||||||
|
@ -296,7 +296,7 @@ void Window::customRender()
|
|||||||
cb->endPass();
|
cb->endPass();
|
||||||
|
|
||||||
// main pass
|
// main pass
|
||||||
cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 });
|
cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 });
|
||||||
cb->setGraphicsPipeline(d.ps);
|
cb->setGraphicsPipeline(d.ps);
|
||||||
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
||||||
enqueueScene(cb, d.srb, oneRoundedUniformBlockSize, 0);
|
enqueueScene(cb, d.srb, oneRoundedUniformBlockSize, 0);
|
||||||
|
@ -127,6 +127,7 @@ QRhiSwapChain::Flags scFlags = 0;
|
|||||||
QRhi::BeginFrameFlags beginFrameFlags = 0;
|
QRhi::BeginFrameFlags beginFrameFlags = 0;
|
||||||
QRhi::EndFrameFlags endFrameFlags = 0;
|
QRhi::EndFrameFlags endFrameFlags = 0;
|
||||||
int framesUntilTdr = -1;
|
int framesUntilTdr = -1;
|
||||||
|
bool transparentBackground = false;
|
||||||
|
|
||||||
class Window : public QWindow
|
class Window : public QWindow
|
||||||
{
|
{
|
||||||
@ -167,6 +168,8 @@ protected:
|
|||||||
QOffscreenSurface *m_fallbackSurface = nullptr;
|
QOffscreenSurface *m_fallbackSurface = nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
QColor m_clearColor;
|
||||||
|
|
||||||
friend int main(int, char**);
|
friend int main(int, char**);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -194,6 +197,8 @@ Window::Window()
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_clearColor = transparentBackground ? Qt::transparent : QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::~Window()
|
Window::~Window()
|
||||||
@ -477,6 +482,9 @@ int main(int argc, char **argv)
|
|||||||
QCommandLineOption swOption(QLatin1String("software"), QLatin1String("Prefer a software renderer when choosing the adapter. "
|
QCommandLineOption swOption(QLatin1String("software"), QLatin1String("Prefer a software renderer when choosing the adapter. "
|
||||||
"Only applicable with some APIs and platforms."));
|
"Only applicable with some APIs and platforms."));
|
||||||
cmdLineParser.addOption(swOption);
|
cmdLineParser.addOption(swOption);
|
||||||
|
// Allow testing having a semi-transparent window.
|
||||||
|
QCommandLineOption transparentOption(QLatin1String("transparent"), QLatin1String("Make background transparent"));
|
||||||
|
cmdLineParser.addOption(transparentOption);
|
||||||
|
|
||||||
cmdLineParser.process(app);
|
cmdLineParser.process(app);
|
||||||
if (cmdLineParser.isSet(nullOption))
|
if (cmdLineParser.isSet(nullOption))
|
||||||
@ -493,6 +501,11 @@ int main(int argc, char **argv)
|
|||||||
qDebug("Selected graphics API is %s", qPrintable(graphicsApiName()));
|
qDebug("Selected graphics API is %s", qPrintable(graphicsApiName()));
|
||||||
qDebug("This is a multi-api example, use command line arguments to override:\n%s", qPrintable(cmdLineParser.helpText()));
|
qDebug("This is a multi-api example, use command line arguments to override:\n%s", qPrintable(cmdLineParser.helpText()));
|
||||||
|
|
||||||
|
if (cmdLineParser.isSet(transparentOption)) {
|
||||||
|
transparentBackground = true;
|
||||||
|
scFlags |= QRhiSwapChain::SurfaceHasPreMulAlpha;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef EXAMPLEFW_PREINIT
|
#ifdef EXAMPLEFW_PREINIT
|
||||||
void preInit();
|
void preInit();
|
||||||
preInit();
|
preInit();
|
||||||
@ -508,6 +521,9 @@ int main(int argc, char **argv)
|
|||||||
fmt.setSwapInterval(0);
|
fmt.setSwapInterval(0);
|
||||||
if (scFlags.testFlag(QRhiSwapChain::sRGB))
|
if (scFlags.testFlag(QRhiSwapChain::sRGB))
|
||||||
fmt.setColorSpace(QSurfaceFormat::sRGBColorSpace);
|
fmt.setColorSpace(QSurfaceFormat::sRGBColorSpace);
|
||||||
|
// Exception: The alpha size is not necessarily OpenGL specific.
|
||||||
|
if (transparentBackground)
|
||||||
|
fmt.setAlphaBufferSize(8);
|
||||||
QSurfaceFormat::setDefaultFormat(fmt);
|
QSurfaceFormat::setDefaultFormat(fmt);
|
||||||
|
|
||||||
// Vulkan setup.
|
// Vulkan setup.
|
||||||
|
@ -296,7 +296,7 @@ void Window::customRender()
|
|||||||
QRhiCommandBuffer *cb = m_sc->currentFrameCommandBuffer();
|
QRhiCommandBuffer *cb = m_sc->currentFrameCommandBuffer();
|
||||||
const QSize outputSizeInPixels = m_sc->currentPixelSize();
|
const QSize outputSizeInPixels = m_sc->currentPixelSize();
|
||||||
|
|
||||||
cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u);
|
cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u);
|
||||||
|
|
||||||
cb->setGraphicsPipeline(d.ps);
|
cb->setGraphicsPipeline(d.ps);
|
||||||
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
|
||||||
|
@ -230,7 +230,7 @@ void Window::customRender()
|
|||||||
if (!d.onScreenOnly)
|
if (!d.onScreenOnly)
|
||||||
d.liveTexCubeRenderer.queueResourceUpdates(u);
|
d.liveTexCubeRenderer.queueResourceUpdates(u);
|
||||||
|
|
||||||
cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u);
|
cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u);
|
||||||
cb->debugMarkBegin(QByteArrayLiteral("Triangle"));
|
cb->debugMarkBegin(QByteArrayLiteral("Triangle"));
|
||||||
d.triRenderer.queueDraw(cb, outputSize);
|
d.triRenderer.queueDraw(cb, outputSize);
|
||||||
cb->debugMarkEnd();
|
cb->debugMarkEnd();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user