Skip to content

Commit

Permalink
Client: Manage GL viewport exclusively with libgui GLState
Browse files Browse the repository at this point in the history
This allows LegacyWidget to use its own viewport without disrupting
the rest of the UI.
  • Loading branch information
skyjake committed Sep 6, 2013
1 parent 0436855 commit 7c9f64a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
12 changes: 9 additions & 3 deletions doomsday/client/src/gl/gl_main.cpp
Expand Up @@ -47,6 +47,7 @@
#include "api_render.h"

#include <de/DisplayMode>
#include <de/GLState>

D_CMD(Fog);
D_CMD(SetBPP);
Expand Down Expand Up @@ -499,7 +500,8 @@ void GL_SwitchTo3DState(boolean push_state, viewport_t const *port, viewdata_t c
viewpy = port->geometry.origin.y + viewData->window.origin.y;
viewpw = MIN_OF(port->geometry.size.width, viewData->window.size.width);
viewph = MIN_OF(port->geometry.size.height, viewData->window.size.height);
glViewport(viewpx, FLIP(viewpy + viewph - 1), viewpw, viewph);
//glViewport(viewpx, FLIP(viewpy + viewph - 1), viewpw, viewph);
GLState::top().setViewport(Rectangleui(viewpx, viewpy, viewpw, viewph)).apply();

// The 3D projection matrix.
GL_ProjectionMatrix();
Expand Down Expand Up @@ -562,8 +564,12 @@ void GL_Restore2DState(int step, viewport_t const *port, viewdata_t const *viewD
break; }

case 2: // After Restore Step 2 we're back in 2D rendering mode.
glViewport(currentView.geometry.origin.x, FLIP(currentView.geometry.origin.y + currentView.geometry.size.height - 1),
currentView.geometry.size.width, currentView.geometry.size.height);
//glViewport(currentView.geometry.origin.x, FLIP(currentView.geometry.origin.y + currentView.geometry.size.height - 1),
// currentView.geometry.size.width, currentView.geometry.size.height);
GLState::top().setViewport(Rectangleui(currentView.geometry.origin.x,
currentView.geometry.origin.y,
currentView.geometry.size.width,
currentView.geometry.size.height));
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
Expand Down
25 changes: 14 additions & 11 deletions doomsday/client/src/render/r_main.cpp
Expand Up @@ -35,6 +35,11 @@

#ifdef __CLIENT__
# include "edit_bias.h"
# include "api_render.h"
# include "render/r_main.h"
# include "render/vignette.h"
# include "render/vissprite.h"
# include <de/GLState>
#endif
#include "gl/svg.h"

Expand All @@ -43,13 +48,6 @@
#include "world/thinkers.h"
#include "BspLeaf"

#include "render/vignette.h"
#include "render/vissprite.h"

#include "api_render.h"

#include "render/r_main.h"

using namespace de;

#ifdef LIBDENG_CAMERA_MOVEMENT_ANALYSIS
Expand Down Expand Up @@ -919,15 +917,20 @@ void R_UseViewPort(viewport_t *vp)
if(!vp)
{
currentViewport = NULL;
glViewport(0, FLIP(0 + DENG_GAMEVIEW_HEIGHT - 1),
DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT);
//glViewport(0, FLIP(0 + DENG_GAMEVIEW_HEIGHT - 1),
// DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT);
GLState::top().setViewport(Rectangleui(0, 0, DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT)).apply();
}
else
{
currentViewport = vp;
glViewport(vp->geometry.origin.x,
/*glViewport(vp->geometry.origin.x,
FLIP(vp->geometry.origin.y + vp->geometry.size.height - 1),
vp->geometry.size.width, vp->geometry.size.height);
vp->geometry.size.width, vp->geometry.size.height);*/
GLState::top().setViewport(Rectangleui(vp->geometry.origin.x,
vp->geometry.origin.y,
vp->geometry.size.width,
vp->geometry.size.height)).apply();
}
}

Expand Down
3 changes: 2 additions & 1 deletion doomsday/client/src/ui/clientwindow.cpp
Expand Up @@ -424,7 +424,8 @@ void ClientWindow::canvasGLReady(Canvas &canvas)
d->root.find(LEGACY_WIDGET_NAME)->enable();

// Configure a viewport immediately.
glViewport(0, FLIP(0 + canvas.height() - 1), canvas.width(), canvas.height());
//glViewport(0, FLIP(0 + canvas.height() - 1), canvas.width(), canvas.height());
GLState::top().setViewport(Rectangleui(0, 0, canvas.width(), canvas.height())).apply();

LOG_DEBUG("LegacyWidget enabled");

Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/src/ui/widgets/busywidget.cpp
Expand Up @@ -90,6 +90,7 @@ void BusyWidget::viewResized()
{
GuiWidget::viewResized();

#if 0
if(!BusyMode_Active() || isDisabled() || Sys_IsShuttingDown()) return;

ClientWindow::main().glActivate(); // needed for legacy stuff
Expand All @@ -108,6 +109,7 @@ void BusyWidget::viewResized()
{
UI_UpdatePageLayout();
}
#endif
}

void BusyWidget::update()
Expand Down
5 changes: 5 additions & 0 deletions doomsday/client/src/ui/widgets/legacywidget.cpp
Expand Up @@ -222,8 +222,13 @@ void LegacyWidget::drawContent()
GL_Init2DState();
#endif

GLState::push();

d->draw();

GLState::considerNativeStateUndefined();
GLState::pop();

#if 0
glPopClientAttrib();
glPopAttrib();
Expand Down

0 comments on commit 7c9f64a

Please sign in to comment.