History

Removing access to the gl widget and display managers

Brad Davis committed 11 years ago

Commit 302aa9d1 parent 539063035 files · +401 −440Browse files

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

Unified · Split

interface/src/Application.cpp+96−29
@@ -801,7 +801,12 @@ void Application::initializeUi() { · 800 unmodified lines
801801
802802 void Application::paintGL() {
803803 PROFILE_RANGE(__FUNCTION__);
804+ _glWidget->makeCurrent();
804805 PerformanceTimer perfTimer("paintGL");
806+ //Need accurate frame timing for the oculus rift
807+ if (OculusManager::isConnected()) {
808+ OculusManager::beginFrameTiming();
809+ }
805810
806811 PerformanceWarning::setSuppressShortTimings(Menu::getInstance()->isOptionChecked(MenuOption::SuppressShortTimings));
807812 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
@@ -847,11 +852,6 @@ void Application::paintGL() { · 39 unmodified lines
847852 glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror);
848853 }
849854
850− // Update camera position
851− if (!OculusManager::isConnected()) {
852− _myCamera.update(1.0f / _fps);
853− }
854−
855855 if (getShadowsEnabled()) {
856856 updateShadowMap();
857857 }
@@ -859,12 +859,10 @@ void Application::paintGL() { · 1 unmodified line
859859 if (OculusManager::isConnected()) {
860860 //When in mirror mode, use camera rotation. Otherwise, use body rotation
861861 if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
862− OculusManager::display(_myCamera.getRotation(), _myCamera.getPosition(), _myCamera);
862+ OculusManager::display(_glWidget, _myCamera.getRotation(), _myCamera.getPosition(), _myCamera);
863863 } else {
864− OculusManager::display(_myAvatar->getWorldAlignedOrientation(), _myAvatar->getDefaultEyePosition(), _myCamera);
864+ OculusManager::display(_glWidget, _myAvatar->getWorldAlignedOrientation(), _myAvatar->getDefaultEyePosition(), _myCamera);
865865 }
866− _myCamera.update(1.0f / _fps);
867−
868866 } else if (TV3DManager::isConnected()) {
869867
870868 TV3DManager::display(_myCamera);
@@ -883,8 +881,7 @@ void Application::paintGL() { · 12 unmodified lines
883881 glPopMatrix();
884882
885883 if (Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) {
886− _rearMirrorTools->render(true);
887−
884+ _rearMirrorTools->render(true, _glWidget->mapFromGlobal(QCursor::pos()));
888885 } else if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
889886 renderRearViewMirror(_mirrorViewRect);
890887 }
@@ -898,6 +895,13 @@ void Application::paintGL() { · 7 unmodified lines
898895 }
899896 }
900897
898+ if (!OculusManager::isConnected() || OculusManager::allowSwap()) {
899+ _glWidget->swapBuffers();
900+ }
901+
902+ if (OculusManager::isConnected()) {
903+ OculusManager::endFrameTiming();
904+ }
901905 _frameCount++;
902906 }
903907
@@ -931,6 +935,7 @@ void Application::resetCamerasOnResizeGL(Camera& camera, int width, int height) · 27 unmodified lines
931935 }
932936
933937 void Application::resizeGL(int width, int height) {
938+ DependencyManager::get<TextureCache>()->setFrameBufferSize(QSize(width, height));
934939 resetCamerasOnResizeGL(_myCamera, width, height);
935940
936941 glViewport(0, 0, width, height); // shouldn't this account for the menu???
@@ -1298,8 +1303,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 361 unmodified lines
12981303 if (!event->isAutoRepeat()) {
12991304 // this starts an HFActionEvent
13001305 HFActionEvent startActionEvent(HFActionEvent::startType(),
1301− _myCamera.computePickRay(getTrueMouseX(),
1302− getTrueMouseY()));
1306+ computePickRay(getTrueMouseX(), getTrueMouseY()));
13031307 sendEvent(this, &startActionEvent);
13041308 }
13051309
@@ -1404,8 +1408,7 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 98 unmodified lines
14041408 if (!event->isAutoRepeat()) {
14051409 // this ends the HFActionEvent
14061410 HFActionEvent endActionEvent(HFActionEvent::endType(),
1407− _myCamera.computePickRay(getTrueMouseX(),
1408− getTrueMouseY()));
1411+ computePickRay(getTrueMouseX(), getTrueMouseY()));
14091412 sendEvent(this, &endActionEvent);
14101413 }
14111414 break;
@@ -1499,7 +1502,7 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { · 87 unmodified lines
14991502
15001503 // nobody handled this - make it an action event on the _window object
15011504 HFActionEvent actionEvent(HFActionEvent::startType(),
1502− _myCamera.computePickRay(event->x(), event->y()));
1505+ computePickRay(event->x(), event->y()));
15031506 sendEvent(this, &actionEvent);
15041507
15051508 } else if (event->button() == Qt::RightButton) {
@@ -1534,7 +1537,7 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { · 28 unmodified lines
15341537
15351538 // fire an action end event
15361539 HFActionEvent actionEvent(HFActionEvent::endType(),
1537− _myCamera.computePickRay(event->x(), event->y()));
1540+ computePickRay(event->x(), event->y()));
15381541 sendEvent(this, &actionEvent);
15391542 }
15401543 }
@@ -2104,19 +2107,16 @@ void Application::init() { · 563 unmodified lines
21042107 _entityClipboardRenderer.setViewFrustum(getViewFrustum());
21052108 _entityClipboardRenderer.setTree(&_entityClipboard);
21062109
2107− _rearMirrorTools = new RearMirrorTools(_glWidget, _mirrorViewRect);
2110+ _rearMirrorTools = new RearMirrorTools(_mirrorViewRect);
21082111
21092112 connect(_rearMirrorTools, SIGNAL(closeView()), SLOT(closeMirrorView()));
21102113 connect(_rearMirrorTools, SIGNAL(restoreView()), SLOT(restoreMirrorView()));
21112114 connect(_rearMirrorTools, SIGNAL(shrinkView()), SLOT(shrinkMirrorView()));
21122115 connect(_rearMirrorTools, SIGNAL(resetView()), SLOT(resetSensors()));
21132116
2114− // make sure our texture cache knows about window size changes
2115− DependencyManager::get<TextureCache>()->associateWithWidget(_glWidget);
2116−
21172117 // 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);
21202120 }
21212121
21222122 void Application::closeMirrorView() {
@@ -2167,7 +2167,7 @@ void Application::updateMouseRay() { · 44 unmodified lines
21672167 // make sure the frustum is up-to-date
21682168 loadViewFrustum(_myCamera, _viewFrustum);
21692169
2170− PickRay pickRay = _myCamera.computePickRay(getTrueMouseX(), getTrueMouseY());
2170+ PickRay pickRay = computePickRay(getTrueMouseX(), getTrueMouseY());
21712171 _mouseRayOrigin = pickRay.origin;
21722172 _mouseRayDirection = pickRay.direction;
21732173
@@ -2979,8 +2979,17 @@ int Application::getBoundaryLevelAdjust() const { · 805 unmodified lines
29792979 return DependencyManager::get<LODManager>()->getBoundaryLevelAdjust();
29802980 }
29812981
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;
29842993 }
29852994
29862995 QImage Application::renderAvatarBillboard() {
@@ -3013,6 +3022,16 @@ ViewFrustum* Application::getViewFrustum() { · 26 unmodified lines
30133022 return &_viewFrustum;
30143023 }
30153024
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+
30163035 ViewFrustum* Application::getDisplayViewFrustum() {
30173036 #ifdef DEBUG
30183037 if (QThread::currentThread() != activeRenderingThread) {
@@ -3376,7 +3395,6 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { · 357 unmodified lines
33763395 _mirrorCamera.setAspectRatio((float)region.width() / region.height());
33773396
33783397 _mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));
3379− _mirrorCamera.update(1.0f/_fps);
33803398
33813399 // set the bounds of rear mirror view
33823400 if (billboard) {
@@ -3402,7 +3420,7 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { · 19 unmodified lines
34023420 glPopMatrix();
34033421
34043422 if (!billboard) {
3405− _rearMirrorTools->render(false);
3423+ _rearMirrorTools->render(false, _glWidget->mapFromGlobal(QCursor::pos()));
34063424 }
34073425
34083426 // reset Viewport and projection matrix
@@ -4283,7 +4301,7 @@ void Application::takeSnapshot() { · 874 unmodified lines
42834301 player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath()));
42844302 player->play();
42854303
4286− QString fileName = Snapshot::saveSnapshot();
4304+ QString fileName = Snapshot::saveSnapshot(_glWidget->grabFrameBuffer());
42874305
42884306 AccountManager& accountManager = AccountManager::getInstance();
42894307 if (!accountManager.isLoggedIn()) {
@@ -4471,3 +4489,52 @@ void Application::friendsWindowClosed() { · 181 unmodified lines
44714489 void Application::postLambdaEvent(std::function<void()> f) {
44724490 QCoreApplication::postEvent(this, new LambdaEvent(f));
44734491 }
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+}