lldrawpool.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  1. /**
  2. * @file lldrawpool.cpp
  3. * @brief LLDrawPool class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "lldrawpool.h"
  34. #include "llglslshader.h"
  35. #include "llmodel.h"
  36. #include "llrender.h"
  37. #include "hbtracy.h"
  38. #include "lldrawable.h"
  39. #include "lldrawpoolalpha.h"
  40. #include "lldrawpoolavatar.h"
  41. #include "lldrawpoolbump.h"
  42. #include "lldrawpoolmaterials.h"
  43. #include "lldrawpoolsimple.h"
  44. #include "lldrawpoolsky.h"
  45. #include "lldrawpooltree.h"
  46. #include "lldrawpoolterrain.h"
  47. #include "lldrawpoolwater.h"
  48. #include "lldrawpoolwlsky.h"
  49. #include "llface.h"
  50. #include "llpipeline.h"
  51. #include "llspatialpartition.h"
  52. #include "llviewercamera.h"
  53. #include "llviewercontrol.h"
  54. #include "llviewerobjectlist.h" // For debug listing.
  55. #include "llviewershadermgr.h"
  56. #include "llvoavatar.h"
  57. ///////////////////////////////////////////////////////////////////////////////
  58. // LLDrawPool class
  59. ///////////////////////////////////////////////////////////////////////////////
  60. //static
  61. S32 LLDrawPool::sNumDrawPools = 0;
  62. LLDrawPool* LLDrawPool::createPool(U32 type, LLViewerTexture* tex0)
  63. {
  64. LLDrawPool* poolp = NULL;
  65. switch (type)
  66. {
  67. case POOL_SIMPLE:
  68. poolp = new LLDrawPoolSimple();
  69. break;
  70. case POOL_GRASS:
  71. poolp = new LLDrawPoolGrass();
  72. break;
  73. case POOL_ALPHA_MASK:
  74. poolp = new LLDrawPoolAlphaMask();
  75. break;
  76. case POOL_FULLBRIGHT_ALPHA_MASK:
  77. poolp = new LLDrawPoolFullbrightAlphaMask();
  78. break;
  79. case POOL_FULLBRIGHT:
  80. poolp = new LLDrawPoolFullbright();
  81. break;
  82. // For the EE renderer only
  83. case POOL_INVISIBLE:
  84. poolp = new LLDrawPoolInvisible();
  85. break;
  86. case POOL_GLOW:
  87. poolp = new LLDrawPoolGlow();
  88. break;
  89. // For the EE renderer only
  90. case POOL_ALPHA:
  91. poolp = new LLDrawPoolAlpha(POOL_ALPHA);
  92. break;
  93. // For the PBR renderer only
  94. case POOL_ALPHA_PRE_WATER:
  95. poolp = new LLDrawPoolAlpha(POOL_ALPHA_PRE_WATER);
  96. break;
  97. // For the PBR renderer only
  98. case POOL_ALPHA_POST_WATER:
  99. poolp = new LLDrawPoolAlpha(POOL_ALPHA_POST_WATER);
  100. break;
  101. case POOL_AVATAR:
  102. case POOL_PUPPET:
  103. poolp = new LLDrawPoolAvatar(type);
  104. break;
  105. case POOL_TREE:
  106. poolp = new LLDrawPoolTree(tex0);
  107. break;
  108. case POOL_TERRAIN:
  109. poolp = new LLDrawPoolTerrain(tex0);
  110. break;
  111. case POOL_SKY:
  112. poolp = new LLDrawPoolSky();
  113. break;
  114. case POOL_WL_SKY:
  115. poolp = new LLDrawPoolWLSky();
  116. break;
  117. case POOL_VOIDWATER:
  118. case POOL_WATER:
  119. poolp = new LLDrawPoolWater();
  120. break;
  121. case POOL_BUMP:
  122. poolp = new LLDrawPoolBump();
  123. break;
  124. case POOL_MATERIALS:
  125. poolp = new LLDrawPoolMaterials();
  126. break;
  127. // For the PBR renderer only
  128. case POOL_MAT_PBR:
  129. poolp = new LLDrawPoolMatPBR(POOL_MAT_PBR);
  130. break;
  131. // For the PBR renderer only
  132. case POOL_MAT_PBR_ALPHA_MASK:
  133. poolp = new LLDrawPoolMatPBR(POOL_MAT_PBR_ALPHA_MASK);
  134. break;
  135. default:
  136. llerrs << "Unknown draw pool type !" << llendl;
  137. }
  138. llassert(poolp->mType == type);
  139. return poolp;
  140. }
  141. LLDrawPool::LLDrawPool(U32 type)
  142. : mType(type),
  143. mId(++sNumDrawPools),
  144. mShaderLevel(0)
  145. {
  146. }
  147. // Forward rendering only works with the EE renderer.
  148. //virtual
  149. S32 LLDrawPool::getNumPasses()
  150. {
  151. return gUsePBRShaders ? 0 : 1;
  152. }
  153. //virtual
  154. void LLDrawPool::endRenderPass(S32)
  155. {
  156. // Make sure channel 0 is active channel
  157. gGL.getTexUnit(0)->activate();
  158. }
  159. ///////////////////////////////////////////////////////////////////////////////
  160. // LLFacePool class
  161. ///////////////////////////////////////////////////////////////////////////////
  162. LLFacePool::LLFacePool(U32 type)
  163. : LLDrawPool(type)
  164. {
  165. resetDrawOrders();
  166. }
  167. LLFacePool::~LLFacePool()
  168. {
  169. destroy();
  170. }
  171. void LLFacePool::destroy()
  172. {
  173. if (!mReferences.empty())
  174. {
  175. llinfos << mReferences.size()
  176. << " references left on deletion of draw pool !" << llendl;
  177. }
  178. }
  179. void LLFacePool::enqueue(LLFace* facep)
  180. {
  181. mDrawFace.push_back(facep);
  182. }
  183. //virtual
  184. bool LLFacePool::addFace(LLFace* facep)
  185. {
  186. addFaceReference(facep);
  187. return true;
  188. }
  189. //virtual
  190. void LLFacePool::pushFaceGeometry()
  191. {
  192. for (U32 i = 0, count = mDrawFace.size(); i < count; ++i)
  193. {
  194. mDrawFace[i]->renderIndexed();
  195. }
  196. }
  197. //virtual
  198. bool LLFacePool::removeFace(LLFace* facep)
  199. {
  200. removeFaceReference(facep);
  201. vector_replace_with_last(mDrawFace, facep);
  202. return true;
  203. }
  204. // Not absolutely sure if we should be resetting all of the chained pools as
  205. // well - djs
  206. void LLFacePool::resetDrawOrders()
  207. {
  208. mDrawFace.resize(0);
  209. }
  210. void LLFacePool::removeFaceReference(LLFace* facep)
  211. {
  212. if (facep->getReferenceIndex() != -1)
  213. {
  214. if (facep->getReferenceIndex() != (S32)mReferences.size())
  215. {
  216. LLFace* lastp = mReferences.back();
  217. mReferences[facep->getReferenceIndex()] = lastp;
  218. lastp->setReferenceIndex(facep->getReferenceIndex());
  219. }
  220. mReferences.pop_back();
  221. }
  222. facep->setReferenceIndex(-1);
  223. }
  224. void LLFacePool::addFaceReference(LLFace* facep)
  225. {
  226. if (facep->getReferenceIndex() == -1)
  227. {
  228. facep->setReferenceIndex(mReferences.size());
  229. mReferences.push_back(facep);
  230. }
  231. }
  232. bool LLFacePool::verify() const
  233. {
  234. bool ok = true;
  235. for (U32 i = 0, count = mDrawFace.size(); i < count; ++i)
  236. {
  237. const LLFace* facep = mDrawFace[i];
  238. if (facep->getPool() != this)
  239. {
  240. llwarns_once << "Face " << std::hex << intptr_t(facep) << std::dec
  241. << " in wrong pool !" << llendl;
  242. facep->printDebugInfo();
  243. ok = false;
  244. }
  245. else if (!facep->verify())
  246. {
  247. ok = false;
  248. }
  249. }
  250. return ok;
  251. }
  252. void LLFacePool::printDebugInfo() const
  253. {
  254. llinfos << "Pool: " << this << " - Type: " << getType() << llendl;
  255. }
  256. bool LLFacePool::LLOverrideFaceColor::sOverrideFaceColor = false;
  257. void LLFacePool::LLOverrideFaceColor::setColor(const LLColor4& color)
  258. {
  259. gGL.diffuseColor4fv(color.mV);
  260. }
  261. void LLFacePool::LLOverrideFaceColor::setColor(const LLColor4U& color)
  262. {
  263. gGL.diffuseColor4ubv(color.mV);
  264. }
  265. void LLFacePool::LLOverrideFaceColor::setColor(F32 r, F32 g, F32 b, F32 a)
  266. {
  267. gGL.diffuseColor4f(r, g, b, a);
  268. }
  269. ///////////////////////////////////////////////////////////////////////////////
  270. // LLRenderPass class
  271. ///////////////////////////////////////////////////////////////////////////////
  272. void LLRenderPass::renderGroup(LLSpatialGroup* groupp, U32 type, U32 mask,
  273. bool texture)
  274. {
  275. LLSpatialGroup::drawmap_elem_t& draw_info = groupp->mDrawMap[type];
  276. for (U32 i = 0, count = draw_info.size(); i < count; ++i)
  277. {
  278. LLDrawInfo* paramsp = draw_info[i].get();
  279. if (paramsp)
  280. {
  281. pushBatch(*paramsp, mask, texture);
  282. }
  283. }
  284. }
  285. void LLRenderPass::renderRiggedGroup(LLSpatialGroup* groupp, U32 type, U32 mask,
  286. bool texture)
  287. {
  288. LL_TRACY_TIMER(TRC_RENDER_RIGGED_GROUP);
  289. LLVOAvatar* last_avatarp = NULL;
  290. U64 last_hash = 0;
  291. // NOTE: does not impact PBR rendering (mask ignored). HB
  292. mask |= LLVertexBuffer::MAP_WEIGHT4;
  293. LLSpatialGroup::drawmap_elem_t& draw_info = groupp->mDrawMap[type];
  294. for (U32 i = 0, count = draw_info.size(); i < count; ++i)
  295. {
  296. LLDrawInfo* paramsp = draw_info[i].get();
  297. if (!paramsp) continue;
  298. if (paramsp->mAvatar.notNull() && paramsp->mSkinInfo.notNull() &&
  299. (paramsp->mAvatar.get() != last_avatarp ||
  300. paramsp->mSkinInfo->mHash != last_hash))
  301. {
  302. #if 0
  303. if (!uploadMatrixPalette(*paramsp))
  304. {
  305. continue;
  306. }
  307. #else
  308. uploadMatrixPalette(*paramsp);
  309. #endif
  310. last_avatarp = paramsp->mAvatar.get();
  311. last_hash = paramsp->mSkinInfo->mHash;
  312. }
  313. pushBatch(*paramsp, mask, texture);
  314. }
  315. }
  316. void LLRenderPass::pushBatches(U32 type, U32 mask, bool texture,
  317. bool batch_textures)
  318. {
  319. if (!texture && gUsePBRShaders)
  320. {
  321. pushUntexturedBatches(type);
  322. return;
  323. }
  324. if (!gPipeline.sCull)
  325. {
  326. // Paranoia (sCull != NULL needed for getRenderMap())
  327. return;
  328. }
  329. LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
  330. for (U32 i = 0, count = draw_list.size(); i < count; )
  331. {
  332. LLDrawInfo* paramsp = draw_list[i++];
  333. // Draw info cache prefetching optimization.
  334. if (i < count)
  335. {
  336. _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
  337. _MM_HINT_NTA);
  338. if (i + 1 < count)
  339. {
  340. _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
  341. }
  342. }
  343. pushBatch(*paramsp, mask, texture, batch_textures);
  344. }
  345. }
  346. void LLRenderPass::pushRiggedBatches(U32 type, U32 mask, bool texture,
  347. bool batch_textures)
  348. {
  349. if (!texture && gUsePBRShaders)
  350. {
  351. pushUntexturedRiggedBatches(type);
  352. return;
  353. }
  354. if (!gPipeline.sCull)
  355. {
  356. // Paranoia (sCull != NULL needed for getRenderMap())
  357. return;
  358. }
  359. LLVOAvatar* last_avatarp = NULL;
  360. U64 last_hash = 0;
  361. mask |= LLVertexBuffer::MAP_WEIGHT4;
  362. LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
  363. for (U32 i = 0, count = draw_list.size(); i < count; )
  364. {
  365. LLDrawInfo* paramsp = draw_list[i++];
  366. // Draw info cache prefetching optimization.
  367. if (i < count)
  368. {
  369. _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
  370. _MM_HINT_NTA);
  371. if (i + 1 < count)
  372. {
  373. _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
  374. }
  375. }
  376. if (paramsp->mAvatar.notNull() && paramsp->mSkinInfo.notNull() &&
  377. (paramsp->mAvatar.get() != last_avatarp ||
  378. paramsp->mSkinInfo->mHash != last_hash))
  379. {
  380. #if 0
  381. if (!uploadMatrixPalette(*paramsp))
  382. {
  383. continue;
  384. }
  385. #else
  386. uploadMatrixPalette(*paramsp);
  387. #endif
  388. last_avatarp = paramsp->mAvatar.get();
  389. last_hash = paramsp->mSkinInfo->mHash;
  390. }
  391. pushBatch(*paramsp, mask, texture, batch_textures);
  392. }
  393. }
  394. void LLRenderPass::pushMaskBatches(U32 type, U32 mask, bool texture,
  395. bool batch_textures)
  396. {
  397. if (!gPipeline.sCull)
  398. {
  399. // Paranoia (sCull != NULL needed for getRenderMap())
  400. return;
  401. }
  402. LLGLSLShader* shaderp = LLGLSLShader::sCurBoundShaderPtr;
  403. if (!shaderp) // Paranoia
  404. {
  405. llwarns_sparse << "sCurBoundShaderPtr is NULL !" << llendl;
  406. llassert(false);
  407. return;
  408. }
  409. LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
  410. for (U32 i = 0, count = draw_list.size(); i < count; )
  411. {
  412. LLDrawInfo* paramsp = draw_list[i++];
  413. // Draw info cache prefetching optimization.
  414. if (i < count)
  415. {
  416. _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
  417. _MM_HINT_NTA);
  418. if (i + 1 < count)
  419. {
  420. _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
  421. }
  422. }
  423. shaderp->setMinimumAlpha(paramsp->mAlphaMaskCutoff);
  424. pushBatch(*paramsp, mask, texture, batch_textures);
  425. }
  426. }
  427. void LLRenderPass::pushRiggedMaskBatches(U32 type, U32 mask, bool texture,
  428. bool batch_textures)
  429. {
  430. if (!gPipeline.sCull)
  431. {
  432. // Paranoia (sCull != NULL needed for getRenderMap())
  433. return;
  434. }
  435. LLGLSLShader* shaderp = LLGLSLShader::sCurBoundShaderPtr;
  436. if (!shaderp)
  437. {
  438. gGL.flush();
  439. }
  440. LLVOAvatar* last_avatarp = NULL;
  441. U64 last_hash = 0;
  442. mask |= LLVertexBuffer::MAP_WEIGHT4;
  443. LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
  444. for (U32 i = 0, count = draw_list.size(); i < count; )
  445. {
  446. LLDrawInfo* paramsp = draw_list[i++];
  447. // Draw info cache prefetching optimization.
  448. if (i < count)
  449. {
  450. _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
  451. _MM_HINT_NTA);
  452. if (i + 1 < count)
  453. {
  454. _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
  455. }
  456. }
  457. if (shaderp)
  458. {
  459. shaderp->setMinimumAlpha(paramsp->mAlphaMaskCutoff);
  460. }
  461. if (paramsp->mAvatar.notNull() && paramsp->mSkinInfo.notNull() &&
  462. (paramsp->mAvatar.get() != last_avatarp ||
  463. paramsp->mSkinInfo->mHash != last_hash))
  464. {
  465. #if 0
  466. if (!uploadMatrixPalette(*paramsp))
  467. {
  468. continue;
  469. }
  470. #else
  471. uploadMatrixPalette(*paramsp);
  472. #endif
  473. last_avatarp = paramsp->mAvatar.get();
  474. last_hash = paramsp->mSkinInfo->mHash;
  475. }
  476. pushBatch(*paramsp, mask, texture, batch_textures);
  477. }
  478. }
  479. //virtual
  480. void LLRenderPass::pushBatch(LLDrawInfo& params, U32 mask, bool texture,
  481. bool batch_textures)
  482. {
  483. if (!params.mCount)
  484. {
  485. return;
  486. }
  487. applyModelMatrix(params);
  488. bool tex_setup = false;
  489. if (texture || gUsePBRShaders)
  490. {
  491. U32 count;
  492. if (batch_textures && (count = params.mTextureList.size()) > 1)
  493. {
  494. for (U32 i = 0; i < count; ++i)
  495. {
  496. const LLPointer<LLViewerTexture>& tex = params.mTextureList[i];
  497. if (tex.notNull())
  498. {
  499. gGL.getTexUnit(i)->bindFast(tex);
  500. }
  501. }
  502. }
  503. // Not batching textures or batch has only 1 texture: might need a
  504. // texture matrix.
  505. else if (params.mTexture.notNull())
  506. {
  507. LLTexUnit* unit0 = gGL.getTexUnit(0);
  508. unit0->bindFast(params.mTexture);
  509. if (params.mTextureMatrix)
  510. {
  511. tex_setup = true;
  512. unit0->activate();
  513. gGL.matrixMode(LLRender::MM_TEXTURE);
  514. gGL.loadMatrix(params.mTextureMatrix->getF32ptr());
  515. ++gPipeline.mTextureMatrixOps;
  516. }
  517. }
  518. else
  519. {
  520. gGL.getTexUnit(0)->unbindFast(LLTexUnit::TT_TEXTURE);
  521. }
  522. }
  523. // Note: mask is ignored for the PBR renderer
  524. params.mVertexBuffer->setBufferFast(mask);
  525. params.mVertexBuffer->drawRange(LLRender::TRIANGLES, params.mStart,
  526. params.mEnd, params.mCount,
  527. params.mOffset);
  528. if (tex_setup)
  529. {
  530. gGL.matrixMode(LLRender::MM_TEXTURE0);
  531. gGL.loadIdentity();
  532. gGL.matrixMode(LLRender::MM_MODELVIEW);
  533. }
  534. }
  535. // Used only by the PBR renderer
  536. //static
  537. void LLRenderPass::pushUntexturedBatches(U32 type)
  538. {
  539. if (!gPipeline.sCull)
  540. {
  541. // Paranoia (sCull != NULL needed for getRenderMap())
  542. return;
  543. }
  544. LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
  545. for (U32 i = 0, count = draw_list.size(); i < count; )
  546. {
  547. LLDrawInfo* paramsp = draw_list[i++];
  548. // Draw info cache prefetching optimization.
  549. if (i < count)
  550. {
  551. _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
  552. _MM_HINT_NTA);
  553. if (i + 1 < count)
  554. {
  555. _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
  556. }
  557. }
  558. pushUntexturedBatch(*paramsp);
  559. }
  560. }
  561. // Used only by the PBR renderer
  562. //static
  563. void LLRenderPass::pushUntexturedRiggedBatches(U32 type)
  564. {
  565. if (!gPipeline.sCull)
  566. {
  567. // Paranoia (sCull != NULL needed for getRenderMap())
  568. return;
  569. }
  570. LLVOAvatar* last_avatarp = NULL;
  571. U64 last_hash = 0;
  572. LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
  573. for (U32 i = 0, count = draw_list.size(); i < count; )
  574. {
  575. LLDrawInfo* paramsp = draw_list[i++];
  576. // Draw info cache prefetching optimization.
  577. if (i < count)
  578. {
  579. _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
  580. _MM_HINT_NTA);
  581. if (i + 1 < count)
  582. {
  583. _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
  584. }
  585. }
  586. if (paramsp->mAvatar.notNull() && paramsp->mSkinInfo.notNull() &&
  587. (paramsp->mAvatar.get() != last_avatarp ||
  588. paramsp->mSkinInfo->mHash != last_hash))
  589. {
  590. #if 0
  591. if (!uploadMatrixPalette(*paramsp))
  592. {
  593. continue;
  594. }
  595. #else
  596. uploadMatrixPalette(*paramsp);
  597. #endif
  598. last_avatarp = paramsp->mAvatar.get();
  599. last_hash = paramsp->mSkinInfo->mHash;
  600. }
  601. pushUntexturedBatch(*paramsp);
  602. }
  603. }
  604. // Used only by the PBR renderer
  605. //static
  606. void LLRenderPass::pushUntexturedBatch(LLDrawInfo& params)
  607. {
  608. if (params.mCount)
  609. {
  610. applyModelMatrix(params);
  611. params.mVertexBuffer->setBuffer();
  612. params.mVertexBuffer->drawRange(LLRender::TRIANGLES, params.mStart,
  613. params.mEnd, params.mCount,
  614. params.mOffset);
  615. }
  616. }
  617. // Used only by the PBR renderer
  618. //static
  619. void LLRenderPass::pushUntexturedGLTFBatches(U32 type)
  620. {
  621. if (!gPipeline.sCull)
  622. {
  623. // Paranoia (sCull != NULL needed for getRenderMap())
  624. return;
  625. }
  626. LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
  627. for (U32 i = 0, count = draw_list.size(); i < count; )
  628. {
  629. LLDrawInfo* paramsp = draw_list[i++];
  630. // Draw info cache prefetching optimization.
  631. if (i < count)
  632. {
  633. _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
  634. _MM_HINT_NTA);
  635. if (i + 1 < count)
  636. {
  637. _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
  638. }
  639. }
  640. pushUntexturedGLTFBatch(*paramsp);
  641. }
  642. }
  643. // Used only by the PBR renderer
  644. //static
  645. void LLRenderPass::pushGLTFBatches(U32 type)
  646. {
  647. if (!gPipeline.sCull)
  648. {
  649. // Paranoia (sCull != NULL needed for getRenderMap())
  650. return;
  651. }
  652. LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
  653. for (U32 i = 0, count = draw_list.size(); i < count; )
  654. {
  655. LLDrawInfo* paramsp = draw_list[i++];
  656. // Draw info cache prefetching optimization.
  657. if (i < count)
  658. {
  659. _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
  660. _MM_HINT_NTA);
  661. if (i + 1 < count)
  662. {
  663. _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
  664. }
  665. }
  666. pushGLTFBatch(*paramsp);
  667. }
  668. }
  669. // Used only by the PBR renderer
  670. //static
  671. void LLRenderPass::pushGLTFBatch(LLDrawInfo& params)
  672. {
  673. bool double_sided = false;
  674. LLFetchedGLTFMaterial* matp = params.mGLTFMaterial.get();
  675. if (matp) // NULL does happen. HB
  676. {
  677. matp->bind(params.mTexture, params.mVSize);
  678. double_sided = matp->mDoubleSided;
  679. }
  680. LLGLDisable cull_face(double_sided ? GL_CULL_FACE : 0);
  681. bool has_tex_matrix = params.mTextureMatrix != NULL;
  682. if (has_tex_matrix)
  683. {
  684. // Special case implementation of texture animation here because of
  685. // special handling of textures for PBR batches.
  686. gGL.getTexUnit(0)->activate();
  687. gGL.matrixMode(LLRender::MM_TEXTURE);
  688. gGL.loadMatrix(params.mTextureMatrix->getF32ptr());
  689. ++gPipeline.mTextureMatrixOps;
  690. }
  691. applyModelMatrix(params);
  692. params.mVertexBuffer->setBuffer();
  693. params.mVertexBuffer->drawRange(LLRender::TRIANGLES, params.mStart,
  694. params.mEnd, params.mCount,
  695. params.mOffset);
  696. if (has_tex_matrix)
  697. {
  698. gGL.matrixMode(LLRender::MM_TEXTURE0);
  699. gGL.loadIdentity();
  700. gGL.matrixMode(LLRender::MM_MODELVIEW);
  701. }
  702. }
  703. // Used only by the PBR renderer
  704. //static
  705. void LLRenderPass::pushUntexturedGLTFBatch(LLDrawInfo& params)
  706. {
  707. LLFetchedGLTFMaterial* matp = params.mGLTFMaterial.get();
  708. if (!matp) // Paranoia ?
  709. {
  710. return;
  711. }
  712. LLGLDisable cull_face(matp->mDoubleSided ? GL_CULL_FACE : 0);
  713. applyModelMatrix(params);
  714. params.mVertexBuffer->setBuffer();
  715. params.mVertexBuffer->drawRange(LLRender::TRIANGLES, params.mStart,
  716. params.mEnd, params.mCount,
  717. params.mOffset);
  718. }
  719. // Used only by the PBR renderer
  720. //static
  721. void LLRenderPass::pushRiggedGLTFBatches(U32 type)
  722. {
  723. if (!gPipeline.sCull)
  724. {
  725. // Paranoia (sCull != NULL needed for getRenderMap())
  726. return;
  727. }
  728. LLVOAvatar* last_avatarp = NULL;
  729. U64 last_hash = 0;
  730. LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
  731. for (U32 i = 0, count = draw_list.size(); i < count; )
  732. {
  733. LLDrawInfo* paramsp = draw_list[i++];
  734. // Draw info cache prefetching optimization.
  735. if (i < count)
  736. {
  737. _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
  738. _MM_HINT_NTA);
  739. if (i + 1 < count)
  740. {
  741. _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
  742. }
  743. }
  744. if (paramsp->mAvatar.notNull() && paramsp->mSkinInfo.notNull() &&
  745. (paramsp->mAvatar.get() != last_avatarp ||
  746. paramsp->mSkinInfo->mHash != last_hash))
  747. {
  748. #if 0
  749. if (!uploadMatrixPalette(*paramsp))
  750. {
  751. continue;
  752. }
  753. #else
  754. uploadMatrixPalette(*paramsp);
  755. #endif
  756. last_avatarp = paramsp->mAvatar.get();
  757. last_hash = paramsp->mSkinInfo->mHash;
  758. }
  759. pushGLTFBatch(*paramsp);
  760. }
  761. }
  762. // Used only by the PBR renderer
  763. //static
  764. void LLRenderPass::pushUntexturedRiggedGLTFBatches(U32 type)
  765. {
  766. if (!gPipeline.sCull)
  767. {
  768. // Paranoia (sCull != NULL needed for getRenderMap())
  769. return;
  770. }
  771. LLVOAvatar* last_avatarp = NULL;
  772. U64 last_hash = 0;
  773. LLCullResult::drawinfo_list_t& draw_list = gPipeline.getRenderMap(type);
  774. for (U32 i = 0, count = draw_list.size(); i < count; )
  775. {
  776. LLDrawInfo* paramsp = draw_list[i++];
  777. // Draw info cache prefetching optimization.
  778. if (i < count)
  779. {
  780. _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
  781. _MM_HINT_NTA);
  782. if (i + 1 < count)
  783. {
  784. _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
  785. }
  786. }
  787. if (paramsp->mAvatar.notNull() && paramsp->mSkinInfo.notNull() &&
  788. (paramsp->mAvatar.get() != last_avatarp ||
  789. paramsp->mSkinInfo->mHash != last_hash))
  790. {
  791. #if 0
  792. if (!uploadMatrixPalette(*paramsp))
  793. {
  794. continue;
  795. }
  796. #else
  797. uploadMatrixPalette(*paramsp);
  798. #endif
  799. last_avatarp = paramsp->mAvatar.get();
  800. last_hash = paramsp->mSkinInfo->mHash;
  801. }
  802. pushUntexturedGLTFBatch(*paramsp);
  803. }
  804. }
  805. //static
  806. void LLRenderPass::applyModelMatrix(LLDrawInfo& params)
  807. {
  808. applyModelMatrix(params.mModelMatrix);
  809. }
  810. //static
  811. void LLRenderPass::applyModelMatrix(const LLMatrix4* model_matp)
  812. {
  813. if (model_matp != gGLLastMatrix)
  814. {
  815. gGLLastMatrix = model_matp;
  816. gGL.matrixMode(LLRender::MM_MODELVIEW);
  817. gGL.loadMatrix(gGLModelView.getF32ptr());
  818. if (model_matp)
  819. {
  820. gGL.multMatrix(model_matp->getF32ptr());
  821. }
  822. ++gPipeline.mMatrixOpCount;
  823. }
  824. }
  825. //static
  826. bool LLRenderPass::uploadMatrixPalette(const LLDrawInfo& params)
  827. {
  828. return uploadMatrixPalette(params.mAvatar, params.mSkinInfo);
  829. }
  830. //static
  831. bool LLRenderPass::uploadMatrixPalette(LLVOAvatar* avp, LLMeshSkinInfo* skinp)
  832. {
  833. if (!skinp || !avp || avp->isDead())
  834. {
  835. return false;
  836. }
  837. U32 count = 0;
  838. const F32* mp = avp->getRiggedMatrix(skinp, count);
  839. if (!count) // Render only after skin info has loaded
  840. {
  841. return false;
  842. }
  843. LLGLSLShader* shaderp = LLGLSLShader::sCurBoundShaderPtr;
  844. if (!shaderp) // Paranoia
  845. {
  846. llwarns_sparse << "sCurBoundShaderPtr is NULL !" << llendl;
  847. llassert(false);
  848. return false;
  849. }
  850. shaderp->uniformMatrix3x4fv(LLShaderMgr::AVATAR_MATRIX, count, false, mp);
  851. return true;
  852. }