From 383f153c54d7aa83472aa9df421c785275d535df Mon Sep 17 00:00:00 2001 From: RTUnreal <22859658+RTUnreal@users.noreply.github.com> Date: Wed, 1 May 2024 22:19:36 +0200 Subject: [PATCH] draft: upgrade codebase to qt6 and cmake (#657) * update qt6 upgrade progress * add flawed addition for QRenderTarget and link needed libs * update to better logging format * move many assets and qml files into qrc * get rid of deprecation messages * remove additional deprecation notices * make Qt6 finally render on desktop with some progress on vr * initialize QRhi with QQuickRenderControl * use default values to stop SegFaults * fix compilation on windows * add windows files for aiding in running exe * fix formatting of testing qt.conf * first attempt on using textures instead of files in AudioTabController * Fix public/private access issue * use getter instead of directly accessing class members * use QImage as a base to set overlay textures * use native logging * add more QImage Overlays * implement faulty vulkan implementation --------- Co-authored-by: ykeara --- src/alarm_clock/vr_alarm.cpp | 7 +- src/openvr/ovr_overlay_wrapper.cpp | 19 +++ src/openvr/ovr_overlay_wrapper.h | 4 + src/overlaycontroller.cpp | 113 ++++++++++-------- src/overlaycontroller.h | 19 ++- src/res/resources.qrc | 6 + src/tabcontrollers/AudioTabController.cpp | 31 ++--- src/tabcontrollers/AudioTabController.h | 6 +- src/tabcontrollers/ChaperoneTabController.cpp | 66 ++++------ src/tabcontrollers/ChaperoneTabController.h | 3 +- src/tabcontrollers/RotationTabController.cpp | 52 +++----- src/tabcontrollers/RotationTabController.h | 5 +- src/tabcontrollers/UtilitiesTabController.cpp | 66 +++++----- src/tabcontrollers/UtilitiesTabController.h | 2 + src/tabcontrollers/VideoTabController.cpp | 82 +++++-------- 15 files changed, 234 insertions(+), 247 deletions(-) diff --git a/src/alarm_clock/vr_alarm.cpp b/src/alarm_clock/vr_alarm.cpp index d39542d..3573a53 100644 --- a/src/alarm_clock/vr_alarm.cpp +++ b/src/alarm_clock/vr_alarm.cpp @@ -6,6 +6,7 @@ #include #include +#include namespace alarm_clock { @@ -23,8 +24,10 @@ VrAlarm::VrAlarm() ovr_overlay_wrapper::hideOverlay( m_alarmOverlayHandle ); - const auto filename = "/res/img/alarm/alarm_activated.png"; - ovr_overlay_wrapper::setOverlayFromFile( m_alarmOverlayHandle, filename ); + // Only need to set it once, no need to keep it in memory + QImage alarmIcon( QString( ":/alarm/alarm_activated.png" ) ); + ovr_overlay_wrapper::setOverlayFromQImage( m_alarmOverlayHandle, + alarmIcon ); ovr_overlay_wrapper::setOverlayWidthInMeters( m_alarmOverlayHandle, 0.3f ); diff --git a/src/openvr/ovr_overlay_wrapper.cpp b/src/openvr/ovr_overlay_wrapper.cpp index c0faef5..6631dc6 100644 --- a/src/openvr/ovr_overlay_wrapper.cpp +++ b/src/openvr/ovr_overlay_wrapper.cpp @@ -1,6 +1,7 @@ #include "ovr_overlay_wrapper.h" #include #include +#include namespace ovr_overlay_wrapper { @@ -100,6 +101,24 @@ OverlayError setOverlayFromFile( vr::VROverlayHandle_t overlayHandle, } } +OverlayError setOverlayFromQImage( vr::VROverlayHandle_t overlayHandle, + QImage& image, + std::string customErrorMsg ) +{ + image.convertTo( QImage::Format_RGBA8888 ); + vr::VROverlayError oError = vr::VROverlay()->SetOverlayRaw( + overlayHandle, image.bits(), image.width(), image.height(), 4 ); + if ( oError != vr::VROverlayError_None ) + { + qCritical() << "Error setting Overlay from" << image << "For" + << getOverlayKey( overlayHandle ) << "with error:" + << vr::VROverlay()->GetOverlayErrorNameFromEnum( oError ) + << customErrorMsg; + return OverlayError::UndefinedError; + } + return OverlayError::NoError; +} + OverlayError showOverlay( vr::VROverlayHandle_t overlayHandle, std::string customErrorMsg ) { diff --git a/src/openvr/ovr_overlay_wrapper.h b/src/openvr/ovr_overlay_wrapper.h index e1bd9c9..ed6df73 100644 --- a/src/openvr/ovr_overlay_wrapper.h +++ b/src/openvr/ovr_overlay_wrapper.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "../utils/paths.h" /* Wrapper For OpenVR's IVR settings class, allows us to do our error logging @@ -42,6 +43,9 @@ OverlayError setOverlayWidthInMeters( vr::VROverlayHandle_t overlayHandle, OverlayError setOverlayFromFile( vr::VROverlayHandle_t overlayHandle, std::string fileName, std::string customErrorMsg = "" ); +OverlayError setOverlayFromQImage( vr::VROverlayHandle_t overlayHandle, + QImage& image, + std::string customErrorMsg = "" ); OverlayError showOverlay( vr::VROverlayHandle_t overlayHandle, std::string customErrorMsg = "" ); OverlayError hideOverlay( vr::VROverlayHandle_t overlayHandle, diff --git a/src/overlaycontroller.cpp b/src/overlaycontroller.cpp index c9a81e6..e197901 100644 --- a/src/overlaycontroller.cpp +++ b/src/overlaycontroller.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -20,6 +21,7 @@ #include #include #include +#include "openvr/ovr_overlay_wrapper.h" #include "utils/Matrix.h" #include "keyboard_input/input_sender.h" #include "settings/settings.h" @@ -387,18 +389,10 @@ void OverlayController::SetWidget( QQuickItem* quickItem, vr::VROverlayFlags_SendVRSmoothScrollEvents, true ); - constexpr auto thumbiconFilename = "res/img/icons/thumbicon.png"; - const auto thumbIconPath - = paths::binaryDirectoryFindFile( thumbiconFilename ); - if ( thumbIconPath.has_value() ) { - vr::VROverlay()->SetOverlayFromFile( m_ulOverlayThumbnailHandle, - thumbIconPath->c_str() ); - } - else - { - qCritical() << "Could not find thumbnail icon \"" - << thumbiconFilename << "\""; + QImage thumbiconImg( QString( ":/icons/thumbicon.png" ) ); + ovr_overlay_wrapper::setOverlayFromQImage( + m_ulOverlayThumbnailHandle, thumbiconImg ); } // Too many render calls in too short time overwhelm Qt and an @@ -413,10 +407,25 @@ void OverlayController::SetWidget( QQuickItem* quickItem, this, SLOT( renderOverlay() ) ); +#if QT_CONFIG( vulkan ) + if ( m_window.graphicsApi() == QSGRendererInterface::Vulkan ) + { + m_vulkanInstance.reset( new QVulkanInstance ); + m_vulkanInstance->setExtensions( + QQuickGraphicsConfiguration::preferredInstanceExtensions() ); + if ( !m_vulkanInstance->create() ) + throw std::runtime_error( "Cannot create vulkan instance" ); + + m_window.setVulkanInstance( m_vulkanInstance.get() ); + } +#endif + if ( !m_renderControl.initialize() ) throw std::runtime_error( "could not initialize m_renderControl" ); - QRhi* rhi = m_renderControl.rhi(); + QRhi* rhi = this->rhi(); + + qInfo() << "Started with" << rhi->backendName(); m_pFBTexture.reset( rhi->newTexture( QRhiTexture::RGBA8, @@ -444,7 +453,6 @@ void OverlayController::SetWidget( QQuickItem* quickItem, 0, static_cast( quickItem->width() ), static_cast( quickItem->height() ) ); - m_renderControl.initialize(); vr::HmdVector2_t vecWindowSize = { static_cast( quickItem->width() ), @@ -511,40 +519,49 @@ void OverlayController::OnRenderRequest() } } -vr::ETextureType OverlayController::vrTextureTypeFromRhiBackend() +void OverlayController::SetOverlayFromQRhiTexture( QRhiTexture& tex ) { - if ( !m_cached_vr_texture_type.has_value() ) + vr::Texture_t vrTex = {}; + QRhi* rhi = this->rhi(); + + switch ( rhi->backend() ) { - QRhi* rhi = m_renderControl.rhi(); - switch ( rhi->backend() ) - { - case QRhi::Vulkan: - m_cached_vr_texture_type = vr::TextureType_Vulkan; - break; - case QRhi::D3D12: - m_cached_vr_texture_type = vr::TextureType_DirectX12; - break; - case QRhi::D3D11: - m_cached_vr_texture_type = vr::TextureType_DirectX; - break; - case QRhi::OpenGLES2: - m_cached_vr_texture_type = vr::TextureType_OpenGL; - break; - case QRhi::Metal: - m_cached_vr_texture_type = vr::TextureType_Metal; - break; - default: - qFatal() << "unknown RHI backend encountered:" << rhi->backend(); - throw std::runtime_error( "unsupported RHI backend encountered" ); - } + case QRhi::OpenGLES2: + { + vrTex.handle = reinterpret_cast( tex.nativeTexture().object ); + vrTex.eType = vr::TextureType_OpenGL; + vrTex.eColorSpace = vr::ColorSpace_Auto; } - return m_cached_vr_texture_type.value(); -} -vr::Texture_t OverlayController::vrTextureFromRhiTexture( QRhiTexture& tex ) -{ - return { reinterpret_cast( tex.nativeTexture().object ), - vrTextureTypeFromRhiBackend(), - vr::ColorSpace_Auto }; + break; +#if QT_CONFIG( vulkan ) + case QRhi::Vulkan: + { + const QRhiVulkanNativeHandles* vulkan_handles + = reinterpret_cast( + rhi->nativeHandles() ); + vr::VRVulkanTextureData_t vulkan = { + .m_nImage = tex.nativeTexture().object, + .m_pDevice = vulkan_handles->dev, + .m_pPhysicalDevice = vulkan_handles->physDev, + .m_pInstance = vulkan_handles->inst->vkInstance(), + .m_pQueue = vulkan_handles->gfxQueue, + .m_nQueueFamilyIndex = vulkan_handles->gfxQueueIdx, + .m_nWidth = static_cast( tex.pixelSize().width() ), + .m_nHeight = static_cast( tex.pixelSize().height() ), + .m_nFormat = tex.format(), + .m_nSampleCount = static_cast( tex.sampleCount() ), + }; + vrTex.handle = &vulkan; + vrTex.eType = vr::TextureType_Vulkan; + vrTex.eColorSpace = vr::ColorSpace_Auto; + } + break; +#endif + default: + qFatal() << "unimplemented backend:" << rhi->backend(); + throw std::runtime_error( "unimplemented backend" ); + } + vr::VROverlay()->SetOverlayTexture( m_ulOverlayHandle, &vrTex ); } void OverlayController::renderOverlay() @@ -563,13 +580,7 @@ void OverlayController::renderOverlay() m_renderControl.render(); m_renderControl.endFrame(); - auto tex = vrTextureFromRhiTexture( *m_pFBTexture ); - vr::VROverlay()->SetOverlayTexture( m_ulOverlayHandle, &tex ); - - /* - m_openGLContext.functions()->glFlush(); // We need to flush otherwise - // the texture may be empty. - */ + SetOverlayFromQRhiTexture( *m_pFBTexture ); } } diff --git a/src/overlaycontroller.h b/src/overlaycontroller.h index 2b87b55..96f74cb 100644 --- a/src/overlaycontroller.h +++ b/src/overlaycontroller.h @@ -108,6 +108,12 @@ private: vr::VROverlayHandle_t m_ulOverlayThumbnailHandle = vr::k_ulOverlayHandleInvalid; +#if QT_CONFIG( vulkan ) + std::unique_ptr m_vulkanInstance = nullptr; +#endif + QQuickRenderControl m_renderControl; + QQuickWindow m_window{ &m_renderControl }; + std::optional m_cached_vr_texture_type; std::unique_ptr m_pFBTexture; std::unique_ptr m_render_target; @@ -163,11 +169,8 @@ private: QJsonObject m_remoteVersionJsonObject; public: - - QQuickRenderControl m_renderControl; - QQuickWindow m_window{ &m_renderControl }; // I know it's an ugly hack to make them public to enable external - // access, but I am too lazy to implement getters. + // access, but I am too lazy to implement getters. SteamVRTabController m_steamVRTabController; ChaperoneTabController m_chaperoneTabController; MoveCenterTabController m_moveCenterTabController; @@ -191,13 +194,17 @@ private: void processRotationBindings(); void processExclusiveInputBinding(); + inline QRhi* rhi() + { + return m_renderControl.rhi(); + } + bool m_exclusiveState = false; bool m_keyPressOneState = false; bool m_keyPressTwoState = false; public: - vr::ETextureType vrTextureTypeFromRhiBackend(); - vr::Texture_t vrTextureFromRhiTexture( QRhiTexture& tex ); + void SetOverlayFromQRhiTexture( QRhiTexture& tex ); OverlayController( bool desktopMode, bool noSound, QQmlEngine& qmlEngine ); virtual ~OverlayController(); diff --git a/src/res/resources.qrc b/src/res/resources.qrc index cb79707..ff43e76 100644 --- a/src/res/resources.qrc +++ b/src/res/resources.qrc @@ -3,6 +3,9 @@ img/common/backarrow.svg img/common/check.svg + + img/icons/thumbicon.png + img/audio/microphone/mic_on.svg img/audio/microphone/mic_off.svg @@ -65,4 +68,7 @@ img/rotation/noautoturn.png img/rotation/noautoturn.svg + + img/alarm/alarm_activated.png + diff --git a/src/tabcontrollers/AudioTabController.cpp b/src/tabcontrollers/AudioTabController.cpp index d6167fe..898f537 100644 --- a/src/tabcontrollers/AudioTabController.cpp +++ b/src/tabcontrollers/AudioTabController.cpp @@ -7,6 +7,7 @@ #include "../settings/settings.h" #include "../settings/settings_object.h" #include "../utils/update_rate.h" +#include "openvr/ovr_overlay_wrapper.h" #ifdef _WIN32 # include "audiomanager/AudioManagerWindows.h" #elif __linux__ @@ -87,31 +88,19 @@ void AudioTabController::initStage2( OverlayController* var_parent ) return; } - QImage pushToTalkIcon; - Q_ASSERT( pushToTalkIcon.load( - QString( "qrc:/res/img/audio/microphone/ptt_notification.png" ) ) ); - QImage pushToMuteIcon; - Q_ASSERT( pushToMuteIcon.load( - QString( "qrc:/res/img/audio/microphone/ptt_notification.png" ) ) ); + m_pushToTalkValues.pushToTalkImg.reset( + new QImage( QString( ":/microphone/ptt_notification.png" ) ) ); + m_pushToTalkValues.pushToMuteImg.reset( + new QImage( QString( ":/microphone/ptm_notification.png" ) ) ); - emit defaultProfileDisplay(); - return; - - auto* rhi = parent->m_renderControl.rhi(); - m_pushToTalkValues.pushToTalkTex.reset( - rhi->newTexture( QRhiTexture::RGBA8, pushToTalkIcon.size(), 1 ) ); - m_pushToTalkValues.pushToMuteTex.reset( - rhi->newTexture( QRhiTexture::RGBA8, pushToTalkIcon.size(), 1 ) ); - - auto* pushToTex = m_pushToTalkValues.pushToTalkTex.get(); + auto* pushToImg = m_pushToTalkValues.pushToTalkImg.get(); if ( settings::getSetting( settings::BoolSetting::AUDIO_micReversePtt ) ) { - pushToTex = m_pushToTalkValues.pushToMuteTex.get(); + pushToImg = m_pushToTalkValues.pushToMuteImg.get(); } - auto tex = parent->vrTextureFromRhiTexture( *pushToTex ); - vr::VROverlay()->SetOverlayTexture( m_pushToTalkValues.overlayHandle, - &tex ); + ovr_overlay_wrapper::setOverlayFromQImage( m_pushToTalkValues.overlayHandle, + *pushToImg ); vr::VROverlay()->SetOverlayWidthInMeters( m_pushToTalkValues.overlayHandle, 0.02f ); vr::HmdMatrix34_t notificationTransform @@ -356,6 +345,8 @@ void AudioTabController::setMicReversePtt( bool value, bool notify ) settings::setSetting( settings::BoolSetting::AUDIO_micReversePtt, value ); + // TODO: if reenabled use `ovr_overlay_wrapper::setOverlayFromQImage` + // instead if ( value ) { // vr::VROverlay()->SetOverlayFromFile(m_ptt_overlayHandle,/*pt_mute*/); diff --git a/src/tabcontrollers/AudioTabController.h b/src/tabcontrollers/AudioTabController.h index 59a23ee..83a1e70 100644 --- a/src/tabcontrollers/AudioTabController.h +++ b/src/tabcontrollers/AudioTabController.h @@ -5,7 +5,7 @@ #include "audiomanager/AudioManager.h" #include -#include +#include #include "../utils/FrameRateUtils.h" #include "../settings/settings_object.h" @@ -116,8 +116,8 @@ private: struct { vr::VROverlayHandle_t overlayHandle = vr::k_ulOverlayHandleInvalid; - std::unique_ptr pushToTalkTex; - std::unique_ptr pushToMuteTex; + std::unique_ptr pushToTalkImg; + std::unique_ptr pushToMuteImg; } m_pushToTalkValues; int m_playbackDeviceIndex = -1; diff --git a/src/tabcontrollers/ChaperoneTabController.cpp b/src/tabcontrollers/ChaperoneTabController.cpp index 86d558b..64f2841 100644 --- a/src/tabcontrollers/ChaperoneTabController.cpp +++ b/src/tabcontrollers/ChaperoneTabController.cpp @@ -1619,8 +1619,22 @@ void ChaperoneTabController::initCenterMarkerOverlay() "" ); if ( overlayError == ovr_overlay_wrapper::OverlayError::NoError ) { - ovr_overlay_wrapper::setOverlayFromFile( - m_chaperoneFloorOverlayHandle, m_floorMarkerFN, "" ); + m_floorMarkers[-3] = std::unique_ptr( + new QImage( QString( ":/chaperone/centermarkl3.png" ) ) ); + m_floorMarkers[-2] = std::unique_ptr( + new QImage( QString( ":/chaperone/centermarkl2.png" ) ) ); + m_floorMarkers[-1] = std::unique_ptr( + new QImage( QString( ":/chaperone/centermarkl1.png" ) ) ); + m_floorMarkers[0] = std::unique_ptr( + new QImage( QString( ":/chaperone/centermark.png" ) ) ); + m_floorMarkers[1] = std::unique_ptr( + new QImage( QString( ":/chaperone/centermarkr1.png" ) ) ); + m_floorMarkers[2] = std::unique_ptr( + new QImage( QString( ":/chaperone/centermarkr2.png" ) ) ); + m_floorMarkers[3] = std::unique_ptr( + new QImage( QString( ":/chaperone/centermarkr3.png" ) ) ); + ovr_overlay_wrapper::setOverlayFromQImage( + m_chaperoneFloorOverlayHandle, *m_floorMarkers[0], "" ); ovr_overlay_wrapper::setOverlayWidthInMeters( m_chaperoneFloorOverlayHandle, 0.5f ); updateCenterMarkerOverlayColor(); @@ -1662,57 +1676,25 @@ void ChaperoneTabController::checkCenterMarkerOverlayRotationCount() if ( rotation > 0 ) { rotation = rotation + 0.5f; - int fullRotation = static_cast( rotation ); - switch ( fullRotation ) - { - case 0: - m_floorMarkerFN = "/res/img/chaperone/centermark.png"; - rotationNext = 0; - break; - case 1: - m_floorMarkerFN = "/res/img/chaperone/centermarkr1.png"; - rotationNext = 1; - break; - case 2: - m_floorMarkerFN = "/res/img/chaperone/centermarkr2.png"; - rotationNext = 2; - break; - - default: - - m_floorMarkerFN = "/res/img/chaperone/centermarkr3.png"; + rotationNext = static_cast( rotation ); + if ( rotationNext > 3 ) rotationNext = 3; - } } else { rotation = rotation + 0.5f; - int fullRotation = static_cast( std::floor( rotation ) ); - switch ( fullRotation ) - { - case 0: - m_floorMarkerFN = "/res/img/chaperone/centermark.png"; - rotationNext = 0; - break; - case -1: - m_floorMarkerFN = "/res/img/chaperone/centermarkl1.png"; - rotationNext = -1; - break; - case -2: - m_floorMarkerFN = "/res/img/chaperone/centermarkl2.png"; - rotationNext = -2; - break; - default: - m_floorMarkerFN = "/res/img/chaperone/centermarkl3.png"; + rotationNext = static_cast( std::floor( rotation ) ); + if ( rotationNext < -3 ) rotationNext = -3; - } } if ( rotationNext != m_rotationCurrent && m_centerMarkerOverlayIsInit ) { m_rotationCurrent = rotationNext; - ovr_overlay_wrapper::setOverlayFromFile( - m_chaperoneFloorOverlayHandle, m_floorMarkerFN, "" ); + ovr_overlay_wrapper::setOverlayFromQImage( + m_chaperoneFloorOverlayHandle, + *m_floorMarkers[rotationNext], + "" ); } } else diff --git a/src/tabcontrollers/ChaperoneTabController.h b/src/tabcontrollers/ChaperoneTabController.h index a28977e..38b3176 100644 --- a/src/tabcontrollers/ChaperoneTabController.h +++ b/src/tabcontrollers/ChaperoneTabController.h @@ -2,6 +2,7 @@ #pragma once #include +#include #include #include #include @@ -379,7 +380,7 @@ private: std::vector chaperoneProfiles; - std::string m_floorMarkerFN = "/res/img/chaperone/centermark.png"; + std::map> m_floorMarkers; void initCenterMarkerOverlay(); void updateCenterMarkerOverlayColor(); void checkCenterMarkerOverlayRotationCount(); diff --git a/src/tabcontrollers/RotationTabController.cpp b/src/tabcontrollers/RotationTabController.cpp index 427a8c9..8e31aa5 100644 --- a/src/tabcontrollers/RotationTabController.cpp +++ b/src/tabcontrollers/RotationTabController.cpp @@ -39,29 +39,14 @@ void RotationTabController::initStage2( OverlayController* var_parent ) return; } + m_autoturnValues.autoturnImg.reset( + new QImage( QString( ":/rotation/autoturn.png" ) ) ); + m_autoturnValues.noautoturnImg.reset( + new QImage( QString( ":/rotation/noautoturn.png" ) ) ); - constexpr auto autoturnIconFilepath = "/res/img/rotation/autoturn.png"; - constexpr auto noautoturnIconFilepath = "/res/img/rotation/noautoturn.png"; + ovr_overlay_wrapper::setOverlayFromQImage( m_autoturnValues.overlayHandle, + *m_autoturnValues.autoturnImg ); - const auto autoturnIconFilePath - = paths::verifyIconFilePath( autoturnIconFilepath ); - const auto noautoturnIconFilePath - = paths::verifyIconFilePath( noautoturnIconFilepath ); - - if ( !autoturnIconFilePath.has_value() - || !noautoturnIconFilePath.has_value() ) - { - emit defaultProfileDisplay(); - return; - } - - m_autoturnValues.autoturnPath = *autoturnIconFilePath; - m_autoturnValues.noautoturnPath = *noautoturnIconFilePath; - - auto pushToPath = m_autoturnValues.autoturnPath.c_str(); - - vr::VROverlay()->SetOverlayFromFile( m_autoturnValues.overlayHandle, - pushToPath ); vr::VROverlay()->SetOverlayWidthInMeters( m_autoturnValues.overlayHandle, 0.02f ); vr::HmdMatrix34_t notificationTransform @@ -677,22 +662,21 @@ void RotationTabController::setAutoTurnEnabled( bool value, bool notify ) emit autoTurnEnabledChanged( value ); } - if ( !value ) - { - vr::VROverlay()->SetOverlayFromFile( - m_autoturnValues.overlayHandle, - m_autoturnValues.noautoturnPath.c_str() ); - } - else - { - vr::VROverlay()->SetOverlayFromFile( - m_autoturnValues.overlayHandle, - m_autoturnValues.autoturnPath.c_str() ); - } - if ( autoTurnShowNotification() && getNotificationOverlayHandle() != vr::k_ulOverlayHandleInvalid ) { + if ( !value ) + { + ovr_overlay_wrapper::setOverlayFromQImage( + m_autoturnValues.overlayHandle, + *m_autoturnValues.noautoturnImg ); + } + else + { + ovr_overlay_wrapper::setOverlayFromQImage( + m_autoturnValues.overlayHandle, *m_autoturnValues.autoturnImg ); + } + vr::VROverlay()->SetOverlayAlpha( getNotificationOverlayHandle(), 1.0f ); vr::VROverlay()->ShowOverlay( getNotificationOverlayHandle() ); diff --git a/src/tabcontrollers/RotationTabController.h b/src/tabcontrollers/RotationTabController.h index de8253a..ca20fe3 100644 --- a/src/tabcontrollers/RotationTabController.h +++ b/src/tabcontrollers/RotationTabController.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -99,8 +100,8 @@ private: struct { vr::VROverlayHandle_t overlayHandle = vr::k_ulOverlayHandleInvalid; - std::string autoturnPath; - std::string noautoturnPath; + std::unique_ptr autoturnImg; + std::unique_ptr noautoturnImg; } m_autoturnValues; virtual vr::VROverlayHandle_t getNotificationOverlayHandle() diff --git a/src/tabcontrollers/UtilitiesTabController.cpp b/src/tabcontrollers/UtilitiesTabController.cpp index ab22206..46310ec 100644 --- a/src/tabcontrollers/UtilitiesTabController.cpp +++ b/src/tabcontrollers/UtilitiesTabController.cpp @@ -7,7 +7,9 @@ #include "../keyboard_input/input_sender.h" #include "../settings/settings.h" #include "../utils/update_rate.h" +#include "openvr/ovr_overlay_wrapper.h" #include +#include #include // application namespace @@ -257,34 +259,36 @@ vr::VROverlayHandle_t UtilitiesTabController::createBatteryOverlay( batteryKey.c_str(), batteryKey.c_str(), &handle ); if ( overlayError == vr::VROverlayError_None ) { - QString batteryIconPath = getBatteryIconPath( 0 ); - if ( QFile::exists( batteryIconPath ) ) + m_batteryImgs[0] = std::unique_ptr( + new QImage( QString( ":/battery/battery_0.png" ) ) ); + m_batteryImgs[1] = std::unique_ptr( + new QImage( QString( ":/battery/battery_1.png" ) ) ); + m_batteryImgs[2] = std::unique_ptr( + new QImage( QString( ":/battery/battery_2.png" ) ) ); + m_batteryImgs[3] = std::unique_ptr( + new QImage( QString( ":/battery/battery_3.png" ) ) ); + m_batteryImgs[4] = std::unique_ptr( + new QImage( QString( ":/battery/battery_4.png" ) ) ); + m_batteryImgs[5] = std::unique_ptr( + new QImage( QString( ":/battery/battery_5.png" ) ) ); + ovr_overlay_wrapper::setOverlayFromQImage( handle, *m_batteryImgs[0] ); + vr::VROverlay()->SetOverlayWidthInMeters( handle, 0.045f ); + vr::HmdMatrix34_t notificationTransform; + if ( style == 1 ) { - vr::VROverlay()->SetOverlayFromFile( - handle, batteryIconPath.toStdString().c_str() ); - vr::VROverlay()->SetOverlayWidthInMeters( handle, 0.045f ); - vr::HmdMatrix34_t notificationTransform; - if ( style == 1 ) - { - notificationTransform = { { { 1.0f, 0.0f, 0.0f, 0.00f }, - { 0.0f, -1.0f, 0.0f, 0.0081f }, - { 0.0f, 0.0f, -1.0f, -0.028f } } }; - } - else - { - notificationTransform = { { { 1.0f, 0.0f, 0.0f, 0.00f }, - { 0.0f, -1.0f, 0.0f, 0.0081f }, - { 0.0f, 0.0f, -1.0f, -0.0178f } } }; - } - vr::VROverlay()->SetOverlayTransformTrackedDeviceRelative( - handle, index, ¬ificationTransform ); - qInfo() << "Created battery overlay for device " << index; + notificationTransform = { { { 1.0f, 0.0f, 0.0f, 0.00f }, + { 0.0f, -1.0f, 0.0f, 0.0081f }, + { 0.0f, 0.0f, -1.0f, -0.028f } } }; } else { - qCritical() << "Could not find battery icon \"" << batteryIconPath - << "\""; + notificationTransform = { { { 1.0f, 0.0f, 0.0f, 0.00f }, + { 0.0f, -1.0f, 0.0f, 0.0081f }, + { 0.0f, 0.0f, -1.0f, -0.0178f } } }; } + vr::VROverlay()->SetOverlayTransformTrackedDeviceRelative( + handle, index, ¬ificationTransform ); + qInfo() << "Created battery overlay for device " << index; } else { @@ -378,19 +382,9 @@ void UtilitiesTabController::handleTrackerBatOvl() qInfo() << "Updating battery overlay for device " << i << " to " << batteryState << "(" << battery << ")" << QString::number( m_batteryOverlayHandles[i] ); - QString batteryIconPath - = getBatteryIconPath( batteryState ); - if ( QFile::exists( batteryIconPath ) ) - { - vr::VROverlay()->SetOverlayFromFile( - m_batteryOverlayHandles[i], - batteryIconPath.toStdString().c_str() ); - } - else - { - qCritical() << "Could not find battery icon \"" - << batteryIconPath << "\""; - } + ovr_overlay_wrapper::setOverlayFromQImage( + m_batteryOverlayHandles[i], + *m_batteryImgs[batteryState] ); m_batteryState[i] = batteryState; } } diff --git a/src/tabcontrollers/UtilitiesTabController.h b/src/tabcontrollers/UtilitiesTabController.h index 8dc0fff..4bd57d1 100644 --- a/src/tabcontrollers/UtilitiesTabController.h +++ b/src/tabcontrollers/UtilitiesTabController.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include "src/keyboard_input/keyboard_input.h" @@ -29,6 +30,7 @@ private: unsigned settingsUpdateCounter = 0; + std::array, 6> m_batteryImgs; vr::VROverlayHandle_t m_batteryOverlayHandles[vr::k_unMaxTrackedDeviceCount] = { 0 }; int m_batteryState[vr::k_unMaxTrackedDeviceCount]; diff --git a/src/tabcontrollers/VideoTabController.cpp b/src/tabcontrollers/VideoTabController.cpp index 17748c1..8a6165d 100644 --- a/src/tabcontrollers/VideoTabController.cpp +++ b/src/tabcontrollers/VideoTabController.cpp @@ -52,30 +52,21 @@ void VideoTabController::initBrightnessOverlay() notifKey.c_str(), notifKey.c_str(), &m_brightnessOverlayHandle ); if ( overlayError == vr::VROverlayError_None ) { - const auto notifIconPath = paths::binaryDirectoryFindFile( - video_keys::k_brightnessOverlayFilename ); - if ( notifIconPath.has_value() ) - { - vr::VROverlay()->SetOverlayFromFile( m_brightnessOverlayHandle, - notifIconPath->c_str() ); - vr::VROverlay()->SetOverlayWidthInMeters( m_brightnessOverlayHandle, - k_overlayWidth ); - vr::HmdMatrix34_t notificationTransform - = { { { 1.0f, 0.0f, 0.0f, 0.00f }, - { 0.0f, 1.0f, 0.0f, 0.00f }, - { 0.0f, 0.0f, 1.0f, k_hmdDistance } } }; - vr::VROverlay()->SetOverlayTransformTrackedDeviceRelative( - m_brightnessOverlayHandle, - vr::k_unTrackedDeviceIndex_Hmd, - ¬ificationTransform ); - vr::VROverlay()->SetOverlaySortOrder( m_brightnessOverlayHandle, - sortMax ); - } - else - { - qCritical() << "Could not find brightness overlay \"" - << video_keys::k_brightnessOverlayFilename << "\""; - } + QImage notifIcon( QString( ":/video/dimmer.png" ) ); + ovr_overlay_wrapper::setOverlayFromQImage( m_brightnessOverlayHandle, + notifIcon ); + vr::VROverlay()->SetOverlayWidthInMeters( m_brightnessOverlayHandle, + k_overlayWidth ); + vr::HmdMatrix34_t notificationTransform + = { { { 1.0f, 0.0f, 0.0f, 0.00f }, + { 0.0f, 1.0f, 0.0f, 0.00f }, + { 0.0f, 0.0f, 1.0f, k_hmdDistance } } }; + vr::VROverlay()->SetOverlayTransformTrackedDeviceRelative( + m_brightnessOverlayHandle, + vr::k_unTrackedDeviceIndex_Hmd, + ¬ificationTransform ); + vr::VROverlay()->SetOverlaySortOrder( m_brightnessOverlayHandle, + sortMax ); } else { @@ -95,32 +86,23 @@ void VideoTabController::initColorOverlay() notifKey.c_str(), notifKey.c_str(), &m_colorOverlayHandle ); if ( overlayError == vr::VROverlayError_None ) { - const auto notifIconPath = paths::binaryDirectoryFindFile( - video_keys::k_colorOverlayFilename ); - if ( notifIconPath.has_value() ) - { - vr::VROverlay()->SetOverlayFromFile( m_colorOverlayHandle, - notifIconPath->c_str() ); - vr::VROverlay()->SetOverlayWidthInMeters( m_colorOverlayHandle, - k_overlayWidth ); - // position it just slightly further out so we don't have to worry - // about render order. - vr::HmdMatrix34_t notificationTransform - = { { { 1.0f, 0.0f, 0.0f, 0.00f }, - { 0.0f, 1.0f, 0.0f, 0.00f }, - { 0.0f, 0.0f, 1.0f, ( k_hmdDistance - 0.01f ) } } }; - vr::VROverlay()->SetOverlayTransformTrackedDeviceRelative( - m_colorOverlayHandle, - vr::k_unTrackedDeviceIndex_Hmd, - ¬ificationTransform ); - vr::VROverlay()->SetOverlaySortOrder( m_brightnessOverlayHandle, - sortMax ); - } - else - { - qCritical() << "Could not find Base color overlay: \"" - << video_keys::k_colorOverlayFilename << "\""; - } + QImage notifIcon( QString( ":/video/color.png" ) ); + ovr_overlay_wrapper::setOverlayFromQImage( m_colorOverlayHandle, + notifIcon ); + vr::VROverlay()->SetOverlayWidthInMeters( m_colorOverlayHandle, + k_overlayWidth ); + // position it just slightly further out so we don't have to worry + // about render order. + vr::HmdMatrix34_t notificationTransform + = { { { 1.0f, 0.0f, 0.0f, 0.00f }, + { 0.0f, 1.0f, 0.0f, 0.00f }, + { 0.0f, 0.0f, 1.0f, ( k_hmdDistance - 0.01f ) } } }; + vr::VROverlay()->SetOverlayTransformTrackedDeviceRelative( + m_colorOverlayHandle, + vr::k_unTrackedDeviceIndex_Hmd, + ¬ificationTransform ); + vr::VROverlay()->SetOverlaySortOrder( m_brightnessOverlayHandle, + sortMax ); } else {