Commit Graph

36 Commits

Author SHA1 Message Date
Kai Köhne
a5de12f0d7 Examples: Use PRIVATE CMake linkage
We (almost) only build apps, for which PRIVATE linkage makes more sense.

Change-Id: I09a509c3fb33a00cdfdede687b3f95d638f42091
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-11-30 14:48:50 +01:00
Kai Köhne
f562711c64 Examples: Use qt_standard_project_setup()
Change-Id: I0ceab08108b7e58e4e2ed25db9e3c289f5c0ddac
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-11-17 19:59:11 +01:00
Kai Köhne
bec264c15f Examples: Use Qt6:: to qualify Qt CMake packages
This is what we promote also in the documentation.

Change-Id: If91aebafe861b0c934acbb2c69afd182abc3345d
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-11-17 19:59:11 +01:00
Lucie Gérard
32df595275 Change the license of all CMakeLists.txt and *.cmake files to BSD
Task-number: QTBUG-105718
Change-Id: I5d3ef70a31235868b9be6cb479b7621bf2a8ba39
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-08-23 23:58:42 +02:00
Lucie Gérard
fb1b20eab3 Add license headers to cmake files
CMakeLists.txt and .cmake files of significant size
(more than 2 lines according to our check in tst_license.pl)
now have the copyright and license header.

Existing copyright statements remain intact

Task-number: QTBUG-88621
Change-Id: I3b98cdc55ead806ec81ce09af9271f9b95af97fa
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-08-03 17:14:55 +02:00
Lucie Gérard
05fc3aef53 Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
Files that have to be modified by hand are modified.
License files are organized under LICENSES directory.

Task-number: QTBUG-67283
Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-05-16 16:37:38 +02:00
Laszlo Agocs
68a4c5da9a Compose render-to-texture widgets through QRhi
QPlatformTextureList holds a QRhiTexture instead of GLuint. A
QPlatformBackingStore now optionally can own a QRhi and a
QRhiSwapChain for the associated window.  Non-GL rendering must use
this QRhi everywhere, whereas GL (QOpenGLWidget) can choose to still
rely on resource sharing between contexts. A widget tells that it
wants QRhi and the desired configuration in a new virtual function in
QWidgetPrivate returning a QPlatformBackingStoreRhiConfig. This is
evaluated (among a top-level's all children) upon create() before
creating the repaint manager and the QWidgetWindow.

In QOpenGLWidget what do request is obvious: it will request an
OpenGL-based QRhi. QQuickWidget (or a potential future QRhiWidget)
will be more interesting: it needs to honor the standard Qt Quick
env.vars. and QQuickWindow APIs (or, in whatever way the user
configured the QRhiWidget), and so will set up the config struct
accordingly.

In addition, the rhiconfig and surface type is (re)evaluated when
(re)parenting a widget to a new tlw. If needed, this will now trigger
a destroy - create on the tlw. This should be be safe to do in
setParent. When multiple child widgets report an enabled rhiconfig,
the first one (the first child encountered) wins. So e.g. attempting
to have a QOpenGLWidget and a Vulkan-based QQuickWidget in the same
top-level window will fail one of the widgets (it likely won't
render).

RasterGLSurface is no longer used by widgets. Rather, the appropriate
surface type is chosen.

The rhi support in the backingstore is usable without widgets as well.
To make rhiFlush() functional, one needs to call setRhiConfig() after
creating the QBackingStore. (like QWidget does to top-level windows)

Most of the QT_NO_OPENGL ifdefs are eliminated all over the place.
Everything with QRhi is unconditional code at compile time, except the
actual initialization.

Having to plumb the widget tlw's shareContext (or, now, the QRhi)
through QWindowPrivate is no longer needed.  The old approach does not
scale: to implement composeAndFlush (now rhiFlush) we need more than
just a QRhi object, and this way we no longer pollute everything
starting from the widget level (QWidget's topextra -> QWidgetWindow ->
QWindowPrivate) just to send data around.

The BackingStoreOpenGLSupport interface and the QtGui - QtOpenGL split
is all gone. Instead, there is a QBackingStoreDefaultCompositor in
QtGui which is what the default implementations of composeAndFlush and
toTexture call. (overriding composeAndFlush and co. f.ex. in eglfs
should continue working mostly as-is, apart from adapting to the
texture list changes and getting the native OpenGL texture id out of
the QRhiTexture)

As QQuickWidget is way too complicated to just port as-is, an rhi
manual test (rhiwidget) is introduced as a first step, in ordewr to
exercise a simple, custom render-to-texture widget that does something
using a (not necessarily OpenGL-backed) QRhi and acts as fully
functional QWidget (modeled after QOpenGLWidget). This can also form
the foundation of a potential future QRhiWidget.

It is also possible to force the QRhi-based flushing always,
regardless of the presence of render-to-texture widgets. To exercise
this, set the env.var. QT_WIDGETS_RHI=1. This picks a
platform-specific default, and can be overridden with
QT_WIDGETS_RHI_BACKEND. (in sync with Qt Quick) This can eventually be
extended to query the platform plugin as well to check if the platform
plugin prefers to always do flushes with a 3D API.

QOpenGLWidget should work like before from the user's perspective, while
internally it has to do some things differently to play nice and prevent
regressions with the new rendering architecture. To exercise this
better, the qopenglwidget example gets a new tab-based view (that could
perhaps replace the example's main window later on?). The openglwidget
manual test is made compatible with Qt 6, and gets a counterpart in form
of the dockedopenglwidget manual test, which is a modified version of
the cube example that features dock widgets. This is relevant in
particular because render-to-texture widgets within a QDockWidget has
its own specific quirks, with logic taking this into account, hence
testing is essential.

For existing applications there are two important consequences with
this patch in place:

- Once the rhi-based composition is enabled, it stays active for the
lifetime of the top-level window.

- Dynamically creating and parenting the first render-to-texture
widget to an already created tlw will destroy and recreate the tlw
(and the underlying window). The visible effects of this depend on the
platform.  (e.g. the window may disappear and reappear on some,
whereas with other windowing systems it is not noticeable at all -
this is not really different from similar situtions with reparenting
or when moving windows between screens, so should be acceptable in
practice)

- On iOS raster windows are flushed with Metal (and rhi) from now on
(previously this was through OpenGL by making flush() call
composeAndFlush().

Change-Id: Id05bd0f7a26fa845f8b7ad8eedda3b0e78ab7a4e
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2022-03-11 21:25:00 +01:00
Kai Köhne
57402ffb9b Examples: Remove unneeded CMake options
CMAKE_INCLUDE_CURRENT_DIR is not necessary anymore for moc since
CMake 3.8: https://cmake.org/cmake/help/latest/release/3.8.html#other-changes

CMAKE_AUTORCC should not be used anymore. Instead, we now use
qt_add_resources() or similar

Enable CMAKE_AUTOUIC only if .ui files are present.

Pick-to: 6.3
Task-number: QTBUG-87643
Change-Id: I835e2994cd5dba9918136999499b9077961b616c
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-01-24 14:00:00 +01:00
Kai Köhne
80a76df178 Examples: Fix whitespace issues in CMakeLists.txt
Pick-to: 6.3
Change-Id: I8e6dd1f250f8be6016ee4164cb2ab7034cbb1203
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-12-13 14:16:26 +00:00
Kai Köhne
51f22a3a04 Examples: Remove remaining conversion markers in CMakeLists.txt
Pick-to: 6.3
Change-Id: Ia5d474a3efd6aadbd0ef1537318f2f24e6c24fee
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-12-13 14:16:26 +00:00
Kai Köhne
7024e7a627 Examples: Use find_package(Qt6 REQUIRED COMPONENTS ...) idiom
Also consolidate several find_package(Qt6 ...) calls in one call.

Task-number: QTBUG-98867
Change-Id: Idfd5e71f46d4489fac7411cbfadb84437a0658f3
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2021-12-10 10:48:26 +01:00
Joerg Bornemann
ff00ef6410 Raise cmake_minimum_required to VERSION 3.16 in examples
Pick-to: 6.2
Task-number: QTBUG-95636
Change-Id: I1270b4846d8a23bc3563b6942c0910e095d2be4a
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-08-17 19:18:54 +02:00
Alexandru Croitor
397b372517 CMake: Regenerate examples to set the WIN32_EXECUTABLE property
As well as the MACOSX_BUNDLE properties as necessary.

Task-number: QTBUG-87664
Task-number: QTBUG-86827
Change-Id: I7677449a26d51fa853bd67bab6b3b61afbd2b12f
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2020-10-27 12:49:39 +01:00
Alexandru Croitor
2ffbac7cb2 CMake: Regenerate examples to use qt_add_executable
Task-number: QTBUG-87661
Change-Id: I0dacfdc97a3fb7d88da85b67800f2c1b084d869b
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2020-10-19 11:51:47 +02:00
Volker Hilsheimer
1c76aa077e Get rid of all usage of QApplication:desktop
Use QScreen APIs instead.

Change-Id: Ie99af94fe4292223dbb165b3f5c1b74e8fe0498b
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2020-10-14 06:38:43 +02:00
Alexandru Croitor
74cb331af3 CMake: Regenerate examples
Change-Id: I1c51b10af4e2b26f54740f257164c56a0e2a03ce
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2020-07-09 09:38:28 +02:00
Jarek Kobus
29c99bddbf Use QList instead of QVector in examples
Task-number: QTBUG-84469
Change-Id: Id14119168bb1bf11f99bda7ef6ee9cf51bcfab2e
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
2020-06-23 14:01:11 +02:00
Volker Hilsheimer
44fb925f50 Phase 2 of removing QDesktopWidget
Remove QDestopWidget public header, simplify the implementation that
maintains a Qt::Desktop type QWidget for each QScreen, and turn
QWidget's initial target screen into a QScreen pointer.

QApplication::desktop() now takes an optional QScreen pointer, and
returns a QWidget pointer, so that applications and widgets can get
access to the root widget for a specific screen without having to
resort to private APIs.

QDesktopWidgetPrivate implementations to look up a screen for an index,
widget, or point are now all inline functions that thinly wrap
QGuiApplication::screens/screenAt calls. We should consider adding those
as convenience APIs to QScreen instead.

Note that QWidget::screen is assumed to return a valid pointer; there is
code that handles the case that it returns nullptr (but also code that
trusts that it never is nullptr), so this needs to be defined, verified
with tests, and asserted. We can then simplify the code further.

Change-Id: Ifc89be65a0dce265b6729feaf54121c35137cb94
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2020-06-08 20:29:49 +02:00
Shawn Rutledge
a061a64642 Replace calls to deprecated QEvent accessor functions
Many of these were generated by clazy using the new qevent-accessors check.

Change-Id: Ie17af17f50fdc9f47d7859d267c14568cc350fd0
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2020-06-08 19:11:51 +02:00
Johan Klokkhammer Helsing
00eeed234f Move QOpenGLWidget from QtOpenGL to its own module
Same pattern as QtQuickWidgets. Gets rid of QtOpenGL's dependency on QtWidgets.

Task-number: QTBUG-74409
Change-Id: I4f9b55c23e25a1e0519734037b768a16e870c7d2
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
2020-02-18 09:22:51 +01:00
Leander Beernaert
48c82e90af Post Merge Fixes
Change-Id: I1e06c01b76b119c3f23b6e6ecbaae8df719b70ce
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2020-01-24 12:29:18 +00:00
Leander Beernaert
502d3d6744 Merge remote-tracking branch 'origin/dev' into merge-dev
Change-Id: I31b761cfd5ea01373c60d02a5da8c33398d34739
2020-01-24 13:17:33 +01:00
Johan Klokkhammer Helsing
d107706ab9 Move QOpenGLWidget from QtWidgets to QtOpenGL
Task-number: QTBUG-74409
Change-Id: I98a4f8a9e1d439bfdc24eb2910385273cedecd29
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
2019-12-12 16:06:31 +01:00
Alexandru Croitor
440286655e Merge remote-tracking branch 'origin/dev' into wip/cmake
Change-Id: I4a78428a8ea273b6960792e3b8043f816fa37fcf
2019-10-14 17:46:34 +02:00
Frederik Gladhorn
d8c3375dbd cmake: add examples/opengl
Fixes: QTBUG-78164
Change-Id: Iccc8bb1354d2362c950de17a6c00e00f95272967
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Qt CMake Build Bot
2019-10-07 07:22:17 +00:00
Christian Ehrlicher
b0042601ed Cleanup QtOpenGL examples
Cleanup the OpenGL examples
 - use nullptr (clang-tidy)
 - use member-initialization
 - avoid redundant checks for != nullptr when deleting a pointer

Change-Id: I3e4702690ed79e71c3e952d51ceef83b907b45b7
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
2019-09-30 22:16:27 +02:00
Friedemann Kleint
e29b72384b Hello GL2 example: Fix exit crash
Bail out of cleanup() when run 2nd time.

Task-number: QTBUG-60626
Change-Id: I8a9be2fcfb0e8a5584ce8ed7952affff24bd2a33
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
2017-09-05 10:55:11 +00:00
Friedemann Kleint
b3717fc7f0 OpenGL examples: Introduce QCommandLineParser
Task-number: QTBUG-60626
Change-Id: I6d102327c89206fcdce10f3ac04e112270b11ad2
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
2017-09-05 10:54:15 +00:00
hjk
40a54bf565 Examples: Replace 'Q_DECL_OVERRIDE' by 'override'
Examples should demonstrate best practice, and we can use the keyword
directly nowadays.

Change-Id: I1f122e5caceca17290757ffbaf3d660e7daa9ae4
Reviewed-by: Topi Reiniö <topi.reinio@theqtcompany.com>
2016-06-15 09:32:30 +00:00
Jani Heikkinen
cd46a2daf5 Unify license header usage.
Update files using old header.LGPL3 to header.LGPL
Update files using old FDL template to use new one
Update files using old BSD template to use new one

Change-Id: I36a78272516f9953d02956522f285b40adfc8915
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-03-29 10:20:03 +00:00
Laszlo Agocs
b46ffbca0c Fix up QOpenGLWidget transparency support
The glColorMask call was troublesome. In addition, the Qt::WA_TranslucentBackground
was misinterpreted and recommended misleadingly in the documentation. The hellogl2
example's --transparent argument was disfunctional in practice.

Replace glColorMask with glBlendFuncSeparate. The hellogl2 example and the docs are
now corrected wrt enabling semi-transparency in a QOpenGLWidget that is not a top-level
(which is the most common case).

Task-number: QTBUG-47276
Change-Id: I6f40e732d455f5efcf158649ac9a52ff9f240e85
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
2015-09-24 12:51:37 +00:00
Benjamin Summerton
2a526b12ce Updated Hello GL2 Example to new Signal/Slot syntax
The Hello GL2 Example was using the older Signal/Slot syntax that made
use of the macros `SIGNAL()` and `SLOT()`.  I changed it to the newer
one.

Change-Id: I8e55015383847a04b07f751fe9fc94b81956a896
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
2015-06-29 11:30:01 +00:00
Jani Heikkinen
2b75c156b6 Updated BSD licensed file headers
Change-Id: I6441ff931dbd33b698d762e6f6784898f3f60fe7
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2015-02-15 07:41:17 +00:00
Jani Heikkinen
83a5694dc2 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.

Outdated header.LGPL removed (use header.LGPL21 instead)

Old header.LGPL3 renamed to header.LGPL3-COMM to match actual licensing
combination. New header.LGPL-COMM taken in the use file which were
using old header.LGPL3 (src/plugins/platforms/android/extract.cpp)

Added new header.LGPL3 containing Commercial + LGPLv3 + GPLv2 license
combination

Change-Id: I6f49b819a8a20cc4f88b794a8f6726d975e8ffbe
Reviewed-by: Matti Paaso <matti.paaso@theqtcompany.com>
2015-02-11 06:49:51 +00:00
Laszlo Agocs
5621a7c501 Fix composition for windows with alpha
While we will cover the entire surface with our textured quads, the clear
is still necessary in order to make top-levels with TranslucentBackground
render correctly: We don't want to blend transparent areas with undefined
content that is in the surface's framebuffer.

Blending is problematic for alpha values. We now prevent the blended alpha
from being written out. This ensures that in examples like qquickviewcomparison,
where the backingstore image contains an alpha of 0.5 while the QQuickWidget
texture 1.0, the result is still an alpha value of 1.0 in the final image.
Writing out an alpha of 0.5 would break on systems where windows get an alpha
buffer by default.

hellogl2 can now take a --transparent parameter which makes the QOpenGLWidget
being cleared to transparent in order to verify it works in combination
with Qt::WA_TranslucentBackground.

The swapped red and blue problem is also corrected. RGBA8888 does not need
swizzling. The only format that needs this is RGB32.

Task-number: QTBUG-40716
Change-Id: I54a9fd3a91a1b59575b38cdb908835315514e40f
Reviewed-by: Jørgen Lind <jorgen.lind@digia.com>
2014-08-13 16:14:19 +02:00
Laszlo Agocs
611558d877 Modernize the OpenGL examples
Change them to use QOpenGLWidget and QOpenGLTexture.
Advocate also the usage of VBOs.

Hopeless examples, that rely on the fixed pipeline and will
not compile or work in ES and dynamic builds, are moved to
a "legacy" directory. The documentation pages for these are
removed. This long due change avoids the confusion newcomers
experience when trying to get started with Qt 5 and OpenGL.

hellowindow's behavior is changed to open a single window only
by default. The old default behavior, that opened three windows
on platforms that supported both MultipleWindows & ThreadedOpenGL,
can be requested by passing --multiple. --single is removed since it
is the default now. This plays much nicer with drivers that have
issues with threading.

In addition, say hello to hellogl2.

This is the old hellogl example updated to use QOpenGLWidget and
OpenGL 2. It also has a mainwindow with multiple (un)dockable widgets
containing the OpenGL widgets. This helps testing the behavior when
the top-level of the QOpenGLWidget changes and provides a very
important example of how to do proper resource management in this case.
(must use aboutToBeDestroyed() of the context, since the context goes
away and is replaced by a new one on every dock/undock)

As a bonus, the logo is now real 3D, no more orthographic nonsense.

Launch with --multisample to request 4x MSAA.

Launch with --coreprofile to request 3.2 Core. In this particular example
the shaders are present in both versions and there is a VAO so the application
is functional with core profile contexts.

Change-Id: Id780a80cb0708ef164cc172450ed74050f065596
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
2014-08-12 07:47:23 +02:00