Showing the changes to interface/src/Application.cpp (1 of 35 files). Show all
Unified · Split
| @@ -801,7 +801,12 @@ void Application::initializeUi() { · 800 unmodified lines | |||
| 801 | 801 | ||
| 802 | void Application::paintGL() { | 802 | void Application::paintGL() { |
| 803 | PROFILE_RANGE(__FUNCTION__); | 803 | PROFILE_RANGE(__FUNCTION__); |
| 804 | _glWidget->makeCurrent(); | ||
| 804 | PerformanceTimer perfTimer("paintGL"); | 805 | PerformanceTimer perfTimer("paintGL"); |
| 806 | //Need accurate frame timing for the oculus rift | ||
| 807 | if (OculusManager::isConnected()) { | ||
| 808 | OculusManager::beginFrameTiming(); | ||
| 809 | } | ||
| 805 | 810 | ||
| 806 | PerformanceWarning::setSuppressShortTimings(Menu::getInstance()->isOptionChecked(MenuOption::SuppressShortTimings)); | 811 | PerformanceWarning::setSuppressShortTimings(Menu::getInstance()->isOptionChecked(MenuOption::SuppressShortTimings)); |
| 807 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | 812 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); |
| @@ -847,11 +852,6 @@ void Application::paintGL() { · 39 unmodified lines | |||
| 847 | glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror); | 852 | glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror); |
| 848 | } | 853 | } |
| 849 | 854 | ||
| 850 | // Update camera position | ||
| 851 | if (!OculusManager::isConnected()) { | ||
| 852 | _myCamera.update(1.0f / _fps); | ||
| 853 | } | ||
| 854 | |||
| 855 | if (getShadowsEnabled()) { | 855 | if (getShadowsEnabled()) { |
| 856 | updateShadowMap(); | 856 | updateShadowMap(); |
| 857 | } | 857 | } |
| @@ -859,12 +859,10 @@ void Application::paintGL() { · 1 unmodified line | |||
| 859 | if (OculusManager::isConnected()) { | 859 | if (OculusManager::isConnected()) { |
| 860 | //When in mirror mode, use camera rotation. Otherwise, use body rotation | 860 | //When in mirror mode, use camera rotation. Otherwise, use body rotation |
| 861 | if (_myCamera.getMode() == CAMERA_MODE_MIRROR) { | 861 | if (_myCamera.getMode() == CAMERA_MODE_MIRROR) { |
| 862 | OculusManager::display(_myCamera.getRotation(), _myCamera.getPosition(), _myCamera); | 862 | OculusManager::display(_glWidget, _myCamera.getRotation(), _myCamera.getPosition(), _myCamera); |
| 863 | } else { | 863 | } else { |
| 864 | OculusManager::display(_myAvatar->getWorldAlignedOrientation(), _myAvatar->getDefaultEyePosition(), _myCamera); | 864 | OculusManager::display(_glWidget, _myAvatar->getWorldAlignedOrientation(), _myAvatar->getDefaultEyePosition(), _myCamera); |
| 865 | } | 865 | } |
| 866 | _myCamera.update(1.0f / _fps); | ||
| 867 | |||
| 868 | } else if (TV3DManager::isConnected()) { | 866 | } else if (TV3DManager::isConnected()) { |
| 869 | 867 | ||
| 870 | TV3DManager::display(_myCamera); | 868 | TV3DManager::display(_myCamera); |
| @@ -883,8 +881,7 @@ void Application::paintGL() { · 12 unmodified lines | |||
| 883 | glPopMatrix(); | 881 | glPopMatrix(); |
| 884 | 882 | ||
| 885 | if (Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) { | 883 | if (Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) { |
| 886 | _rearMirrorTools->render(true); | 884 | _rearMirrorTools->render(true, _glWidget->mapFromGlobal(QCursor::pos())); |
| 887 | |||
| 888 | } else if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) { | 885 | } else if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) { |
| 889 | renderRearViewMirror(_mirrorViewRect); | 886 | renderRearViewMirror(_mirrorViewRect); |
| 890 | } | 887 | } |
| @@ -898,6 +895,13 @@ void Application::paintGL() { · 7 unmodified lines | |||
| 898 | } | 895 | } |
| 899 | } | 896 | } |
| 900 | 897 | ||
| 898 | if (!OculusManager::isConnected() || OculusManager::allowSwap()) { | ||
| 899 | _glWidget->swapBuffers(); | ||
| 900 | } | ||
| 901 | |||
| 902 | if (OculusManager::isConnected()) { | ||
| 903 | OculusManager::endFrameTiming(); | ||
| 904 | } | ||
| 901 | _frameCount++; | 905 | _frameCount++; |
| 902 | } | 906 | } |
| 903 | 907 | ||
| @@ -931,6 +935,7 @@ void Application::resetCamerasOnResizeGL(Camera& camera, int width, int height) · 27 unmodified lines | |||
| 931 | } | 935 | } |
| 932 | 936 | ||
| 933 | void Application::resizeGL(int width, int height) { | 937 | void Application::resizeGL(int width, int height) { |
| 938 | DependencyManager::get<TextureCache>()->setFrameBufferSize(QSize(width, height)); | ||
| 934 | resetCamerasOnResizeGL(_myCamera, width, height); | 939 | resetCamerasOnResizeGL(_myCamera, width, height); |
| 935 | 940 | ||
| 936 | glViewport(0, 0, width, height); // shouldn't this account for the menu??? | 941 | glViewport(0, 0, width, height); // shouldn't this account for the menu??? |
| @@ -1298,8 +1303,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 361 unmodified lines | |||
| 1298 | if (!event->isAutoRepeat()) { | 1303 | if (!event->isAutoRepeat()) { |
| 1299 | // this starts an HFActionEvent | 1304 | // this starts an HFActionEvent |
| 1300 | HFActionEvent startActionEvent(HFActionEvent::startType(), | 1305 | HFActionEvent startActionEvent(HFActionEvent::startType(), |
| 1301 | _myCamera.computePickRay(getTrueMouseX(), | 1306 | computePickRay(getTrueMouseX(), getTrueMouseY())); |
| 1302 | getTrueMouseY())); | ||
| 1303 | sendEvent(this, &startActionEvent); | 1307 | sendEvent(this, &startActionEvent); |
| 1304 | } | 1308 | } |
| 1305 | 1309 | ||
| @@ -1404,8 +1408,7 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 98 unmodified lines | |||
| 1404 | if (!event->isAutoRepeat()) { | 1408 | if (!event->isAutoRepeat()) { |
| 1405 | // this ends the HFActionEvent | 1409 | // this ends the HFActionEvent |
| 1406 | HFActionEvent endActionEvent(HFActionEvent::endType(), | 1410 | HFActionEvent endActionEvent(HFActionEvent::endType(), |
| 1407 | _myCamera.computePickRay(getTrueMouseX(), | 1411 | computePickRay(getTrueMouseX(), getTrueMouseY())); |
| 1408 | getTrueMouseY())); | ||
| 1409 | sendEvent(this, &endActionEvent); | 1412 | sendEvent(this, &endActionEvent); |
| 1410 | } | 1413 | } |
| 1411 | break; | 1414 | break; |
| @@ -1499,7 +1502,7 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { · 87 unmodified lines | |||
| 1499 | 1502 | ||
| 1500 | // nobody handled this - make it an action event on the _window object | 1503 | // nobody handled this - make it an action event on the _window object |
| 1501 | HFActionEvent actionEvent(HFActionEvent::startType(), | 1504 | HFActionEvent actionEvent(HFActionEvent::startType(), |
| 1502 | _myCamera.computePickRay(event->x(), event->y())); | 1505 | computePickRay(event->x(), event->y())); |
| 1503 | sendEvent(this, &actionEvent); | 1506 | sendEvent(this, &actionEvent); |
| 1504 | 1507 | ||
| 1505 | } else if (event->button() == Qt::RightButton) { | 1508 | } else if (event->button() == Qt::RightButton) { |
| @@ -1534,7 +1537,7 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { · 28 unmodified lines | |||
| 1534 | 1537 | ||
| 1535 | // fire an action end event | 1538 | // fire an action end event |
| 1536 | HFActionEvent actionEvent(HFActionEvent::endType(), | 1539 | HFActionEvent actionEvent(HFActionEvent::endType(), |
| 1537 | _myCamera.computePickRay(event->x(), event->y())); | 1540 | computePickRay(event->x(), event->y())); |
| 1538 | sendEvent(this, &actionEvent); | 1541 | sendEvent(this, &actionEvent); |
| 1539 | } | 1542 | } |
| 1540 | } | 1543 | } |
| @@ -2104,19 +2107,16 @@ void Application::init() { · 563 unmodified lines | |||
| 2104 | _entityClipboardRenderer.setViewFrustum(getViewFrustum()); | 2107 | _entityClipboardRenderer.setViewFrustum(getViewFrustum()); |
| 2105 | _entityClipboardRenderer.setTree(&_entityClipboard); | 2108 | _entityClipboardRenderer.setTree(&_entityClipboard); |
| 2106 | 2109 | ||
| 2107 | _rearMirrorTools = new RearMirrorTools(_glWidget, _mirrorViewRect); | 2110 | _rearMirrorTools = new RearMirrorTools(_mirrorViewRect); |
| 2108 | 2111 | ||
| 2109 | connect(_rearMirrorTools, SIGNAL(closeView()), SLOT(closeMirrorView())); | 2112 | connect(_rearMirrorTools, SIGNAL(closeView()), SLOT(closeMirrorView())); |
| 2110 | connect(_rearMirrorTools, SIGNAL(restoreView()), SLOT(restoreMirrorView())); | 2113 | connect(_rearMirrorTools, SIGNAL(restoreView()), SLOT(restoreMirrorView())); |
| 2111 | connect(_rearMirrorTools, SIGNAL(shrinkView()), SLOT(shrinkMirrorView())); | 2114 | connect(_rearMirrorTools, SIGNAL(shrinkView()), SLOT(shrinkMirrorView())); |
| 2112 | connect(_rearMirrorTools, SIGNAL(resetView()), SLOT(resetSensors())); | 2115 | connect(_rearMirrorTools, SIGNAL(resetView()), SLOT(resetSensors())); |
| 2113 | 2116 | ||
| 2114 | // make sure our texture cache knows about window size changes | ||
| 2115 | DependencyManager::get<TextureCache>()->associateWithWidget(_glWidget); | ||
| 2116 | |||
| 2117 | // initialize the GlowEffect with our widget | 2117 | // initialize the GlowEffect with our widget |
| 2118 | DependencyManager::get<GlowEffect>()->init(_glWidget, | 2118 | bool glow = Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect); |
| 2119 | Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect)); | 2119 | DependencyManager::get<GlowEffect>()->init(glow); |
| 2120 | } | 2120 | } |
| 2121 | 2121 | ||
| 2122 | void Application::closeMirrorView() { | 2122 | void Application::closeMirrorView() { |
| @@ -2167,7 +2167,7 @@ void Application::updateMouseRay() { · 44 unmodified lines | |||
| 2167 | // make sure the frustum is up-to-date | 2167 | // make sure the frustum is up-to-date |
| 2168 | loadViewFrustum(_myCamera, _viewFrustum); | 2168 | loadViewFrustum(_myCamera, _viewFrustum); |
| 2169 | 2169 | ||
| 2170 | PickRay pickRay = _myCamera.computePickRay(getTrueMouseX(), getTrueMouseY()); | 2170 | PickRay pickRay = computePickRay(getTrueMouseX(), getTrueMouseY()); |
| 2171 | _mouseRayOrigin = pickRay.origin; | 2171 | _mouseRayOrigin = pickRay.origin; |
| 2172 | _mouseRayDirection = pickRay.direction; | 2172 | _mouseRayDirection = pickRay.direction; |
| 2173 | 2173 | ||
| @@ -2979,8 +2979,17 @@ int Application::getBoundaryLevelAdjust() const { · 805 unmodified lines | |||
| 2979 | return DependencyManager::get<LODManager>()->getBoundaryLevelAdjust(); | 2979 | return DependencyManager::get<LODManager>()->getBoundaryLevelAdjust(); |
| 2980 | } | 2980 | } |
| 2981 | 2981 | ||
| 2982 | PickRay Application::computePickRay(float x, float y) { | 2982 | PickRay Application::computePickRay(float x, float y) const { |
| 2983 | return getCamera()->computePickRay(x, y); | 2983 | glm::vec2 size = getCanvasSize(); |
| 2984 | x /= size.x; | ||
| 2985 | y /= size.y; | ||
| 2986 | PickRay result; | ||
| 2987 | if (isHMDMode()) { | ||
| 2988 | ApplicationOverlay::computeHmdPickRay(glm::vec2(x, y), result.origin, result.direction); | ||
| 2989 | } else { | ||
| 2990 | getViewFrustum()->computePickRay(x, y, result.origin, result.direction); | ||
| 2991 | } | ||
| 2992 | return result; | ||
| 2984 | } | 2993 | } |
| 2985 | 2994 | ||
| 2986 | QImage Application::renderAvatarBillboard() { | 2995 | QImage Application::renderAvatarBillboard() { |
| @@ -3013,6 +3022,16 @@ ViewFrustum* Application::getViewFrustum() { · 26 unmodified lines | |||
| 3013 | return &_viewFrustum; | 3022 | return &_viewFrustum; |
| 3014 | } | 3023 | } |
| 3015 | 3024 | ||
| 3025 | const ViewFrustum* Application::getViewFrustum() const { | ||
| 3026 | #ifdef DEBUG | ||
| 3027 | if (QThread::currentThread() == activeRenderingThread) { | ||
| 3028 | // FIXME, should this be an assert? | ||
| 3029 | qWarning() << "Calling Application::getViewFrustum() from the active rendering thread, did you mean Application::getDisplayViewFrustum()?"; | ||
| 3030 | } | ||
| 3031 | #endif | ||
| 3032 | return &_viewFrustum; | ||
| 3033 | } | ||
| 3034 | |||
| 3016 | ViewFrustum* Application::getDisplayViewFrustum() { | 3035 | ViewFrustum* Application::getDisplayViewFrustum() { |
| 3017 | #ifdef DEBUG | 3036 | #ifdef DEBUG |
| 3018 | if (QThread::currentThread() != activeRenderingThread) { | 3037 | if (QThread::currentThread() != activeRenderingThread) { |
| @@ -3376,7 +3395,6 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { · 357 unmodified lines | |||
| 3376 | _mirrorCamera.setAspectRatio((float)region.width() / region.height()); | 3395 | _mirrorCamera.setAspectRatio((float)region.width() / region.height()); |
| 3377 | 3396 | ||
| 3378 | _mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f))); | 3397 | _mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f))); |
| 3379 | _mirrorCamera.update(1.0f/_fps); | ||
| 3380 | 3398 | ||
| 3381 | // set the bounds of rear mirror view | 3399 | // set the bounds of rear mirror view |
| 3382 | if (billboard) { | 3400 | if (billboard) { |
| @@ -3402,7 +3420,7 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { · 19 unmodified lines | |||
| 3402 | glPopMatrix(); | 3420 | glPopMatrix(); |
| 3403 | 3421 | ||
| 3404 | if (!billboard) { | 3422 | if (!billboard) { |
| 3405 | _rearMirrorTools->render(false); | 3423 | _rearMirrorTools->render(false, _glWidget->mapFromGlobal(QCursor::pos())); |
| 3406 | } | 3424 | } |
| 3407 | 3425 | ||
| 3408 | // reset Viewport and projection matrix | 3426 | // reset Viewport and projection matrix |
| @@ -4283,7 +4301,7 @@ void Application::takeSnapshot() { · 874 unmodified lines | |||
| 4283 | player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath())); | 4301 | player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath())); |
| 4284 | player->play(); | 4302 | player->play(); |
| 4285 | 4303 | ||
| 4286 | QString fileName = Snapshot::saveSnapshot(); | 4304 | QString fileName = Snapshot::saveSnapshot(_glWidget->grabFrameBuffer()); |
| 4287 | 4305 | ||
| 4288 | AccountManager& accountManager = AccountManager::getInstance(); | 4306 | AccountManager& accountManager = AccountManager::getInstance(); |
| 4289 | if (!accountManager.isLoggedIn()) { | 4307 | if (!accountManager.isLoggedIn()) { |
| @@ -4471,3 +4489,52 @@ void Application::friendsWindowClosed() { · 181 unmodified lines | |||
| 4471 | void Application::postLambdaEvent(std::function<void()> f) { | 4489 | void Application::postLambdaEvent(std::function<void()> f) { |
| 4472 | QCoreApplication::postEvent(this, new LambdaEvent(f)); | 4490 | QCoreApplication::postEvent(this, new LambdaEvent(f)); |
| 4473 | } | 4491 | } |
| 4492 | |||
| 4493 | void Application::initPlugins() { | ||
| 4494 | OculusManager::init(); | ||
| 4495 | } | ||
| 4496 | |||
| 4497 | void Application::shutdownPlugins() { | ||
| 4498 | OculusManager::deinit(); | ||
| 4499 | } | ||
| 4500 | |||
| 4501 | glm::vec3 Application::getHeadPosition() const { | ||
| 4502 | return OculusManager::getRelativePosition(); | ||
| 4503 | } | ||
| 4504 | |||
| 4505 | |||
| 4506 | glm::quat Application::getHeadOrientation() const { | ||
| 4507 | return OculusManager::getOrientation(); | ||
| 4508 | } | ||
| 4509 | |||
| 4510 | glm::uvec2 Application::getCanvasSize() const { | ||
| 4511 | return glm::uvec2(_glWidget->width(), _glWidget->height()); | ||
| 4512 | } | ||
| 4513 | |||
| 4514 | QSize Application::getDeviceSize() const { | ||
| 4515 | return _glWidget->getDeviceSize(); | ||
| 4516 | } | ||
| 4517 | |||
| 4518 | int Application::getTrueMouseX() const { | ||
| 4519 | return _glWidget->mapFromGlobal(QCursor::pos()).x(); | ||
| 4520 | } | ||
| 4521 | |||
| 4522 | int Application::getTrueMouseY() const { | ||
| 4523 | return _glWidget->mapFromGlobal(QCursor::pos()).y(); | ||
| 4524 | } | ||
| 4525 | |||
| 4526 | bool Application::isThrottleRendering() const { | ||
| 4527 | return _glWidget->isThrottleRendering(); | ||
| 4528 | } | ||
| 4529 | |||
| 4530 | PickRay Application::computePickRay() const { | ||
| 4531 | return computePickRay(getTrueMouseX(), getTrueMouseY()); | ||
| 4532 | } | ||
| 4533 | |||
| 4534 | bool Application::hasFocus() const { | ||
| 4535 | return _glWidget->hasFocus(); | ||
| 4536 | } | ||
| 4537 | |||
| 4538 | void Application::resizeGL() { | ||
| 4539 | this->resizeGL(_glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); | ||
| 4540 | } | ||