llprefsgraphics.cpp 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428
  1. /**
  2. * @file llprefsgraphics.cpp
  3. * @brief Graphics preferences for the preferences floater
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-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 <regex>
  34. #include "llprefsgraphics.h"
  35. #include "llcheckboxctrl.h"
  36. #include "llcombobox.h"
  37. #include "lllineeditor.h"
  38. #include "lllocale.h"
  39. #include "llnotifications.h"
  40. #include "llpanel.h"
  41. #include "llradiogroup.h"
  42. #include "llsliderctrl.h"
  43. #include "llspinctrl.h"
  44. #include "llstartup.h"
  45. #include "lltabcontainer.h"
  46. #include "lltextbox.h"
  47. #include "lluictrlfactory.h"
  48. #include "llwindow.h"
  49. #include "llfeaturemanager.h"
  50. #include "llfloaterpreference.h"
  51. #include "llpipeline.h"
  52. #include "llsky.h"
  53. #include "llstartup.h"
  54. #include "llviewercamera.h"
  55. #include "llviewercontrol.h"
  56. #include "llviewermessage.h" // For send_agent_update()
  57. #include "llviewerobjectlist.h"
  58. #include "llviewershadermgr.h"
  59. #include "llviewertexturelist.h"
  60. #include "llviewerwindow.h"
  61. #include "llvoavatar.h"
  62. #include "llvosky.h"
  63. #include "llvotree.h"
  64. #include "llvovolume.h"
  65. #include "llworld.h"
  66. static bool sNeedsRefresh = false;
  67. class LLPrefsGraphicsImpl final : public LLPanel
  68. {
  69. friend class LLPreferenceCore;
  70. public:
  71. LLPrefsGraphicsImpl();
  72. ~LLPrefsGraphicsImpl() override;
  73. bool postBuild() override;
  74. void draw() override;
  75. void refresh() override; // Refresh enable/disable
  76. void apply(); // Apply the changed values.
  77. void applyResolution();
  78. void applyWindowSize();
  79. void cancel();
  80. private:
  81. void setCloudsMaxAlt();
  82. void initWindowSizeControls();
  83. bool extractSizeFromString(const std::string& instr, U32& width,
  84. U32& height);
  85. void refreshEnabledState();
  86. static void onTabChanged(void* data, bool);
  87. // When the quality radio buttons are changed
  88. static void onChangeQuality(LLUICtrl* ctrl, void* data);
  89. // When the custom settings box is clicked
  90. static void onChangeCustom(LLUICtrl* ctrl, void* data);
  91. static void onOpenHelp(void* data);
  92. static void onCommitAutoDetectAspect(LLUICtrl* ctrl, void* data);
  93. static void onKeystrokeAspectRatio(LLLineEditor* caller, void* data);
  94. static void onSelectAspectRatio(LLUICtrl*, void*);
  95. static void onCommitWindowedMode(LLUICtrl* ctrl, void* data);
  96. static void updateSliderText(LLUICtrl* ctrl, void* data);
  97. static void updateMeterText(LLUICtrl* ctrl, void* data);
  98. static void onClassicClouds(LLUICtrl* ctrl, void* data);
  99. static void onCommitNeedsRefresh(LLUICtrl*, void* data);
  100. static void onCommitAvatarPhysics(LLUICtrl* ctrl, void* data);
  101. static void onCommitMaxNonImpostors(LLUICtrl* ctrl, void* data);
  102. // Callback for defaults
  103. static void setHardwareDefaults(void* data);
  104. // Helper method
  105. static void fractionFromDecimal(F32 decimal_val, S32& numerator,
  106. S32& denominator);
  107. private:
  108. typedef boost::signals2::connection connection_t;
  109. connection_t mCommitSignal;
  110. LLTabContainer* mTabContainer;
  111. // Aspect ratio sliders and boxes
  112. LLComboBox* mCtrlFullScreen; // Fullscreen resolution
  113. LLCheckBoxCtrl* mCtrlAutoDetectAspect; // Auto-detect aspect ratio
  114. LLComboBox* mCtrlAspectRatio; // User provided aspect ratio
  115. LLCheckBoxCtrl* mCtrlWindowed; // Windowed mode
  116. LLComboBox* mCtrlWindowSize; // Window size for windowed mode
  117. LLCheckBoxCtrl* mCtrlBenchmark; // Benchmark GPU
  118. /// Performance radio group
  119. LLSliderCtrl* mCtrlSliderQuality;
  120. // Performance sliders and boxes
  121. LLSliderCtrl* mCtrlDrawDistance; // Draw distance slider
  122. LLSliderCtrl* mCtrlLocalLightCount; // Mas local lights count
  123. LLSliderCtrl* mCtrlGlowResolution; // Glow map resolution
  124. LLSliderCtrl* mCtrlLODFactor; // LOD for volume objects
  125. LLSliderCtrl* mCtrlFlexFactor; // Timeslice for flexible objects
  126. LLSliderCtrl* mCtrlTreeFactor; // Control tree cutoff distance
  127. LLSliderCtrl* mCtrlAvatarFactor; // LOD for avatars
  128. LLSliderCtrl* mCtrlTerrainFactor; // LOD for terrain
  129. LLSliderCtrl* mCtrlTerrainMaterials; // Details for terrain materials
  130. LLSliderCtrl* mCtrlSkyFactor; // LOD for terrain
  131. LLSliderCtrl* mCtrlMaxParticle; // Max Particle
  132. LLCheckBoxCtrl* mCtrlGlow;
  133. LLCheckBoxCtrl* mCtrlDeferredEnable;
  134. LLCheckBoxCtrl* mCtrlAvatarCloth;
  135. LLCheckBoxCtrl* mCtrlClassicClouds;
  136. LLCheckBoxCtrl* mCtrlPBREnable;
  137. LLSliderCtrl* mCtrlExposure;
  138. LLCheckBoxCtrl* mCtrlTransparentWater;
  139. LLCheckBoxCtrl* mCtrlTerrainPBRTriplanar;
  140. LLSpinCtrl* mRenderGlowStrength;
  141. LLSpinCtrl* mSpinCloudsAltitude;
  142. LLComboBox* mComboRenderShadowDetail;
  143. LLComboBox* mComboWaterReflectionType;
  144. LLComboBox* mComboReflections;
  145. LLComboBox* mComboReflectionLevel;
  146. LLComboBox* mComboMirrors;
  147. LLCheckBoxCtrl* mCtrlSMAA;
  148. LLCheckBoxCtrl* mCtrlSharpen;
  149. LLTextBox* mAspectRatioLabel1;
  150. LLTextBox* mDisplayResLabel;
  151. LLTextBox* mFullScreenInfo;
  152. LLTextBox* mWindowSizeLabel;
  153. LLTextBox* mDrawDistanceMeterText1;
  154. LLTextBox* mDrawDistanceMeterText2;
  155. LLTextBox* mLODFactorText;
  156. LLTextBox* mFlexFactorText;
  157. LLTextBox* mTreeFactorText;
  158. LLTextBox* mAvatarFactorText;
  159. LLTextBox* mTerrainFactorText;
  160. LLTextBox* mTerrainMaterialsText;
  161. LLTextBox* mSkyFactorText;
  162. LLTextBox* mGlowResolutionText;
  163. LLTextBox* mClassicCloudsText;
  164. // GPU/GL features sub-tab
  165. LLCheckBoxCtrl* mCtrlOcclusion;
  166. // Avatar rendering sub-tab
  167. LLSliderCtrl* mCtrlMaxNonImpostors;
  168. LLSliderCtrl* mCtrlMaximumComplexity;
  169. LLSliderCtrl* mCtrlSurfaceAreaLimit;
  170. LLSliderCtrl* mCtrlGeometryBytesLimit;
  171. F32 mAspectRatio;
  172. // Performance value holders for cancel
  173. S32 mQualityPerformance;
  174. // Renderer settings sub-tab
  175. U32 mWaterReflectionType;
  176. U32 mWaterMaxAltitude;
  177. S32 mAvatarMode;
  178. S32 mClassicCloudsAvgAlt;
  179. U32 mLocalLightCount;
  180. U32 mRenderShadowDetail;
  181. U32 mReflectionProbes;
  182. U32 mReflectionProbeLevel;
  183. U32 mRenderTerrainPBRDetail;
  184. F32 mRenderFarClip;
  185. F32 mPrimLOD;
  186. F32 mMeshLODBoost;
  187. F32 mFlexLOD;
  188. F32 mTreeLOD;
  189. F32 mAvatarLOD;
  190. F32 mTerrainLOD;
  191. S32 mSkyLOD;
  192. S32 mParticleCount;
  193. S32 mPostProcess;
  194. F32 mGlowStrength;
  195. F32 mExposure;
  196. U32 mMirrors;
  197. U32 mFSAASamples;
  198. bool mFullScreen;
  199. bool mGlow;
  200. bool mRenderTransparentWater;
  201. bool mScreenSpaceReflections;
  202. bool mUseSMAAShader;
  203. bool mUseSharpenShader;
  204. bool mTerrainPBRTriplanar;
  205. bool mFSAutoDetectAspect;
  206. #if !LL_LINUX // Irrelevant setting for Linux
  207. bool mRenderHiDPI;
  208. #endif
  209. bool mRenderPBR;
  210. bool mRenderDeferred;
  211. bool mAvatarCloth;
  212. bool mUseClassicClouds;
  213. bool mCanDoCloth;
  214. bool mCanDoDeferred;
  215. // GPU/GL features sub-tab
  216. bool mRenderGLCoreProfile;
  217. bool mUseAniso;
  218. bool mDisableVRAMCheck;
  219. bool mCompressTextures;
  220. bool mRenderUseRGBA16ATI;
  221. S32 mGLWorkerThreads;
  222. F32 mGamma;
  223. U32 mVRAMOverride;
  224. S32 mTextureMem;
  225. U32 mMaxBoundTexMem;
  226. U32 mRenderCompressThreshold;
  227. // Avatars rendering sub-tab
  228. U32 mNonImpostors;
  229. U32 mNonImpostorsPuppets;
  230. U32 mRenderAvatarMaxComplexity;
  231. F32 mRenderAutoMuteSurfaceAreaLimit;
  232. U32 mRenderAutoMuteMemoryLimit;
  233. F32 mRenderAvatarPhysicsLODFactor;
  234. bool mAvatarPhysics;
  235. bool mAlwaysRenderFriends;
  236. bool mColoredJellyDolls;
  237. bool mFirstRun;
  238. };
  239. constexpr S32 ASPECT_RATIO_STR_LEN = 100;
  240. LLPrefsGraphicsImpl::LLPrefsGraphicsImpl()
  241. : mFirstRun(true)
  242. {
  243. LLUICtrlFactory::getInstance()->buildPanel(this,
  244. "panel_preferences_graphics.xml");
  245. }
  246. bool LLPrefsGraphicsImpl::postBuild()
  247. {
  248. mTabContainer = getChild<LLTabContainer>("graphics_tabs");
  249. LLPanel* tab = mTabContainer->getChild<LLPanel>("Renderer settings");
  250. mTabContainer->setTabChangeCallback(tab, onTabChanged);
  251. mTabContainer->setTabUserData(tab, this);
  252. tab = mTabContainer->getChild<LLPanel>("GPU/GL features");
  253. mTabContainer->setTabChangeCallback(tab, onTabChanged);
  254. mTabContainer->setTabUserData(tab, this);
  255. tab = mTabContainer->getChild<LLPanel>("Avatars rendering");
  256. mTabContainer->setTabChangeCallback(tab, onTabChanged);
  257. mTabContainer->setTabUserData(tab, this);
  258. // Setup graphic card driver capabilities
  259. mCanDoCloth = gFeatureManager.isFeatureAvailable("RenderAvatarCloth");
  260. mCanDoDeferred = gFeatureManager.isFeatureAvailable("RenderDeferred");
  261. // Return to default values
  262. childSetAction("Defaults", setHardwareDefaults, this);
  263. // Help button
  264. childSetAction("GraphicsPreferencesHelpButton", onOpenHelp, this);
  265. // Resolution
  266. // Radio set for fullscreen size
  267. mCtrlWindowed = getChild<LLCheckBoxCtrl>("windowed mode");
  268. mCtrlWindowed->setCommitCallback(onCommitWindowedMode);
  269. mCtrlWindowed->setCallbackUserData(this);
  270. mAspectRatioLabel1 = getChild<LLTextBox>("AspectRatioLabel1");
  271. mFullScreenInfo = getChild<LLTextBox>("FullScreenInfo");
  272. mDisplayResLabel = getChild<LLTextBox>("DisplayResLabel");
  273. S32 num_resolutions = 0;
  274. LLWindow::LLWindowResolution* resolutions =
  275. gWindowp->getSupportedResolutions(num_resolutions);
  276. S32 fullscreen_mode = num_resolutions - 1;
  277. mCtrlFullScreen = getChild<LLComboBox>("fullscreen combo");
  278. LLUIString resolution_label = getString("resolution_format");
  279. for (S32 i = 0; i < num_resolutions; ++i)
  280. {
  281. resolution_label.setArg("[RES_X]",
  282. llformat("%d", resolutions[i].mWidth));
  283. resolution_label.setArg("[RES_Y]",
  284. llformat("%d", resolutions[i].mHeight));
  285. mCtrlFullScreen->add(resolution_label, ADD_BOTTOM);
  286. }
  287. bool want_full_screen = gSavedSettings.getBool("FullScreen");
  288. U32 width, height;
  289. gViewerWindowp->getTargetWindow(want_full_screen, width, height);
  290. if (want_full_screen)
  291. {
  292. fullscreen_mode = 0;
  293. for (S32 i = 0; i < num_resolutions; ++i)
  294. {
  295. if (width == (U32)resolutions[i].mWidth &&
  296. height == (U32)resolutions[i].mHeight)
  297. {
  298. fullscreen_mode = i;
  299. }
  300. }
  301. mCtrlFullScreen->setCurrentByIndex(fullscreen_mode);
  302. mCtrlWindowed->set(false);
  303. mCtrlFullScreen->setVisible(true);
  304. }
  305. else
  306. {
  307. // Set to windowed mode
  308. mCtrlWindowed->set(true);
  309. mCtrlFullScreen->setCurrentByIndex(0);
  310. mCtrlFullScreen->setVisible(false);
  311. }
  312. initWindowSizeControls();
  313. if (gSavedSettings.getBool("FullScreenAutoDetectAspectRatio"))
  314. {
  315. mAspectRatio = gViewerWindowp->getDisplayAspectRatio();
  316. }
  317. else
  318. {
  319. mAspectRatio = gSavedSettings.getF32("FullScreenAspectRatio");
  320. }
  321. S32 numerator = 0;
  322. S32 denominator = 0;
  323. fractionFromDecimal(mAspectRatio, numerator, denominator);
  324. LLUIString aspect_ratio_text = getString("aspect_ratio_text");
  325. if (numerator != 0)
  326. {
  327. aspect_ratio_text.setArg("[NUM]", llformat("%d", numerator));
  328. aspect_ratio_text.setArg("[DEN]", llformat("%d", denominator));
  329. }
  330. else
  331. {
  332. aspect_ratio_text = llformat("%.3f", mAspectRatio);
  333. }
  334. mCtrlAspectRatio = getChild<LLComboBox>("aspect_ratio");
  335. mCtrlAspectRatio->setTextEntryCallback(onKeystrokeAspectRatio);
  336. mCtrlAspectRatio->setCommitCallback(onSelectAspectRatio);
  337. mCtrlAspectRatio->setCallbackUserData(this);
  338. // Add default aspect ratios
  339. mCtrlAspectRatio->add(aspect_ratio_text, &mAspectRatio, ADD_TOP);
  340. mCtrlAspectRatio->setCurrentByIndex(0);
  341. mCtrlAutoDetectAspect = getChild<LLCheckBoxCtrl>("aspect_auto_detect");
  342. mCtrlAutoDetectAspect->setCommitCallback(onCommitAutoDetectAspect);
  343. mCtrlAutoDetectAspect->setCallbackUserData(this);
  344. #if LL_LINUX
  345. // HiDPI (Retina) mode for macOS or UI scaling under Windows 10. Irrelevant
  346. // to Linux.
  347. childHide("hi_dpi_check");
  348. #endif
  349. // Radio performance box
  350. mCtrlSliderQuality = getChild<LLSliderCtrl>("QualityPerformanceSelection");
  351. mCtrlSliderQuality->setSliderMouseUpCallback(onChangeQuality);
  352. mCtrlSliderQuality->setCallbackUserData(this);
  353. mCtrlBenchmark = getChild<LLCheckBoxCtrl>("benchmark_gpu_check");
  354. // Glow
  355. mCtrlGlow = getChild<LLCheckBoxCtrl>("RenderGlowCheck");
  356. mCtrlGlow->setCommitCallback(onCommitNeedsRefresh);
  357. mCtrlGlow->setCallbackUserData(this);
  358. mRenderGlowStrength = getChild<LLSpinCtrl>("glow_strength");
  359. mCtrlGlowResolution = getChild<LLSliderCtrl>("GlowResolutionPow");
  360. mGlowResolutionText = getChild<LLTextBox>("GlowResolutionText");
  361. mCtrlGlowResolution->setCommitCallback(updateSliderText);
  362. mCtrlGlowResolution->setCallbackUserData(mGlowResolutionText);
  363. // Water opacity or reflections
  364. mComboWaterReflectionType = getChild<LLComboBox>("WaterReflectionTypeCombo");
  365. mComboWaterReflectionType->setCurrentByIndex(gSavedSettings.getU32("RenderWaterReflectionType"));
  366. mCtrlTransparentWater = getChild<LLCheckBoxCtrl>("TransparentWaterCheck");
  367. // PBR reflections
  368. mComboReflections = getChild<LLComboBox>("ReflectionsCombo");
  369. mComboReflections->setCurrentByIndex(gSavedSettings.getU32("RenderReflectionProbes"));
  370. mComboReflectionLevel = getChild<LLComboBox>("ReflectionLevelCombo");
  371. mComboReflectionLevel->setCurrentByIndex(gSavedSettings.getU32("RenderReflectionProbeLevel"));
  372. mComboMirrors = getChild<LLComboBox>("RenderHeroProbeResLevel");
  373. mComboMirrors->setCurrentByIndex(gSavedSettings.getU32("RenderHeroProbeResLevel"));
  374. // Avatar shader
  375. mCtrlAvatarCloth = getChild<LLCheckBoxCtrl>("AvatarCloth");
  376. // Deferred rendering
  377. mCtrlDeferredEnable = getChild<LLCheckBoxCtrl>("RenderDeferred");
  378. mCtrlDeferredEnable->setCommitCallback(onCommitNeedsRefresh);
  379. mCtrlDeferredEnable->setCallbackUserData(this);
  380. mComboRenderShadowDetail =
  381. getChild<LLComboBox>("RenderShadowDetailCombo");
  382. mComboRenderShadowDetail->setCurrentByIndex(gSavedSettings.getU32("RenderShadowDetail"));
  383. mCtrlSMAA = getChild<LLCheckBoxCtrl>("smaa");
  384. mCtrlSharpen = getChild<LLCheckBoxCtrl>("sharpen");
  385. mCtrlPBREnable = getChild<LLCheckBoxCtrl>("UsePBRCheck");
  386. mCtrlExposure = getChild<LLSliderCtrl>("RenderExposureCtrl");
  387. // Object detail slider
  388. mCtrlDrawDistance = getChild<LLSliderCtrl>("DrawDistance");
  389. mDrawDistanceMeterText1 = getChild<LLTextBox>("DrawDistanceMeterText1");
  390. mDrawDistanceMeterText2 = getChild<LLTextBox>("DrawDistanceMeterText2");
  391. mCtrlDrawDistance->setCommitCallback(updateMeterText);
  392. mCtrlDrawDistance->setCallbackUserData(this);
  393. updateMeterText(mCtrlDrawDistance, (void*)this);
  394. // Object detail slider
  395. mCtrlLODFactor = getChild<LLSliderCtrl>("ObjectMeshDetail");
  396. mLODFactorText = getChild<LLTextBox>("ObjectMeshDetailText");
  397. mCtrlLODFactor->setCommitCallback(updateSliderText);
  398. mCtrlLODFactor->setCallbackUserData(mLODFactorText);
  399. // Flex object detail slider
  400. mCtrlFlexFactor = getChild<LLSliderCtrl>("FlexibleMeshDetail");
  401. mFlexFactorText = getChild<LLTextBox>("FlexibleMeshDetailText");
  402. mCtrlFlexFactor->setCommitCallback(updateSliderText);
  403. mCtrlFlexFactor->setCallbackUserData(mFlexFactorText);
  404. // Tree detail slider
  405. mCtrlTreeFactor = getChild<LLSliderCtrl>("TreeMeshDetail");
  406. mTreeFactorText = getChild<LLTextBox>("TreeMeshDetailText");
  407. mCtrlTreeFactor->setCommitCallback(updateSliderText);
  408. mCtrlTreeFactor->setCallbackUserData(mTreeFactorText);
  409. // Avatar detail slider
  410. mCtrlAvatarFactor = getChild<LLSliderCtrl>("AvatarMeshDetail");
  411. mAvatarFactorText = getChild<LLTextBox>("AvatarMeshDetailText");
  412. mCtrlAvatarFactor->setCommitCallback(updateSliderText);
  413. mCtrlAvatarFactor->setCallbackUserData(mAvatarFactorText);
  414. // Terrain detail
  415. mCtrlTerrainFactor = getChild<LLSliderCtrl>("TerrainMeshDetail");
  416. mTerrainFactorText = getChild<LLTextBox>("TerrainMeshDetailText");
  417. mCtrlTerrainFactor->setCommitCallback(updateSliderText);
  418. mCtrlTerrainFactor->setCallbackUserData(mTerrainFactorText);
  419. mCtrlTerrainMaterials = getChild<LLSliderCtrl>("TerrainMaterials");
  420. mTerrainMaterialsText = getChild<LLTextBox>("TerrainMaterialsText");
  421. mCtrlTerrainMaterials->setCommitCallback(updateSliderText);
  422. mCtrlTerrainMaterials->setCallbackUserData(mTerrainMaterialsText);
  423. mCtrlTerrainPBRTriplanar = getChild<LLCheckBoxCtrl>("triplanar");
  424. // Sky detail slider
  425. mCtrlSkyFactor = getChild<LLSliderCtrl>("SkyMeshDetail");
  426. mSkyFactorText = getChild<LLTextBox>("SkyMeshDetailText");
  427. mCtrlSkyFactor->setCommitCallback(updateSliderText);
  428. mCtrlSkyFactor->setCallbackUserData(mSkyFactorText);
  429. // Classic clouds
  430. mCtrlClassicClouds = getChild<LLCheckBoxCtrl>("ClassicClouds");
  431. mCtrlClassicClouds->setCommitCallback(onClassicClouds);
  432. mCtrlClassicClouds->setCallbackUserData(this);
  433. mClassicCloudsText = getChild<LLTextBox>("ClassicCloudsText");
  434. mSpinCloudsAltitude = getChild<LLSpinCtrl>("CloudsAltitude");
  435. LLControlVariable* controlp =
  436. gSavedSettings.getControl("ClassicCloudsMaxAlt");
  437. if (!controlp)
  438. {
  439. llerrs << "ClassicCloudsMaxAlt debug setting is missing !" << llendl;
  440. }
  441. mCommitSignal =
  442. controlp->getSignal()->connect(boost::bind(&LLPrefsGraphicsImpl::setCloudsMaxAlt,
  443. this));
  444. setCloudsMaxAlt();
  445. // Particle detail slider
  446. mCtrlMaxParticle = getChild<LLSliderCtrl>("MaxParticleCount");
  447. // Local lights count slider
  448. mCtrlLocalLightCount = getChild<LLSliderCtrl>("LocalLightCount");
  449. // GPU/GL features sub-tab:
  450. mCtrlOcclusion = getChild<LLCheckBoxCtrl>("occlusion");
  451. childSetCommitCallback("texture_compression", onCommitNeedsRefresh, this);
  452. childSetVisible("after_restart", LLStartUp::isLoggedIn());
  453. #if LL_DARWIN
  454. // Under macOS, this setting allows to choose between the legacy GL v2.1
  455. // compatibility profile, and the GL v3.2 (or v4.1, depending on the macOS
  456. // version) core profile, so this control must always be available, even
  457. // when running under the v2.1 compatibility profile. HB
  458. childSetEnabled("core_gl", true);
  459. childSetToolTip("core_gl", getString("core_gl_macos_tip"));
  460. #else
  461. childSetEnabled("core_gl", gGLManager.mGLVersion >= 3.f);
  462. #endif
  463. // Intel iGPUs do not have the necessary GL call for VRAM checks, since
  464. // they do not have VRAM at all ! This might change with the future ARC
  465. // discrete GPUs... HB
  466. if (!gGLManager.mHasATIMemInfo && !gGLManager.mHasNVXMemInfo)
  467. {
  468. childSetVisible("no_vram_check", false);
  469. }
  470. // Avatars rendering sub-tab:
  471. std::string off_text = getString("off_text");
  472. mCtrlMaxNonImpostors = getChild<LLSliderCtrl>("MaxNonImpostors");
  473. mCtrlMaxNonImpostors->setOffLimit(off_text, 0.f);
  474. mCtrlMaxNonImpostors->setCommitCallback(onCommitMaxNonImpostors);
  475. mCtrlMaxNonImpostors->setCallbackUserData(this);
  476. mCtrlMaximumComplexity = getChild<LLSliderCtrl>("MaximumComplexity");
  477. mCtrlMaximumComplexity->setOffLimit(off_text, 0.f);
  478. mCtrlSurfaceAreaLimit = getChild<LLSliderCtrl>("SurfaceAreaLimit");
  479. mCtrlSurfaceAreaLimit->setOffLimit(off_text, 0.f);
  480. mCtrlGeometryBytesLimit = getChild<LLSliderCtrl>("GeometryBytesLimit");
  481. mCtrlGeometryBytesLimit->setOffLimit(off_text, 0.f);
  482. LLSliderCtrl* slider = getChild<LLSliderCtrl>("MaxPuppetAvatars");
  483. slider->setOffLimit(off_text, 0.f);
  484. childSetCommitCallback("AvatarPhysics", onCommitAvatarPhysics, this);
  485. bool show_rgba16 = gGLManager.mIsAMD && gGLManager.mGLVersion >= 4.f;
  486. childSetVisible("rgba16_text", show_rgba16);
  487. childSetVisible("rgba16_check", show_rgba16);
  488. refresh();
  489. return true;
  490. }
  491. void LLPrefsGraphicsImpl::initWindowSizeControls()
  492. {
  493. // Window size
  494. mWindowSizeLabel = getChild<LLTextBox>("WindowSizeLabel");
  495. mCtrlWindowSize = getChild<LLComboBox>("windowsize combo");
  496. // Look to see if current window size matches existing window sizes, if so
  497. // then just set the selection value...
  498. const U32 height = gViewerWindowp->getWindowDisplayHeight();
  499. const U32 width = gViewerWindowp->getWindowDisplayWidth();
  500. for (S32 i = 0; i < mCtrlWindowSize->getItemCount(); ++i)
  501. {
  502. U32 height_test = 0;
  503. U32 width_test = 0;
  504. mCtrlWindowSize->setCurrentByIndex(i);
  505. if (extractSizeFromString(mCtrlWindowSize->getValue().asString(),
  506. width_test, height_test))
  507. {
  508. if (height_test == height && width_test == width)
  509. {
  510. return;
  511. }
  512. }
  513. }
  514. // ...otherwise, add a new entry with the current window height/width.
  515. LLUIString resolution_label = getString("resolution_format");
  516. resolution_label.setArg("[RES_X]", llformat("%d", width));
  517. resolution_label.setArg("[RES_Y]", llformat("%d", height));
  518. mCtrlWindowSize->add(resolution_label, ADD_TOP);
  519. mCtrlWindowSize->setCurrentByIndex(0);
  520. }
  521. LLPrefsGraphicsImpl::~LLPrefsGraphicsImpl()
  522. {
  523. mCommitSignal.disconnect();
  524. #if 0
  525. // Clean up user data
  526. for (S32 i = 0; i < mCtrlAspectRatio->getItemCount(); ++i)
  527. {
  528. mCtrlAspectRatio->setCurrentByIndex(i);
  529. }
  530. for (S32 i = 0; i < mCtrlWindowSize->getItemCount(); ++i)
  531. {
  532. mCtrlWindowSize->setCurrentByIndex(i);
  533. }
  534. #endif
  535. }
  536. void LLPrefsGraphicsImpl::setCloudsMaxAlt()
  537. {
  538. F32 max_alt = gSavedSettings.getU32("ClassicCloudsMaxAlt");
  539. mSpinCloudsAltitude->setMinValue(-max_alt);
  540. mSpinCloudsAltitude->setMaxValue(max_alt);
  541. }
  542. void LLPrefsGraphicsImpl::draw()
  543. {
  544. if (mFirstRun)
  545. {
  546. mFirstRun = false;
  547. mTabContainer->selectTab(gSavedSettings.getS32("LastGraphicsPrefTab"));
  548. }
  549. if (sNeedsRefresh)
  550. {
  551. sNeedsRefresh = false;
  552. refresh();
  553. }
  554. LLPanel::draw();
  555. }
  556. void LLPrefsGraphicsImpl::refresh()
  557. {
  558. mFullScreen = gSavedSettings.getBool("FullScreen");
  559. mFSAutoDetectAspect =
  560. gSavedSettings.getBool("FullScreenAutoDetectAspectRatio");
  561. #if !LL_LINUX // Irrelevant setting for Linux
  562. mRenderHiDPI = gSavedSettings.getBool("RenderHiDPI");
  563. #endif
  564. mQualityPerformance = gSavedSettings.getU32("RenderQualityPerformance");
  565. F32 bw = gFeatureManager.getGPUMemoryBandwidth();
  566. if (bw > 0.f)
  567. {
  568. mCtrlBenchmark->setToolTip(getString("tool_tip_bench"));
  569. mCtrlBenchmark->setToolTipArg("[BW]", llformat("%d", (S32)bw));
  570. }
  571. // Shaders settings
  572. mWaterReflectionType = gSavedSettings.getU32("RenderWaterReflectionType");
  573. mWaterMaxAltitude = gSavedSettings.getU32("RenderWaterMaxAltitude");
  574. mRenderTransparentWater = gSavedSettings.getBool("RenderTransparentWater");
  575. mScreenSpaceReflections =
  576. gSavedSettings.getBool("RenderScreenSpaceReflections");
  577. mAvatarCloth = mCanDoCloth && gSavedSettings.getBool("RenderAvatarCloth");
  578. mUseSMAAShader = gSavedSettings.getBool("RenderDeferredUseSMAA");
  579. mUseSharpenShader = gSavedSettings.getBool("RenderDeferredAASharpen");
  580. // Draw distance
  581. mRenderFarClip = gSavedSettings.getF32("RenderFarClip");
  582. // Sliders and their text boxes
  583. mPrimLOD = gSavedSettings.getF32("RenderVolumeLODFactor");
  584. mMeshLODBoost = gSavedSettings.getF32("MeshLODBoostFactor");
  585. mFlexLOD = gSavedSettings.getF32("RenderFlexTimeFactor");
  586. mTreeLOD = gSavedSettings.getF32("RenderTreeLODFactor");
  587. mAvatarLOD = gSavedSettings.getF32("RenderAvatarLODFactor");
  588. mTerrainLOD = gSavedSettings.getF32("RenderTerrainLODFactor");
  589. mSkyLOD = gSavedSettings.getU32("WLSkyDetail");
  590. mParticleCount = gSavedSettings.getS32("RenderMaxPartCount");
  591. mPostProcess = gSavedSettings.getU32("RenderGlowResolutionPow");
  592. // Classic clouds
  593. mUseClassicClouds = gSavedSettings.getBool("SkyUseClassicClouds");
  594. mClassicCloudsAvgAlt = gSavedSettings.getS32("ClassicCloudsAvgAlt");
  595. // Lighting and terrain radios
  596. mGlow = gSavedSettings.getBool("RenderGlow");
  597. mGlowStrength = gSavedSettings.getF32("RenderGlowStrength");
  598. mLocalLightCount = gSavedSettings.getU32("RenderLocalLightCount");
  599. mExposure = gSavedSettings.getF32("RenderExposure");
  600. mRenderPBR = gSavedSettings.getBool("RenderUsePBR");
  601. mRenderDeferred = gSavedSettings.getBool("RenderDeferred");
  602. mRenderShadowDetail = gSavedSettings.getU32("RenderShadowDetail");
  603. mReflectionProbes = gSavedSettings.getU32("RenderReflectionProbes");
  604. mReflectionProbeLevel =
  605. gSavedSettings.getU32("RenderReflectionProbeLevel");
  606. mMirrors = gSavedSettings.getU32("RenderHeroProbeResLevel");
  607. mRenderTerrainPBRDetail = gSavedSettings.getU32("RenderTerrainPBRDetail");
  608. mTerrainPBRTriplanar = gSavedSettings.getBool("RenderTerrainPBRTriplanar");
  609. // Slider text boxes
  610. updateSliderText(mCtrlLODFactor, mLODFactorText);
  611. updateSliderText(mCtrlFlexFactor, mFlexFactorText);
  612. updateSliderText(mCtrlTreeFactor, mTreeFactorText);
  613. updateSliderText(mCtrlAvatarFactor, mAvatarFactorText);
  614. updateSliderText(mCtrlTerrainFactor, mTerrainFactorText);
  615. updateSliderText(mCtrlTerrainMaterials, mTerrainMaterialsText);
  616. updateSliderText(mCtrlGlowResolution, mGlowResolutionText);
  617. updateSliderText(mCtrlSkyFactor, mSkyFactorText);
  618. // GPU/GL features sub-tab
  619. mRenderGLCoreProfile = gSavedSettings.getBool("RenderGLCoreProfile");
  620. mUseAniso = gSavedSettings.getBool("RenderAnisotropic");
  621. mFSAASamples = gSavedSettings.getU32("RenderFSAASamples");
  622. mGamma = gSavedSettings.getF32("DisplayGamma");
  623. mVRAMOverride = gSavedSettings.getU32("VRAMOverride");
  624. mTextureMem = gSavedSettings.getS32("TextureMemory");
  625. mMaxBoundTexMem = gSavedSettings.getU32("MaxBoundTexMem");
  626. mCompressTextures = gGLManager.mGLVersion >= 2.1f &&
  627. gSavedSettings.getBool("RenderCompressTextures");
  628. mRenderCompressThreshold =
  629. gSavedSettings.getU32("RenderCompressThreshold");
  630. mDisableVRAMCheck = gSavedSettings.getBool("DisableVRAMCheck");
  631. childSetValue("fsaa", (LLSD::Integer)mFSAASamples);
  632. mRenderUseRGBA16ATI = gSavedSettings.getBool("RenderUseRGBA16ATI");
  633. mGLWorkerThreads = gSavedSettings.getS32("GLWorkerThreads");
  634. // Avatars rendering sub-tab
  635. mNonImpostors = gSavedSettings.getU32("RenderAvatarMaxNonImpostors");
  636. mNonImpostorsPuppets = gSavedSettings.getU32("RenderAvatarMaxPuppets");
  637. mAvatarPhysics = gSavedSettings.getBool("AvatarPhysics");
  638. mAlwaysRenderFriends = gSavedSettings.getBool("AlwaysRenderFriends");
  639. mColoredJellyDolls = gSavedSettings.getBool("ColoredJellyDolls");
  640. mRenderAvatarPhysicsLODFactor =
  641. gSavedSettings.getF32("RenderAvatarPhysicsLODFactor");
  642. mRenderAvatarMaxComplexity =
  643. gSavedSettings.getU32("RenderAvatarMaxComplexity");
  644. mRenderAutoMuteSurfaceAreaLimit =
  645. gSavedSettings.getF32("RenderAutoMuteSurfaceAreaLimit");
  646. mRenderAutoMuteMemoryLimit =
  647. gSavedSettings.getU32("RenderAutoMuteMemoryLimit");
  648. refreshEnabledState();
  649. }
  650. void LLPrefsGraphicsImpl::refreshEnabledState()
  651. {
  652. // Windowed/full-screen modes UI elements visibility
  653. mDisplayResLabel->setVisible(mFullScreen);
  654. mCtrlFullScreen->setVisible(mFullScreen);
  655. mCtrlAspectRatio->setVisible(mFullScreen);
  656. mAspectRatioLabel1->setVisible(mFullScreen);
  657. mCtrlAutoDetectAspect->setVisible(mFullScreen);
  658. mCtrlWindowSize->setVisible(!mFullScreen);
  659. mFullScreenInfo->setVisible(!mFullScreen);
  660. mWindowSizeLabel->setVisible(!mFullScreen);
  661. // Glow
  662. if (LLPipeline::sCanRenderGlow)
  663. {
  664. mCtrlGlow->setEnabled(true);
  665. bool glow_enabled = mCtrlGlow->get();
  666. mRenderGlowStrength->setEnabled(glow_enabled);
  667. mCtrlGlowResolution->setEnabled(glow_enabled);
  668. mGlowResolutionText->setEnabled(glow_enabled);
  669. }
  670. else
  671. {
  672. mCtrlGlow->setEnabled(false);
  673. mRenderGlowStrength->setEnabled(false);
  674. mCtrlGlowResolution->setEnabled(false);
  675. mGlowResolutionText->setEnabled(false);
  676. }
  677. // Classic clouds
  678. bool clouds = mCtrlClassicClouds->get();
  679. mSpinCloudsAltitude->setEnabled(clouds);
  680. // Avatar Mode
  681. bool skinning = !LLStartUp::isLoggedIn() ||
  682. gViewerShaderMgrp->mMaxAvatarShaderLevel > 0;
  683. bool cloth = mCanDoCloth && skinning;
  684. // Avatar cloth
  685. mCtrlAvatarCloth->setEnabled(cloth);
  686. if (!cloth)
  687. {
  688. mCtrlAvatarCloth->setValue(false);
  689. }
  690. // Deferred rendering
  691. bool deferred = mCanDoDeferred && skinning;
  692. mCtrlPBREnable->setVisible(deferred);
  693. if (gUsePBRShaders)
  694. {
  695. mCtrlDeferredEnable->setVisible(false);
  696. childSetVisible("water_text", false);
  697. mComboWaterReflectionType->setVisible(false);
  698. mCtrlAvatarCloth->setVisible(false);
  699. mCtrlExposure->setVisible(true);
  700. mCtrlTransparentWater->setVisible(true);
  701. childSetVisible("reflections_text", true);
  702. childSetVisible("no_reflections_text", !LLViewerShaderMgr::sCanDoRP);
  703. mComboReflections->setVisible(LLViewerShaderMgr::sCanDoRP);
  704. childSetVisible("coverage_text", LLViewerShaderMgr::sHasRP);
  705. mComboReflectionLevel->setVisible(LLViewerShaderMgr::sHasRP);
  706. childSetVisible("mirrors_text", LLViewerShaderMgr::sHasRP);
  707. mComboMirrors->setVisible(LLViewerShaderMgr::sHasRP);
  708. static LLCachedControl<bool> pbr_terrain(gSavedSettings,
  709. "RenderTerrainPBREnabled");
  710. bool has_pbr_terrain = pbr_terrain &&
  711. gGLManager.mNumTextureImageUnits >= 16;
  712. mCtrlTerrainMaterials->setVisible(has_pbr_terrain);
  713. mTerrainMaterialsText->setVisible(has_pbr_terrain);
  714. mCtrlTerrainPBRTriplanar->setVisible(has_pbr_terrain);
  715. }
  716. else
  717. {
  718. mCtrlDeferredEnable->setVisible(true);
  719. mCtrlPBREnable->setEnabled(gGLManager.mGLVersion >= 3.1f);
  720. mCtrlDeferredEnable->setEnabled(deferred);
  721. if (!deferred)
  722. {
  723. mCtrlDeferredEnable->setValue(false);
  724. }
  725. mCtrlExposure->setVisible(false);
  726. mCtrlTransparentWater->setVisible(false);
  727. childSetVisible("water_text", true);
  728. mComboWaterReflectionType->setVisible(true);
  729. childSetVisible("reflections_text", false);
  730. childSetVisible("no_reflections_text", false);
  731. mComboReflections->setVisible(false);
  732. childSetVisible("coverage_text", false);
  733. mComboReflectionLevel->setVisible(false);
  734. childSetVisible("mirrors_text", false);
  735. mComboMirrors->setVisible(false);
  736. mCtrlTerrainMaterials->setVisible(false);
  737. mTerrainMaterialsText->setVisible(false);
  738. mCtrlTerrainPBRTriplanar->setVisible(false);
  739. mCtrlAvatarCloth->setVisible(true);
  740. }
  741. bool alm_on = gUsePBRShaders || mCtrlDeferredEnable->get();
  742. mComboRenderShadowDetail->setEnabled(alm_on);
  743. // Visibility of settings depending on ALM shaders
  744. mCtrlSMAA->setVisible(alm_on && LLViewerShaderMgr::sHasSMAA);
  745. mCtrlSharpen->setVisible(alm_on && LLViewerShaderMgr::sHasCAS);
  746. deferred &= gUsePBRShaders || mCtrlDeferredEnable->get();
  747. mComboRenderShadowDetail->setVisible(deferred);
  748. childSetVisible("no_alm_text", !deferred);
  749. childSetToolTip("no_alm_text", getString("tool_tip_no_deferred"));
  750. // GPU/GL features sub-tab
  751. S32 min_tex_mem = LLViewerTextureList::getMinVideoRamSetting();
  752. S32 max_tex_mem = LLViewerTextureList::getMaxVideoRamSetting(true);
  753. childSetMinValue("GrapicsCardTextureMemory", min_tex_mem);
  754. childSetMaxValue("GrapicsCardTextureMemory", max_tex_mem);
  755. if (!gFeatureManager.isFeatureAvailable("RenderCompressTextures") ||
  756. gGLManager.mGLVersion < 2.1f)
  757. {
  758. childSetEnabled("texture_compression", false);
  759. }
  760. if (!gFeatureManager.isFeatureAvailable("UseOcclusion"))
  761. {
  762. mCtrlOcclusion->setEnabled(false);
  763. }
  764. // Texture compression settings.
  765. bool compress = gSavedSettings.getBool("RenderCompressTextures");
  766. childSetEnabled("compress_throttle", compress);
  767. childSetEnabled("pixels_text", compress);
  768. // Avatars rendering sub-tab
  769. bool impostors = mCtrlMaxNonImpostors->getValue().asInteger() > 0;
  770. mCtrlMaximumComplexity->setEnabled(impostors);
  771. mCtrlSurfaceAreaLimit->setEnabled(impostors);
  772. mCtrlGeometryBytesLimit->setEnabled(impostors);
  773. childSetEnabled("AvatarPhysicsLOD",
  774. gSavedSettings.getBool("AvatarPhysics"));
  775. }
  776. void LLPrefsGraphicsImpl::cancel()
  777. {
  778. gSavedSettings.setBool("FullScreen", mFullScreen);
  779. gSavedSettings.setBool("FullScreenAutoDetectAspectRatio",
  780. mFSAutoDetectAspect);
  781. #if !LL_LINUX // Irrelevant setting for Linux
  782. gSavedSettings.setBool("RenderHiDPI", mRenderHiDPI);
  783. #endif
  784. gSavedSettings.setF32("FullScreenAspectRatio", mAspectRatio);
  785. gSavedSettings.setU32("RenderQualityPerformance", mQualityPerformance);
  786. gSavedSettings.setU32("RenderWaterReflectionType", mWaterReflectionType);
  787. gSavedSettings.setU32("RenderWaterMaxAltitude", mWaterMaxAltitude);
  788. gSavedSettings.setBool("RenderTransparentWater", mRenderTransparentWater);
  789. gSavedSettings.setBool("RenderScreenSpaceReflections",
  790. mScreenSpaceReflections);
  791. gSavedSettings.setBool("RenderAvatarCloth", mAvatarCloth);
  792. gSavedSettings.setBool("SkyUseClassicClouds", mUseClassicClouds);
  793. gSavedSettings.setS32("ClassicCloudsAvgAlt", mClassicCloudsAvgAlt);
  794. gSavedSettings.setBool("RenderUsePBR", mRenderPBR);
  795. gSavedSettings.setBool("RenderDeferred", mRenderDeferred);
  796. gSavedSettings.setU32("RenderShadowDetail", mRenderShadowDetail);
  797. gSavedSettings.setBool("RenderGlow", mGlow);
  798. gSavedSettings.setF32("RenderGlowStrength", mGlowStrength);
  799. gSavedSettings.setU32("RenderLocalLightCount", mLocalLightCount);
  800. gSavedSettings.setF32("RenderExposure", mExposure);
  801. gSavedSettings.setU32("RenderReflectionProbes", mReflectionProbes);
  802. gSavedSettings.setU32("RenderReflectionProbeLevel", mReflectionProbeLevel);
  803. gSavedSettings.setU32("RenderHeroProbeResLevel", mMirrors);
  804. gSavedSettings.setBool("RenderDeferredUseSMAA", mUseSMAAShader);
  805. gSavedSettings.setBool("RenderDeferredAASharpen", mUseSharpenShader);
  806. gSavedSettings.setU32("RenderTerrainPBRDetail", mRenderTerrainPBRDetail);
  807. gSavedSettings.setBool("RenderTerrainPBRTriplanar", mTerrainPBRTriplanar);
  808. gSavedSettings.setF32("RenderFarClip", mRenderFarClip);
  809. gSavedSettings.setF32("RenderVolumeLODFactor", mPrimLOD);
  810. gSavedSettings.setF32("MeshLODBoostFactor", mMeshLODBoost);
  811. gSavedSettings.setF32("RenderFlexTimeFactor", mFlexLOD);
  812. gSavedSettings.setF32("RenderTreeLODFactor", mTreeLOD);
  813. gSavedSettings.setF32("RenderAvatarLODFactor", mAvatarLOD);
  814. gSavedSettings.setF32("RenderTerrainLODFactor", mTerrainLOD);
  815. gSavedSettings.setU32("WLSkyDetail", mSkyLOD);
  816. gSavedSettings.setS32("RenderMaxPartCount", mParticleCount);
  817. gSavedSettings.setU32("RenderGlowResolutionPow", mPostProcess);
  818. // GPU/GL features sub-tab
  819. gSavedSettings.setBool("RenderGLCoreProfile", mRenderGLCoreProfile);
  820. gSavedSettings.setBool("RenderAnisotropic", mUseAniso);
  821. gSavedSettings.setU32("RenderFSAASamples", mFSAASamples);
  822. gSavedSettings.setF32("DisplayGamma", mGamma);
  823. gSavedSettings.setU32("VRAMOverride", mVRAMOverride);
  824. gSavedSettings.setS32("TextureMemory", mTextureMem);
  825. gSavedSettings.setU32("MaxBoundTexMem", mMaxBoundTexMem);
  826. gSavedSettings.setBool("RenderCompressTextures", mCompressTextures);
  827. gSavedSettings.setU32("RenderCompressThreshold", mRenderCompressThreshold);
  828. gSavedSettings.setBool("DisableVRAMCheck", mDisableVRAMCheck);
  829. gSavedSettings.setBool("RenderUseRGBA16ATI", mRenderUseRGBA16ATI);
  830. gSavedSettings.setS32("GLWorkerThreads", mGLWorkerThreads);
  831. // Avatars rendering sub-tab
  832. gSavedSettings.setU32("RenderAvatarMaxNonImpostors", mNonImpostors);
  833. gSavedSettings.setU32("RenderAvatarMaxPuppets", mNonImpostorsPuppets);
  834. gSavedSettings.setBool("AvatarPhysics", mAvatarPhysics);
  835. gSavedSettings.setBool("AlwaysRenderFriends", mAlwaysRenderFriends);
  836. gSavedSettings.setBool("ColoredJellyDolls", mColoredJellyDolls);
  837. gSavedSettings.setF32("RenderAvatarPhysicsLODFactor",
  838. mRenderAvatarPhysicsLODFactor);
  839. gSavedSettings.setU32("RenderAvatarMaxComplexity",
  840. mRenderAvatarMaxComplexity);
  841. gSavedSettings.setF32("RenderAutoMuteSurfaceAreaLimit",
  842. mRenderAutoMuteSurfaceAreaLimit);
  843. gSavedSettings.setU32("RenderAutoMuteMemoryLimit",
  844. mRenderAutoMuteMemoryLimit);
  845. }
  846. void LLPrefsGraphicsImpl::apply()
  847. {
  848. applyResolution();
  849. applyWindowSize();
  850. }
  851. void LLPrefsGraphicsImpl::applyResolution()
  852. {
  853. gGL.flush();
  854. glFinish();
  855. bool restart_display = false;
  856. bool after_restart = false;
  857. bool full_screen = gWindowp->getFullscreen();
  858. bool want_full_screen = !mCtrlWindowed->get();
  859. char aspect_ratio_text[ASPECT_RATIO_STR_LEN];
  860. if (mCtrlAspectRatio->getCurrentIndex() == -1)
  861. {
  862. // Cannot pass const char* from c_str() into strtok
  863. strncpy(aspect_ratio_text, mCtrlAspectRatio->getSimple().c_str(),
  864. sizeof(aspect_ratio_text) -1);
  865. aspect_ratio_text[sizeof(aspect_ratio_text) -1] = '\0';
  866. char* element = strtok(aspect_ratio_text, ":/\\");
  867. if (!element)
  868. {
  869. mAspectRatio = 0.f; // Will be clamped later
  870. }
  871. else
  872. {
  873. LLLocale locale(LLLocale::USER_LOCALE);
  874. mAspectRatio = (F32)atof(element);
  875. }
  876. // Look for denominator
  877. element = strtok(NULL, ":/\\");
  878. if (element)
  879. {
  880. LLLocale locale(LLLocale::USER_LOCALE);
  881. F32 denominator = (F32)atof(element);
  882. if (denominator > 0.f)
  883. {
  884. mAspectRatio /= denominator;
  885. }
  886. }
  887. }
  888. else
  889. {
  890. mAspectRatio = (F32)mCtrlAspectRatio->getValue().asReal();
  891. }
  892. // Presumably, user entered a non-numeric value if mAspectRatio == 0.f
  893. if (mAspectRatio != 0.f)
  894. {
  895. mAspectRatio = llclamp(mAspectRatio, 0.2f, 5.f);
  896. gSavedSettings.setF32("FullScreenAspectRatio", mAspectRatio);
  897. }
  898. // Screen resolution
  899. S32 num_resolutions;
  900. LLWindow::LLWindowResolution* resolutions =
  901. gWindowp->getSupportedResolutions(num_resolutions);
  902. S32 res_idx = mCtrlFullScreen->getCurrentIndex();
  903. if (res_idx >= 0 && res_idx < num_resolutions)
  904. {
  905. S32 width = resolutions[res_idx].mWidth;
  906. S32 height = resolutions[res_idx].mHeight;
  907. S32 old_width = gSavedSettings.getS32("FullScreenWidth");
  908. S32 old_height = gSavedSettings.getS32("FullScreenHeight");
  909. if (old_width != width)
  910. {
  911. gSavedSettings.setS32("FullScreenWidth", width);
  912. if (want_full_screen && full_screen)
  913. {
  914. after_restart = true;
  915. }
  916. }
  917. if (old_height != height)
  918. {
  919. gSavedSettings.setS32("FullScreenHeight", height);
  920. if (want_full_screen && full_screen)
  921. {
  922. after_restart = true;
  923. }
  924. }
  925. }
  926. gViewerWindowp->requestResolutionUpdate();
  927. send_agent_update(true);
  928. // GPU/GL features sub-tab
  929. if (gSavedSettings.getBool("RenderGLCoreProfile") != mRenderGLCoreProfile)
  930. {
  931. after_restart = true;
  932. }
  933. if (gSavedSettings.getU32("RenderFSAASamples") != mFSAASamples)
  934. {
  935. after_restart = true;
  936. }
  937. if (gSavedSettings.getBool("RenderAnisotropic") != mUseAniso)
  938. {
  939. restart_display = true;
  940. }
  941. if (gSavedSettings.getS32("GLWorkerThreads") != mGLWorkerThreads)
  942. {
  943. restart_display = true;
  944. }
  945. #if !LL_LINUX // Irrelevant setting for Linux
  946. if (gSavedSettings.getBool("RenderHiDPI") != mRenderHiDPI)
  947. {
  948. after_restart = true;
  949. }
  950. #endif
  951. // We do not support any more full screen <--> windowed mode changes during
  952. // sessions (and when in full screen mode, we do start it before displaying
  953. // the login screen), since those have always been prone to failures, black
  954. // screens and crashes. HB
  955. if (want_full_screen != full_screen)
  956. {
  957. after_restart = true;
  958. }
  959. // There are currently issues with core GL profile and display settings
  960. // changes, so require a restart instead for those. HB
  961. if (restart_display && LLRender::sGLCoreProfile)
  962. {
  963. restart_display = false;
  964. after_restart = true;
  965. }
  966. if (restart_display)
  967. {
  968. gViewerWindowp->restartDisplay();
  969. }
  970. if (after_restart)
  971. {
  972. gNotifications.add("InEffectAfterRestart");
  973. }
  974. // Update enable/disable
  975. refresh();
  976. }
  977. // Extract from strings of the form "<width> x <height>", e.g. "640 x 480".
  978. bool LLPrefsGraphicsImpl::extractSizeFromString(const std::string& instr,
  979. U32& width, U32& height)
  980. {
  981. try
  982. {
  983. std::cmatch what;
  984. const std::regex expression("([0-9]+) x ([0-9]+)");
  985. if (std::regex_match(instr.c_str(), what, expression))
  986. {
  987. width = atoi(what[1].first);
  988. height = atoi(what[2].first);
  989. return true;
  990. }
  991. }
  992. catch (std::regex_error& e)
  993. {
  994. llwarns << "Regex error: " << e.what() << llendl;
  995. }
  996. width = height = 0;
  997. return false;
  998. }
  999. void LLPrefsGraphicsImpl::applyWindowSize()
  1000. {
  1001. // Only apply the new window size in real time (i.e. without a restart)
  1002. // when in windowed mode and when the user wants to change the size for
  1003. // that mode. Changing the size (i.e. the resolution or scaling) while in
  1004. // full screen mode most often fails with a black screen or worst, and if
  1005. // the user did not ask for a size change for the windowed mode while we
  1006. // are running in this mode, then we do not care. HB
  1007. if (!(bool)mCtrlWindowed->get() || gWindowp->getFullscreen() ||
  1008. // Check for bogus index (missing combo ?)
  1009. mCtrlWindowSize->getCurrentIndex() == -1)
  1010. {
  1011. return;
  1012. }
  1013. U32 width = 0;
  1014. U32 height = 0;
  1015. std::string res_str = mCtrlWindowSize->getValue().asString();
  1016. if (extractSizeFromString(res_str, width, height))
  1017. {
  1018. gViewerWindowp->resizeWindow(width, height);
  1019. }
  1020. }
  1021. void LLPrefsGraphicsImpl::onChangeQuality(LLUICtrl* ctrl, void* data)
  1022. {
  1023. LLPrefsGraphicsImpl* self = (LLPrefsGraphicsImpl*)data;
  1024. LLSliderCtrl* sldr = (LLSliderCtrl*)ctrl;
  1025. if (self && sldr)
  1026. {
  1027. U32 set = (U32)sldr->getValueF32();
  1028. gFeatureManager.setGraphicsLevel(set, true);
  1029. self->refreshEnabledState();
  1030. self->refresh();
  1031. self->applyResolution();
  1032. }
  1033. }
  1034. //static
  1035. void LLPrefsGraphicsImpl::onTabChanged(void* data, bool)
  1036. {
  1037. LLPrefsGraphicsImpl* self = (LLPrefsGraphicsImpl*)data;
  1038. if (self && self->mTabContainer)
  1039. {
  1040. gSavedSettings.setS32("LastGraphicsPrefTab",
  1041. self->mTabContainer->getCurrentPanelIndex());
  1042. }
  1043. }
  1044. //static
  1045. void LLPrefsGraphicsImpl::onOpenHelp(void* data)
  1046. {
  1047. LLPrefsGraphicsImpl* self = (LLPrefsGraphicsImpl*)data;
  1048. if (!self) return;
  1049. LLFloater* parentp = gFloaterViewp->getParentFloater(self);
  1050. if (!parentp) return;
  1051. gNotifications.add(parentp->contextualNotification("GraphicsPreferencesHelp"));
  1052. }
  1053. //static
  1054. void LLPrefsGraphicsImpl::onCommitWindowedMode(LLUICtrl*, void* data)
  1055. {
  1056. LLPrefsGraphicsImpl* self = (LLPrefsGraphicsImpl*)data;
  1057. if (self)
  1058. {
  1059. // Store the mode the user wants.
  1060. gSavedSettings.setBool("FullScreen", !self->mCtrlWindowed->get());
  1061. self->refresh();
  1062. }
  1063. }
  1064. //static
  1065. void LLPrefsGraphicsImpl::onCommitAutoDetectAspect(LLUICtrl* ctrl, void* data)
  1066. {
  1067. LLPrefsGraphicsImpl* self = (LLPrefsGraphicsImpl*)data;
  1068. if (!self || !ctrl) return;
  1069. bool auto_detect = ((LLCheckBoxCtrl*)ctrl)->get();
  1070. if (auto_detect)
  1071. {
  1072. S32 numerator = 0;
  1073. S32 denominator = 0;
  1074. // Clear any aspect ratio override
  1075. gWindowp->setNativeAspectRatio(0.f);
  1076. fractionFromDecimal(gWindowp->getNativeAspectRatio(), numerator,
  1077. denominator);
  1078. std::string aspect;
  1079. if (numerator != 0)
  1080. {
  1081. aspect = llformat("%d:%d", numerator, denominator);
  1082. }
  1083. else
  1084. {
  1085. aspect = llformat("%.3f", gWindowp->getNativeAspectRatio());
  1086. }
  1087. self->mCtrlAspectRatio->setLabel(aspect);
  1088. F32 ratio = gWindowp->getNativeAspectRatio();
  1089. gSavedSettings.setF32("FullScreenAspectRatio", ratio);
  1090. }
  1091. }
  1092. //static
  1093. void LLPrefsGraphicsImpl::onKeystrokeAspectRatio(LLLineEditor*, void* data)
  1094. {
  1095. LLPrefsGraphicsImpl* self = (LLPrefsGraphicsImpl*)data;
  1096. if (self)
  1097. {
  1098. self->mCtrlAutoDetectAspect->set(false);
  1099. }
  1100. }
  1101. //static
  1102. void LLPrefsGraphicsImpl::onSelectAspectRatio(LLUICtrl*, void* data)
  1103. {
  1104. LLPrefsGraphicsImpl* self = (LLPrefsGraphicsImpl*)data;
  1105. if (self)
  1106. {
  1107. self->mCtrlAutoDetectAspect->set(false);
  1108. }
  1109. }
  1110. //static
  1111. void LLPrefsGraphicsImpl::fractionFromDecimal(F32 decimal_val, S32& numerator,
  1112. S32& denominator)
  1113. {
  1114. numerator = 0;
  1115. denominator = 0;
  1116. for (F32 test_denominator = 1.f; test_denominator < 30.f;
  1117. test_denominator += 1.f)
  1118. {
  1119. if (fmodf((decimal_val * test_denominator) + 0.01f, 1.f) < 0.02f)
  1120. {
  1121. numerator = ll_round(decimal_val * test_denominator);
  1122. denominator = ll_round(test_denominator);
  1123. break;
  1124. }
  1125. }
  1126. }
  1127. //static
  1128. void LLPrefsGraphicsImpl::onCommitNeedsRefresh(LLUICtrl*, void* data)
  1129. {
  1130. LLPrefsGraphicsImpl* self = (LLPrefsGraphicsImpl*)data;
  1131. if (self)
  1132. {
  1133. self->refreshEnabledState();
  1134. }
  1135. }
  1136. //static
  1137. void LLPrefsGraphicsImpl::onCommitAvatarPhysics(LLUICtrl* ctrl, void* data)
  1138. {
  1139. LLPrefsGraphicsImpl* self = (LLPrefsGraphicsImpl*)data;
  1140. LLCheckBoxCtrl* check = (LLCheckBoxCtrl*)ctrl;
  1141. if (!self || !check) return;
  1142. bool enabled = check->get();
  1143. self->childSetEnabled("AvatarPhysicsLOD", enabled);
  1144. }
  1145. //static
  1146. void LLPrefsGraphicsImpl::onCommitMaxNonImpostors(LLUICtrl* ctrl, void* data)
  1147. {
  1148. LLPrefsGraphicsImpl* self = (LLPrefsGraphicsImpl*)data;
  1149. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1150. if (!self || !slider) return;
  1151. bool enabled = slider->getValue().asInteger() > 0;
  1152. self->mCtrlMaximumComplexity->setEnabled(enabled);
  1153. self->mCtrlSurfaceAreaLimit->setEnabled(enabled);
  1154. self->mCtrlGeometryBytesLimit->setEnabled(enabled);
  1155. }
  1156. void LLPrefsGraphicsImpl::setHardwareDefaults(void* data)
  1157. {
  1158. LLPrefsGraphicsImpl* self = (LLPrefsGraphicsImpl*)data;
  1159. if (self)
  1160. {
  1161. gFeatureManager.applyRecommendedSettings();
  1162. self->refreshEnabledState();
  1163. self->refresh();
  1164. }
  1165. }
  1166. void LLPrefsGraphicsImpl::updateSliderText(LLUICtrl* ctrl, void* data)
  1167. {
  1168. // Get our UI widgets
  1169. LLTextBox* text_box = (LLTextBox*)data;
  1170. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1171. if (!text_box || !slider)
  1172. {
  1173. return;
  1174. }
  1175. // Get range and points when text should change
  1176. F32 range = slider->getMaxValue() - slider->getMinValue();
  1177. llassert(range > 0);
  1178. F32 midPoint = slider->getMinValue() + range / 3.f;
  1179. F32 highPoint = slider->getMinValue() + (2.f / 3.f) * range;
  1180. // Choose the right text
  1181. if (slider->getValueF32() < midPoint)
  1182. {
  1183. text_box->setText("Low");
  1184. }
  1185. else if (slider->getValueF32() < highPoint)
  1186. {
  1187. text_box->setText("Mid");
  1188. }
  1189. else
  1190. {
  1191. text_box->setText("High");
  1192. }
  1193. }
  1194. void LLPrefsGraphicsImpl::updateMeterText(LLUICtrl* ctrl, void* data)
  1195. {
  1196. // Get our UI widgets
  1197. LLPrefsGraphicsImpl* self = (LLPrefsGraphicsImpl*)data;
  1198. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1199. if (self && ctrl)
  1200. {
  1201. // Toggle the two text boxes based on whether we have 1 or two digits
  1202. F32 val = slider->getValueF32();
  1203. bool two_digits = val < 100;
  1204. self->mDrawDistanceMeterText1->setVisible(two_digits);
  1205. self->mDrawDistanceMeterText2->setVisible(!two_digits);
  1206. }
  1207. }
  1208. void LLPrefsGraphicsImpl::onClassicClouds(LLUICtrl* ctrl, void* data)
  1209. {
  1210. LLPrefsGraphicsImpl* self = (LLPrefsGraphicsImpl*)data;
  1211. LLCheckBoxCtrl* check = (LLCheckBoxCtrl*)ctrl;
  1212. if (self && check)
  1213. {
  1214. self->mSpinCloudsAltitude->setEnabled(check->get());
  1215. }
  1216. }
  1217. //-----------------------------------------------------------------------------
  1218. LLPrefsGraphics::LLPrefsGraphics()
  1219. : impl(*new LLPrefsGraphicsImpl())
  1220. {
  1221. }
  1222. LLPrefsGraphics::~LLPrefsGraphics()
  1223. {
  1224. delete &impl;
  1225. }
  1226. void LLPrefsGraphics::apply()
  1227. {
  1228. impl.apply();
  1229. }
  1230. void LLPrefsGraphics::cancel()
  1231. {
  1232. impl.cancel();
  1233. }
  1234. LLPanel* LLPrefsGraphics::getPanel()
  1235. {
  1236. return &impl;
  1237. }
  1238. //static
  1239. void LLPrefsGraphics::refresh()
  1240. {
  1241. sNeedsRefresh = true;
  1242. }