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 *) ...@@ -363,12 +363,13 @@ void Window::exposeEvent(QExposeEvent *)
render(); render();
} }
// stop pushing frames when not exposed (on some platforms this is essential, optional on others) // stop pushing frames when not exposed (or size is 0)
if (!isExposed() && m_running) if ((!isExposed() || (m_hasSwapChain && m_sc->surfacePixelSize().isEmpty())) && m_running)
m_notExposed = true; m_notExposed = true;
// continue when exposed again // continue when exposed again and the surface has a valid size.
if (isExposed() && m_running && m_notExposed) { // 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_notExposed = false;
m_newlyExposed = true; m_newlyExposed = true;
render(); render();
......
...@@ -566,21 +566,41 @@ void Renderer::render(bool newlyExposed, bool wakeBeforePresent) ...@@ -566,21 +566,41 @@ void Renderer::render(bool newlyExposed, bool wakeBeforePresent)
m_proj.translate(0, 0, -4); 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(); buildOrResizeSwapChain();
if (!m_hasSwapChain) if (!m_hasSwapChain) {
wakeUpIfNeeded();
return; return;
}
QRhi::FrameOpResult result = r->beginFrame(m_sc); QRhi::FrameOpResult result = r->beginFrame(m_sc);
if (result == QRhi::FrameOpSwapChainOutOfDate) { if (result == QRhi::FrameOpSwapChainOutOfDate) {
buildOrResizeSwapChain(); buildOrResizeSwapChain();
if (!m_hasSwapChain) if (!m_hasSwapChain) {
wakeUpIfNeeded();
return; return;
}
result = r->beginFrame(m_sc); result = r->beginFrame(m_sc);
} }
if (result != QRhi::FrameOpSuccess) if (result != QRhi::FrameOpSuccess) {
wakeUpIfNeeded();
return; return;
}
QRhiCommandBuffer *cb = m_sc->currentFrameCommandBuffer(); QRhiCommandBuffer *cb = m_sc->currentFrameCommandBuffer();
const QSize outputSize = m_sc->currentPixelSize(); const QSize outputSize = m_sc->currentPixelSize();
...@@ -610,11 +630,7 @@ void Renderer::render(bool newlyExposed, bool wakeBeforePresent) ...@@ -610,11 +630,7 @@ void Renderer::render(bool newlyExposed, bool wakeBeforePresent)
cb->endPass(); cb->endPass();
// make sure the main/gui thread is not blocked when issuing the Present (or equivalent) wakeUpIfNeeded();
if (wakeBeforePresent) {
thread->cond.wakeOne();
thread->mutex.unlock();
}
r->endFrame(m_sc); 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