History

Merge branch 'master' of https://github.com/worklist/hifi into 20660

Thijs Wenker committed 11 years ago

Commit 0f8cf802 parents 63f0173 53f981580 files · +2139 −880Browse files

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

Unified · Split

interface/src/Application.cpp+61−187
@@ -58,6 +58,8 @@ · 57 unmodified lines
5858 #include <AutoUpdater.h>
5959 #include <DeferredLightingEffect.h>
6060 #include <DependencyManager.h>
61+#include <plugins/PluginContainer.h>
62+#include <plugins/PluginManager.h>
6163 #include <display-plugins/DisplayPlugin.h>
6264
6365 #include <EntityScriptingInterface.h>
@@ -148,6 +150,8 @@ · 84 unmodified lines
148150
149151 #include "ui/overlays/Cube3DOverlay.h"
150152
153+#include "PluginContainerProxy.h"
154+
151155 // ON WIndows PC, NVidia Optimus laptop, we want to enable NVIDIA GPU
152156 // FIXME seems to be broken.
153157 #if defined(Q_OS_WIN)
@@ -301,7 +305,7 @@ bool setupEssentials(int& argc, char** argv) { · 147 unmodified lines
301305 // continuing to overburden Application.cpp
302306 Cube3DOverlay* _keyboardFocusHighlight{ nullptr };
303307 int _keyboardFocusHighlightID{ -1 };
304−
308+PluginContainer* _pluginContainer;
305309
306310 Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
307311 QApplication(argc, argv),
@@ -351,7 +355,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 43 unmodified lines
351355 _applicationOverlay()
352356 {
353357 setInstance(this);
354− Plugin::setContainer(this);
358+
359+ _pluginContainer = new PluginContainerProxy();
360+ Plugin::setContainer(_pluginContainer);
355361 #ifdef Q_OS_WIN
356362 installNativeEventFilter(&MyNativeEventFilter::getInstance());
357363 #endif
@@ -995,6 +1001,8 @@ void Application::paintGL() { · 637 unmodified lines
9951001 auto displayPlugin = getActiveDisplayPlugin();
9961002 displayPlugin->preRender();
9971003 _offscreenContext->makeCurrent();
1004+ // update the avatar with a fresh HMD pose
1005+ _myAvatar->updateFromHMDSensorMatrix(getHMDSensorPose());
9981006
9991007 auto lodManager = DependencyManager::get<LODManager>();
10001008
@@ -1091,7 +1099,6 @@ void Application::paintGL() { · 90 unmodified lines
10911099 glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror);
10921100 renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
10931101 }
1094−
10951102 // Update camera position
10961103 if (!isHMDMode()) {
10971104 _myCamera.update(1.0f / _fps);
@@ -1100,64 +1107,46 @@ void Application::paintGL() { · 2 unmodified lines
11001107
11011108 // Primary rendering pass
11021109 auto framebufferCache = DependencyManager::get<FramebufferCache>();
1103− QSize size = framebufferCache->getFrameBufferSize();
1110+ const QSize size = framebufferCache->getFrameBufferSize();
11041111 {
11051112 PROFILE_RANGE(__FUNCTION__ "/mainRender");
11061113 // Viewport is assigned to the size of the framebuffer
1107− QSize size = DependencyManager::get<FramebufferCache>()->getFrameBufferSize();
1108− renderArgs._viewport = glm::ivec4(0, 0, size.width(), size.height());
1109−
1110− {
1111− PROFILE_RANGE(__FUNCTION__ "/clear");
1112− doInBatch(&renderArgs, [&](gpu::Batch& batch) {
1113− auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
1114− batch.setFramebuffer(primaryFbo);
1115− // clear the normal and specular buffers
1116− batch.clearFramebuffer(
1117− gpu::Framebuffer::BUFFER_COLOR0 |
1118− gpu::Framebuffer::BUFFER_COLOR1 |
1119− gpu::Framebuffer::BUFFER_COLOR2 |
1120− gpu::Framebuffer::BUFFER_DEPTH,
1121− vec4(vec3(0), 1), 1.0, 0.0);
1122− });
1123− }
1124−
1114+ renderArgs._viewport = ivec4(0, 0, size.width(), size.height());
11251115 if (displayPlugin->isStereo()) {
1126− PROFILE_RANGE(__FUNCTION__ "/stereoRender");
1127− QRect currentViewport(QPoint(0, 0), QSize(size.width() / 2, size.height()));
1128− glEnable(GL_SCISSOR_TEST);
1129− for_each_eye([&](Eye eye){
1130− // Load the view frustum, used by meshes
1131− Camera eyeCamera;
1132− if (qApp->isHMDMode()) {
1133− // Allow the displayPlugin to compose the final eye transform, based on the most up-to-date head motion.
1134− eyeCamera.setTransform(displayPlugin->getModelview(eye, _myAvatar->getSensorToWorldMatrix()));
1135− } else {
1136− eyeCamera.setTransform(displayPlugin->getModelview(eye, _myCamera.getTransform()));
1137− }
1138− eyeCamera.setProjection(displayPlugin->getProjection(eye, _myCamera.getProjection()));
1139− renderArgs._viewport = toGlm(currentViewport);
1140− doInBatch(&renderArgs, [&](gpu::Batch& batch) {
1141− batch.setViewportTransform(renderArgs._viewport);
1142− batch.setStateScissorRect(renderArgs._viewport);
1143− });
1144− displaySide(&renderArgs, eyeCamera);
1145− }, [&] {
1146− currentViewport.moveLeft(currentViewport.width());
1147− });
1148− glDisable(GL_SCISSOR_TEST);
1149− } else {
1150− PROFILE_RANGE(__FUNCTION__ "/monoRender");
1151− renderArgs._viewport = gpu::Vec4i(0, 0, size.width(), size.height());
1152− // Viewport is assigned to the size of the framebuffer
1153− doInBatch(&renderArgs, [&](gpu::Batch& batch) {
1154− batch.setViewportTransform(renderArgs._viewport);
1155− batch.setStateScissorRect(renderArgs._viewport);
1116+ // Stereo modes will typically have a larger projection matrix overall,
1117+ // so we ask for the 'mono' projection matrix, which for stereo and HMD
1118+ // plugins will imply the combined projection for both eyes.
1119+ //
1120+ // This is properly implemented for the Oculus plugins, but for OpenVR
1121+ // and Stereo displays I'm not sure how to get / calculate it, so we're
1122+ // just relying on the left FOV in each case and hoping that the
1123+ // overall culling margin of error doesn't cause popping in the
1124+ // right eye. There are FIXMEs in the relevant plugins
1125+ _myCamera.setProjection(displayPlugin->getProjection(Mono, _myCamera.getProjection()));
1126+ renderArgs._context->enableStereo(true);
1127+ mat4 eyeViews[2];
1128+ mat4 eyeProjections[2];
1129+ auto baseProjection = renderArgs._viewFrustum->getProjection();
1130+ // FIXME we probably don't need to set the projection matrix every frame,
1131+ // only when the display plugin changes (or in non-HMD modes when the user
1132+ // changes the FOV manually, which right now I don't think they can.
1133+ for_each_eye([&](Eye eye) {
1134+ // For providing the stereo eye views, the HMD head pose has already been
1135+ // applied to the avatar, so we need to get the difference between the head
1136+ // pose applied to the avatar and the per eye pose, and use THAT as
1137+ // the per-eye stereo matrix adjustment.
1138+ mat4 eyePose = displayPlugin->getEyePose(eye);
1139+ mat4 headPose = displayPlugin->getHeadPose();
1140+ mat4 eyeView = glm::inverse(eyePose) * headPose;
1141+ eyeViews[eye] = eyeView;
1142+ eyeProjections[eye] = displayPlugin->getProjection(eye, baseProjection);
11561143 });
1157− displaySide(&renderArgs, _myCamera);
1144+ renderArgs._context->setStereoProjections(eyeProjections);
1145+ renderArgs._context->setStereoViews(eyeViews);
11581146 }
1159−
1160− doInBatch(&renderArgs, [](gpu::Batch& batch){
1147+ displaySide(&renderArgs, _myCamera);
1148+ renderArgs._context->enableStereo(false);
1149+ doInBatch(&renderArgs, [](gpu::Batch& batch) {
11611150 batch.setFramebuffer(nullptr);
11621151 });
11631152 }
@@ -1191,7 +1180,6 @@ void Application::paintGL() { · 27 unmodified lines
11911180 PROFILE_RANGE(__FUNCTION__ "/pluginOutput");
11921181 auto primaryFbo = framebufferCache->getPrimaryFramebuffer();
11931182 GLuint finalTexture = gpu::GLBackend::getTextureID(primaryFbo->getRenderBuffer(0));
1194− uvec2 finalSize = toGlm(size);
11951183 // Ensure the rendering context commands are completed when rendering
11961184 GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
11971185 // Ensure the sync object is flushed to the driver thread before releasing the context
@@ -1207,7 +1195,7 @@ void Application::paintGL() { · 9 unmodified lines
12071195
12081196 {
12091197 PROFILE_RANGE(__FUNCTION__ "/pluginDisplay");
1210− displayPlugin->display(finalTexture, finalSize);
1198+ displayPlugin->display(finalTexture, toGlm(size));
12111199 }
12121200
12131201 {
@@ -1280,6 +1268,7 @@ void Application::resizeGL() { · 66 unmodified lines
12801268 // Possible change in aspect ratio
12811269 loadViewFrustum(_myCamera, _viewFrustum);
12821270 float fov = glm::radians(DEFAULT_FIELD_OF_VIEW_DEGREES);
1271+ // FIXME the aspect ratio for stereo displays is incorrect based on this.
12831272 float aspectRatio = aspect(_renderResolution);
12841273 _myCamera.setProjection(glm::perspective(fov, aspectRatio, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
12851274 }
@@ -1439,7 +1428,15 @@ void Application::keyPressEvent(QKeyEvent* event) { · 153 unmodified lines
14391428 break;
14401429 case Qt::Key_Enter:
14411430 case Qt::Key_Return:
1442− Menu::getInstance()->triggerOption(MenuOption::AddressBar);
1431+ if (isOption) {
1432+ if (_window->isFullScreen()) {
1433+ _pluginContainer->unsetFullscreen();
1434+ } else {
1435+ _pluginContainer->setFullscreen(nullptr);
1436+ }
1437+ } else {
1438+ Menu::getInstance()->triggerOption(MenuOption::AddressBar);
1439+ }
14431440 break;
14441441
14451442 case Qt::Key_B:
@@ -2705,9 +2702,6 @@ void Application::update(float deltaTime) { · 1259 unmodified lines
27052702 updateLOD();
27062703 updateMouseRay(); // check what's under the mouse and update the mouse voxel
27072704
2708− // update the avatar with a fresh HMD pose
2709− _myAvatar->updateFromHMDSensorMatrix(getHMDSensorPose());
2710−
27112705 {
27122706 PerformanceTimer perfTimer("devices");
27132707 DeviceTracker::updateAll();
@@ -4638,10 +4632,6 @@ void Application::checkSkeleton() { · 1924 unmodified lines
46384632 }
46394633 }
46404634
4641−bool Application::isForeground() {
4642− return _isForeground && !getWindow()->isMinimized();
4643−}
4644−
46454635 void Application::activeChanged(Qt::ApplicationState state) {
46464636 switch (state) {
46474637 case Qt::ApplicationActive:
@@ -4747,6 +4737,10 @@ const DisplayPlugin * Application::getActiveDisplayPlugin() const { · 99 unmodified lines
47474737 return ((Application*)this)->getActiveDisplayPlugin();
47484738 }
47494739
4740+bool _activatingDisplayPlugin{ false };
4741+QVector<QPair<QString, QString>> _currentDisplayPluginActions;
4742+QVector<QPair<QString, QString>> _currentInputPluginActions;
4743+
47504744
47514745 static void addDisplayPluginToMenu(DisplayPluginPointer displayPlugin, bool active = false) {
47524746 auto menu = Menu::getInstance();
@@ -4768,9 +4762,6 @@ static void addDisplayPluginToMenu(DisplayPluginPointer displayPlugin, bool acti · 15 unmodified lines
47684762 Q_ASSERT(menu->menuItemExists(MenuOption::OutputMenu, name));
47694763 }
47704764
4771−static QVector<QPair<QString, QString>> _currentDisplayPluginActions;
4772−static bool _activatingDisplayPlugin{false};
4773−
47744765 void Application::updateDisplayMode() {
47754766 auto menu = Menu::getInstance();
47764767 auto displayPlugins = PluginManager::getInstance()->getDisplayPlugins();
@@ -4837,7 +4828,7 @@ void Application::updateDisplayMode() { · 60 unmodified lines
48374828 // Only show the hmd tools after the correct plugin has
48384829 // been activated so that it's UI is setup correctly
48394830 if (newPluginWantsHMDTools) {
4840− showDisplayPluginsTools();
4831+ _pluginContainer->showDisplayPluginsTools();
48414832 }
48424833
48434834 if (oldDisplayPlugin) {
@@ -4855,9 +4846,6 @@ void Application::updateDisplayMode() { · 11 unmodified lines
48554846 Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin");
48564847 }
48574848
4858−static QVector<QPair<QString, QString>> _currentInputPluginActions;
4859−
4860−
48614849 static void addInputPluginToMenu(InputPluginPointer inputPlugin, bool active = false) {
48624850 auto menu = Menu::getInstance();
48634851 QString name = inputPlugin->getName();
@@ -4931,42 +4919,6 @@ void Application::updateInputModes() { · 67 unmodified lines
49314919 //}
49324920 }
49334921
4934−void Application::addMenu(const QString& menuName) {
4935− Menu::getInstance()->addMenu(menuName);
4936−}
4937−
4938−void Application::removeMenu(const QString& menuName) {
4939− Menu::getInstance()->removeMenu(menuName);
4940−}
4941−
4942−void Application::addMenuItem(const QString& path, const QString& name, std::function<void(bool)> onClicked, bool checkable, bool checked, const QString& groupName) {
4943− auto menu = Menu::getInstance();
4944− MenuWrapper* parentItem = menu->getMenu(path);
4945− QAction* action = menu->addActionToQMenuAndActionHash(parentItem, name);
4946− connect(action, &QAction::triggered, [=] {
4947− onClicked(action->isChecked());
4948− });
4949− action->setCheckable(checkable);
4950− action->setChecked(checked);
4951− if (_activatingDisplayPlugin) {
4952− _currentDisplayPluginActions.push_back({ path, name });
4953− } else {
4954− _currentInputPluginActions.push_back({ path, name });
4955− }
4956−}
4957−
4958−void Application::removeMenuItem(const QString& menuName, const QString& menuItem) {
4959− Menu::getInstance()->removeMenuItem(menuName, menuItem);
4960−}
4961−
4962−bool Application::isOptionChecked(const QString& name) {
4963− return Menu::getInstance()->isOptionChecked(name);
4964−}
4965−
4966−void Application::setIsOptionChecked(const QString& path, bool checked) {
4967− Menu::getInstance()->setIsOptionChecked(path, checked);
4968−}
4969−
49704922 mat4 Application::getEyeProjection(int eye) const {
49714923 if (isHMDMode()) {
49724924 return getActiveDisplayPlugin()->getProjection((Eye)eye, _viewFrustum.getProjection());
@@ -4986,7 +4938,7 @@ mat4 Application::getEyePose(int eye) const { · 13 unmodified lines
49864938 mat4 Application::getEyeOffset(int eye) const {
49874939 if (isHMDMode()) {
49884940 mat4 identity;
4989− return getActiveDisplayPlugin()->getModelview((Eye)eye, identity);
4941+ return getActiveDisplayPlugin()->getView((Eye)eye, identity);
49904942 }
49914943
49924944 return mat4();
@@ -4999,84 +4951,6 @@ mat4 Application::getHMDSensorPose() const { · 6 unmodified lines
49994951 return mat4();
50004952 }
50014953
5002−void Application::setFullscreen(const QScreen* target) {
5003− if (!_window->isFullScreen()) {
5004− _savedGeometry = _window->geometry();
5005− }
5006−#ifdef Q_OS_MAC
5007− _window->setGeometry(target->availableGeometry());
5008−#endif
5009− _window->windowHandle()->setScreen((QScreen*)target);
5010− _window->showFullScreen();
5011−
5012−#ifndef Q_OS_MAC
5013− // also hide the QMainWindow's menuBar
5014− QMenuBar* menuBar = _window->menuBar();
5015− if (menuBar) {
5016− menuBar->setVisible(false);
5017− }
5018−#endif
5019−}
5020−
5021−void Application::unsetFullscreen(const QScreen* avoid) {
5022− _window->showNormal();
5023−
5024− QRect targetGeometry = _savedGeometry;
5025− if (avoid != nullptr) {
5026− QRect avoidGeometry = avoid->geometry();
5027− if (avoidGeometry.contains(targetGeometry.topLeft())) {
5028− QScreen* newTarget = primaryScreen();
5029− if (newTarget == avoid) {
5030− foreach(auto screen, screens()) {
5031− if (screen != avoid) {
5032− newTarget = screen;
5033− break;
5034− }
5035− }
5036− }
5037− targetGeometry = newTarget->availableGeometry();
5038− }
5039− }
5040−#ifdef Q_OS_MAC
5041− QTimer* timer = new QTimer();
5042− timer->singleShot(2000, [=] {
5043− _window->setGeometry(targetGeometry);
5044− timer->deleteLater();
5045− });
5046−#else
5047− _window->setGeometry(targetGeometry);
5048−#endif
5049−
5050−#ifndef Q_OS_MAC
5051− // also show the QMainWindow's menuBar
5052− QMenuBar* menuBar = _window->menuBar();
5053− if (menuBar) {
5054− menuBar->setVisible(true);
5055− }
5056−#endif
5057−}
5058−
5059−
5060−void Application::showDisplayPluginsTools() {
5061− DependencyManager::get<DialogsManager>()->hmdTools(true);
5062−}
5063−
5064−QGLWidget* Application::getPrimarySurface() {
5065− return _glWidget;
5066−}
5067−
5068−void Application::setActiveDisplayPlugin(const QString& pluginName) {
5069− auto menu = Menu::getInstance();
5070− foreach(DisplayPluginPointer displayPlugin, PluginManager::getInstance()->getDisplayPlugins()) {
5071− QString name = displayPlugin->getName();
5072− QAction* action = menu->getActionForOption(name);
5073− if (pluginName == name) {
5074− action->setChecked(true);
5075− }
5076− }
5077− updateDisplayMode();
5078−}
5079−
50804954 void Application::setPalmData(Hand* hand, UserInputMapper::PoseValue pose, float deltaTime, int index) {
50814955 PalmData* palm;
50824956 bool foundHand = false;