History

Merging with upstream master/graphics

samcake committed 10 years ago

Commit e70ab472 parents a50b14d c99ae5d8 files · +107 −75Browse files

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

Unified · Split

interface/src/Application.cpp+87−24
@@ -1150,7 +1150,7 @@ void Application::paintGL() { · 1149 unmodified lines
11501150
11511151 if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
11521152 PerformanceTimer perfTimer("Mirror");
1153− auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor();
1153+ auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
11541154
11551155 renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
11561156 renderRearViewMirror(&renderArgs, _mirrorViewRect);
@@ -1231,15 +1231,28 @@ void Application::paintGL() { · 74 unmodified lines
12311231 }
12321232 } else if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
12331233 if (isHMDMode()) {
1234+ auto mirrorBodyOrientation = myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI + _rotateMirror, 0.0f));
1235+
12341236 glm::quat hmdRotation = extractRotation(myAvatar->getHMDSensorMatrix());
1235− _myCamera.setRotation(myAvatar->getWorldAlignedOrientation()
1236− * glm::quat(glm::vec3(0.0f, PI + _rotateMirror, 0.0f)) * hmdRotation);
1237+ // Mirror HMD yaw and roll
1238+ glm::vec3 mirrorHmdEulers = glm::eulerAngles(hmdRotation);
1239+ mirrorHmdEulers.y = -mirrorHmdEulers.y;
1240+ mirrorHmdEulers.z = -mirrorHmdEulers.z;
1241+ glm::quat mirrorHmdRotation = glm::quat(mirrorHmdEulers);
1242+
1243+ glm::quat worldMirrorRotation = mirrorBodyOrientation * mirrorHmdRotation;
1244+
1245+ _myCamera.setRotation(worldMirrorRotation);
1246+
12371247 glm::vec3 hmdOffset = extractTranslation(myAvatar->getHMDSensorMatrix());
1248+ // Mirror HMD lateral offsets
1249+ hmdOffset.x = -hmdOffset.x;
1250+
12381251 _myCamera.setPosition(myAvatar->getDefaultEyePosition()
12391252 + glm::vec3(0, _raiseMirror * myAvatar->getAvatarScale(), 0)
1240− + (myAvatar->getOrientation() * glm::quat(glm::vec3(0.0f, _rotateMirror, 0.0f))) *
1241− glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror
1242− + (myAvatar->getOrientation() * glm::quat(glm::vec3(0.0f, PI + _rotateMirror, 0.0f))) * hmdOffset);
1253+ + mirrorBodyOrientation * glm::vec3(0.0f, 0.0f, 1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror
1254+ + mirrorBodyOrientation * hmdOffset);
1255+
12431256 } else {
12441257 _myCamera.setRotation(myAvatar->getWorldAlignedOrientation()
12451258 * glm::quat(glm::vec3(0.0f, PI + _rotateMirror, 0.0f)));
@@ -1273,6 +1286,10 @@ void Application::paintGL() { · 27 unmodified lines
12731286 // Primary rendering pass
12741287 auto framebufferCache = DependencyManager::get<FramebufferCache>();
12751288 const QSize size = framebufferCache->getFrameBufferSize();
1289+
1290+ // Final framebuffer that will be handled to the display-plugin
1291+ auto finalFramebuffer = framebufferCache->getFramebuffer();
1292+
12761293 {
12771294 PROFILE_RANGE(__FUNCTION__ "/mainRender");
12781295 PerformanceTimer perfTimer("mainRender");
@@ -1326,9 +1343,63 @@ void Application::paintGL() { · 47 unmodified lines
13261343 }
13271344 displaySide(&renderArgs, _myCamera);
13281345 renderArgs._context->enableStereo(false);
1329− gpu::doInBatch(renderArgs._context, [](gpu::Batch& batch) {
1330− batch.setFramebuffer(nullptr);
1331− });
1346+
1347+ // Blit primary to final FBO
1348+ auto primaryFbo = framebufferCache->getPrimaryFramebuffer();
1349+
1350+ if (renderArgs._renderMode == RenderArgs::MIRROR_RENDER_MODE) {
1351+ if (displayPlugin->isStereo()) {
1352+ gpu::doInBatch(renderArgs._context, [=](gpu::Batch& batch) {
1353+ gpu::Vec4i srcRectLeft;
1354+ srcRectLeft.z = size.width() / 2;
1355+ srcRectLeft.w = size.height();
1356+
1357+ gpu::Vec4i srcRectRight;
1358+ srcRectRight.x = size.width() / 2;
1359+ srcRectRight.z = size.width();
1360+ srcRectRight.w = size.height();
1361+
1362+ gpu::Vec4i destRectLeft;
1363+ destRectLeft.x = srcRectLeft.z;
1364+ destRectLeft.z = srcRectLeft.x;
1365+ destRectLeft.y = srcRectLeft.y;
1366+ destRectLeft.w = srcRectLeft.w;
1367+
1368+ gpu::Vec4i destRectRight;
1369+ destRectRight.x = srcRectRight.z;
1370+ destRectRight.z = srcRectRight.x;
1371+ destRectRight.y = srcRectRight.y;
1372+ destRectRight.w = srcRectRight.w;
1373+
1374+ batch.setFramebuffer(finalFramebuffer);
1375+ batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0f, 0.0f, 1.0f, 0.0f));
1376+ // BLit left to right and right to left in stereo
1377+ batch.blit(primaryFbo, srcRectRight, finalFramebuffer, destRectLeft);
1378+ batch.blit(primaryFbo, srcRectLeft, finalFramebuffer, destRectRight);
1379+ });
1380+ } else {
1381+ gpu::doInBatch(renderArgs._context, [=](gpu::Batch& batch) {
1382+ gpu::Vec4i srcRect;
1383+ srcRect.z = size.width();
1384+ srcRect.w = size.height();
1385+ gpu::Vec4i destRect;
1386+ destRect.x = size.width();
1387+ destRect.y = 0;
1388+ destRect.z = 0;
1389+ destRect.w = size.height();
1390+ batch.setFramebuffer(finalFramebuffer);
1391+ batch.blit(primaryFbo, srcRect, finalFramebuffer, destRect);
1392+ });
1393+ }
1394+ } else {
1395+ gpu::doInBatch(renderArgs._context, [=](gpu::Batch& batch) {
1396+ gpu::Vec4i rect;
1397+ rect.z = size.width();
1398+ rect.w = size.height();
1399+ batch.setFramebuffer(finalFramebuffer);
1400+ batch.blit(primaryFbo, rect, finalFramebuffer, rect);
1401+ });
1402+ }
13321403 }
13331404
13341405 // Overlay Composition, needs to occur after screen space effects have completed
@@ -1336,7 +1407,9 @@ void Application::paintGL() { · 1 unmodified line
13361407 {
13371408 PROFILE_RANGE(__FUNCTION__ "/compositor");
13381409 PerformanceTimer perfTimer("compositor");
1339− auto primaryFbo = framebufferCache->getPrimaryFramebufferDepthColor();
1410+
1411+ auto primaryFbo = finalFramebuffer;
1412+
13401413 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFbo));
13411414 if (displayPlugin->isStereo()) {
13421415 QRect currentViewport(QPoint(0, 0), QSize(size.width() / 2, size.height()));
@@ -1362,23 +1435,13 @@ void Application::paintGL() { · 19 unmodified lines
13621435 PROFILE_RANGE(__FUNCTION__ "/pluginOutput");
13631436 PerformanceTimer perfTimer("pluginOutput");
13641437
1365− auto primaryFramebuffer = framebufferCache->getPrimaryFramebufferDepthColor();
1366− auto scratchFramebuffer = framebufferCache->getFramebuffer();
1367− gpu::doInBatch(renderArgs._context, [=](gpu::Batch& batch) {
1368− gpu::Vec4i rect;
1369− rect.z = size.width();
1370− rect.w = size.height();
1371− batch.setFramebuffer(scratchFramebuffer);
1372− batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0f, 0.0f, 0.0f, 0.0f));
1373− batch.blit(primaryFramebuffer, rect, scratchFramebuffer, rect);
1374− batch.setFramebuffer(nullptr);
1375− });
1376− auto finalTexturePointer = scratchFramebuffer->getRenderBuffer(0);
1438+ auto finalTexturePointer = finalFramebuffer->getRenderBuffer(0);
1439+
13771440 GLuint finalTexture = gpu::GLBackend::getTextureID(finalTexturePointer);
13781441 Q_ASSERT(0 != finalTexture);
13791442
13801443 Q_ASSERT(!_lockedFramebufferMap.contains(finalTexture));
1381− _lockedFramebufferMap[finalTexture] = scratchFramebuffer;
1444+ _lockedFramebufferMap[finalTexture] = finalFramebuffer;
13821445
13831446 Q_ASSERT(isCurrentContext(_offscreenContext->getContext()));
13841447 {
@@ -3331,7 +3394,7 @@ QImage Application::renderAvatarBillboard(RenderArgs* renderArgs) { · 1946 unmodified lines
33313394 renderArgs->_renderMode = RenderArgs::DEFAULT_RENDER_MODE;
33323395 renderRearViewMirror(renderArgs, QRect(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE), true);
33333396
3334− auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor();
3397+ auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
33353398 QImage image(BILLBOARD_SIZE, BILLBOARD_SIZE, QImage::Format_ARGB32);
33363399 renderArgs->_context->downloadFramebuffer(primaryFbo, glm::ivec4(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE), image);
33373400