Skip to content

Commit

Permalink
libgui|GLState: Setting a normalized viewport
Browse files Browse the repository at this point in the history
A normalized viewport is useful when the actual root view is larger
or smaller than the render target. A normalized viewport is relative
to the render target size.
  • Loading branch information
skyjake committed Oct 25, 2013
1 parent 6ef1860 commit 9de82c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doomsday/libgui/include/de/gui/glstate.h
Expand Up @@ -110,6 +110,13 @@ class LIBGUI_PUBLIC GLState
GLState &setTarget(GLTarget &target);
GLState &setDefaultTarget();
GLState &setViewport(Rectangleui const &viewportRect);

/**
* Sets a viewport that is normalized within the current render target.
* @param normViewportRect Normalized viewport rectangle.
*/
GLState &setNormalizedViewport(Rectanglef const &normViewportRect);

GLState &setScissor(Rectanglei const &scissorRect);
GLState &setScissor(Rectangleui const &scissorRect);

Expand Down
10 changes: 10 additions & 0 deletions doomsday/libgui/src/glstate.cpp
Expand Up @@ -384,6 +384,16 @@ GLState &GLState::setViewport(Rectangleui const &viewportRect)
return *this;
}

GLState &GLState::setNormalizedViewport(Rectanglef const &normViewportRect)
{
GLTarget::Size const size = target().size();
Rectangleui vp(Vector2ui(normViewportRect.left() * size.x,
normViewportRect.top() * size.y),
Vector2ui(std::ceil(normViewportRect.right() * size.x),
std::ceil(normViewportRect.bottom() * size.y)));
return setViewport(vp);
}

GLState &GLState::setScissor(Rectanglei const &scissorRect)
{
return setScissor(scissorRect.toRectangleui());
Expand Down

0 comments on commit 9de82c6

Please sign in to comment.