diff --git a/VisualStudio/osg/osg.dsp b/VisualStudio/osg/osg.dsp index 5290d9d4e..0e9e69054 100755 --- a/VisualStudio/osg/osg.dsp +++ b/VisualStudio/osg/osg.dsp @@ -201,6 +201,10 @@ SOURCE=..\..\src\osg\LineSegment.cpp # End Source File # Begin Source File +SOURCE=..\..\src\osg\LineStipple.cpp +# End Source File +# Begin Source File + SOURCE=..\..\src\osg\LineWidth.cpp # End Source File # Begin Source File @@ -445,6 +449,10 @@ SOURCE=..\..\Include\Osg\LineSegment # End Source File # Begin Source File +SOURCE=..\..\Include\Osg\LineStipple +# End Source File +# Begin Source File + SOURCE=..\..\Include\Osg\LineWidth # End Source File # Begin Source File diff --git a/VisualStudio/osgPlugins/osg/dot_osg.dsp b/VisualStudio/osgPlugins/osg/dot_osg.dsp index 179095c49..76e27ee9e 100755 --- a/VisualStudio/osgPlugins/osg/dot_osg.dsp +++ b/VisualStudio/osgPlugins/osg/dot_osg.dsp @@ -170,6 +170,10 @@ SOURCE=..\..\..\src\osgPlugins\osg\LineWidth.cpp # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\osg\LineStipple.cpp +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\osg\LOD.cpp # End Source File # Begin Source File diff --git a/include/osg/LineStipple b/include/osg/LineStipple new file mode 100644 index 000000000..818cf99ad --- /dev/null +++ b/include/osg/LineStipple @@ -0,0 +1,67 @@ +//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield +//Distributed under the terms of the GNU Library General Public License (LGPL) +//as published by the Free Software Foundation. + +#ifndef OSG_LINESTIPPLE +#define OSG_LINESTIPPLE 1 + +#include +#include + +namespace osg { + +class SG_EXPORT LineStipple : public StateAttribute +{ + public : + + LineStipple(); + + /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ + LineStipple(const LineStipple& lw,const CopyOp& copyop=CopyOp::SHALLOW_COPY): + StateAttribute(lw,copyop), + _factor(lw._factor), + _pattern(lw._pattern) {} + + META_StateAttribute(LineStipple, LINESTIPPLE); + + /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ + virtual int compare(const StateAttribute& sa) const + { + // check the types are equal and then create the rhs variable + // used by the COMPARE_StateAttribute_Paramter macro's below. + COMPARE_StateAttribute_Types(LineStipple,sa) + + // compare each paramter in turn against the rhs. + COMPARE_StateAttribute_Parameter(_factor) + COMPARE_StateAttribute_Parameter(_pattern) + + return 0; // passed all the above comparison macro's, must be equal. + } + + virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const + { + ds.setMode(GL_LINE_STIPPLE,value); + } + + + void setFactor(const int factor); + inline const int getFactor() const { return _factor; } + + void setPattern(const unsigned short pattern); + inline const unsigned short getPattern() const { return _pattern; } + + virtual void apply(State& state) const; + + + protected : + + virtual ~LineStipple(); + + int _factor; + unsigned short _pattern; + +}; + +} + +#endif diff --git a/include/osg/StateAttribute b/include/osg/StateAttribute index 633096a58..97b8fb982 100644 --- a/include/osg/StateAttribute +++ b/include/osg/StateAttribute @@ -124,6 +124,7 @@ class SG_EXPORT StateAttribute : public Object POINT, LINEWIDTH, + LINESTIPPLE, SHADEMODEL, POLYGONMODE, POLYGONOFFSET, diff --git a/src/Demos/osgscribe/osgscribe.cpp b/src/Demos/osgscribe/osgscribe.cpp index 855ef5cc2..5aaed1a17 100644 --- a/src/Demos/osgscribe/osgscribe.cpp +++ b/src/Demos/osgscribe/osgscribe.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -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); diff --git a/src/osg/LineStipple.cpp b/src/osg/LineStipple.cpp new file mode 100644 index 000000000..0d96d076a --- /dev/null +++ b/src/osg/LineStipple.cpp @@ -0,0 +1,33 @@ +#include +#include +#include + +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); +} + diff --git a/src/osg/Makefile b/src/osg/Makefile index ef0379add..a1ec5a2ac 100644 --- a/src/osg/Makefile +++ b/src/osg/Makefile @@ -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\ diff --git a/src/osgPlugins/osg/LineStipple.cpp b/src/osgPlugins/osg/LineStipple.cpp new file mode 100644 index 000000000..1bed8d7d4 --- /dev/null +++ b/src/osgPlugins/osg/LineStipple.cpp @@ -0,0 +1,60 @@ +#include + +#include +#include +#include + +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(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(obj); + + fw.indent() << "factor " << linestipple.getFactor() << std::endl; + fw.indent() << "pattern 0x" << std::hex << linestipple.getPattern() << std::dec << std::endl; + + return true; +} + diff --git a/src/osgPlugins/osg/Makefile b/src/osgPlugins/osg/Makefile index 16ffac421..43162d62d 100644 --- a/src/osgPlugins/osg/Makefile +++ b/src/osgPlugins/osg/Makefile @@ -20,6 +20,7 @@ C++FILES = \ Impostor.cpp\ Light.cpp\ LightSource.cpp\ + LineStipple.cpp\ LineWidth.cpp\ LOD.cpp\ Material.cpp\ diff --git a/src/osgPlugins/osg/StateSet.cpp b/src/osgPlugins/osg/StateSet.cpp index 52539c3a5..edc74e555 100644 --- a/src/osgPlugins/osg/StateSet.cpp +++ b/src/osgPlugins/osg/StateSet.cpp @@ -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);