PageRenderTime 26ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/indra/newview/pipeline.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 2147 lines | 1734 code | 308 blank | 105 comment | 242 complexity | a626ac3162a100298701681638d51672 MD5 | raw file
Possible License(s): LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. /**
  2. * @file pipeline.cpp
  3. * @brief Rendering pipeline.
  4. *
  5. * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "pipeline.h"
  28. // library includes
  29. #include "llaudioengine.h" // For debugging.
  30. #include "imageids.h"
  31. #include "llerror.h"
  32. #include "llviewercontrol.h"
  33. #include "llfasttimer.h"
  34. #include "llfontgl.h"
  35. #include "llmemtype.h"
  36. #include "llnamevalue.h"
  37. #include "llpointer.h"
  38. #include "llprimitive.h"
  39. #include "llvolume.h"
  40. #include "material_codes.h"
  41. #include "timing.h"
  42. #include "v3color.h"
  43. #include "llui.h"
  44. #include "llglheaders.h"
  45. #include "llrender.h"
  46. #include "llwindow.h" // swapBuffers()
  47. // newview includes
  48. #include "llagent.h"
  49. #include "llagentcamera.h"
  50. #include "lldrawable.h"
  51. #include "lldrawpoolalpha.h"
  52. #include "lldrawpoolavatar.h"
  53. #include "lldrawpoolground.h"
  54. #include "lldrawpoolbump.h"
  55. #include "lldrawpooltree.h"
  56. #include "lldrawpoolwater.h"
  57. #include "llface.h"
  58. #include "llfeaturemanager.h"
  59. #include "llfloatertelehub.h"
  60. #include "llfloaterreg.h"
  61. #include "llgldbg.h"
  62. #include "llhudmanager.h"
  63. #include "llhudnametag.h"
  64. #include "llhudtext.h"
  65. #include "lllightconstants.h"
  66. #include "llmeshrepository.h"
  67. #include "llresmgr.h"
  68. #include "llselectmgr.h"
  69. #include "llsky.h"
  70. #include "lltracker.h"
  71. #include "lltool.h"
  72. #include "lltoolmgr.h"
  73. #include "llviewercamera.h"
  74. #include "llviewermediafocus.h"
  75. #include "llviewertexturelist.h"
  76. #include "llviewerobject.h"
  77. #include "llviewerobjectlist.h"
  78. #include "llviewerparcelmgr.h"
  79. #include "llviewerregion.h" // for audio debugging.
  80. #include "llviewerwindow.h" // For getSpinAxis
  81. #include "llvoavatarself.h"
  82. #include "llvoground.h"
  83. #include "llvosky.h"
  84. #include "llvotree.h"
  85. #include "llvovolume.h"
  86. #include "llvosurfacepatch.h"
  87. #include "llvowater.h"
  88. #include "llvotree.h"
  89. #include "llvopartgroup.h"
  90. #include "llworld.h"
  91. #include "llcubemap.h"
  92. #include "llviewershadermgr.h"
  93. #include "llviewerstats.h"
  94. #include "llviewerjoystick.h"
  95. #include "llviewerdisplay.h"
  96. #include "llwlparammanager.h"
  97. #include "llwaterparammanager.h"
  98. #include "llspatialpartition.h"
  99. #include "llmutelist.h"
  100. #include "lltoolpie.h"
  101. #include "llcurl.h"
  102. #include "llnotifications.h"
  103. #ifdef _DEBUG
  104. // Debug indices is disabled for now for debug performance - djs 4/24/02
  105. //#define DEBUG_INDICES
  106. #else
  107. //#define DEBUG_INDICES
  108. #endif
  109. //cached settings
  110. BOOL LLPipeline::RenderAvatarVP;
  111. BOOL LLPipeline::VertexShaderEnable;
  112. BOOL LLPipeline::WindLightUseAtmosShaders;
  113. BOOL LLPipeline::RenderDeferred;
  114. F32 LLPipeline::RenderDeferredSunWash;
  115. U32 LLPipeline::RenderFSAASamples;
  116. U32 LLPipeline::RenderResolutionDivisor;
  117. BOOL LLPipeline::RenderUIBuffer;
  118. S32 LLPipeline::RenderShadowDetail;
  119. BOOL LLPipeline::RenderDeferredSSAO;
  120. F32 LLPipeline::RenderShadowResolutionScale;
  121. BOOL LLPipeline::RenderLocalLights;
  122. BOOL LLPipeline::RenderDelayCreation;
  123. BOOL LLPipeline::RenderAnimateRes;
  124. BOOL LLPipeline::FreezeTime;
  125. S32 LLPipeline::DebugBeaconLineWidth;
  126. F32 LLPipeline::RenderHighlightBrightness;
  127. LLColor4 LLPipeline::RenderHighlightColor;
  128. F32 LLPipeline::RenderHighlightThickness;
  129. BOOL LLPipeline::RenderSpotLightsInNondeferred;
  130. LLColor4 LLPipeline::PreviewAmbientColor;
  131. LLColor4 LLPipeline::PreviewDiffuse0;
  132. LLColor4 LLPipeline::PreviewSpecular0;
  133. LLColor4 LLPipeline::PreviewDiffuse1;
  134. LLColor4 LLPipeline::PreviewSpecular1;
  135. LLColor4 LLPipeline::PreviewDiffuse2;
  136. LLColor4 LLPipeline::PreviewSpecular2;
  137. LLVector3 LLPipeline::PreviewDirection0;
  138. LLVector3 LLPipeline::PreviewDirection1;
  139. LLVector3 LLPipeline::PreviewDirection2;
  140. F32 LLPipeline::RenderGlowMinLuminance;
  141. F32 LLPipeline::RenderGlowMaxExtractAlpha;
  142. F32 LLPipeline::RenderGlowWarmthAmount;
  143. LLVector3 LLPipeline::RenderGlowLumWeights;
  144. LLVector3 LLPipeline::RenderGlowWarmthWeights;
  145. S32 LLPipeline::RenderGlowResolutionPow;
  146. S32 LLPipeline::RenderGlowIterations;
  147. F32 LLPipeline::RenderGlowWidth;
  148. F32 LLPipeline::RenderGlowStrength;
  149. BOOL LLPipeline::RenderDepthOfField;
  150. F32 LLPipeline::CameraFocusTransitionTime;
  151. F32 LLPipeline::CameraFNumber;
  152. F32 LLPipeline::CameraFocalLength;
  153. F32 LLPipeline::CameraFieldOfView;
  154. F32 LLPipeline::RenderShadowNoise;
  155. F32 LLPipeline::RenderShadowBlurSize;
  156. F32 LLPipeline::RenderSSAOScale;
  157. U32 LLPipeline::RenderSSAOMaxScale;
  158. F32 LLPipeline::RenderSSAOFactor;
  159. LLVector3 LLPipeline::RenderSSAOEffect;
  160. F32 LLPipeline::RenderShadowOffsetError;
  161. F32 LLPipeline::RenderShadowBiasError;
  162. F32 LLPipeline::RenderShadowOffset;
  163. F32 LLPipeline::RenderShadowBias;
  164. F32 LLPipeline::RenderSpotShadowOffset;
  165. F32 LLPipeline::RenderSpotShadowBias;
  166. F32 LLPipeline::RenderEdgeDepthCutoff;
  167. F32 LLPipeline::RenderEdgeNormCutoff;
  168. LLVector3 LLPipeline::RenderShadowGaussian;
  169. F32 LLPipeline::RenderShadowBlurDistFactor;
  170. BOOL LLPipeline::RenderDeferredAtmospheric;
  171. S32 LLPipeline::RenderReflectionDetail;
  172. F32 LLPipeline::RenderHighlightFadeTime;
  173. LLVector3 LLPipeline::RenderShadowClipPlanes;
  174. LLVector3 LLPipeline::RenderShadowOrthoClipPlanes;
  175. LLVector3 LLPipeline::RenderShadowNearDist;
  176. F32 LLPipeline::RenderFarClip;
  177. LLVector3 LLPipeline::RenderShadowSplitExponent;
  178. F32 LLPipeline::RenderShadowErrorCutoff;
  179. F32 LLPipeline::RenderShadowFOVCutoff;
  180. BOOL LLPipeline::CameraOffset;
  181. F32 LLPipeline::CameraMaxCoF;
  182. F32 LLPipeline::CameraDoFResScale;
  183. const F32 BACKLIGHT_DAY_MAGNITUDE_AVATAR = 0.2f;
  184. const F32 BACKLIGHT_NIGHT_MAGNITUDE_AVATAR = 0.1f;
  185. const F32 BACKLIGHT_DAY_MAGNITUDE_OBJECT = 0.1f;
  186. const F32 BACKLIGHT_NIGHT_MAGNITUDE_OBJECT = 0.08f;
  187. const S32 MAX_OFFSCREEN_GEOMETRY_CHANGES_PER_FRAME = 10;
  188. const U32 REFLECTION_MAP_RES = 128;
  189. const U32 DEFERRED_VB_MASK = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_TEXCOORD1;
  190. // Max number of occluders to search for. JC
  191. const S32 MAX_OCCLUDER_COUNT = 2;
  192. extern S32 gBoxFrame;
  193. //extern BOOL gHideSelectedObjects;
  194. extern BOOL gDisplaySwapBuffers;
  195. extern BOOL gDebugGL;
  196. // hack counter for rendering a fixed number of frames after toggling
  197. // fullscreen to work around DEV-5361
  198. static S32 sDelayedVBOEnable = 0;
  199. BOOL gAvatarBacklight = FALSE;
  200. BOOL gDebugPipeline = FALSE;
  201. LLPipeline gPipeline;
  202. const LLMatrix4* gGLLastMatrix = NULL;
  203. LLFastTimer::DeclareTimer FTM_RENDER_GEOMETRY("Geometry");
  204. LLFastTimer::DeclareTimer FTM_RENDER_GRASS("Grass");
  205. LLFastTimer::DeclareTimer FTM_RENDER_INVISIBLE("Invisible");
  206. LLFastTimer::DeclareTimer FTM_RENDER_OCCLUSION("Occlusion");
  207. LLFastTimer::DeclareTimer FTM_RENDER_SHINY("Shiny");
  208. LLFastTimer::DeclareTimer FTM_RENDER_SIMPLE("Simple");
  209. LLFastTimer::DeclareTimer FTM_RENDER_TERRAIN("Terrain");
  210. LLFastTimer::DeclareTimer FTM_RENDER_TREES("Trees");
  211. LLFastTimer::DeclareTimer FTM_RENDER_UI("UI");
  212. LLFastTimer::DeclareTimer FTM_RENDER_WATER("Water");
  213. LLFastTimer::DeclareTimer FTM_RENDER_WL_SKY("Windlight Sky");
  214. LLFastTimer::DeclareTimer FTM_RENDER_ALPHA("Alpha Objects");
  215. LLFastTimer::DeclareTimer FTM_RENDER_CHARACTERS("Avatars");
  216. LLFastTimer::DeclareTimer FTM_RENDER_BUMP("Bump");
  217. LLFastTimer::DeclareTimer FTM_RENDER_FULLBRIGHT("Fullbright");
  218. LLFastTimer::DeclareTimer FTM_RENDER_GLOW("Glow");
  219. LLFastTimer::DeclareTimer FTM_GEO_UPDATE("Geo Update");
  220. LLFastTimer::DeclareTimer FTM_POOLRENDER("RenderPool");
  221. LLFastTimer::DeclareTimer FTM_POOLS("Pools");
  222. LLFastTimer::DeclareTimer FTM_RENDER_BLOOM_FBO("First FBO");
  223. LLFastTimer::DeclareTimer FTM_STATESORT("Sort Draw State");
  224. LLFastTimer::DeclareTimer FTM_PIPELINE("Pipeline");
  225. LLFastTimer::DeclareTimer FTM_CLIENT_COPY("Client Copy");
  226. LLFastTimer::DeclareTimer FTM_RENDER_DEFERRED("Deferred Shading");
  227. static LLFastTimer::DeclareTimer FTM_STATESORT_DRAWABLE("Sort Drawables");
  228. static LLFastTimer::DeclareTimer FTM_STATESORT_POSTSORT("Post Sort");
  229. //----------------------------------------
  230. std::string gPoolNames[] =
  231. {
  232. // Correspond to LLDrawpool enum render type
  233. "NONE",
  234. "POOL_SIMPLE",
  235. "POOL_GROUND",
  236. "POOL_FULLBRIGHT",
  237. "POOL_BUMP",
  238. "POOL_TERRAIN,"
  239. "POOL_SKY",
  240. "POOL_WL_SKY",
  241. "POOL_TREE",
  242. "POOL_GRASS",
  243. "POOL_INVISIBLE",
  244. "POOL_AVATAR",
  245. "POOL_VOIDWATER",
  246. "POOL_WATER",
  247. "POOL_GLOW",
  248. "POOL_ALPHA"
  249. };
  250. void drawBox(const LLVector3& c, const LLVector3& r);
  251. void drawBoxOutline(const LLVector3& pos, const LLVector3& size);
  252. U32 nhpo2(U32 v);
  253. glh::matrix4f glh_copy_matrix(F32* src)
  254. {
  255. glh::matrix4f ret;
  256. ret.set_value(src);
  257. return ret;
  258. }
  259. glh::matrix4f glh_get_current_modelview()
  260. {
  261. return glh_copy_matrix(gGLModelView);
  262. }
  263. glh::matrix4f glh_get_current_projection()
  264. {
  265. return glh_copy_matrix(gGLProjection);
  266. }
  267. glh::matrix4f glh_get_last_modelview()
  268. {
  269. return glh_copy_matrix(gGLLastModelView);
  270. }
  271. glh::matrix4f glh_get_last_projection()
  272. {
  273. return glh_copy_matrix(gGLLastProjection);
  274. }
  275. void glh_copy_matrix(const glh::matrix4f& src, F32* dst)
  276. {
  277. for (U32 i = 0; i < 16; i++)
  278. {
  279. dst[i] = src.m[i];
  280. }
  281. }
  282. void glh_set_current_modelview(const glh::matrix4f& mat)
  283. {
  284. glh_copy_matrix(mat, gGLModelView);
  285. }
  286. void glh_set_current_projection(glh::matrix4f& mat)
  287. {
  288. glh_copy_matrix(mat, gGLProjection);
  289. }
  290. glh::matrix4f gl_ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat znear, GLfloat zfar)
  291. {
  292. glh::matrix4f ret(
  293. 2.f/(right-left), 0.f, 0.f, -(right+left)/(right-left),
  294. 0.f, 2.f/(top-bottom), 0.f, -(top+bottom)/(top-bottom),
  295. 0.f, 0.f, -2.f/(zfar-znear), -(zfar+znear)/(zfar-znear),
  296. 0.f, 0.f, 0.f, 1.f);
  297. return ret;
  298. }
  299. void display_update_camera();
  300. //----------------------------------------
  301. S32 LLPipeline::sCompiles = 0;
  302. BOOL LLPipeline::sPickAvatar = TRUE;
  303. BOOL LLPipeline::sDynamicLOD = TRUE;
  304. BOOL LLPipeline::sShowHUDAttachments = TRUE;
  305. BOOL LLPipeline::sRenderMOAPBeacons = FALSE;
  306. BOOL LLPipeline::sRenderPhysicalBeacons = TRUE;
  307. BOOL LLPipeline::sRenderScriptedBeacons = FALSE;
  308. BOOL LLPipeline::sRenderScriptedTouchBeacons = TRUE;
  309. BOOL LLPipeline::sRenderParticleBeacons = FALSE;
  310. BOOL LLPipeline::sRenderSoundBeacons = FALSE;
  311. BOOL LLPipeline::sRenderBeacons = FALSE;
  312. BOOL LLPipeline::sRenderHighlight = TRUE;
  313. BOOL LLPipeline::sForceOldBakedUpload = FALSE;
  314. S32 LLPipeline::sUseOcclusion = 0;
  315. BOOL LLPipeline::sDelayVBUpdate = TRUE;
  316. BOOL LLPipeline::sAutoMaskAlphaDeferred = TRUE;
  317. BOOL LLPipeline::sAutoMaskAlphaNonDeferred = FALSE;
  318. BOOL LLPipeline::sDisableShaders = FALSE;
  319. BOOL LLPipeline::sRenderBump = TRUE;
  320. BOOL LLPipeline::sBakeSunlight = FALSE;
  321. BOOL LLPipeline::sNoAlpha = FALSE;
  322. BOOL LLPipeline::sUseTriStrips = TRUE;
  323. BOOL LLPipeline::sUseFarClip = TRUE;
  324. BOOL LLPipeline::sShadowRender = FALSE;
  325. BOOL LLPipeline::sWaterReflections = FALSE;
  326. BOOL LLPipeline::sRenderGlow = FALSE;
  327. BOOL LLPipeline::sReflectionRender = FALSE;
  328. BOOL LLPipeline::sImpostorRender = FALSE;
  329. BOOL LLPipeline::sUnderWaterRender = FALSE;
  330. BOOL LLPipeline::sTextureBindTest = FALSE;
  331. BOOL LLPipeline::sRenderFrameTest = FALSE;
  332. BOOL LLPipeline::sRenderAttachedLights = TRUE;
  333. BOOL LLPipeline::sRenderAttachedParticles = TRUE;
  334. BOOL LLPipeline::sRenderDeferred = FALSE;
  335. BOOL LLPipeline::sMemAllocationThrottled = FALSE;
  336. S32 LLPipeline::sVisibleLightCount = 0;
  337. F32 LLPipeline::sMinRenderSize = 0.f;
  338. static LLCullResult* sCull = NULL;
  339. static const U32 gl_cube_face[] =
  340. {
  341. GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
  342. GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
  343. GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
  344. GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
  345. GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
  346. GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
  347. };
  348. void validate_framebuffer_object();
  349. bool addDeferredAttachments(LLRenderTarget& target)
  350. {
  351. return target.addColorAttachment(GL_RGBA) && //specular
  352. target.addColorAttachment(GL_RGBA); //normal+z
  353. }
  354. LLPipeline::LLPipeline() :
  355. mBackfaceCull(FALSE),
  356. mBatchCount(0),
  357. mMatrixOpCount(0),
  358. mTextureMatrixOps(0),
  359. mMaxBatchSize(0),
  360. mMinBatchSize(0),
  361. mMeanBatchSize(0),
  362. mTrianglesDrawn(0),
  363. mNumVisibleNodes(0),
  364. mVerticesRelit(0),
  365. mLightingChanges(0),
  366. mGeometryChanges(0),
  367. mNumVisibleFaces(0),
  368. mInitialized(FALSE),
  369. mVertexShadersEnabled(FALSE),
  370. mVertexShadersLoaded(0),
  371. mRenderDebugFeatureMask(0),
  372. mRenderDebugMask(0),
  373. mOldRenderDebugMask(0),
  374. mGroupQ1Locked(false),
  375. mGroupQ2Locked(false),
  376. mLastRebuildPool(NULL),
  377. mAlphaPool(NULL),
  378. mSkyPool(NULL),
  379. mTerrainPool(NULL),
  380. mWaterPool(NULL),
  381. mGroundPool(NULL),
  382. mSimplePool(NULL),
  383. mFullbrightPool(NULL),
  384. mInvisiblePool(NULL),
  385. mGlowPool(NULL),
  386. mBumpPool(NULL),
  387. mWLSkyPool(NULL),
  388. mLightMask(0),
  389. mLightMovingMask(0),
  390. mLightingDetail(0),
  391. mScreenWidth(0),
  392. mScreenHeight(0)
  393. {
  394. mNoiseMap = 0;
  395. mTrueNoiseMap = 0;
  396. mLightFunc = 0;
  397. }
  398. void LLPipeline::init()
  399. {
  400. LLMemType mt(LLMemType::MTYPE_PIPELINE_INIT);
  401. refreshCachedSettings();
  402. gOctreeMaxCapacity = gSavedSettings.getU32("OctreeMaxNodeCapacity");
  403. sDynamicLOD = gSavedSettings.getBOOL("RenderDynamicLOD");
  404. sRenderBump = gSavedSettings.getBOOL("RenderObjectBump");
  405. sUseTriStrips = gSavedSettings.getBOOL("RenderUseTriStrips");
  406. LLVertexBuffer::sUseStreamDraw = gSavedSettings.getBOOL("RenderUseStreamVBO");
  407. LLVertexBuffer::sUseVAO = gSavedSettings.getBOOL("RenderUseVAO");
  408. LLVertexBuffer::sPreferStreamDraw = gSavedSettings.getBOOL("RenderPreferStreamDraw");
  409. sRenderAttachedLights = gSavedSettings.getBOOL("RenderAttachedLights");
  410. sRenderAttachedParticles = gSavedSettings.getBOOL("RenderAttachedParticles");
  411. mInitialized = TRUE;
  412. stop_glerror();
  413. //create render pass pools
  414. getPool(LLDrawPool::POOL_ALPHA);
  415. getPool(LLDrawPool::POOL_SIMPLE);
  416. getPool(LLDrawPool::POOL_GRASS);
  417. getPool(LLDrawPool::POOL_FULLBRIGHT);
  418. getPool(LLDrawPool::POOL_INVISIBLE);
  419. getPool(LLDrawPool::POOL_BUMP);
  420. getPool(LLDrawPool::POOL_GLOW);
  421. LLViewerStats::getInstance()->mTrianglesDrawnStat.reset();
  422. resetFrameStats();
  423. for (U32 i = 0; i < NUM_RENDER_TYPES; ++i)
  424. {
  425. mRenderTypeEnabled[i] = TRUE; //all rendering types start enabled
  426. }
  427. mRenderDebugFeatureMask = 0xffffffff; // All debugging features on
  428. mRenderDebugMask = 0; // All debug starts off
  429. // Don't turn on ground when this is set
  430. // Mac Books with intel 950s need this
  431. if(!gSavedSettings.getBOOL("RenderGround"))
  432. {
  433. toggleRenderType(RENDER_TYPE_GROUND);
  434. }
  435. // make sure RenderPerformanceTest persists (hackity hack hack)
  436. // disables non-object rendering (UI, sky, water, etc)
  437. if (gSavedSettings.getBOOL("RenderPerformanceTest"))
  438. {
  439. gSavedSettings.setBOOL("RenderPerformanceTest", FALSE);
  440. gSavedSettings.setBOOL("RenderPerformanceTest", TRUE);
  441. }
  442. mOldRenderDebugMask = mRenderDebugMask;
  443. mBackfaceCull = TRUE;
  444. stop_glerror();
  445. // Enable features
  446. LLViewerShaderMgr::instance()->setShaders();
  447. stop_glerror();
  448. for (U32 i = 0; i < 2; ++i)
  449. {
  450. mSpotLightFade[i] = 1.f;
  451. }
  452. mDeferredVB = new LLVertexBuffer(DEFERRED_VB_MASK, 0);
  453. mDeferredVB->allocateBuffer(8, 0, true);
  454. setLightingDetail(-1);
  455. //
  456. // Update all settings to trigger a cached settings refresh
  457. //
  458. gSavedSettings.getControl("RenderAutoMaskAlphaDeferred")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  459. gSavedSettings.getControl("RenderAutoMaskAlphaNonDeferred")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  460. gSavedSettings.getControl("RenderUseFarClip")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  461. gSavedSettings.getControl("RenderAvatarMaxVisible")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  462. gSavedSettings.getControl("RenderDelayVBUpdate")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  463. gSavedSettings.getControl("UseOcclusion")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  464. gSavedSettings.getControl("VertexShaderEnable")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  465. gSavedSettings.getControl("RenderAvatarVP")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  466. gSavedSettings.getControl("WindLightUseAtmosShaders")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  467. gSavedSettings.getControl("RenderDeferred")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  468. gSavedSettings.getControl("RenderDeferredSunWash")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  469. gSavedSettings.getControl("RenderFSAASamples")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  470. gSavedSettings.getControl("RenderResolutionDivisor")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  471. gSavedSettings.getControl("RenderUIBuffer")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  472. gSavedSettings.getControl("RenderShadowDetail")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  473. gSavedSettings.getControl("RenderDeferredSSAO")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  474. gSavedSettings.getControl("RenderShadowResolutionScale")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  475. gSavedSettings.getControl("RenderLocalLights")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  476. gSavedSettings.getControl("RenderDelayCreation")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  477. gSavedSettings.getControl("RenderAnimateRes")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  478. gSavedSettings.getControl("FreezeTime")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  479. gSavedSettings.getControl("DebugBeaconLineWidth")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  480. gSavedSettings.getControl("RenderHighlightBrightness")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  481. gSavedSettings.getControl("RenderHighlightColor")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  482. gSavedSettings.getControl("RenderHighlightThickness")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  483. gSavedSettings.getControl("RenderSpotLightsInNondeferred")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  484. gSavedSettings.getControl("PreviewAmbientColor")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  485. gSavedSettings.getControl("PreviewDiffuse0")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  486. gSavedSettings.getControl("PreviewSpecular0")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  487. gSavedSettings.getControl("PreviewDiffuse1")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  488. gSavedSettings.getControl("PreviewSpecular1")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  489. gSavedSettings.getControl("PreviewDiffuse2")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  490. gSavedSettings.getControl("PreviewSpecular2")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  491. gSavedSettings.getControl("PreviewDirection0")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  492. gSavedSettings.getControl("PreviewDirection1")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  493. gSavedSettings.getControl("PreviewDirection2")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  494. gSavedSettings.getControl("RenderGlowMinLuminance")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  495. gSavedSettings.getControl("RenderGlowMaxExtractAlpha")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  496. gSavedSettings.getControl("RenderGlowWarmthAmount")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  497. gSavedSettings.getControl("RenderGlowLumWeights")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  498. gSavedSettings.getControl("RenderGlowWarmthWeights")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  499. gSavedSettings.getControl("RenderGlowResolutionPow")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  500. gSavedSettings.getControl("RenderGlowIterations")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  501. gSavedSettings.getControl("RenderGlowWidth")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  502. gSavedSettings.getControl("RenderGlowStrength")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  503. gSavedSettings.getControl("RenderDepthOfField")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  504. gSavedSettings.getControl("CameraFocusTransitionTime")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  505. gSavedSettings.getControl("CameraFNumber")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  506. gSavedSettings.getControl("CameraFocalLength")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  507. gSavedSettings.getControl("CameraFieldOfView")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  508. gSavedSettings.getControl("RenderShadowNoise")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  509. gSavedSettings.getControl("RenderShadowBlurSize")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  510. gSavedSettings.getControl("RenderSSAOScale")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  511. gSavedSettings.getControl("RenderSSAOMaxScale")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  512. gSavedSettings.getControl("RenderSSAOFactor")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  513. gSavedSettings.getControl("RenderSSAOEffect")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  514. gSavedSettings.getControl("RenderShadowOffsetError")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  515. gSavedSettings.getControl("RenderShadowBiasError")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  516. gSavedSettings.getControl("RenderShadowOffset")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  517. gSavedSettings.getControl("RenderShadowBias")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  518. gSavedSettings.getControl("RenderSpotShadowOffset")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  519. gSavedSettings.getControl("RenderSpotShadowBias")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  520. gSavedSettings.getControl("RenderEdgeDepthCutoff")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  521. gSavedSettings.getControl("RenderEdgeNormCutoff")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  522. gSavedSettings.getControl("RenderShadowGaussian")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  523. gSavedSettings.getControl("RenderShadowBlurDistFactor")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  524. gSavedSettings.getControl("RenderDeferredAtmospheric")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  525. gSavedSettings.getControl("RenderReflectionDetail")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  526. gSavedSettings.getControl("RenderHighlightFadeTime")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  527. gSavedSettings.getControl("RenderShadowClipPlanes")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  528. gSavedSettings.getControl("RenderShadowOrthoClipPlanes")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  529. gSavedSettings.getControl("RenderShadowNearDist")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  530. gSavedSettings.getControl("RenderFarClip")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  531. gSavedSettings.getControl("RenderShadowSplitExponent")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  532. gSavedSettings.getControl("RenderShadowErrorCutoff")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  533. gSavedSettings.getControl("RenderShadowFOVCutoff")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  534. gSavedSettings.getControl("CameraOffset")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  535. gSavedSettings.getControl("CameraMaxCoF")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  536. gSavedSettings.getControl("CameraDoFResScale")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
  537. }
  538. LLPipeline::~LLPipeline()
  539. {
  540. }
  541. void LLPipeline::cleanup()
  542. {
  543. assertInitialized();
  544. mGroupQ1.clear() ;
  545. mGroupQ2.clear() ;
  546. for(pool_set_t::iterator iter = mPools.begin();
  547. iter != mPools.end(); )
  548. {
  549. pool_set_t::iterator curiter = iter++;
  550. LLDrawPool* poolp = *curiter;
  551. if (poolp->isFacePool())
  552. {
  553. LLFacePool* face_pool = (LLFacePool*) poolp;
  554. if (face_pool->mReferences.empty())
  555. {
  556. mPools.erase(curiter);
  557. removeFromQuickLookup( poolp );
  558. delete poolp;
  559. }
  560. }
  561. else
  562. {
  563. mPools.erase(curiter);
  564. removeFromQuickLookup( poolp );
  565. delete poolp;
  566. }
  567. }
  568. if (!mTerrainPools.empty())
  569. {
  570. llwarns << "Terrain Pools not cleaned up" << llendl;
  571. }
  572. if (!mTreePools.empty())
  573. {
  574. llwarns << "Tree Pools not cleaned up" << llendl;
  575. }
  576. delete mAlphaPool;
  577. mAlphaPool = NULL;
  578. delete mSkyPool;
  579. mSkyPool = NULL;
  580. delete mTerrainPool;
  581. mTerrainPool = NULL;
  582. delete mWaterPool;
  583. mWaterPool = NULL;
  584. delete mGroundPool;
  585. mGroundPool = NULL;
  586. delete mSimplePool;
  587. mSimplePool = NULL;
  588. delete mFullbrightPool;
  589. mFullbrightPool = NULL;
  590. delete mInvisiblePool;
  591. mInvisiblePool = NULL;
  592. delete mGlowPool;
  593. mGlowPool = NULL;
  594. delete mBumpPool;
  595. mBumpPool = NULL;
  596. // don't delete wl sky pool it was handled above in the for loop
  597. //delete mWLSkyPool;
  598. mWLSkyPool = NULL;
  599. releaseGLBuffers();
  600. mFaceSelectImagep = NULL;
  601. mMovedBridge.clear();
  602. mInitialized = FALSE;
  603. mDeferredVB = NULL;
  604. }
  605. //============================================================================
  606. void LLPipeline::destroyGL()
  607. {
  608. stop_glerror();
  609. unloadShaders();
  610. mHighlightFaces.clear();
  611. resetDrawOrders();
  612. resetVertexBuffers();
  613. releaseGLBuffers();
  614. if (LLVertexBuffer::sEnableVBOs)
  615. {
  616. // render 30 frames after switching to work around DEV-5361
  617. sDelayedVBOEnable = 30;
  618. LLVertexBuffer::sEnableVBOs = FALSE;
  619. }
  620. }
  621. static LLFastTimer::DeclareTimer FTM_RESIZE_SCREEN_TEXTURE("Resize Screen Texture");
  622. //static
  623. void LLPipeline::throttleNewMemoryAllocation(BOOL disable)
  624. {
  625. if(sMemAllocationThrottled != disable)
  626. {
  627. sMemAllocationThrottled = disable ;
  628. if(sMemAllocationThrottled)
  629. {
  630. //send out notification
  631. LLNotification::Params params("LowMemory");
  632. LLNotifications::instance().add(params);
  633. //release some memory.
  634. }
  635. }
  636. }
  637. void LLPipeline::resizeScreenTexture()
  638. {
  639. LLFastTimer ft(FTM_RESIZE_SCREEN_TEXTURE);
  640. if (gPipeline.canUseVertexShaders() && assertInitialized())
  641. {
  642. GLuint resX = gViewerWindow->getWorldViewWidthRaw();
  643. GLuint resY = gViewerWindow->getWorldViewHeightRaw();
  644. allocateScreenBuffer(resX,resY);
  645. }
  646. }
  647. void LLPipeline::allocatePhysicsBuffer()
  648. {
  649. GLuint resX = gViewerWindow->getWorldViewWidthRaw();
  650. GLuint resY = gViewerWindow->getWorldViewHeightRaw();
  651. if (mPhysicsDisplay.getWidth() != resX || mPhysicsDisplay.getHeight() != resY)
  652. {
  653. mPhysicsDisplay.allocate(resX, resY, GL_RGBA, TRUE, FALSE, LLTexUnit::TT_RECT_TEXTURE, FALSE);
  654. }
  655. }
  656. void LLPipeline::allocateScreenBuffer(U32 resX, U32 resY)
  657. {
  658. refreshCachedSettings();
  659. U32 samples = RenderFSAASamples;
  660. //try to allocate screen buffers at requested resolution and samples
  661. // - on failure, shrink number of samples and try again
  662. // - if not multisampled, shrink resolution and try again (favor X resolution over Y)
  663. // Make sure to call "releaseScreenBuffers" after each failure to cleanup the partially loaded state
  664. if (!allocateScreenBuffer(resX, resY, samples))
  665. {
  666. releaseScreenBuffers();
  667. //reduce number of samples
  668. while (samples > 0)
  669. {
  670. samples /= 2;
  671. if (allocateScreenBuffer(resX, resY, samples))
  672. { //success
  673. return;
  674. }
  675. releaseScreenBuffers();
  676. }
  677. samples = 0;
  678. //reduce resolution
  679. while (resY > 0 && resX > 0)
  680. {
  681. resY /= 2;
  682. if (allocateScreenBuffer(resX, resY, samples))
  683. {
  684. return;
  685. }
  686. releaseScreenBuffers();
  687. resX /= 2;
  688. if (allocateScreenBuffer(resX, resY, samples))
  689. {
  690. return;
  691. }
  692. releaseScreenBuffers();
  693. }
  694. llwarns << "Unable to allocate screen buffer at any resolution!" << llendl;
  695. }
  696. }
  697. bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples)
  698. {
  699. refreshCachedSettings();
  700. // remember these dimensions
  701. mScreenWidth = resX;
  702. mScreenHeight = resY;
  703. U32 res_mod = RenderResolutionDivisor;
  704. if (res_mod > 1 && res_mod < resX && res_mod < resY)
  705. {
  706. resX /= res_mod;
  707. resY /= res_mod;
  708. }
  709. if (RenderUIBuffer)
  710. {
  711. if (!mUIScreen.allocate(resX,resY, GL_RGBA, FALSE, FALSE, LLTexUnit::TT_RECT_TEXTURE, FALSE))
  712. {
  713. return false;
  714. }
  715. }
  716. if (LLPipeline::sRenderDeferred)
  717. {
  718. S32 shadow_detail = RenderShadowDetail;
  719. BOOL ssao = RenderDeferredSSAO;
  720. //allocate deferred rendering color buffers
  721. if (!mDeferredScreen.allocate(resX, resY, GL_RGBA, TRUE, TRUE, LLTexUnit::TT_RECT_TEXTURE, FALSE, samples)) return false;
  722. if (!mDeferredDepth.allocate(resX, resY, 0, TRUE, FALSE, LLTexUnit::TT_RECT_TEXTURE, FALSE, samples)) return false;
  723. if (!addDeferredAttachments(mDeferredScreen)) return false;
  724. if (!mScreen.allocate(resX, resY, GL_RGBA, FALSE, FALSE, LLTexUnit::TT_RECT_TEXTURE, FALSE, samples)) return false;
  725. if (samples > 0)
  726. {
  727. if (!mFXAABuffer.allocate(nhpo2(resX), nhpo2(resY), GL_RGBA, FALSE, FALSE, LLTexUnit::TT_TEXTURE, FALSE, samples)) return false;
  728. }
  729. else
  730. {
  731. mFXAABuffer.release();
  732. }
  733. if (shadow_detail > 0 || ssao || RenderDepthOfField || samples > 0)
  734. { //only need mDeferredLight for shadows OR ssao OR dof OR fxaa
  735. if (!mDeferredLight.allocate(resX, resY, GL_RGBA, FALSE, FALSE, LLTexUnit::TT_RECT_TEXTURE, FALSE)) return false;
  736. }
  737. else
  738. {
  739. mDeferredLight.release();
  740. }
  741. F32 scale = RenderShadowResolutionScale;
  742. if (shadow_detail > 0)
  743. { //allocate 4 sun shadow maps
  744. for (U32 i = 0; i < 4; i++)
  745. {
  746. if (!mShadow[i].allocate(U32(resX*scale),U32(resY*scale), 0, TRUE, FALSE, LLTexUnit::TT_RECT_TEXTURE)) return false;
  747. }
  748. }
  749. else
  750. {
  751. for (U32 i = 0; i < 4; i++)
  752. {
  753. mShadow[i].release();
  754. }
  755. }
  756. U32 width = nhpo2(U32(resX*scale))/2;
  757. U32 height = width;
  758. if (shadow_detail > 1)
  759. { //allocate two spot shadow maps
  760. for (U32 i = 4; i < 6; i++)
  761. {
  762. if (!mShadow[i].allocate(width, height, 0, TRUE, FALSE)) return false;
  763. }
  764. }
  765. else
  766. {
  767. for (U32 i = 4; i < 6; i++)
  768. {
  769. mShadow[i].release();
  770. }
  771. }
  772. }
  773. else
  774. {
  775. mDeferredLight.release();
  776. for (U32 i = 0; i < 6; i++)
  777. {
  778. mShadow[i].release();
  779. }
  780. mFXAABuffer.release();
  781. mScreen.release();
  782. mDeferredScreen.release(); //make sure to release any render targets that share a depth buffer with mDeferredScreen first
  783. mDeferredDepth.release();
  784. if (!mScreen.allocate(resX, resY, GL_RGBA, TRUE, TRUE, LLTexUnit::TT_RECT_TEXTURE, FALSE)) return false;
  785. }
  786. if (LLPipeline::sRenderDeferred)
  787. { //share depth buffer between deferred targets
  788. mDeferredScreen.shareDepthBuffer(mScreen);
  789. }
  790. gGL.getTexUnit(0)->disable();
  791. stop_glerror();
  792. return true;
  793. }
  794. //static
  795. void LLPipeline::updateRenderDeferred()
  796. {
  797. BOOL deferred = ((RenderDeferred &&
  798. LLRenderTarget::sUseFBO &&
  799. LLFeatureManager::getInstance()->isFeatureAvailable("RenderDeferred") &&
  800. VertexShaderEnable &&
  801. RenderAvatarVP &&
  802. WindLightUseAtmosShaders) ? TRUE : FALSE) &&
  803. !gUseWireframe;
  804. sRenderDeferred = deferred;
  805. if (deferred)
  806. { //must render glow when rendering deferred since post effect pass is needed to present any lighting at all
  807. sRenderGlow = TRUE;
  808. }
  809. }
  810. //static
  811. void LLPipeline::refreshCachedSettings()
  812. {
  813. LLPipeline::sAutoMaskAlphaDeferred = gSavedSettings.getBOOL("RenderAutoMaskAlphaDeferred");
  814. LLPipeline::sAutoMaskAlphaNonDeferred = gSavedSettings.getBOOL("RenderAutoMaskAlphaNonDeferred");
  815. LLPipeline::sUseFarClip = gSavedSettings.getBOOL("RenderUseFarClip");
  816. LLVOAvatar::sMaxVisible = (U32)gSavedSettings.getS32("RenderAvatarMaxVisible");
  817. LLPipeline::sDelayVBUpdate = gSavedSettings.getBOOL("RenderDelayVBUpdate");
  818. LLPipeline::sUseOcclusion =
  819. (!gUseWireframe
  820. && LLFeatureManager::getInstance()->isFeatureAvailable("UseOcclusion")
  821. && gSavedSettings.getBOOL("UseOcclusion")
  822. && gGLManager.mHasOcclusionQuery) ? 2 : 0;
  823. VertexShaderEnable = gSavedSettings.getBOOL("VertexShaderEnable");
  824. RenderAvatarVP = gSavedSettings.getBOOL("RenderAvatarVP");
  825. WindLightUseAtmosShaders = gSavedSettings.getBOOL("WindLightUseAtmosShaders");
  826. RenderDeferred = gSavedSettings.getBOOL("RenderDeferred");
  827. RenderDeferredSunWash = gSavedSettings.getF32("RenderDeferredSunWash");
  828. RenderFSAASamples = gSavedSettings.getU32("RenderFSAASamples");
  829. RenderResolutionDivisor = gSavedSettings.getU32("RenderResolutionDivisor");
  830. RenderUIBuffer = gSavedSettings.getBOOL("RenderUIBuffer");
  831. RenderShadowDetail = gSavedSettings.getS32("RenderShadowDetail");
  832. RenderDeferredSSAO = gSavedSettings.getBOOL("RenderDeferredSSAO");
  833. RenderShadowResolutionScale = gSavedSettings.getF32("RenderShadowResolutionScale");
  834. RenderLocalLights = gSavedSettings.getBOOL("RenderLocalLights");
  835. RenderDelayCreation = gSavedSettings.getBOOL("RenderDelayCreation");
  836. RenderAnimateRes = gSavedSettings.getBOOL("RenderAnimateRes");
  837. FreezeTime = gSavedSettings.getBOOL("FreezeTime");
  838. DebugBeaconLineWidth = gSavedSettings.getS32("DebugBeaconLineWidth");
  839. RenderHighlightBrightness = gSavedSettings.getF32("RenderHighlightBrightness");
  840. RenderHighlightColor = gSavedSettings.getColor4("RenderHighlightColor");
  841. RenderHighlightThickness = gSavedSettings.getF32("RenderHighlightThickness");
  842. RenderSpotLightsInNondeferred = gSavedSettings.getBOOL("RenderSpotLightsInNondeferred");
  843. PreviewAmbientColor = gSavedSettings.getColor4("PreviewAmbientColor");
  844. PreviewDiffuse0 = gSavedSettings.getColor4("PreviewDiffuse0");
  845. PreviewSpecular0 = gSavedSettings.getColor4("PreviewSpecular0");
  846. PreviewDiffuse1 = gSavedSettings.getColor4("PreviewDiffuse1");
  847. PreviewSpecular1 = gSavedSettings.getColor4("PreviewSpecular1");
  848. PreviewDiffuse2 = gSavedSettings.getColor4("PreviewDiffuse2");
  849. PreviewSpecular2 = gSavedSettings.getColor4("PreviewSpecular2");
  850. PreviewDirection0 = gSavedSettings.getVector3("PreviewDirection0");
  851. PreviewDirection1 = gSavedSettings.getVector3("PreviewDirection1");
  852. PreviewDirection2 = gSavedSettings.getVector3("PreviewDirection2");
  853. RenderGlowMinLuminance = gSavedSettings.getF32("RenderGlowMinLuminance");
  854. RenderGlowMaxExtractAlpha = gSavedSettings.getF32("RenderGlowMaxExtractAlpha");
  855. RenderGlowWarmthAmount = gSavedSettings.getF32("RenderGlowWarmthAmount");
  856. RenderGlowLumWeights = gSavedSettings.getVector3("RenderGlowLumWeights");
  857. RenderGlowWarmthWeights = gSavedSettings.getVector3("RenderGlowWarmthWeights");
  858. RenderGlowResolutionPow = gSavedSettings.getS32("RenderGlowResolutionPow");
  859. RenderGlowIterations = gSavedSettings.getS32("RenderGlowIterations");
  860. RenderGlowWidth = gSavedSettings.getF32("RenderGlowWidth");
  861. RenderGlowStrength = gSavedSettings.getF32("RenderGlowStrength");
  862. RenderDepthOfField = gSavedSettings.getBOOL("RenderDepthOfField");
  863. CameraFocusTransitionTime = gSavedSettings.getF32("CameraFocusTransitionTime");
  864. CameraFNumber = gSavedSettings.getF32("CameraFNumber");
  865. CameraFocalLength = gSavedSettings.getF32("CameraFocalLength");
  866. CameraFieldOfView = gSavedSettings.getF32("CameraFieldOfView");
  867. RenderShadowNoise = gSavedSettings.getF32("RenderShadowNoise");
  868. RenderShadowBlurSize = gSavedSettings.getF32("RenderShadowBlurSize");
  869. RenderSSAOScale = gSavedSettings.getF32("RenderSSAOScale");
  870. RenderSSAOMaxScale = gSavedSettings.getU32("RenderSSAOMaxScale");
  871. RenderSSAOFactor = gSavedSettings.getF32("RenderSSAOFactor");
  872. RenderSSAOEffect = gSavedSettings.getVector3("RenderSSAOEffect");
  873. RenderShadowOffsetError = gSavedSettings.getF32("RenderShadowOffsetError");
  874. RenderShadowBiasError = gSavedSettings.getF32("RenderShadowBiasError");
  875. RenderShadowOffset = gSavedSettings.getF32("RenderShadowOffset");
  876. RenderShadowBias = gSavedSettings.getF32("RenderShadowBias");
  877. RenderSpotShadowOffset = gSavedSettings.getF32("RenderSpotShadowOffset");
  878. RenderSpotShadowBias = gSavedSettings.getF32("RenderSpotShadowBias");
  879. RenderEdgeDepthCutoff = gSavedSettings.getF32("RenderEdgeDepthCutoff");
  880. RenderEdgeNormCutoff = gSavedSettings.getF32("RenderEdgeNormCutoff");
  881. RenderShadowGaussian = gSavedSettings.getVector3("RenderShadowGaussian");
  882. RenderShadowBlurDistFactor = gSavedSettings.getF32("RenderShadowBlurDistFactor");
  883. RenderDeferredAtmospheric = gSavedSettings.getBOOL("RenderDeferredAtmospheric");
  884. RenderReflectionDetail = gSavedSettings.getS32("RenderReflectionDetail");
  885. RenderHighlightFadeTime = gSavedSettings.getF32("RenderHighlightFadeTime");
  886. RenderShadowClipPlanes = gSavedSettings.getVector3("RenderShadowClipPlanes");
  887. RenderShadowOrthoClipPlanes = gSavedSettings.getVector3("RenderShadowOrthoClipPlanes");
  888. RenderShadowNearDist = gSavedSettings.getVector3("RenderShadowNearDist");
  889. RenderFarClip = gSavedSettings.getF32("RenderFarClip");
  890. RenderShadowSplitExponent = gSavedSettings.getVector3("RenderShadowSplitExponent");
  891. RenderShadowErrorCutoff = gSavedSettings.getF32("RenderShadowErrorCutoff");
  892. RenderShadowFOVCutoff = gSavedSettings.getF32("RenderShadowFOVCutoff");
  893. CameraOffset = gSavedSettings.getBOOL("CameraOffset");
  894. CameraMaxCoF = gSavedSettings.getF32("CameraMaxCoF");
  895. CameraDoFResScale = gSavedSettings.getF32("CameraDoFResScale");
  896. updateRenderDeferred();
  897. }
  898. void LLPipeline::releaseGLBuffers()
  899. {
  900. assertInitialized();
  901. if (mNoiseMap)
  902. {
  903. LLImageGL::deleteTextures(1, &mNoiseMap);
  904. mNoiseMap = 0;
  905. }
  906. if (mTrueNoiseMap)
  907. {
  908. LLImageGL::deleteTextures(1, &mTrueNoiseMap);
  909. mTrueNoiseMap = 0;
  910. }
  911. if (mLightFunc)
  912. {
  913. LLImageGL::deleteTextures(1, &mLightFunc);
  914. mLightFunc = 0;
  915. }
  916. mWaterRef.release();
  917. mWaterDis.release();
  918. for (U32 i = 0; i < 3; i++)
  919. {
  920. mGlow[i].release();
  921. }
  922. releaseScreenBuffers();
  923. gBumpImageList.destroyGL();
  924. LLVOAvatar::resetImpostors();
  925. }
  926. void LLPipeline::releaseScreenBuffers()
  927. {
  928. mUIScreen.release();
  929. mScreen.release();
  930. mFXAABuffer.release();
  931. mPhysicsDisplay.release();
  932. mDeferredScreen.release();
  933. mDeferredDepth.release();
  934. mDeferredLight.release();
  935. mHighlight.release();
  936. for (U32 i = 0; i < 6; i++)
  937. {
  938. mShadow[i].release();
  939. }
  940. }
  941. void LLPipeline::createGLBuffers()
  942. {
  943. stop_glerror();
  944. LLMemType mt_cb(LLMemType::MTYPE_PIPELINE_CREATE_BUFFERS);
  945. assertInitialized();
  946. updateRenderDeferred();
  947. if (LLPipeline::sWaterReflections)
  948. { //water reflection texture
  949. U32 res = (U32) gSavedSettings.getS32("RenderWaterRefResolution");
  950. mWaterRef.allocate(res,res,GL_RGBA,TRUE,FALSE);
  951. mWaterDis.allocate(res,res,GL_RGBA,TRUE,FALSE);
  952. }
  953. mHighlight.allocate(256,256,GL_RGBA, FALSE, FALSE);
  954. stop_glerror();
  955. GLuint resX = gViewerWindow->getWorldViewWidthRaw();
  956. GLuint resY = gViewerWindow->getWorldViewHeightRaw();
  957. if (LLPipeline::sRenderGlow)
  958. { //screen space glow buffers
  959. const U32 glow_res = llmax(1,
  960. llmin(512, 1 << gSavedSettings.getS32("RenderGlowResolutionPow")));
  961. for (U32 i = 0; i < 3; i++)
  962. {
  963. mGlow[i].allocate(512,glow_res,GL_RGBA,FALSE,FALSE);
  964. }
  965. allocateScreenBuffer(resX,resY);
  966. mScreenWidth = 0;
  967. mScreenHeight = 0;
  968. }
  969. if (sRenderDeferred)
  970. {
  971. if (!mNoiseMap)
  972. {
  973. const U32 noiseRes = 128;
  974. LLVector3 noise[noiseRes*noiseRes];
  975. F32 scaler = gSavedSettings.getF32("RenderDeferredNoise")/100.f;
  976. for (U32 i = 0; i < noiseRes*noiseRes; ++i)
  977. {
  978. noise[i] = LLVector3(ll_frand()-0.5f, ll_frand()-0.5f, 0.f);
  979. noise[i].normVec();
  980. noise[i].mV[2] = ll_frand()*scaler+1.f-scaler/2.f;
  981. }
  982. LLImageGL::generateTextures(1, &mNoiseMap);
  983. gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mNoiseMap);
  984. LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, GL_RGB16F_ARB, noiseRes, noiseRes, GL_RGB, GL_FLOAT, noise);
  985. gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
  986. }
  987. if (!mTrueNoiseMap)
  988. {
  989. const U32 noiseRes = 128;
  990. F32 noise[noiseRes*noiseRes*3];
  991. for (U32 i = 0; i < noiseRes*noiseRes*3; i++)
  992. {
  993. noise[i] = ll_frand()*2.0-1.0;
  994. }
  995. LLImageGL::generateTextures(1, &mTrueNoiseMap);
  996. gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mTrueNoiseMap);
  997. LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, GL_RGB16F_ARB, noiseRes, noiseRes, GL_RGB,GL_FLOAT, noise);
  998. gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
  999. }
  1000. if (!mLightFunc)
  1001. {
  1002. U32 lightResX = gSavedSettings.getU32("RenderSpecularResX");
  1003. U32 lightResY = gSavedSettings.getU32("RenderSpecularResY");
  1004. U8* lg = new U8[lightResX*lightResY];
  1005. for (U32 y = 0; y < lightResY; ++y)
  1006. {
  1007. for (U32 x = 0; x < lightResX; ++x)
  1008. {
  1009. //spec func
  1010. F32 sa = (F32) x/(lightResX-1);
  1011. F32 spec = (F32) y/(lightResY-1);
  1012. //lg[y*lightResX+x] = (U8) (powf(sa, 128.f*spec*spec)*255);
  1013. //F32 sp = acosf(sa)/(1.f-spec);
  1014. sa = powf(sa, gSavedSettings.getF32("RenderSpecularExponent"));
  1015. F32 a = acosf(sa*0.25f+0.75f);
  1016. F32 m = llmax(0.5f-spec*0.5f, 0.001f);
  1017. F32 t2 = tanf(a)/m;
  1018. t2 *= t2;
  1019. F32 c4a = (3.f+4.f*cosf(2.f*a)+cosf(4.f*a))/8.f;
  1020. F32 bd = 1.f/(4.f*m*m*c4a)*powf(F_E, -t2);
  1021. lg[y*lightResX+x] = (U8) (llclamp(bd, 0.f, 1.f)*255);
  1022. }
  1023. }
  1024. LLImageGL::generateTextures(1, &mLightFunc);
  1025. gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mLightFunc);
  1026. LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, GL_R8, lightResX, lightResY, GL_RED, GL_UNSIGNED_BYTE, lg);
  1027. gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
  1028. gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_TRILINEAR);
  1029. delete [] lg;
  1030. }
  1031. }
  1032. gBumpImageList.restoreGL();
  1033. }
  1034. void LLPipeline::restoreGL()
  1035. {
  1036. LLMemType mt_cb(LLMemType::MTYPE_PIPELINE_RESTORE_GL);
  1037. assertInitialized();
  1038. if (mVertexShadersEnabled)
  1039. {
  1040. LLViewerShaderMgr::instance()->setShaders();
  1041. }
  1042. for (LLWorld::region_list_t::const_iterator iter = LLWorld::getInstance()->getRegionList().begin();
  1043. iter != LLWorld::getInstance()->getRegionList().end(); ++iter)
  1044. {
  1045. LLViewerRegion* region = *iter;
  1046. for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++)
  1047. {
  1048. LLSpatialPartition* part = region->getSpatialPartition(i);
  1049. if (part)
  1050. {
  1051. part->restoreGL();
  1052. }
  1053. }
  1054. }
  1055. }
  1056. BOOL LLPipeline::canUseVertexShaders()
  1057. {
  1058. if (sDisableShaders ||
  1059. !gGLManager.mHasVertexShader ||
  1060. !gGLManager.mHasFragmentShader ||
  1061. !LLFeatureManager::getInstance()->isFeatureAvailable("VertexShaderEnable") ||
  1062. (assertInitialized() && mVertexShadersLoaded != 1) )
  1063. {
  1064. return FALSE;
  1065. }
  1066. else
  1067. {
  1068. return TRUE;
  1069. }
  1070. }
  1071. BOOL LLPipeline::canUseWindLightShaders() const
  1072. {
  1073. return (!LLPipeline::sDisableShaders &&
  1074. gWLSkyProgram.mProgramObject != 0 &&
  1075. LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_WINDLIGHT) > 1);
  1076. }
  1077. BOOL LLPipeline::canUseWindLightShadersOnObjects() const
  1078. {
  1079. return (canUseWindLightShaders()
  1080. && LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_OBJECT) > 0);
  1081. }
  1082. BOOL LLPipeline::canUseAntiAliasing() const
  1083. {
  1084. return TRUE;
  1085. }
  1086. void LLPipeline::unloadShaders()
  1087. {
  1088. LLMemType mt_us(LLMemType::MTYPE_PIPELINE_UNLOAD_SHADERS);
  1089. LLViewerShaderMgr::instance()->unloadShaders();
  1090. mVertexShadersLoaded = 0;
  1091. }
  1092. void LLPipeline::assertInitializedDoError()
  1093. {
  1094. llerrs << "LLPipeline used when uninitialized." << llendl;
  1095. }
  1096. //============================================================================
  1097. void LLPipeline::enableShadows(const BOOL enable_shadows)
  1098. {
  1099. //should probably do something here to wrangle shadows....
  1100. }
  1101. S32 LLPipeline::getMaxLightingDetail() const
  1102. {
  1103. /*if (mVertexShaderLevel[SHADER_OBJECT] >= LLDrawPoolSimple::SHADER_LEVEL_LOCAL_LIGHTS)
  1104. {
  1105. return 3;
  1106. }
  1107. else*/
  1108. {
  1109. return 1;
  1110. }
  1111. }
  1112. S32 LLPipeline::setLightingDetail(S32 level)
  1113. {
  1114. LLMemType mt_ld(LLMemType::MTYPE_PIPELINE_LIGHTING_DETAIL);
  1115. refreshCachedSettings();
  1116. if (level < 0)
  1117. {
  1118. if (RenderLocalLights)
  1119. {
  1120. level = 1;
  1121. }
  1122. else
  1123. {
  1124. level = 0;
  1125. }
  1126. }
  1127. level = llclamp(level, 0, getMaxLightingDetail());
  1128. mLightingDetail = level;
  1129. return mLightingDetail;
  1130. }
  1131. class LLOctreeDirtyTexture : public LLOctreeTraveler<LLDrawable>
  1132. {
  1133. public:
  1134. const std::set<LLViewerFetchedTexture*>& mTextures;
  1135. LLOctreeDirtyTexture(const std::set<LLViewerFetchedTexture*>& textures) : mTextures(textures) { }
  1136. virtual void visit(const LLOctreeNode<LLDrawable>* node)
  1137. {
  1138. LLSpatialGroup* group = (LLSpatialGroup*) node->getListener(0);
  1139. if (!group->isState(LLSpatialGroup::GEOM_DIRTY) && !group->getData().empty())
  1140. {
  1141. for (LLSpatialGroup::draw_map_t::iterator i = group->mDrawMap.begin(); i != group->mDrawMap.end(); ++i)
  1142. {
  1143. for (LLSpatialGroup::drawmap_elem_t::iterator j = i->second.begin(); j != i->second.end(); ++j)
  1144. {
  1145. LLDrawInfo* params = *j;
  1146. LLViewerFetchedTexture* tex = LLViewerTextureManager::staticCastToFetchedTexture(params->mTexture);
  1147. if (tex && mTextures.find(tex) != mTextures.end())
  1148. {
  1149. group->setState(LLSpatialGroup::GEOM_DIRTY);
  1150. }
  1151. }
  1152. }
  1153. }
  1154. for (LLSpatialGroup::bridge_list_t::iterator i = group->mBridgeList.begin(); i != group->mBridgeList.end(); ++i)
  1155. {
  1156. LLSpatialBridge* bridge = *i;
  1157. traverse(bridge->mOctree);
  1158. }
  1159. }
  1160. };
  1161. // Called when a texture changes # of channels (causes faces to move to alpha pool)
  1162. void LLPipeline::dirtyPoolObjectTextures(const std::set<LLViewerFetchedTexture*>& textures)
  1163. {
  1164. assertInitialized();
  1165. // *TODO: This is inefficient and causes frame spikes; need a better way to do this
  1166. // Most of the time is spent in dirty.traverse.
  1167. for (pool_set_t::iterator iter = mPools.begin(); iter != mPools.end(); ++iter)
  1168. {
  1169. LLDrawPool *poolp = *iter;
  1170. if (poolp->isFacePool())
  1171. {
  1172. ((LLFacePool*) poolp)->dirtyTextures(textures);
  1173. }
  1174. }
  1175. LLOctreeDirtyTexture dirty(textures);
  1176. for (LLWorld::region_list_t::const_iterator iter = LLWorld::getInstance()->getRegionList().begin();
  1177. iter != LLWorld::getInstance()->getRegionList().end(); ++iter)
  1178. {
  1179. LLViewerRegion* region = *iter;
  1180. for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++)
  1181. {
  1182. LLSpatialPartition* part = region->getSpatialPartition(i);
  1183. if (part)
  1184. {
  1185. dirty.traverse(part->mOctree);
  1186. }
  1187. }
  1188. }
  1189. }
  1190. LLDrawPool *LLPipeline::findPool(const U32 type, LLViewerTexture *tex0)
  1191. {
  1192. assertInitialized();
  1193. LLDrawPool *poolp = NULL;
  1194. switch( type )
  1195. {
  1196. case LLDrawPool::POOL_SIMPLE:
  1197. poolp = mSimplePool;
  1198. break;
  1199. case LLDrawPool::POOL_GRASS:
  1200. poolp = mGrassPool;
  1201. break;
  1202. case LLDrawPool::POOL_FULLBRIGHT:
  1203. poolp = mFullbrightPool;
  1204. break;
  1205. case LLDrawPool::POOL_INVISIBLE:
  1206. poolp = mInvisiblePool;
  1207. break;
  1208. case LLDrawPool::POOL_GLOW:
  1209. poolp = mGlowPool;
  1210. break;
  1211. case LLDrawPool::POOL_TREE:
  1212. poolp = get_if_there(mTreePools, (uintptr_t)tex0, (LLDrawPool*)0 );
  1213. break;
  1214. case LLDrawPool::POOL_TERRAIN:
  1215. poolp = get_if_there(mTerrainPools, (uintptr_t)tex0, (LLDrawPool*)0 );
  1216. break;
  1217. case LLDrawPool::POOL_BUMP:
  1218. poolp = mBumpPool;
  1219. break;
  1220. case LLDrawPool::POOL_ALPHA:
  1221. poolp = mAlphaPool;
  1222. break;
  1223. case LLDrawPool::POOL_AVATAR:
  1224. break; // Do nothing
  1225. case LLDrawPool::POOL_SKY:
  1226. poolp = mSkyPool;
  1227. break;
  1228. case LLDrawPool::POOL_WATER:
  1229. poolp = mWaterPool;
  1230. break;
  1231. case LLDrawPool::POOL_GROUND:
  1232. poolp = mGroundPool;
  1233. break;
  1234. case LLDrawPool::POOL_WL_SKY:
  1235. poolp = mWLSkyPool;
  1236. break;
  1237. default:
  1238. llassert(0);
  1239. llerrs << "Invalid Pool Type in LLPipeline::findPool() type=" << type << llendl;
  1240. break;
  1241. }
  1242. return poolp;
  1243. }
  1244. LLDrawPool *LLPipeline::getPool(const U32 type, LLViewerTexture *tex0)
  1245. {
  1246. LLMemType mt(LLMemType::MTYPE_PIPELINE);
  1247. LLDrawPool *poolp = findPool(type, tex0);
  1248. if (poolp)
  1249. {
  1250. return poolp;
  1251. }
  1252. LLDrawPool *new_poolp = LLDrawPool::createPool(type, tex0);
  1253. addPool( new_poolp );
  1254. return new_poolp;
  1255. }
  1256. // static
  1257. LLDrawPool* LLPipeline::getPoolFromTE(const LLTextureEntry* te, LLViewerTexture* imagep)
  1258. {
  1259. LLMemType mt(LLMemType::MTYPE_PIPELINE);
  1260. U32 type = getPoolTypeFromTE(te, imagep);
  1261. return gPipeline.getPool(type, imagep);
  1262. }
  1263. //static
  1264. U32 LLPipeline::getPoolTypeFromTE(const LLTextureEntry* te, LLViewerTexture* imagep)
  1265. {
  1266. LLMemType mt_gpt(LLMemType::MTYPE_PIPELINE_GET_POOL_TYPE);
  1267. if (!te || !imagep)
  1268. {
  1269. return 0;
  1270. }
  1271. bool alpha = te->getColor().mV[3] < 0.999f;
  1272. if (imagep)
  1273. {
  1274. alpha = alpha || (imagep->getComponents() == 4 && imagep->getType() != LLViewerTexture::MEDIA_TEXTURE) || (imagep->getComponents() == 2);
  1275. }
  1276. if (alpha)
  1277. {
  1278. return LLDrawPool::POOL_ALPHA;
  1279. }
  1280. else if ((te->getBumpmap() || te->getShiny()))
  1281. {
  1282. return LLDrawPool::POOL_BUMP;
  1283. }
  1284. else
  1285. {
  1286. return LLDrawPool::POOL_SIMPLE;
  1287. }
  1288. }
  1289. void LLPipeline::ad

Large files files are truncated, but you can click here to view the full file