From 1a526641b71e6394ed6fac99c5029d8e800a3fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Wed, 28 Sep 2016 14:29:05 +0300 Subject: [PATCH] UI|Client: Draw the game HUD layer in ViewCompositor --- .../apps/client/include/ui/viewcompositor.h | 2 +- .../apps/client/src/ui/viewcompositor.cpp | 66 ++++++++++++++++--- .../apps/client/src/ui/widgets/gamewidget.cpp | 3 +- 3 files changed, 59 insertions(+), 12 deletions(-) diff --git a/doomsday/apps/client/include/ui/viewcompositor.h b/doomsday/apps/client/include/ui/viewcompositor.h index b7b2e0578f..35528662f6 100644 --- a/doomsday/apps/client/include/ui/viewcompositor.h +++ b/doomsday/apps/client/include/ui/viewcompositor.h @@ -78,7 +78,7 @@ class ViewCompositor * * @param rect Rectangle in which to draw the layers. */ - void drawCompositedLayers(de::Rectanglei const &rect); + void drawCompositedLayers(); private: DENG2_PRIVATE(d) diff --git a/doomsday/apps/client/src/ui/viewcompositor.cpp b/doomsday/apps/client/src/ui/viewcompositor.cpp index 9e985b07a0..4101b74eeb 100644 --- a/doomsday/apps/client/src/ui/viewcompositor.cpp +++ b/doomsday/apps/client/src/ui/viewcompositor.cpp @@ -157,7 +157,7 @@ GLTextureFramebuffer const &ViewCompositor::gameView() const return d->viewFramebuf; } -void ViewCompositor::drawCompositedLayers(Rectanglei const &rect) +void ViewCompositor::drawCompositedLayers() { DENG2_ASSERT(d->frameDrawable.isReady()); @@ -168,31 +168,79 @@ void ViewCompositor::drawCompositedLayers(Rectanglei const &rect) .setCull (gl::None); Rectanglei const view3D = R_Console3DViewRect(d->playerNum); - - // First the game view (using the previously rendered texture). - d->uFrameTex = d->viewFramebuf.colorTexture(); - d->uMvpMatrix = ClientWindow::main().root().projMatrix2D() * - Matrix4f::scaleThenTranslate(view3D.size(), view3D.topLeft); - d->frameDrawable.draw(); + auto const oldDisplayPlayer = displayPlayer; // View border around the game view. - auto const oldDisplayPlayer = displayPlayer; displayPlayer = d->playerNum; R_UseViewPort(d->playerNum); - //R_RenderPlayerViewBorder(); + // 3D world view (using the previously rendered texture). + { + d->uFrameTex = d->viewFramebuf.colorTexture(); + d->uMvpMatrix = ClientWindow::main().root().projMatrix2D() * + Matrix4f::scaleThenTranslate(view3D.size(), view3D.topLeft); + d->frameDrawable.draw(); + } + + // Some of the layers use OpenGL 2 drawing code. + DGL_MatrixMode(DGL_PROJECTION); + DGL_PushMatrix(); + LIBGUI_GL.glLoadMatrixf(ClientWindow::main().root().projMatrix2D().values()); + + // Fill around a scaled-down 3D view. The border is not visible if the 3D view + // covers the entire area. + { + R_RenderPlayerViewBorder(); + } // Game HUD. + { + /// @todo HUD rendering probably doesn't need the vdWindow. + + auto const *vp = R_CurrentViewPort(); + RectRaw vpGeometry(vp->geometry.topLeft.x, vp->geometry.topLeft.y, + vp->geometry.width(), vp->geometry.height()); + + viewdata_t const *vd = &DD_Player(d->playerNum)->viewport(); + RectRaw vdWindow(vd->window.topLeft.x, vd->window.topLeft.y, + vd->window.width(), vd->window.height()); + + if (gx.DrawViewPort) + { + GLState::current() + .setBlend(true) + .apply(); + + gx.DrawViewPort(P_ConsoleToLocal(d->playerNum), + &vpGeometry, + &vdWindow, + displayPlayer, + /* layer: */ 1); + } + } // Finale. + { + + } // Non-map game screens. + { + + } // Legacy engine/debug UIs (stuff from the old Net_Drawer). + { + } + + // Restore the default drawing state. R_UseViewPort(nullptr); displayPlayer = oldDisplayPlayer; + DGL_MatrixMode(DGL_PROJECTION); + DGL_PopMatrix(); + GLState::pop().apply(); } diff --git a/doomsday/apps/client/src/ui/widgets/gamewidget.cpp b/doomsday/apps/client/src/ui/widgets/gamewidget.cpp index f76dbfe12f..c2ffb415ba 100644 --- a/doomsday/apps/client/src/ui/widgets/gamewidget.cpp +++ b/doomsday/apps/client/src/ui/widgets/gamewidget.cpp @@ -91,7 +91,7 @@ DENG2_PIMPL(GameWidget) { ClientApp::app().forLocalPlayers([this] (ClientPlayer &player) { - player.viewCompositor().drawCompositedLayers(self.rule().recti()); + player.viewCompositor().drawCompositedLayers(); return LoopContinue; }); } @@ -157,7 +157,6 @@ GameWidget::GameWidget(String const &name) void GameWidget::glApplyViewport(Rectanglei const &rect) { - qDebug() << "glApplyViewport:" << rect.asText(); GLState::current() .setNormalizedViewport(normalizedRect(rect)) .apply();