mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 08:53:52 +00:00
Merge branch 'recalculate-projection-matrix-on-window-resize' into 'master'
Recalculate the Projection Matrix every time the window is resized. See merge request OpenMW/openmw!1382
This commit is contained in:
commit
e221013692
7 changed files with 72 additions and 33 deletions
|
@ -1098,12 +1098,21 @@ namespace MWGui
|
||||||
|
|
||||||
void WindowManager::windowResized(int x, int y)
|
void WindowManager::windowResized(int x, int y)
|
||||||
{
|
{
|
||||||
// Note: this is a side effect of resolution change or window resize.
|
|
||||||
// There is no need to track these changes.
|
|
||||||
Settings::Manager::setInt("resolution x", "Video", x);
|
Settings::Manager::setInt("resolution x", "Video", x);
|
||||||
Settings::Manager::setInt("resolution y", "Video", y);
|
Settings::Manager::setInt("resolution y", "Video", y);
|
||||||
Settings::Manager::resetPendingChange("resolution x", "Video");
|
|
||||||
Settings::Manager::resetPendingChange("resolution y", "Video");
|
// We only want to process changes to window-size related settings.
|
||||||
|
Settings::CategorySettingVector filter = {{"Video", "resolution x"},
|
||||||
|
{"Video", "resolution y"}};
|
||||||
|
|
||||||
|
// If the HUD has not been initialised, the World singleton will not be available.
|
||||||
|
if (mHud)
|
||||||
|
{
|
||||||
|
MWBase::Environment::get().getWorld()->processChangedSettings(
|
||||||
|
Settings::Manager::getPendingChanges(filter));
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings::Manager::resetPendingChanges(filter);
|
||||||
|
|
||||||
mGuiPlatform->getRenderManagerPtr()->setViewSize(x, y);
|
mGuiPlatform->getRenderManagerPtr()->setViewSize(x, y);
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
|
|
||||||
#include "vismask.hpp"
|
#include "vismask.hpp"
|
||||||
#include "renderingmanager.hpp"
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -132,11 +131,10 @@ namespace
|
||||||
|
|
||||||
namespace MWRender
|
namespace MWRender
|
||||||
{
|
{
|
||||||
PostProcessor::PostProcessor(RenderingManager& rendering, osgViewer::Viewer* viewer, osg::Group* rootNode)
|
PostProcessor::PostProcessor(osgViewer::Viewer* viewer, osg::Group* rootNode)
|
||||||
: mViewer(viewer)
|
: mViewer(viewer)
|
||||||
, mRootNode(new osg::Group)
|
, mRootNode(new osg::Group)
|
||||||
, mDepthFormat(GL_DEPTH_COMPONENT24)
|
, mDepthFormat(GL_DEPTH_COMPONENT24)
|
||||||
, mRendering(rendering)
|
|
||||||
{
|
{
|
||||||
bool softParticles = Settings::Manager::getBool("soft particles", "Shaders");
|
bool softParticles = Settings::Manager::getBool("soft particles", "Shaders");
|
||||||
|
|
||||||
|
@ -239,7 +237,6 @@ namespace MWRender
|
||||||
|
|
||||||
mViewer->getCamera()->resize(width, height);
|
mViewer->getCamera()->resize(width, height);
|
||||||
mHUDCamera->resize(width, height);
|
mHUDCamera->resize(width, height);
|
||||||
mRendering.updateProjectionMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PostProcessor::createTexturesAndCamera(int width, int height)
|
void PostProcessor::createTexturesAndCamera(int width, int height)
|
||||||
|
|
|
@ -14,12 +14,10 @@ namespace osgViewer
|
||||||
|
|
||||||
namespace MWRender
|
namespace MWRender
|
||||||
{
|
{
|
||||||
class RenderingManager;
|
|
||||||
|
|
||||||
class PostProcessor : public osg::Referenced
|
class PostProcessor : public osg::Referenced
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PostProcessor(RenderingManager& rendering, osgViewer::Viewer* viewer, osg::Group* rootNode);
|
PostProcessor(osgViewer::Viewer* viewer, osg::Group* rootNode);
|
||||||
|
|
||||||
auto getMsaaFbo() { return mMsaaFbo; }
|
auto getMsaaFbo() { return mMsaaFbo; }
|
||||||
auto getFbo() { return mFbo; }
|
auto getFbo() { return mFbo; }
|
||||||
|
@ -46,8 +44,6 @@ namespace MWRender
|
||||||
osg::ref_ptr<osg::Texture2D> mOpaqueDepthTex;
|
osg::ref_ptr<osg::Texture2D> mOpaqueDepthTex;
|
||||||
|
|
||||||
int mDepthFormat;
|
int mDepthFormat;
|
||||||
|
|
||||||
RenderingManager& mRendering;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -455,7 +455,7 @@ namespace MWRender
|
||||||
mSharedUniformStateUpdater = new SharedUniformStateUpdater(groundcover);
|
mSharedUniformStateUpdater = new SharedUniformStateUpdater(groundcover);
|
||||||
rootNode->addUpdateCallback(mSharedUniformStateUpdater);
|
rootNode->addUpdateCallback(mSharedUniformStateUpdater);
|
||||||
|
|
||||||
mPostProcessor = new PostProcessor(*this, viewer, mRootNode);
|
mPostProcessor = new PostProcessor(viewer, mRootNode);
|
||||||
resourceSystem->getSceneManager()->setDepthFormat(mPostProcessor->getDepthFormat());
|
resourceSystem->getSceneManager()->setDepthFormat(mPostProcessor->getDepthFormat());
|
||||||
resourceSystem->getSceneManager()->setOpaqueDepthTex(mPostProcessor->getOpaqueDepthTex());
|
resourceSystem->getSceneManager()->setOpaqueDepthTex(mPostProcessor->getOpaqueDepthTex());
|
||||||
|
|
||||||
|
@ -1209,19 +1209,26 @@ namespace MWRender
|
||||||
|
|
||||||
void RenderingManager::processChangedSettings(const Settings::CategorySettingVector &changed)
|
void RenderingManager::processChangedSettings(const Settings::CategorySettingVector &changed)
|
||||||
{
|
{
|
||||||
|
// Only perform a projection matrix update once if a relevant setting is changed.
|
||||||
|
bool updateProjection = false;
|
||||||
|
|
||||||
for (Settings::CategorySettingVector::const_iterator it = changed.begin(); it != changed.end(); ++it)
|
for (Settings::CategorySettingVector::const_iterator it = changed.begin(); it != changed.end(); ++it)
|
||||||
{
|
{
|
||||||
if (it->first == "Camera" && it->second == "field of view")
|
if (it->first == "Camera" && it->second == "field of view")
|
||||||
{
|
{
|
||||||
mFieldOfView = Settings::Manager::getFloat("field of view", "Camera");
|
mFieldOfView = Settings::Manager::getFloat("field of view", "Camera");
|
||||||
updateProjectionMatrix();
|
updateProjection = true;
|
||||||
|
}
|
||||||
|
else if (it->first == "Video" && (it->second == "resolution x" || it->second == "resolution y"))
|
||||||
|
{
|
||||||
|
updateProjection = true;
|
||||||
}
|
}
|
||||||
else if (it->first == "Camera" && it->second == "viewing distance")
|
else if (it->first == "Camera" && it->second == "viewing distance")
|
||||||
{
|
{
|
||||||
mViewDistance = Settings::Manager::getFloat("viewing distance", "Camera");
|
mViewDistance = Settings::Manager::getFloat("viewing distance", "Camera");
|
||||||
if(!Settings::Manager::getBool("use distant fog", "Fog"))
|
if(!Settings::Manager::getBool("use distant fog", "Fog"))
|
||||||
mStateUpdater->setFogEnd(mViewDistance);
|
mStateUpdater->setFogEnd(mViewDistance);
|
||||||
updateProjectionMatrix();
|
updateProjection = true;
|
||||||
}
|
}
|
||||||
else if (it->first == "General" && (it->second == "texture filter" ||
|
else if (it->first == "General" && (it->second == "texture filter" ||
|
||||||
it->second == "texture mipmap" ||
|
it->second == "texture mipmap" ||
|
||||||
|
@ -1264,6 +1271,11 @@ namespace MWRender
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (updateProjection)
|
||||||
|
{
|
||||||
|
updateProjectionMatrix();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float RenderingManager::getNearClipDistance() const
|
float RenderingManager::getNearClipDistance() const
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
namespace Settings
|
namespace Settings
|
||||||
{
|
{
|
||||||
using CategorySetting = std::pair<std::string, std::string>;
|
using CategorySetting = std::pair<std::string, std::string>;
|
||||||
using CategorySettingVector = std::set<std::pair<std::string, std::string>>;
|
using CategorySettingVector = std::set<CategorySetting>;
|
||||||
using CategorySettingValueMap = std::map<CategorySetting, std::string>;
|
using CategorySettingValueMap = std::map<CategorySetting, std::string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ void Manager::saveUser(const std::string &file)
|
||||||
|
|
||||||
std::string Manager::getString(const std::string &setting, const std::string &category)
|
std::string Manager::getString(const std::string &setting, const std::string &category)
|
||||||
{
|
{
|
||||||
CategorySettingValueMap::key_type key = std::make_pair(category, setting);
|
CategorySettingValueMap::key_type key (category, setting);
|
||||||
CategorySettingValueMap::iterator it = mUserSettings.find(key);
|
CategorySettingValueMap::iterator it = mUserSettings.find(key);
|
||||||
if (it != mUserSettings.end())
|
if (it != mUserSettings.end())
|
||||||
return it->second;
|
return it->second;
|
||||||
|
@ -93,7 +93,7 @@ osg::Vec2f Manager::getVector2 (const std::string& setting, const std::string& c
|
||||||
stream >> x >> y;
|
stream >> x >> y;
|
||||||
if (stream.fail())
|
if (stream.fail())
|
||||||
throw std::runtime_error(std::string("Can't parse 2d vector: " + value));
|
throw std::runtime_error(std::string("Can't parse 2d vector: " + value));
|
||||||
return osg::Vec2f(x, y);
|
return {x, y};
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::Vec3f Manager::getVector3 (const std::string& setting, const std::string& category)
|
osg::Vec3f Manager::getVector3 (const std::string& setting, const std::string& category)
|
||||||
|
@ -104,14 +104,14 @@ osg::Vec3f Manager::getVector3 (const std::string& setting, const std::string& c
|
||||||
stream >> x >> y >> z;
|
stream >> x >> y >> z;
|
||||||
if (stream.fail())
|
if (stream.fail())
|
||||||
throw std::runtime_error(std::string("Can't parse 3d vector: " + value));
|
throw std::runtime_error(std::string("Can't parse 3d vector: " + value));
|
||||||
return osg::Vec3f(x, y, z);
|
return {x, y, z};
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
CategorySettingValueMap::key_type key = std::make_pair(category, setting);
|
CategorySettingValueMap::key_type key (category, setting);
|
||||||
|
|
||||||
CategorySettingValueMap::iterator found = mUserSettings.find(key);
|
auto found = mUserSettings.find(key);
|
||||||
if (found != mUserSettings.end())
|
if (found != mUserSettings.end())
|
||||||
{
|
{
|
||||||
if (found->second == value)
|
if (found->second == value)
|
||||||
|
@ -165,18 +165,35 @@ void Manager::setVector3 (const std::string &setting, const std::string &categor
|
||||||
|
|
||||||
void Manager::resetPendingChange(const std::string &setting, const std::string &category)
|
void Manager::resetPendingChange(const std::string &setting, const std::string &category)
|
||||||
{
|
{
|
||||||
CategorySettingValueMap::key_type key = std::make_pair(category, setting);
|
CategorySettingValueMap::key_type key (category, setting);
|
||||||
mChangedSettings.erase(key);
|
mChangedSettings.erase(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
const CategorySettingVector Manager::getPendingChanges()
|
CategorySettingVector Manager::getPendingChanges()
|
||||||
{
|
{
|
||||||
return mChangedSettings;
|
return mChangedSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CategorySettingVector Manager::getPendingChanges(const CategorySettingVector& filter)
|
||||||
|
{
|
||||||
|
CategorySettingVector intersection;
|
||||||
|
std::set_intersection(mChangedSettings.begin(), mChangedSettings.end(),
|
||||||
|
filter.begin(), filter.end(),
|
||||||
|
std::inserter(intersection, intersection.begin()));
|
||||||
|
return intersection;
|
||||||
|
}
|
||||||
|
|
||||||
void Manager::resetPendingChanges()
|
void Manager::resetPendingChanges()
|
||||||
{
|
{
|
||||||
mChangedSettings.clear();
|
mChangedSettings.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Manager::resetPendingChanges(const CategorySettingVector& filter)
|
||||||
|
{
|
||||||
|
for (const auto& key : filter)
|
||||||
|
{
|
||||||
|
mChangedSettings.erase(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,19 @@ namespace Settings
|
||||||
///< save user settings to file
|
///< save user settings to file
|
||||||
|
|
||||||
static void resetPendingChange(const std::string &setting, const std::string &category);
|
static void resetPendingChange(const std::string &setting, const std::string &category);
|
||||||
|
///< resets a single pending change
|
||||||
|
|
||||||
static void resetPendingChanges();
|
static void resetPendingChanges();
|
||||||
|
///< resets the list of all pending changes
|
||||||
|
|
||||||
static const CategorySettingVector getPendingChanges();
|
static void resetPendingChanges(const CategorySettingVector& filter);
|
||||||
///< returns the list of changed settings and then clears it
|
///< resets only the pending changes listed in the filter
|
||||||
|
|
||||||
|
static CategorySettingVector getPendingChanges();
|
||||||
|
///< returns the list of changed settings
|
||||||
|
|
||||||
|
static CategorySettingVector getPendingChanges(const CategorySettingVector& filter);
|
||||||
|
///< returns the list of changed settings intersecting with the filter
|
||||||
|
|
||||||
static int getInt (const std::string& setting, const std::string& category);
|
static int getInt (const std::string& setting, const std::string& category);
|
||||||
static float getFloat (const std::string& setting, const std::string& category);
|
static float getFloat (const std::string& setting, const std::string& category);
|
||||||
|
@ -50,15 +58,15 @@ namespace Settings
|
||||||
static osg::Vec2f getVector2 (const std::string& setting, const std::string& category);
|
static osg::Vec2f getVector2 (const std::string& setting, const std::string& category);
|
||||||
static osg::Vec3f getVector3 (const std::string& setting, const std::string& category);
|
static osg::Vec3f getVector3 (const std::string& setting, const std::string& category);
|
||||||
|
|
||||||
static void setInt (const std::string& setting, const std::string& category, const int value);
|
static void setInt (const std::string& setting, const std::string& category, int value);
|
||||||
static void setFloat (const std::string& setting, const std::string& category, const float value);
|
static void setFloat (const std::string& setting, const std::string& category, float value);
|
||||||
static void setDouble (const std::string& setting, const std::string& category, const double value);
|
static void setDouble (const std::string& setting, const std::string& category, double value);
|
||||||
static void setString (const std::string& setting, const std::string& category, const std::string& value);
|
static void setString (const std::string& setting, const std::string& category, const std::string& value);
|
||||||
static void setBool (const std::string& setting, const std::string& category, const bool value);
|
static void setBool (const std::string& setting, const std::string& category, bool value);
|
||||||
static void setVector2 (const std::string& setting, const std::string& category, const osg::Vec2f value);
|
static void setVector2 (const std::string& setting, const std::string& category, osg::Vec2f value);
|
||||||
static void setVector3 (const std::string& setting, const std::string& category, const osg::Vec3f value);
|
static void setVector3 (const std::string& setting, const std::string& category, osg::Vec3f value);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // _COMPONENTS_SETTINGS_H
|
#endif // COMPONENTS_SETTINGS_H
|
||||||
|
|
Loading…
Reference in a new issue