Skip to content

Commit

Permalink
Refactor|Client: Began refactoring game view compositing
Browse files Browse the repository at this point in the history
Compositing the game view will be managed by ViewCompositor.
  • Loading branch information
skyjake committed Sep 24, 2016
1 parent 680b298 commit 42aad74
Show file tree
Hide file tree
Showing 14 changed files with 382 additions and 25 deletions.
1 change: 1 addition & 0 deletions doomsday/apps/api/api_render.h
Expand Up @@ -23,6 +23,7 @@

#include "apis.h"
#include "api_gl.h"
#include "dd_share.h"

DENG_API_TYPEDEF(Rend)
{
Expand Down
3 changes: 3 additions & 0 deletions doomsday/apps/client/include/clientplayer.h
Expand Up @@ -24,6 +24,7 @@
//#include "lzss.h" // legacy demo code

struct ConsoleEffectStack;
class ViewCompositor;
namespace render { class PlayerWeaponAnimator; }

/**
Expand Down Expand Up @@ -74,6 +75,8 @@ class ClientPlayer : public Player
public:
ClientPlayer();

ViewCompositor &viewCompositor();

viewdata_t &viewport();
viewdata_t const &viewport() const;

Expand Down
4 changes: 3 additions & 1 deletion doomsday/apps/client/include/render/viewports.h
Expand Up @@ -112,7 +112,9 @@ void R_ResetFrameCount();
/**
* Render all view ports in the viewport grid.
*/
void R_RenderViewPorts(ViewPortLayer layer);
//void R_RenderViewPorts(ViewPortLayer layer);

void R_RenderViewPort(int playerNum);

/**
* Render a blank view for the specified player.
Expand Down
87 changes: 87 additions & 0 deletions doomsday/apps/client/include/ui/viewcompositor.h
@@ -0,0 +1,87 @@
/** @file viewcompositor.h Game view compositor.
*
* @authors Copyright (c) 2016 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef DENG_CLIENT_UI_VIEWCOMPOSITOR_H
#define DENG_CLIENT_UI_VIEWCOMPOSITOR_H

#include <de/GLTextureFramebuffer>

/**
* Compositor for the game view.
*
* Owns a framebuffer for the player view and manages the compositing of the various
* view layers.
*
* The game view itself is stored in a texture, sized according to the view window
* (which may be scaled down for vanilla emulation) and renderer pixel density. I.e.,
* the view border is outside this view texture.
*
* Lens FX are rendered inside the player view framebuffer after 3D rendering has been
* completed and the color and depth textures are available.
*
* The finished game view texture is kept around until the next frame begins. It can be
* copied for savegames, etc. at any time.
*
* After Lens FX, the contents of the framebuffer are ready for compositing with
* additional layers, such as the view border and game HUD. These are drawn into the
* current framebuffer.
*/
class ViewCompositor
{
public:
ViewCompositor();

void setPlayerNumber(int playerNum);

/**
* Release all GL resources.
*/
void glDeinit();

/**
* Renders the contents of the game view framebuffer of a player. All enabled Lens FX
* are rendered after the @a renderFunc callback has finished.
*
* The framebuffer is available via gameView() at any time.
*
* @param playerNum Player number.
* @param renderFunc Callback that does the actual rendering.
*/
void renderGameView(std::function<void (int)> renderFunc);

de::GLTextureFramebuffer & gameView();
de::GLTextureFramebuffer const & gameView() const;

/**
* Draws the game view and additional view layers into the current render target,
* using the current GL viewport.
*
* Can be called at any time.
*
* Note that the existing contents of the game view framebuffer are used as-is; the
* game view needs to be redrawn separately beforehand, if needed.
*
* @param playerNum Player number.
*/
void drawCompositedLayers();

private:
DENG2_PRIVATE(d)
};

#endif // DENG_CLIENT_UI_VIEWCOMPOSITOR_H
11 changes: 7 additions & 4 deletions doomsday/apps/client/include/ui/widgets/gamewidget.h
Expand Up @@ -47,10 +47,13 @@ class GameWidget : public de::GuiWidget
void pause();

// Events.
void viewResized();
void update();
void drawContent();
bool handleEvent(de::Event const &event);
void viewResized() override;
void update() override;
void drawContent() override;
bool handleEvent(de::Event const &event) override;

protected:
void glDeinit() override;

private:
DENG2_PRIVATE(d)
Expand Down
14 changes: 14 additions & 0 deletions doomsday/apps/client/src/clientapp.cpp
Expand Up @@ -77,6 +77,7 @@
#include "ui/dialogs/alertdialog.h"
#include "ui/dialogs/packagecompatibilitydialog.h"
#include "ui/styledlogsinkformatter.h"
#include "ui/viewcompositor.h"
#include "render/rend_particle.h"
#include "render/r_draw.h"
#include "network/net_demo.h"
Expand Down Expand Up @@ -244,8 +245,15 @@ DENG2_PIMPL(ClientApp)
{
try
{
ClientWindow::main().glActivate(); // for GL deinit

LogBuffer::get().removeSink(logAlarm);

self.players().forAll([] (Player &p)
{
p.as<ClientPlayer>().viewCompositor().glDeinit();
return LoopContinue;
});
self.glDeinit();

Sys_Shutdown();
Expand Down Expand Up @@ -536,6 +544,12 @@ void ClientApp::initialize()
initSubsystems(); // loads Config
DoomsdayApp::initialize();

// Initialize players.
for (int i = 0; i < players().count(); ++i)
{
players().at(i).as<ClientPlayer>().viewCompositor().setPlayerNumber(i);
}

// Set up the log alerts (observes Config variables).
d->logAlarm.alertMask.init();

Expand Down
7 changes: 7 additions & 0 deletions doomsday/apps/client/src/clientplayer.cpp
Expand Up @@ -19,12 +19,14 @@
#include "clientplayer.h"
#include "render/consoleeffect.h"
#include "render/playerweaponanimator.h"
#include "ui/viewcompositor.h"
#include "def_share.h"

using namespace de;

DENG2_PIMPL(ClientPlayer)
{
ViewCompositor viewCompositor;
viewdata_t viewport;
ConsoleEffectStack effects;
render::PlayerWeaponAnimator playerWeaponAnimator;
Expand All @@ -50,6 +52,11 @@ ClientPlayer::ClientPlayer()
, d(new Impl(this))
{}

ViewCompositor &ClientPlayer::viewCompositor()
{
return d->viewCompositor;
}

viewdata_t &ClientPlayer::viewport()
{
return d->viewport;
Expand Down
94 changes: 88 additions & 6 deletions doomsday/apps/client/src/render/viewports.cpp
Expand Up @@ -699,17 +699,17 @@ void R_UseViewPort(viewport_t const *vp)
DENG_ASSERT_IN_MAIN_THREAD();
DENG_ASSERT_GL_CONTEXT_ACTIVE();

if(!vp)
if (!vp)
{
currentViewport = nullptr;
ClientWindow::main().game().glApplyViewport(
/*ClientWindow::main().game().glApplyViewport(
Rectanglei::fromSize(Vector2i(DENG_GAMEVIEW_X, DENG_GAMEVIEW_Y),
Vector2ui(DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT)));
Vector2ui(DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT)));*/
}
else
{
currentViewport = const_cast<viewport_t *>(vp);
ClientWindow::main().game().glApplyViewport(vp->geometry);
//ClientWindow::main().game().glApplyViewport(vp->geometry);
}
}

Expand Down Expand Up @@ -1044,6 +1044,87 @@ static void clearViewPorts()
LIBGUI_GL.glClear(bits);
}

void R_RenderViewPort(int playerNum)
{
int localNum = P_ConsoleToLocal(playerNum);
if (localNum < 0) return;

viewport_t const *vp = &viewportOfLocalPlayer[localNum];

DENG2_ASSERT(vp->console == playerNum);

dint const oldDisplay = displayPlayer;
displayPlayer = vp->console;
R_UseViewPort(vp);

if(displayPlayer < 0 || (DD_Player(displayPlayer)->publicData().flags & DDPF_UNDEFINED_ORIGIN))
{
// if(layer == Player3DViewLayer)
{
R_RenderBlankView();
}
return;
}

LIBGUI_GL.glMatrixMode(GL_PROJECTION);
LIBGUI_GL.glPushMatrix();
LIBGUI_GL.glLoadIdentity();

// Use an orthographic projection in real pixel dimensions.
LIBGUI_GL.glOrtho(0, vp->geometry.width(), vp->geometry.height(), 0, -1, 1);

viewdata_t const *vd = &DD_Player(vp->console)->viewport();
RectRaw vpGeometry(vp->geometry.topLeft.x, vp->geometry.topLeft.y,
vp->geometry.width(), vp->geometry.height());

RectRaw vdWindow(vd->window.topLeft.x, vd->window.topLeft.y,
vd->window.width(), vd->window.height());

//switch(layer)
//{
//case Player3DViewLayer:

R_UpdateViewer(vp->console);
//LensFx_BeginFrame(vp->console);

gx.DrawViewPort(localNum, &vpGeometry, &vdWindow, displayPlayer, 0/*layer #0*/);

//LensFx_EndFrame();
//break;

#if 0
case ViewBorderLayer:
R_RenderPlayerViewBorder();
break;

case HUDLayer:
gx.DrawViewPort(p, &vpGeometry, &vdWindow, displayPlayer, 1/*layer #1*/);
break;
}
#endif

restoreDefaultGLState();

LIBGUI_GL.glMatrixMode(GL_PROJECTION);
LIBGUI_GL.glPopMatrix();
//}

//if(layer == Player3DViewLayer)
//{
// Increment the internal frame count. This does not
// affect the window's FPS counter.
frameCount++;

// Keep reseting until a new sharp world has arrived.
if(resetNextViewer > 1) resetNextViewer = 0;
//}

// Restore things back to normal.
displayPlayer = oldDisplay;
R_UseViewPort(nullptr);
}

#if 0
void R_RenderViewPorts(ViewPortLayer layer)
{
dint oldDisplay = displayPlayer;
Expand Down Expand Up @@ -1090,9 +1171,9 @@ void R_RenderViewPorts(ViewPortLayer layer)
{
case Player3DViewLayer:
R_UpdateViewer(vp->console);
LensFx_BeginFrame(vp->console);
//LensFx_BeginFrame(vp->console);
gx.DrawViewPort(p, &vpGeometry, &vdWindow, displayPlayer, 0/*layer #0*/);
LensFx_EndFrame();
//LensFx_EndFrame();
break;

case ViewBorderLayer:
Expand Down Expand Up @@ -1125,6 +1206,7 @@ void R_RenderViewPorts(ViewPortLayer layer)
displayPlayer = oldDisplay;
R_UseViewPort(nullptr);
}
#endif

void R_ClearViewData()
{
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/client/src/ui/busyvisual.cpp
Expand Up @@ -151,6 +151,8 @@ static void sampleDoomWipe(void)

void Con_DrawTransition(void)
{
return; // TODO: re-enable with copied GameWidget FBO contents

if (isDedicated) return;
if (!Con_TransitionInProgress()) return;

Expand Down

0 comments on commit 42aad74

Please sign in to comment.