mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-10 15:39:02 +00:00
60 lines
2.0 KiB
C++
60 lines
2.0 KiB
C++
#ifndef OPENMW_COMPONENTS_SCENEUTIL_SHADOWBIN_H
|
|
#define OPENMW_COMPONENTS_SCENEUTIL_SHADOWBIN_H
|
|
#include <unordered_set>
|
|
#include <osgUtil/RenderBin>
|
|
|
|
namespace osg
|
|
{
|
|
class Material;
|
|
}
|
|
|
|
namespace SceneUtil
|
|
{
|
|
|
|
/// renderbin which culls redundent state for shadows rendering
|
|
class ShadowsBin : public osgUtil::RenderBin
|
|
{
|
|
private:
|
|
osg::ref_ptr<osg::StateSet> mStateSet;
|
|
public:
|
|
META_Object(SceneUtil, ShadowsBin)
|
|
ShadowsBin();
|
|
ShadowsBin(const ShadowsBin& rhs, const osg::CopyOp& copyop) : osgUtil::RenderBin(rhs, copyop), mStateSet(rhs.mStateSet) {}
|
|
|
|
void sortImplementation() override;
|
|
|
|
struct State
|
|
{
|
|
State():mAlphaBlend(false),mAlphaBlendOverride(false),mAlphaTest(false),mAlphaTestOverride(false),mMaterial(nullptr),mMaterialOverride(false),mImportantState(false){}
|
|
bool mAlphaBlend;
|
|
bool mAlphaBlendOverride;
|
|
bool mAlphaTest;
|
|
bool mAlphaTestOverride;
|
|
osg::Material* mMaterial;
|
|
bool mMaterialOverride;
|
|
bool mImportantState;
|
|
bool needTexture() const { return mAlphaBlend || mAlphaTest; }
|
|
bool needShadows() const;
|
|
// A state is interesting if there's anything about it that might affect whether we can optimise child state
|
|
bool interesting() const { return !needShadows() || needTexture() || mAlphaBlendOverride || mAlphaTestOverride || mMaterialOverride || mImportantState; }
|
|
};
|
|
|
|
bool cullStateGraph(osgUtil::StateGraph* sg, osgUtil::StateGraph* root, std::unordered_set<osgUtil::StateGraph*>& uninteresting);
|
|
|
|
static void addPrototype(const std::string& name)
|
|
{
|
|
osg::ref_ptr<osgUtil::RenderBin> bin (new ShadowsBin);
|
|
osgUtil::RenderBin::addRenderBinPrototype(name, bin);
|
|
}
|
|
};
|
|
|
|
class ShadowsBinAdder
|
|
{
|
|
public:
|
|
ShadowsBinAdder(const std::string& name){ ShadowsBin::addPrototype(name); }
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|