123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985 |
- /**
- * @file lldrawpool.cpp
- * @brief LLDrawPool class implementation
- *
- * $LicenseInfo:firstyear=2002&license=viewergpl$
- *
- * Copyright (c) 2002-2009, Linden Research, Inc.
- *
- * 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
- *
- * 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
- *
- * 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.
- *
- * 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$
- */
- #include "llviewerprecompiledheaders.h"
- #include "lldrawpool.h"
- #include "llglslshader.h"
- #include "llmodel.h"
- #include "llrender.h"
- #include "hbtracy.h"
- #include "lldrawable.h"
- #include "lldrawpoolalpha.h"
- #include "lldrawpoolavatar.h"
- #include "lldrawpoolbump.h"
- #include "lldrawpoolmaterials.h"
- #include "lldrawpoolsimple.h"
- #include "lldrawpoolsky.h"
- #include "lldrawpooltree.h"
- #include "lldrawpoolterrain.h"
- #include "lldrawpoolwater.h"
- #include "lldrawpoolwlsky.h"
- #include "llface.h"
- #include "llpipeline.h"
- #include "llspatialpartition.h"
- #include "llviewercamera.h"
- #include "llviewercontrol.h"
- #include "llviewerobjectlist.h" // For debug listing.
- #include "llviewershadermgr.h"
- #include "llvoavatar.h"
- ///////////////////////////////////////////////////////////////////////////////
- // LLDrawPool class
- ///////////////////////////////////////////////////////////////////////////////
- //static
- S32 LLDrawPool::sNumDrawPools = 0;
- LLDrawPool* LLDrawPool::createPool(U32 type, LLViewerTexture* tex0)
- {
- LLDrawPool* poolp = NULL;
- switch (type)
- {
- case POOL_SIMPLE:
- poolp = new LLDrawPoolSimple();
- break;
- case POOL_GRASS:
- poolp = new LLDrawPoolGrass();
- break;
- case POOL_ALPHA_MASK:
- poolp = new LLDrawPoolAlphaMask();
- break;
- case POOL_FULLBRIGHT_ALPHA_MASK:
- poolp = new LLDrawPoolFullbrightAlphaMask();
- break;
- case POOL_FULLBRIGHT:
- poolp = new LLDrawPoolFullbright();
- break;
- // For the EE renderer only
- case POOL_INVISIBLE:
- poolp = new LLDrawPoolInvisible();
- break;
- case POOL_GLOW:
- poolp = new LLDrawPoolGlow();
- break;
- // For the EE renderer only
- case POOL_ALPHA:
- poolp = new LLDrawPoolAlpha(POOL_ALPHA);
- break;
- // For the PBR renderer only
- case POOL_ALPHA_PRE_WATER:
- poolp = new LLDrawPoolAlpha(POOL_ALPHA_PRE_WATER);
- break;
- // For the PBR renderer only
- case POOL_ALPHA_POST_WATER:
- poolp = new LLDrawPoolAlpha(POOL_ALPHA_POST_WATER);
- break;
- case POOL_AVATAR:
- case POOL_PUPPET:
- poolp = new LLDrawPoolAvatar(type);
- break;
- case POOL_TREE:
- poolp = new LLDrawPoolTree(tex0);
- break;
- case POOL_TERRAIN:
- poolp = new LLDrawPoolTerrain(tex0);
- break;
- case POOL_SKY:
- poolp = new LLDrawPoolSky();
- break;
- case POOL_WL_SKY:
- poolp = new LLDrawPoolWLSky();
- break;
- case POOL_VOIDWATER:
- case POOL_WATER:
- poolp = new LLDrawPoolWater();
- break;
- case POOL_BUMP:
- poolp = new LLDrawPoolBump();
- break;
- case POOL_MATERIALS:
- poolp = new LLDrawPoolMaterials();
- break;
- // For the PBR renderer only
- case POOL_MAT_PBR:
- poolp = new LLDrawPoolMatPBR(POOL_MAT_PBR);
- break;
- // For the PBR renderer only
- case POOL_MAT_PBR_ALPHA_MASK:
- poolp = new LLDrawPoolMatPBR(POOL_MAT_PBR_ALPHA_MASK);
- break;
- default:
- llerrs << "Unknown draw pool type !" << llendl;
- }
- llassert(poolp->mType == type);
- return poolp;
- }
- LLDrawPool::LLDrawPool(U32 type)
- : mType(type),
- mId(++sNumDrawPools),
- mShaderLevel(0)
- {
- }
- // Forward rendering only works with the EE renderer.
- //virtual
- S32 LLDrawPool::getNumPasses()
- {
- return gUsePBRShaders ? 0 : 1;
- }
- //virtual
- void LLDrawPool::endRenderPass(S32)
- {
- // Make sure channel 0 is active channel
- gGL.getTexUnit(0)->activate();
- }
- ///////////////////////////////////////////////////////////////////////////////
- // LLFacePool class
- ///////////////////////////////////////////////////////////////////////////////
- LLFacePool::LLFacePool(U32 type)
- : LLDrawPool(type)
- {
- resetDrawOrders();
- }
- LLFacePool::~LLFacePool()
- {
- destroy();
- }
- void LLFacePool::destroy()
- {
- if (!mReferences.empty())
- {
- llinfos << mReferences.size()
- << " references left on deletion of draw pool !" << llendl;
- }
- }
- void LLFacePool::enqueue(LLFace* facep)
- {
- mDrawFace.push_back(facep);
- }
- //virtual
- bool LLFacePool::addFace(LLFace* facep)
- {
- addFaceReference(facep);
- return true;
- }
- //virtual
- void LLFacePool::pushFaceGeometry()
- {
- for (U32 i = 0, count = mDrawFace.size(); i < count; ++i)
- {
- mDrawFace[i]->renderIndexed();
- }
- }
- //virtual
- bool LLFacePool::removeFace(LLFace* facep)
- {
- removeFaceReference(facep);
- vector_replace_with_last(mDrawFace, facep);
- return true;
- }
- // Not absolutely sure if we should be resetting all of the chained pools as
- // well - djs
- void LLFacePool::resetDrawOrders()
- {
- mDrawFace.resize(0);
- }
- void LLFacePool::removeFaceReference(LLFace* facep)
- {
- if (facep->getReferenceIndex() != -1)
- {
- if (facep->getReferenceIndex() != (S32)mReferences.size())
- {
- LLFace* lastp = mReferences.back();
- mReferences[facep->getReferenceIndex()] = lastp;
- lastp->setReferenceIndex(facep->getReferenceIndex());
- }
- mReferences.pop_back();
- }
- facep->setReferenceIndex(-1);
- }
- void LLFacePool::addFaceReference(LLFace* facep)
- {
- if (facep->getReferenceIndex() == -1)
- {
- facep->setReferenceIndex(mReferences.size());
- mReferences.push_back(facep);
- }
- }
- bool LLFacePool::verify() const
- {
- bool ok = true;
- for (U32 i = 0, count = mDrawFace.size(); i < count; ++i)
- {
- const LLFace* facep = mDrawFace[i];
- if (facep->getPool() != this)
- {
- llwarns_once << "Face " << std::hex << intptr_t(facep) << std::dec
- << " in wrong pool !" << llendl;
- facep->printDebugInfo();
- ok = false;
- }
- else if (!facep->verify())
- {
- ok = false;
- }
- }
- return ok;
- }
- void LLFacePool::printDebugInfo() const
- {
- llinfos << "Pool: " << this << " - Type: " << getType() << llendl;
- }
- bool LLFacePool::LLOverrideFaceColor::sOverrideFaceColor = false;
- void LLFacePool::LLOverrideFaceColor::setColor(const LLColor4& color)
- {
- gGL.diffuseColor4fv(color.mV);
- }
- void LLFacePool::LLOverrideFaceColor::setColor(const LLColor4U& color)
- {
- gGL.diffuseColor4ubv(color.mV);
- }
- void LLFacePool::LLOverrideFaceColor::setColor(F32 r, F32 g, F32 b, F32 a)
- {
- gGL.diffuseColor4f(r, g, b, a);
- }
- ///////////////////////////////////////////////////////////////////////////////
- // LLRenderPass class
- ///////////////////////////////////////////////////////////////////////////////
- void LLRenderPass::renderGroup(LLSpatialGroup* groupp, U32 type, U32 mask,
- bool texture)
- {
- LLSpatialGroup::drawmap_elem_t& draw_info = groupp->mDrawMap[type];
- for (U32 i = 0, count = draw_info.size(); i < count; ++i)
- {
- LLDrawInfo* paramsp = draw_info[i].get();
- if (paramsp)
- {
- pushBatch(*paramsp, mask, texture);
- }
- }
- }
- void LLRenderPass::renderRiggedGroup(LLSpatialGroup* groupp, U32 type, U32 mask,
- bool texture)
- {
- LL_TRACY_TIMER(TRC_RENDER_RIGGED_GROUP);
- LLVOAvatar* last_avatarp = NULL;
- U64 last_hash = 0;
- // NOTE: does not impact PBR rendering (mask ignored). HB
- mask |= LLVertexBuffer::MAP_WEIGHT4;
- LLSpatialGroup::drawmap_elem_t& draw_info = groupp->mDrawMap[type];
- for (U32 i = 0, count = draw_info.size(); i < count; ++i)
- {
- LLDrawInfo* paramsp = draw_info[i].get();
- if (!paramsp) continue;
- if (paramsp->mAvatar.notNull() && paramsp->mSkinInfo.notNull() &&
- (paramsp->mAvatar.get() != last_avatarp ||
- paramsp->mSkinInfo->mHash != last_hash))
- {
- #if 0
- if (!uploadMatrixPalette(*paramsp))
- {
- continue;
- }
- #else
- uploadMatrixPalette(*paramsp);
- #endif
- last_avatarp = paramsp->mAvatar.get();
- last_hash = paramsp->mSkinInfo->mHash;
- }
- pushBatch(*paramsp, mask, texture);
- }
- }
- void LLRenderPass::pushBatches(U32 type, U32 mask, bool texture,
- bool batch_textures)
- {
- if (!texture && gUsePBRShaders)
- {
- pushUntexturedBatches(type);
- return;
- }
- if (!gPipeline.sCull)
- {
- // Paranoia (sCull != NULL needed for getRenderMap())
- return;
- }
- LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
- for (U32 i = 0, count = draw_list.size(); i < count; )
- {
- LLDrawInfo* paramsp = draw_list[i++];
- // Draw info cache prefetching optimization.
- if (i < count)
- {
- _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
- _MM_HINT_NTA);
- if (i + 1 < count)
- {
- _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
- }
- }
- pushBatch(*paramsp, mask, texture, batch_textures);
- }
- }
- void LLRenderPass::pushRiggedBatches(U32 type, U32 mask, bool texture,
- bool batch_textures)
- {
- if (!texture && gUsePBRShaders)
- {
- pushUntexturedRiggedBatches(type);
- return;
- }
- if (!gPipeline.sCull)
- {
- // Paranoia (sCull != NULL needed for getRenderMap())
- return;
- }
- LLVOAvatar* last_avatarp = NULL;
- U64 last_hash = 0;
- mask |= LLVertexBuffer::MAP_WEIGHT4;
- LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
- for (U32 i = 0, count = draw_list.size(); i < count; )
- {
- LLDrawInfo* paramsp = draw_list[i++];
- // Draw info cache prefetching optimization.
- if (i < count)
- {
- _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
- _MM_HINT_NTA);
- if (i + 1 < count)
- {
- _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
- }
- }
- if (paramsp->mAvatar.notNull() && paramsp->mSkinInfo.notNull() &&
- (paramsp->mAvatar.get() != last_avatarp ||
- paramsp->mSkinInfo->mHash != last_hash))
- {
- #if 0
- if (!uploadMatrixPalette(*paramsp))
- {
- continue;
- }
- #else
- uploadMatrixPalette(*paramsp);
- #endif
- last_avatarp = paramsp->mAvatar.get();
- last_hash = paramsp->mSkinInfo->mHash;
- }
- pushBatch(*paramsp, mask, texture, batch_textures);
- }
- }
- void LLRenderPass::pushMaskBatches(U32 type, U32 mask, bool texture,
- bool batch_textures)
- {
- if (!gPipeline.sCull)
- {
- // Paranoia (sCull != NULL needed for getRenderMap())
- return;
- }
- LLGLSLShader* shaderp = LLGLSLShader::sCurBoundShaderPtr;
- if (!shaderp) // Paranoia
- {
- llwarns_sparse << "sCurBoundShaderPtr is NULL !" << llendl;
- llassert(false);
- return;
- }
- LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
- for (U32 i = 0, count = draw_list.size(); i < count; )
- {
- LLDrawInfo* paramsp = draw_list[i++];
- // Draw info cache prefetching optimization.
- if (i < count)
- {
- _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
- _MM_HINT_NTA);
- if (i + 1 < count)
- {
- _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
- }
- }
- shaderp->setMinimumAlpha(paramsp->mAlphaMaskCutoff);
- pushBatch(*paramsp, mask, texture, batch_textures);
- }
- }
- void LLRenderPass::pushRiggedMaskBatches(U32 type, U32 mask, bool texture,
- bool batch_textures)
- {
- if (!gPipeline.sCull)
- {
- // Paranoia (sCull != NULL needed for getRenderMap())
- return;
- }
- LLGLSLShader* shaderp = LLGLSLShader::sCurBoundShaderPtr;
- if (!shaderp)
- {
- gGL.flush();
- }
- LLVOAvatar* last_avatarp = NULL;
- U64 last_hash = 0;
- mask |= LLVertexBuffer::MAP_WEIGHT4;
- LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
- for (U32 i = 0, count = draw_list.size(); i < count; )
- {
- LLDrawInfo* paramsp = draw_list[i++];
- // Draw info cache prefetching optimization.
- if (i < count)
- {
- _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
- _MM_HINT_NTA);
- if (i + 1 < count)
- {
- _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
- }
- }
- if (shaderp)
- {
- shaderp->setMinimumAlpha(paramsp->mAlphaMaskCutoff);
- }
- if (paramsp->mAvatar.notNull() && paramsp->mSkinInfo.notNull() &&
- (paramsp->mAvatar.get() != last_avatarp ||
- paramsp->mSkinInfo->mHash != last_hash))
- {
- #if 0
- if (!uploadMatrixPalette(*paramsp))
- {
- continue;
- }
- #else
- uploadMatrixPalette(*paramsp);
- #endif
- last_avatarp = paramsp->mAvatar.get();
- last_hash = paramsp->mSkinInfo->mHash;
- }
- pushBatch(*paramsp, mask, texture, batch_textures);
- }
- }
- //virtual
- void LLRenderPass::pushBatch(LLDrawInfo& params, U32 mask, bool texture,
- bool batch_textures)
- {
- if (!params.mCount)
- {
- return;
- }
- applyModelMatrix(params);
- bool tex_setup = false;
- if (texture || gUsePBRShaders)
- {
- U32 count;
- if (batch_textures && (count = params.mTextureList.size()) > 1)
- {
- for (U32 i = 0; i < count; ++i)
- {
- const LLPointer<LLViewerTexture>& tex = params.mTextureList[i];
- if (tex.notNull())
- {
- gGL.getTexUnit(i)->bindFast(tex);
- }
- }
- }
- // Not batching textures or batch has only 1 texture: might need a
- // texture matrix.
- else if (params.mTexture.notNull())
- {
- LLTexUnit* unit0 = gGL.getTexUnit(0);
- unit0->bindFast(params.mTexture);
- if (params.mTextureMatrix)
- {
- tex_setup = true;
- unit0->activate();
- gGL.matrixMode(LLRender::MM_TEXTURE);
- gGL.loadMatrix(params.mTextureMatrix->getF32ptr());
- ++gPipeline.mTextureMatrixOps;
- }
- }
- else
- {
- gGL.getTexUnit(0)->unbindFast(LLTexUnit::TT_TEXTURE);
- }
- }
- // Note: mask is ignored for the PBR renderer
- params.mVertexBuffer->setBufferFast(mask);
- params.mVertexBuffer->drawRange(LLRender::TRIANGLES, params.mStart,
- params.mEnd, params.mCount,
- params.mOffset);
- if (tex_setup)
- {
- gGL.matrixMode(LLRender::MM_TEXTURE0);
- gGL.loadIdentity();
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- }
- }
- // Used only by the PBR renderer
- //static
- void LLRenderPass::pushUntexturedBatches(U32 type)
- {
- if (!gPipeline.sCull)
- {
- // Paranoia (sCull != NULL needed for getRenderMap())
- return;
- }
- LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
- for (U32 i = 0, count = draw_list.size(); i < count; )
- {
- LLDrawInfo* paramsp = draw_list[i++];
- // Draw info cache prefetching optimization.
- if (i < count)
- {
- _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
- _MM_HINT_NTA);
- if (i + 1 < count)
- {
- _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
- }
- }
- pushUntexturedBatch(*paramsp);
- }
- }
- // Used only by the PBR renderer
- //static
- void LLRenderPass::pushUntexturedRiggedBatches(U32 type)
- {
- if (!gPipeline.sCull)
- {
- // Paranoia (sCull != NULL needed for getRenderMap())
- return;
- }
- LLVOAvatar* last_avatarp = NULL;
- U64 last_hash = 0;
- LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
- for (U32 i = 0, count = draw_list.size(); i < count; )
- {
- LLDrawInfo* paramsp = draw_list[i++];
- // Draw info cache prefetching optimization.
- if (i < count)
- {
- _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
- _MM_HINT_NTA);
- if (i + 1 < count)
- {
- _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
- }
- }
- if (paramsp->mAvatar.notNull() && paramsp->mSkinInfo.notNull() &&
- (paramsp->mAvatar.get() != last_avatarp ||
- paramsp->mSkinInfo->mHash != last_hash))
- {
- #if 0
- if (!uploadMatrixPalette(*paramsp))
- {
- continue;
- }
- #else
- uploadMatrixPalette(*paramsp);
- #endif
- last_avatarp = paramsp->mAvatar.get();
- last_hash = paramsp->mSkinInfo->mHash;
- }
- pushUntexturedBatch(*paramsp);
- }
- }
- // Used only by the PBR renderer
- //static
- void LLRenderPass::pushUntexturedBatch(LLDrawInfo& params)
- {
- if (params.mCount)
- {
- applyModelMatrix(params);
- params.mVertexBuffer->setBuffer();
- params.mVertexBuffer->drawRange(LLRender::TRIANGLES, params.mStart,
- params.mEnd, params.mCount,
- params.mOffset);
- }
- }
- // Used only by the PBR renderer
- //static
- void LLRenderPass::pushUntexturedGLTFBatches(U32 type)
- {
- if (!gPipeline.sCull)
- {
- // Paranoia (sCull != NULL needed for getRenderMap())
- return;
- }
- LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
- for (U32 i = 0, count = draw_list.size(); i < count; )
- {
- LLDrawInfo* paramsp = draw_list[i++];
- // Draw info cache prefetching optimization.
- if (i < count)
- {
- _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
- _MM_HINT_NTA);
- if (i + 1 < count)
- {
- _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
- }
- }
- pushUntexturedGLTFBatch(*paramsp);
- }
- }
- // Used only by the PBR renderer
- //static
- void LLRenderPass::pushGLTFBatches(U32 type)
- {
- if (!gPipeline.sCull)
- {
- // Paranoia (sCull != NULL needed for getRenderMap())
- return;
- }
- LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
- for (U32 i = 0, count = draw_list.size(); i < count; )
- {
- LLDrawInfo* paramsp = draw_list[i++];
- // Draw info cache prefetching optimization.
- if (i < count)
- {
- _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
- _MM_HINT_NTA);
- if (i + 1 < count)
- {
- _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
- }
- }
- pushGLTFBatch(*paramsp);
- }
- }
- // Used only by the PBR renderer
- //static
- void LLRenderPass::pushGLTFBatch(LLDrawInfo& params)
- {
- bool double_sided = false;
- LLFetchedGLTFMaterial* matp = params.mGLTFMaterial.get();
- if (matp) // NULL does happen. HB
- {
- matp->bind(params.mTexture, params.mVSize);
- double_sided = matp->mDoubleSided;
- }
- LLGLDisable cull_face(double_sided ? GL_CULL_FACE : 0);
- bool has_tex_matrix = params.mTextureMatrix != NULL;
- if (has_tex_matrix)
- {
- // Special case implementation of texture animation here because of
- // special handling of textures for PBR batches.
- gGL.getTexUnit(0)->activate();
- gGL.matrixMode(LLRender::MM_TEXTURE);
- gGL.loadMatrix(params.mTextureMatrix->getF32ptr());
- ++gPipeline.mTextureMatrixOps;
- }
- applyModelMatrix(params);
- params.mVertexBuffer->setBuffer();
- params.mVertexBuffer->drawRange(LLRender::TRIANGLES, params.mStart,
- params.mEnd, params.mCount,
- params.mOffset);
-
- if (has_tex_matrix)
- {
- gGL.matrixMode(LLRender::MM_TEXTURE0);
- gGL.loadIdentity();
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- }
- }
- // Used only by the PBR renderer
- //static
- void LLRenderPass::pushUntexturedGLTFBatch(LLDrawInfo& params)
- {
- LLFetchedGLTFMaterial* matp = params.mGLTFMaterial.get();
- if (!matp) // Paranoia ?
- {
- return;
- }
- LLGLDisable cull_face(matp->mDoubleSided ? GL_CULL_FACE : 0);
- applyModelMatrix(params);
- params.mVertexBuffer->setBuffer();
- params.mVertexBuffer->drawRange(LLRender::TRIANGLES, params.mStart,
- params.mEnd, params.mCount,
- params.mOffset);
- }
- // Used only by the PBR renderer
- //static
- void LLRenderPass::pushRiggedGLTFBatches(U32 type)
- {
- if (!gPipeline.sCull)
- {
- // Paranoia (sCull != NULL needed for getRenderMap())
- return;
- }
- LLVOAvatar* last_avatarp = NULL;
- U64 last_hash = 0;
- LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
- for (U32 i = 0, count = draw_list.size(); i < count; )
- {
- LLDrawInfo* paramsp = draw_list[i++];
- // Draw info cache prefetching optimization.
- if (i < count)
- {
- _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
- _MM_HINT_NTA);
- if (i + 1 < count)
- {
- _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
- }
- }
- if (paramsp->mAvatar.notNull() && paramsp->mSkinInfo.notNull() &&
- (paramsp->mAvatar.get() != last_avatarp ||
- paramsp->mSkinInfo->mHash != last_hash))
- {
- #if 0
- if (!uploadMatrixPalette(*paramsp))
- {
- continue;
- }
- #else
- uploadMatrixPalette(*paramsp);
- #endif
- last_avatarp = paramsp->mAvatar.get();
- last_hash = paramsp->mSkinInfo->mHash;
- }
- pushGLTFBatch(*paramsp);
- }
- }
- // Used only by the PBR renderer
- //static
- void LLRenderPass::pushUntexturedRiggedGLTFBatches(U32 type)
- {
- if (!gPipeline.sCull)
- {
- // Paranoia (sCull != NULL needed for getRenderMap())
- return;
- }
- LLVOAvatar* last_avatarp = NULL;
- U64 last_hash = 0;
- LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
- for (U32 i = 0, count = draw_list.size(); i < count; )
- {
- LLDrawInfo* paramsp = draw_list[i++];
- // Draw info cache prefetching optimization.
- if (i < count)
- {
- _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
- _MM_HINT_NTA);
- if (i + 1 < count)
- {
- _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
- }
- }
- if (paramsp->mAvatar.notNull() && paramsp->mSkinInfo.notNull() &&
- (paramsp->mAvatar.get() != last_avatarp ||
- paramsp->mSkinInfo->mHash != last_hash))
- {
- #if 0
- if (!uploadMatrixPalette(*paramsp))
- {
- continue;
- }
- #else
- uploadMatrixPalette(*paramsp);
- #endif
- last_avatarp = paramsp->mAvatar.get();
- last_hash = paramsp->mSkinInfo->mHash;
- }
- pushUntexturedGLTFBatch(*paramsp);
- }
- }
- //static
- void LLRenderPass::applyModelMatrix(LLDrawInfo& params)
- {
- applyModelMatrix(params.mModelMatrix);
- }
- //static
- void LLRenderPass::applyModelMatrix(const LLMatrix4* model_matp)
- {
- if (model_matp != gGLLastMatrix)
- {
- gGLLastMatrix = model_matp;
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.loadMatrix(gGLModelView.getF32ptr());
- if (model_matp)
- {
- gGL.multMatrix(model_matp->getF32ptr());
- }
- ++gPipeline.mMatrixOpCount;
- }
- }
- //static
- bool LLRenderPass::uploadMatrixPalette(const LLDrawInfo& params)
- {
- return uploadMatrixPalette(params.mAvatar, params.mSkinInfo);
- }
- //static
- bool LLRenderPass::uploadMatrixPalette(LLVOAvatar* avp, LLMeshSkinInfo* skinp)
- {
- if (!skinp || !avp || avp->isDead())
- {
- return false;
- }
- U32 count = 0;
- const F32* mp = avp->getRiggedMatrix(skinp, count);
- if (!count) // Render only after skin info has loaded
- {
- return false;
- }
- LLGLSLShader* shaderp = LLGLSLShader::sCurBoundShaderPtr;
- if (!shaderp) // Paranoia
- {
- llwarns_sparse << "sCurBoundShaderPtr is NULL !" << llendl;
- llassert(false);
- return false;
- }
- shaderp->uniformMatrix3x4fv(LLShaderMgr::AVATAR_MATRIX, count, false, mp);
- return true;
- }
|