History

Merge branch 'master' of https://github.com/highfidelity/hifi into cruftRemovalRedux

Brad Hefta-Gaub committed 10 years ago

Commit 2a243cc2 parents be4bc7b 06c823545 files · +703 −369Browse files

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

Unified · Split

interface/src/Application.cpp+52−50
@@ -44,6 +44,9 @@ · 43 unmodified lines
4444
4545 #include <QtNetwork/QNetworkDiskCache>
4646
47+#include <gl/Config.h>
48+#include <QtGui/QOpenGLContext>
49+
4750 #include <AccountManager.h>
4851 #include <AddressManager.h>
4952 #include <ApplicationVersion.h>
@@ -617,6 +620,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 567 unmodified lines
617620
618621 // enable mouse tracking; otherwise, we only get drag events
619622 _glWidget->setMouseTracking(true);
623+ _glWidget->makeCurrent();
624+ _glWidget->initializeGL();
620625
621626 _offscreenContext = new OffscreenGLCanvas();
622627 _offscreenContext->create(_glWidget->context()->contextHandle());
@@ -1136,7 +1141,7 @@ void Application::paintGL() { · 513 unmodified lines
11361141 _lastInstantaneousFps = instantaneousFps;
11371142
11381143 auto displayPlugin = getActiveDisplayPlugin();
1139− displayPlugin->preRender();
1144+ // FIXME not needed anymore?
11401145 _offscreenContext->makeCurrent();
11411146
11421147 // update the avatar with a fresh HMD pose
@@ -1191,6 +1196,9 @@ void Application::paintGL() { · 48 unmodified lines
11911196 QSize size = getDeviceSize();
11921197 renderArgs._viewport = glm::ivec4(0, 0, size.width(), size.height());
11931198 _applicationOverlay.renderOverlay(&renderArgs);
1199+ gpu::FramebufferPointer overlayFramebuffer = _applicationOverlay.getOverlayFramebuffer();
1200+
1201+
11941202 }
11951203
11961204 {
@@ -1304,6 +1312,13 @@ void Application::paintGL() { · 107 unmodified lines
13041312 auto baseProjection = renderArgs._viewFrustum->getProjection();
13051313 auto hmdInterface = DependencyManager::get<HMDScriptingInterface>();
13061314 float IPDScale = hmdInterface->getIPDScale();
1315+
1316+ // Tell the plugin what pose we're using to render. In this case we're just using the
1317+ // unmodified head pose because the only plugin that cares (the Oculus plugin) uses it
1318+ // for rotational timewarp. If we move to support positonal timewarp, we need to
1319+ // ensure this contains the full pose composed with the eye offsets.
1320+ mat4 headPose = displayPlugin->getHeadPose(_frameCount);
1321+
13071322 // FIXME we probably don't need to set the projection matrix every frame,
13081323 // only when the display plugin changes (or in non-HMD modes when the user
13091324 // changes the FOV manually, which right now I don't think they can.
@@ -1319,12 +1334,7 @@ void Application::paintGL() { · 9 unmodified lines
13191334 mat4 eyeOffsetTransform = glm::translate(mat4(), eyeOffset * -1.0f * IPDScale);
13201335 eyeOffsets[eye] = eyeOffsetTransform;
13211336
1322− // Tell the plugin what pose we're using to render. In this case we're just using the
1323− // unmodified head pose because the only plugin that cares (the Oculus plugin) uses it
1324− // for rotational timewarp. If we move to support positonal timewarp, we need to
1325− // ensure this contains the full pose composed with the eye offsets.
1326− mat4 headPose = displayPlugin->getHeadPose();
1327− displayPlugin->setEyeRenderPose(eye, headPose);
1337+ displayPlugin->setEyeRenderPose(_frameCount, eye, headPose);
13281338
13291339 eyeProjections[eye] = displayPlugin->getProjection(eye, baseProjection);
13301340 });
@@ -1339,6 +1349,7 @@ void Application::paintGL() { · 8 unmodified lines
13391349 }
13401350
13411351 // Overlay Composition, needs to occur after screen space effects have completed
1352+ // FIXME migrate composition into the display plugins
13421353 {
13431354 PROFILE_RANGE(__FUNCTION__ "/compositor");
13441355 PerformanceTimer perfTimer("compositor");
@@ -1367,44 +1378,40 @@ void Application::paintGL() { · 22 unmodified lines
13671378 {
13681379 PROFILE_RANGE(__FUNCTION__ "/pluginOutput");
13691380 PerformanceTimer perfTimer("pluginOutput");
1370− auto primaryFbo = framebufferCache->getPrimaryFramebuffer();
1371− GLuint finalTexture = gpu::GLBackend::getTextureID(primaryFbo->getRenderBuffer(0));
1372− // Ensure the rendering context commands are completed when rendering
1373− GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
1374− // Ensure the sync object is flushed to the driver thread before releasing the context
1375− // CRITICAL for the mac driver apparently.
1376− glFlush();
1377− _offscreenContext->doneCurrent();
1378−
1379− // Switches to the display plugin context
1380− displayPlugin->preDisplay();
1381− // Ensure all operations from the previous context are complete before we try to read the fbo
1382− glWaitSync(sync, 0, GL_TIMEOUT_IGNORED);
1383− glDeleteSync(sync);
1384− uint64_t displayStart = usecTimestampNow();
1381+ auto primaryFramebuffer = framebufferCache->getPrimaryFramebuffer();
1382+ auto scratchFramebuffer = framebufferCache->getFramebuffer();
1383+ gpu::doInBatch(renderArgs._context, [=](gpu::Batch& batch) {
1384+ gpu::Vec4i rect;
1385+ rect.z = size.width();
1386+ rect.w = size.height();
1387+ batch.setFramebuffer(scratchFramebuffer);
1388+ batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0f, 0.0f, 0.0f, 0.0f));
1389+ batch.blit(primaryFramebuffer, rect, scratchFramebuffer, rect);
1390+ batch.setFramebuffer(nullptr);
1391+ });
1392+ auto finalTexturePointer = scratchFramebuffer->getRenderBuffer(0);
1393+ GLuint finalTexture = gpu::GLBackend::getTextureID(finalTexturePointer);
1394+ Q_ASSERT(0 != finalTexture);
13851395
1386− {
1387− PROFILE_RANGE(__FUNCTION__ "/pluginDisplay");
1388− PerformanceTimer perfTimer("pluginDisplay");
1389− displayPlugin->display(finalTexture, toGlm(size));
1390− }
1396+ Q_ASSERT(!_lockedFramebufferMap.contains(finalTexture));
1397+ _lockedFramebufferMap[finalTexture] = scratchFramebuffer;
13911398
1399+ uint64_t displayStart = usecTimestampNow();
1400+ Q_ASSERT(QOpenGLContext::currentContext() == _offscreenContext->getContext());
13921401 {
1393− PROFILE_RANGE(__FUNCTION__ "/bufferSwap");
1394− PerformanceTimer perfTimer("bufferSwap");
1395− displayPlugin->finishFrame();
1402+ PROFILE_RANGE(__FUNCTION__ "/pluginSubmitScene");
1403+ PerformanceTimer perfTimer("pluginSubmitScene");
1404+ displayPlugin->submitSceneTexture(_frameCount, finalTexture, toGlm(size));
13961405 }
1406+ Q_ASSERT(QOpenGLContext::currentContext() == _offscreenContext->getContext());
1407+
13971408 uint64_t displayEnd = usecTimestampNow();
13981409 const float displayPeriodUsec = (float)(displayEnd - displayStart); // usecs
13991410 _lastPaintWait = displayPeriodUsec / (float)USECS_PER_SECOND;
1400−
14011411 }
14021412
14031413 {
1404− PerformanceTimer perfTimer("makeCurrent");
1405− _offscreenContext->makeCurrent();
14061414 Stats::getInstance()->setRenderDetails(renderArgs._details);
1407−
14081415 // Reset the gpu::Context Stages
14091416 // Back to the default framebuffer;
14101417 gpu::doInBatch(renderArgs._context, [=](gpu::Batch& batch) {
@@ -2612,7 +2619,7 @@ void Application::updateMyAvatarLookAtPosition() { · 1201 unmodified lines
26122619 lookAtPosition.x = -lookAtPosition.x;
26132620 }
26142621 if (isHMD) {
2615− glm::mat4 headPose = getActiveDisplayPlugin()->getHeadPose();
2622+ glm::mat4 headPose = getActiveDisplayPlugin()->getHeadPose(_frameCount);
26162623 glm::quat hmdRotation = glm::quat_cast(headPose);
26172624 lookAtSpot = _myCamera.getPosition() + myAvatar->getOrientation() * (hmdRotation * lookAtPosition);
26182625 } else {
@@ -4503,7 +4510,7 @@ void Application::takeSnapshot() { · 1884 unmodified lines
45034510 player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath()));
45044511 player->play();
45054512
4506− QString fileName = Snapshot::saveSnapshot(_glWidget->grabFrameBuffer());
4513+ QString fileName = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getScreenshot());
45074514
45084515 AccountManager& accountManager = AccountManager::getInstance();
45094516 if (!accountManager.isLoggedIn()) {
@@ -4514,7 +4521,6 @@ void Application::takeSnapshot() { · 4 unmodified lines
45144521 _snapshotShareDialog = new SnapshotShareDialog(fileName, _glWidget);
45154522 }
45164523 _snapshotShareDialog->show();
4517−
45184524 }
45194525
45204526 float Application::getRenderResolutionScale() const {
@@ -4697,10 +4703,6 @@ const DisplayPlugin* Application::getActiveDisplayPlugin() const { · 176 unmodified lines
46974703 return ((Application*)this)->getActiveDisplayPlugin();
46984704 }
46994705
4700−bool _activatingDisplayPlugin{ false };
4701−QVector<QPair<QString, QString>> _currentDisplayPluginActions;
4702−QVector<QPair<QString, QString>> _currentInputPluginActions;
4703−
47044706 static void addDisplayPluginToMenu(DisplayPluginPointer displayPlugin, bool active = false) {
47054707 auto menu = Menu::getInstance();
47064708 QString name = displayPlugin->getName();
@@ -4730,9 +4732,10 @@ void Application::updateDisplayMode() { · 23 unmodified lines
47304732 bool first = true;
47314733 foreach(auto displayPlugin, displayPlugins) {
47324734 addDisplayPluginToMenu(displayPlugin, first);
4733− QObject::connect(displayPlugin.get(), &DisplayPlugin::requestRender, [this] {
4734− paintGL();
4735− });
4735+ // This must be a queued connection to avoid a deadlock
4736+ QObject::connect(displayPlugin.get(), &DisplayPlugin::requestRender,
4737+ this, &Application::paintGL, Qt::QueuedConnection);
4738+
47364739 QObject::connect(displayPlugin.get(), &DisplayPlugin::recommendedFramebufferSizeChanged, [this](const QSize & size) {
47374740 resizeGL();
47384741 });
@@ -4774,19 +4777,18 @@ void Application::updateDisplayMode() { · 35 unmodified lines
47744777 return;
47754778 }
47764779
4777− if (!_currentDisplayPluginActions.isEmpty()) {
4780+
4781+ if (!_pluginContainer->currentDisplayActions().isEmpty()) {
47784782 auto menu = Menu::getInstance();
4779− foreach(auto itemInfo, _currentDisplayPluginActions) {
4783+ foreach(auto itemInfo, _pluginContainer->currentDisplayActions()) {
47804784 menu->removeMenuItem(itemInfo.first, itemInfo.second);
47814785 }
4782− _currentDisplayPluginActions.clear();
4786+ _pluginContainer->currentDisplayActions().clear();
47834787 }
47844788
47854789 if (newDisplayPlugin) {
47864790 _offscreenContext->makeCurrent();
4787− _activatingDisplayPlugin = true;
47884791 newDisplayPlugin->activate();
4789− _activatingDisplayPlugin = false;
47904792 _offscreenContext->makeCurrent();
47914793 offscreenUi->resize(fromGlm(newDisplayPlugin->getRecommendedUiSize()));
47924794 _offscreenContext->makeCurrent();
@@ -4912,7 +4914,7 @@ mat4 Application::getEyeOffset(int eye) const { · 119 unmodified lines
49124914
49134915 mat4 Application::getHMDSensorPose() const {
49144916 if (isHMDMode()) {
4915− return getActiveDisplayPlugin()->getHeadPose();
4917+ return getActiveDisplayPlugin()->getHeadPose(_frameCount);
49164918 }
49174919 return mat4();
49184920 }