Newer
Older
/**
* @file llrender.cpp
* @brief LLRender implementation
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Copyright (C) 2010, 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.
* 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.
* 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
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "llrender.h"
#include "llvertexbuffer.h"
#include "llcubemap.h"
#include "llglslshader.h"
#include "llimagegl.h"
#include "llrendertarget.h"
LLRender gGL;
// Handy copies of last good GL matrices
F64 gGLModelView[16];
F64 gGLLastModelView[16];
F64 gGLProjection[16];
S32 gGLViewport[4];
Palmer Truelson
committed
U32 LLRender::sUICalls = 0;
U32 LLRender::sUIVerts = 0;
David Parks
committed
static const U32 LL_NUM_TEXTURE_LAYERS = 32;
David Parks
committed
static const U32 LL_NUM_LIGHT_UNITS = 8;
static GLenum sGLTextureType[] =
{
GL_TEXTURE_2D,
GL_TEXTURE_RECTANGLE_ARB,
David Parks
committed
GL_TEXTURE_CUBE_MAP_ARB,
GL_TEXTURE_2D_MULTISAMPLE
};
static GLint sGLAddressMode[] =
{
GL_REPEAT,
GL_MIRRORED_REPEAT,
GL_CLAMP_TO_EDGE
};
static GLenum sGLCompareFunc[] =
{
GL_NEVER,
GL_ALWAYS,
GL_LESS,
GL_LEQUAL,
GL_EQUAL,
GL_NOTEQUAL,
GL_GEQUAL,
GL_GREATER
};
const U32 immediate_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_TEXCOORD0;
static GLenum sGLBlendFactor[] =
{
GL_ONE,
GL_ZERO,
GL_DST_COLOR,
GL_SRC_COLOR,
GL_ONE_MINUS_DST_COLOR,
GL_ONE_MINUS_SRC_COLOR,
GL_DST_ALPHA,
GL_SRC_ALPHA,
GL_ONE_MINUS_DST_ALPHA,
GL_ONE_MINUS_SRC_ALPHA,
GL_ZERO // 'BF_UNDEF'
LLTexUnit::LLTexUnit(S32 index)
: mCurrTexType(TT_NONE), mCurrBlendType(TB_MULT),
mCurrColorOp(TBO_MULT), mCurrAlphaOp(TBO_MULT),
mCurrColorSrc1(TBS_TEX_COLOR), mCurrColorSrc2(TBS_PREV_COLOR),
mCurrAlphaSrc1(TBS_TEX_ALPHA), mCurrAlphaSrc2(TBS_PREV_ALPHA),
mCurrColorScale(1), mCurrAlphaScale(1), mCurrTexture(0),
mHasMipMaps(false)
llassert_always(index < (S32)LL_NUM_TEXTURE_LAYERS);
mIndex = index;
}
//static
U32 LLTexUnit::getInternalType(eTextureType type)
return sGLTextureType[type];
void LLTexUnit::refreshState(void)
// We set dirty to true so that the tex unit knows to ignore caching
// and we reset the cached tex unit state
gGL.flush();
glActiveTextureARB(GL_TEXTURE0_ARB + mIndex);
//
// Per apple spec, don't call glEnable/glDisable when index exceeds max texture units
// http://www.mailinglistarchive.com/html/mac-opengl@lists.apple.com/2008-07/msg00653.html
//
bool enableDisable = (mIndex < gGLManager.mNumTextureUnits) && mCurrTexType != LLTexUnit::TT_MULTISAMPLE_TEXTURE;
if (mCurrTexType != TT_NONE)
if (enableDisable)
{
glEnable(sGLTextureType[mCurrTexType]);
}
glBindTexture(sGLTextureType[mCurrTexType], mCurrTexture);
if (enableDisable)
{
glDisable(GL_TEXTURE_2D);
}
glBindTexture(GL_TEXTURE_2D, 0);
}
if (mCurrBlendType != TB_COMBINE)
{
setTextureBlendType(mCurrBlendType);
}
else
{
setTextureCombiner(mCurrColorOp, mCurrColorSrc1, mCurrColorSrc2, false);
setTextureCombiner(mCurrAlphaOp, mCurrAlphaSrc1, mCurrAlphaSrc2, true);
}
}
void LLTexUnit::activate(void)
{
if (mIndex < 0) return;
if ((S32)gGL.mCurrTextureUnitIndex != mIndex || gGL.mDirty)
David Parks
committed
gGL.flush();
glActiveTextureARB(GL_TEXTURE0_ARB + mIndex);
gGL.mCurrTextureUnitIndex = mIndex;
}
}
void LLTexUnit::enable(eTextureType type)
if (mIndex < 0) return;
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.
}
mCurrTexType = type;
gGL.flush();
if (type != LLTexUnit::TT_MULTISAMPLE_TEXTURE &&
{
glEnable(sGLTextureType[type]);
}
}
}
void LLTexUnit::disable(void)
{
if (mIndex < 0) return;
if (mCurrTexType != TT_NONE)
Loading
Loading full blame...