PageRenderTime 433ms CodeModel.GetById 153ms app.highlight 105ms RepoModel.GetById 126ms app.codeStats 1ms

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