PageRenderTime 27ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llwlparammanager.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 415 lines | 250 code | 88 blank | 77 comment | 18 complexity | e6dc4ef34c2e61d8db5aab4e44db58a5 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llwlparammanager.h
  3. * @brief Implementation for the LLWLParamManager class.
  4. *
  5. * $LicenseInfo:firstyear=2007&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. #ifndef LL_WLPARAMMANAGER_H
  27. #define LL_WLPARAMMANAGER_H
  28. #include <list>
  29. #include <map>
  30. #include "llenvmanager.h"
  31. #include "llwlparamset.h"
  32. #include "llwlanimator.h"
  33. #include "llwldaycycle.h"
  34. #include "llviewercamera.h"
  35. #include "lltrans.h"
  36. class LLGLSLShader;
  37. // color control
  38. struct WLColorControl {
  39. F32 r, g, b, i; /// the values
  40. std::string mName; /// name to use to dereference params
  41. std::string mSliderName; /// name of the slider in menu
  42. bool hasSliderName; /// only set slider name for true color types
  43. bool isSunOrAmbientColor; /// flag for if it's the sun or ambient color controller
  44. bool isBlueHorizonOrDensity; /// flag for if it's the Blue Horizon or Density color controller
  45. inline WLColorControl(F32 red, F32 green, F32 blue, F32 intensity,
  46. const std::string& n, const std::string& sliderName = LLStringUtil::null)
  47. : r(red), g(green), b(blue), i(intensity), mName(n), mSliderName(sliderName)
  48. {
  49. // if there's a slider name, say we have one
  50. hasSliderName = false;
  51. if (mSliderName != "") {
  52. hasSliderName = true;
  53. }
  54. // if it's the sun controller
  55. isSunOrAmbientColor = false;
  56. if (mSliderName == "WLSunlight" || mSliderName == "WLAmbient") {
  57. isSunOrAmbientColor = true;
  58. }
  59. isBlueHorizonOrDensity = false;
  60. if (mSliderName == "WLBlueHorizon" || mSliderName == "WLBlueDensity") {
  61. isBlueHorizonOrDensity = true;
  62. }
  63. }
  64. inline WLColorControl & operator = (LLVector4 const & val) {
  65. r = val.mV[0];
  66. g = val.mV[1];
  67. b = val.mV[2];
  68. i = val.mV[3];
  69. return *this;
  70. }
  71. inline operator LLVector4 (void) const {
  72. return LLVector4(r, g, b, i);
  73. }
  74. inline operator LLVector3 (void) const {
  75. return LLVector3(r, g, b);
  76. }
  77. inline void update(LLWLParamSet & params) const {
  78. params.set(mName, r, g, b, i);
  79. }
  80. };
  81. // float slider control
  82. struct WLFloatControl {
  83. F32 x;
  84. std::string mName;
  85. F32 mult;
  86. inline WLFloatControl(F32 val, const std::string& n, F32 m=1.0f)
  87. : x(val), mName(n), mult(m)
  88. {
  89. }
  90. inline WLFloatControl & operator = (LLVector4 const & val) {
  91. x = val.mV[0];
  92. return *this;
  93. }
  94. inline operator F32 (void) const {
  95. return x;
  96. }
  97. inline void update(LLWLParamSet & params) const {
  98. params.set(mName, x);
  99. }
  100. };
  101. struct LLWLParamKey : LLEnvKey
  102. {
  103. public:
  104. // scope and source of a param set (WL sky preset)
  105. std::string name;
  106. EScope scope;
  107. // for conversion from LLSD
  108. static const int NAME_IDX = 0;
  109. static const int SCOPE_IDX = 1;
  110. inline LLWLParamKey(const std::string& n, EScope s)
  111. : name(n), scope(s)
  112. {
  113. }
  114. inline LLWLParamKey(LLSD llsd)
  115. : name(llsd[NAME_IDX].asString()), scope(EScope(llsd[SCOPE_IDX].asInteger()))
  116. {
  117. }
  118. inline LLWLParamKey() // NOT really valid, just so std::maps can return a default of some sort
  119. : name(""), scope(SCOPE_LOCAL)
  120. {
  121. }
  122. inline LLWLParamKey(std::string& stringVal)
  123. {
  124. size_t len = stringVal.length();
  125. if (len > 0)
  126. {
  127. name = stringVal.substr(0, len - 1);
  128. scope = (EScope) atoi(stringVal.substr(len - 1, len).c_str());
  129. }
  130. }
  131. inline std::string toStringVal() const
  132. {
  133. std::stringstream str;
  134. str << name << scope;
  135. return str.str();
  136. }
  137. inline LLSD toLLSD() const
  138. {
  139. LLSD llsd = LLSD::emptyArray();
  140. llsd.append(LLSD(name));
  141. llsd.append(LLSD(scope));
  142. return llsd;
  143. }
  144. inline void fromLLSD(const LLSD& llsd)
  145. {
  146. name = llsd[NAME_IDX].asString();
  147. scope = EScope(llsd[SCOPE_IDX].asInteger());
  148. }
  149. inline bool operator <(const LLWLParamKey other) const
  150. {
  151. if (name < other.name)
  152. {
  153. return true;
  154. }
  155. else if (name > other.name)
  156. {
  157. return false;
  158. }
  159. else
  160. {
  161. return scope < other.scope;
  162. }
  163. }
  164. inline bool operator ==(const LLWLParamKey other) const
  165. {
  166. return (name == other.name) && (scope == other.scope);
  167. }
  168. inline std::string toString() const
  169. {
  170. switch (scope)
  171. {
  172. case SCOPE_LOCAL:
  173. return name + std::string(" (") + LLTrans::getString("Local") + std::string(")");
  174. break;
  175. case SCOPE_REGION:
  176. return name + std::string(" (") + LLTrans::getString("Region") + std::string(")");
  177. break;
  178. default:
  179. return name + " (?)";
  180. }
  181. }
  182. };
  183. /// WindLight parameter manager class - what controls all the wind light shaders
  184. class LLWLParamManager : public LLSingleton<LLWLParamManager>
  185. {
  186. LOG_CLASS(LLWLParamManager);
  187. public:
  188. typedef std::list<std::string> preset_name_list_t;
  189. typedef std::list<LLWLParamKey> preset_key_list_t;
  190. typedef boost::signals2::signal<void()> preset_list_signal_t;
  191. /// save the parameter presets to file
  192. void savePreset(const LLWLParamKey key);
  193. /// Set shader uniforms dirty, so they'll update automatically.
  194. void propagateParameters(void);
  195. /// Update shader uniforms that have changed.
  196. void updateShaderUniforms(LLGLSLShader * shader);
  197. /// setup the animator to run
  198. void resetAnimator(F32 curTime, bool run);
  199. /// update information camera dependent parameters
  200. void update(LLViewerCamera * cam);
  201. /// apply specified day cycle, setting time to noon by default
  202. bool applyDayCycleParams(const LLSD& params, LLEnvKey::EScope scope, F32 time = 0.5);
  203. /// apply specified fixed sky params
  204. bool applySkyParams(const LLSD& params);
  205. // get where the light is pointing
  206. inline LLVector4 getLightDir(void) const;
  207. // get where the light is pointing
  208. inline LLVector4 getClampedLightDir(void) const;
  209. // get where the light is pointing
  210. inline LLVector4 getRotatedLightDir(void) const;
  211. /// get the dome's offset
  212. inline F32 getDomeOffset(void) const;
  213. /// get the radius of the dome
  214. inline F32 getDomeRadius(void) const;
  215. /// add a param set (preset) to the list
  216. bool addParamSet(const LLWLParamKey& key, LLWLParamSet& param);
  217. /// add a param set (preset) to the list
  218. BOOL addParamSet(const LLWLParamKey& key, LLSD const & param);
  219. /// get a param set (preset) from the list
  220. bool getParamSet(const LLWLParamKey& key, LLWLParamSet& param);
  221. /// check whether the preset is in the list
  222. bool hasParamSet(const LLWLParamKey& key);
  223. /// set the param in the list with a new param
  224. bool setParamSet(const LLWLParamKey& key, LLWLParamSet& param);
  225. /// set the param in the list with a new param
  226. bool setParamSet(const LLWLParamKey& key, LLSD const & param);
  227. /// gets rid of a parameter and any references to it
  228. /// ignores "delete_from_disk" if the scope is not local
  229. void removeParamSet(const LLWLParamKey& key, bool delete_from_disk);
  230. /// clear parameter mapping of a given scope
  231. void clearParamSetsOfScope(LLEnvKey::EScope scope);
  232. /// @return true if the preset comes out of the box
  233. bool isSystemPreset(const std::string& preset_name) const;
  234. /// @return user and system preset names as a single list
  235. void getPresetNames(preset_name_list_t& region, preset_name_list_t& user, preset_name_list_t& sys) const;
  236. /// @return user preset names
  237. void getUserPresetNames(preset_name_list_t& user) const;
  238. /// @return keys of all known presets
  239. void getPresetKeys(preset_key_list_t& keys) const;
  240. /// Emitted when a preset gets added or deleted.
  241. boost::signals2::connection setPresetListChangeCallback(const preset_list_signal_t::slot_type& cb);
  242. /// add all skies in LLSD using the given scope
  243. void addAllSkies(LLEnvKey::EScope scope, const LLSD& preset_map);
  244. /// refresh region-scope presets
  245. void refreshRegionPresets();
  246. // returns all skies referenced by the current day cycle (in mDay), with their final names
  247. // side effect: applies changes to all internal structures! (trashes all unreferenced skies in scope, keys in day cycle rescoped to scope, etc.)
  248. std::map<LLWLParamKey, LLWLParamSet> finalizeFromDayCycle(LLWLParamKey::EScope scope);
  249. // returns all skies in map (intended to be called with output from a finalize)
  250. static LLSD createSkyMap(std::map<LLWLParamKey, LLWLParamSet> map);
  251. /// escape string in a way different from LLURI::escape()
  252. static std::string escapeString(const std::string& str);
  253. // helper variables
  254. LLWLAnimator mAnimator;
  255. /// actual direction of the sun
  256. LLVector4 mLightDir;
  257. /// light norm adjusted so haze works correctly
  258. LLVector4 mRotatedLightDir;
  259. /// clamped light norm for shaders that
  260. /// are adversely affected when the sun goes below the
  261. /// horizon
  262. LLVector4 mClampedLightDir;
  263. // list of params and how they're cycled for days
  264. LLWLDayCycle mDay;
  265. LLWLParamSet mCurParams;
  266. /// Sun Delta Terrain tweak variables.
  267. F32 mSunDeltaYaw;
  268. WLFloatControl mWLGamma;
  269. F32 mSceneLightStrength;
  270. /// Atmospherics
  271. WLColorControl mBlueHorizon;
  272. WLColorControl mHazeDensity;
  273. WLColorControl mBlueDensity;
  274. WLFloatControl mDensityMult;
  275. WLColorControl mHazeHorizon;
  276. WLFloatControl mMaxAlt;
  277. /// Lighting
  278. WLColorControl mLightnorm;
  279. WLColorControl mSunlight;
  280. WLColorControl mAmbient;
  281. WLColorControl mGlow;
  282. /// Clouds
  283. WLColorControl mCloudColor;
  284. WLColorControl mCloudMain;
  285. WLFloatControl mCloudCoverage;
  286. WLColorControl mCloudDetail;
  287. WLFloatControl mDistanceMult;
  288. WLFloatControl mCloudScale;
  289. /// sky dome
  290. F32 mDomeOffset;
  291. F32 mDomeRadius;
  292. private:
  293. friend class LLWLAnimator;
  294. void loadAllPresets();
  295. void loadPresetsFromDir(const std::string& dir);
  296. bool loadPreset(const std::string& path);
  297. static std::string getSysDir();
  298. static std::string getUserDir();
  299. friend class LLSingleton<LLWLParamManager>;
  300. /*virtual*/ void initSingleton();
  301. LLWLParamManager();
  302. ~LLWLParamManager();
  303. // list of all the parameters, listed by name
  304. std::map<LLWLParamKey, LLWLParamSet> mParamList;
  305. preset_list_signal_t mPresetListChangeSignal;
  306. };
  307. inline F32 LLWLParamManager::getDomeOffset(void) const
  308. {
  309. return mDomeOffset;
  310. }
  311. inline F32 LLWLParamManager::getDomeRadius(void) const
  312. {
  313. return mDomeRadius;
  314. }
  315. inline LLVector4 LLWLParamManager::getLightDir(void) const
  316. {
  317. return mLightDir;
  318. }
  319. inline LLVector4 LLWLParamManager::getClampedLightDir(void) const
  320. {
  321. return mClampedLightDir;
  322. }
  323. inline LLVector4 LLWLParamManager::getRotatedLightDir(void) const
  324. {
  325. return mRotatedLightDir;
  326. }
  327. #endif