mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 06:53:53 +00:00
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/Light>
|
||||||
#include <osg/LightModel>
|
#include <osg/LightModel>
|
||||||
#include <osg/Fog>
|
#include <osg/Fog>
|
||||||
|
#include <osg/PolygonMode>
|
||||||
#include <osg/Group>
|
#include <osg/Group>
|
||||||
#include <osg/PositionAttitudeTransform>
|
#include <osg/PositionAttitudeTransform>
|
||||||
#include <osg/UserDataContainer>
|
#include <osg/UserDataContainer>
|
||||||
|
@ -42,6 +43,7 @@ namespace MWRender
|
||||||
public:
|
public:
|
||||||
StateUpdater()
|
StateUpdater()
|
||||||
: mFogEnd(0.f)
|
: mFogEnd(0.f)
|
||||||
|
, mWireframe(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +55,14 @@ namespace MWRender
|
||||||
fog->setStart(1);
|
fog->setStart(1);
|
||||||
fog->setMode(osg::Fog::LINEAR);
|
fog->setMode(osg::Fog::LINEAR);
|
||||||
stateset->setAttributeAndModes(fog, osg::StateAttribute::ON);
|
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*)
|
virtual void apply(osg::StateSet* stateset, osg::NodeVisitor*)
|
||||||
|
@ -79,10 +89,25 @@ namespace MWRender
|
||||||
mFogEnd = end;
|
mFogEnd = end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setWireframe(bool wireframe)
|
||||||
|
{
|
||||||
|
if (mWireframe != wireframe)
|
||||||
|
{
|
||||||
|
mWireframe = wireframe;
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getWireframe() const
|
||||||
|
{
|
||||||
|
return mWireframe;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
osg::Vec4f mAmbientColor;
|
osg::Vec4f mAmbientColor;
|
||||||
osg::Vec4f mFogColor;
|
osg::Vec4f mFogColor;
|
||||||
float mFogEnd;
|
float mFogEnd;
|
||||||
|
bool mWireframe;
|
||||||
};
|
};
|
||||||
|
|
||||||
RenderingManager::RenderingManager(osgViewer::Viewer* viewer, osg::ref_ptr<osg::Group> rootNode, Resource::ResourceSystem* resourceSystem)
|
RenderingManager::RenderingManager(osgViewer::Viewer* viewer, osg::ref_ptr<osg::Group> rootNode, Resource::ResourceSystem* resourceSystem)
|
||||||
|
@ -224,7 +249,9 @@ namespace MWRender
|
||||||
return mPathgrid->toggleRenderMode(mode);
|
return mPathgrid->toggleRenderMode(mode);
|
||||||
else if (mode == Render_Wireframe)
|
else if (mode == Render_Wireframe)
|
||||||
{
|
{
|
||||||
return false;
|
bool wireframe = !mStateUpdater->getWireframe();
|
||||||
|
mStateUpdater->setWireframe(wireframe);
|
||||||
|
return wireframe;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
else //if (mode == Render_BoundingBoxes)
|
else //if (mode == Render_BoundingBoxes)
|
||||||
|
|
|
@ -28,6 +28,12 @@ namespace SceneUtil
|
||||||
traverse(node, nv);
|
traverse(node, nv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StateSetUpdater::reset()
|
||||||
|
{
|
||||||
|
mStateSets[0] = NULL;
|
||||||
|
mStateSets[1] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
StateSetUpdater::StateSetUpdater()
|
StateSetUpdater::StateSetUpdater()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,10 @@ namespace SceneUtil
|
||||||
/// @par May be used e.g. to allocate StateAttributes.
|
/// @par May be used e.g. to allocate StateAttributes.
|
||||||
virtual void setDefaults(osg::StateSet* stateset) {}
|
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:
|
private:
|
||||||
osg::ref_ptr<osg::StateSet> mStateSets[2];
|
osg::ref_ptr<osg::StateSet> mStateSets[2];
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue