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