void LLWLParamManager::loadPreset(const std::string & name,bool propagate) { // Check if we already have the preset before we try loading it again. if(mParamList.find(name) != mParamList.end()) { if(propagate) { getParamSet(name, mCurParams); propagateParameters(); } return; } // bugfix for SL-46920: preventing filenames that break stuff. char * curl_str = curl_escape(name.c_str(), name.size()); std::string escaped_filename(curl_str); curl_free(curl_str); curl_str = NULL; escaped_filename += ".xml"; std::string pathName(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/skies", escaped_filename)); LL_DEBUGS2("AppInit", "Shaders") << "Loading WindLight sky setting from " << pathName << LL_ENDL; llifstream presetsXML; presetsXML.open(pathName.c_str()); // That failed, try loading from the users area instead. if(!presetsXML) { pathName=gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/skies", escaped_filename); LL_DEBUGS2("AppInit", "Shaders")<< "Loading User WindLight sky setting from " << LL_ENDL; presetsXML.open(pathName.c_str()); } if (presetsXML) { loadPresetXML(name, presetsXML); presetsXML.close(); } else { llwarns << "Can't find " << name << llendl; return; } if(propagate) { getParamSet(name, mCurParams); propagateParameters(); } notifyObservers(); }
void LLWLParamManager::savePreset(const std::string & name) { // bugfix for SL-46920: preventing filenames that break stuff. char * curl_str = curl_escape(name.c_str(), name.size()); std::string escaped_filename(curl_str); curl_free(curl_str); curl_str = NULL; escaped_filename += ".xml"; // make an empty llsd LLSD paramsData(LLSD::emptyMap()); std::string pathName(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/skies", escaped_filename)); // fill it with LLSD windlight params paramsData = mParamList[name].getAll(); // write to file llofstream presetsXML(pathName); LLPointer<LLSDFormatter> formatter = new LLSDXMLFormatter(); formatter->format(paramsData, presetsXML, LLSDFormatter::OPTIONS_PRETTY); presetsXML.close(); propagateParameters(); notifyObservers(); }
void LLWaterParamManager::update(LLViewerCamera * cam) { LLFastTimer ftm(LLFastTimer::FTM_UPDATE_WLPARAM); // update the shaders and the menu propagateParameters(); // sync menus if they exist if(LLFloaterWater::isOpen()) { LLFloaterWater::instance()->syncMenu(); } // only do this if we're dealing with shaders if(gPipeline.canUseVertexShaders()) { //transform water plane to eye space glh::vec3f norm(0.f, 0.f, 1.f); glh::vec3f p(0.f, 0.f, gAgent.getRegion()->getWaterHeight()+0.1f); F32 modelView[16]; for (U32 i = 0; i < 16; i++) { modelView[i] = (F32) gGLModelView[i]; } glh::matrix4f mat(modelView); glh::matrix4f invtrans = mat.inverse().transpose(); glh::vec3f enorm; glh::vec3f ep; invtrans.mult_matrix_vec(norm, enorm); enorm.normalize(); mat.mult_matrix_vec(p, ep); mWaterPlane = LLVector4(enorm.v[0], enorm.v[1], enorm.v[2], -ep.dot(enorm)); LLVector3 sunMoonDir; if (gSky.getSunDirection().mV[2] > NIGHTTIME_ELEVATION_COS) { sunMoonDir = gSky.getSunDirection(); } else { sunMoonDir = gSky.getMoonDirection(); } sunMoonDir.normVec(); mWaterFogKS = 1.f/llmax(sunMoonDir.mV[2], WATER_FOG_LIGHT_CLAMP); LLViewerShaderMgr::shader_iter shaders_iter, end_shaders; end_shaders = LLViewerShaderMgr::instance()->endShaders(); for(shaders_iter = LLViewerShaderMgr::instance()->beginShaders(); shaders_iter != end_shaders; ++shaders_iter) { if (shaders_iter->mProgramObject != 0 && shaders_iter->mShaderGroup == LLGLSLShader::SG_WATER) { shaders_iter->mUniformsDirty = TRUE; } } } }
void LLWLParamManager::savePresets(const std::string & fileName) { //Nobody currently calls me, but if they did, then its reasonable to write the data out to the user's folder //and not over the RO system wide version. LLSD paramsData(LLSD::emptyMap()); std::string pathName(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight", fileName)); for(std::map<std::string, LLWLParamSet>::iterator mIt = mParamList.begin(); mIt != mParamList.end(); ++mIt) { paramsData[mIt->first] = mIt->second.getAll(); } llofstream presetsXML(pathName); LLPointer<LLSDFormatter> formatter = new LLSDXMLFormatter(); formatter->format(paramsData, presetsXML, LLSDFormatter::OPTIONS_PRETTY); presetsXML.close(); propagateParameters(); }
void LLWLParamManager::loadPreset(const std::string & name,bool propagate) { // bugfix for SL-46920: preventing filenames that break stuff. char * curl_str = curl_escape(name.c_str(), name.size()); std::string escaped_filename(curl_str); curl_free(curl_str); curl_str = NULL; escaped_filename += ".xml"; std::string pathName(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/skies", escaped_filename)); LL_DEBUGS2("AppInit", "Shaders") << "Loading WindLight sky setting from " << pathName << LL_ENDL; llifstream presetsXML; presetsXML.open(pathName.c_str()); // That failed, try loading from the users area instead. if(!presetsXML) { pathName=gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/skies", escaped_filename); LL_DEBUGS2("AppInit", "Shaders")<< "Loading User WindLight sky setting from " << LL_ENDL; presetsXML.open(pathName.c_str()); } if (presetsXML) { LLSD paramsData(LLSD::emptyMap()); LLPointer<LLSDParser> parser = new LLSDXMLParser(); parser->parse(presetsXML, paramsData, LLSDSerialize::SIZE_UNLIMITED); std::map<std::string, LLWLParamSet>::iterator mIt = mParamList.find(name); if(mIt == mParamList.end()) { addParamSet(name, paramsData); } else { setParamSet(name, paramsData); } presetsXML.close(); } else { llwarns << "Can't find " << name << llendl; return; } if(propagate) { getParamSet(name, mCurParams); propagateParameters(); } notifyObservers(); }
void LLWLParamManager::update(LLViewerCamera * cam) { LLFastTimer ftm(LLFastTimer::FTM_UPDATE_WLPARAM); // update clouds, sun, and general mCurParams.updateCloudScrolling(); // update only if running if(mAnimator.mIsRunning) { mAnimator.update(mCurParams); } // update the shaders and the menu propagateParameters(); // sync menus if they exist if(LLFloaterWindLight::isOpen()) { LLFloaterWindLight::instance()->syncMenu(); } if(LLFloaterDayCycle::isOpen()) { LLFloaterDayCycle::instance()->syncMenu(); } if(LLFloaterEnvSettings::isOpen()) { LLFloaterEnvSettings::instance()->syncMenu(); } F32 camYaw = cam->getYaw(); stop_glerror(); // *TODO: potential optimization - this block may only need to be // executed some of the time. For example for water shaders only. { F32 camYawDelta = mSunDeltaYaw * DEG_TO_RAD; LLVector3 lightNorm3(mLightDir); lightNorm3 *= LLQuaternion(-(camYaw + camYawDelta), LLVector3(0.f, 1.f, 0.f)); mRotatedLightDir = LLVector4(lightNorm3, 0.f); LLViewerShaderMgr::shader_iter shaders_iter, end_shaders; end_shaders = LLViewerShaderMgr::instance()->endShaders(); for(shaders_iter = LLViewerShaderMgr::instance()->beginShaders(); shaders_iter != end_shaders; ++shaders_iter) { if (shaders_iter->mProgramObject != 0 && (gPipeline.canUseWindLightShaders() || shaders_iter->mShaderGroup == LLGLSLShader::SG_WATER)) { shaders_iter->mUniformsDirty = TRUE; } } } }
bool LLWLParamManager::savePresetToNotecard(const std::string & name) { // make an empty llsd LLSD paramsData(LLSD::emptyMap()); // fill it with LLSD windlight params paramsData = mParamList[name].getAll(); // get some XML std::ostringstream presetsXML; LLPointer<LLSDFormatter> formatter = new LLSDXMLFormatter(); formatter->format(paramsData, presetsXML, LLSDFormatter::OPTIONS_PRETTY); // Write it to a notecard LLNotecard notecard; notecard.setText(presetsXML.str()); LLInventoryItem *item = gInventory.getItem(mParamList[name].mInventoryID); if(!item) { mParamList[name].mInventoryID = LLUUID::null; return false; } std::string agent_url = gAgent.getRegion()->getCapability("UpdateNotecardAgentInventory"); if(!agent_url.empty()) { LLTransactionID tid; LLAssetID asset_id; tid.generate(); asset_id = tid.makeAssetID(gAgent.getSecureSessionID()); LLVFile file(gVFS, asset_id, LLAssetType::AT_NOTECARD, LLVFile::APPEND); std::ostringstream stream; notecard.exportStream(stream); std::string buffer = stream.str(); S32 size = buffer.length() + 1; file.setMaxSize(size); file.write((U8*)buffer.c_str(), size); LLSD body; body["item_id"] = item->getUUID(); LLHTTPClient::post(agent_url, body, new LLUpdateAgentInventoryResponder(body, asset_id, LLAssetType::AT_NOTECARD)); } else { LL_WARNS("WindLight") << "Stuff the legacy system." << LL_ENDL; return false; } propagateParameters(); return true; }
void LLWaterParamManager::loadPreset(const std::string & name,bool propagate) { // bugfix for SL-46920: preventing filenames that break stuff. std::string escaped_filename = LLWeb::curlEscape(name); escaped_filename += ".xml"; std::string pathName(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/water", escaped_filename)); llinfos << "Loading water settings from " << pathName << llendl; std::ifstream presetsXML; presetsXML.open(pathName.c_str()); // That failed, try loading from the users area instead. if(!presetsXML) { pathName=gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/water", escaped_filename); llinfos << "Loading User water setting from " << pathName << llendl; presetsXML.open(pathName.c_str()); } if (presetsXML) { LLSD paramsData(LLSD::emptyMap()); LLPointer<LLSDParser> parser = new LLSDXMLParser(); parser->parse(presetsXML, paramsData, LLSDSerialize::SIZE_UNLIMITED); std::map<std::string, LLWaterParamSet>::iterator mIt = mParamList.find(name); if(mIt == mParamList.end()) { addParamSet(name, paramsData); } else { setParamSet(name, paramsData); } presetsXML.close(); } else { llwarns << "Can't find " << name << llendl; return; } if(propagate) { getParamSet(name, mCurParams); propagateParameters(); } }
void LLWLParamManager::update(LLViewerCamera * cam) { LLFastTimer ftm(FTM_UPDATE_WLPARAM); // update clouds, sun, and general mCurParams.updateCloudScrolling(); // update only if running if(mAnimator.getIsRunning()) { mAnimator.update(mCurParams); } // update the shaders and the menu propagateParameters(); // sync menus if they exist if(LLFloaterWindLight::isOpen()) { LLFloaterWindLight::instance()->syncMenu(); } if(LLFloaterDayCycle::isOpen()) { LLFloaterDayCycle::instance()->syncMenu(); } if(LLFloaterEnvSettings::isOpen()) { LLFloaterEnvSettings::instance()->syncMenu(); } F32 camYaw = cam->getYaw(); stop_glerror(); // *TODO: potential optimization - this block may only need to be // executed some of the time. For example for water shaders only. { F32 camYawDelta = mSunDeltaYaw * DEG_TO_RAD; LLVector3 lightNorm3(mLightDir); lightNorm3 *= LLQuaternion(-(camYaw + camYawDelta), LLVector3(0.f, 1.f, 0.f)); mRotatedLightDir = LLVector4(lightNorm3, 0.f); std::vector<LLGLSLShader*>::iterator shaders_iter=mShaderList.begin(); for(; shaders_iter != mShaderList.end(); ++shaders_iter) { (*shaders_iter)->mUniformsDirty = TRUE; } } }
void LLWLParamManager::savePreset(LLWLParamKey key) { llassert(key.scope == LLEnvKey::SCOPE_LOCAL && !key.name.empty()); // make an empty llsd LLSD paramsData(LLSD::emptyMap()); std::string pathName(getUserDir() + LLWeb::curlEscape(key.name) + ".xml"); // fill it with LLSD windlight params paramsData = mParamList[key].getAll(); // write to file llofstream presetsXML(pathName); LLPointer<LLSDFormatter> formatter = new LLSDXMLFormatter(); formatter->format(paramsData, presetsXML, LLSDFormatter::OPTIONS_PRETTY); presetsXML.close(); propagateParameters(); }
void LLWaterParamManager::savePreset(const std::string & name) { llassert(!name.empty()); // make an empty llsd LLSD paramsData(LLSD::emptyMap()); std::string pathName(getUserDir() + LLURI::escape(name) + ".xml"); // fill it with LLSD windlight params paramsData = mParamList[name].getAll(); // write to file llofstream presetsXML(pathName.c_str()); LLPointer<LLSDFormatter> formatter = new LLSDXMLFormatter(); formatter->format(paramsData, presetsXML, LLSDFormatter::OPTIONS_PRETTY); presetsXML.close(); propagateParameters(); }
void LLWaterParamManager::savePreset(const std::string & name) { std::string escaped_filename = LLCurl::escapeSafe(name); escaped_filename += ".xml"; // make an empty llsd LLSD paramsData(LLSD::emptyMap()); std::string pathName(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/water", escaped_filename)); // fill it with LLSD windlight params paramsData = mParamList[name].getAll(); // write to file llofstream presetsXML(pathName); LLPointer<LLSDFormatter> formatter = new LLSDXMLFormatter(); formatter->format(paramsData, presetsXML, LLSDFormatter::OPTIONS_PRETTY); presetsXML.close(); propagateParameters(); }
bool LLWLParamManager::loadPresetXML(const std::string& name, std::istream& preset_stream, bool propagate /* = false */, bool check_if_real /* = false */) { LLSD paramsData(LLSD::emptyMap()); LLPointer<LLSDParser> parser = new LLSDXMLParser(); if(parser->parse(preset_stream, paramsData, LLSDSerialize::SIZE_UNLIMITED) == LLSDParser::PARSE_FAILURE) { return false; } if(check_if_real) { static const char* expected_windlight_settings[] = { "ambient", "blue_density", "blue_horizon", "cloud_color", "cloud_pos_density1", "cloud_pos_density2", "cloud_scale", "cloud_scroll_rate", "cloud_shadow", "density_multiplier", "distance_multiplier", "east_angle", "enable_cloud_scroll", "gamma", "glow", "haze_density", "haze_horizon", "lightnorm", "max_y", "star_brightness", "sun_angle", "sunlight_color" }; static S32 expected_count = LL_ARRAY_SIZE(expected_windlight_settings); for(S32 i = 0; i < expected_count; ++i) { if(!paramsData.has(expected_windlight_settings[i])) { LL_WARNS("WindLight") << "Attempted to load WindLight param set without " << expected_windlight_settings[i] << LL_ENDL; return false; } } } std::map<std::string, LLWLParamSet>::iterator mIt = mParamList.find(name); if(mIt == mParamList.end()) { addParamSet(name, paramsData); } else { setParamSet(name, paramsData); } if(propagate) { getParamSet(name, mCurParams); propagateParameters(); } return true; }
void LLWaterParamManager::update(LLViewerCamera * cam) { LLFastTimer ftm(LLFastTimer::FTM_UPDATE_WLPARAM); // update the shaders and the menu propagateParameters(); // sync menus if they exist if(LLFloaterWater::isOpen()) { LLFloaterWater::instance()->syncMenu(); } stop_glerror(); // only do this if we're dealing with shaders if(gPipeline.canUseVertexShaders()) { //transform water plane to eye space glh::vec3f norm(0.f, 0.f, 1.f); glh::vec3f p(0.f, 0.f, gAgent.getRegion()->getWaterHeight()+0.1f); F32 modelView[16]; for (U32 i = 0; i < 16; i++) { modelView[i] = (F32) gGLModelView[i]; } glh::matrix4f mat(modelView); glh::matrix4f invtrans = mat.inverse().transpose(); glh::vec3f enorm; glh::vec3f ep; invtrans.mult_matrix_vec(norm, enorm); enorm.normalize(); mat.mult_matrix_vec(p, ep); mWaterPlane = LLVector4(enorm.v[0], enorm.v[1], enorm.v[2], -ep.dot(enorm)); if((mWaterPlane.mV[3] >= 0.f) == LLViewerCamera::getInstance()->cameraUnderWater()) //Sign borkage.. { mWaterPlane.scaleVec(LLVector4(-1.f,-1.f,-1.f,-1.f)); } LLVector3 sunMoonDir; if (gSky.getSunDirection().mV[2] > LLSky::NIGHTTIME_ELEVATION_COS) { sunMoonDir = gSky.getSunDirection(); } else { sunMoonDir = gSky.getMoonDirection(); } sunMoonDir.normVec(); mWaterFogKS = 1.f/llmax(sunMoonDir.mV[2], WATER_FOG_LIGHT_CLAMP); std::vector<LLGLSLShader*>::iterator shaders_iter=mShaderList.begin(); for(; shaders_iter != mShaderList.end(); ++shaders_iter) { (*shaders_iter)->mUniformsDirty = TRUE; } } }
void LLWLParamManager::update(LLViewerCamera * cam) { LLFastTimer ftm(LLFastTimer::FTM_UPDATE_WLPARAM); // update clouds, sun, and general mCurParams.updateCloudScrolling(); // update only if running if(mAnimator.mIsRunning) { mAnimator.update(mCurParams); } // update the shaders and the menu propagateParameters(); // sync menus if they exist if(LLFloaterWindLight::isOpen()) { LLFloaterWindLight::instance()->syncMenu(); } if(LLFloaterDayCycle::isOpen()) { LLFloaterDayCycle::instance()->syncMenu(); } if(LLFloaterEnvSettings::isOpen()) { LLFloaterEnvSettings::instance()->syncMenu(); } F32 camYaw = cam->getYaw(); stop_glerror(); // *TODO: potential optimization - this block may only need to be // executed some of the time. For example for water shaders only. { F32 camYawDelta = mSunDeltaYaw * DEG_TO_RAD; LLVector3 lightNorm3(mLightDir); lightNorm3 *= LLQuaternion(-(camYaw + camYawDelta), LLVector3(0.f, 1.f, 0.f)); mRotatedLightDir = LLVector4(lightNorm3, 0.f); LLViewerShaderMgr::shader_iter shaders_iter, end_shaders; end_shaders = LLViewerShaderMgr::instance()->endShaders(); for(shaders_iter = LLViewerShaderMgr::instance()->beginShaders(); shaders_iter != end_shaders; ++shaders_iter) { if (shaders_iter->mProgramObject != 0 && (gPipeline.canUseWindLightShaders() || shaders_iter->mShaderGroup == LLGLSLShader::SG_WATER)) { shaders_iter->mUniformsDirty = TRUE; } } } //Mix windlight settings if needed if(sNeedsMix == TRUE) { if(sMixSet == NULL) { sNeedsMix = FALSE; return; } if (wlSmoothTransitionTimer.getElapsedTimeF32() >= (sMixTime / 100)) //100 steps inbetween { wlSmoothTransitionTimer.reset(); mCurParams.mix(mCurParams, *sMixSet, sMixCount / 100);//.01 to 1.0 } sMixCount++; if((sMixCount / 100) == 1) { //All done sNeedsMix = FALSE; std::string wlSkyPresetName = "(Region settings)"; mCurParams.mName = wlSkyPresetName; removeParamSet( wlSkyPresetName, true ); addParamSet( wlSkyPresetName, mCurParams ); savePreset( wlSkyPresetName ); mAnimator.mIsRunning = false; mAnimator.mUseLindenTime = false; loadPreset( wlSkyPresetName, true ); sMixSet = NULL; } } }