On the Steam Frame, the fixed 1200x800 QML layout overflows: about the bottom quarter is cut off and the navigation icons overlap their text. Forcing 96 DPI and switching the Quick Controls style didn't help, so the cause has to be measured rather than guessed. - SetWidget() logs the application font (family, pt, px), what 20 pt (MyText) is in px, the screen's DPI and the device pixel ratio. - --snapshot <file> writes the rendered overlay (RenderBackend::readback) as PNG at most once per second while it is visible. A time interval, because OVRAS only renders when the scene changes. Written to a temporary file and renamed, so readers never see a partial file. - run.sh passes arguments after the graphics API to the program. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
170 lines
6.3 KiB
C++
170 lines
6.3 KiB
C++
#include "utils/setup.h"
|
|
#include "settings/settings.h"
|
|
#include "openvr/ovr_settings_wrapper.h"
|
|
#include "render/RenderBackend.h"
|
|
|
|
#include <QtLogging>
|
|
#include <QtDebug>
|
|
#include <memory>
|
|
|
|
#ifdef _WIN64
|
|
# include <windows.h>
|
|
extern "C" __declspec( dllexport ) DWORD NvOptimusEnablement = 0x00000001;
|
|
extern "C" __declspec( dllexport ) DWORD AmdPowerXpressRequestHighPerformance
|
|
= 0x00000001;
|
|
#endif
|
|
|
|
int main( int argc, char* argv[] )
|
|
{
|
|
setUpLogging();
|
|
|
|
qInfo() << "Settings File: " << settings::initializeAndGetSettingsPath();
|
|
|
|
qInfo() << settings::getSettingsAndValues();
|
|
|
|
QCoreApplication::setAttribute( Qt::AA_Use96Dpi );
|
|
QCoreApplication::setAttribute( Qt::AA_UseDesktopOpenGL );
|
|
MyQApplication mainEventLoop( argc, argv );
|
|
mainEventLoop.setOrganizationName(
|
|
application_strings::applicationOrganizationName );
|
|
mainEventLoop.setApplicationName( application_strings::applicationName );
|
|
mainEventLoop.setApplicationDisplayName(
|
|
application_strings::applicationDisplayName );
|
|
mainEventLoop.setApplicationVersion(
|
|
application_strings::applicationVersionString );
|
|
|
|
const auto commandLineArgs
|
|
= argument::returnCommandLineParser( mainEventLoop );
|
|
|
|
// It is important that either install_manifest or remove_manifest are true,
|
|
// otherwise the handleManifests function will not behave properly.
|
|
if ( commandLineArgs.forceInstallManifest
|
|
|| commandLineArgs.forceRemoveManifest )
|
|
{
|
|
manifest::handleManifests( commandLineArgs.forceInstallManifest,
|
|
commandLineArgs.forceRemoveManifest );
|
|
}
|
|
|
|
// Render backend (render/RenderBackend.h). Chosen before connecting to
|
|
// OpenVR, so a wrong --graphics-api fails right away.
|
|
GraphicsApi graphicsApi = GraphicsApi::OpenGL;
|
|
if ( !parseGraphicsApi( commandLineArgs.graphicsApi, &graphicsApi ) )
|
|
{
|
|
qCritical() << "Unknown graphics API:" << commandLineArgs.graphicsApi
|
|
<< "(expected opengl or vulkan)";
|
|
return ReturnErrorCode::GENERAL_FAILURE;
|
|
}
|
|
std::unique_ptr<RenderBackend> renderBackend
|
|
= createRenderBackend( graphicsApi );
|
|
if ( !renderBackend )
|
|
{
|
|
qCritical() << "Graphics API" << commandLineArgs.graphicsApi
|
|
<< "is not compiled into this build";
|
|
return ReturnErrorCode::GENERAL_FAILURE;
|
|
}
|
|
|
|
openvr_init::initializeOpenVR(
|
|
openvr_init::OpenVrInitializationType::Overlay );
|
|
|
|
// Initialized after OpenVR, because the Vulkan backend needs SteamVR's
|
|
// device requirements (openvr_init::renderInterop()), and before
|
|
// OverlayController, because QQuickWindow::setGraphicsApi() must run
|
|
// before any QQuickWindow exists (OverlayController owns one).
|
|
QString renderBackendError;
|
|
if ( !renderBackend->initialize( openvr_init::renderInterop(),
|
|
&renderBackendError ) )
|
|
{
|
|
qCritical() << renderBackend->name()
|
|
<< "initialization failed:" << renderBackendError;
|
|
return ReturnErrorCode::GENERAL_FAILURE;
|
|
}
|
|
QQuickWindow::setGraphicsApi( renderBackend->graphicsApi() );
|
|
|
|
try
|
|
{
|
|
QQmlEngine qmlEngine;
|
|
|
|
// Just error checking to ensure QRC works properly
|
|
qDebug() << "list of qmldirs";
|
|
QDirIterator it( ":", QDirIterator::Subdirectories );
|
|
while ( it.hasNext() )
|
|
{
|
|
qDebug() << it.next();
|
|
}
|
|
|
|
std::unique_ptr<advsettings::OverlayController> controller(
|
|
new advsettings::OverlayController( commandLineArgs.desktopMode,
|
|
commandLineArgs.forceNoSound,
|
|
qmlEngine,
|
|
std::move( renderBackend ) ) );
|
|
controller->setSnapshotPath( commandLineArgs.snapshotPath );
|
|
//const auto url
|
|
// = QUrl( ":/qt/qml/AdvancedSettings/src/res/qml/common/mainwidget.qml" );
|
|
QQmlComponent component( &qmlEngine, ":/qt/qml/AdvancedSettings/src/res/qml/common/mainwidget.qml" );
|
|
auto errors = component.errors();
|
|
for ( auto& e : errors )
|
|
{
|
|
qCritical() << "QML Error: "
|
|
<< e.toString().toStdString(); //<< std::endl;
|
|
}
|
|
auto quickObj = component.create();
|
|
controller->SetWidget( qobject_cast<QQuickItem*>( quickObj ),
|
|
application_strings::applicationDisplayName,
|
|
application_strings::applicationKey );
|
|
|
|
// Attempts to install the application manifest on all "regular" starts.
|
|
if ( !commandLineArgs.forceNoManifest )
|
|
{
|
|
try
|
|
{
|
|
const auto manifestPath = paths::binaryDirectoryFindFile(
|
|
manifest::kVRManifestName );
|
|
if ( !manifestPath.has_value() )
|
|
{
|
|
throw std::runtime_error(
|
|
"Could not find applications manifest." );
|
|
}
|
|
else
|
|
{
|
|
manifest::installApplicationManifest( *manifestPath );
|
|
}
|
|
}
|
|
catch ( std::exception& e )
|
|
{
|
|
qCritical() << e.what();
|
|
}
|
|
}
|
|
|
|
if ( commandLineArgs.desktopMode
|
|
|| settings::getSetting(
|
|
settings::BoolSetting::APPLICATION_desktopModeToggle ) )
|
|
{
|
|
//TODO TEMP
|
|
//qDebug() << "Desktop MODE!";
|
|
//auto m_pWindow = new QQuickWindow();
|
|
//qobject_cast<QQuickItem*>( quickObj )
|
|
// ->setParentItem( m_pWindow->contentItem() );
|
|
//m_pWindow->setGeometry(
|
|
// 0,
|
|
// 0,
|
|
// static_cast<int>(
|
|
// qobject_cast<QQuickItem*>( quickObj )->width() ),
|
|
// static_cast<int>(
|
|
// qobject_cast<QQuickItem*>( quickObj )->height() ) );
|
|
//m_pWindow->show();
|
|
}
|
|
if ( commandLineArgs.resetSettings )
|
|
{
|
|
// resets all settings if called
|
|
ovr_settings_wrapper::resetAllSettings();
|
|
}
|
|
|
|
return mainEventLoop.exec();
|
|
}
|
|
catch ( const std::exception& e )
|
|
{
|
|
qFatal() << e.what();
|
|
return ReturnErrorCode::GENERAL_FAILURE;
|
|
}
|
|
}
|