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 | 802 | void Application::paintGL() { |
| 803 | 803 | PROFILE_RANGE(__FUNCTION__); |
| 804 | + _glWidget->makeCurrent(); | |
| 804 | 805 | PerformanceTimer perfTimer("paintGL"); |
| 806 | + //Need accurate frame timing for the oculus rift | |
| 807 | + if (OculusManager::isConnected()) { | |
| 808 | + OculusManager::beginFrameTiming(); | |
| 809 | + } | |
| 805 | 810 | |
| 806 | 811 | PerformanceWarning::setSuppressShortTimings(Menu::getInstance()->isOptionChecked(MenuOption::SuppressShortTimings)); |
| 807 | 812 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); |
| @@ -847,11 +852,6 @@ void Application::paintGL() { · 39 unmodified lines | ||
| 847 | 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 | 855 | if (getShadowsEnabled()) { |
| 856 | 856 | updateShadowMap(); |
| 857 | 857 | } |
| @@ -859,12 +859,10 @@ void Application::paintGL() { · 1 unmodified line | ||
| 859 | 859 | if (OculusManager::isConnected()) { |
| 860 | 860 | //When in mirror mode, use camera rotation. Otherwise, use body rotation |
| 861 | 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 | 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 | 866 | } else if (TV3DManager::isConnected()) { |
| 869 | 867 | |
| 870 | 868 | TV3DManager::display(_myCamera); |
| @@ -883,8 +881,7 @@ void Application::paintGL() { · 12 unmodified lines | ||
| 883 | 881 | glPopMatrix(); |
| 884 | 882 | |
| 885 | 883 | if (Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) { |
| 886 | − _rearMirrorTools->render(true); | |
| 887 | − | |
| 884 | + _rearMirrorTools->render(true, _glWidget->mapFromGlobal(QCursor::pos())); | |
| 888 | 885 | } else if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) { |
| 889 | 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 | 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 | 937 | void Application::resizeGL(int width, int height) { |
| 938 | + DependencyManager::get<TextureCache>()->setFrameBufferSize(QSize(width, height)); | |
| 934 | 939 | resetCamerasOnResizeGL(_myCamera, width, height); |
| 935 | 940 | |
| 936 | 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 | 1303 | if (!event->isAutoRepeat()) { |
| 1299 | 1304 | // this starts an HFActionEvent |
| 1300 | 1305 | HFActionEvent startActionEvent(HFActionEvent::startType(), |
| 1301 | − _myCamera.computePickRay(getTrueMouseX(), | |
| 1302 | − getTrueMouseY())); | |
| 1306 | + computePickRay(getTrueMouseX(), getTrueMouseY())); | |
| 1303 | 1307 | sendEvent(this, &startActionEvent); |
| 1304 | 1308 | } |
| 1305 | 1309 | |
| @@ -1404,8 +1408,7 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 98 unmodified lines | ||
| 1404 | 1408 | if (!event->isAutoRepeat()) { |
| 1405 | 1409 | // this ends the HFActionEvent |
| 1406 | 1410 | HFActionEvent endActionEvent(HFActionEvent::endType(), |
| 1407 | − _myCamera.computePickRay(getTrueMouseX(), | |
| 1408 | − getTrueMouseY())); | |
| 1411 | + computePickRay(getTrueMouseX(), getTrueMouseY())); | |
| 1409 | 1412 | sendEvent(this, &endActionEvent); |
| 1410 | 1413 | } |
| 1411 | 1414 | break; |
| @@ -1499,7 +1502,7 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { · 87 unmodified lines | ||
| 1499 | 1502 | |
| 1500 | 1503 | // nobody handled this - make it an action event on the _window object |
| 1501 | 1504 | HFActionEvent actionEvent(HFActionEvent::startType(), |
| 1502 | − _myCamera.computePickRay(event->x(), event->y())); | |
| 1505 | + computePickRay(event->x(), event->y())); | |
| 1503 | 1506 | sendEvent(this, &actionEvent); |
| 1504 | 1507 | |
| 1505 | 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 | 1538 | // fire an action end event |
| 1536 | 1539 | HFActionEvent actionEvent(HFActionEvent::endType(), |
| 1537 | − _myCamera.computePickRay(event->x(), event->y())); | |
| 1540 | + computePickRay(event->x(), event->y())); | |
| 1538 | 1541 | sendEvent(this, &actionEvent); |
| 1539 | 1542 | } |
| 1540 | 1543 | } |
| @@ -2104,19 +2107,16 @@ void Application::init() { · 563 unmodified lines | ||
| 2104 | 2107 | _entityClipboardRenderer.setViewFrustum(getViewFrustum()); |
| 2105 | 2108 | _entityClipboardRenderer.setTree(&_entityClipboard); |
| 2106 | 2109 | |
| 2107 | − _rearMirrorTools = new RearMirrorTools(_glWidget, _mirrorViewRect); | |
| 2110 | + _rearMirrorTools = new RearMirrorTools(_mirrorViewRect); | |
| 2108 | 2111 | |
| 2109 | 2112 | connect(_rearMirrorTools, SIGNAL(closeView()), SLOT(closeMirrorView())); |
| 2110 | 2113 | connect(_rearMirrorTools, SIGNAL(restoreView()), SLOT(restoreMirrorView())); |
| 2111 | 2114 | connect(_rearMirrorTools, SIGNAL(shrinkView()), SLOT(shrinkMirrorView())); |
| 2112 | 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 | 2117 | // initialize the GlowEffect with our widget |
| 2118 | − DependencyManager::get<GlowEffect>()->init(_glWidget, | |
| 2119 | − Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect)); | |
| 2118 | + bool glow = Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect); | |
| 2119 | + DependencyManager::get<GlowEffect>()->init(glow); | |
| 2120 | 2120 | } |
| 2121 | 2121 | |
| 2122 | 2122 | void Application::closeMirrorView() { |
| @@ -2167,7 +2167,7 @@ void Application::updateMouseRay() { · 44 unmodified lines | ||
| 2167 | 2167 | // make sure the frustum is up-to-date |
| 2168 | 2168 | loadViewFrustum(_myCamera, _viewFrustum); |
| 2169 | 2169 | |
| 2170 | − PickRay pickRay = _myCamera.computePickRay(getTrueMouseX(), getTrueMouseY()); | |
| 2170 | + PickRay pickRay = computePickRay(getTrueMouseX(), getTrueMouseY()); | |
| 2171 | 2171 | _mouseRayOrigin = pickRay.origin; |
| 2172 | 2172 | _mouseRayDirection = pickRay.direction; |
| 2173 | 2173 | |
| @@ -2979,8 +2979,17 @@ int Application::getBoundaryLevelAdjust() const { · 805 unmodified lines | ||
| 2979 | 2979 | return DependencyManager::get<LODManager>()->getBoundaryLevelAdjust(); |
| 2980 | 2980 | } |
| 2981 | 2981 | |
| 2982 | −PickRay Application::computePickRay(float x, float y) { | |
| 2983 | − return getCamera()->computePickRay(x, y); | |
| 2982 | +PickRay Application::computePickRay(float x, float y) const { | |
| 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 | 2995 | QImage Application::renderAvatarBillboard() { |
| @@ -3013,6 +3022,16 @@ ViewFrustum* Application::getViewFrustum() { · 26 unmodified lines | ||
| 3013 | 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 | 3035 | ViewFrustum* Application::getDisplayViewFrustum() { |
| 3017 | 3036 | #ifdef DEBUG |
| 3018 | 3037 | if (QThread::currentThread() != activeRenderingThread) { |
| @@ -3376,7 +3395,6 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { · 357 unmodified lines | ||
| 3376 | 3395 | _mirrorCamera.setAspectRatio((float)region.width() / region.height()); |
| 3377 | 3396 | |
| 3378 | 3397 | _mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f))); |
| 3379 | − _mirrorCamera.update(1.0f/_fps); | |
| 3380 | 3398 | |
| 3381 | 3399 | // set the bounds of rear mirror view |
| 3382 | 3400 | if (billboard) { |
| @@ -3402,7 +3420,7 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { · 19 unmodified lines | ||
| 3402 | 3420 | glPopMatrix(); |
| 3403 | 3421 | |
| 3404 | 3422 | if (!billboard) { |
| 3405 | − _rearMirrorTools->render(false); | |
| 3423 | + _rearMirrorTools->render(false, _glWidget->mapFromGlobal(QCursor::pos())); | |
| 3406 | 3424 | } |
| 3407 | 3425 | |
| 3408 | 3426 | // reset Viewport and projection matrix |
| @@ -4283,7 +4301,7 @@ void Application::takeSnapshot() { · 874 unmodified lines | ||
| 4283 | 4301 | player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath())); |
| 4284 | 4302 | player->play(); |
| 4285 | 4303 | |
| 4286 | − QString fileName = Snapshot::saveSnapshot(); | |
| 4304 | + QString fileName = Snapshot::saveSnapshot(_glWidget->grabFrameBuffer()); | |
| 4287 | 4305 | |
| 4288 | 4306 | AccountManager& accountManager = AccountManager::getInstance(); |
| 4289 | 4307 | if (!accountManager.isLoggedIn()) { |
| @@ -4471,3 +4489,52 @@ void Application::friendsWindowClosed() { · 181 unmodified lines | ||
| 4471 | 4489 | void Application::postLambdaEvent(std::function<void()> f) { |
| 4472 | 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 | +} | |