mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 15:29:55 +00:00
Refactor PostProcessor code
This commit is contained in:
parent
67421a400a
commit
395de4b251
5 changed files with 79 additions and 71 deletions
|
@ -1,5 +1,6 @@
|
|||
#include "postprocessor.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <SDL_opengl_glext.h>
|
||||
|
||||
#include <osg/Texture1D>
|
||||
|
@ -172,6 +173,21 @@ namespace MWRender
|
|||
Stereo::Manager::instance().screenResolutionChanged();
|
||||
}
|
||||
|
||||
void PostProcessor::populateTechniqueFiles()
|
||||
{
|
||||
for (const auto& name : mVFS->getRecursiveDirectoryIterator(fx::Technique::sSubdir))
|
||||
{
|
||||
std::filesystem::path path = name;
|
||||
std::string fileExt = Misc::StringUtils::lowerCase(path.extension().string());
|
||||
if (!path.parent_path().has_parent_path() && fileExt == fx::Technique::sExt)
|
||||
{
|
||||
auto absolutePath = std::filesystem::path(mVFS->getAbsoluteFileName(name));
|
||||
|
||||
mTechniqueFileMap[absolutePath.stem().string()] = absolutePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PostProcessor::enable(bool usePostProcessing)
|
||||
{
|
||||
mReload = true;
|
||||
|
@ -193,17 +209,8 @@ namespace MWRender
|
|||
|
||||
if (mUsePostProcessing && mTechniqueFileMap.empty())
|
||||
{
|
||||
for (const auto& name : mVFS->getRecursiveDirectoryIterator(fx::Technique::sSubdir))
|
||||
{
|
||||
std::filesystem::path path = name;
|
||||
std::string fileExt = Misc::StringUtils::lowerCase(path.extension().string());
|
||||
if (!path.parent_path().has_parent_path() && fileExt == fx::Technique::sExt)
|
||||
{
|
||||
auto absolutePath = std::filesystem::path(mVFS->getAbsoluteFileName(name));
|
||||
populateTechniqueFiles();
|
||||
|
||||
mTechniqueFileMap[absolutePath.stem().string()] = absolutePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mMainTemplate->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
|
||||
|
@ -357,47 +364,51 @@ namespace MWRender
|
|||
}
|
||||
}
|
||||
|
||||
void PostProcessor::update(size_t frameId)
|
||||
void PostProcessor::updateLiveReload()
|
||||
{
|
||||
static const bool liveReload = Settings::Manager::getBool("live reload", "Post Processing");
|
||||
if (!liveReload)
|
||||
return;
|
||||
|
||||
if (liveReload)
|
||||
for (auto& technique : mTechniques)
|
||||
{
|
||||
for (auto& technique : mTechniques)
|
||||
{
|
||||
if (technique->getStatus() == fx::Technique::Status::File_Not_exists)
|
||||
continue;
|
||||
if (technique->getStatus() == fx::Technique::Status::File_Not_exists)
|
||||
continue;
|
||||
|
||||
technique->setLastModificationTime(std::filesystem::last_write_time(mTechniqueFileMap[technique->getName()]));
|
||||
const auto lastWriteTime = std::filesystem::last_write_time(mTechniqueFileMap[technique->getName()]);
|
||||
const bool isDirty = technique->setLastModificationTime(lastWriteTime);
|
||||
|
||||
if(technique->isValid() && !technique->isDirty())
|
||||
continue;
|
||||
if (technique->isValid() && !isDirty)
|
||||
continue;
|
||||
|
||||
if (technique->isDirty())
|
||||
{
|
||||
technique->compile();
|
||||
if (technique->compile())
|
||||
Log(Debug::Info) << "Reloaded technique : " << mTechniqueFileMap[technique->getName()].string();
|
||||
|
||||
if (technique->isValid())
|
||||
Log(Debug::Info) << "Reloaded technique : " << mTechniqueFileMap[technique->getName()].string();
|
||||
|
||||
if (!mReload)
|
||||
mReload = technique->isValid();
|
||||
}
|
||||
}
|
||||
mReload = technique->isValid();
|
||||
}
|
||||
}
|
||||
|
||||
if (mReload)
|
||||
{
|
||||
mReload = false;
|
||||
void PostProcessor::reloadIfRequired()
|
||||
{
|
||||
if (!mReload)
|
||||
return;
|
||||
|
||||
if (!mTechniques.empty())
|
||||
reloadMainPass(*mTechniques[0]);
|
||||
mReload = false;
|
||||
|
||||
reloadTechniques();
|
||||
if (!mTechniques.empty())
|
||||
reloadMainPass(*mTechniques[0]);
|
||||
|
||||
if (!mUsePostProcessing)
|
||||
resize();
|
||||
}
|
||||
reloadTechniques();
|
||||
|
||||
if (!mUsePostProcessing)
|
||||
resize();
|
||||
}
|
||||
|
||||
void PostProcessor::update(size_t frameId)
|
||||
{
|
||||
updateLiveReload();
|
||||
|
||||
reloadIfRequired();
|
||||
|
||||
if (mDirty && mDirtyFrameId == frameId)
|
||||
{
|
||||
|
@ -647,29 +658,23 @@ namespace MWRender
|
|||
|
||||
bool PostProcessor::disableTechnique(std::shared_ptr<fx::Technique> technique, bool dirty)
|
||||
{
|
||||
for (size_t i = 1; i < mTechniques.size(); ++i)
|
||||
{
|
||||
if (technique.get() == mTechniques[i].get())
|
||||
{
|
||||
mTechniques.erase(mTechniques.begin() + i);
|
||||
if (dirty)
|
||||
dirtyTechniques();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
auto it = std::find(mTechniques.begin(), mTechniques.end(), technique);
|
||||
if (it == std::end(mTechniques))
|
||||
return false;
|
||||
|
||||
return false;
|
||||
mTechniques.erase(it);
|
||||
if (dirty)
|
||||
dirtyTechniques();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PostProcessor::isTechniqueEnabled(const std::shared_ptr<fx::Technique>& technique) const
|
||||
{
|
||||
for (const auto& t : mTechniques)
|
||||
{
|
||||
if (technique.get() == t.get())
|
||||
return technique->isValid();
|
||||
}
|
||||
if (auto it = std::find(mTechniques.begin(), mTechniques.end(), technique); it == mTechniques.end())
|
||||
return false;
|
||||
|
||||
return false;
|
||||
return technique->isValid();
|
||||
}
|
||||
|
||||
void PostProcessor::createTexturesAndCamera(size_t frameId)
|
||||
|
@ -762,7 +767,7 @@ namespace MWRender
|
|||
technique->compile();
|
||||
|
||||
if (technique->getStatus() != fx::Technique::Status::File_Not_exists)
|
||||
technique->setLastModificationTime(std::filesystem::last_write_time(mTechniqueFileMap[technique->getName()]), false);
|
||||
technique->setLastModificationTime(std::filesystem::last_write_time(mTechniqueFileMap[technique->getName()]));
|
||||
|
||||
if (!insert)
|
||||
return technique;
|
||||
|
|
|
@ -161,6 +161,9 @@ namespace MWRender
|
|||
void setRenderTargetSize(int width, int height) { mWidth = width; mHeight = height; }
|
||||
|
||||
private:
|
||||
|
||||
void populateTechniqueFiles();
|
||||
|
||||
size_t frame() const { return mViewer->getFrameStamp()->getFrameNumber(); }
|
||||
|
||||
void createObjectsForFrame(size_t frameId);
|
||||
|
@ -175,6 +178,10 @@ namespace MWRender
|
|||
|
||||
void update(size_t frameId);
|
||||
|
||||
void reloadIfRequired();
|
||||
|
||||
void updateLiveReload();
|
||||
|
||||
void cull(size_t frameId, osgUtil::CullVisitor* cv);
|
||||
|
||||
osg::ref_ptr<osg::Group> mRootNode;
|
||||
|
|
|
@ -55,7 +55,6 @@ namespace fx
|
|||
{
|
||||
mTextures.clear();
|
||||
mStatus = Status::Uncompiled;
|
||||
mDirty = false;
|
||||
mValid = false;
|
||||
mHDR = false;
|
||||
mNormals = false;
|
||||
|
@ -180,12 +179,11 @@ namespace fx
|
|||
return mFileName;
|
||||
}
|
||||
|
||||
void Technique::setLastModificationTime(std::filesystem::file_time_type timeStamp, bool dirty)
|
||||
bool Technique::setLastModificationTime(std::filesystem::file_time_type timeStamp)
|
||||
{
|
||||
if (dirty && mLastModificationTime != timeStamp)
|
||||
mDirty = true;
|
||||
|
||||
const bool isDirty = timeStamp != mLastModificationTime;
|
||||
mLastModificationTime = timeStamp;
|
||||
return isDirty;
|
||||
}
|
||||
|
||||
[[noreturn]] void Technique::error(const std::string& msg)
|
||||
|
@ -541,6 +539,9 @@ namespace fx
|
|||
constexpr bool isVec = std::is_same_v<osg::Vec2f, SrcT> || std::is_same_v<osg::Vec3f, SrcT> || std::is_same_v<osg::Vec4f, SrcT>;
|
||||
constexpr bool isFloat = std::is_same_v<float, SrcT>;
|
||||
constexpr bool isInt = std::is_same_v<int, SrcT>;
|
||||
constexpr bool isBool = std::is_same_v<bool, SrcT>;
|
||||
|
||||
static_assert(isVec || isFloat || isInt || isBool, "Unsupported type");
|
||||
|
||||
std::optional<double> step;
|
||||
|
||||
|
@ -555,7 +556,7 @@ namespace fx
|
|||
data.mDefault = parseFloat();
|
||||
else if constexpr (isInt)
|
||||
data.mDefault = parseInteger();
|
||||
else
|
||||
else if constexpr (isBool)
|
||||
data.mDefault = parseBool();
|
||||
}
|
||||
else if (key == "min")
|
||||
|
@ -566,7 +567,7 @@ namespace fx
|
|||
data.mMin = parseFloat();
|
||||
else if constexpr (isInt)
|
||||
data.mMin = parseInteger();
|
||||
else
|
||||
else if constexpr (isBool)
|
||||
data.mMin = parseBool();
|
||||
}
|
||||
else if (key == "max")
|
||||
|
@ -577,7 +578,7 @@ namespace fx
|
|||
data.mMax = parseFloat();
|
||||
else if constexpr (isInt)
|
||||
data.mMax = parseInteger();
|
||||
else
|
||||
else if constexpr (isBool)
|
||||
data.mMax = parseBool();
|
||||
}
|
||||
else if (key == "step")
|
||||
|
|
|
@ -117,11 +117,7 @@ namespace fx
|
|||
|
||||
std::string getFileName() const;
|
||||
|
||||
void setLastModificationTime(std::filesystem::file_time_type timeStamp, bool dirty = true);
|
||||
|
||||
bool isDirty() const { return mDirty; }
|
||||
|
||||
void setDirty(bool dirty) { mDirty = dirty; }
|
||||
bool setLastModificationTime(std::filesystem::file_time_type timeStamp);
|
||||
|
||||
bool isValid() const { return mValid; }
|
||||
|
||||
|
@ -251,7 +247,6 @@ namespace fx
|
|||
bool mEnabled;
|
||||
|
||||
std::filesystem::file_time_type mLastModificationTime;
|
||||
bool mDirty;
|
||||
bool mValid;
|
||||
bool mHDR;
|
||||
bool mNormals;
|
||||
|
|
|
@ -95,7 +95,7 @@ namespace Settings
|
|||
|
||||
return value.as<T>();
|
||||
}
|
||||
catch(const YAML::BadConversion& e)
|
||||
catch(const YAML::BadConversion&)
|
||||
{
|
||||
Log(Debug::Warning) << "Failed retrieving " << tname << ", " << uname << " : mismatched types in config file.";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue