Commit 28730ead authored by Laszlo Agocs's avatar Laszlo Agocs

multiwindow examples: handle zero size

parent ccb04e70
......@@ -363,12 +363,13 @@ void Window::exposeEvent(QExposeEvent *)
render();
}
// stop pushing frames when not exposed (on some platforms this is essential, optional on others)
if (!isExposed() && m_running)
// stop pushing frames when not exposed (or size is 0)
if ((!isExposed() || (m_hasSwapChain && m_sc->surfacePixelSize().isEmpty())) && m_running)
m_notExposed = true;
// continue when exposed again
if (isExposed() && m_running && m_notExposed) {
// continue when exposed again and the surface has a valid size.
// note that the surface size can be (0, 0) even though size() reports a valid one...
if (isExposed() && m_running && m_notExposed && !m_sc->surfacePixelSize().isEmpty()) {
m_notExposed = false;
m_newlyExposed = true;
render();
......
......@@ -566,21 +566,41 @@ void Renderer::render(bool newlyExposed, bool wakeBeforePresent)
m_proj.translate(0, 0, -4);
};
if (newlyExposed || m_sc->currentPixelSize() != m_sc->surfacePixelSize())
auto wakeUpIfNeeded = [wakeBeforePresent, this] {
// make sure the main/gui thread is not blocked when issuing the Present (or equivalent)
if (wakeBeforePresent) {
thread->cond.wakeOne();
thread->mutex.unlock();
}
};
const QSize surfaceSize = m_sc->surfacePixelSize();
if (surfaceSize.isEmpty()) {
wakeUpIfNeeded();
return;
}
if (newlyExposed || m_sc->currentPixelSize() != surfaceSize)
buildOrResizeSwapChain();
if (!m_hasSwapChain)
if (!m_hasSwapChain) {
wakeUpIfNeeded();
return;
}
QRhi::FrameOpResult result = r->beginFrame(m_sc);
if (result == QRhi::FrameOpSwapChainOutOfDate) {
buildOrResizeSwapChain();
if (!m_hasSwapChain)
if (!m_hasSwapChain) {
wakeUpIfNeeded();
return;
}
result = r->beginFrame(m_sc);
}
if (result != QRhi::FrameOpSuccess)
if (result != QRhi::FrameOpSuccess) {
wakeUpIfNeeded();
return;
}
QRhiCommandBuffer *cb = m_sc->currentFrameCommandBuffer();
const QSize outputSize = m_sc->currentPixelSize();
......@@ -610,11 +630,7 @@ void Renderer::render(bool newlyExposed, bool wakeBeforePresent)
cb->endPass();
// make sure the main/gui thread is not blocked when issuing the Present (or equivalent)
if (wakeBeforePresent) {
thread->cond.wakeOne();
thread->mutex.unlock();
}
wakeUpIfNeeded();
r->endFrame(m_sc);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment