History

Merge branch 'master' of github.com:highfidelity/hifi into perfTest_1

NissimHadar committed 8 years ago

Commit 5f219e22 parents 39e5b57 ea2651217 files · +310 −158Browse files

Showing the changes to interface/src/Application.cpp (1 of 17 files). Show all

Unified · Split

interface/src/Application.cpp+171−99
@@ -144,6 +144,7 @@ · 143 unmodified lines
144144 #include <trackers/EyeTracker.h>
145145 #include <avatars-renderer/ScriptAvatar.h>
146146 #include <RenderableEntityItem.h>
147+#include <procedural/ProceduralSkybox.h>
147148
148149 #include "AudioClient.h"
149150 #include "audio/AudioScope.h"
@@ -375,7 +376,7 @@ Setting::Handle<int> maxOctreePacketsPerSecond("maxOctreePPS", DEFAULT_MAX_OCTRE · 225 unmodified lines
375376 static const QString MARKETPLACE_CDN_HOSTNAME = "mpassets.highfidelity.com";
376377 static const int INTERVAL_TO_CHECK_HMD_WORN_STATUS = 500; // milliseconds
377378 static const QString DESKTOP_DISPLAY_PLUGIN_NAME = "Desktop";
378−
379+static const QString ACTIVE_DISPLAY_PLUGIN_SETTING_NAME = "activeDisplayPlugin";
379380 static const QString SYSTEM_TABLET = "com.highfidelity.interface.tablet.system";
380381
381382 const std::vector<std::pair<QString, Application::AcceptURLMethod>> Application::_acceptedExtensions {
@@ -1352,10 +1353,14 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 970 unmodified lines
13521353 QCoreApplication::processEvents();
13531354 _glWidget->createContext();
13541355
1355− // Create the main thread context, the GPU backend, and the display plugins
1356+ // Create the main thread context, the GPU backend
13561357 initializeGL();
1357− DependencyManager::get<TextureCache>()->setGPUContext(_gpuContext);
1358− qCDebug(interfaceapp, "Initialized Display.");
1358+ qCDebug(interfaceapp, "Initialized GL");
1359+
1360+ // Initialize the display plugin architecture
1361+ initializeDisplayPlugins();
1362+ qCDebug(interfaceapp, "Initialized Display");
1363+
13591364 // Create the rendering engine. This can be slow on some machines due to lots of
13601365 // GPU pipeline creation.
13611366 initializeRenderEngine();
@@ -2256,8 +2261,11 @@ void Application::updateVerboseLogging() { · 894 unmodified lines
22562261 }
22572262 bool enable = menu->isOptionChecked(MenuOption::VerboseLogging);
22582263
2259− QString rules = "*.debug=%1\n"
2260− "*.info=%1";
2264+ QString rules =
2265+ "hifi.*.debug=%1\n"
2266+ "hifi.*.info=%1\n"
2267+ "hifi.audio-stream.debug=false\n"
2268+ "hifi.audio-stream.info=false";
22612269 rules = rules.arg(enable ? "true" : "false");
22622270 QLoggingCategory::setFilterRules(rules);
22632271 }
@@ -2372,6 +2380,10 @@ void Application::onAboutToQuit() { · 108 unmodified lines
23722380 }
23732381 }
23742382
2383+ // The active display plugin needs to be loaded before the menu system is active,
2384+ // so its persisted explicitly here
2385+ Setting::Handle<QString>{ ACTIVE_DISPLAY_PLUGIN_SETTING_NAME }.set(getActiveDisplayPlugin()->getName());
2386+
23752387 getActiveDisplayPlugin()->deactivate();
23762388 if (_autoSwitchDisplayModeSupportedHMDPlugin
23772389 && _autoSwitchDisplayModeSupportedHMDPlugin->isSessionActive()) {
@@ -2611,10 +2623,84 @@ void Application::initializeGL() { · 233 unmodified lines
26112623 _glWidget->makeCurrent();
26122624 _gpuContext = std::make_shared<gpu::Context>();
26132625
2626+ DependencyManager::get<TextureCache>()->setGPUContext(_gpuContext);
2627+
26142628 // Restore the default main thread context
26152629 _offscreenContext->makeCurrent();
2630+}
2631+
2632+static const QString SPLASH_SKYBOX{ "{\"ProceduralEntity\":{ \"version\":2, \"shaderUrl\":\"qrc:///shaders/splashSkybox.frag\" } }" };
2633+
2634+void Application::initializeDisplayPlugins() {
2635+ auto displayPlugins = PluginManager::getInstance()->getDisplayPlugins();
2636+ Setting::Handle<QString> activeDisplayPluginSetting{ ACTIVE_DISPLAY_PLUGIN_SETTING_NAME, displayPlugins.at(0)->getName() };
2637+ auto lastActiveDisplayPluginName = activeDisplayPluginSetting.get();
2638+
2639+ auto defaultDisplayPlugin = displayPlugins.at(0);
2640+ // Once time initialization code
2641+ DisplayPluginPointer targetDisplayPlugin;
2642+ foreach(auto displayPlugin, displayPlugins) {
2643+ displayPlugin->setContext(_gpuContext);
2644+ if (displayPlugin->getName() == lastActiveDisplayPluginName) {
2645+ targetDisplayPlugin = displayPlugin;
2646+ }
2647+ QObject::connect(displayPlugin.get(), &DisplayPlugin::recommendedFramebufferSizeChanged,
2648+ [this](const QSize& size) { resizeGL(); });
2649+ QObject::connect(displayPlugin.get(), &DisplayPlugin::resetSensorsRequested, this, &Application::requestReset);
2650+ }
2651+
2652+ // The default display plugin needs to be activated first, otherwise the display plugin thread
2653+ // may be launched by an external plugin, which is bad
2654+ setDisplayPlugin(defaultDisplayPlugin);
2655+
2656+ // Now set the desired plugin if it's not the same as the default plugin
2657+ if (targetDisplayPlugin != defaultDisplayPlugin) {
2658+ setDisplayPlugin(targetDisplayPlugin);
2659+ }
2660+
2661+ // Submit a default frame to render until the engine starts up
2662+ updateRenderArgs(0.0f);
2663+
2664+ _offscreenContext->makeCurrent();
26162665
2617− updateDisplayMode();
2666+#define ENABLE_SPLASH_FRAME 0
2667+#if ENABLE_SPLASH_FRAME
2668+ {
2669+ QMutexLocker viewLocker(&_renderArgsMutex);
2670+
2671+ if (_appRenderArgs._isStereo) {
2672+ _gpuContext->enableStereo(true);
2673+ _gpuContext->setStereoProjections(_appRenderArgs._eyeProjections);
2674+ _gpuContext->setStereoViews(_appRenderArgs._eyeOffsets);
2675+ }
2676+
2677+ // Frame resources
2678+ auto framebufferCache = DependencyManager::get<FramebufferCache>();
2679+ gpu::FramebufferPointer finalFramebuffer = framebufferCache->getFramebuffer();
2680+ std::shared_ptr<ProceduralSkybox> procedural = std::make_shared<ProceduralSkybox>();
2681+ procedural->parse(SPLASH_SKYBOX);
2682+
2683+ _gpuContext->beginFrame(_appRenderArgs._view, _appRenderArgs._headPose);
2684+ gpu::doInBatch("splashFrame", _gpuContext, [&](gpu::Batch& batch) {
2685+ batch.resetStages();
2686+ batch.enableStereo(false);
2687+ batch.setFramebuffer(finalFramebuffer);
2688+ batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, { 0, 0, 0, 1 });
2689+ batch.enableSkybox(true);
2690+ batch.enableStereo(_appRenderArgs._isStereo);
2691+ batch.setViewportTransform({ 0, 0, finalFramebuffer->getSize() });
2692+ procedural->render(batch, _appRenderArgs._renderArgs.getViewFrustum());
2693+ });
2694+ auto frame = _gpuContext->endFrame();
2695+ frame->frameIndex = 0;
2696+ frame->framebuffer = finalFramebuffer;
2697+ frame->pose = _appRenderArgs._headPose;
2698+ frame->framebufferRecycler = [framebufferCache, procedural](const gpu::FramebufferPointer& framebuffer) {
2699+ framebufferCache->releaseFramebuffer(framebuffer);
2700+ };
2701+ _displayPlugin->submitFrame(frame);
2702+ }
2703+#endif
26182704 }
26192705
26202706 void Application::initializeRenderEngine() {
@@ -2638,6 +2724,7 @@ void Application::initializeRenderEngine() { · 17 unmodified lines
26382724 }
26392725
26402726 extern void setupPreferences();
2727+static void addDisplayPluginToMenu(const DisplayPluginPointer& displayPlugin, bool active);
26412728
26422729 void Application::initializeUi() {
26432730 // Build a shared canvas / context for the Chromium processes
@@ -2779,10 +2866,25 @@ void Application::initializeUi() { · 135 unmodified lines
27792866 offscreenSurfaceCache->reserve(TabletScriptingInterface::QML, 1);
27802867 offscreenSurfaceCache->reserve(Web3DOverlay::QML, 2);
27812868
2782− // Now that the menu is instantiated, ensure the display plugin menu is properly updated
2783− updateDisplayMode();
27842869 flushMenuUpdates();
27852870
2871+ // Now that the menu is instantiated, ensure the display plugin menu is properly updated
2872+ {
2873+ auto displayPlugins = PluginManager::getInstance()->getDisplayPlugins();
2874+ // first sort the plugins into groupings: standard, advanced, developer
2875+ std::stable_sort(displayPlugins.begin(), displayPlugins.end(),
2876+ [](const DisplayPluginPointer& a, const DisplayPluginPointer& b)->bool { return a->getGrouping() < b->getGrouping(); });
2877+
2878+ // concatenate the groupings into a single list in the order: standard, advanced, developer
2879+ for(const auto& displayPlugin : displayPlugins) {
2880+ addDisplayPluginToMenu(displayPlugin, _displayPlugin == displayPlugin);
2881+ }
2882+
2883+ // after all plugins have been added to the menu, add a separator to the menu
2884+ auto parent = getPrimaryMenu()->getMenu(MenuOption::OutputMenu);
2885+ parent->addSeparator();
2886+ }
2887+
27862888 // The display plugins are created before the menu now, so we need to do this here to hide the menu bar
27872889 // now that it exists
27882890 if (_window && _window->isFullScreen()) {
@@ -2933,7 +3035,7 @@ void Application::updateCamera(RenderArgs& renderArgs, float deltaTime) { · 144 unmodified lines
29333035 _thirdPersonHMDCameraBoomValid = false;
29343036
29353037 _myCamera.setOrientation(myAvatar->getHead()->getOrientation());
2936− if (Menu::getInstance()->isOptionChecked(MenuOption::CenterPlayerInView)) {
3038+ if (isOptionChecked(MenuOption::CenterPlayerInView)) {
29373039 _myCamera.setPosition(myAvatar->getDefaultEyePosition()
29383040 + _myCamera.getOrientation() * boomOffset);
29393041 }
@@ -5735,6 +5837,32 @@ void Application::update(float deltaTime) { · 2795 unmodified lines
57355837 }
57365838
57375839
5840+ updateRenderArgs(deltaTime);
5841+
5842+ // HACK
5843+ // load the view frustum
5844+ // FIXME: This preDisplayRender call is temporary until we create a separate render::scene for the mirror rendering.
5845+ // Then we can move this logic into the Avatar::simulate call.
5846+ myAvatar->preDisplaySide(&_appRenderArgs._renderArgs);
5847+
5848+
5849+ {
5850+ PerformanceTimer perfTimer("limitless");
5851+ AnimDebugDraw::getInstance().update();
5852+ }
5853+
5854+ {
5855+ PerformanceTimer perfTimer("limitless");
5856+ DependencyManager::get<LimitlessVoiceRecognitionScriptingInterface>()->update();
5857+ }
5858+
5859+ { // Game loop is done, mark the end of the frame for the scene transactions and the render loop to take over
5860+ PerformanceTimer perfTimer("enqueueFrame");
5861+ getMain3DScene()->enqueueFrame();
5862+ }
5863+}
5864+
5865+void Application::updateRenderArgs(float deltaTime) {
57385866 editRenderArgs([this, deltaTime](AppRenderArgs& appRenderArgs) {
57395867 PerformanceTimer perfTimer("editRenderArgs");
57405868 appRenderArgs._headPose = getHMDSensorPose();
@@ -5758,9 +5886,9 @@ void Application::update(float deltaTime) { · 17 unmodified lines
57585886 QMutexLocker viewLocker(&_viewMutex);
57595887 // adjust near clip plane to account for sensor scaling.
57605888 auto adjustedProjection = glm::perspective(glm::radians(_fieldOfView.get()),
5761− getActiveDisplayPlugin()->getRecommendedAspectRatio(),
5762− DEFAULT_NEAR_CLIP * sensorToWorldScale,
5763− DEFAULT_FAR_CLIP);
5889+ getActiveDisplayPlugin()->getRecommendedAspectRatio(),
5890+ DEFAULT_NEAR_CLIP * sensorToWorldScale,
5891+ DEFAULT_FAR_CLIP);
57645892 _viewFrustum.setProjection(adjustedProjection);
57655893 _viewFrustum.calculate();
57665894 }
@@ -5776,8 +5904,14 @@ void Application::update(float deltaTime) { · 9 unmodified lines
57765904 }
57775905 {
57785906 PROFILE_RANGE(render, "/resizeGL");
5779− PerformanceWarning::setSuppressShortTimings(Menu::getInstance()->isOptionChecked(MenuOption::SuppressShortTimings));
5780− bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
5907+ bool showWarnings = false;
5908+ bool suppressShortTimings = false;
5909+ auto menu = Menu::getInstance();
5910+ if (menu) {
5911+ suppressShortTimings = menu->isOptionChecked(MenuOption::SuppressShortTimings);
5912+ showWarnings = menu->isOptionChecked(MenuOption::PipelineWarnings);
5913+ }
5914+ PerformanceWarning::setSuppressShortTimings(suppressShortTimings);
57815915 PerformanceWarning warn(showWarnings, "Application::paintGL()");
57825916 resizeGL();
57835917 }
@@ -5833,12 +5967,6 @@ void Application::update(float deltaTime) { · 49 unmodified lines
58335967 }
58345968 }
58355969
5836− // HACK
5837− // load the view frustum
5838− // FIXME: This preDisplayRender call is temporary until we create a separate render::scene for the mirror rendering.
5839− // Then we can move this logic into the Avatar::simulate call.
5840− myAvatar->preDisplaySide(&appRenderArgs._renderArgs);
5841−
58425970 {
58435971 QMutexLocker viewLocker(&_viewMutex);
58445972 _myCamera.loadViewFrustum(_displayViewFrustum);
@@ -5850,21 +5978,6 @@ void Application::update(float deltaTime) { · 5 unmodified lines
58505978 appRenderArgs._renderArgs.setViewFrustum(_displayViewFrustum);
58515979 }
58525980 });
5853−
5854− {
5855− PerformanceTimer perfTimer("limitless");
5856− AnimDebugDraw::getInstance().update();
5857− }
5858−
5859− {
5860− PerformanceTimer perfTimer("limitless");
5861− DependencyManager::get<LimitlessVoiceRecognitionScriptingInterface>()->update();
5862− }
5863−
5864− { // Game loop is done, mark the end of the frame for the scene transactions and the render loop to take over
5865− PerformanceTimer perfTimer("enqueueFrame");
5866− getMain3DScene()->enqueueFrame();
5867− }
58685981 }
58695982
58705983 void Application::queryAvatars() {
@@ -7509,15 +7622,19 @@ void Application::shareSnapshot(const QString& path, const QUrl& href) { · 1638 unmodified lines
75097622 }
75107623
75117624 float Application::getRenderResolutionScale() const {
7512− if (Menu::getInstance()->isOptionChecked(MenuOption::RenderResolutionOne)) {
7625+ auto menu = Menu::getInstance();
7626+ if (!menu) {
7627+ return 1.0f;
7628+ }
7629+ if (menu->isOptionChecked(MenuOption::RenderResolutionOne)) {
75137630 return 1.0f;
7514− } else if (Menu::getInstance()->isOptionChecked(MenuOption::RenderResolutionTwoThird)) {
7631+ } else if (menu->isOptionChecked(MenuOption::RenderResolutionTwoThird)) {
75157632 return 0.666f;
7516− } else if (Menu::getInstance()->isOptionChecked(MenuOption::RenderResolutionHalf)) {
7633+ } else if (menu->isOptionChecked(MenuOption::RenderResolutionHalf)) {
75177634 return 0.5f;
7518− } else if (Menu::getInstance()->isOptionChecked(MenuOption::RenderResolutionThird)) {
7635+ } else if (menu->isOptionChecked(MenuOption::RenderResolutionThird)) {
75197636 return 0.333f;
7520− } else if (Menu::getInstance()->isOptionChecked(MenuOption::RenderResolutionQuarter)) {
7637+ } else if (menu->isOptionChecked(MenuOption::RenderResolutionQuarter)) {
75217638 return 0.25f;
75227639 } else {
75237640 return 1.0f;
@@ -7741,7 +7858,7 @@ DisplayPluginPointer Application::getActiveDisplayPlugin() const { · 217 unmodified lines
77417858
77427859 static const char* EXCLUSION_GROUP_KEY = "exclusionGroup";
77437860
7744−static void addDisplayPluginToMenu(DisplayPluginPointer displayPlugin, bool active = false) {
7861+static void addDisplayPluginToMenu(const DisplayPluginPointer& displayPlugin, bool active) {
77457862 auto menu = Menu::getInstance();
77467863 QString name = displayPlugin->getName();
77477864 auto grouping = displayPlugin->getGrouping();
@@ -7786,65 +7903,12 @@ void Application::updateDisplayMode() { · 38 unmodified lines
77867903 qFatal("Attempted to switch display plugins from a non-main thread");
77877904 }
77887905
7789− auto displayPlugins = PluginManager::getInstance()->getDisplayPlugins();
7790−
7791− // Once time initialization code
7792− static std::once_flag once;
7793− std::call_once(once, [&] {
7794− foreach(auto displayPlugin, displayPlugins) {
7795− displayPlugin->setContext(_gpuContext);
7796− QObject::connect(displayPlugin.get(), &DisplayPlugin::recommendedFramebufferSizeChanged,
7797− [this](const QSize& size) { resizeGL(); });
7798− QObject::connect(displayPlugin.get(), &DisplayPlugin::resetSensorsRequested, this, &Application::requestReset);
7799− }
7800− });
7801−
78027906 // Once time initialization code that depends on the UI being available
7803− auto menu = Menu::getInstance();
7804− if (menu) {
7805− static std::once_flag onceUi;
7806− std::call_once(onceUi, [&] {
7807− bool first = true;
7808−
7809− // first sort the plugins into groupings: standard, advanced, developer
7810− DisplayPluginList standard;
7811− DisplayPluginList advanced;
7812− DisplayPluginList developer;
7813− foreach(auto displayPlugin, displayPlugins) {
7814− displayPlugin->setContext(_gpuContext);
7815− auto grouping = displayPlugin->getGrouping();
7816− switch (grouping) {
7817− case Plugin::ADVANCED:
7818− advanced.push_back(displayPlugin);
7819− break;
7820− case Plugin::DEVELOPER:
7821− developer.push_back(displayPlugin);
7822− break;
7823− default:
7824− standard.push_back(displayPlugin);
7825− break;
7826− }
7827− }
7828−
7829− // concatenate the groupings into a single list in the order: standard, advanced, developer
7830− standard.insert(std::end(standard), std::begin(advanced), std::end(advanced));
7831− standard.insert(std::end(standard), std::begin(developer), std::end(developer));
7832−
7833− foreach(auto displayPlugin, standard) {
7834− addDisplayPluginToMenu(displayPlugin, first);
7835− first = false;
7836− }
7837−
7838− // after all plugins have been added to the menu, add a separator to the menu
7839− auto parent = menu->getMenu(MenuOption::OutputMenu);
7840− parent->addSeparator();
7841− });
7842−
7843− }
7844−
7907+ auto displayPlugins = getDisplayPlugins();
78457908
78467909 // Default to the first item on the list, in case none of the menu items match
78477910 DisplayPluginPointer newDisplayPlugin = displayPlugins.at(0);
7911+ auto menu = getPrimaryMenu();
78487912 if (menu) {
78497913 foreach(DisplayPluginPointer displayPlugin, PluginManager::getInstance()->getDisplayPlugins()) {
78507914 QString name = displayPlugin->getName();
@@ -7868,6 +7932,14 @@ void Application::updateDisplayMode() { · 17 unmodified lines
78687932 }
78697933
78707934 void Application::setDisplayPlugin(DisplayPluginPointer newDisplayPlugin) {
7935+ if (newDisplayPlugin == _displayPlugin) {
7936+ return;
7937+ }
7938+
7939+ // FIXME don't have the application directly set the state of the UI,
7940+ // instead emit a signal that the display plugin is changing and let
7941+ // the desktop lock itself. Reduces coupling between the UI and display
7942+ // plugins
78717943 auto offscreenUi = DependencyManager::get<OffscreenUi>();
78727944 auto desktop = offscreenUi->getDesktop();
78737945 auto menu = Menu::getInstance();
@@ -7878,8 +7950,8 @@ void Application::setDisplayPlugin(DisplayPluginPointer newDisplayPlugin) { · 4 unmodified lines
78787950 bool wasRepositionLocked = false;
78797951 if (desktop) {
78807952 // Tell the desktop to no reposition (which requires plugin info), until we have set the new plugin, below.
7881− wasRepositionLocked = offscreenUi->getDesktop()->property("repositionLocked").toBool();
7882− offscreenUi->getDesktop()->setProperty("repositionLocked", true);
7953+ wasRepositionLocked = desktop->property("repositionLocked").toBool();
7954+ desktop->setProperty("repositionLocked", true);
78837955 }
78847956
78857957 if (_displayPlugin) {