Skip to content

Commit

Permalink
Client|UI|GL: Player view rendered in final size (all scaling factore…
Browse files Browse the repository at this point in the history
…d in)

Rather than using a viewport to restrict the game view to a smaller
section of the framebuffer, the player view is now rendered into an
appropriately sized texture. The layer composition then positions
the view texture as needed considering the view window scaling.
  • Loading branch information
skyjake committed Sep 28, 2016
1 parent c90e141 commit a8df58b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 24 deletions.
7 changes: 7 additions & 0 deletions doomsday/apps/client/include/render/viewports.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ void R_UseViewPort(viewport_t const *vp);

void R_UseViewPort(int consoleNum);

/**
* Determines the location of the viewport of a player.
* @param console Player number.
* @return View rectangle in UI coordinates.
*/
de::Rectanglei R_ConsoleViewRect(int console);

void R_UpdateViewer(int consoleNum);

void R_ResetViewer();
Expand Down
13 changes: 8 additions & 5 deletions doomsday/apps/client/src/gl/gl_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,16 @@ void GL_SwitchTo3DState(dd_bool pushState, viewport_t const *port, viewdata_t co

std::memcpy(&currentView, port, sizeof(currentView));

viewpx = port->geometry.topLeft.x + viewData->window.topLeft.x;
viewpy = port->geometry.topLeft.y + viewData->window.topLeft.y;
//viewpx = port->geometry.topLeft.x + viewData->window.topLeft.x;
//viewpy = port->geometry.topLeft.y + viewData->window.topLeft.y;

viewpx = 0;
viewpy = 0;
viewpw = de::min(port->geometry.width(), viewData->window.width());
viewph = de::min(port->geometry.height(), viewData->window.height());

ClientWindow::main().game().glApplyViewport(Rectanglei::fromSize(Vector2i(viewpx, viewpy),
Vector2ui(viewpw, viewph)));
/*ClientWindow::main().game().glApplyViewport(Rectanglei::fromSize(Vector2i(viewpx, viewpy),
Vector2ui(viewpw, viewph)));*/

// The 3D projection matrix.
GL_ProjectionMatrix();
Expand Down Expand Up @@ -496,7 +499,7 @@ void GL_Restore2DState(dint step, viewport_t const *port, viewdata_t const *view
break; }

case 2: // After Restore Step 2 we're back in 2D rendering mode.
ClientWindow::main().game().glApplyViewport(currentView.geometry);
//ClientWindow::main().game().glApplyViewport(currentView.geometry);
LIBGUI_GL.glMatrixMode(GL_PROJECTION);
LIBGUI_GL.glPopMatrix();
LIBGUI_GL.glMatrixMode(GL_MODELVIEW);
Expand Down
40 changes: 27 additions & 13 deletions doomsday/apps/client/src/render/viewports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,33 @@ void R_UseViewPort(viewport_t const *vp)
}
}

void R_UseViewPort(int consoleNum)
{
int local = P_ConsoleToLocal(consoleNum);
if (local >= 0)
{
R_UseViewPort(&viewportOfLocalPlayer[local]);
}
else
{
R_UseViewPort(nullptr);
}
}

Rectanglei R_ConsoleViewRect(int console)
{
int local = P_ConsoleToLocal(console);
if (local < 0) return Rectanglei();

auto const &pv = DD_Player(console)->viewport();
auto const &port = viewportOfLocalPlayer[local];

return Rectanglei(port.geometry.topLeft.x + pv.window.topLeft.x,
port.geometry.topLeft.y + pv.window.topLeft.y,
de::min(port.geometry.width(), pv.window.width()),
de::min(port.geometry.height(), pv.window.height()));
}

viewport_t const *R_CurrentViewPort()
{
return currentViewport;
Expand Down Expand Up @@ -1493,16 +1520,3 @@ void Viewports_Register()

C_CMD("viewgrid", "ii", ViewGrid);
}

void R_UseViewPort(int consoleNum)
{
int local = P_ConsoleToLocal(consoleNum);
if (local >= 0)
{
R_UseViewPort(&viewportOfLocalPlayer[local]);
}
else
{
R_UseViewPort(nullptr);
}
}
20 changes: 14 additions & 6 deletions doomsday/apps/client/src/ui/viewcompositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,19 @@ DENG2_PIMPL(ViewCompositor)

GLFramebuffer::Size framebufferSize() const
{
RectRaw geom;
R_ViewPortGeometry(playerNum, &geom);
GLFramebuffer::Size size { uint(geom.size.width), uint(geom.size.height) };
//RectRaw geom;
//R_ViewPortGeometry(playerNum, &geom);
Rectanglei const playerView = R_ConsoleViewRect(playerNum);
GLFramebuffer::Size size = playerView.size();

// Apply game view scaling.
// Game view scaling for vanilla emulation.
//viewdata_t const &vd = DD_Player(playerNum)->viewport();

// Apply pixel density.
/*Rectanglei vdWindow(vd.window.topLeft.x, vd.window.topLeft.y,
vd.window.width(), vd.window.height());*/
//qDebug() << vdWindow.asText();

// Pixel density.
size *= scaleFactor();

return size;
Expand Down Expand Up @@ -171,10 +177,12 @@ void ViewCompositor::drawCompositedLayers(Rectanglei const &rect)
.setDepthTest(false)
.setCull (gl::None);

Rectanglei const playerView = R_ConsoleViewRect(d->playerNum);

// First the game view (using the previously rendered texture).
d->uFrameTex = d->viewFramebuf.colorTexture();
d->uMvpMatrix = ClientWindow::main().root().projMatrix2D() *
Matrix4f::scaleThenTranslate(rect.size(), rect.topLeft);
Matrix4f::scaleThenTranslate(playerView.size(), playerView.topLeft);
d->frameDrawable.draw();

// View border around the game view.
Expand Down
1 change: 1 addition & 0 deletions doomsday/apps/client/src/ui/widgets/gamewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ GameWidget::GameWidget(String const &name)

void GameWidget::glApplyViewport(Rectanglei const &rect)
{
qDebug() << "glApplyViewport:" << rect.asText();
GLState::current()
.setNormalizedViewport(normalizedRect(rect))
.apply();
Expand Down

0 comments on commit a8df58b

Please sign in to comment.