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
875 PerformanceWarning warn(showWarnings, "Application::paintGL()");875 PerformanceWarning warn(showWarnings, "Application::paintGL()");
876 resizeGL();876 resizeGL();
877 877
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 }
878 905
879 {906 {
880 PerformanceTimer perfTimer("renderOverlay");907 PerformanceTimer perfTimer("renderOverlay");
@@ -936,7 +963,7 @@ void Application::paintGL() { · 55 unmodified lines
936 }963 }
937 964
938 // Sync up the View Furstum with the camera965 // Sync up the View Furstum with the camera
939 loadViewFrustum(_myCamera, _viewFrustum);966 // loadViewFrustum(_myCamera, _viewFrustum);
940 967
941 968
942 renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE;969 renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE;
@@ -974,19 +1001,17 @@ void Application::paintGL() { · 31 unmodified lines
974 1001
975 displaySide(&renderArgs, _myCamera);1002 displaySide(&renderArgs, _myCamera);
976 1003
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
983 {1004 {
984 auto geometryCache = DependencyManager::get<GeometryCache>();1005 auto geometryCache = DependencyManager::get<GeometryCache>();
985 auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();1006 auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
986 gpu::Batch batch;1007 gpu::Batch batch;
987 batch.blit(primaryFbo, glm::ivec4(0, 0, _renderResolution.x, _renderResolution.y),1008 batch.blit(primaryFbo, glm::ivec4(0, 0, _renderResolution.x, _renderResolution.y),
988 nullptr, glm::ivec4(0, 0, _glWidget->getDeviceSize().width(), _glWidget->getDeviceSize().height()));1009 nullptr, glm::ivec4(0, 0, _glWidget->getDeviceSize().width(), _glWidget->getDeviceSize().height()));
1010
1011 batch.setFramebuffer(nullptr);
1012
989 renderArgs._context->render(batch);1013 renderArgs._context->render(batch);
1014
990 }1015 }
991 1016
992 _compositor.displayOverlayTexture(&renderArgs);1017 _compositor.displayOverlayTexture(&renderArgs);
@@ -2958,7 +2983,7 @@ PickRay Application::computePickRay(float x, float y) const { · 1965 unmodified lines
2958}2983}
2959 2984
2960QImage Application::renderAvatarBillboard(RenderArgs* renderArgs) {2985QImage Application::renderAvatarBillboard(RenderArgs* renderArgs) {
2961 auto primaryFramebuffer = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();2986/* auto primaryFramebuffer = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
2962 glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFramebuffer));2987 glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFramebuffer));
2963 2988
2964 // clear the alpha channel so the background is transparent2989 // clear the alpha channel so the background is transparent
@@ -2966,17 +2991,41 @@ QImage Application::renderAvatarBillboard(RenderArgs* renderArgs) { · 1 unmodified line
2966 glClearColor(0.0, 0.0, 0.0, 0.0);2991 glClearColor(0.0, 0.0, 0.0, 0.0);
2967 glClear(GL_COLOR_BUFFER_BIT);2992 glClear(GL_COLOR_BUFFER_BIT);
2968 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);2993 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();
2969 3001
2970 const int BILLBOARD_SIZE = 64;3002 {
2971 // TODO: Pass a RenderArgs to renderAvatarBillboard3003 gpu::Batch batch;
2972 renderRearViewMirror(renderArgs, QRect(0, _glWidget->getDeviceHeight() - BILLBOARD_SIZE,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,
2973 BILLBOARD_SIZE, BILLBOARD_SIZE),3010 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
2975 QImage image(BILLBOARD_SIZE, BILLBOARD_SIZE, QImage::Format_ARGB32);3024 QImage image(BILLBOARD_SIZE, BILLBOARD_SIZE, QImage::Format_ARGB32);
3025 glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFbo));
2976 glReadPixels(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE, GL_BGRA, GL_UNSIGNED_BYTE, image.bits());3026 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
2979 glBindFramebuffer(GL_FRAMEBUFFER, 0);3027 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3028
2980 return image;3029 return image;
2981}3030}
2982 3031
@@ -3390,13 +3439,18 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi · 407 unmodified lines
3390 gpu::Vec4i viewport;3439 gpu::Vec4i viewport;
3391 if (billboard) {3440 if (billboard) {
3392 QSize size = DependencyManager::get<FramebufferCache>()->getFrameBufferSize();3441 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());
3394 } else {3444 } else {
3395 // if not rendering the billboard, the region is in device independent coordinates; must convert to device3445 // if not rendering the billboard, the region is in device independent coordinates; must convert to device
3396 QSize size = DependencyManager::get<FramebufferCache>()->getFrameBufferSize();3446 QSize size = DependencyManager::get<FramebufferCache>()->getFrameBufferSize();
3397 float ratio = (float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale();3447 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;3448 int x = region.x() * ratio;
3399 viewport = gpu::Vec4i(x, size.height() - y - height, width, height);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);
3400 }3454 }
3401 renderArgs->_viewport = viewport;3455 renderArgs->_viewport = viewport;
3402 3456
@@ -3414,8 +3468,7 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi · 11 unmodified lines
3414 renderArgs->_context->render(batch);3468 renderArgs->_context->render(batch);
3415 }3469 }
3416 3470
3417 bool updateViewFrustum = false;3471 // loadViewFrustum(_mirrorCamera, _viewFrustum);
3418 loadViewFrustum(_mirrorCamera, _viewFrustum);
3419 3472
3420 // render rear mirror view3473 // render rear mirror view
3421 displaySide(renderArgs, _mirrorCamera, true, billboard);3474 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