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
99 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
1010 //
1111
12−#include <sstream>
12+#include "Application.h"
1313
14−#include <stdlib.h>
15−#include <cmath>
16−#include <math.h>
14+#include <sstream>
1715
1816 #include <glm/glm.hpp>
1917 #include <glm/gtx/component_wise.hpp>
@@ -63,6 +61,7 @@ · 43 unmodified lines
6361
6462 #include <EntityScriptingInterface.h>
6563 #include <ErrorDialog.h>
64+#include <FramebufferCache.h>
6665 #include <GlWindow.h>
6766 #include <gpu/Batch.h>
6867 #include <gpu/Context.h>
@@ -92,13 +91,13 @@ · 23 unmodified lines
9291 #include <SettingHandle.h>
9392 #include <SimpleAverage.h>
9493 #include <SoundCache.h>
94+#include <TextureCache.h>
9595 #include <Tooltip.h>
9696 #include <UserActivityLogger.h>
9797 #include <UUID.h>
9898 #include <input-plugins/UserInputMapper.h>
9999 #include <VrMenu.h>
100100
101−#include "Application.h"
102101 #include "AudioClient.h"
103102 #include "DiscoverabilityManager.h"
104103 #include "InterfaceVersion.h"
@@ -268,6 +267,8 @@ bool setupEssentials(int& argc, char** argv) { · 163 unmodified lines
268267 auto audioScope = DependencyManager::set<AudioScope>();
269268 auto deferredLightingEffect = DependencyManager::set<DeferredLightingEffect>();
270269 auto textureCache = DependencyManager::set<TextureCache>();
270+ auto framebufferCache = DependencyManager::set<FramebufferCache>();
271+
271272 auto animationCache = DependencyManager::set<AnimationCache>();
272273 auto ddeFaceTracker = DependencyManager::set<DdeFaceTracker>();
273274 auto modelBlender = DependencyManager::set<ModelBlender>();
@@ -771,6 +772,7 @@ Application::~Application() { · 497 unmodified lines
771772 DependencyManager::destroy<OffscreenUi>();
772773 DependencyManager::destroy<AvatarManager>();
773774 DependencyManager::destroy<AnimationCache>();
775+ DependencyManager::destroy<FramebufferCache>();
774776 DependencyManager::destroy<TextureCache>();
775777 DependencyManager::destroy<GeometryCache>();
776778 DependencyManager::destroy<ScriptCache>();
@@ -804,33 +806,8 @@ void Application::initializeGL() { · 27 unmodified lines
804806 }
805807 #endif
806808
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());
834811
835812 initDisplay();
836813 qCDebug(interfaceapp, "Initialized Display.");
@@ -929,8 +906,9 @@ void Application::paintGL() { · 92 unmodified lines
929906 _offscreenContext->makeCurrent();
930907
931908 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(),
934912 lodManager->getBoundaryLevelAdjust(), RenderArgs::DEFAULT_RENDER_MODE,
935913 RenderArgs::MONO, RenderArgs::RENDER_DEBUG_NONE);
936914
@@ -942,17 +920,16 @@ void Application::paintGL() { · 5 unmodified lines
942920 PerformanceWarning warn(showWarnings, "Application::paintGL()");
943921 resizeGL();
944922
923+
945924 {
946925 PerformanceTimer perfTimer("renderOverlay");
947926 // NOTE: There is no batch associated with this renderArgs
948927 // the ApplicationOverlay class assumes it's viewport is setup to be the device size
949928 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());
951930 _applicationOverlay.renderOverlay(&renderArgs);
952931 }
953932
954− glEnable(GL_LINE_SMOOTH);
955−
956933 if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON || _myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
957934 Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, _myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN);
958935 Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, !(_myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN));
@@ -1000,8 +977,7 @@ void Application::paintGL() { · 41 unmodified lines
1000977 }
1001978
1002979 // 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);
1005981
1006982
1007983 renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE;
@@ -1015,19 +991,15 @@ void Application::paintGL() { · 7 unmodified lines
1015991 {
1016992 PROFILE_RANGE(__FUNCTION__ "/clear");
1017993 doInBatch(&renderArgs, [&](gpu::Batch& batch) {
1018− batch.setFramebuffer(textureCache->getPrimaryFramebuffer());
994+ auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
995+ batch.setFramebuffer(primaryFbo);
1019996 // clear the normal and specular buffers
1020997 batch.clearFramebuffer(
1021998 gpu::Framebuffer::BUFFER_COLOR0 |
1022999 gpu::Framebuffer::BUFFER_COLOR1 |
10231000 gpu::Framebuffer::BUFFER_COLOR2 |
10241001 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);
10311003 });
10321004 }
10331005
@@ -1048,7 +1020,9 @@ void Application::paintGL() { · 14 unmodified lines
10481020 displaySide(&renderArgs, eyeCamera);
10491021 if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror) &&
10501022 !Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) {
1023+ renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
10511024 renderRearViewMirror(&renderArgs, _mirrorViewRect);
1025+ renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE;
10521026 }
10531027 }, [&] {
10541028 r.moveLeft(r.width());
@@ -1065,7 +1039,9 @@ void Application::paintGL() { · 10 unmodified lines
10651039 displaySide(&renderArgs, _myCamera);
10661040 if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror) &&
10671041 !Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) {
1042+ renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
10681043 renderRearViewMirror(&renderArgs, _mirrorViewRect);
1044+ renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE;
10691045 }
10701046 }
10711047 }
@@ -1107,8 +1083,10 @@ void Application::paintGL() { · 35 unmodified lines
11071083 GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
11081084 #endif
11091085 _offscreenContext->doneCurrent();
1086+ // Switches to the display plugin context
11101087 displayPlugin->preDisplay();
11111088
1089+ // Ensure all operations from the previous context are complete before we try to read the fbo
11121090 #ifdef Q_OS_MAC
11131091 #else
11141092 // FIXME? make the sync a parameter to preDisplay and let the plugin manage this
@@ -1954,6 +1932,13 @@ void Application::idle() { · 839 unmodified lines
19541932 }
19551933 double timeSinceLastUpdate = (double)_lastTimeUpdated.nsecsElapsed() / 1000000.0;
19561934 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+
19571942 _lastTimeUpdated.start();
19581943 {
19591944 PerformanceTimer perfTimer("update");
@@ -1986,12 +1971,19 @@ void Application::idle() { · 26 unmodified lines
19861971 _idleLoopMeasuredJitter = _idleLoopStdev.getStDev();
19871972 _idleLoopStdev.reset();
19881973 }
1989−
19901974 }
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+ }
19951987
19961988 // check for any requested background downloads.
19971989 emit checkBackgroundDownloads();
@@ -3207,7 +3199,7 @@ PickRay Application::computePickRay(float x, float y) const { · 1209 unmodified lines
32073199 }
32083200
32093201 QImage Application::renderAvatarBillboard(RenderArgs* renderArgs) {
3210− auto primaryFramebuffer = DependencyManager::get<TextureCache>()->getPrimaryFramebuffer();
3202+ auto primaryFramebuffer = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
32113203 glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFramebuffer));
32123204
32133205 // clear the alpha channel so the background is transparent
@@ -3400,10 +3392,6 @@ namespace render { · 186 unmodified lines
34003392 model::Skybox::render(batch, *(Application::getInstance()->getDisplayViewFrustum()), *skybox);
34013393 }
34023394 }
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);
34073395 }
34083396 }
34093397
@@ -3605,11 +3593,11 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi · 195 unmodified lines
36053593 // set the bounds of rear mirror view
36063594 gpu::Vec4i viewport;
36073595 if (billboard) {
3608− QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize();
3596+ QSize size = DependencyManager::get<FramebufferCache>()->getFrameBufferSize();
36093597 viewport = gpu::Vec4i(region.x(), size.height() - region.y() - region.height(), region.width(), region.height());
36103598 } else {
36113599 // 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();
36133601 float ratio = (float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale();
36143602 int x = region.x() * ratio, y = region.y() * ratio, width = region.width() * ratio, height = region.height() * ratio;
36153603 viewport = gpu::Vec4i(x, size.height() - y - height, width, height);