aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2017-03-07 19:52:34 +0100
committerLaszlo Agocs <laszlo.agocs@qt.io>2017-03-17 11:26:07 +0000
commit13fc05fde8cde6a81d3cf3161fa34cf9d3652eb2 (patch)
treee2c01385a9d3e8600346cc50102601fd869f3516 /examples
parente7a6544225a5ab3749230fc6783a5145e02dbe32 (diff)
Document and demo that fboId can be 0
...in QQuickWindow::setRenderTarget(). The rendercontrol example is extended with a --onscreen command line argument that can be used to request rendering to the default framebuffer of the window. Change-Id: I7a500d1585dee8334b902fb1dddcb1cb21a2e038 Task-number: QTBUG-59340 Reviewed-by: Gunnar Sletta <gunnar@crimson.no>
Diffstat (limited to 'examples')
-rw-r--r--examples/quick/rendercontrol/window_singlethreaded.cpp46
-rw-r--r--examples/quick/rendercontrol/window_singlethreaded.h2
2 files changed, 39 insertions, 9 deletions
diff --git a/examples/quick/rendercontrol/window_singlethreaded.cpp b/examples/quick/rendercontrol/window_singlethreaded.cpp
index ef8f2fed43..bd4de9a7cb 100644
--- a/examples/quick/rendercontrol/window_singlethreaded.cpp
+++ b/examples/quick/rendercontrol/window_singlethreaded.cpp
@@ -82,6 +82,10 @@ WindowSingleThreaded::WindowSingleThreaded()
{
setSurfaceType(QSurface::OpenGLSurface);
+ // The rendercontrol does not necessarily need an FBO. Demonstrate this
+ // when requested.
+ m_onscreen = QCoreApplication::arguments().contains(QStringLiteral("--onscreen"));
+
QSurfaceFormat format;
// Qt Quick may need a depth and stencil buffer. Always make sure these are available.
format.setDepthBufferSize(16);
@@ -164,8 +168,14 @@ void WindowSingleThreaded::createFbo()
// The scene graph has been initialized. It is now time to create an FBO and associate
// it with the QQuickWindow.
m_dpr = devicePixelRatio();
- m_fbo = new QOpenGLFramebufferObject(size() * m_dpr, QOpenGLFramebufferObject::CombinedDepthStencil);
- m_quickWindow->setRenderTarget(m_fbo);
+ if (!m_onscreen) {
+ m_fbo = new QOpenGLFramebufferObject(size() * m_dpr, QOpenGLFramebufferObject::CombinedDepthStencil);
+ m_quickWindow->setRenderTarget(m_fbo);
+ } else {
+ // Special case: No FBO. Render directly to the window's default framebuffer.
+ m_onscreenSize = size() * m_dpr;
+ m_quickWindow->setRenderTarget(0, m_onscreenSize);
+ }
}
void WindowSingleThreaded::destroyFbo()
@@ -176,7 +186,10 @@ void WindowSingleThreaded::destroyFbo()
void WindowSingleThreaded::render()
{
- if (!m_context->makeCurrent(m_offscreenSurface))
+ QSurface *surface = m_offscreenSurface;
+ if (m_onscreen)
+ surface = this;
+ if (!m_context->makeCurrent(surface))
return;
// Polish, synchronize and render the next frame (into our fbo). In this example
@@ -195,7 +208,10 @@ void WindowSingleThreaded::render()
m_quickReady = true;
// Get something onto the screen.
- m_cubeRenderer->render(this, m_context, m_quickReady ? m_fbo->texture() : 0);
+ if (!m_onscreen)
+ m_cubeRenderer->render(this, m_context, m_quickReady ? m_fbo->texture() : 0);
+ else
+ m_context->swapBuffers(this);
}
void WindowSingleThreaded::requestUpdate()
@@ -237,7 +253,10 @@ void WindowSingleThreaded::run()
updateSizes();
// Initialize the render control and our OpenGL resources.
- m_context->makeCurrent(m_offscreenSurface);
+ QSurface *surface = m_offscreenSurface;
+ if (m_onscreen)
+ surface = this;
+ m_context->makeCurrent(surface);
m_renderControl->initialize(m_context);
m_quickInitialized = true;
}
@@ -266,7 +285,8 @@ void WindowSingleThreaded::exposeEvent(QExposeEvent *)
{
if (isExposed()) {
if (!m_quickInitialized) {
- m_cubeRenderer->render(this, m_context, m_quickReady ? m_fbo->texture() : 0);
+ if (!m_onscreen)
+ m_cubeRenderer->render(this, m_context, m_quickReady ? m_fbo->texture() : 0);
startQuick(QStringLiteral("qrc:/rendercontrol/demo.qml"));
}
}
@@ -274,7 +294,10 @@ void WindowSingleThreaded::exposeEvent(QExposeEvent *)
void WindowSingleThreaded::resizeFbo()
{
- if (m_rootItem && m_context->makeCurrent(m_offscreenSurface)) {
+ QSurface *surface = m_offscreenSurface;
+ if (m_onscreen)
+ surface = this;
+ if (m_rootItem && m_context->makeCurrent(surface)) {
delete m_fbo;
createFbo();
m_context->doneCurrent();
@@ -287,8 +310,13 @@ void WindowSingleThreaded::resizeEvent(QResizeEvent *)
{
// If this is a resize after the scene is up and running, recreate the fbo and the
// Quick item and scene.
- if (m_fbo && m_fbo->size() != size() * devicePixelRatio())
- resizeFbo();
+ if (!m_onscreen) {
+ if (m_fbo && m_fbo->size() != size() * devicePixelRatio())
+ resizeFbo();
+ } else {
+ if (m_onscreenSize != size() * devicePixelRatio())
+ resizeFbo();
+ }
}
void WindowSingleThreaded::handleScreenChange()
diff --git a/examples/quick/rendercontrol/window_singlethreaded.h b/examples/quick/rendercontrol/window_singlethreaded.h
index 534d6b9bc3..4736f036ad 100644
--- a/examples/quick/rendercontrol/window_singlethreaded.h
+++ b/examples/quick/rendercontrol/window_singlethreaded.h
@@ -97,6 +97,8 @@ private:
QTimer m_updateTimer;
CubeRenderer *m_cubeRenderer;
qreal m_dpr;
+ bool m_onscreen;
+ QSize m_onscreenSize;
};
#endif