forked from teamnwah/openmw-tes3coop
Wireframe mode
This commit is contained in:
parent
7f9f9a32d2
commit
c85764b654
3 changed files with 38 additions and 1 deletions
|
@ -5,6 +5,7 @@
|
|||
#include <osg/Light>
|
||||
#include <osg/LightModel>
|
||||
#include <osg/Fog>
|
||||
#include <osg/PolygonMode>
|
||||
#include <osg/Group>
|
||||
#include <osg/PositionAttitudeTransform>
|
||||
#include <osg/UserDataContainer>
|
||||
|
@ -42,6 +43,7 @@ namespace MWRender
|
|||
public:
|
||||
StateUpdater()
|
||||
: mFogEnd(0.f)
|
||||
, mWireframe(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -53,6 +55,14 @@ namespace MWRender
|
|||
fog->setStart(1);
|
||||
fog->setMode(osg::Fog::LINEAR);
|
||||
stateset->setAttributeAndModes(fog, osg::StateAttribute::ON);
|
||||
if (mWireframe)
|
||||
{
|
||||
osg::PolygonMode* polygonmode = new osg::PolygonMode;
|
||||
polygonmode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE);
|
||||
stateset->setAttributeAndModes(polygonmode, osg::StateAttribute::ON);
|
||||
}
|
||||
else
|
||||
stateset->removeAttribute(osg::StateAttribute::POLYGONMODE);
|
||||
}
|
||||
|
||||
virtual void apply(osg::StateSet* stateset, osg::NodeVisitor*)
|
||||
|
@ -79,10 +89,25 @@ namespace MWRender
|
|||
mFogEnd = end;
|
||||
}
|
||||
|
||||
void setWireframe(bool wireframe)
|
||||
{
|
||||
if (mWireframe != wireframe)
|
||||
{
|
||||
mWireframe = wireframe;
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
bool getWireframe() const
|
||||
{
|
||||
return mWireframe;
|
||||
}
|
||||
|
||||
private:
|
||||
osg::Vec4f mAmbientColor;
|
||||
osg::Vec4f mFogColor;
|
||||
float mFogEnd;
|
||||
bool mWireframe;
|
||||
};
|
||||
|
||||
RenderingManager::RenderingManager(osgViewer::Viewer* viewer, osg::ref_ptr<osg::Group> rootNode, Resource::ResourceSystem* resourceSystem)
|
||||
|
@ -224,7 +249,9 @@ namespace MWRender
|
|||
return mPathgrid->toggleRenderMode(mode);
|
||||
else if (mode == Render_Wireframe)
|
||||
{
|
||||
return false;
|
||||
bool wireframe = !mStateUpdater->getWireframe();
|
||||
mStateUpdater->setWireframe(wireframe);
|
||||
return wireframe;
|
||||
}
|
||||
/*
|
||||
else //if (mode == Render_BoundingBoxes)
|
||||
|
|
|
@ -28,6 +28,12 @@ namespace SceneUtil
|
|||
traverse(node, nv);
|
||||
}
|
||||
|
||||
void StateSetUpdater::reset()
|
||||
{
|
||||
mStateSets[0] = NULL;
|
||||
mStateSets[1] = NULL;
|
||||
}
|
||||
|
||||
StateSetUpdater::StateSetUpdater()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -35,6 +35,10 @@ namespace SceneUtil
|
|||
/// @par May be used e.g. to allocate StateAttributes.
|
||||
virtual void setDefaults(osg::StateSet* stateset) {}
|
||||
|
||||
protected:
|
||||
/// Reset mStateSets, forcing a setDefaults() on the next frame. Can be used to change the defaults if needed.
|
||||
void reset();
|
||||
|
||||
private:
|
||||
osg::ref_ptr<osg::StateSet> mStateSets[2];
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue