diff options
Diffstat (limited to 'indra/llrender/llrender.cpp')
-rw-r--r-- | indra/llrender/llrender.cpp | 176 |
1 files changed, 116 insertions, 60 deletions
diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index a829616df2..70601663e6 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -2,25 +2,31 @@ * @file llrender.cpp * @brief LLRender implementation * - * $LicenseInfo:firstyear=2001&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. + * $LicenseInfo:firstyear=2001&license=viewergpl$ + * + * Copyright (c) 2001-2009, Linden Research, Inc. * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. + * Second Life Viewer Source Code + * The source code in this file ("Source Code") is provided by Linden Lab + * to you under the terms of the GNU General Public License, version 2.0 + * ("GPL"), unless you have obtained a separate licensing agreement + * ("Other License"), formally executed by you and Linden Lab. Terms of + * the GPL can be found in doc/GPL-license.txt in this distribution, or + * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 * - * This library 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 - * Lesser General Public License for more details. + * There are special exceptions to the terms and conditions of the GPL as + * it is applied to this Source Code. View the full text of the exception + * in the file doc/FLOSS-exception.txt in this software distribution, or + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * By copying, modifying or distributing this software, you acknowledge + * that you have read and understood your obligations described above, + * and agree to abide by those obligations. * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO + * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, + * COMPLETENESS OR PERFORMANCE. * $/LicenseInfo$ */ @@ -33,6 +39,7 @@ #include "llimagegl.h" #include "llrendertarget.h" #include "lltexture.h" +#include "llvector4a.h" LLRender gGL; @@ -47,6 +54,7 @@ U32 LLRender::sUICalls = 0; U32 LLRender::sUIVerts = 0; static const U32 LL_NUM_TEXTURE_LAYERS = 16; +static const U32 LL_MAX_UI_STACK_DEPTH = 32; static GLenum sGLTextureType[] = { @@ -159,6 +167,7 @@ void LLTexUnit::enable(eTextureType type) if ( (mCurrTexType != type || gGL.mDirty) && (type != TT_NONE) ) { activate(); + if (mCurrTexType != TT_NONE && !gGL.mDirty) { disable(); // Force a disable of a previous texture type if it's enabled. @@ -750,14 +759,27 @@ LLRender::LLRender() mCount(0), mMode(LLRender::TRIANGLES), mCurrTextureUnitIndex(0), - mMaxAnisotropy(0.f) + mMaxAnisotropy(0.f), + mUIStackDepth(0) { mBuffer = new LLVertexBuffer(immediate_mask, 0); mBuffer->allocateBuffer(4096, 0, TRUE); - mBuffer->getVertexStrider(mVerticesp); - mBuffer->getTexCoord0Strider(mTexcoordsp); - mBuffer->getColorStrider(mColorsp); - + + LLStrider<LLVector3> vert; + LLStrider<LLVector2> tc; + LLStrider<LLColor4U> color; + + mBuffer->getVertexStrider(vert); + mBuffer->getTexCoord0Strider(tc); + mBuffer->getColorStrider(color); + + mVerticesp = (LLVector4a*) vert.get(); + mTexcoordsp = tc.get(); + mColorsp = color.get(); + + mUIOffset = (LLVector4a*) ll_aligned_malloc_16(LL_MAX_UI_STACK_DEPTH*sizeof(LLVector4a)); + mUIScale = (LLVector4a*) ll_aligned_malloc_16(LL_MAX_UI_STACK_DEPTH*sizeof(LLVector4a)); + mTexUnits.reserve(LL_NUM_TEXTURE_LAYERS); for (U32 i = 0; i < LL_NUM_TEXTURE_LAYERS; i++) { @@ -772,8 +794,11 @@ LLRender::LLRender() mCurrAlphaFunc = CF_DEFAULT; mCurrAlphaFuncVal = 0.01f; - mCurrBlendSFactor = BF_UNDEF; - mCurrBlendDFactor = BF_UNDEF; + + mCurrBlendColorSFactor = BF_UNDEF; + mCurrBlendAlphaSFactor = BF_UNDEF; + mCurrBlendColorDFactor = BF_UNDEF; + mCurrBlendAlphaDFactor = BF_UNDEF; } LLRender::~LLRender() @@ -790,6 +815,11 @@ void LLRender::shutdown() mTexUnits.clear(); delete mDummyTexUnit; mDummyTexUnit = NULL; + + ll_aligned_free_16(mUIOffset); + mUIOffset = NULL; + ll_aligned_free_16(mUIScale); + mUIScale = NULL; } void LLRender::refreshState(void) @@ -838,84 +868,83 @@ void LLRender::popMatrix() void LLRender::translateUI(F32 x, F32 y, F32 z) { - if (mUIOffset.empty()) + if (mUIStackDepth == 0) { llerrs << "Need to push a UI translation frame before offsetting" << llendl; } - mUIOffset.front().mV[0] += x; - mUIOffset.front().mV[1] += y; - mUIOffset.front().mV[2] += z; + LLVector4a trans(x,y,z); + mUIOffset[mUIStackDepth-1].add(trans); } void LLRender::scaleUI(F32 x, F32 y, F32 z) { - if (mUIScale.empty()) + if (mUIStackDepth == 0) { llerrs << "Need to push a UI transformation frame before scaling." << llendl; } - mUIScale.front().scaleVec(LLVector3(x,y,z)); + LLVector4a scale(x,y,z); + mUIScale[mUIStackDepth-1].mul(scale); } void LLRender::pushUIMatrix() { - if (mUIOffset.empty()) - { - mUIOffset.push_front(LLVector3(0,0,0)); - } - else + if (mUIStackDepth == 0) { - mUIOffset.push_front(mUIOffset.front()); + mUIOffset[0].clear(); + mUIScale[0].splat(1.f); } - - if (mUIScale.empty()) + else if (mUIStackDepth < LL_MAX_UI_STACK_DEPTH) { - mUIScale.push_front(LLVector3(1,1,1)); + mUIOffset[mUIStackDepth] = mUIOffset[mUIStackDepth-1]; + mUIScale[mUIStackDepth] = mUIScale[mUIStackDepth-1]; } else { - mUIScale.push_front(mUIScale.front()); + llerrs << "Blown UI matrix stack." << llendl; } + + ++mUIStackDepth; + } void LLRender::popUIMatrix() { - if (mUIOffset.empty()) + if (mUIStackDepth == 0) { llerrs << "UI offset stack blown." << llendl; } - mUIOffset.pop_front(); - mUIScale.pop_front(); + --mUIStackDepth; } LLVector3 LLRender::getUITranslation() { - if (mUIOffset.empty()) + if (mUIStackDepth == 0) { llerrs << "UI offset stack empty." << llendl; } - return mUIOffset.front(); + return LLVector3(mUIOffset[mUIStackDepth-1].getF32()); } LLVector3 LLRender::getUIScale() { - if (mUIScale.empty()) + if (mUIStackDepth == 0) { llerrs << "UI scale stack empty." << llendl; } - return mUIScale.front(); + return LLVector3(mUIScale[mUIStackDepth-1].getF32()); } void LLRender::loadUIIdentity() { - if (mUIOffset.empty()) + if (mUIStackDepth == 0) { llerrs << "Need to push UI translation frame before clearing offset." << llendl; } - mUIOffset.front().setVec(0,0,0); - mUIScale.front().setVec(1,1,1); + mUIOffset[mUIStackDepth-1].clear(); + mUIScale[mUIStackDepth-1].splat(1.f); } void LLRender::setColorMask(bool writeColor, bool writeAlpha) @@ -989,15 +1018,44 @@ void LLRender::blendFunc(eBlendFactor sfactor, eBlendFactor dfactor) { llassert(sfactor < BF_UNDEF); llassert(dfactor < BF_UNDEF); - if (mCurrBlendSFactor != sfactor || mCurrBlendDFactor != dfactor) + if (mCurrBlendColorSFactor != sfactor || mCurrBlendColorDFactor != dfactor || + mCurrBlendAlphaSFactor != sfactor || mCurrBlendAlphaDFactor != dfactor) { - mCurrBlendSFactor = sfactor; - mCurrBlendDFactor = dfactor; + mCurrBlendColorSFactor = sfactor; + mCurrBlendAlphaSFactor = sfactor; + mCurrBlendColorDFactor = dfactor; + mCurrBlendAlphaDFactor = dfactor; flush(); glBlendFunc(sGLBlendFactor[sfactor], sGLBlendFactor[dfactor]); } } +void LLRender::blendFunc(eBlendFactor color_sfactor, eBlendFactor color_dfactor, + eBlendFactor alpha_sfactor, eBlendFactor alpha_dfactor) +{ + llassert(color_sfactor < BF_UNDEF); + llassert(color_dfactor < BF_UNDEF); + llassert(alpha_sfactor < BF_UNDEF); + llassert(alpha_dfactor < BF_UNDEF); + if (!gGLManager.mHasBlendFuncSeparate) + { + LL_WARNS_ONCE("render") << "no glBlendFuncSeparateEXT(), using color-only blend func" << llendl; + blendFunc(color_sfactor, color_dfactor); + return; + } + if (mCurrBlendColorSFactor != color_sfactor || mCurrBlendColorDFactor != color_dfactor || + mCurrBlendAlphaSFactor != alpha_sfactor || mCurrBlendAlphaDFactor != alpha_dfactor) + { + mCurrBlendColorSFactor = color_sfactor; + mCurrBlendAlphaSFactor = alpha_sfactor; + mCurrBlendColorDFactor = color_dfactor; + mCurrBlendAlphaDFactor = alpha_dfactor; + flush(); + glBlendFuncSeparateEXT(sGLBlendFactor[color_sfactor], sGLBlendFactor[color_dfactor], + sGLBlendFactor[alpha_sfactor], sGLBlendFactor[alpha_dfactor]); + } +} + LLTexUnit* LLRender::getTexUnit(U32 index) { if (index < mTexUnits.size()) @@ -1115,7 +1173,7 @@ void LLRender::flush() } #endif - if (!mUIOffset.empty()) + if (mUIStackDepth > 0) { sUICalls++; sUIVerts += mCount; @@ -1167,24 +1225,22 @@ void LLRender::vertex3f(const GLfloat& x, const GLfloat& y, const GLfloat& z) return; } - if (mUIOffset.empty()) + LLVector3& v = reinterpret_cast<LLVector3&>(mVerticesp[mCount]); + v.set(x,y,z); + if (mUIStackDepth != 0) { - mVerticesp[mCount] = LLVector3(x,y,z); - } - else - { - LLVector3 vert = (LLVector3(x,y,z)+mUIOffset.front()).scaledVec(mUIScale.front()); - mVerticesp[mCount] = vert; + v += reinterpret_cast<LLVector3&>(mUIOffset[mUIStackDepth-1]); + v.scaleVec(reinterpret_cast<LLVector3&>(mUIScale[mUIStackDepth-1])); } mCount++; if (mCount < 4096) { - mVerticesp[mCount] = mVerticesp[mCount-1]; mColorsp[mCount] = mColorsp[mCount-1]; mTexcoordsp[mCount] = mTexcoordsp[mCount-1]; } } + void LLRender::vertex2i(const GLint& x, const GLint& y) { vertex3f((GLfloat) x, (GLfloat) y, 0); |