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

@@ -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

View File

@@ -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

67
include/osg/LineStipple Normal file
View File

@@ -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 <osg/StateAttribute>
#include <osg/StateSet>
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

View File

@@ -124,6 +124,7 @@ class SG_EXPORT StateAttribute : public Object
POINT,
LINEWIDTH,
LINESTIPPLE,
SHADEMODEL,
POLYGONMODE,
POLYGONOFFSET,

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);