Added PolygonStipple class from Mike, with mods from Robert to make data

management local.
This commit is contained in:
Robert Osfield
2002-09-19 10:30:15 +00:00
parent 68384e984b
commit ce51fb1841
6 changed files with 137 additions and 0 deletions

View File

@@ -4,6 +4,7 @@
#include <osg/Vec3>
#include <osg/MatrixTransform>
#include <osg/Texture2D>
#include <osg/PolygonStipple>
#include <osgDB/ReadFile>
@@ -489,6 +490,11 @@ osg::Node* createScene()
polyGeom->addPrimitive(new osg::DrawArrays(osg::Primitive::TRIANGLE_STRIP,6,6));
polyGeom->addPrimitive(new osg::DrawArrays(osg::Primitive::TRIANGLE_FAN,12,5));
// polygon stipple
osg::StateSet* stateSet = new osg::StateSet();
polyGeom->setStateSet(stateSet);
osg::PolygonStipple* polygonStipple = new osg::PolygonStipple;
stateSet->setAttributeAndModes(polygonStipple,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
printTriangles("Triangles/Strip/Fan",*polyGeom);

View File

@@ -59,6 +59,7 @@ CXXFILES =\
Point.cpp\
PolygonMode.cpp\
PolygonOffset.cpp\
PolygonStipple.cpp\
PositionAttitudeTransform.cpp\
Primitive.cpp\
Projection.cpp\

View File

@@ -0,0 +1,69 @@
#include <osg/GL>
#include <osg/PolygonStipple>
#include <osg/Notify>
#include <algorithm>
using namespace osg;
static GLubyte defaultPolygonStippleMask[] =
{
0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99,
0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99,
0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99,
0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99,
0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99,
0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99,
0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99,
0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99,
0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99,
0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99,
0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99,
0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99,
0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99,
0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99,
0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99,
0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99
};
PolygonStipple::PolygonStipple()
{
setMask(defaultPolygonStippleMask);
}
PolygonStipple::PolygonStipple(const PolygonStipple& ps,const CopyOp& copyop):
StateAttribute(ps,copyop)
{
setMask(ps.getMask());
}
PolygonStipple::~PolygonStipple()
{
}
int PolygonStipple::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(PolygonStipple,sa)
// compare each parameter in turn against the rhs.
for(unsigned int i=0;i<128;++i)
{
if (_mask[i]<rhs._mask[i]) return -1;
else if (_mask[i]>rhs._mask[i]) return 1;
}
return 0; // passed all the above comparison macro's, must be equal.
}
void PolygonStipple::setMask(const GLubyte* givenMask)
{
std::copy(givenMask,givenMask+128,_mask);
}
void PolygonStipple::apply(State&) const
{
glPolygonStipple(_mask);
}