summaryrefslogtreecommitdiffstats
path: root/examples/gui
diff options
context:
space:
mode:
Diffstat (limited to 'examples/gui')
-rw-r--r--examples/gui/CMakeLists.txt2
-rw-r--r--examples/gui/doc/src/rasterwindow.qdoc1
-rw-r--r--examples/gui/doc/src/rhiwindow.qdoc6
-rw-r--r--examples/gui/rasterwindow/CMakeLists.txt21
-rw-r--r--examples/gui/rhiwindow/CMakeLists.txt21
-rw-r--r--examples/gui/rhiwindow/main.cpp14
-rw-r--r--examples/gui/rhiwindow/rhiwindow.cpp11
7 files changed, 48 insertions, 28 deletions
diff --git a/examples/gui/CMakeLists.txt b/examples/gui/CMakeLists.txt
index 8eda006a11..afc52ac3fa 100644
--- a/examples/gui/CMakeLists.txt
+++ b/examples/gui/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
if(NOT TARGET Qt6::Gui)
return()
diff --git a/examples/gui/doc/src/rasterwindow.qdoc b/examples/gui/doc/src/rasterwindow.qdoc
index 4458f12782..d30b4d7643 100644
--- a/examples/gui/doc/src/rasterwindow.qdoc
+++ b/examples/gui/doc/src/rasterwindow.qdoc
@@ -4,6 +4,7 @@
/*!
\example rasterwindow
\title Raster Window Example
+ \examplecategory {Graphics}
\brief This example shows how to create a minimal QWindow based
application using QPainter for rendering.
diff --git a/examples/gui/doc/src/rhiwindow.qdoc b/examples/gui/doc/src/rhiwindow.qdoc
index e3c6b83c16..3ee33c8002 100644
--- a/examples/gui/doc/src/rhiwindow.qdoc
+++ b/examples/gui/doc/src/rhiwindow.qdoc
@@ -4,6 +4,7 @@
/*!
\example rhiwindow
\title RHI Window Example
+ \examplecategory {Graphics}
\brief This example shows how to create a minimal QWindow-based
application using QRhi.
@@ -426,6 +427,11 @@
QRhiShaderResourceBindings, continue to be valid all the time. It is only
the underlying native resources that come and go over time.
+ Note also that we set a device pixel ratio on the image that matches
+ the window that we're drawing into. This ensures that the drawing code
+ can be DPR-agnostic, producing the same layout regardless of the DPR,
+ while also taking advantage of the additional pixels for improved fidelity.
+
\snippet rhiwindow/rhiwindow.cpp ensure-texture
Once a QImage is generated and the QPainter-based drawing into it has
diff --git a/examples/gui/rasterwindow/CMakeLists.txt b/examples/gui/rasterwindow/CMakeLists.txt
index 1a7878cc0a..7fb00895c9 100644
--- a/examples/gui/rasterwindow/CMakeLists.txt
+++ b/examples/gui/rasterwindow/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(rasterwindow LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/gui/rasterwindow")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui)
qt_standard_project_setup()
@@ -30,7 +24,14 @@ target_link_libraries(rasterwindow PRIVATE
)
install(TARGETS rasterwindow
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET rasterwindow
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/gui/rhiwindow/CMakeLists.txt b/examples/gui/rhiwindow/CMakeLists.txt
index 3c50add134..49b36286ee 100644
--- a/examples/gui/rhiwindow/CMakeLists.txt
+++ b/examples/gui/rhiwindow/CMakeLists.txt
@@ -1,15 +1,9 @@
# Copyright (C) 2023 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(rhiwindow LANGUAGES CXX)
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/gui/rhiwindow")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui)
qt_standard_project_setup()
@@ -53,7 +47,14 @@ qt_add_resources(rhiwindow "rhiwindow"
)
install(TARGETS rhiwindow
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET rhiwindow
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/gui/rhiwindow/main.cpp b/examples/gui/rhiwindow/main.cpp
index c6d9ce5669..37977e3a34 100644
--- a/examples/gui/rhiwindow/main.cpp
+++ b/examples/gui/rhiwindow/main.cpp
@@ -14,7 +14,7 @@ int main(int argc, char **argv)
// Use platform-specific defaults when no command-line arguments given.
#if defined(Q_OS_WIN)
graphicsApi = QRhi::D3D11;
-#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS)
+#elif QT_CONFIG(metal)
graphicsApi = QRhi::Metal;
#elif QT_CONFIG(vulkan)
graphicsApi = QRhi::Vulkan;
@@ -52,10 +52,20 @@ int main(int argc, char **argv)
graphicsApi = QRhi::Metal;
//! [api-setup]
- // For OpenGL.
+ // For OpenGL, to ensure there is a depth/stencil buffer for the window.
+ // With other APIs this is under the application's control (QRhiRenderBuffer etc.)
+ // and so no special setup is needed for those.
QSurfaceFormat fmt;
fmt.setDepthBufferSize(24);
fmt.setStencilBufferSize(8);
+ // Special case macOS to allow using OpenGL there.
+ // (the default Metal is the recommended approach, though)
+ // gl_VertexID is a GLSL 130 feature, and so the default OpenGL 2.1 context
+ // we get on macOS is not sufficient.
+#ifdef Q_OS_MACOS
+ fmt.setVersion(4, 1);
+ fmt.setProfile(QSurfaceFormat::CoreProfile);
+#endif
QSurfaceFormat::setDefaultFormat(fmt);
// For Vulkan.
diff --git a/examples/gui/rhiwindow/rhiwindow.cpp b/examples/gui/rhiwindow/rhiwindow.cpp
index 5022244b86..3ae6faa802 100644
--- a/examples/gui/rhiwindow/rhiwindow.cpp
+++ b/examples/gui/rhiwindow/rhiwindow.cpp
@@ -146,7 +146,7 @@ void RhiWindow::init()
}
#endif
-#if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
+#if QT_CONFIG(metal)
if (m_graphicsApi == QRhi::Metal) {
QRhiMetalInitParams params;
m_rhi.reset(QRhi::create(QRhi::Metal, &params));
@@ -281,17 +281,18 @@ void HelloWindow::ensureFullscreenTexture(const QSize &pixelSize, QRhiResourceUp
m_texture->create();
QImage image(pixelSize, QImage::Format_RGBA8888_Premultiplied);
+ image.setDevicePixelRatio(devicePixelRatio());
//! [ensure-texture]
QPainter painter(&image);
- painter.fillRect(QRectF(QPointF(0, 0), pixelSize), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f));
+ painter.fillRect(QRectF(QPointF(0, 0), size()), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f));
painter.setPen(Qt::transparent);
painter.setBrush({ QGradient(QGradient::DeepBlue) });
- painter.drawRoundedRect(QRectF(QPointF(20, 20), pixelSize - QSize(40, 40)), 16, 16);
+ painter.drawRoundedRect(QRectF(QPointF(20, 20), size() - QSize(40, 40)), 16, 16);
painter.setPen(Qt::black);
QFont font;
- font.setPixelSize(0.05 * qMin(pixelSize.width(), pixelSize.height()));
+ font.setPixelSize(0.05 * qMin(width(), height()));
painter.setFont(font);
- painter.drawText(QRectF(QPointF(60, 60), pixelSize - QSize(120, 120)), 0,
+ painter.drawText(QRectF(QPointF(60, 60), size() - QSize(120, 120)), 0,
QLatin1String("Rendering with QRhi to a resizable QWindow.\nThe 3D API is %1.\nUse the command-line options to choose a different API.")
.arg(graphicsApiName()));
painter.end();