backend changes, terrain num lights setting

actorid
scrawl 13 years ago
parent f4bbcb48a6
commit 7b3adb27a3

@ -426,6 +426,9 @@ void OMW::Engine::go()
// Start the main rendering loop
mOgre->start();
// Save user settings
settings.saveUser(settingspath);
std::cout << "Quitting peacefully.\n";
}

@ -36,7 +36,7 @@ THE SOFTWARE.
#include "OgreHardwarePixelBuffer.h"
#include "OgreShadowCameraSetupPSSM.h"
#define POINTLIGHTS
#include <components/settings/settings.hpp>
namespace Ogre
{
@ -220,22 +220,10 @@ namespace Ogre
}
int TerrainMaterialGeneratorB::SM2Profile::getNumberOfLightsSupported() const
{
#ifndef POINTLIGHTS
return 1;
#else
// number of supported lights depends on the number of available constant registers,
// which in turn depends on the shader profile used
if (GpuProgramManager::getSingleton().isSyntaxSupported("ps_3_0")
|| GpuProgramManager::getSingleton().isSyntaxSupported("ps_4_0")
|| GpuProgramManager::getSingleton().isSyntaxSupported("fp40")
)
return 32;
else
return 8;
#endif
}
int TerrainMaterialGeneratorB::SM2Profile::getNumberOfLightsSupported() const
{
return Settings::Manager::getInt("num lights", "Terrain");
}
//---------------------------------------------------------------------
MaterialPtr TerrainMaterialGeneratorB::SM2Profile::generate(const Terrain* terrain)
{
@ -565,7 +553,8 @@ namespace Ogre
{
params->setNamedAutoConstant("lightPosObjSpace"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_POSITION_OBJECT_SPACE, i);
params->setNamedAutoConstant("lightDiffuseColour"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_DIFFUSE_COLOUR, i);
params->setNamedAutoConstant("lightAttenuation"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_ATTENUATION, i);
if (prof->getNumberOfLightsSupported() > 1)
params->setNamedAutoConstant("lightAttenuation"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_ATTENUATION, i);
//params->setNamedAutoConstant("lightSpecularColour"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_SPECULAR_COLOUR, i);
}
@ -980,10 +969,9 @@ namespace Ogre
//"uniform float3 lightSpecularColour"<<i<<",\n"
;
#ifdef POINTLIGHTS
outStream <<
"uniform float4 lightAttenuation"<<i<<",\n";
#endif
if (prof->getNumberOfLightsSupported() > 1)
outStream <<
"uniform float4 lightAttenuation"<<i<<",\n";
}
@ -1130,10 +1118,9 @@ namespace Ogre
}
else
{
#ifdef POINTLIGHTS
outStream << "float d; \n"
if (prof->getNumberOfLightsSupported() > 1)
outStream << "float d; \n"
"float attn; \n";
#endif
outStream <<
" eyeDir = normalize(eyeDir); \n";
@ -1144,13 +1131,12 @@ namespace Ogre
outStream << " float3 halfAngle"<<i<<" = normalize(lightDir"<<i<<" + eyeDir);\n"
" float4 litRes"<<i<<" = lit(dot(normalize(lightDir"<<i<<"), normal), dot(halfAngle"<<i<<", normal), scaleBiasSpecular.z);\n";
#ifdef POINTLIGHTS
if (prof->getNumberOfLightsSupported() > 1)
outStream <<
// pre-multiply light color with attenuation factor
"d = length( lightDir"<<i<<" ); \n"
"attn = ( 1.0 / (( lightAttenuation"<<i<<".y ) + ( lightAttenuation"<<i<<".z * d ) + ( lightAttenuation"<<i<<".w * d * d ))); \n"
"lightDiffuseColour"<<i<<" *= attn; \n";
#endif
}
}
}

@ -9,7 +9,8 @@ using namespace Settings;
Ogre::ConfigFile Manager::mFile = Ogre::ConfigFile();
Ogre::ConfigFile Manager::mDefaultFile = Ogre::ConfigFile();
SettingCategoryVector Manager::mChangedSettings = SettingCategoryVector();
CategorySettingVector Manager::mChangedSettings = CategorySettingVector();
CategorySettingValueMap Manager::mNewSettings = CategorySettingValueMap();
void Manager::loadUser (const std::string& file)
{
@ -43,15 +44,40 @@ void Manager::saveUser(const std::string& file)
Ogre::ConfigFile::SettingsMultiMap::iterator i;
for (i = settings->begin(); i != settings->end(); ++i)
{
fout << i->first.c_str() << '=' << i->second.c_str() << '\n';
fout << i->first.c_str() << " = " << i->second.c_str() << '\n';
}
seci.getNext();
CategorySettingValueMap::iterator it = mNewSettings.begin();
while (it != mNewSettings.end())
{
if (it->first.first == sectionName)
{
fout << it->first.second << " = " << it->second << '\n';
mNewSettings.erase(it++);
}
else
++it;
}
}
std::string category = "";
for (CategorySettingValueMap::iterator it = mNewSettings.begin();
it != mNewSettings.end(); ++it)
{
if (category != it->first.first)
{
category = it->first.first;
fout << '\n' << '[' << category << ']' << '\n';
}
fout << it->first.second << " = " << it->second << '\n';
}
}
const std::string Manager::getString (const std::string& setting, const std::string& category)
{
if (mNewSettings.find(std::make_pair(category, setting)) != mNewSettings.end())
return mNewSettings[std::make_pair(category, setting)];
std::string defaultval = mDefaultFile.getSetting(setting, category);
return mFile.getSetting(setting, category, defaultval);
}
@ -73,22 +99,45 @@ const bool Manager::getBool (const std::string& setting, const std::string& cate
void Manager::setString (const std::string& setting, const std::string& category, const std::string& value)
{
CategorySetting s = std::make_pair(category, setting);
bool found=false;
Ogre::ConfigFile::SettingsIterator it = mFile.getSettingsIterator(category);
while (it.hasMoreElements())
try
{
Ogre::ConfigFile::SettingsMultiMap::iterator i = it.current();
if ((*i).first == setting && (*i).second != value)
Ogre::ConfigFile::SettingsIterator it = mFile.getSettingsIterator(category);
while (it.hasMoreElements())
{
mChangedSettings.push_back(std::make_pair(setting, category));
(*i).second = value;
found = true;
Ogre::ConfigFile::SettingsMultiMap::iterator i = it.current();
if ((*i).first == setting)
{
if ((*i).second != value)
{
mChangedSettings.push_back(std::make_pair(category, setting));
(*i).second = value;
}
found = true;
}
it.getNext();
}
}
catch (Ogre::Exception&)
{}
it.getNext();
if (!found)
{
if (mNewSettings.find(s) != mNewSettings.end())
{
if (mNewSettings[s] != value)
{
mChangedSettings.push_back(std::make_pair(category, setting));
mNewSettings[s] = value;
}
}
else
mNewSettings[s] = value;
}
assert(found && "Attempting to change a non-existing setting");
}
void Manager::setInt (const std::string& setting, const std::string& category, const int value)
@ -106,9 +155,9 @@ void Manager::setBool (const std::string& setting, const std::string& category,
setString(setting, category, Ogre::StringConverter::toString(value));
}
const SettingCategoryVector Manager::apply()
const CategorySettingVector Manager::apply()
{
SettingCategoryVector vec = mChangedSettings;
CategorySettingVector vec = mChangedSettings;
mChangedSettings.clear();
return vec;
}

@ -5,7 +5,9 @@
namespace Settings
{
typedef std::vector< std::pair<std::string, std::string> > SettingCategoryVector;
typedef std::pair < std::string, std::string > CategorySetting;
typedef std::vector< std::pair<std::string, std::string> > CategorySettingVector;
typedef std::map < CategorySetting, std::string > CategorySettingValueMap;
///
/// \brief Settings management (can change during runtime)
@ -16,9 +18,12 @@ namespace Settings
static Ogre::ConfigFile mFile;
static Ogre::ConfigFile mDefaultFile;
static SettingCategoryVector mChangedSettings;
static CategorySettingVector mChangedSettings;
///< tracks all the settings that were changed since the last apply() call
static CategorySettingValueMap mNewSettings;
///< tracks all the settings that are in the default file, but not in user file yet
void loadDefault (const std::string& file);
///< load file as the default settings (can be overridden by user settings)
@ -31,7 +36,7 @@ namespace Settings
void saveUser (const std::string& file);
///< save user settings to file
const SettingCategoryVector apply();
static const CategorySettingVector apply();
///< returns the list of changed settings and then clears it
static const int getInt (const std::string& setting, const std::string& category);

@ -1,3 +1,6 @@
[Objects]
shaders = true
num lights = 8
[Terrain]
num lights = 8

Loading…
Cancel
Save