Showing the changes to interface/src/Application.cpp (1 of 28 files). Show all
Unified · Split
| @@ -9,11 +9,9 @@ · 8 unmodified lines | ||
| 9 | 9 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html |
| 10 | 10 | // |
| 11 | 11 | |
| 12 | −#include <sstream> | |
| 12 | +#include "Application.h" | |
| 13 | 13 | |
| 14 | −#include <stdlib.h> | |
| 15 | −#include <cmath> | |
| 16 | −#include <math.h> | |
| 14 | +#include <sstream> | |
| 17 | 15 | |
| 18 | 16 | #include <glm/glm.hpp> |
| 19 | 17 | #include <glm/gtx/component_wise.hpp> |
| @@ -63,6 +61,7 @@ · 43 unmodified lines | ||
| 63 | 61 | |
| 64 | 62 | #include <EntityScriptingInterface.h> |
| 65 | 63 | #include <ErrorDialog.h> |
| 64 | +#include <FramebufferCache.h> | |
| 66 | 65 | #include <GlWindow.h> |
| 67 | 66 | #include <gpu/Batch.h> |
| 68 | 67 | #include <gpu/Context.h> |
| @@ -92,13 +91,13 @@ · 23 unmodified lines | ||
| 92 | 91 | #include <SettingHandle.h> |
| 93 | 92 | #include <SimpleAverage.h> |
| 94 | 93 | #include <SoundCache.h> |
| 94 | +#include <TextureCache.h> | |
| 95 | 95 | #include <Tooltip.h> |
| 96 | 96 | #include <UserActivityLogger.h> |
| 97 | 97 | #include <UUID.h> |
| 98 | 98 | #include <input-plugins/UserInputMapper.h> |
| 99 | 99 | #include <VrMenu.h> |
| 100 | 100 | |
| 101 | −#include "Application.h" | |
| 102 | 101 | #include "AudioClient.h" |
| 103 | 102 | #include "DiscoverabilityManager.h" |
| 104 | 103 | #include "InterfaceVersion.h" |
| @@ -268,6 +267,8 @@ bool setupEssentials(int& argc, char** argv) { · 163 unmodified lines | ||
| 268 | 267 | auto audioScope = DependencyManager::set<AudioScope>(); |
| 269 | 268 | auto deferredLightingEffect = DependencyManager::set<DeferredLightingEffect>(); |
| 270 | 269 | auto textureCache = DependencyManager::set<TextureCache>(); |
| 270 | + auto framebufferCache = DependencyManager::set<FramebufferCache>(); | |
| 271 | + | |
| 271 | 272 | auto animationCache = DependencyManager::set<AnimationCache>(); |
| 272 | 273 | auto ddeFaceTracker = DependencyManager::set<DdeFaceTracker>(); |
| 273 | 274 | auto modelBlender = DependencyManager::set<ModelBlender>(); |
| @@ -771,6 +772,7 @@ Application::~Application() { · 497 unmodified lines | ||
| 771 | 772 | DependencyManager::destroy<OffscreenUi>(); |
| 772 | 773 | DependencyManager::destroy<AvatarManager>(); |
| 773 | 774 | DependencyManager::destroy<AnimationCache>(); |
| 775 | + DependencyManager::destroy<FramebufferCache>(); | |
| 774 | 776 | DependencyManager::destroy<TextureCache>(); |
| 775 | 777 | DependencyManager::destroy<GeometryCache>(); |
| 776 | 778 | DependencyManager::destroy<ScriptCache>(); |
| @@ -804,33 +806,8 @@ void Application::initializeGL() { · 27 unmodified lines | ||
| 804 | 806 | } |
| 805 | 807 | #endif |
| 806 | 808 | |
| 807 | − #ifdef WIN32 | |
| 808 | − GLenum err = glewInit(); | |
| 809 | − if (GLEW_OK != err) { | |
| 810 | − /* Problem: glewInit failed, something is seriously wrong. */ | |
| 811 | − qCDebug(interfaceapp, "Error: %s\n", glewGetErrorString(err)); | |
| 812 | − } | |
| 813 | − qCDebug(interfaceapp, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); | |
| 814 | − | |
| 815 | − if (wglewGetExtension("WGL_EXT_swap_control")) { | |
| 816 | − int swapInterval = wglGetSwapIntervalEXT(); | |
| 817 | − qCDebug(interfaceapp, "V-Sync is %s\n", (swapInterval > 0 ? "ON" : "OFF")); | |
| 818 | − } | |
| 819 | − #endif | |
| 820 | − | |
| 821 | − | |
| 822 | − qCDebug(interfaceapp) << "GL Version: " << QString((const char*) glGetString(GL_VERSION)); | |
| 823 | − qCDebug(interfaceapp) << "GL Shader Language Version: " << QString((const char*) glGetString(GL_SHADING_LANGUAGE_VERSION)); | |
| 824 | − qCDebug(interfaceapp) << "GL Vendor: " << QString((const char*) glGetString(GL_VENDOR)); | |
| 825 | − qCDebug(interfaceapp) << "GL Renderer: " << QString((const char*) glGetString(GL_RENDERER)); | |
| 826 | − | |
| 827 | −#if defined(Q_OS_LINUX) | |
| 828 | − // TODO: Write the correct code for Linux... | |
| 829 | − /* if (wglewGetExtension("WGL_EXT_swap_control")) { | |
| 830 | − int swapInterval = wglGetSwapIntervalEXT(); | |
| 831 | − qCDebug(interfaceapp, "V-Sync is %s\n", (swapInterval > 0 ? "ON" : "OFF")); | |
| 832 | − }*/ | |
| 833 | −#endif | |
| 809 | + // Where the gpuContext is created and where the TRUE Backend is created and assigned | |
| 810 | + _gpuContext = std::make_shared<gpu::Context>(new gpu::GLBackend()); | |
| 834 | 811 | |
| 835 | 812 | initDisplay(); |
| 836 | 813 | qCDebug(interfaceapp, "Initialized Display."); |
| @@ -929,8 +906,9 @@ void Application::paintGL() { · 92 unmodified lines | ||
| 929 | 906 | _offscreenContext->makeCurrent(); |
| 930 | 907 | |
| 931 | 908 | auto lodManager = DependencyManager::get<LODManager>(); |
| 932 | − gpu::Context context(new gpu::GLBackend()); | |
| 933 | − RenderArgs renderArgs(&context, nullptr, getViewFrustum(), lodManager->getOctreeSizeScale(), | |
| 909 | + | |
| 910 | + | |
| 911 | + RenderArgs renderArgs(_gpuContext, nullptr, getViewFrustum(), lodManager->getOctreeSizeScale(), | |
| 934 | 912 | lodManager->getBoundaryLevelAdjust(), RenderArgs::DEFAULT_RENDER_MODE, |
| 935 | 913 | RenderArgs::MONO, RenderArgs::RENDER_DEBUG_NONE); |
| 936 | 914 | |
| @@ -942,17 +920,16 @@ void Application::paintGL() { · 5 unmodified lines | ||
| 942 | 920 | PerformanceWarning warn(showWarnings, "Application::paintGL()"); |
| 943 | 921 | resizeGL(); |
| 944 | 922 | |
| 923 | + | |
| 945 | 924 | { |
| 946 | 925 | PerformanceTimer perfTimer("renderOverlay"); |
| 947 | 926 | // NOTE: There is no batch associated with this renderArgs |
| 948 | 927 | // the ApplicationOverlay class assumes it's viewport is setup to be the device size |
| 949 | 928 | QSize size = qApp->getDeviceSize(); |
| 950 | − renderArgs._viewport = glm::ivec4(0, 0, size.width(), size.height()); | |
| 929 | + renderArgs._viewport = glm::ivec4(0, 0, size.width(), size.height()); | |
| 951 | 930 | _applicationOverlay.renderOverlay(&renderArgs); |
| 952 | 931 | } |
| 953 | 932 | |
| 954 | − glEnable(GL_LINE_SMOOTH); | |
| 955 | − | |
| 956 | 933 | if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON || _myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) { |
| 957 | 934 | Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, _myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN); |
| 958 | 935 | Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, !(_myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN)); |
| @@ -1000,8 +977,7 @@ void Application::paintGL() { · 41 unmodified lines | ||
| 1000 | 977 | } |
| 1001 | 978 | |
| 1002 | 979 | // Sync up the View Furstum with the camera |
| 1003 | − // FIXME: it's happening again in the updateSHadow and it shouldn't, this should be the place | |
| 1004 | − _myCamera.loadViewFrustum(_viewFrustum); | |
| 980 | + loadViewFrustum(_myCamera, _viewFrustum); | |
| 1005 | 981 | |
| 1006 | 982 | |
| 1007 | 983 | renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE; |
| @@ -1015,19 +991,15 @@ void Application::paintGL() { · 7 unmodified lines | ||
| 1015 | 991 | { |
| 1016 | 992 | PROFILE_RANGE(__FUNCTION__ "/clear"); |
| 1017 | 993 | doInBatch(&renderArgs, [&](gpu::Batch& batch) { |
| 1018 | − batch.setFramebuffer(textureCache->getPrimaryFramebuffer()); | |
| 994 | + auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer(); | |
| 995 | + batch.setFramebuffer(primaryFbo); | |
| 1019 | 996 | // clear the normal and specular buffers |
| 1020 | 997 | batch.clearFramebuffer( |
| 1021 | 998 | gpu::Framebuffer::BUFFER_COLOR0 | |
| 1022 | 999 | gpu::Framebuffer::BUFFER_COLOR1 | |
| 1023 | 1000 | gpu::Framebuffer::BUFFER_COLOR2 | |
| 1024 | 1001 | gpu::Framebuffer::BUFFER_DEPTH, |
| 1025 | − vec4(vec3(0), 1), 1.0, 0.0, true); | |
| 1026 | − batch.clearColorFramebuffer( | |
| 1027 | − gpu::Framebuffer::BUFFER_COLOR0 | | |
| 1028 | − gpu::Framebuffer::BUFFER_COLOR1 | | |
| 1029 | − gpu::Framebuffer::BUFFER_COLOR2, | |
| 1030 | − vec4(vec3(0), 1)); | |
| 1002 | + vec4(vec3(0), 1), 1.0, 0.0); | |
| 1031 | 1003 | }); |
| 1032 | 1004 | } |
| 1033 | 1005 | |
| @@ -1048,7 +1020,9 @@ void Application::paintGL() { · 14 unmodified lines | ||
| 1048 | 1020 | displaySide(&renderArgs, eyeCamera); |
| 1049 | 1021 | if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror) && |
| 1050 | 1022 | !Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) { |
| 1023 | + renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE; | |
| 1051 | 1024 | renderRearViewMirror(&renderArgs, _mirrorViewRect); |
| 1025 | + renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE; | |
| 1052 | 1026 | } |
| 1053 | 1027 | }, [&] { |
| 1054 | 1028 | r.moveLeft(r.width()); |
| @@ -1065,7 +1039,9 @@ void Application::paintGL() { · 10 unmodified lines | ||
| 1065 | 1039 | displaySide(&renderArgs, _myCamera); |
| 1066 | 1040 | if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror) && |
| 1067 | 1041 | !Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) { |
| 1042 | + renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE; | |
| 1068 | 1043 | renderRearViewMirror(&renderArgs, _mirrorViewRect); |
| 1044 | + renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE; | |
| 1069 | 1045 | } |
| 1070 | 1046 | } |
| 1071 | 1047 | } |
| @@ -1107,8 +1083,10 @@ void Application::paintGL() { · 35 unmodified lines | ||
| 1107 | 1083 | GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); |
| 1108 | 1084 | #endif |
| 1109 | 1085 | _offscreenContext->doneCurrent(); |
| 1086 | + // Switches to the display plugin context | |
| 1110 | 1087 | displayPlugin->preDisplay(); |
| 1111 | 1088 | |
| 1089 | + // Ensure all operations from the previous context are complete before we try to read the fbo | |
| 1112 | 1090 | #ifdef Q_OS_MAC |
| 1113 | 1091 | #else |
| 1114 | 1092 | // FIXME? make the sync a parameter to preDisplay and let the plugin manage this |
| @@ -1954,6 +1932,13 @@ void Application::idle() { · 839 unmodified lines | ||
| 1954 | 1932 | } |
| 1955 | 1933 | double timeSinceLastUpdate = (double)_lastTimeUpdated.nsecsElapsed() / 1000000.0; |
| 1956 | 1934 | if (timeSinceLastUpdate > targetFramePeriod) { |
| 1935 | + | |
| 1936 | + { | |
| 1937 | + static const int IDLE_EVENT_PROCESS_MAX_TIME_MS = 2; | |
| 1938 | + PerformanceTimer perfTimer("processEvents"); | |
| 1939 | + processEvents(QEventLoop::AllEvents, IDLE_EVENT_PROCESS_MAX_TIME_MS); | |
| 1940 | + } | |
| 1941 | + | |
| 1957 | 1942 | _lastTimeUpdated.start(); |
| 1958 | 1943 | { |
| 1959 | 1944 | PerformanceTimer perfTimer("update"); |
| @@ -1986,12 +1971,19 @@ void Application::idle() { · 26 unmodified lines | ||
| 1986 | 1971 | _idleLoopMeasuredJitter = _idleLoopStdev.getStDev(); |
| 1987 | 1972 | _idleLoopStdev.reset(); |
| 1988 | 1973 | } |
| 1989 | − | |
| 1990 | 1974 | } |
| 1991 | − // After finishing all of the above work, ensure the idle timer is set to the proper interval, | |
| 1992 | − // depending on whether we're throttling or not | |
| 1993 | − idleTimer->start(getActiveDisplayPlugin()->isThrottled() ? THROTTLED_IDLE_TIMER_DELAY : 0); | |
| 1994 | − } | |
| 1975 | + | |
| 1976 | + // depending on whether we're throttling or not. | |
| 1977 | + // Once rendering is off on another thread we should be able to have Application::idle run at start(0) in | |
| 1978 | + // perpetuity and not expect events to get backed up. | |
| 1979 | + | |
| 1980 | + static const int IDLE_TIMER_DELAY_MS = 0; | |
| 1981 | + int desiredInterval = _glWidget->isThrottleRendering() ? THROTTLED_IDLE_TIMER_DELAY : IDLE_TIMER_DELAY_MS; | |
| 1982 | + | |
| 1983 | + if (idleTimer->interval() != desiredInterval) { | |
| 1984 | + idleTimer->start(desiredInterval); | |
| 1985 | + } | |
| 1986 | + } | |
| 1995 | 1987 | |
| 1996 | 1988 | // check for any requested background downloads. |
| 1997 | 1989 | emit checkBackgroundDownloads(); |
| @@ -3207,7 +3199,7 @@ PickRay Application::computePickRay(float x, float y) const { · 1209 unmodified lines | ||
| 3207 | 3199 | } |
| 3208 | 3200 | |
| 3209 | 3201 | QImage Application::renderAvatarBillboard(RenderArgs* renderArgs) { |
| 3210 | − auto primaryFramebuffer = DependencyManager::get<TextureCache>()->getPrimaryFramebuffer(); | |
| 3202 | + auto primaryFramebuffer = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer(); | |
| 3211 | 3203 | glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFramebuffer)); |
| 3212 | 3204 | |
| 3213 | 3205 | // clear the alpha channel so the background is transparent |
| @@ -3400,10 +3392,6 @@ namespace render { · 186 unmodified lines | ||
| 3400 | 3392 | model::Skybox::render(batch, *(Application::getInstance()->getDisplayViewFrustum()), *skybox); |
| 3401 | 3393 | } |
| 3402 | 3394 | } |
| 3403 | − // FIX ME - If I don't call this renderBatch() here, then the atmosphere and skybox don't render, but it | |
| 3404 | − // seems like these payloadRender() methods shouldn't be doing this. We need to investigate why the engine | |
| 3405 | − // isn't rendering our batch | |
| 3406 | − gpu::GLBackend::renderBatch(batch, true); | |
| 3407 | 3395 | } |
| 3408 | 3396 | } |
| 3409 | 3397 | |
| @@ -3605,11 +3593,11 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi · 195 unmodified lines | ||
| 3605 | 3593 | // set the bounds of rear mirror view |
| 3606 | 3594 | gpu::Vec4i viewport; |
| 3607 | 3595 | if (billboard) { |
| 3608 | − QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize(); | |
| 3596 | + QSize size = DependencyManager::get<FramebufferCache>()->getFrameBufferSize(); | |
| 3609 | 3597 | viewport = gpu::Vec4i(region.x(), size.height() - region.y() - region.height(), region.width(), region.height()); |
| 3610 | 3598 | } else { |
| 3611 | 3599 | // if not rendering the billboard, the region is in device independent coordinates; must convert to device |
| 3612 | − QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize(); | |
| 3600 | + QSize size = DependencyManager::get<FramebufferCache>()->getFrameBufferSize(); | |
| 3613 | 3601 | float ratio = (float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale(); |
| 3614 | 3602 | int x = region.x() * ratio, y = region.y() * ratio, width = region.width() * ratio, height = region.height() * ratio; |
| 3615 | 3603 | viewport = gpu::Vec4i(x, size.height() - y - height, width, height); |