History

Merge branch 'master' into plugins

Bradley Austin Davis committed 11 years ago

Commit 1db41622 parents b636cd9 e729a8728 files · +446 −361Browse files

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

Unified · Split

interface/src/Application.cpp+46−58
@@ -9,11 +9,9 @@ · 8 unmodified lines
9// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html9// 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>14#include <sstream>
15#include <cmath>
16#include <math.h>
17 15
18#include <glm/glm.hpp>16#include <glm/glm.hpp>
19#include <glm/gtx/component_wise.hpp>17#include <glm/gtx/component_wise.hpp>
@@ -63,6 +61,7 @@ · 43 unmodified lines
63 61
64#include <EntityScriptingInterface.h>62#include <EntityScriptingInterface.h>
65#include <ErrorDialog.h>63#include <ErrorDialog.h>
64#include <FramebufferCache.h>
66#include <GlWindow.h>65#include <GlWindow.h>
67#include <gpu/Batch.h>66#include <gpu/Batch.h>
68#include <gpu/Context.h>67#include <gpu/Context.h>
@@ -92,13 +91,13 @@ · 23 unmodified lines
92#include <SettingHandle.h>91#include <SettingHandle.h>
93#include <SimpleAverage.h>92#include <SimpleAverage.h>
94#include <SoundCache.h>93#include <SoundCache.h>
94#include <TextureCache.h>
95#include <Tooltip.h>95#include <Tooltip.h>
96#include <UserActivityLogger.h>96#include <UserActivityLogger.h>
97#include <UUID.h>97#include <UUID.h>
98#include <input-plugins/UserInputMapper.h>98#include <input-plugins/UserInputMapper.h>
99#include <VrMenu.h>99#include <VrMenu.h>
100 100
101#include "Application.h"
102#include "AudioClient.h"101#include "AudioClient.h"
103#include "DiscoverabilityManager.h"102#include "DiscoverabilityManager.h"
104#include "InterfaceVersion.h"103#include "InterfaceVersion.h"
@@ -268,6 +267,8 @@ bool setupEssentials(int& argc, char** argv) { · 163 unmodified lines
268 auto audioScope = DependencyManager::set<AudioScope>();267 auto audioScope = DependencyManager::set<AudioScope>();
269 auto deferredLightingEffect = DependencyManager::set<DeferredLightingEffect>();268 auto deferredLightingEffect = DependencyManager::set<DeferredLightingEffect>();
270 auto textureCache = DependencyManager::set<TextureCache>();269 auto textureCache = DependencyManager::set<TextureCache>();
270 auto framebufferCache = DependencyManager::set<FramebufferCache>();
271
271 auto animationCache = DependencyManager::set<AnimationCache>();272 auto animationCache = DependencyManager::set<AnimationCache>();
272 auto ddeFaceTracker = DependencyManager::set<DdeFaceTracker>();273 auto ddeFaceTracker = DependencyManager::set<DdeFaceTracker>();
273 auto modelBlender = DependencyManager::set<ModelBlender>();274 auto modelBlender = DependencyManager::set<ModelBlender>();
@@ -771,6 +772,7 @@ Application::~Application() { · 497 unmodified lines
771 DependencyManager::destroy<OffscreenUi>();772 DependencyManager::destroy<OffscreenUi>();
772 DependencyManager::destroy<AvatarManager>();773 DependencyManager::destroy<AvatarManager>();
773 DependencyManager::destroy<AnimationCache>();774 DependencyManager::destroy<AnimationCache>();
775 DependencyManager::destroy<FramebufferCache>();
774 DependencyManager::destroy<TextureCache>();776 DependencyManager::destroy<TextureCache>();
775 DependencyManager::destroy<GeometryCache>();777 DependencyManager::destroy<GeometryCache>();
776 DependencyManager::destroy<ScriptCache>();778 DependencyManager::destroy<ScriptCache>();
@@ -804,33 +806,8 @@ void Application::initializeGL() { · 27 unmodified lines
804 }806 }
805 #endif807 #endif
806 808
807 #ifdef WIN32809 // Where the gpuContext is created and where the TRUE Backend is created and assigned
808 GLenum err = glewInit();810 _gpuContext = std::make_shared<gpu::Context>(new gpu::GLBackend());
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
834 811
835 initDisplay();812 initDisplay();
836 qCDebug(interfaceapp, "Initialized Display.");813 qCDebug(interfaceapp, "Initialized Display.");
@@ -929,8 +906,9 @@ void Application::paintGL() { · 92 unmodified lines
929 _offscreenContext->makeCurrent();906 _offscreenContext->makeCurrent();
930 907
931 auto lodManager = DependencyManager::get<LODManager>();908 auto lodManager = DependencyManager::get<LODManager>();
932 gpu::Context context(new gpu::GLBackend());909
933 RenderArgs renderArgs(&context, nullptr, getViewFrustum(), lodManager->getOctreeSizeScale(),910
911 RenderArgs renderArgs(_gpuContext, nullptr, getViewFrustum(), lodManager->getOctreeSizeScale(),
934 lodManager->getBoundaryLevelAdjust(), RenderArgs::DEFAULT_RENDER_MODE,912 lodManager->getBoundaryLevelAdjust(), RenderArgs::DEFAULT_RENDER_MODE,
935 RenderArgs::MONO, RenderArgs::RENDER_DEBUG_NONE);913 RenderArgs::MONO, RenderArgs::RENDER_DEBUG_NONE);
936 914
@@ -942,17 +920,16 @@ void Application::paintGL() { · 5 unmodified lines
942 PerformanceWarning warn(showWarnings, "Application::paintGL()");920 PerformanceWarning warn(showWarnings, "Application::paintGL()");
943 resizeGL();921 resizeGL();
944 922
923
945 {924 {
946 PerformanceTimer perfTimer("renderOverlay");925 PerformanceTimer perfTimer("renderOverlay");
947 // NOTE: There is no batch associated with this renderArgs926 // NOTE: There is no batch associated with this renderArgs
948 // the ApplicationOverlay class assumes it's viewport is setup to be the device size927 // the ApplicationOverlay class assumes it's viewport is setup to be the device size
949 QSize size = qApp->getDeviceSize();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 _applicationOverlay.renderOverlay(&renderArgs);930 _applicationOverlay.renderOverlay(&renderArgs);
952 }931 }
953 932
954 glEnable(GL_LINE_SMOOTH);
955
956 if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON || _myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {933 if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON || _myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
957 Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, _myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN);934 Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, _myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN);
958 Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, !(_myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN));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 // Sync up the View Furstum with the camera979 // 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 place980 loadViewFrustum(_myCamera, _viewFrustum);
1004 _myCamera.loadViewFrustum(_viewFrustum);
1005 981
1006 982
1007 renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE;983 renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE;
@@ -1015,19 +991,15 @@ void Application::paintGL() { · 7 unmodified lines
1015 {991 {
1016 PROFILE_RANGE(__FUNCTION__ "/clear");992 PROFILE_RANGE(__FUNCTION__ "/clear");
1017 doInBatch(&renderArgs, [&](gpu::Batch& batch) {993 doInBatch(&renderArgs, [&](gpu::Batch& batch) {
1018 batch.setFramebuffer(textureCache->getPrimaryFramebuffer());994 auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
995 batch.setFramebuffer(primaryFbo);
1019 // clear the normal and specular buffers996 // clear the normal and specular buffers
1020 batch.clearFramebuffer(997 batch.clearFramebuffer(
1021 gpu::Framebuffer::BUFFER_COLOR0 |998 gpu::Framebuffer::BUFFER_COLOR0 |
1022 gpu::Framebuffer::BUFFER_COLOR1 |999 gpu::Framebuffer::BUFFER_COLOR1 |
1023 gpu::Framebuffer::BUFFER_COLOR2 |1000 gpu::Framebuffer::BUFFER_COLOR2 |
1024 gpu::Framebuffer::BUFFER_DEPTH,1001 gpu::Framebuffer::BUFFER_DEPTH,
1025 vec4(vec3(0), 1), 1.0, 0.0, true);1002 vec4(vec3(0), 1), 1.0, 0.0);
1026 batch.clearColorFramebuffer(
1027 gpu::Framebuffer::BUFFER_COLOR0 |
1028 gpu::Framebuffer::BUFFER_COLOR1 |
1029 gpu::Framebuffer::BUFFER_COLOR2,
1030 vec4(vec3(0), 1));
1031 });1003 });
1032 }1004 }
1033 1005
@@ -1048,7 +1020,9 @@ void Application::paintGL() { · 14 unmodified lines
1048 displaySide(&renderArgs, eyeCamera);1020 displaySide(&renderArgs, eyeCamera);
1049 if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror) && 1021 if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror) &&
1050 !Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) {1022 !Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) {
1023 renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
1051 renderRearViewMirror(&renderArgs, _mirrorViewRect);1024 renderRearViewMirror(&renderArgs, _mirrorViewRect);
1025 renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE;
1052 }1026 }
1053 }, [&] {1027 }, [&] {
1054 r.moveLeft(r.width());1028 r.moveLeft(r.width());
@@ -1065,7 +1039,9 @@ void Application::paintGL() { · 10 unmodified lines
1065 displaySide(&renderArgs, _myCamera);1039 displaySide(&renderArgs, _myCamera);
1066 if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror) && 1040 if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror) &&
1067 !Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) {1041 !Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) {
1042 renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
1068 renderRearViewMirror(&renderArgs, _mirrorViewRect);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 GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);1083 GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
1108#endif1084#endif
1109 _offscreenContext->doneCurrent();1085 _offscreenContext->doneCurrent();
1086 // Switches to the display plugin context
1110 displayPlugin->preDisplay();1087 displayPlugin->preDisplay();
1111 1088
1089 // Ensure all operations from the previous context are complete before we try to read the fbo
1112#ifdef Q_OS_MAC1090#ifdef Q_OS_MAC
1113#else1091#else
1114 // FIXME? make the sync a parameter to preDisplay and let the plugin manage this1092 // 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 double timeSinceLastUpdate = (double)_lastTimeUpdated.nsecsElapsed() / 1000000.0;1933 double timeSinceLastUpdate = (double)_lastTimeUpdated.nsecsElapsed() / 1000000.0;
1956 if (timeSinceLastUpdate > targetFramePeriod) {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 _lastTimeUpdated.start();1942 _lastTimeUpdated.start();
1958 {1943 {
1959 PerformanceTimer perfTimer("update");1944 PerformanceTimer perfTimer("update");
@@ -1986,12 +1971,19 @@ void Application::idle() { · 26 unmodified lines
1986 _idleLoopMeasuredJitter = _idleLoopStdev.getStDev();1971 _idleLoopMeasuredJitter = _idleLoopStdev.getStDev();
1987 _idleLoopStdev.reset();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,1975
1992 // depending on whether we're throttling or not1976 // depending on whether we're throttling or not.
1993 idleTimer->start(getActiveDisplayPlugin()->isThrottled() ? THROTTLED_IDLE_TIMER_DELAY : 0);1977 // Once rendering is off on another thread we should be able to have Application::idle run at start(0) in
1994 } 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 // check for any requested background downloads.1988 // check for any requested background downloads.
1997 emit checkBackgroundDownloads();1989 emit checkBackgroundDownloads();
@@ -3207,7 +3199,7 @@ PickRay Application::computePickRay(float x, float y) const { · 1209 unmodified lines
3207}3199}
3208 3200
3209QImage Application::renderAvatarBillboard(RenderArgs* renderArgs) {3201QImage Application::renderAvatarBillboard(RenderArgs* renderArgs) {
3210 auto primaryFramebuffer = DependencyManager::get<TextureCache>()->getPrimaryFramebuffer();3202 auto primaryFramebuffer = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
3211 glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFramebuffer));3203 glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFramebuffer));
3212 3204
3213 // clear the alpha channel so the background is transparent3205 // clear the alpha channel so the background is transparent
@@ -3400,10 +3392,6 @@ namespace render { · 186 unmodified lines
3400 model::Skybox::render(batch, *(Application::getInstance()->getDisplayViewFrustum()), *skybox);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 // set the bounds of rear mirror view3593 // set the bounds of rear mirror view
3606 gpu::Vec4i viewport;3594 gpu::Vec4i viewport;
3607 if (billboard) {3595 if (billboard) {
3608 QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize();3596 QSize size = DependencyManager::get<FramebufferCache>()->getFrameBufferSize();
3609 viewport = gpu::Vec4i(region.x(), size.height() - region.y() - region.height(), region.width(), region.height());3597 viewport = gpu::Vec4i(region.x(), size.height() - region.y() - region.height(), region.width(), region.height());
3610 } else {3598 } else {
3611 // if not rendering the billboard, the region is in device independent coordinates; must convert to device3599 // 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 float ratio = (float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale();3601 float ratio = (float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale();
3614 int x = region.x() * ratio, y = region.y() * ratio, width = region.width() * ratio, height = region.height() * ratio;3602 int x = region.x() * ratio, y = region.y() * ratio, width = region.width() * ratio, height = region.height() * ratio;
3615 viewport = gpu::Vec4i(x, size.height() - y - height, width, height);3603 viewport = gpu::Vec4i(x, size.height() - y - height, width, height);