forked from teamnwah/openmw-tes3coop
backend changes, terrain num lights setting
This commit is contained in:
parent
f4bbcb48a6
commit
7b3adb27a3
5 changed files with 92 additions and 46 deletions
|
@ -426,6 +426,9 @@ void OMW::Engine::go()
|
||||||
// Start the main rendering loop
|
// Start the main rendering loop
|
||||||
mOgre->start();
|
mOgre->start();
|
||||||
|
|
||||||
|
// Save user settings
|
||||||
|
settings.saveUser(settingspath);
|
||||||
|
|
||||||
std::cout << "Quitting peacefully.\n";
|
std::cout << "Quitting peacefully.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ THE SOFTWARE.
|
||||||
#include "OgreHardwarePixelBuffer.h"
|
#include "OgreHardwarePixelBuffer.h"
|
||||||
#include "OgreShadowCameraSetupPSSM.h"
|
#include "OgreShadowCameraSetupPSSM.h"
|
||||||
|
|
||||||
#define POINTLIGHTS
|
#include <components/settings/settings.hpp>
|
||||||
|
|
||||||
namespace Ogre
|
namespace Ogre
|
||||||
{
|
{
|
||||||
|
@ -220,22 +220,10 @@ namespace Ogre
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
int TerrainMaterialGeneratorB::SM2Profile::getNumberOfLightsSupported() const
|
int TerrainMaterialGeneratorB::SM2Profile::getNumberOfLightsSupported() const
|
||||||
{
|
{
|
||||||
#ifndef POINTLIGHTS
|
return Settings::Manager::getInt("num lights", "Terrain");
|
||||||
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
|
|
||||||
}
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
MaterialPtr TerrainMaterialGeneratorB::SM2Profile::generate(const Terrain* 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("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("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);
|
//params->setNamedAutoConstant("lightSpecularColour"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_SPECULAR_COLOUR, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -980,10 +969,9 @@ namespace Ogre
|
||||||
//"uniform float3 lightSpecularColour"<<i<<",\n"
|
//"uniform float3 lightSpecularColour"<<i<<",\n"
|
||||||
;
|
;
|
||||||
|
|
||||||
#ifdef POINTLIGHTS
|
if (prof->getNumberOfLightsSupported() > 1)
|
||||||
outStream <<
|
outStream <<
|
||||||
"uniform float4 lightAttenuation"<<i<<",\n";
|
"uniform float4 lightAttenuation"<<i<<",\n";
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1130,10 +1118,9 @@ namespace Ogre
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef POINTLIGHTS
|
if (prof->getNumberOfLightsSupported() > 1)
|
||||||
outStream << "float d; \n"
|
outStream << "float d; \n"
|
||||||
"float attn; \n";
|
"float attn; \n";
|
||||||
#endif
|
|
||||||
|
|
||||||
outStream <<
|
outStream <<
|
||||||
" eyeDir = normalize(eyeDir); \n";
|
" eyeDir = normalize(eyeDir); \n";
|
||||||
|
@ -1144,13 +1131,12 @@ namespace Ogre
|
||||||
outStream << " float3 halfAngle"<<i<<" = normalize(lightDir"<<i<<" + eyeDir);\n"
|
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";
|
" float4 litRes"<<i<<" = lit(dot(normalize(lightDir"<<i<<"), normal), dot(halfAngle"<<i<<", normal), scaleBiasSpecular.z);\n";
|
||||||
|
|
||||||
#ifdef POINTLIGHTS
|
if (prof->getNumberOfLightsSupported() > 1)
|
||||||
outStream <<
|
outStream <<
|
||||||
// pre-multiply light color with attenuation factor
|
// pre-multiply light color with attenuation factor
|
||||||
"d = length( lightDir"<<i<<" ); \n"
|
"d = length( lightDir"<<i<<" ); \n"
|
||||||
"attn = ( 1.0 / (( lightAttenuation"<<i<<".y ) + ( lightAttenuation"<<i<<".z * d ) + ( lightAttenuation"<<i<<".w * d * d ))); \n"
|
"attn = ( 1.0 / (( lightAttenuation"<<i<<".y ) + ( lightAttenuation"<<i<<".z * d ) + ( lightAttenuation"<<i<<".w * d * d ))); \n"
|
||||||
"lightDiffuseColour"<<i<<" *= attn; \n";
|
"lightDiffuseColour"<<i<<" *= attn; \n";
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,8 @@ using namespace Settings;
|
||||||
|
|
||||||
Ogre::ConfigFile Manager::mFile = Ogre::ConfigFile();
|
Ogre::ConfigFile Manager::mFile = Ogre::ConfigFile();
|
||||||
Ogre::ConfigFile Manager::mDefaultFile = 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)
|
void Manager::loadUser (const std::string& file)
|
||||||
{
|
{
|
||||||
|
@ -43,15 +44,40 @@ void Manager::saveUser(const std::string& file)
|
||||||
Ogre::ConfigFile::SettingsMultiMap::iterator i;
|
Ogre::ConfigFile::SettingsMultiMap::iterator i;
|
||||||
for (i = settings->begin(); i != settings->end(); ++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)
|
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);
|
std::string defaultval = mDefaultFile.getSetting(setting, category);
|
||||||
return mFile.getSetting(setting, category, defaultval);
|
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)
|
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;
|
bool found=false;
|
||||||
Ogre::ConfigFile::SettingsIterator it = mFile.getSettingsIterator(category);
|
try
|
||||||
while (it.hasMoreElements())
|
|
||||||
{
|
{
|
||||||
Ogre::ConfigFile::SettingsMultiMap::iterator i = it.current();
|
Ogre::ConfigFile::SettingsIterator it = mFile.getSettingsIterator(category);
|
||||||
|
while (it.hasMoreElements())
|
||||||
if ((*i).first == setting && (*i).second != value)
|
|
||||||
{
|
{
|
||||||
mChangedSettings.push_back(std::make_pair(setting, category));
|
Ogre::ConfigFile::SettingsMultiMap::iterator i = it.current();
|
||||||
(*i).second = value;
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
it.getNext();
|
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&)
|
||||||
|
{}
|
||||||
|
|
||||||
|
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)
|
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));
|
setString(setting, category, Ogre::StringConverter::toString(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
const SettingCategoryVector Manager::apply()
|
const CategorySettingVector Manager::apply()
|
||||||
{
|
{
|
||||||
SettingCategoryVector vec = mChangedSettings;
|
CategorySettingVector vec = mChangedSettings;
|
||||||
mChangedSettings.clear();
|
mChangedSettings.clear();
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,9 @@
|
||||||
|
|
||||||
namespace Settings
|
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)
|
/// \brief Settings management (can change during runtime)
|
||||||
|
@ -16,9 +18,12 @@ namespace Settings
|
||||||
static Ogre::ConfigFile mFile;
|
static Ogre::ConfigFile mFile;
|
||||||
static Ogre::ConfigFile mDefaultFile;
|
static Ogre::ConfigFile mDefaultFile;
|
||||||
|
|
||||||
static SettingCategoryVector mChangedSettings;
|
static CategorySettingVector mChangedSettings;
|
||||||
///< tracks all the settings that were changed since the last apply() call
|
///< 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);
|
void loadDefault (const std::string& file);
|
||||||
///< load file as the default settings (can be overridden by user settings)
|
///< load file as the default settings (can be overridden by user settings)
|
||||||
|
|
||||||
|
@ -31,7 +36,7 @@ namespace Settings
|
||||||
void saveUser (const std::string& file);
|
void saveUser (const std::string& file);
|
||||||
///< save user settings to file
|
///< save user settings to file
|
||||||
|
|
||||||
const SettingCategoryVector apply();
|
static const CategorySettingVector apply();
|
||||||
///< returns the list of changed settings and then clears it
|
///< returns the list of changed settings and then clears it
|
||||||
|
|
||||||
static const int getInt (const std::string& setting, const std::string& category);
|
static const int getInt (const std::string& setting, const std::string& category);
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
[Objects]
|
[Objects]
|
||||||
shaders = true
|
shaders = true
|
||||||
num lights = 8
|
num lights = 8
|
||||||
|
|
||||||
|
[Terrain]
|
||||||
|
num lights = 8
|
||||||
|
|
Loading…
Reference in a new issue