Added support for glLineStipple via osg::LineStipple state attribute.

This commit is contained in:
Robert Osfield
2002-02-24 20:55:45 +00:00
parent 4c4eae8073
commit f600f6fe4a
10 changed files with 184 additions and 1 deletions

View File

@@ -6,6 +6,7 @@
#include <osg/Material>
#include <osg/PolygonOffset>
#include <osg/PolygonMode>
#include <osg/LineStipple>
#include <osgDB/Registry>
#include <osgDB/ReadFile>
@@ -120,6 +121,12 @@ int main( int argc, char **argv )
stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE_ON);
stateset->setMode(GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE_OFF);
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE_ON);
// osg::LineStipple* linestipple = new osg::LineStipple;
// linestipple->setFactor(1);
// linestipple->setPattern(0xf0f0);
// stateset->setAttributeAndModes(linestipple,osg::StateAttribute::OVERRIDE_ON);
decorator->setStateSet(stateset);

33
src/osg/LineStipple.cpp Normal file
View File

@@ -0,0 +1,33 @@
#include <osg/GL>
#include <osg/LineStipple>
#include <osg/Notify>
using namespace osg;
LineStipple::LineStipple()
{
_factor = 1;
_pattern = 0xffff;
}
LineStipple::~LineStipple()
{
}
void LineStipple::setFactor(const int factor)
{
_factor = factor;
}
void LineStipple::setPattern(const unsigned short pattern)
{
_pattern = pattern;
}
void LineStipple::apply(State&) const
{
glLineStipple(_factor, _pattern);
}

View File

@@ -30,6 +30,7 @@ C++FILES = \
Light.cpp\
LightSource.cpp\
LineSegment.cpp\
LineStipple.cpp\
LineWidth.cpp\
LOD.cpp\
Material.cpp\
@@ -99,6 +100,7 @@ TARGET_INCLUDE_FILES = \
osg/Light\
osg/LightSource\
osg/LineSegment\
osg/LineStipple\
osg/LineWidth\
osg/Material\
osg/Math\

View File

@@ -0,0 +1,60 @@
#include <osg/LineStipple>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
using namespace osg;
using namespace osgDB;
// forward declare functions to use later.
bool LineStipple_readLocalData(Object& obj, Input& fr);
bool LineStipple_writeLocalData(const Object& obj, Output& fw);
// register the read and write functions with the osgDB::Registry.
RegisterDotOsgWrapperProxy g_LineStippleProxy
(
new osg::LineStipple,
"LineStipple",
"Object StateAttribute LineStipple",
&LineStipple_readLocalData,
&LineStipple_writeLocalData
);
bool LineStipple_readLocalData(Object& obj, Input& fr)
{
bool iteratorAdvanced = false;
LineStipple& linestipple = static_cast<LineStipple&>(obj);
int ref = linestipple.getFactor();
if (fr[0].matchWord("factor") && fr[1].getInt(ref))
{
linestipple.setFactor(ref);
fr+=2;
iteratorAdvanced = true;
}
osg::uint mask = linestipple.getPattern();
if (fr[0].matchWord("functionMask") && fr[1].getUInt(mask))
{
linestipple.setPattern(mask);
fr+=2;
iteratorAdvanced = true;
}
return iteratorAdvanced;
}
bool LineStipple_writeLocalData(const Object& obj,Output& fw)
{
const LineStipple& linestipple = static_cast<const LineStipple&>(obj);
fw.indent() << "factor " << linestipple.getFactor() << std::endl;
fw.indent() << "pattern 0x" << std::hex << linestipple.getPattern() << std::dec << std::endl;
return true;
}

View File

@@ -20,6 +20,7 @@ C++FILES = \
Impostor.cpp\
Light.cpp\
LightSource.cpp\
LineStipple.cpp\
LineWidth.cpp\
LOD.cpp\
Material.cpp\

View File

@@ -65,6 +65,7 @@ void initGLNames()
ADD_NAME("GL_FOG",GL_FOG)
ADD_NAME("GL_LIGHTING",GL_LIGHTING)
ADD_NAME("GL_POINT_SMOOTH",GL_POINT_SMOOTH)
ADD_NAME("GL_LINE_STIPPLE",GL_LINE_STIPPLE)
ADD_NAME("GL_POLYGON_OFFSET_FILL",GL_POLYGON_OFFSET_FILL)
ADD_NAME("GL_POLYGON_OFFSET_LINE",GL_POLYGON_OFFSET_LINE)
ADD_NAME("GL_POLYGON_OFFSET_POINT",GL_POLYGON_OFFSET_POINT)
@@ -304,7 +305,6 @@ bool StateSet_readLocalData(Object& obj, Input& fr)
{
if (StateSet_matchModeStr(fr[1].getStr(),value))
{
int mode;
fr[0].getInt(mode);
stateset.setMode((StateAttribute::GLMode)mode,value);