PageRenderTime 41ms CodeModel.GetById 14ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/lllocalcliprect.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 110 lines | 64 code | 14 blank | 32 comment | 5 complexity | d12ea4052be4c664586e7ab98175275a MD5 | raw file
  1/** 
  2* @file lllocalcliprect.cpp
  3*
  4* $LicenseInfo:firstyear=2009&license=viewerlgpl$
  5* Second Life Viewer Source Code
  6* Copyright (C) 2010, Linden Research, Inc.
  7* 
  8* This library is free software; you can redistribute it and/or
  9* modify it under the terms of the GNU Lesser General Public
 10* License as published by the Free Software Foundation;
 11* version 2.1 of the License only.
 12* 
 13* This library is distributed in the hope that it will be useful,
 14* but WITHOUT ANY WARRANTY; without even the implied warranty of
 15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 16* Lesser General Public License for more details.
 17* 
 18* You should have received a copy of the GNU Lesser General Public
 19* License along with this library; if not, write to the Free Software
 20* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 21* 
 22* Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 23* $/LicenseInfo$
 24*/
 25#include "linden_common.h"
 26
 27#include "lllocalcliprect.h"
 28
 29#include "llfontgl.h"
 30#include "llui.h"
 31
 32/*static*/ std::stack<LLRect> LLScreenClipRect::sClipRectStack;
 33
 34
 35LLScreenClipRect::LLScreenClipRect(const LLRect& rect, BOOL enabled)
 36:	mScissorState(GL_SCISSOR_TEST),
 37	mEnabled(enabled)
 38{
 39	if (mEnabled)
 40	{
 41		pushClipRect(rect);
 42		mScissorState.setEnabled(!sClipRectStack.empty());
 43		updateScissorRegion();
 44	}
 45}
 46
 47LLScreenClipRect::~LLScreenClipRect()
 48{
 49	if (mEnabled)
 50	{
 51		popClipRect();
 52		updateScissorRegion();
 53	}
 54}
 55
 56//static 
 57void LLScreenClipRect::pushClipRect(const LLRect& rect)
 58{
 59	LLRect combined_clip_rect = rect;
 60	if (!sClipRectStack.empty())
 61	{
 62		LLRect top = sClipRectStack.top();
 63		combined_clip_rect.intersectWith(top);
 64
 65		if(combined_clip_rect.isEmpty())
 66		{
 67			// avoid artifacts where zero area rects show up as lines
 68			combined_clip_rect = LLRect::null;
 69		}
 70	}
 71	sClipRectStack.push(combined_clip_rect);
 72}
 73
 74//static 
 75void LLScreenClipRect::popClipRect()
 76{
 77	sClipRectStack.pop();
 78}
 79
 80//static
 81void LLScreenClipRect::updateScissorRegion()
 82{
 83	if (sClipRectStack.empty()) return;
 84
 85	// finish any deferred calls in the old clipping region
 86	gGL.flush();
 87
 88	LLRect rect = sClipRectStack.top();
 89	stop_glerror();
 90	S32 x,y,w,h;
 91	x = llfloor(rect.mLeft * LLUI::sGLScaleFactor.mV[VX]);
 92	y = llfloor(rect.mBottom * LLUI::sGLScaleFactor.mV[VY]);
 93	w = llmax(0, llceil(rect.getWidth() * LLUI::sGLScaleFactor.mV[VX])) + 1;
 94	h = llmax(0, llceil(rect.getHeight() * LLUI::sGLScaleFactor.mV[VY])) + 1;
 95	glScissor( x,y,w,h );
 96	stop_glerror();
 97}
 98
 99//---------------------------------------------------------------------------
100// LLLocalClipRect
101//---------------------------------------------------------------------------
102LLLocalClipRect::LLLocalClipRect(const LLRect& rect, BOOL enabled /* = TRUE */)
103:	LLScreenClipRect(LLRect(rect.mLeft + LLFontGL::sCurOrigin.mX, 
104					rect.mTop + LLFontGL::sCurOrigin.mY, 
105					rect.mRight + LLFontGL::sCurOrigin.mX, 
106					rect.mBottom + LLFontGL::sCurOrigin.mY), enabled)
107{}
108
109LLLocalClipRect::~LLLocalClipRect()
110{}