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
58#include <AutoUpdater.h>58#include <AutoUpdater.h>
59#include <DeferredLightingEffect.h>59#include <DeferredLightingEffect.h>
60#include <DependencyManager.h>60#include <DependencyManager.h>
61#include <plugins/PluginContainer.h>
62#include <plugins/PluginManager.h>
61#include <display-plugins/DisplayPlugin.h>63#include <display-plugins/DisplayPlugin.h>
62 64
63#include <EntityScriptingInterface.h>65#include <EntityScriptingInterface.h>
@@ -148,6 +150,8 @@ · 84 unmodified lines
148 150
149#include "ui/overlays/Cube3DOverlay.h"151#include "ui/overlays/Cube3DOverlay.h"
150 152
153#include "PluginContainerProxy.h"
154
151// ON WIndows PC, NVidia Optimus laptop, we want to enable NVIDIA GPU155// ON WIndows PC, NVidia Optimus laptop, we want to enable NVIDIA GPU
152// FIXME seems to be broken.156// FIXME seems to be broken.
153#if defined(Q_OS_WIN)157#if defined(Q_OS_WIN)
@@ -301,7 +305,7 @@ bool setupEssentials(int& argc, char** argv) { · 147 unmodified lines
301// continuing to overburden Application.cpp305// continuing to overburden Application.cpp
302Cube3DOverlay* _keyboardFocusHighlight{ nullptr };306Cube3DOverlay* _keyboardFocusHighlight{ nullptr };
303int _keyboardFocusHighlightID{ -1 };307int _keyboardFocusHighlightID{ -1 };
304 308PluginContainer* _pluginContainer;
305 309
306Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :310Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
307 QApplication(argc, argv),311 QApplication(argc, argv),
@@ -351,7 +355,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 43 unmodified lines
351 _applicationOverlay()355 _applicationOverlay()
352{356{
353 setInstance(this);357 setInstance(this);
354 Plugin::setContainer(this);358
359 _pluginContainer = new PluginContainerProxy();
360 Plugin::setContainer(_pluginContainer);
355#ifdef Q_OS_WIN361#ifdef Q_OS_WIN
356 installNativeEventFilter(&MyNativeEventFilter::getInstance());362 installNativeEventFilter(&MyNativeEventFilter::getInstance());
357#endif363#endif
@@ -995,6 +1001,8 @@ void Application::paintGL() { · 637 unmodified lines
995 auto displayPlugin = getActiveDisplayPlugin();1001 auto displayPlugin = getActiveDisplayPlugin();
996 displayPlugin->preRender();1002 displayPlugin->preRender();
997 _offscreenContext->makeCurrent();1003 _offscreenContext->makeCurrent();
1004 // update the avatar with a fresh HMD pose
1005 _myAvatar->updateFromHMDSensorMatrix(getHMDSensorPose());
998 1006
999 auto lodManager = DependencyManager::get<LODManager>();1007 auto lodManager = DependencyManager::get<LODManager>();
1000 1008
@@ -1091,7 +1099,6 @@ void Application::paintGL() { · 90 unmodified lines
1091 glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror);1099 glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror);
1092 renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;1100 renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
1093 }1101 }
1094
1095 // Update camera position1102 // Update camera position
1096 if (!isHMDMode()) {1103 if (!isHMDMode()) {
1097 _myCamera.update(1.0f / _fps);1104 _myCamera.update(1.0f / _fps);
@@ -1100,64 +1107,46 @@ void Application::paintGL() { · 2 unmodified lines
1100 1107
1101 // Primary rendering pass1108 // Primary rendering pass
1102 auto framebufferCache = DependencyManager::get<FramebufferCache>();1109 auto framebufferCache = DependencyManager::get<FramebufferCache>();
1103 QSize size = framebufferCache->getFrameBufferSize();1110 const QSize size = framebufferCache->getFrameBufferSize();
1104 {1111 {
1105 PROFILE_RANGE(__FUNCTION__ "/mainRender");1112 PROFILE_RANGE(__FUNCTION__ "/mainRender");
1106 // Viewport is assigned to the size of the framebuffer1113 // Viewport is assigned to the size of the framebuffer
1107 QSize size = DependencyManager::get<FramebufferCache>()->getFrameBufferSize();1114 renderArgs._viewport = ivec4(0, 0, size.width(), size.height());
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
1125 if (displayPlugin->isStereo()) {1115 if (displayPlugin->isStereo()) {
1126 PROFILE_RANGE(__FUNCTION__ "/stereoRender");1116 // Stereo modes will typically have a larger projection matrix overall,
1127 QRect currentViewport(QPoint(0, 0), QSize(size.width() / 2, size.height()));1117 // so we ask for the 'mono' projection matrix, which for stereo and HMD
1128 glEnable(GL_SCISSOR_TEST);1118 // plugins will imply the combined projection for both eyes.
1129 for_each_eye([&](Eye eye){1119 //
1130 // Load the view frustum, used by meshes1120 // This is properly implemented for the Oculus plugins, but for OpenVR
1131 Camera eyeCamera;1121 // and Stereo displays I'm not sure how to get / calculate it, so we're
1132 if (qApp->isHMDMode()) {1122 // just relying on the left FOV in each case and hoping that the
1133 // Allow the displayPlugin to compose the final eye transform, based on the most up-to-date head motion.1123 // overall culling margin of error doesn't cause popping in the
1134 eyeCamera.setTransform(displayPlugin->getModelview(eye, _myAvatar->getSensorToWorldMatrix()));1124 // right eye. There are FIXMEs in the relevant plugins
1135 } else {1125 _myCamera.setProjection(displayPlugin->getProjection(Mono, _myCamera.getProjection()));
1136 eyeCamera.setTransform(displayPlugin->getModelview(eye, _myCamera.getTransform()));1126 renderArgs._context->enableStereo(true);
1137 }1127 mat4 eyeViews[2];
1138 eyeCamera.setProjection(displayPlugin->getProjection(eye, _myCamera.getProjection()));1128 mat4 eyeProjections[2];
1139 renderArgs._viewport = toGlm(currentViewport);1129 auto baseProjection = renderArgs._viewFrustum->getProjection();
1140 doInBatch(&renderArgs, [&](gpu::Batch& batch) {1130 // FIXME we probably don't need to set the projection matrix every frame,
1141 batch.setViewportTransform(renderArgs._viewport);1131 // only when the display plugin changes (or in non-HMD modes when the user
1142 batch.setStateScissorRect(renderArgs._viewport);1132 // changes the FOV manually, which right now I don't think they can.
1143 });1133 for_each_eye([&](Eye eye) {
1144 displaySide(&renderArgs, eyeCamera);1134 // For providing the stereo eye views, the HMD head pose has already been
1145 }, [&] {1135 // applied to the avatar, so we need to get the difference between the head
1146 currentViewport.moveLeft(currentViewport.width());1136 // pose applied to the avatar and the per eye pose, and use THAT as
1147 });1137 // the per-eye stereo matrix adjustment.
1148 glDisable(GL_SCISSOR_TEST);1138 mat4 eyePose = displayPlugin->getEyePose(eye);
1149 } else {1139 mat4 headPose = displayPlugin->getHeadPose();
1150 PROFILE_RANGE(__FUNCTION__ "/monoRender");1140 mat4 eyeView = glm::inverse(eyePose) * headPose;
1151 renderArgs._viewport = gpu::Vec4i(0, 0, size.width(), size.height());1141 eyeViews[eye] = eyeView;
1152 // Viewport is assigned to the size of the framebuffer1142 eyeProjections[eye] = displayPlugin->getProjection(eye, baseProjection);
1153 doInBatch(&renderArgs, [&](gpu::Batch& batch) {
1154 batch.setViewportTransform(renderArgs._viewport);
1155 batch.setStateScissorRect(renderArgs._viewport);
1156 });1143 });
1157 displaySide(&renderArgs, _myCamera);1144 renderArgs._context->setStereoProjections(eyeProjections);
1145 renderArgs._context->setStereoViews(eyeViews);
1158 }1146 }
1159 1147 displaySide(&renderArgs, _myCamera);
1160 doInBatch(&renderArgs, [](gpu::Batch& batch){1148 renderArgs._context->enableStereo(false);
1149 doInBatch(&renderArgs, [](gpu::Batch& batch) {
1161 batch.setFramebuffer(nullptr);1150 batch.setFramebuffer(nullptr);
1162 });1151 });
1163 }1152 }
@@ -1191,7 +1180,6 @@ void Application::paintGL() { · 27 unmodified lines
1191 PROFILE_RANGE(__FUNCTION__ "/pluginOutput");1180 PROFILE_RANGE(__FUNCTION__ "/pluginOutput");
1192 auto primaryFbo = framebufferCache->getPrimaryFramebuffer();1181 auto primaryFbo = framebufferCache->getPrimaryFramebuffer();
1193 GLuint finalTexture = gpu::GLBackend::getTextureID(primaryFbo->getRenderBuffer(0));1182 GLuint finalTexture = gpu::GLBackend::getTextureID(primaryFbo->getRenderBuffer(0));
1194 uvec2 finalSize = toGlm(size);
1195 // Ensure the rendering context commands are completed when rendering 1183 // Ensure the rendering context commands are completed when rendering
1196 GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);1184 GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
1197 // Ensure the sync object is flushed to the driver thread before releasing the context1185 // Ensure the sync object is flushed to the driver thread before releasing the context
@@ -1207,7 +1195,7 @@ void Application::paintGL() { · 9 unmodified lines
1207 1195
1208 {1196 {
1209 PROFILE_RANGE(__FUNCTION__ "/pluginDisplay");1197 PROFILE_RANGE(__FUNCTION__ "/pluginDisplay");
1210 displayPlugin->display(finalTexture, finalSize);1198 displayPlugin->display(finalTexture, toGlm(size));
1211 }1199 }
1212 1200
1213 {1201 {
@@ -1280,6 +1268,7 @@ void Application::resizeGL() { · 66 unmodified lines
1280 // Possible change in aspect ratio1268 // Possible change in aspect ratio
1281 loadViewFrustum(_myCamera, _viewFrustum);1269 loadViewFrustum(_myCamera, _viewFrustum);
1282 float fov = glm::radians(DEFAULT_FIELD_OF_VIEW_DEGREES);1270 float fov = glm::radians(DEFAULT_FIELD_OF_VIEW_DEGREES);
1271 // FIXME the aspect ratio for stereo displays is incorrect based on this.
1283 float aspectRatio = aspect(_renderResolution);1272 float aspectRatio = aspect(_renderResolution);
1284 _myCamera.setProjection(glm::perspective(fov, aspectRatio, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));1273 _myCamera.setProjection(glm::perspective(fov, aspectRatio, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
1285 }1274 }
@@ -1439,7 +1428,15 @@ void Application::keyPressEvent(QKeyEvent* event) { · 153 unmodified lines
1439 break;1428 break;
1440 case Qt::Key_Enter:1429 case Qt::Key_Enter:
1441 case Qt::Key_Return:1430 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 }
1443 break;1440 break;
1444 1441
1445 case Qt::Key_B:1442 case Qt::Key_B:
@@ -2705,9 +2702,6 @@ void Application::update(float deltaTime) { · 1259 unmodified lines
2705 updateLOD();2702 updateLOD();
2706 updateMouseRay(); // check what's under the mouse and update the mouse voxel2703 updateMouseRay(); // check what's under the mouse and update the mouse voxel
2707 2704
2708 // update the avatar with a fresh HMD pose
2709 _myAvatar->updateFromHMDSensorMatrix(getHMDSensorPose());
2710
2711 {2705 {
2712 PerformanceTimer perfTimer("devices");2706 PerformanceTimer perfTimer("devices");
2713 DeviceTracker::updateAll();2707 DeviceTracker::updateAll();
@@ -4638,10 +4632,6 @@ void Application::checkSkeleton() { · 1924 unmodified lines
4638 }4632 }
4639}4633}
4640 4634
4641bool Application::isForeground() {
4642 return _isForeground && !getWindow()->isMinimized();
4643}
4644
4645void Application::activeChanged(Qt::ApplicationState state) {4635void Application::activeChanged(Qt::ApplicationState state) {
4646 switch (state) {4636 switch (state) {
4647 case Qt::ApplicationActive:4637 case Qt::ApplicationActive:
@@ -4747,6 +4737,10 @@ const DisplayPlugin * Application::getActiveDisplayPlugin() const { · 99 unmodified lines
4747 return ((Application*)this)->getActiveDisplayPlugin();4737 return ((Application*)this)->getActiveDisplayPlugin();
4748}4738}
4749 4739
4740bool _activatingDisplayPlugin{ false };
4741QVector<QPair<QString, QString>> _currentDisplayPluginActions;
4742QVector<QPair<QString, QString>> _currentInputPluginActions;
4743
4750 4744
4751static void addDisplayPluginToMenu(DisplayPluginPointer displayPlugin, bool active = false) {4745static void addDisplayPluginToMenu(DisplayPluginPointer displayPlugin, bool active = false) {
4752 auto menu = Menu::getInstance();4746 auto menu = Menu::getInstance();
@@ -4768,9 +4762,6 @@ static void addDisplayPluginToMenu(DisplayPluginPointer displayPlugin, bool acti · 15 unmodified lines
4768 Q_ASSERT(menu->menuItemExists(MenuOption::OutputMenu, name));4762 Q_ASSERT(menu->menuItemExists(MenuOption::OutputMenu, name));
4769}4763}
4770 4764
4771static QVector<QPair<QString, QString>> _currentDisplayPluginActions;
4772static bool _activatingDisplayPlugin{false};
4773
4774void Application::updateDisplayMode() {4765void Application::updateDisplayMode() {
4775 auto menu = Menu::getInstance();4766 auto menu = Menu::getInstance();
4776 auto displayPlugins = PluginManager::getInstance()->getDisplayPlugins();4767 auto displayPlugins = PluginManager::getInstance()->getDisplayPlugins();
@@ -4837,7 +4828,7 @@ void Application::updateDisplayMode() { · 60 unmodified lines
4837 // Only show the hmd tools after the correct plugin has4828 // Only show the hmd tools after the correct plugin has
4838 // been activated so that it's UI is setup correctly4829 // been activated so that it's UI is setup correctly
4839 if (newPluginWantsHMDTools) {4830 if (newPluginWantsHMDTools) {
4840 showDisplayPluginsTools();4831 _pluginContainer->showDisplayPluginsTools();
4841 }4832 }
4842 4833
4843 if (oldDisplayPlugin) {4834 if (oldDisplayPlugin) {
@@ -4855,9 +4846,6 @@ void Application::updateDisplayMode() { · 11 unmodified lines
4855 Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin");4846 Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin");
4856}4847}
4857 4848
4858static QVector<QPair<QString, QString>> _currentInputPluginActions;
4859
4860
4861static void addInputPluginToMenu(InputPluginPointer inputPlugin, bool active = false) {4849static void addInputPluginToMenu(InputPluginPointer inputPlugin, bool active = false) {
4862 auto menu = Menu::getInstance();4850 auto menu = Menu::getInstance();
4863 QString name = inputPlugin->getName();4851 QString name = inputPlugin->getName();
@@ -4931,42 +4919,6 @@ void Application::updateInputModes() { · 67 unmodified lines
4931 //}4919 //}
4932}4920}
4933 4921
4934void Application::addMenu(const QString& menuName) {
4935 Menu::getInstance()->addMenu(menuName);
4936}
4937
4938void Application::removeMenu(const QString& menuName) {
4939 Menu::getInstance()->removeMenu(menuName);
4940}
4941
4942void 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
4958void Application::removeMenuItem(const QString& menuName, const QString& menuItem) {
4959 Menu::getInstance()->removeMenuItem(menuName, menuItem);
4960}
4961
4962bool Application::isOptionChecked(const QString& name) {
4963 return Menu::getInstance()->isOptionChecked(name);
4964}
4965
4966void Application::setIsOptionChecked(const QString& path, bool checked) {
4967 Menu::getInstance()->setIsOptionChecked(path, checked);
4968}
4969
4970mat4 Application::getEyeProjection(int eye) const {4922mat4 Application::getEyeProjection(int eye) const {
4971 if (isHMDMode()) {4923 if (isHMDMode()) {
4972 return getActiveDisplayPlugin()->getProjection((Eye)eye, _viewFrustum.getProjection());4924 return getActiveDisplayPlugin()->getProjection((Eye)eye, _viewFrustum.getProjection());
@@ -4986,7 +4938,7 @@ mat4 Application::getEyePose(int eye) const { · 13 unmodified lines
4986mat4 Application::getEyeOffset(int eye) const {4938mat4 Application::getEyeOffset(int eye) const {
4987 if (isHMDMode()) {4939 if (isHMDMode()) {
4988 mat4 identity;4940 mat4 identity;
4989 return getActiveDisplayPlugin()->getModelview((Eye)eye, identity);4941 return getActiveDisplayPlugin()->getView((Eye)eye, identity);
4990 }4942 }
4991 4943
4992 return mat4();4944 return mat4();
@@ -4999,84 +4951,6 @@ mat4 Application::getHMDSensorPose() const { · 6 unmodified lines
4999 return mat4();4951 return mat4();
5000}4952}
5001 4953
5002void 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
5021void 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
5060void Application::showDisplayPluginsTools() {
5061 DependencyManager::get<DialogsManager>()->hmdTools(true);
5062}
5063
5064QGLWidget* Application::getPrimarySurface() {
5065 return _glWidget;
5066}
5067
5068void 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
5080void Application::setPalmData(Hand* hand, UserInputMapper::PoseValue pose, float deltaTime, int index) {4954void Application::setPalmData(Hand* hand, UserInputMapper::PoseValue pose, float deltaTime, int index) {
5081 PalmData* palm;4955 PalmData* palm;
5082 bool foundHand = false;4956 bool foundHand = false;