History

Render the rear view mirror in a separate target and then display it during overlay pass

Sam Gateau committed 11 years ago

Commit a5618741 parent f86c06410 files · +146 −27Browse files

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

Unified · Split

interface/src/Application.cpp+72−19
@@ -875,6 +875,33 @@ void Application::paintGL() { · 874 unmodified lines
875875 PerformanceWarning warn(showWarnings, "Application::paintGL()");
876876 resizeGL();
877877
878+ // Before anything else, let's sync up the gpuContext with the true glcontext used in case anything happened
879+ renderArgs._context->syncCache();
880+
881+ if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
882+ auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
883+ {
884+ gpu::Batch batch;
885+ batch.setFramebuffer(nullptr);
886+ batch.setFramebuffer(primaryFbo);
887+ renderArgs._context->render(batch);
888+ }
889+ renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
890+ renderRearViewMirror(&renderArgs, _mirrorViewRect);
891+ renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE;
892+
893+ {
894+ auto mirrorViewport = glm::ivec4(0, 0, _mirrorViewRect.width(), _mirrorViewRect.height());
895+ float ratio = 1.0f / ((float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale());
896+
897+ auto mirrorViewportDest = glm::ivec4(0, 0, ratio * mirrorViewport.z, ratio * mirrorViewport.w);
898+
899+ auto selfieFbo = DependencyManager::get<FramebufferCache>()->getSelfieFramebuffer();
900+ gpu::Batch batch;
901+ batch.blit(primaryFbo, mirrorViewport, selfieFbo, mirrorViewportDest);
902+ renderArgs._context->render(batch);
903+ }
904+ }
878905
879906 {
880907 PerformanceTimer perfTimer("renderOverlay");
@@ -936,7 +963,7 @@ void Application::paintGL() { · 55 unmodified lines
936963 }
937964
938965 // Sync up the View Furstum with the camera
939− loadViewFrustum(_myCamera, _viewFrustum);
966+ // loadViewFrustum(_myCamera, _viewFrustum);
940967
941968
942969 renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE;
@@ -974,19 +1001,17 @@ void Application::paintGL() { · 31 unmodified lines
9741001
9751002 displaySide(&renderArgs, _myCamera);
9761003
977− if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
978− renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
979− renderRearViewMirror(&renderArgs, _mirrorViewRect);
980− renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE;
981− }
982−
9831004 {
9841005 auto geometryCache = DependencyManager::get<GeometryCache>();
9851006 auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
9861007 gpu::Batch batch;
9871008 batch.blit(primaryFbo, glm::ivec4(0, 0, _renderResolution.x, _renderResolution.y),
9881009 nullptr, glm::ivec4(0, 0, _glWidget->getDeviceSize().width(), _glWidget->getDeviceSize().height()));
1010+
1011+ batch.setFramebuffer(nullptr);
1012+
9891013 renderArgs._context->render(batch);
1014+
9901015 }
9911016
9921017 _compositor.displayOverlayTexture(&renderArgs);
@@ -2958,7 +2983,7 @@ PickRay Application::computePickRay(float x, float y) const { · 1965 unmodified lines
29582983 }
29592984
29602985 QImage Application::renderAvatarBillboard(RenderArgs* renderArgs) {
2961− auto primaryFramebuffer = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
2986+/* auto primaryFramebuffer = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
29622987 glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFramebuffer));
29632988
29642989 // clear the alpha channel so the background is transparent
@@ -2966,17 +2991,41 @@ QImage Application::renderAvatarBillboard(RenderArgs* renderArgs) { · 1 unmodified line
29662991 glClearColor(0.0, 0.0, 0.0, 0.0);
29672992 glClear(GL_COLOR_BUFFER_BIT);
29682993 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
2994+ */
2995+
2996+ // const int BILLBOARD_SIZE = 64;
2997+ const int BILLBOARD_SIZE = 256;
2998+ _glWidget->makeCurrent();
2999+
3000+ auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
29693001
2970− const int BILLBOARD_SIZE = 64;
2971− // TODO: Pass a RenderArgs to renderAvatarBillboard
2972− renderRearViewMirror(renderArgs, QRect(0, _glWidget->getDeviceHeight() - BILLBOARD_SIZE,
3002+ {
3003+ gpu::Batch batch;
3004+ batch.setFramebuffer(nullptr);
3005+ batch.setFramebuffer(primaryFbo);
3006+ renderArgs->_context->render(batch);
3007+ }
3008+ renderArgs->_renderMode = RenderArgs::MIRROR_RENDER_MODE;
3009+ renderRearViewMirror(renderArgs, QRect(0, /*_glWidget->getDeviceHeight() - BILLBOARD_SIZE*/ 0,
29733010 BILLBOARD_SIZE, BILLBOARD_SIZE),
2974− true);
3011+ false);
3012+ renderArgs->_renderMode = RenderArgs::NORMAL_RENDER_MODE;
3013+
3014+ auto selfieFbo = DependencyManager::get<FramebufferCache>()->getSelfieFramebuffer();
3015+ {
3016+ auto mirrorViewport = glm::ivec4(0, 0,BILLBOARD_SIZE, BILLBOARD_SIZE);
3017+ gpu::Batch batch;
3018+ // batch.blit(primaryFbo, mirrorViewport, selfieFbo, mirrorViewport);
3019+ batch.setFramebuffer(nullptr);
3020+ renderArgs->_context->render(batch);
3021+ }
3022+
3023+
29753024 QImage image(BILLBOARD_SIZE, BILLBOARD_SIZE, QImage::Format_ARGB32);
3025+ glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFbo));
29763026 glReadPixels(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE, GL_BGRA, GL_UNSIGNED_BYTE, image.bits());
2977− glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
2978−
29793027 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3028+
29803029 return image;
29813030 }
29823031
@@ -3390,13 +3439,18 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi · 407 unmodified lines
33903439 gpu::Vec4i viewport;
33913440 if (billboard) {
33923441 QSize size = DependencyManager::get<FramebufferCache>()->getFrameBufferSize();
3393− viewport = gpu::Vec4i(region.x(), size.height() - region.y() - region.height(), region.width(), region.height());
3442+ // viewport = gpu::Vec4i(region.x(), size.height() - region.y() - region.height(), region.width(), region.height());
3443+ viewport = gpu::Vec4i(0, 0, region.width(), region.height());
33943444 } else {
33953445 // if not rendering the billboard, the region is in device independent coordinates; must convert to device
33963446 QSize size = DependencyManager::get<FramebufferCache>()->getFrameBufferSize();
33973447 float ratio = (float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale();
3398− int x = region.x() * ratio, y = region.y() * ratio, width = region.width() * ratio, height = region.height() * ratio;
3399− viewport = gpu::Vec4i(x, size.height() - y - height, width, height);
3448+ int x = region.x() * ratio;
3449+ int y = region.y() * ratio;
3450+ int width = region.width() * ratio;
3451+ int height = region.height() * ratio;
3452+ // viewport = gpu::Vec4i(x, size.height() - y - height, width, height);
3453+ viewport = gpu::Vec4i(0, 0, width, height);
34003454 }
34013455 renderArgs->_viewport = viewport;
34023456
@@ -3414,8 +3468,7 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi · 11 unmodified lines
34143468 renderArgs->_context->render(batch);
34153469 }
34163470
3417− bool updateViewFrustum = false;
3418− loadViewFrustum(_mirrorCamera, _viewFrustum);
3471+ // loadViewFrustum(_mirrorCamera, _viewFrustum);
34193472
34203473 // render rear mirror view
34213474 displaySide(renderArgs, _mirrorCamera, true, billboard);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t