Showing the changes to interface/src/Application.cpp (1 of 1 file). Show all
Unified · Split
| @@ -173,6 +173,22 @@ public: · 172 unmodified lines | |||
| 173 | }; | 173 | }; |
| 174 | 174 | ||
| 175 | 175 | ||
| 176 | template <typename F> | ||
| 177 | void with_stable_stack_check(F f) { | ||
| 178 | GLint mvDepth, prDepth; | ||
| 179 | glGetIntegerv(GL_MODELVIEW_STACK_DEPTH, &mvDepth); | ||
| 180 | glGetIntegerv(GL_PROJECTION_STACK_DEPTH, &prDepth); | ||
| 181 | f(); | ||
| 182 | GLint mvDepthFinal, prDepthFinal; | ||
| 183 | glGetIntegerv(GL_MODELVIEW_STACK_DEPTH, &mvDepthFinal); | ||
| 184 | glGetIntegerv(GL_PROJECTION_STACK_DEPTH, &prDepthFinal); | ||
| 185 | Q_ASSERT(mvDepth == mvDepthFinal); | ||
| 186 | Q_ASSERT(prDepth == prDepthFinal); | ||
| 187 | if (mvDepth != mvDepthFinal || prDepth != prDepthFinal) { | ||
| 188 | qFatal("Failed to preserve GL stack depth"); | ||
| 189 | } | ||
| 190 | } | ||
| 191 | |||
| 176 | using namespace std; | 192 | using namespace std; |
| 177 | 193 | ||
| 178 | // Starfield information | 194 | // Starfield information |
| @@ -839,14 +855,12 @@ void Application::initializeUi() { · 660 unmodified lines | |||
| 839 | 855 | ||
| 840 | auto offscreenUi = DependencyManager::get<OffscreenUi>(); | 856 | auto offscreenUi = DependencyManager::get<OffscreenUi>(); |
| 841 | offscreenUi->create(_offscreenContext->getContext()); | 857 | offscreenUi->create(_offscreenContext->getContext()); |
| 842 | offscreenUi->resize(fromGlm(getActiveDisplayPlugin()->getCanvasSize())); | ||
| 843 | offscreenUi->setProxyWindow(_window->windowHandle()); | 858 | offscreenUi->setProxyWindow(_window->windowHandle()); |
| 844 | offscreenUi->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/")); | 859 | offscreenUi->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/")); |
| 845 | offscreenUi->load("Root.qml"); | 860 | offscreenUi->load("Root.qml"); |
| 846 | offscreenUi->load("RootMenu.qml"); | 861 | offscreenUi->load("RootMenu.qml"); |
| 847 | VrMenu::load(); | 862 | VrMenu::load(); |
| 848 | VrMenu::executeQueuedLambdas(); | 863 | VrMenu::executeQueuedLambdas(); |
| 849 | offscreenUi->setMouseTranslator(getActiveDisplayPlugin()->getMouseTranslator()); | ||
| 850 | offscreenUi->resume(); | 864 | offscreenUi->resume(); |
| 851 | connect(_window, &MainWindow::windowGeometryChanged, [this](const QRect & r){ | 865 | connect(_window, &MainWindow::windowGeometryChanged, [this](const QRect & r){ |
| 852 | static qreal oldDevicePixelRatio = 0; | 866 | static qreal oldDevicePixelRatio = 0; |
| @@ -960,10 +974,11 @@ void Application::paintGL() { · 107 unmodified lines | |||
| 960 | auto finalFbo = primaryFbo; | 974 | auto finalFbo = primaryFbo; |
| 961 | glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFbo)); | 975 | glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFbo)); |
| 962 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | 976 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 963 | glPushMatrix(); | 977 | // Viewport is assigned to the size of the framebuffer |
| 978 | QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize(); | ||
| 979 | |||
| 980 | // Primary scene rendering | ||
| 964 | { | 981 | { |
| 965 | // Viewport is assigned to the size of the framebuffer | ||
| 966 | QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize(); | ||
| 967 | if (displayPlugin->isStereo()) { | 982 | if (displayPlugin->isStereo()) { |
| 968 | QRect r(QPoint(0, 0), QSize(size.width() / 2, size.height())); | 983 | QRect r(QPoint(0, 0), QSize(size.width() / 2, size.height())); |
| 969 | glEnable(GL_SCISSOR_TEST); | 984 | glEnable(GL_SCISSOR_TEST); |
| @@ -978,14 +993,11 @@ void Application::paintGL() { · 8 unmodified lines | |||
| 978 | Camera eyeCamera; | 993 | Camera eyeCamera; |
| 979 | eyeCamera.setTransform(displayPlugin->getModelview(eye, _myCamera.getTransform())); | 994 | eyeCamera.setTransform(displayPlugin->getModelview(eye, _myCamera.getTransform())); |
| 980 | eyeCamera.setProjection(displayPlugin->getProjection(eye, _myCamera.getProjection())); | 995 | eyeCamera.setProjection(displayPlugin->getProjection(eye, _myCamera.getProjection())); |
| 981 | |||
| 982 | displaySide(&renderArgs, eyeCamera); | 996 | displaySide(&renderArgs, eyeCamera); |
| 983 | |||
| 984 | if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror) && | 997 | if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror) && |
| 985 | !Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) { | 998 | !Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) { |
| 986 | renderRearViewMirror(&renderArgs, _mirrorViewRect); | 999 | renderRearViewMirror(&renderArgs, _mirrorViewRect); |
| 987 | } | 1000 | } |
| 988 | |||
| 989 | }, [&] { | 1001 | }, [&] { |
| 990 | r.moveLeft(r.width()); | 1002 | r.moveLeft(r.width()); |
| 991 | }); | 1003 | }); |
| @@ -998,8 +1010,11 @@ void Application::paintGL() { · 6 unmodified lines | |||
| 998 | renderRearViewMirror(&renderArgs, _mirrorViewRect); | 1010 | renderRearViewMirror(&renderArgs, _mirrorViewRect); |
| 999 | } | 1011 | } |
| 1000 | } | 1012 | } |
| 1001 | finalFbo = DependencyManager::get<GlowEffect>()->render(&renderArgs); | 1013 | } |
| 1002 | 1014 | ||
| 1015 | // Overlay Composition | ||
| 1016 | finalFbo = DependencyManager::get<GlowEffect>()->render(&renderArgs); | ||
| 1017 | { | ||
| 1003 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(finalFbo)); | 1018 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(finalFbo)); |
| 1004 | if (displayPlugin->isStereo()) { | 1019 | if (displayPlugin->isStereo()) { |
| 1005 | QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize(); | 1020 | QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize(); |
| @@ -1008,7 +1023,7 @@ void Application::paintGL() { · 2 unmodified lines | |||
| 1008 | for_each_eye([&](Eye eye) { | 1023 | for_each_eye([&](Eye eye) { |
| 1009 | glViewport(r.x(), r.y(), r.width(), r.height()); | 1024 | glViewport(r.x(), r.y(), r.width(), r.height()); |
| 1010 | if (displayPlugin->isHmd()) { | 1025 | if (displayPlugin->isHmd()) { |
| 1011 | _compositor.displayOverlayTexture(&renderArgs); | 1026 | _compositor.displayOverlayTextureHmd(&renderArgs, eye); |
| 1012 | } else { | 1027 | } else { |
| 1013 | _compositor.displayOverlayTexture(&renderArgs); | 1028 | _compositor.displayOverlayTexture(&renderArgs); |
| 1014 | } | 1029 | } |
| @@ -1020,7 +1035,6 @@ void Application::paintGL() { · 5 unmodified lines | |||
| 1020 | _compositor.displayOverlayTexture(&renderArgs); | 1035 | _compositor.displayOverlayTexture(&renderArgs); |
| 1021 | } | 1036 | } |
| 1022 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); | 1037 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); |
| 1023 | glFinish(); | ||
| 1024 | } | 1038 | } |
| 1025 | 1039 | ||
| 1026 | #if 0 | 1040 | #if 0 |
| @@ -1031,25 +1045,26 @@ void Application::paintGL() { · 4 unmodified lines | |||
| 1031 | renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE; | 1045 | renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE; |
| 1032 | #endif | 1046 | #endif |
| 1033 | 1047 | ||
| 1034 | // Ensure the rendering context commands are completed when rendering | 1048 | // deliver final composited scene to the display plugin |
| 1035 | GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); | 1049 | { |
| 1036 | _offscreenContext->doneCurrent(); | 1050 | GLuint finalTexture = gpu::GLBackend::getTextureID(finalFbo->getRenderBuffer(0)); |
| 1037 | Q_ASSERT(!QOpenGLContext::currentContext()); | 1051 | uvec2 finalSize = toGlm(size); |
| 1038 | 1052 | // Ensure the rendering context commands are completed when rendering | |
| 1039 | GLuint finalTexture = gpu::GLBackend::getTextureID(finalFbo->getRenderBuffer(0)); | 1053 | GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); |
| 1040 | displayPlugin->preDisplay(); | 1054 | _offscreenContext->doneCurrent(); |
| 1041 | 1055 | Q_ASSERT(!QOpenGLContext::currentContext()); | |
| 1042 | Q_ASSERT(QOpenGLContext::currentContext()); | 1056 | displayPlugin->preDisplay(); |
| 1043 | glWaitSync(sync, 0, GL_TIMEOUT_IGNORED); | 1057 | Q_ASSERT(QOpenGLContext::currentContext()); |
| 1044 | glDeleteSync(sync); | 1058 | // FIXME? make the sync a parameter to preDisplay and let the plugin manage this |
| 1045 | 1059 | glWaitSync(sync, 0, GL_TIMEOUT_IGNORED); | |
| 1046 | displayPlugin->display(finalTexture, finalFbo->getSize()); | 1060 | glDeleteSync(sync); |
| 1047 | 1061 | displayPlugin->display(finalTexture, finalSize); | |
| 1048 | displayPlugin->finishFrame(); | 1062 | displayPlugin->finishFrame(); |
| 1049 | Q_ASSERT(!QOpenGLContext::currentContext()); | 1063 | Q_ASSERT(!QOpenGLContext::currentContext()); |
| 1050 | _offscreenContext->makeCurrent(); | 1064 | _offscreenContext->makeCurrent(); |
| 1051 | _frameCount++; | 1065 | _frameCount++; |
| 1052 | Stats::getInstance()->setRenderDetails(renderArgs._details); | 1066 | Stats::getInstance()->setRenderDetails(renderArgs._details); |
| 1067 | } | ||
| 1053 | } | 1068 | } |
| 1054 | 1069 | ||
| 1055 | void Application::runTests() { | 1070 | void Application::runTests() { |
| @@ -3338,16 +3353,18 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 2282 unmodified lines | |||
| 3338 | 3353 | ||
| 3339 | // Load the legacy GL stacks, used by entities (for now) | 3354 | // Load the legacy GL stacks, used by entities (for now) |
| 3340 | glMatrixMode(GL_PROJECTION); | 3355 | glMatrixMode(GL_PROJECTION); |
| 3356 | glPushMatrix(); | ||
| 3341 | glLoadMatrixf(glm::value_ptr(theCamera.getProjection())); | 3357 | glLoadMatrixf(glm::value_ptr(theCamera.getProjection())); |
| 3342 | 3358 | ||
| 3343 | glMatrixMode(GL_MODELVIEW); | 3359 | glMatrixMode(GL_MODELVIEW); |
| 3360 | glPushMatrix(); | ||
| 3344 | glLoadMatrixf(glm::value_ptr(glm::inverse(theCamera.getTransform()))); | 3361 | glLoadMatrixf(glm::value_ptr(glm::inverse(theCamera.getTransform()))); |
| 3345 | 3362 | ||
| 3346 | // FIXME just flip the texture coordinates | 3363 | // FIXME just flip the texture coordinates |
| 3347 | // flip x if in mirror mode (also requires reversing winding order for backface culling) | 3364 | // flip x if in mirror mode (also requires reversing winding order for backface culling) |
| 3348 | if (theCamera.getMode() == CAMERA_MODE_MIRROR) { | 3365 | if (theCamera.getMode() == CAMERA_MODE_MIRROR) { |
| 3349 | //glScalef(-1.0f, 1.0f, 1.0f); | 3366 | glScalef(-1.0f, 1.0f, 1.0f); |
| 3350 | //glFrontFace(GL_CW); | 3367 | glFrontFace(GL_CW); |
| 3351 | } else { | 3368 | } else { |
| 3352 | glFrontFace(GL_CCW); | 3369 | glFrontFace(GL_CCW); |
| 3353 | } | 3370 | } |
| @@ -3360,7 +3377,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 6 unmodified lines | |||
| 3360 | viewTransform.setTranslation(theCamera.getPosition()); | 3377 | viewTransform.setTranslation(theCamera.getPosition()); |
| 3361 | viewTransform.setRotation(rotation); | 3378 | viewTransform.setRotation(rotation); |
| 3362 | if (theCamera.getMode() == CAMERA_MODE_MIRROR) { | 3379 | if (theCamera.getMode() == CAMERA_MODE_MIRROR) { |
| 3363 | // viewTransform.setScale(Transform::Vec3(-1.0f, 1.0f, 1.0f)); | 3380 | viewTransform.setScale(Transform::Vec3(-1.0f, 1.0f, 1.0f)); |
| 3364 | } | 3381 | } |
| 3365 | 3382 | ||
| 3366 | setViewTransform(viewTransform); | 3383 | setViewTransform(viewTransform); |
| @@ -3524,6 +3541,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 157 unmodified lines | |||
| 3524 | PerformanceTimer perfTimer("octreeFades"); | 3541 | PerformanceTimer perfTimer("octreeFades"); |
| 3525 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | 3542 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), |
| 3526 | "Application::displaySide() ... octree fades..."); | 3543 | "Application::displaySide() ... octree fades..."); |
| 3544 | |||
| 3527 | _octreeFadesLock.lockForWrite(); | 3545 | _octreeFadesLock.lockForWrite(); |
| 3528 | for(std::vector<OctreeFade>::iterator fade = _octreeFades.begin(); fade != _octreeFades.end();) { | 3546 | for(std::vector<OctreeFade>::iterator fade = _octreeFades.begin(); fade != _octreeFades.end();) { |
| 3529 | fade->render(renderArgs); | 3547 | fade->render(renderArgs); |
| @@ -3547,6 +3565,12 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 17 unmodified lines | |||
| 3547 | glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | 3565 | glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); |
| 3548 | } | 3566 | } |
| 3549 | 3567 | ||
| 3568 | glMatrixMode(GL_PROJECTION); | ||
| 3569 | glPopMatrix(); | ||
| 3570 | glLoadMatrixf(glm::value_ptr(theCamera.getProjection())); | ||
| 3571 | |||
| 3572 | glMatrixMode(GL_MODELVIEW); | ||
| 3573 | glPopMatrix(); | ||
| 3550 | activeRenderingThread = nullptr; | 3574 | activeRenderingThread = nullptr; |
| 3551 | } | 3575 | } |
| 3552 | 3576 | ||
| @@ -4755,7 +4779,10 @@ const DisplayPlugin * Application::getActiveDisplayPlugin() const { · 1202 unmodified lines | |||
| 4755 | 4779 | ||
| 4756 | void Application::updateDisplayMode() { | 4780 | void Application::updateDisplayMode() { |
| 4757 | auto menu = Menu::getInstance(); | 4781 | auto menu = Menu::getInstance(); |
| 4758 | DisplayPluginPointer newDisplayPlugin; | 4782 | auto displayPlugins = getDisplayPlugins(); |
| 4783 | |||
| 4784 | // Default to the first item on the list, in case none of the menu items match | ||
| 4785 | DisplayPluginPointer newDisplayPlugin = displayPlugins.at(0); | ||
| 4759 | foreach(DisplayPluginPointer displayPlugin, getDisplayPlugins()) { | 4786 | foreach(DisplayPluginPointer displayPlugin, getDisplayPlugins()) { |
| 4760 | QString name = displayPlugin->getName(); | 4787 | QString name = displayPlugin->getName(); |
| 4761 | QAction* action = menu->getActionForOption(name); | 4788 | QAction* action = menu->getActionForOption(name); |
| @@ -4764,30 +4791,40 @@ void Application::updateDisplayMode() { · 2 unmodified lines | |||
| 4764 | break; | 4791 | break; |
| 4765 | } | 4792 | } |
| 4766 | } | 4793 | } |
| 4767 | if (_displayPlugin != newDisplayPlugin) { | 4794 | |
| 4768 | DependencyManager::get<OffscreenUi>()->setProxyWindow(nullptr); | 4795 | auto offscreenUi = DependencyManager::get<OffscreenUi>(); |
| 4796 | DisplayPluginPointer oldDisplayPlugin = _displayPlugin; | ||
| 4797 | if (oldDisplayPlugin != newDisplayPlugin) { | ||
| 4798 | if (oldDisplayPlugin) { | ||
| 4799 | oldDisplayPlugin->removeEventFilter(offscreenUi.data()); | ||
| 4800 | oldDisplayPlugin->removeEventFilter(qApp); | ||
| 4801 | } | ||
| 4769 | 4802 | ||
| 4770 | if (newDisplayPlugin) { | 4803 | if (newDisplayPlugin) { |
| 4771 | _offscreenContext->makeCurrent(); | 4804 | _offscreenContext->makeCurrent(); |
| 4772 | newDisplayPlugin->activate(this); | 4805 | newDisplayPlugin->activate(this); |
| 4773 | newDisplayPlugin->installEventFilter(DependencyManager::get<OffscreenUi>().data()); | 4806 | |
| 4807 | _offscreenContext->makeCurrent(); | ||
| 4808 | newDisplayPlugin->installEventFilter(offscreenUi.data()); | ||
| 4774 | newDisplayPlugin->installEventFilter(qApp); | 4809 | newDisplayPlugin->installEventFilter(qApp); |
| 4775 | QWindow* pluginWindow = newDisplayPlugin->getWindow(); | 4810 | QWindow* pluginWindow = newDisplayPlugin->getWindow(); |
| 4776 | if (pluginWindow) { | 4811 | if (pluginWindow) { |
| 4777 | DependencyManager::get<OffscreenUi>()->setProxyWindow(pluginWindow); | 4812 | DependencyManager::get<OffscreenUi>()->setProxyWindow(pluginWindow); |
| 4778 | } | 4813 | } else { |
| 4814 | DependencyManager::get<OffscreenUi>()->setProxyWindow(nullptr); | ||
| 4815 | } | ||
| 4816 | offscreenUi->setMouseTranslator(newDisplayPlugin->getMouseTranslator()); | ||
| 4817 | offscreenUi->resize(fromGlm(newDisplayPlugin->getCanvasSize())); | ||
| 4779 | _offscreenContext->makeCurrent(); | 4818 | _offscreenContext->makeCurrent(); |
| 4780 | } | 4819 | } |
| 4781 | 4820 | ||
| 4782 | std::swap(newDisplayPlugin, _displayPlugin); | 4821 | oldDisplayPlugin = _displayPlugin; |
| 4783 | if (newDisplayPlugin) { | 4822 | _displayPlugin = newDisplayPlugin; |
| 4784 | newDisplayPlugin->removeEventFilter(DependencyManager::get<OffscreenUi>().data()); | 4823 | |
| 4785 | newDisplayPlugin->deactivate(); | 4824 | if (oldDisplayPlugin) { |
| 4825 | oldDisplayPlugin->deactivate(); | ||
| 4786 | _offscreenContext->makeCurrent(); | 4826 | _offscreenContext->makeCurrent(); |
| 4787 | } | 4827 | } |
| 4788 | |||
| 4789 | auto offscreenUi = DependencyManager::get<OffscreenUi>(); | ||
| 4790 | offscreenUi->setMouseTranslator(getActiveDisplayPlugin()->getMouseTranslator()); | ||
| 4791 | } | 4828 | } |
| 4792 | Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin"); | 4829 | Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin"); |
| 4793 | } | 4830 | } |