Commit Graph

85 Commits

Author SHA1 Message Date
Laszlo Agocs 400d176760 Allow redirecting QRhi-based rendering via QQuickRenderControl
Implement the Qt 6 TODO for using an externally-provided render target
when rendering the scene via QRhi.

And say hello to QQuickRenderTarget. This class exists to allow
potentially extending later what a "render target" consists
of. Instead of hard-coding taking a single void * in the
setRenderTarget() function, it takes a (implicitly shared,
d-pointered) QQuickRenderTarget, which in turn can be created via
static factory functions - of which new ones can be added later on.

The new version of QQuickWindow::setRenderTarget() takes a
QQuickRenderTarget.

QQuickRenderControl gets a new initialize() variant, and a few extra
functions (beginFrame(), endFrame()). This allows it to, by using
QSGRhiSupport internally, create a QRhi under the hood.

As a bonus, this also fixes an existing scenegraph resource leak when
destroying the QQuickRenderControl.

The qquickrendercontrol autotest is extended, with a QRhi-based test
case that is executed for all of the QRhi backends that succeed to
initialize.  This is the internal verification. In addition, there is
a Vulkan-based one that creates its own VkDevice, VkImage, and
friends, and then uses Qt Quick with the same Vulkan device, targeting
the VkImage. This test verifies the typical application use
case. (sadly, life is too short to waste it on writing Vulkan
boilerplate for an on-screen version of this, but we have the D3D11
example instead)

What QQuickRenderControl loses, when used in combination with QRhi, is
the grab() function. This never made much sense as a public API:
QQuickWindow::grabWindow() call this when the window is associated
with a rendercontrol, so as a public API QQuickRenderControl::grab()
is redundant, because one gets the same result via the standard
QQuickWindow API. It is now made private.

More importantly, reading back the content is no longer supported,
unless the 'software' backend is in use. The reasoning here is that,
if the client of the API manages and provides the render target (as
abstracted by QQuickRenderTarget), it is then expected to be capable
of reading back the content in whatever way it sees fit, because it
owns and manages the resource (e.g. the texture) in the first
place. Providing fragile convenience functions for this is not
reasonable anymore, and was questionable even with OpenGL, given that
it is not future proof - what if the target is suddenly a floating
point texture, for instance? The software backend case makes sense
because that relies on private APIs - and has no render target concept
either - so there the same cannot be achieved by applications by
relying on public APIs only.

Another new class is QQuickGraphicsDevice. This is very similar to
QQuickRenderTarget, it is a simple container capable of holding a set
of of native objects, mostly in the form of void*s, with future
extensibility thanks to the static factory functions. (examples of
native object sets would be a ID3D11Device + ID3D11DeviceContext, or a
QOpenGLContext, or a MTLDevice + MTLCommandQueue, or a number of
Vulkan device-related objects, etc.)  This allows one to specify that
the QRhi created under the hood (either by QQuickRenderControl or by
the render loop) should use an existing graphics device (i.e. it is
basically a public wrapper for values that go into a QRhi*InitParams
under the hood).

QQuickRenderTarget and QQuickGraphicsDevice are both demonstrated in a
new example: rendercontrol_d3d11. We choose D3D11 because it is
reasonably simple to set up a renderer with a window, and, because
there is known user demand for Qt Quick - external D3D engine
interop. Passing in the custom engine's own ID3D11Device and
ID3D11DeviceContext is essential: the texture (ID3D11Texture2D) Qt
Quick is targeting would not be usable if Qt Quick's QRhi was using a
different ID3D11Device.

Task-number: QTBUG-78595
Change-Id: I5dfe7f6cf1540daffc2f11136be114a08e87202b
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-04-11 18:23:55 +02:00
Laszlo Agocs 1a1028a1e4 Move legacy rendercontrol example into a subdirectory
...called rendercontrol_opengl under examples/quick/rendercontrol. This
example is going to be migrated to support operating with RHI-on-OpenGL
later on.

Additionally, we can this way introduce more rendercontrol examples in
the future, for example to show how to do things with Vulkan, Metal,
D3D.

Task-number: QTBUG-78595
Change-Id: I7f5243b1f86e62949400107bf12bfa07b17b1031
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-03-24 17:03:12 +01:00
Leander Beernaert 9e633bbda7 Regenerate Examples
Change-Id: I2fbfb44bbb6d667e022bffb480feaf74ff0d0a5e
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-10-14 09:09:55 +00:00
Leander Beernaert bf58a1cc04 Update Examples with lowercase qt6_add_resources()
Re-run pro2cmake on all exampls.

Change-Id: Iafd1092beff023b407a8f29c2a5b651f2e534b75
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-09-20 08:38:06 +00:00
Leander Beernaert b938edcfb3 Convert Examples
This patch converts all examples in qtdeclarative except for a few
exceptions which require a public facing qml plugin api.

Change-Id: I2cd2b1bb455be8b48796893a8235dea7f8b35aa2
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-08-23 13:51:06 +00:00
Paul Wicking ed3a93feee Doc: Add missing dots (qtdeclarative)
Task-number: QTBUG-68933
Change-Id: Ibb5aa227e82825085e7214e17dcffcb17fd44157
Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
2018-06-19 12:44:48 +00:00
Shawn Rutledge 499ec43937 use nullptr consistently (clang-tidy)
From now on we prefer nullptr instead of 0 to clarify cases where
we are assigning or testing a pointer rather than a numeric zero.

Also, replaced cases where 0 was passed as Qt::KeyboardModifiers
with Qt::NoModifier (clang-tidy replaced them with nullptr, which
waas wrong, so it was just as well to make the tests more readable
rather than to revert those lines).

Change-Id: I4735d35e4d9f42db5216862ce091429eadc6e65d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-02-26 07:13:18 +00:00
Liang Qi 692ff26085 Merge remote-tracking branch 'origin/5.10' into dev
Change-Id: I1ed923d72566af663555898c3ec708191eef8ae9
2017-11-06 18:05:07 +01:00
Liang Qi 15dd1b7883 Merge remote-tracking branch 'origin/5.9' into 5.10
Conflicts:
	src/qml/qml/qqmlimport.cpp
	src/qml/qml/qqmlimport_p.h
	src/qml/qml/qqmltypenamecache.cpp

Done-with: Ulf Hermann<ulf.hermann@qt.io>
Change-Id: I41ba7a592b2659ddf53da6952ea3b456a7bba319
2017-10-24 11:13:09 +02:00
Friedemann Kleint f82c4de515 Qt Quick examples: Introduce QCommandLineParser
Task-number: QTBUG-60630
Change-Id: Iaf24e09fdec92f8af495a1288685f266c39be4a7
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
2017-10-18 09:45:59 +00:00
Kai Koehne 341a04377b Fix outdated FDL license header
Change-Id: I76dccf547de40b5e72fd7abaa062fa96cb2c118a
Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io>
2017-10-17 11:18:21 +00:00
Kai Koehne ea6cd0de3c Fix outdated BSD license header
Change-Id: Icc08925454445fc9497fb3bfd2c26efe90605983
Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io>
2017-10-17 11:18:11 +00:00
Kevin Funk d8b0ad3506 Replace Q_NULLPTR with nullptr
Change-Id: I0c01862dbb475494c84e39c695cb563df8cbcfa8
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-09-27 08:37:48 +00:00
Kevin Funk 681f93c74d Replace Q_DECL_OVERRIDE with override
Change-Id: I176f91a8c51e81a2df3fe91733118261491223ee
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-09-25 08:27:35 +00:00
Laszlo Agocs 13fc05fde8 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>
2017-03-17 11:26:07 +00:00
Laszlo Agocs e8801e7c09 Enable shader disk cache in Qt Quick
Change-Id: I14ee97ee75664c5dfcd229a5be2be6294c936b2c
Task-number: QTBUG-55496
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2016-11-27 22:10:41 +00:00
Anton Kudryavtsev 2f9db0a631 examples: replace 'foreach' with 'range for'
While touching the code, replace QStringLiteral
with QL1S in QStringBuilder expression.

Change-Id: I2519b254d82453e1c9bd5b834c0bd78e5c026f83
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2016-09-03 16:50:01 +00:00
Liang Qi 20a51e87fd Merge remote-tracking branch 'origin/5.6' into dev
Conflicts:
	.qmake.conf

Change-Id: I356ec83cf687bd2833f9a7c5e820d56b1efa8979
2016-02-12 10:53:43 +01:00
Jan Arve Saether 1e1ad53904 Don't call render during expose, since we are already calling render().
This causes drawing artifacts on Win7 with ANGLES d3d11 backend.

Task-number: QTBUG-49923

Change-Id: I801282c4359bd485d1894e409e34393b4264d994
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
2016-02-05 10:56:41 +00:00
Jani Heikkinen aad500cafb Updated license headers
From Qt 5.7 -> examples are lisenced under BSD license, see
http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/

Updated license headers to use new BSD header instead of LGPL21 one
(in those files which will be under BSD)

Change-Id: I09ba19590e9425d5116a6c27cbc183debb485dde
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-01-20 11:46:11 +00:00
Friedemann Kleint 1e2e356f0f Port examples to new connection syntax.
Change-Id: I121c59ac0ad56acb4cd54b99ecd37567368385ce
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
2015-07-22 22:16:19 +00:00
Laszlo Agocs e3f56a8b8d Fix rendercontrol example for screens with different dpr
renderWindow() was not reimplemented in the example. This is pretty
bad since renderWindowFor() fails to find a window and thus falls
back to using the default device pixel ratio (which is the highest
dpr present in the system). The result is broken content from Quick
because it operates with a dpr of 2 any time a retina screen is connected,
even when the example's own QWindow is placed on a normal screen.

Add also a note to the QQuickRenderControl docs because it is easy to
overlook.

Task-number: QTBUG-45613
Change-Id: I31bf92ec285f3d9867a5604a4b4e3bea73791932
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
2015-04-28 15:02:06 +00:00
Laszlo Agocs 4da32851de Recreate the FBO on dpr change in rendercontrol example
Even when the window size is not changing. This provides a useful
example of connecting to the screenChanged() signal.

Task-number: QTBUG-45613
Change-Id: I0652838d9c0cfec8b64b3422997159f385445b20
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
2015-04-28 15:01:49 +00:00
Laszlo Agocs facf3b15b3 Avoid showing garbage when resizing the rendercontrol example
The threaded variant was working well since that triggers a render
when resizing. The single threaded version lacked this and this
resulted in showing garbage on OS X at least since the new FBO had
undefined contents. Avoid this.

Task-number: QTBUG-45613
Change-Id: Ibb3d3f7640bab5da913df1c0c63cc3a3aaafb140
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
2015-04-28 15:01:26 +00:00
Holger Hans Peter Freyther ca4dbd5675 Address uninitialized pointer variables
Coverity CID 10721, 84861, 86705, 85424, 85422,
85259, 84863, 84857

Change-Id: Ia86970b5ac4e0be9de01b79b618d33011da6a328
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-04-20 04:09:59 +00:00
Jani Heikkinen 20c207815a Fixed license headers
Change-Id: I4d5640ff95e1361ec7e65fb3e87d7726d8185ff5
Reviewed-by: Sergio Ahumada <sahumada@texla.cl>
2015-02-17 13:33:18 +00:00
Jani Heikkinen c5796292ad Update copyright headers
Qt copyrights are now in The Qt Company, so we could update the source
code headers accordingly. In the same go we should also fix the links to
point to qt.io.

Change-Id: I61120571787870c0ed17066afb31779b1e6e30e9
Reviewed-by: Iikka Eklund <iikka.eklund@theqtcompany.com>
2015-02-12 10:28:11 +00:00
Laszlo Agocs fae16f9d2f Prevent windows outside the gui thread in rendercontrol example
In the multithreaded case we attempted to create QWindows outside
the gui thread on platforms where QOffscreenSurface is backed by
the hidden QWindow in the absence of a better solution. This has
to be avoided. Therefore, pass a suitable surface from the gui
thread instead.

This will avoid "Attempting to create QWindow-based QOffscreenSurface
outside the gui thread." type of warnings when running on OS X with
--threaded.

Change-Id: Ie3ebeeeaa9e6bdf83e763e40213e2940fbfde667
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
Reviewed-by: Jørgen Lind <jorgen.lind@theqtcompany.com>
2015-01-07 13:21:00 +01:00
Laszlo Agocs 5a7b256a62 rendercontrol example: calculate fbo size correctly
Change-Id: Ida1e7cb9426d31ed6406dd6db86f5834f0f1a6ac
Reviewed-by: Jørgen Lind <jorgen.lind@theqtcompany.com>
2014-12-18 10:15:26 +01:00
Laszlo Agocs 92a1c1f60c rendercontrol example: Add missing flushes
Otherwise we will show broken output with some drivers.
QQuickWidget does this already.

Change-Id: I5193595c4606d0497dbe85f6f8c670618ca366e9
Reviewed-by: Jørgen Lind <jorgen.lind@theqtcompany.com>
2014-12-17 10:17:12 +01:00
Laszlo Agocs 6179550a0c Support threading with QQuickRenderControl
Reorganize the rendercontrol example to demonstrate both the single
and multi threaded approaches.

A small helper function is introduced to the QQuickRenderControl API:
The QSGRenderContext has to live on the render thread. Previously there
was no way for applications to move it to the desired thread. This is
now possible.

Pass --threaded to the rendercontrol example to use a separate render thread.

[ChangeLog][QtQuick] QQuickRenderControl can now be used to render the Qt Quick
scene on a dedicated render thread, similarly to how the built-in threaded render
loop operates.

Task-number: QTBUG-42813
Change-Id: I01c3b2ffca8a174d9d2c267a51f2e484ed7b34b3
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Reviewed-by: Jørgen Lind <jorgen.lind@theqtcompany.com>
2014-12-12 12:19:14 +01:00
Laszlo Agocs 72eef1da9e Avoid crashing the rendercontrol example on exit
Task-number: QTBUG-41278
Change-Id: I456467698e66fb28f1bf6a05d85771ac25f454d0
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
2014-09-18 10:06:57 +02:00
Laszlo Agocs a02cd6d37b Tune the colors in the rendercontrol example
Change-Id: I904782e6a54c8df63a2e187cdfed5a3193ff2a54
Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
2014-09-10 20:20:15 +02:00
Jani Heikkinen e7ceacda70 Update license headers and add new licenses
- Renamed LICENSE.LGPL to LICENSE.LGPLv21
- Added LICENSE.LGPLv3 & LICENSE.GPLv2
- Removed LICENSE.GPL

Change-Id: I84a565e2e0caa3b76bf291a7d188a57a4b00e1b0
Reviewed-by: Jani Heikkinen <jani.heikkinen@digia.com>
2014-08-25 11:28:46 +02:00
Laszlo Agocs 745a71196c Make QQuickRenderControl public
QQuickRenderControl allows rendering Qt Quick 2 scenes into framebuffer
objects which can then be used in arbitrary ways in Qt-based or 3rd party
OpenGL renderers.

[ChangeLog][QtQuick] Introduced QQuickRenderControl as a public API.

Task-number: QTBUG-37944
Change-Id: I84262243b261b35cefdf67ec6bba8127a0f29275
Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
2014-06-24 14:22:19 +02:00