aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llwaterparammanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/llwaterparammanager.cpp')
-rw-r--r--linden/indra/newview/llwaterparammanager.cpp111
1 files changed, 56 insertions, 55 deletions
diff --git a/linden/indra/newview/llwaterparammanager.cpp b/linden/indra/newview/llwaterparammanager.cpp
index 0156622..2386631 100644
--- a/linden/indra/newview/llwaterparammanager.cpp
+++ b/linden/indra/newview/llwaterparammanager.cpp
@@ -3,9 +3,9 @@
3 * @brief Implementation for the LLWaterParamManager class. 3 * @brief Implementation for the LLWaterParamManager class.
4 * 4 *
5 * $LicenseInfo:firstyear=2007&license=viewergpl$ 5 * $LicenseInfo:firstyear=2007&license=viewergpl$
6 * 6 *
7 * Copyright (c) 2007-2009, Linden Research, Inc. 7 * Copyright (c) 2007-2009, Linden Research, Inc.
8 * 8 *
9 * Second Life Viewer Source Code 9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab 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 11 * to you under the terms of the GNU General Public License, version 2.0
@@ -13,17 +13,17 @@
13 * ("Other License"), formally executed by you and Linden Lab. Terms of 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 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 15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 * 16 *
17 * There are special exceptions to the terms and conditions of the GPL as 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 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 19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at 20 * online at
21 * http://secondlifegrid.net/programs/open_source/licensing/flossexception 21 * http://secondlifegrid.net/programs/open_source/licensing/flossexception
22 * 22 *
23 * By copying, modifying or distributing this software, you acknowledge 23 * By copying, modifying or distributing this software, you acknowledge
24 * that you have read and understood your obligations described above, 24 * that you have read and understood your obligations described above,
25 * and agree to abide by those obligations. 25 * and agree to abide by those obligations.
26 * 26 *
27 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO 27 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
28 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, 28 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
29 * COMPLETENESS OR PERFORMANCE. 29 * COMPLETENESS OR PERFORMANCE.
@@ -69,6 +69,7 @@
69 69
70#include "llwlparammanager.h" 70#include "llwlparammanager.h"
71#include "llwaterparamset.h" 71#include "llwaterparamset.h"
72#include "llettherebelight.h"
72#include "llpostprocess.h" 73#include "llpostprocess.h"
73#include "llfloaterwater.h" 74#include "llfloaterwater.h"
74 75
@@ -102,9 +103,9 @@ void LLWaterParamManager::loadAllPresets(const std::string& file_name)
102{ 103{
103 std::string path_name(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/water", "")); 104 std::string path_name(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/water", ""));
104 LL_DEBUGS2("AppInit", "ShaderLoading") << "Loading Default water settings from " << path_name << LL_ENDL; 105 LL_DEBUGS2("AppInit", "ShaderLoading") << "Loading Default water settings from " << path_name << LL_ENDL;
105 106
106 bool found = true; 107 bool found = true;
107 while(found) 108 while(found)
108 { 109 {
109 std::string name; 110 std::string name;
110 found = gDirUtilp->getNextFileInDir(path_name, "*.xml", name, false); 111 found = gDirUtilp->getNextFileInDir(path_name, "*.xml", name, false);
@@ -128,9 +129,9 @@ void LLWaterParamManager::loadAllPresets(const std::string& file_name)
128 129
129 std::string path_name2(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/water", "")); 130 std::string path_name2(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/water", ""));
130 LL_DEBUGS2("AppInit", "Shaders") << "Loading User water settings from " << path_name2 << LL_ENDL; 131 LL_DEBUGS2("AppInit", "Shaders") << "Loading User water settings from " << path_name2 << LL_ENDL;
131 132
132 found = true; 133 found = true;
133 while(found) 134 while(found)
134 { 135 {
135 std::string name; 136 std::string name;
136 found = gDirUtilp->getNextFileInDir(path_name2, "*.xml", name, false); 137 found = gDirUtilp->getNextFileInDir(path_name2, "*.xml", name, false);
@@ -159,7 +160,7 @@ void LLWaterParamManager::loadPreset(const std::string & name,bool propagate)
159 if(propagate) 160 if(propagate)
160 { 161 {
161 getParamSet(name, mCurParams); 162 getParamSet(name, mCurParams);
162 propagateParameters(); 163 LightShare::apply(&mCurParams, NULL, NULL, WL_SCOPE_USER);
163 } 164 }
164 return; 165 return;
165 } 166 }
@@ -174,10 +175,10 @@ void LLWaterParamManager::loadPreset(const std::string & name,bool propagate)
174 175
175 std::string pathName(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/water", escaped_filename)); 176 std::string pathName(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/water", escaped_filename));
176 LL_DEBUGS2("AppInit", "Shaders") << "Loading water settings from " << pathName << LL_ENDL; 177 LL_DEBUGS2("AppInit", "Shaders") << "Loading water settings from " << pathName << LL_ENDL;
177 178
178 std::ifstream presetsXML; 179 std::ifstream presetsXML;
179 presetsXML.open(pathName.c_str()); 180 presetsXML.open(pathName.c_str());
180 181
181 // That failed, try loading from the users area instead. 182 // That failed, try loading from the users area instead.
182 if(!presetsXML) 183 if(!presetsXML)
183 { 184 {
@@ -190,8 +191,8 @@ void LLWaterParamManager::loadPreset(const std::string & name,bool propagate)
190 { 191 {
191 loadPresetXML(name, presetsXML); 192 loadPresetXML(name, presetsXML);
192 presetsXML.close(); 193 presetsXML.close();
193 } 194 }
194 else 195 else
195 { 196 {
196 llwarns << "Can't find " << name << llendl; 197 llwarns << "Can't find " << name << llendl;
197 return; 198 return;
@@ -200,21 +201,21 @@ void LLWaterParamManager::loadPreset(const std::string & name,bool propagate)
200 if(propagate) 201 if(propagate)
201 { 202 {
202 getParamSet(name, mCurParams); 203 getParamSet(name, mCurParams);
203 propagateParameters(); 204 LightShare::apply(&mCurParams, NULL, NULL, WL_SCOPE_USER);
204 } 205 }
205} 206}
206 207
207bool LLWaterParamManager::loadPresetXML(const std::string& name, std::istream& preset_stream, bool propagate /* = false */, bool check_if_real /* = false */) 208bool LLWaterParamManager::loadPresetXML(const std::string& name, std::istream& preset_stream, bool propagate /* = false */, bool check_if_real /* = false */)
208{ 209{
209 LLSD paramsData(LLSD::emptyMap()); 210 LLSD paramsData(LLSD::emptyMap());
210 211
211 LLPointer<LLSDParser> parser = new LLSDXMLParser(); 212 LLPointer<LLSDParser> parser = new LLSDXMLParser();
212 213
213 if(parser->parse(preset_stream, paramsData, LLSDSerialize::SIZE_UNLIMITED) == LLSDParser::PARSE_FAILURE) 214 if(parser->parse(preset_stream, paramsData, LLSDSerialize::SIZE_UNLIMITED) == LLSDParser::PARSE_FAILURE)
214 { 215 {
215 return false; 216 return false;
216 } 217 }
217 218
218 if(check_if_real) 219 if(check_if_real)
219 { 220 {
220 static const char* expected_windlight_settings[] = { 221 static const char* expected_windlight_settings[] = {
@@ -240,17 +241,17 @@ bool LLWaterParamManager::loadPresetXML(const std::string& name, std::istream& p
240 } 241 }
241 } 242 }
242 } 243 }
243 244
244 std::map<std::string, LLWaterParamSet>::iterator mIt = mParamList.find(name); 245 std::map<std::string, LLWaterParamSet>::iterator mIt = mParamList.find(name);
245 if(mIt == mParamList.end()) 246 if(mIt == mParamList.end())
246 { 247 {
247 addParamSet(name, paramsData); 248 addParamSet(name, paramsData);
248 } 249 }
249 else 250 else
250 { 251 {
251 setParamSet(name, paramsData); 252 setParamSet(name, paramsData);
252 } 253 }
253 254
254 if(propagate) 255 if(propagate)
255 { 256 {
256 getParamSet(name, mCurParams); 257 getParamSet(name, mCurParams);
@@ -306,19 +307,19 @@ bool LLWaterParamManager::savePresetToNotecard(const std::string & name)
306{ 307{
307 // make an empty llsd 308 // make an empty llsd
308 LLSD paramsData(LLSD::emptyMap()); 309 LLSD paramsData(LLSD::emptyMap());
309 310
310 // fill it with LLSD windlight params 311 // fill it with LLSD windlight params
311 paramsData = mParamList[name].getAll(); 312 paramsData = mParamList[name].getAll();
312 313
313 // get some XML 314 // get some XML
314 std::ostringstream presetsXML; 315 std::ostringstream presetsXML;
315 LLPointer<LLSDFormatter> formatter = new LLSDXMLFormatter(); 316 LLPointer<LLSDFormatter> formatter = new LLSDXMLFormatter();
316 formatter->format(paramsData, presetsXML, LLSDFormatter::OPTIONS_PRETTY); 317 formatter->format(paramsData, presetsXML, LLSDFormatter::OPTIONS_PRETTY);
317 318
318 // Write it to a notecard 319 // Write it to a notecard
319 LLNotecard notecard; 320 LLNotecard notecard;
320 notecard.setText(presetsXML.str()); 321 notecard.setText(presetsXML.str());
321 322
322 LLInventoryItem *item = gInventory.getItem(mParamList[name].mInventoryID); 323 LLInventoryItem *item = gInventory.getItem(mParamList[name].mInventoryID);
323 if(!item) 324 if(!item)
324 { 325 {
@@ -332,13 +333,13 @@ bool LLWaterParamManager::savePresetToNotecard(const std::string & name)
332 LLAssetID asset_id; 333 LLAssetID asset_id;
333 tid.generate(); 334 tid.generate();
334 asset_id = tid.makeAssetID(gAgent.getSecureSessionID()); 335 asset_id = tid.makeAssetID(gAgent.getSecureSessionID());
335 336
336 LLVFile file(gVFS, asset_id, LLAssetType::AT_NOTECARD, LLVFile::APPEND); 337 LLVFile file(gVFS, asset_id, LLAssetType::AT_NOTECARD, LLVFile::APPEND);
337 338
338 std::ostringstream stream; 339 std::ostringstream stream;
339 notecard.exportStream(stream); 340 notecard.exportStream(stream);
340 std::string buffer = stream.str(); 341 std::string buffer = stream.str();
341 342
342 S32 size = buffer.length() + 1; 343 S32 size = buffer.length() + 1;
343 file.setMaxSize(size); 344 file.setMaxSize(size);
344 file.write((U8*)buffer.c_str(), size); 345 file.write((U8*)buffer.c_str(), size);
@@ -351,7 +352,7 @@ bool LLWaterParamManager::savePresetToNotecard(const std::string & name)
351 LL_WARNS("WindLight") << "Stuff the legacy system." << LL_ENDL; 352 LL_WARNS("WindLight") << "Stuff the legacy system." << LL_ENDL;
352 return false; 353 return false;
353 } 354 }
354 355
355 propagateParameters(); 356 propagateParameters();
356 return true; 357 return true;
357} 358}
@@ -374,8 +375,8 @@ void LLWaterParamManager::propagateParameters(void)
374 } 375 }
375 376
376 bool err; 377 bool err;
377 F32 fog_density_slider = 378 F32 fog_density_slider =
378 log(mCurParams.getFloat(mFogDensity.mName, err)) / 379 log(mCurParams.getFloat(mFogDensity.mName, err)) /
379 log(mFogDensity.mBase); 380 log(mFogDensity.mBase);
380 381
381 setDensitySliderValue(fog_density_slider); 382 setDensitySliderValue(fog_density_slider);
@@ -398,12 +399,12 @@ void LLWaterParamManager::updateShaderUniforms(LLGLSLShader * shader)
398void LLWaterParamManager::update(LLViewerCamera * cam) 399void LLWaterParamManager::update(LLViewerCamera * cam)
399{ 400{
400 LLFastTimer ftm(LLFastTimer::FTM_UPDATE_WLPARAM); 401 LLFastTimer ftm(LLFastTimer::FTM_UPDATE_WLPARAM);
401 402
402 // update the shaders and the menu 403 // update the shaders and the menu
403 propagateParameters(); 404 propagateParameters();
404 405
405 // sync menus if they exist 406 // sync menus if they exist
406 if(LLFloaterWater::isOpen()) 407 if(LLFloaterWater::isOpen())
407 { 408 {
408 LLFloaterWater::instance()->syncMenu(); 409 LLFloaterWater::instance()->syncMenu();
409 } 410 }
@@ -411,12 +412,12 @@ void LLWaterParamManager::update(LLViewerCamera * cam)
411 stop_glerror(); 412 stop_glerror();
412 413
413 // only do this if we're dealing with shaders 414 // only do this if we're dealing with shaders
414 if(gPipeline.canUseVertexShaders()) 415 if(gPipeline.canUseVertexShaders())
415 { 416 {
416 //transform water plane to eye space 417 //transform water plane to eye space
417 glh::vec3f norm(0.f, 0.f, 1.f); 418 glh::vec3f norm(0.f, 0.f, 1.f);
418 glh::vec3f p(0.f, 0.f, gAgent.getRegion()->getWaterHeight()+0.1f); 419 glh::vec3f p(0.f, 0.f, gAgent.getRegion()->getWaterHeight()+0.1f);
419 420
420 F32 modelView[16]; 421 F32 modelView[16];
421 for (U32 i = 0; i < 16; i++) 422 for (U32 i = 0; i < 16; i++)
422 { 423 {
@@ -434,13 +435,13 @@ void LLWaterParamManager::update(LLViewerCamera * cam)
434 mWaterPlane = LLVector4(enorm.v[0], enorm.v[1], enorm.v[2], -ep.dot(enorm)); 435 mWaterPlane = LLVector4(enorm.v[0], enorm.v[1], enorm.v[2], -ep.dot(enorm));
435 436
436 LLVector3 sunMoonDir; 437 LLVector3 sunMoonDir;
437 if (gSky.getSunDirection().mV[2] > NIGHTTIME_ELEVATION_COS) 438 if (gSky.getSunDirection().mV[2] > NIGHTTIME_ELEVATION_COS)
438 { 439 {
439 sunMoonDir = gSky.getSunDirection(); 440 sunMoonDir = gSky.getSunDirection();
440 } 441 }
441 else 442 else
442 { 443 {
443 sunMoonDir = gSky.getMoonDirection(); 444 sunMoonDir = gSky.getMoonDirection();
444 } 445 }
445 sunMoonDir.normVec(); 446 sunMoonDir.normVec();
446 mWaterFogKS = 1.f/llmax(sunMoonDir.mV[2], WATER_FOG_LIGHT_CLAMP); 447 mWaterFogKS = 1.f/llmax(sunMoonDir.mV[2], WATER_FOG_LIGHT_CLAMP);
@@ -510,8 +511,8 @@ bool LLWaterParamManager::addParamSet(const std::string& name, LLWaterParamSet&
510{ 511{
511 // add a new one if not one there already 512 // add a new one if not one there already
512 std::map<std::string, LLWaterParamSet>::iterator mIt = mParamList.find(name); 513 std::map<std::string, LLWaterParamSet>::iterator mIt = mParamList.find(name);
513 if(mIt == mParamList.end()) 514 if(mIt == mParamList.end())
514 { 515 {
515 mParamList[name] = param; 516 mParamList[name] = param;
516 return true; 517 return true;
517 } 518 }
@@ -538,7 +539,7 @@ bool LLWaterParamManager::getParamSet(const std::string& name, LLWaterParamSet&
538{ 539{
539 // find it and set it 540 // find it and set it
540 std::map<std::string, LLWaterParamSet>::iterator mIt = mParamList.find(name); 541 std::map<std::string, LLWaterParamSet>::iterator mIt = mParamList.find(name);
541 if(mIt != mParamList.end()) 542 if(mIt != mParamList.end())
542 { 543 {
543 param = mParamList[name]; 544 param = mParamList[name];
544 param.mName = name; 545 param.mName = name;
@@ -558,11 +559,11 @@ bool LLWaterParamManager::setParamSet(const std::string& name, LLWaterParamSet&
558bool LLWaterParamManager::setParamSet(const std::string& name, const LLSD & param) 559bool LLWaterParamManager::setParamSet(const std::string& name, const LLSD & param)
559{ 560{
560 // quick, non robust (we won't be working with files, but assets) check 561 // quick, non robust (we won't be working with files, but assets) check
561 if(!param.isMap()) 562 if(!param.isMap())
562 { 563 {
563 return false; 564 return false;
564 } 565 }
565 566
566 mParamList[name].setAll(param); 567 mParamList[name].setAll(param);
567 568
568 return true; 569 return true;
@@ -572,7 +573,7 @@ bool LLWaterParamManager::removeParamSet(const std::string& name, bool delete_fr
572{ 573{
573 // remove from param list 574 // remove from param list
574 std::map<std::string, LLWaterParamSet>::iterator mIt = mParamList.find(name); 575 std::map<std::string, LLWaterParamSet>::iterator mIt = mParamList.find(name);
575 if(mIt != mParamList.end()) 576 if(mIt != mParamList.end())
576 { 577 {
577 mParamList.erase(mIt); 578 mParamList.erase(mIt);
578 } 579 }
@@ -581,13 +582,13 @@ bool LLWaterParamManager::removeParamSet(const std::string& name, bool delete_fr
581 { 582 {
582 583
583 std::string path_name(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/water", "")); 584 std::string path_name(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/water", ""));
584 585
585 // use full curl escaped name 586 // use full curl escaped name
586 char * curl_str = curl_escape(name.c_str(), name.size()); 587 char * curl_str = curl_escape(name.c_str(), name.size());
587 std::string escaped_name(curl_str); 588 std::string escaped_name(curl_str);
588 curl_free(curl_str); 589 curl_free(curl_str);
589 curl_str = NULL; 590 curl_str = NULL;
590 591
591 gDirUtilp->deleteFilesInDir(path_name, escaped_name + ".xml"); 592 gDirUtilp->deleteFilesInDir(path_name, escaped_name + ".xml");
592 } 593 }
593 594
@@ -599,7 +600,7 @@ F32 LLWaterParamManager::getFogDensity(void)
599 bool err; 600 bool err;
600 601
601 F32 fogDensity = mCurParams.getFloat("waterFogDensity", err); 602 F32 fogDensity = mCurParams.getFloat("waterFogDensity", err);
602 603
603 // modify if we're underwater 604 // modify if we're underwater
604 const F32 water_height = gAgent.getRegion() ? gAgent.getRegion()->getWaterHeight() : 0.f; 605 const F32 water_height = gAgent.getRegion() ? gAgent.getRegion()->getWaterHeight() : 0.f;
605 F32 camera_height = gAgent.getCameraPositionAgent().mV[2]; 606 F32 camera_height = gAgent.getCameraPositionAgent().mV[2];
@@ -659,7 +660,7 @@ void LLWaterParamManager::loadWaterNotecard(LLVFS *vfs, const LLUUID& asset_id,
659 } 660 }
660 else 661 else
661 { 662 {
662 // We can do this because we know mCurParams 663 // We can do this because we know mCurParams
663 sInstance->mParamList[name].mInventoryID = inventory_id; 664 sInstance->mParamList[name].mInventoryID = inventory_id;
664 } 665 }
665 } 666 }