From 4c86af8ada5dae07d98473b67a4fb51a8c40fedc Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Fri, 8 Dec 2023 16:56:04 -0600 Subject: [PATCH] Qt6 migrations that are compatible with Qt5 (#598) Signed-off-by: Michael Carroll --- CMakeLists.txt | 10 +- .../plugin/custom_context_menu/CMakeLists.txt | 10 +- .../plugin/dialog_from_plugin/CMakeLists.txt | 9 +- examples/plugin/gz_components/CMakeLists.txt | 8 +- examples/plugin/hello_plugin/CMakeLists.txt | 11 +- examples/plugin/multiple_qml/CMakeLists.txt | 7 +- .../standalone/custom_drawer/CMakeLists.txt | 8 +- examples/standalone/dialogs/CMakeLists.txt | 10 +- examples/standalone/window/CMakeLists.txt | 7 +- include/gz/gui/CMakeLists.txt | 32 +--- src/Application.cc | 12 +- src/CMakeLists.txt | 2 +- src/Conversions.cc | 4 - src/Conversions_TEST.cc | 27 ++-- src/plugins/CMakeLists.txt | 6 +- src/plugins/minimal_scene/MinimalScene.cc | 130 ++++++--------- src/plugins/minimal_scene/MinimalScene.hh | 148 +++++++++--------- src/plugins/minimal_scene/MinimalSceneRhi.hh | 7 + .../minimal_scene/MinimalSceneRhiOpenGL.cc | 70 +++------ .../minimal_scene/MinimalSceneRhiVulkan.cc | 42 +++-- src/plugins/topic_echo/TopicEcho_TEST.cc | 17 +- test/CMakeLists.txt | 5 +- test/helpers/CMakeLists.txt | 2 +- test/integration/CMakeLists.txt | 6 +- test/plugins/CMakeLists.txt | 12 +- 25 files changed, 247 insertions(+), 355 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f8290883..46013d036 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,15 +81,19 @@ set(GZ_TOOLS_VER 2) #-------------------------------------- # Find QT -gz_find_package (Qt5 +set(QT_MAJOR_VERSION 5) +set(QT_MINOR_VERSION 15) +gz_find_package (Qt${QT_MAJOR_VERSION} + VERSION ${QT_MAJOR_VERSION}.${QT_MINOR_VERSION} COMPONENTS Core Quick QuickControls2 Widgets + Test REQUIRED - PKGCONFIG "Qt5Core Qt5Quick Qt5QuickControls2 Qt5Widgets" -) + PKGCONFIG "Qt${QT_MAJOR_VERSION}Core Qt${QT_MAJOR_VERSION}Quick Qt${QT_MAJOR_VERSION}QuickControls2 Qt${QT_MAJOR_VERSION}Widgets") +add_compile_definitions(QT_DISABLE_DEPRECATED_UP_TO=0x050F00) set(GZ_GUI_PLUGIN_RELATIVE_INSTALL_DIR ${GZ_LIB_INSTALL_DIR}/gz-${GZ_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins diff --git a/examples/plugin/custom_context_menu/CMakeLists.txt b/examples/plugin/custom_context_menu/CMakeLists.txt index a0a2a67a1..0ad64aa2e 100644 --- a/examples/plugin/custom_context_menu/CMakeLists.txt +++ b/examples/plugin/custom_context_menu/CMakeLists.txt @@ -9,7 +9,7 @@ endif() set (CMAKE_AUTOMOC ON) # Find Qt5 -find_package (Qt5 +find_package (Qt5 5.15 COMPONENTS Core Quick @@ -21,9 +21,7 @@ find_package (Qt5 find_package(gz-gui9 REQUIRED) set(GZ_GUI_VER ${gz-gui9_VERSION_MAJOR}) -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GZ-GUI_CXX_FLAGS}") - -QT5_ADD_RESOURCES(resources_RCC CustomContext.qrc) +qt_add_resources(resources_RCC CustomContext.qrc) # Generate examples add_library(CustomContext SHARED ${headers_MOC} @@ -32,8 +30,4 @@ add_library(CustomContext SHARED ${headers_MOC} ) target_link_libraries(CustomContext gz-gui${GZ_GUI_VER}::gz-gui${GZ_GUI_VER} - ${Qt5Core_LIBRARIES} - ${Qt5Qml_LIBRARIES} - ${Qt5Quick_LIBRARIES} - ${Qt5QuickControls2_LIBRARIES} ) diff --git a/examples/plugin/dialog_from_plugin/CMakeLists.txt b/examples/plugin/dialog_from_plugin/CMakeLists.txt index 038238de1..54de73a3d 100644 --- a/examples/plugin/dialog_from_plugin/CMakeLists.txt +++ b/examples/plugin/dialog_from_plugin/CMakeLists.txt @@ -8,7 +8,6 @@ endif() set (CMAKE_AUTOMOC ON) -# Find Qt5 find_package (Qt5 COMPONENTS Core @@ -21,9 +20,7 @@ find_package (Qt5 find_package(gz-gui9 REQUIRED) set(GZ_GUI_VER ${gz-gui9_VERSION_MAJOR}) -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GZ-GUI_CXX_FLAGS}") - -QT5_ADD_RESOURCES(resources_RCC DialogFromPlugin.qrc) +qt_add_resources(resources_RCC DialogFromPlugin.qrc) # Generate examples add_library(DialogFromPlugin SHARED ${headers_MOC} @@ -32,8 +29,4 @@ add_library(DialogFromPlugin SHARED ${headers_MOC} ) target_link_libraries(DialogFromPlugin gz-gui${GZ_GUI_VER}::gz-gui${GZ_GUI_VER} - ${Qt5Core_LIBRARIES} - ${Qt5Qml_LIBRARIES} - ${Qt5Quick_LIBRARIES} - ${Qt5QuickControls2_LIBRARIES} ) diff --git a/examples/plugin/gz_components/CMakeLists.txt b/examples/plugin/gz_components/CMakeLists.txt index 24cc05cfc..0ae3f9461 100644 --- a/examples/plugin/gz_components/CMakeLists.txt +++ b/examples/plugin/gz_components/CMakeLists.txt @@ -8,7 +8,7 @@ endif() set (CMAKE_AUTOMOC ON) -find_package (Qt5 +find_package (Qt5 5.15 COMPONENTS Core Quick @@ -21,7 +21,7 @@ set(GZ_GUI_VER ${gz-gui9_VERSION_MAJOR}) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GZ-GUI_CXX_FLAGS}") -QT5_ADD_RESOURCES(resources_RCC GzComponents.qrc) +qt_add_resources(resources_RCC GzComponents.qrc) # Generate examples add_library(GzComponents SHARED ${headers_MOC} @@ -30,8 +30,4 @@ add_library(GzComponents SHARED ${headers_MOC} ) target_link_libraries(GzComponents gz-gui${GZ_GUI_VER}::gz-gui${GZ_GUI_VER} - ${Qt5Core_LIBRARIES} - ${Qt5Qml_LIBRARIES} - ${Qt5Quick_LIBRARIES} - ${Qt5QuickControls2_LIBRARIES} ) diff --git a/examples/plugin/hello_plugin/CMakeLists.txt b/examples/plugin/hello_plugin/CMakeLists.txt index ea9c4dc85..940dc5580 100644 --- a/examples/plugin/hello_plugin/CMakeLists.txt +++ b/examples/plugin/hello_plugin/CMakeLists.txt @@ -8,8 +8,7 @@ endif() set (CMAKE_AUTOMOC ON) -# Find Qt5 -find_package (Qt5 +find_package (Qt5 5.15 COMPONENTS Core Quick @@ -21,9 +20,7 @@ find_package (Qt5 find_package(gz-gui9 REQUIRED) set(GZ_GUI_VER ${gz-gui9_VERSION_MAJOR}) -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GZ-GUI_CXX_FLAGS}") - -QT5_ADD_RESOURCES(resources_RCC hello.qrc) +qt_add_resources(resources_RCC hello.qrc) # Generate examples add_library(HelloPlugin SHARED ${headers_MOC} @@ -32,8 +29,4 @@ add_library(HelloPlugin SHARED ${headers_MOC} ) target_link_libraries(HelloPlugin gz-gui${GZ_GUI_VER}::gz-gui${GZ_GUI_VER} - ${Qt5Core_LIBRARIES} - ${Qt5Qml_LIBRARIES} - ${Qt5Quick_LIBRARIES} - ${Qt5QuickControls2_LIBRARIES} ) diff --git a/examples/plugin/multiple_qml/CMakeLists.txt b/examples/plugin/multiple_qml/CMakeLists.txt index 269f41cd7..76ca88aea 100644 --- a/examples/plugin/multiple_qml/CMakeLists.txt +++ b/examples/plugin/multiple_qml/CMakeLists.txt @@ -8,7 +8,6 @@ endif() set (CMAKE_AUTOMOC ON) -# Find Qt5 find_package (Qt5 COMPONENTS Core @@ -23,7 +22,7 @@ set(GZ_GUI_VER ${gz-gui9_VERSION_MAJOR}) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GZ-GUI_CXX_FLAGS}") -QT5_ADD_RESOURCES(resources_RCC MultipleQml.qrc) +qt_add_resources(resources_RCC MultipleQml.qrc) # Generate examples add_library(MultipleQml SHARED ${headers_MOC} @@ -32,8 +31,4 @@ add_library(MultipleQml SHARED ${headers_MOC} ) target_link_libraries(MultipleQml gz-gui${GZ_GUI_VER}::gz-gui${GZ_GUI_VER} - ${Qt5Core_LIBRARIES} - ${Qt5Qml_LIBRARIES} - ${Qt5Quick_LIBRARIES} - ${Qt5QuickControls2_LIBRARIES} ) diff --git a/examples/standalone/custom_drawer/CMakeLists.txt b/examples/standalone/custom_drawer/CMakeLists.txt index 7765a7ebd..31d79d8a3 100644 --- a/examples/standalone/custom_drawer/CMakeLists.txt +++ b/examples/standalone/custom_drawer/CMakeLists.txt @@ -21,9 +21,7 @@ find_package (Qt5 find_package(gz-gui9 REQUIRED) set(GZ_GUI_VER ${gz-gui9_VERSION_MAJOR}) -QT5_ADD_RESOURCES(resources_RCC custom_drawer.qrc) - -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GZ-GUI_CXX_FLAGS}") +qt_add_resources(resources_RCC custom_drawer.qrc) # Generate example add_executable(custom_drawer @@ -32,8 +30,4 @@ add_executable(custom_drawer ) target_link_libraries(custom_drawer gz-gui${GZ_GUI_VER}::gz-gui${GZ_GUI_VER} - ${Qt5Core_LIBRARIES} - ${Qt5Qml_LIBRARIES} - ${Qt5Quick_LIBRARIES} - ${Qt5QuickControls2_LIBRARIES} ) diff --git a/examples/standalone/dialogs/CMakeLists.txt b/examples/standalone/dialogs/CMakeLists.txt index 54c146035..49fd17ea4 100644 --- a/examples/standalone/dialogs/CMakeLists.txt +++ b/examples/standalone/dialogs/CMakeLists.txt @@ -8,8 +8,7 @@ endif() set (CMAKE_AUTOMOC ON) -# Find Qt5 -find_package (Qt5 +find_package (Qt5 5.15 COMPONENTS Core Quick @@ -21,17 +20,10 @@ find_package (Qt5 find_package(gz-gui9 REQUIRED) set(GZ_GUI_VER ${gz-gui9_VERSION_MAJOR}) -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GZ-GUI_CXX_FLAGS}") - # Generate example add_executable(dialogs dialogs.cc ) target_link_libraries(dialogs gz-gui${GZ_GUI_VER}::gz-gui${GZ_GUI_VER} - ${Qt5Core_LIBRARIES} - ${Qt5Qml_LIBRARIES} - ${Qt5Quick_LIBRARIES} - ${Qt5QuickControls2_LIBRARIES} ) - diff --git a/examples/standalone/window/CMakeLists.txt b/examples/standalone/window/CMakeLists.txt index 710ee91f6..9c062dd87 100644 --- a/examples/standalone/window/CMakeLists.txt +++ b/examples/standalone/window/CMakeLists.txt @@ -9,7 +9,7 @@ endif() set (CMAKE_AUTOMOC ON) # Find Qt5 -find_package (Qt5 +find_package (Qt5 5.15 COMPONENTS Core Quick @@ -29,9 +29,4 @@ add_executable(window ) target_link_libraries(window gz-gui${GZ_GUI_VER}::gz-gui${GZ_GUI_VER} - ${Qt5Core_LIBRARIES} - ${Qt5Qml_LIBRARIES} - ${Qt5Quick_LIBRARIES} - ${Qt5QuickControls2_LIBRARIES} ) - diff --git a/include/gz/gui/CMakeLists.txt b/include/gz/gui/CMakeLists.txt index 27db7054e..5e15317d6 100644 --- a/include/gz/gui/CMakeLists.txt +++ b/include/gz/gui/CMakeLists.txt @@ -1,26 +1,9 @@ -include_directories( - ${Qt5Core_INCLUDE_DIRS} - ${tinyxml_INCLUDE_DIRS} - ${Qt5Qml_INCLUDE_DIRS} - ${Qt5Quick_INCLUDE_DIRS} - ${Qt5QuickControls2_INCLUDE_DIRS} - ${Qt5Widgets_INCLUDE_DIRS} -) - if(POLICY CMP0100) cmake_policy(SET CMP0100 NEW) endif() set (CMAKE_AUTOMOC ON) -add_definitions( - ${Qt5Core_DEFINITIONS} - ${Qt5Qml_DEFINITIONS} - ${Qt5Quick_DEFINITIONS} - ${Qt5QuickControls2_DEFINITIONS} - ${Qt5Widgets_DEFINITIONS} -) - set (qt_headers Application.hh Dialog.hh @@ -42,8 +25,8 @@ set (headers set (resources resources.qrc) -QT5_WRAP_CPP(headers_MOC ${qt_headers}) -QT5_ADD_RESOURCES(resources_RCC ${resources}) +qt_wrap_cpp(headers_MOC ${qt_headers}) +qt_add_resources(resources_RCC ${resources}) gz_create_core_library(SOURCES ${sources} @@ -67,13 +50,12 @@ target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME} gz-msgs${GZ_MSGS_VER}::gz-msgs${GZ_MSGS_VER} gz-plugin${GZ_PLUGIN_VER}::loader gz-transport${GZ_TRANSPORT_VER}::gz-transport${GZ_TRANSPORT_VER} - ${Qt5Core_LIBRARIES} - ${Qt5Qml_LIBRARIES} - ${Qt5Quick_LIBRARIES} - ${Qt5QuickControls2_LIBRARIES} - ${Qt5Widgets_LIBRARIES} + Qt::Core + Qt::Qml + Qt::Quick + Qt::QuickControls2 + Qt::Widgets TINYXML2::TINYXML2 ) gz_install_all_headers() - diff --git a/src/Application.cc b/src/Application.cc index 87201de81..5427a67c3 100644 --- a/src/Application.cc +++ b/src/Application.cc @@ -15,6 +15,7 @@ * */ +#include #include #include @@ -126,7 +127,12 @@ Application::Application(int &_argc, char **_argv, const WindowType _type, { // Use the Metal graphics API on macOS. gzdbg << "Qt using Metal graphics interface" << std::endl; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QQuickWindow::setGraphicsApi(QSGRendererInterface::MetalRhi); +#else QQuickWindow::setSceneGraphBackend(QSGRendererInterface::MetalRhi); +#endif + } // TODO(srmainwaring): implement facility for overriding the default @@ -161,9 +167,11 @@ Application::Application(int &_argc, char **_argv, const WindowType _type, # endif ); -# if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QQuickWindow::setGraphicsApi(QSGRendererInterface::VulkanRhi); +#else QQuickWindow::setSceneGraphBackend(QSGRendererInterface::VulkanRhi); -# endif +#endif } else { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5d555f470..86684d476 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,7 +54,7 @@ gz_build_tests(TYPE UNIT TINYXML2::TINYXML2 TEST_LIST gtest_targets - ENVIRONMENT + ENVIRONMENT GZ_GUI_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} ) diff --git a/src/Conversions.cc b/src/Conversions.cc index 6e2d6c292..6fbd79419 100644 --- a/src/Conversions.cc +++ b/src/Conversions.cc @@ -122,11 +122,7 @@ gz::common::MouseEvent convert(const QWheelEvent &_e) common::MouseEvent event; event.SetType(common::MouseEvent::SCROLL); -#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) - event.SetPos(_e.x(), _e.y()); -#else event.SetPos(_e.position().x(), _e.position().y()); -#endif double scroll = (_e.angleDelta().y() > 0) ? -1.0 : 1.0; event.SetScroll(scroll, scroll); diff --git a/src/Conversions_TEST.cc b/src/Conversions_TEST.cc index 54902d1d3..e7afc2fc5 100644 --- a/src/Conversions_TEST.cc +++ b/src/Conversions_TEST.cc @@ -104,8 +104,11 @@ TEST(ConversionsTest, MouseEvent) { // Press + Shift { - QMouseEvent qtEvent(QEvent::MouseButtonPress, QPointF(10, 20), - Qt::RightButton, Qt::MiddleButton, Qt::ShiftModifier); + QMouseEvent qtEvent(QEvent::MouseButtonPress, + QPointF(10, 20), QPointF(10, 20), + Qt::RightButton, + Qt::MiddleButton, + Qt::ShiftModifier); auto gzEvent = convert(qtEvent); @@ -119,8 +122,11 @@ TEST(ConversionsTest, MouseEvent) // Release + Control { - QMouseEvent qtEvent(QEvent::MouseButtonRelease, QPointF(0, 200), - Qt::MiddleButton, Qt::RightButton, Qt::ControlModifier); + QMouseEvent qtEvent(QEvent::MouseButtonRelease, + QPointF(0, 200), QPointF(0, 200), + Qt::MiddleButton, + Qt::RightButton, + Qt::ControlModifier); auto gzEvent = convert(qtEvent); @@ -134,8 +140,11 @@ TEST(ConversionsTest, MouseEvent) // Move + Alt { - QMouseEvent qtEvent(QEvent::MouseMove, QPointF(123, 456), - Qt::LeftButton, Qt::LeftButton, Qt::AltModifier); + QMouseEvent qtEvent(QEvent::MouseMove, + QPointF(123, 456), QPointF(123, 456), + Qt::LeftButton, + Qt::LeftButton, + Qt::AltModifier); auto gzEvent = convert(qtEvent); @@ -149,15 +158,9 @@ TEST(ConversionsTest, MouseEvent) // Scroll { -#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0) - QWheelEvent qtEvent(QPointF(123, 456), QPointF(1000, 2000), QPoint(2, 3), - QPoint(1, 4), -1, Qt::Horizontal, Qt::MiddleButton, Qt::ShiftModifier, - Qt::ScrollUpdate, Qt::MouseEventNotSynthesized, false); -#else QWheelEvent qtEvent(QPointF(123, 456), QPointF(1000, 2000), QPoint(2, 3), QPoint(1, 4), Qt::MiddleButton, Qt::ShiftModifier, Qt::ScrollUpdate, false); -#endif auto gzEvent = convert(qtEvent); diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 3f40148e9..f5bcf98f1 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -22,8 +22,8 @@ function(gz_gui_add_library library_name) set(multiValueArgs SOURCES QT_HEADERS PUBLIC_LINK_LIBS PRIVATE_LINK_LIBS) cmake_parse_arguments(gz_gui_add_library "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - QT5_WRAP_CPP(${library_name}_headers_MOC ${gz_gui_add_library_QT_HEADERS}) - QT5_ADD_RESOURCES(${library_name}_RCC ${library_name}.qrc) + qt_wrap_cpp(${library_name}_headers_MOC ${gz_gui_add_library_QT_HEADERS}) + qt_add_resources(${library_name}_RCC ${library_name}.qrc) add_library(${library_name} SHARED ${gz_gui_add_library_SOURCES} @@ -94,7 +94,7 @@ function(gz_gui_add_plugin plugin_name) ${PROJECT_SOURCE_DIR} # Used to make test_config.h visible to the unit tests ${PROJECT_BINARY_DIR} - ENVIRONMENT + ENVIRONMENT GZ_GUI_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}) endif() diff --git a/src/plugins/minimal_scene/MinimalScene.cc b/src/plugins/minimal_scene/MinimalScene.cc index 7b92cf407..613fc6878 100644 --- a/src/plugins/minimal_scene/MinimalScene.cc +++ b/src/plugins/minimal_scene/MinimalScene.cc @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -52,11 +53,10 @@ #include "gz/gui/Helpers.hh" #include "gz/gui/MainWindow.hh" -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \ - defined(GZ_RENDERING_HAVE_VULKAN) +#if GZ_GUI_HAVE_VULKAN # include # include -#endif +#endif // GZ_GUI_HAVE_VULKAN Q_DECLARE_METATYPE(gz::gui::plugins::RenderSync*) @@ -216,11 +216,11 @@ class gz::gui::plugins::RenderWindowItem::Implementation /// \brief Graphics API. The default is platform specific. public: gz::rendering::GraphicsAPI graphicsAPI = -#ifdef __APPLE__ +#if GZ_GUI_HAVE_METAL rendering::GraphicsAPI::METAL; #else rendering::GraphicsAPI::OPENGL; -#endif +#endif // GZ_GUI_HAVE_METAL /// \brief Render thread public: RenderThread *renderThread = nullptr; @@ -584,14 +584,14 @@ rendering::CameraPtr GzRenderer::Camera() return this->dataPtr->camera; } -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \ - defined(GZ_RENDERING_HAVE_VULKAN) +#if GZ_GUI_HAVE_VULKAN +namespace { ///////////////////////////////////////////////// /// \brief fillQtInstanceExtensionsToOgre /// Extract Vulkan Instance extension information to be sent to OgreNext /// \param[in] inst Qt's Vulkan Instance to extract /// \param[out] externalInstance Data to be sent to OgreNext -static void fillQtInstanceExtensionsToOgre( +void fillQtInstanceExtensionsToOgre( const QVulkanInstance *inst, rendering::GzVulkanExternalInstance &externalInstance) { @@ -628,7 +628,7 @@ static void fillQtInstanceExtensionsToOgre( /// Extract Vulkan Device extension info to be sent to OgreNext /// This data is obtained from Environment variables /// \param[out] externalDevice Data to be sent to OgreNext -static void fillQtDeviceExtensionsToOgre( +void fillQtDeviceExtensionsToOgre( rendering::GzVulkanExternalDevice &externalDevice) { // We know Qt adds these by looking at @@ -658,13 +658,14 @@ static void fillQtDeviceExtensionsToOgre( extProp.extensionName[VK_MAX_EXTENSION_NAME_SIZE - 1u] = 0; } } -#endif +} // namespace +#endif // GZ_GUI_HAVE_VULKAN ///////////////////////////////////////////////// std::string GzRenderer::Initialize(RenderThreadRhi &_rhi) { if (this->initialized) - return std::string(); + return {}; // Currently only support one engine at a time rendering::RenderEngine *engine{nullptr}; @@ -678,8 +679,7 @@ std::string GzRenderer::Initialize(RenderThreadRhi &_rhi) this->dataPtr->rhiParams["winID"] = std::to_string(quickWindow->winId()); -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \ - defined(GZ_RENDERING_HAVE_VULKAN) +#if GZ_GUI_HAVE_VULKAN // externalInstance & externalDevice MUST be declared at this scope // because we save their stack addresses into this->dataPtr->rhiParams // and must be alive until rendering::engine() returns. @@ -734,7 +734,7 @@ std::string GzRenderer::Initialize(RenderThreadRhi &_rhi) engine = rendering::engine(loadedEngines.front()); } - if (!engine) + if (engine == nullptr) { return "Engine [" + this->engineName + "] is not supported"; } @@ -788,7 +788,7 @@ std::string GzRenderer::Initialize(RenderThreadRhi &_rhi) this->dataPtr->rayQuery = this->dataPtr->camera->Scene()->CreateRayQuery(); this->initialized = true; - return std::string(); + return {}; } ///////////////////////////////////////////////// @@ -807,14 +807,13 @@ void GzRenderer::SetGraphicsAPI(const rendering::GraphicsAPI &_graphicsAPI) { gzdbg << "Creating gz-rendering interface for Vulkan" << std::endl; this->dataPtr->rhiParams["vulkan"] = "1"; -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \ - defined(GZ_RENDERING_HAVE_VULKAN) +#if GZ_GUI_HAVE_VULKAN this->dataPtr->rhi = std::make_unique(); #else this->dataPtr->rhi = std::make_unique(); #endif } -#ifdef __APPLE__ +#if GZ_GUI_HAVE_METAL else if (_graphicsAPI == rendering::GraphicsAPI::METAL) { gzdbg << "Creating gz-renderering interface for Metal" << std::endl; @@ -827,11 +826,11 @@ void GzRenderer::SetGraphicsAPI(const rendering::GraphicsAPI &_graphicsAPI) ///////////////////////////////////////////////// void GzRenderer::Destroy() { - auto engine = rendering::engine(this->engineName); - if (!engine) + auto *engine = rendering::engine(this->engineName); + if (engine == nullptr) return; auto scene = engine->SceneByName(this->sceneName); - if (!scene) + if (scene == nullptr) return; scene->DestroySensor(this->dataPtr->camera); @@ -902,7 +901,7 @@ RenderThread::RenderThread() ///////////////////////////////////////////////// void RenderThread::SetErrorCb(std::function _cb) { - this->errorCb = _cb; + this->errorCb = std::move(_cb); } ///////////////////////////////////////////////// @@ -929,8 +928,8 @@ void RenderThread::ShutDown() ///////////////////////////////////////////////// void RenderThread::SizeChanged() { - auto item = qobject_cast(this->sender()); - if (!item) + auto *item = qobject_cast(this->sender()); + if (item == nullptr) { gzerr << "Internal error, sender is not QQuickItem." << std::endl; return; @@ -975,32 +974,26 @@ void RenderThread::SetGraphicsAPI(const rendering::GraphicsAPI &_graphicsAPI) this->gzRenderer.SetGraphicsAPI(_graphicsAPI); // Create the render interface - if (_graphicsAPI == rendering::GraphicsAPI::OPENGL -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \ - defined(GZ_RENDERING_HAVE_VULKAN) - // Use fallback (GPU -> CPU -> GPU) - || _graphicsAPI == rendering::GraphicsAPI::VULKAN -#endif - ) + if (_graphicsAPI == rendering::GraphicsAPI::OPENGL) { gzdbg << "Creating render thread interface for OpenGL" << std::endl; this->rhi = std::make_unique(&this->gzRenderer); } -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \ - defined(GZ_RENDERING_HAVE_VULKAN) + +#if GZ_GUI_HAVE_VULKAN else if (_graphicsAPI == rendering::GraphicsAPI::VULKAN) { gzdbg << "Creating render thread interface for Vulkan" << std::endl; this->rhi = std::make_unique(&this->gzRenderer); } -#endif -#ifdef __APPLE__ +#endif // GZ_GUI_HAVE_VULKAN +#if GZ_GUI_HAVE_METAL else if (_graphicsAPI == rendering::GraphicsAPI::METAL) { gzdbg << "Creating render thread interface for Metal" << std::endl; this->rhi = std::make_unique(&this->gzRenderer); } -#endif +#endif // GZ_GUI_HAVE_METAL } ///////////////////////////////////////////////// @@ -1017,42 +1010,29 @@ std::string RenderThread::Initialize() ///////////////////////////////////////////////// TextureNode::TextureNode(QQuickWindow *_window, RenderSync &_renderSync, const rendering::GraphicsAPI &_graphicsAPI, - rendering::CameraPtr & -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \ - defined(GZ_RENDERING_HAVE_VULKAN) - _camera -#endif - ) : + rendering::CameraPtr &_camera): renderSync(_renderSync), window(_window) { - if (_graphicsAPI == rendering::GraphicsAPI::OPENGL -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \ - defined(GZ_RENDERING_HAVE_VULKAN) - // Use fallback (GPU -> CPU -> GPU) - || _graphicsAPI == rendering::GraphicsAPI::VULKAN -#endif - ) + if (_graphicsAPI == rendering::GraphicsAPI::OPENGL) { gzdbg << "Creating texture node render interface for OpenGL" << std::endl; this->rhi = std::make_unique(_window); } -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \ - defined(GZ_RENDERING_HAVE_VULKAN) +#if GZ_GUI_HAVE_VULKAN else if (_graphicsAPI == rendering::GraphicsAPI::VULKAN) { gzdbg << "Creating texture node render interface for Vulkan" << std::endl; this->rhi = std::make_unique(_window, _camera); } -#else -#endif -#ifdef __APPLE__ +#endif // GZ_GUI_HAVE_VULKAN +#if GZ_GUI_HAVE_METAL else if (_graphicsAPI == rendering::GraphicsAPI::METAL) { gzdbg << "Creating texture node render interface for Metal" << std::endl; this->rhi = std::make_unique(_window); } -#endif +#endif // GZ_GUI_HAVE_METAL this->setTexture(this->rhi->Texture()); } @@ -1144,13 +1124,7 @@ void RenderWindowItem::StopRendering() // This slot will run on the main thread void RenderWindowItem::Ready() { - if (this->dataPtr->graphicsAPI == rendering::GraphicsAPI::OPENGL -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \ - defined(GZ_RENDERING_HAVE_VULKAN) - // Use fallback (GPU -> CPU -> GPU) - || this->dataPtr->graphicsAPI == rendering::GraphicsAPI::VULKAN -#endif - ) + if (this->dataPtr->graphicsAPI == rendering::GraphicsAPI::OPENGL) { this->dataPtr->renderThread->SetSurface(new QOffscreenSurface()); this->dataPtr->renderThread->Surface()->setFormat( @@ -1164,13 +1138,7 @@ void RenderWindowItem::Ready() return; } - if (this->dataPtr->graphicsAPI == rendering::GraphicsAPI::OPENGL -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \ - defined(GZ_RENDERING_HAVE_VULKAN) - // Use fallback (GPU -> CPU -> GPU) - || this->dataPtr->graphicsAPI == rendering::GraphicsAPI::VULKAN -#endif - ) + if (this->dataPtr->graphicsAPI == rendering::GraphicsAPI::OPENGL) { // Move context to the render thread this->dataPtr->renderThread->Context()->moveToThread( @@ -1213,15 +1181,15 @@ QSGNode *RenderWindowItem::updatePaintNode(QSGNode *_node, this->dataPtr->renderThread->SetGraphicsAPI( this->dataPtr->graphicsAPI); - if (this->dataPtr->graphicsAPI == rendering::GraphicsAPI::OPENGL -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \ - defined(GZ_RENDERING_HAVE_VULKAN) - // Use fallback (GPU -> CPU -> GPU) - || this->dataPtr->graphicsAPI == rendering::GraphicsAPI::VULKAN -#endif - ) + if (this->dataPtr->graphicsAPI == rendering::GraphicsAPI::OPENGL) { - QOpenGLContext *current = this->window()->openglContext(); + auto *rif = this->window()->rendererInterface(); + Q_ASSERT(rif->graphicsApi() == QSGRendererInterface::OpenGL); + + auto *current = static_cast( + rif->getResource(this->window(), + QSGRendererInterface::OpenGLContextResource)); + // Some GL implementations require that the currently bound context is // made non-current before we set up sharing, so we doneCurrent here // and makeCurrent down below while setting up our own context. @@ -1658,21 +1626,21 @@ void RenderWindowItem::HandleKeyRelease(const common::KeyEvent &_e) ///////////////////////////////////////////////// void MinimalScene::OnHovered(int _mouseX, int _mouseY) { - auto renderWindow = this->PluginItem()->findChild(); + auto *renderWindow = this->PluginItem()->findChild(); renderWindow->OnHovered({_mouseX, _mouseY}); } ///////////////////////////////////////////////// void MinimalScene::OnDropped(const QString &_drop, int _mouseX, int _mouseY) { - auto renderWindow = this->PluginItem()->findChild(); + auto *renderWindow = this->PluginItem()->findChild(); renderWindow->OnDropped(_drop, {_mouseX, _mouseY}); } ///////////////////////////////////////////////// void MinimalScene::OnFocusWindow() { - auto renderWindow = this->PluginItem()->findChild(); + auto *renderWindow = this->PluginItem()->findChild(); renderWindow->forceActiveFocus(); } @@ -1687,7 +1655,7 @@ void MinimalScene::SetLoadingError(const QString &_loadingError) { if (!_loadingError.isEmpty()) { - auto renderWindow = this->PluginItem()->findChild(); + auto *renderWindow = this->PluginItem()->findChild(); if (nullptr != renderWindow) renderWindow->StopRendering(); } diff --git a/src/plugins/minimal_scene/MinimalScene.hh b/src/plugins/minimal_scene/MinimalScene.hh index 5f8bd433d..e7edf343d 100644 --- a/src/plugins/minimal_scene/MinimalScene.hh +++ b/src/plugins/minimal_scene/MinimalScene.hh @@ -380,108 +380,108 @@ namespace gz::gui::plugins /// \param[in] _view_controller The camera view controller type to set public: void SetCameraViewController(const std::string &_view_controller); - /// \brief Slot called when thread is ready to be started - public Q_SLOTS: void Ready(); + /// \brief Slot called when thread is ready to be started + public Q_SLOTS: void Ready(); - /// \brief Handle key press event for snapping - /// \param[in] _e The key event to process. - public: void HandleKeyPress(const common::KeyEvent &_e); + /// \brief Handle key press event for snapping + /// \param[in] _e The key event to process. + public: void HandleKeyPress(const common::KeyEvent &_e); - /// \brief Handle key release event for snapping - /// \param[in] _e The key event to process. - public: void HandleKeyRelease(const common::KeyEvent &_e); + /// \brief Handle key release event for snapping + /// \param[in] _e The key event to process. + public: void HandleKeyRelease(const common::KeyEvent &_e); - /// \brief Set a callback to be called in case there are errors. - /// \param[in] _cb Error callback - public: void SetErrorCb(std::function _cb); + /// \brief Set a callback to be called in case there are errors. + /// \param[in] _cb Error callback + public: void SetErrorCb(std::function _cb); - /// \brief Stop rendering and shutdown resources. - public: void StopRendering(); + /// \brief Stop rendering and shutdown resources. + public: void StopRendering(); - // Documentation inherited - protected: virtual void mousePressEvent(QMouseEvent *_e) override; + // Documentation inherited + protected: virtual void mousePressEvent(QMouseEvent *_e) override; - // Documentation inherited - protected: virtual void mouseReleaseEvent(QMouseEvent *_e) override; + // Documentation inherited + protected: virtual void mouseReleaseEvent(QMouseEvent *_e) override; - // Documentation inherited - protected: virtual void mouseMoveEvent(QMouseEvent *_e) override; + // Documentation inherited + protected: virtual void mouseMoveEvent(QMouseEvent *_e) override; - // Documentation inherited - protected: virtual void keyPressEvent(QKeyEvent *_e) override; + // Documentation inherited + protected: virtual void keyPressEvent(QKeyEvent *_e) override; - // Documentation inherited - protected: virtual void keyReleaseEvent(QKeyEvent *_e) override; + // Documentation inherited + protected: virtual void keyReleaseEvent(QKeyEvent *_e) override; - // Documentation inherited - protected: virtual void wheelEvent(QWheelEvent *_e) override; + // Documentation inherited + protected: virtual void wheelEvent(QWheelEvent *_e) override; - /// \brief Overrides the paint event to render the render engine - /// camera view - /// \param[in] _oldNode The node passed in previous updatePaintNode - /// function. It represents the visual representation of the item. - /// \param[in] _data The node transformation data. - /// \return Updated node. - private: QSGNode *updatePaintNode(QSGNode *_oldNode, - QQuickItem::UpdatePaintNodeData *_data) override; + /// \brief Overrides the paint event to render the render engine + /// camera view + /// \param[in] _oldNode The node passed in previous updatePaintNode + /// function. It represents the visual representation of the item. + /// \param[in] _data The node transformation data. + /// \return Updated node. + private: QSGNode *updatePaintNode(QSGNode *_oldNode, + QQuickItem::UpdatePaintNodeData *_data) override; - /// \internal - /// \brief Pointer to private data. - GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr) -}; + /// \internal + /// \brief Pointer to private data. + GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr) + }; -/// \brief Texture node for displaying the render texture from gz-renderer -class TextureNode : public QObject, public QSGSimpleTextureNode -{ - Q_OBJECT + /// \brief Texture node for displaying the render texture from gz-renderer + class TextureNode : public QObject, public QSGSimpleTextureNode + { + Q_OBJECT - /// \brief Constructor - /// \param[in] _window Window to display the texture - /// \param[in] _renderSync RenderSync to safely - /// synchronize Qt (this) and worker thread - /// \param[in] _graphicsAPI The type of graphics API - /// \param[in] _camera Camera owning the Texture Handle - public: explicit TextureNode(QQuickWindow *_window, - RenderSync &_renderSync, - const rendering::GraphicsAPI &_graphicsAPI, - rendering::CameraPtr &_camera); + /// \brief Constructor + /// \param[in] _window Window to display the texture + /// \param[in] _renderSync RenderSync to safely + /// synchronize Qt (this) and worker thread + /// \param[in] _graphicsAPI The type of graphics API + /// \param[in] _camera Camera owning the Texture Handle + public: explicit TextureNode(QQuickWindow *_window, + RenderSync &_renderSync, + const rendering::GraphicsAPI &_graphicsAPI, + rendering::CameraPtr &_camera); - /// \brief Destructor - public: ~TextureNode() override; + /// \brief Destructor + public: ~TextureNode() override; - /// \brief This function gets called on the FBO rendering thread and will - /// store the texture id and size and schedule an update on the window. - /// \param[in] _texturePtr Pointer to a texture Id - /// \param[in] _size Texture size - // public slots: void NewTexture(uint _id, const QSize &_size); - public slots: void NewTexture(void* _texturePtr, const QSize &_size); + /// \brief This function gets called on the FBO rendering thread and will + /// store the texture id and size and schedule an update on the window. + /// \param[in] _texturePtr Pointer to a texture Id + /// \param[in] _size Texture size + // public slots: void NewTexture(uint _id, const QSize &_size); + public slots: void NewTexture(void* _texturePtr, const QSize &_size); - /// \brief Before the scene graph starts to render, we update to the - /// pending texture - public slots: void PrepareNode(); + /// \brief Before the scene graph starts to render, we update to the + /// pending texture + public slots: void PrepareNode(); - /// \param[in] _renderSync RenderSync to send to the worker thread - signals: void TextureInUse(gz::gui::plugins::RenderSync *_renderSync); + /// \param[in] _renderSync RenderSync to send to the worker thread + signals: void TextureInUse(gz::gui::plugins::RenderSync *_renderSync); - /// \brief Signal emitted when a new texture is ready to trigger window - /// update - signals: void PendingNewTexture(); + /// \brief Signal emitted when a new texture is ready to trigger window + /// update + signals: void PendingNewTexture(); - /// \brief Texture size - public: QSize size = QSize(0, 0); + /// \brief Texture size + public: QSize size = QSize(0, 0); - /// \brief Mutex to protect the texture variables - public: QMutex mutex; + /// \brief Mutex to protect the texture variables + public: QMutex mutex; - /// \brief See RenderSync - public: RenderSync &renderSync; + /// \brief See RenderSync + public: RenderSync &renderSync; /// \brief Qt quick window public: QQuickWindow *window = nullptr; /// \brief Pointer to render interface to handle OpenGL/Metal compatibility private: std::unique_ptr rhi; - }; + }; } // namespace gz::gui::plugins #endif // GZ_GUI_PLUGINS_MINIMALSCENE_HH_ diff --git a/src/plugins/minimal_scene/MinimalSceneRhi.hh b/src/plugins/minimal_scene/MinimalSceneRhi.hh index ff79a3dc9..978b8241f 100644 --- a/src/plugins/minimal_scene/MinimalSceneRhi.hh +++ b/src/plugins/minimal_scene/MinimalSceneRhi.hh @@ -26,6 +26,13 @@ #include #include +#define GZ_GUI_HAVE_VULKAN \ + QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && \ + QT_CONFIG(vulkan) && \ + GZ_RENDERING_HAVE_VULKAN + +#define GZ_GUI_HAVE_METAL __APPLE__ + namespace gz::gui::plugins { /// \brief Render interface class to handle OpenGL / Metal compatibility diff --git a/src/plugins/minimal_scene/MinimalSceneRhiOpenGL.cc b/src/plugins/minimal_scene/MinimalSceneRhiOpenGL.cc index c75fb3aba..732259907 100644 --- a/src/plugins/minimal_scene/MinimalSceneRhiOpenGL.cc +++ b/src/plugins/minimal_scene/MinimalSceneRhiOpenGL.cc @@ -59,6 +59,27 @@ namespace gz::gui::plugins public: QMutex mutex; public: QSGTexture *texture = nullptr; public: QQuickWindow *window = nullptr; + + public: void CreateTexture(GLuint *_id, QSize _size) { + delete this->texture; + this->texture = nullptr; + + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + this->texture = QNativeInterface::QSGOpenGLTexture::fromNative( + *_id, + this->window, + _size); +#else + this->texture = + this->window->createTextureFromNativeObject( + QQuickWindow::NativeObjectTexture, + static_cast(_id), + 0, + _size); +#endif + } + }; ///////////////////////////////////////////////// @@ -206,26 +227,8 @@ TextureNodeRhiOpenGL::TextureNodeRhiOpenGL(QQuickWindow *_window) this->dataPtr->window = _window; // Our texture node must have a texture, so use the default 0 texture. -#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) -# ifndef _WIN32 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" -# endif - this->dataPtr->texture = this->dataPtr->window->createTextureFromId( - this->dataPtr->textureId, - QSize(1, 1), - QQuickWindow::TextureIsOpaque); -# ifndef _WIN32 -# pragma GCC diagnostic pop -# endif -#else - this->dataPtr->texture = - this->dataPtr->window->createTextureFromNativeObject( - QQuickWindow::NativeObjectTexture, - static_cast(&this->dataPtr->textureId), - 0, - QSize(1, 1)); -#endif + this->dataPtr->CreateTexture( + &this->dataPtr->textureId, QSize(1, 1)); } ///////////////////////////////////////////////// @@ -260,31 +263,10 @@ void TextureNodeRhiOpenGL::PrepareNode() this->dataPtr->textureId = 0; this->dataPtr->mutex.unlock(); - if (this->dataPtr->newTextureId) + if (this->dataPtr->newTextureId != 0) { - delete this->dataPtr->texture; - this->dataPtr->texture = nullptr; - -#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) -# ifndef _WIN32 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" -# endif - this->dataPtr->texture = this->dataPtr->window->createTextureFromId( - this->dataPtr->newTextureId, - this->dataPtr->newSize, - QQuickWindow::TextureIsOpaque); -# ifndef _WIN32 -# pragma GCC diagnostic pop -# endif -#else - this->dataPtr->texture = - this->dataPtr->window->createTextureFromNativeObject( - QQuickWindow::NativeObjectTexture, - static_cast(&this->dataPtr->newTextureId), - 0, - this->dataPtr->newSize); -#endif + this->dataPtr->CreateTexture( + &this->dataPtr->newTextureId, this->dataPtr->newSize); } } } // namespace gz::gui::plugins diff --git a/src/plugins/minimal_scene/MinimalSceneRhiVulkan.cc b/src/plugins/minimal_scene/MinimalSceneRhiVulkan.cc index 9352a7a56..6670eef33 100644 --- a/src/plugins/minimal_scene/MinimalSceneRhiVulkan.cc +++ b/src/plugins/minimal_scene/MinimalSceneRhiVulkan.cc @@ -17,7 +17,7 @@ #include "MinimalSceneRhiVulkan.hh" -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) +#if GZ_GUI_HAVE_VULKAN #include "EngineToQtInterface.hh" #include "MinimalScene.hh" @@ -60,8 +60,29 @@ class TextureNodeRhiVulkanPrivate public: QMutex mutex; public: QSGTexture *texture = nullptr; public: QQuickWindow *window = nullptr; + + public: void CreateTexture(VkImage *_id, QSize _size) { + delete this->texture; + this->texture = nullptr; + + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + this->texture = QNativeInterface::QSGVulkanTexture::fromNative( + *_id, + VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + this->window, + _size); +#else + this->texture = this->window->createTextureFromNativeObject( + QQuickWindow::NativeObjectTexture, + static_cast(_id), // + VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL, + _size); +#endif + } }; + ///////////////////////////////////////////////// GzCameraTextureRhiVulkan::~GzCameraTextureRhiVulkan() = default; @@ -182,10 +203,8 @@ TextureNodeRhiVulkan::TextureNodeRhiVulkan(QQuickWindow *_window, _camera->RenderTextureMetalId(&this->dataPtr->textureId); this->dataPtr->lastCamera = _camera; - this->dataPtr->texture = this->dataPtr->window->createTextureFromNativeObject( - QQuickWindow::NativeObjectTexture, - static_cast(&this->dataPtr->textureId), // - 0, // + this->dataPtr->CreateTexture( + &this->dataPtr->textureId, QSize(static_cast(_camera->ImageWidth()), static_cast(_camera->ImageHeight()))); } @@ -229,16 +248,9 @@ void TextureNodeRhiVulkan::PrepareNode() if (this->dataPtr->newTextureId != nullptr) { - delete this->dataPtr->texture; - this->dataPtr->texture = nullptr; - - this->dataPtr->texture = - this->dataPtr->window->createTextureFromNativeObject( - QQuickWindow::NativeObjectTexture, - static_cast(&this->dataPtr->newTextureId), - VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, - this->dataPtr->newSize); + this->dataPtr->CreateTexture( + &this->dataPtr->newTextureId, this->dataPtr->newSize); } } } // namespace gz::gui::plugins -#endif // HAVE_QT_VULKAN +#endif // GZ_GUI_HAVE_VULKAN diff --git a/src/plugins/topic_echo/TopicEcho_TEST.cc b/src/plugins/topic_echo/TopicEcho_TEST.cc index edb746589..50ec24b9a 100644 --- a/src/plugins/topic_echo/TopicEcho_TEST.cc +++ b/src/plugins/topic_echo/TopicEcho_TEST.cc @@ -16,7 +16,6 @@ */ #include -#include #include @@ -130,7 +129,7 @@ TEST(TopicEchoTest, GZ_UTILS_TEST_DISABLED_ON_WIN32(Echo)) int sleep = 0; int maxSleep = 30; - while(msgStringList->rowCount() == 0 && sleep < maxSleep) + while (msgStringList->rowCount() == 0 && sleep < maxSleep) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); QCoreApplication::processEvents(); @@ -150,18 +149,13 @@ TEST(TopicEchoTest, GZ_UTILS_TEST_DISABLED_ON_WIN32(Echo)) pub.Publish(msg); } - QRegExp regExp13("*13"); - regExp13.setPatternSyntax(QRegExp::Wildcard); - QRegExp regExp14("*14"); - regExp14.setPatternSyntax(QRegExp::Wildcard); - // Wait until all 15 messages are received // To avoid flakiness due to messages coming out of order, we check for both // 13 and 14. There's a chance a lower number comes afterwards, but that's // just bad luck. sleep = 0; - while (msgStringList->stringList().filter(regExp13).count() == 0 - && msgStringList->stringList().filter(regExp14).count() == 0 + while (msgStringList->stringList().filter("13").count() == 0 + && msgStringList->stringList().filter("14").count() == 0 && sleep < maxSleep) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); @@ -176,13 +170,10 @@ TEST(TopicEchoTest, GZ_UTILS_TEST_DISABLED_ON_WIN32(Echo)) // We can't guarantee the order of messages // We expect that out of the 10 messages last, at least 6 belong to the [5-14] // range - QRegExp regExp; - regExp.setPatternSyntax(QRegExp::Wildcard); unsigned int count = 0; for (auto i = 5; i < 15; ++i) { - regExp.setPattern("*" + QString::number(i)); - if (msgStringList->stringList().filter(regExp).count() > 0) + if (msgStringList->stringList().filter(QString::number(i)).count() > 0) ++count; } EXPECT_GE(count, 6u); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3c471aa58..553a2c6b0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,9 +1,6 @@ -configure_file (test_config.hh.in +configure_file (test_config.hh.in ${PROJECT_BINARY_DIR}/include/test_config.hh ) -include_directories ( - ${PROJECT_BINARY_DIR}/include -) add_subdirectory(gtest_vendor) add_subdirectory(helpers) diff --git a/test/helpers/CMakeLists.txt b/test/helpers/CMakeLists.txt index 46af75c2a..082f3dcd5 100644 --- a/test/helpers/CMakeLists.txt +++ b/test/helpers/CMakeLists.txt @@ -2,7 +2,7 @@ set (qt_headers TestHelper.hh ) -QT5_WRAP_CPP(headers_MOC ${qt_headers}) +qt_wrap_cpp(headers_MOC ${qt_headers}) add_library(${PROJECT_NAME}_test_helpers SHARED TestHelper.cc diff --git a/test/integration/CMakeLists.txt b/test/integration/CMakeLists.txt index 70c2ff1e5..2a04b198a 100644 --- a/test/integration/CMakeLists.txt +++ b/test/integration/CMakeLists.txt @@ -1,7 +1,5 @@ gz_get_sources(tests) -find_package(Qt5Test REQUIRED) - gz_build_tests( TYPE INTEGRATION SOURCES ${tests} @@ -9,7 +7,7 @@ gz_build_tests( ${PROJECT_NAME}_test_helpers gz-plugin${GZ_PLUGIN_VER}::loader gz-rendering${GZ_RENDERING_VER}::gz-rendering${GZ_RENDERING_VER} - Qt5::Test - ENVIRONMENT + Qt::Test + ENVIRONMENT GZ_GUI_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} ) diff --git a/test/plugins/CMakeLists.txt b/test/plugins/CMakeLists.txt index ec5cd1b93..6f2b4b345 100644 --- a/test/plugins/CMakeLists.txt +++ b/test/plugins/CMakeLists.txt @@ -2,13 +2,6 @@ if (WIN32) add_definitions(-DBUILDING_DLL) endif() -include_directories( - ${PROJECT_SOURCE_DIR} -) - -link_directories( -) - set (plugins TestBadInheritancePlugin TestInvalidQmlPlugin @@ -18,9 +11,9 @@ set (plugins # Plugin shared libraries foreach (src ${plugins}) - QT5_WRAP_CPP(${src}_MOC ${src}.hh) + qt_wrap_cpp(${src}_MOC ${src}.hh) if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${src}.qrc") - QT5_ADD_RESOURCES(${src}_RCC ${src}.qrc) + qt_add_resources(${src}_RCC ${src}.qrc) endif() add_library(${src} SHARED ${src}.cc @@ -34,4 +27,3 @@ foreach (src ${plugins}) gz-plugin${GZ_PLUGIN_VER}::register ) endforeach (src ${qt_headers_local}) -