2019-02-20 13:37:00 +00:00
|
|
|
#ifndef OPENMW_COMPONENTS_SCENEUTIL_SHADOWBIN_H
|
|
|
|
#define OPENMW_COMPONENTS_SCENEUTIL_SHADOWBIN_H
|
2020-12-16 23:44:15 +00:00
|
|
|
#include <array>
|
2019-02-20 13:37:00 +00:00
|
|
|
#include <osgUtil/RenderBin>
|
|
|
|
#include <unordered_set>
|
|
|
|
|
|
|
|
namespace osg
|
|
|
|
{
|
|
|
|
class Material;
|
2020-12-16 23:44:15 +00:00
|
|
|
class AlphaFunc;
|
2019-02-20 13:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2021-09-01 23:12:47 +00:00
|
|
|
public:
|
|
|
|
template <class T>
|
|
|
|
using Array = std::array<T, GL_ALWAYS - GL_NEVER + 1>;
|
2020-12-16 23:44:15 +00:00
|
|
|
|
2021-09-01 23:12:47 +00:00
|
|
|
using CastingPrograms = Array<osg::ref_ptr<osg::Program>>;
|
2020-12-16 23:44:15 +00:00
|
|
|
|
2020-10-31 19:06:20 +00:00
|
|
|
META_Object(SceneUtil, ShadowsBin)
|
2021-09-02 19:31:11 +00:00
|
|
|
ShadowsBin(const CastingPrograms& castingPrograms);
|
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)
|
2020-12-16 23:44:15 +00:00
|
|
|
, mAlphaFuncShaders(rhs.mAlphaFuncShaders)
|
2020-11-12 17:04:23 +00:00
|
|
|
{
|
|
|
|
}
|
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)
|
2020-12-16 23:44:15 +00:00
|
|
|
, mAlphaFunc(nullptr)
|
|
|
|
, mAlphaFuncOverride(false)
|
2020-11-12 17:04:23 +00:00
|
|
|
, mMaterial(nullptr)
|
|
|
|
, mMaterialOverride(false)
|
|
|
|
, mImportantState(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-02-20 13:37:00 +00:00
|
|
|
bool mAlphaBlend;
|
|
|
|
bool mAlphaBlendOverride;
|
2020-12-16 23:44:15 +00:00
|
|
|
osg::AlphaFunc* mAlphaFunc;
|
|
|
|
bool mAlphaFuncOverride;
|
2019-02-20 13:37:00 +00:00
|
|
|
osg::Material* mMaterial;
|
|
|
|
bool mMaterialOverride;
|
|
|
|
bool mImportantState;
|
2020-12-16 23:44:15 +00:00
|
|
|
bool needTexture() const;
|
2019-02-20 13:37:00 +00:00
|
|
|
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
|
|
|
|
{
|
2020-12-16 23:44:15 +00:00
|
|
|
return !needShadows() || needTexture() || mAlphaBlendOverride || mAlphaFuncOverride || mMaterialOverride
|
|
|
|
|| mImportantState;
|
2020-11-12 17:04:23 +00:00
|
|
|
}
|
2019-02-20 13:37:00 +00:00
|
|
|
};
|
|
|
|
|
2020-12-23 01:24:15 +00:00
|
|
|
osgUtil::StateGraph* cullStateGraph(osgUtil::StateGraph* sg, osgUtil::StateGraph* root,
|
|
|
|
std::unordered_set<osgUtil::StateGraph*>& uninteresting, bool cullFaceOverridden);
|
2019-02-20 13:37:00 +00:00
|
|
|
|
2021-09-01 23:12:47 +00:00
|
|
|
private:
|
2021-09-02 19:31:11 +00:00
|
|
|
ShadowsBin() {}
|
2021-09-01 23:12:47 +00:00
|
|
|
|
|
|
|
osg::ref_ptr<osg::StateSet> mNoTestStateSet;
|
|
|
|
osg::ref_ptr<osg::StateSet> mShaderAlphaTestStateSet;
|
|
|
|
|
|
|
|
Array<osg::ref_ptr<osg::StateSet>> mAlphaFuncShaders;
|
2019-02-20 13:37:00 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|