2019-02-20 13:37:00 +00:00
|
|
|
#ifndef OPENMW_COMPONENTS_SCENEUTIL_SHADOWBIN_H
|
|
|
|
#define OPENMW_COMPONENTS_SCENEUTIL_SHADOWBIN_H
|
|
|
|
#include <unordered_set>
|
|
|
|
#include <osgUtil/RenderBin>
|
|
|
|
|
|
|
|
namespace osg
|
|
|
|
{
|
|
|
|
class Material;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace SceneUtil
|
|
|
|
{
|
|
|
|
|
2020-11-12 16:58:29 +00:00
|
|
|
/// renderbin which culls redundant state for shadow map rendering
|
2019-02-20 13:37:00 +00:00
|
|
|
class ShadowsBin : public osgUtil::RenderBin
|
|
|
|
{
|
|
|
|
private:
|
2020-11-12 00:26:30 +00:00
|
|
|
osg::ref_ptr<osg::StateSet> mNoTestStateSet;
|
|
|
|
osg::ref_ptr<osg::StateSet> mShaderAlphaTestStateSet;
|
2019-02-20 13:37:00 +00:00
|
|
|
public:
|
2020-10-31 19:06:20 +00:00
|
|
|
META_Object(SceneUtil, ShadowsBin)
|
|
|
|
ShadowsBin();
|
2020-11-12 17:04:23 +00:00
|
|
|
ShadowsBin(const ShadowsBin& rhs, const osg::CopyOp& copyop)
|
|
|
|
: osgUtil::RenderBin(rhs, copyop)
|
|
|
|
, mNoTestStateSet(rhs.mNoTestStateSet)
|
|
|
|
, mShaderAlphaTestStateSet(rhs.mShaderAlphaTestStateSet)
|
|
|
|
{}
|
2019-02-20 13:37:00 +00:00
|
|
|
|
2020-11-11 14:58:06 +00:00
|
|
|
void sortImplementation() override;
|
2019-02-20 13:37:00 +00:00
|
|
|
|
|
|
|
struct State
|
|
|
|
{
|
2020-11-12 17:04:23 +00:00
|
|
|
State()
|
|
|
|
: mAlphaBlend(false)
|
|
|
|
, mAlphaBlendOverride(false)
|
|
|
|
, mAlphaTest(false)
|
|
|
|
, mAlphaTestOverride(false)
|
|
|
|
, mMaterial(nullptr)
|
|
|
|
, mMaterialOverride(false)
|
|
|
|
, mImportantState(false)
|
|
|
|
{}
|
|
|
|
|
2019-02-20 13:37:00 +00:00
|
|
|
bool mAlphaBlend;
|
|
|
|
bool mAlphaBlendOverride;
|
|
|
|
bool mAlphaTest;
|
|
|
|
bool mAlphaTestOverride;
|
|
|
|
osg::Material* mMaterial;
|
|
|
|
bool mMaterialOverride;
|
|
|
|
bool mImportantState;
|
|
|
|
bool needTexture() const { return mAlphaBlend || mAlphaTest; }
|
|
|
|
bool needShadows() const;
|
2020-10-31 19:06:20 +00:00
|
|
|
// A state is interesting if there's anything about it that might affect whether we can optimise child state
|
2020-11-12 17:04:23 +00:00
|
|
|
bool interesting() const
|
|
|
|
{
|
|
|
|
return !needShadows() || needTexture() || mAlphaBlendOverride || mAlphaTestOverride || mMaterialOverride || mImportantState;
|
|
|
|
}
|
2019-02-20 13:37:00 +00:00
|
|
|
};
|
|
|
|
|
2020-11-12 00:26:30 +00:00
|
|
|
osgUtil::StateGraph* cullStateGraph(osgUtil::StateGraph* sg, osgUtil::StateGraph* root, std::unordered_set<osgUtil::StateGraph*>& uninteresting);
|
2019-02-20 13:37:00 +00:00
|
|
|
|
2020-10-31 19:06:20 +00:00
|
|
|
static void addPrototype(const std::string& name)
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osgUtil::RenderBin> bin (new ShadowsBin);
|
|
|
|
osgUtil::RenderBin::addRenderBinPrototype(name, bin);
|
|
|
|
}
|
2019-02-20 13:37:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ShadowsBinAdder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ShadowsBinAdder(const std::string& name){ ShadowsBin::addPrototype(name); }
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|